dymokomi/luce-gpu
Source of release 0.5.3
0.5.3 / src / gpu / params.lucb
#==============================================================================================
#
# params - Per-draw fragment parameters
#
# DESCRIPTION:
# The 48 bytes every draw hands its fragment shader on both backends: a pixel rectangle
# with either a coverage image (mode 1) or a texture's source rectangle (mode 2) mapped
# onto it. Mode 0 draws the interpolated vertex color alone. Modes 3 and 4 copy the
# source rectangle: as stored, or from premultiplied to straight alpha. Layout is shared with the
# Metal and GLSL shader sources; change all three together.
#
#==============================================================================================
extern struct DrawParams:
x: f32
y: f32
width: f32
height: f32
columns: u32
rows: u32
offset: u32
mode: u32
u0: f32
v0: f32
u1: f32
v1: f32
let draw_solid: u32 = 0
let draw_coverage: u32 = 1
let draw_sampled: u32 = 2
let draw_copied: u32 = 3
let draw_straightened: u32 = 4
## Or'd into the mode on an encoded target: the shader encodes its linear-light
## color (straight) before premultiplying it.
let draw_encoded: u32 = 16
## The pixel-space parameters for `rectangle` mapped onto a texture's `source`.
func image_params(rectangle: Rect, source: Region, texture_width: u32, texture_height: u32, mode: u32 = draw_sampled) -> DrawParams:
return DrawParams((f32)rectangle.x, (f32)rectangle.y, (f32)rectangle.width, (f32)rectangle.height, 0, 0, 0, mode,
(f32)source.x / (f32)texture_width, (f32)source.y / (f32)texture_height,
(f32)(source.x + source.width) / (f32)texture_width, (f32)(source.y + source.height) / (f32)texture_height)