Texture Rendering (#9)
Co-authored-by: Zachary Levy <zachary@sunforge.is> Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
@@ -35,6 +35,7 @@ Shape_Kind :: enum u8 {
|
||||
|
||||
Shape_Flag :: enum u8 {
|
||||
Stroke,
|
||||
Textured,
|
||||
}
|
||||
|
||||
Shape_Flags :: bit_set[Shape_Flag;u8]
|
||||
@@ -106,9 +107,10 @@ Primitive :: struct {
|
||||
rotation: f32, // 24: shader self-rotation in radians (used by RRect, Ellipse)
|
||||
_pad: f32, // 28: alignment to vec4 boundary
|
||||
params: Shape_Params, // 32: two vec4s of shape params
|
||||
uv_rect: [4]f32, // 64: u_min, v_min, u_max, v_max (default {0,0,1,1})
|
||||
}
|
||||
|
||||
#assert(size_of(Primitive) == 64)
|
||||
#assert(size_of(Primitive) == 80)
|
||||
|
||||
pack_kind_flags :: #force_inline proc(kind: Shape_Kind, flags: Shape_Flags) -> u32 {
|
||||
return u32(kind) | (u32(transmute(u8)flags) << 8)
|
||||
@@ -566,6 +568,7 @@ draw_layer :: proc(
|
||||
current_mode: Draw_Mode = .Tessellated
|
||||
current_vert_buf := main_vert_buf
|
||||
current_atlas: ^sdl.GPUTexture
|
||||
current_sampler := sampler
|
||||
|
||||
// Text vertices live after shape vertices in the GPU vertex buffer
|
||||
text_vertex_gpu_base := u32(len(GLOB.tmp_shape_verts))
|
||||
@@ -584,14 +587,24 @@ draw_layer :: proc(
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vert_buf, offset = 0}, 1)
|
||||
current_vert_buf = main_vert_buf
|
||||
}
|
||||
if current_atlas != white_texture {
|
||||
// Determine texture and sampler for this batch
|
||||
batch_texture: ^sdl.GPUTexture = white_texture
|
||||
batch_sampler: ^sdl.GPUSampler = sampler
|
||||
if batch.texture_id != INVALID_TEXTURE {
|
||||
if bound_texture := texture_gpu_handle(batch.texture_id); bound_texture != nil {
|
||||
batch_texture = bound_texture
|
||||
}
|
||||
batch_sampler = get_sampler(batch.sampler)
|
||||
}
|
||||
if current_atlas != batch_texture || current_sampler != batch_sampler {
|
||||
sdl.BindGPUFragmentSamplers(
|
||||
render_pass,
|
||||
0,
|
||||
&sdl.GPUTextureSamplerBinding{texture = white_texture, sampler = sampler},
|
||||
&sdl.GPUTextureSamplerBinding{texture = batch_texture, sampler = batch_sampler},
|
||||
1,
|
||||
)
|
||||
current_atlas = white_texture
|
||||
current_atlas = batch_texture
|
||||
current_sampler = batch_sampler
|
||||
}
|
||||
sdl.DrawGPUPrimitives(render_pass, batch.count, 1, batch.offset, 0)
|
||||
|
||||
@@ -632,14 +645,24 @@ draw_layer :: proc(
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = unit_quad, offset = 0}, 1)
|
||||
current_vert_buf = unit_quad
|
||||
}
|
||||
if current_atlas != white_texture {
|
||||
// Determine texture and sampler for this batch
|
||||
batch_texture: ^sdl.GPUTexture = white_texture
|
||||
batch_sampler: ^sdl.GPUSampler = sampler
|
||||
if batch.texture_id != INVALID_TEXTURE {
|
||||
if bound_texture := texture_gpu_handle(batch.texture_id); bound_texture != nil {
|
||||
batch_texture = bound_texture
|
||||
}
|
||||
batch_sampler = get_sampler(batch.sampler)
|
||||
}
|
||||
if current_atlas != batch_texture || current_sampler != batch_sampler {
|
||||
sdl.BindGPUFragmentSamplers(
|
||||
render_pass,
|
||||
0,
|
||||
&sdl.GPUTextureSamplerBinding{texture = white_texture, sampler = sampler},
|
||||
&sdl.GPUTextureSamplerBinding{texture = batch_texture, sampler = batch_sampler},
|
||||
1,
|
||||
)
|
||||
current_atlas = white_texture
|
||||
current_atlas = batch_texture
|
||||
current_sampler = batch_sampler
|
||||
}
|
||||
sdl.DrawGPUPrimitives(render_pass, 6, batch.count, 0, batch.offset)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user