Massive renaming
This commit is contained in:
@@ -240,31 +240,31 @@ create_pipeline_2d_base :: proc(
|
||||
}
|
||||
|
||||
// Create vertex buffer
|
||||
vb_ok: bool
|
||||
pipeline.vertex_buffer, vb_ok = create_buffer(
|
||||
vert_buf_ok: bool
|
||||
pipeline.vertex_buffer, vert_buf_ok = create_buffer(
|
||||
device,
|
||||
size_of(Vertex) * BUFFER_INIT_SIZE,
|
||||
sdl.GPUBufferUsageFlags{.VERTEX},
|
||||
)
|
||||
if !vb_ok do return pipeline, false
|
||||
if !vert_buf_ok do return pipeline, false
|
||||
|
||||
// Create index buffer (used by text)
|
||||
ib_ok: bool
|
||||
pipeline.index_buffer, ib_ok = create_buffer(
|
||||
idx_buf_ok: bool
|
||||
pipeline.index_buffer, idx_buf_ok = create_buffer(
|
||||
device,
|
||||
size_of(c.int) * BUFFER_INIT_SIZE,
|
||||
sdl.GPUBufferUsageFlags{.INDEX},
|
||||
)
|
||||
if !ib_ok do return pipeline, false
|
||||
if !idx_buf_ok do return pipeline, false
|
||||
|
||||
// Create primitive storage buffer (used by SDF instanced drawing)
|
||||
pb_ok: bool
|
||||
pipeline.primitive_buffer, pb_ok = create_buffer(
|
||||
prim_buf_ok: bool
|
||||
pipeline.primitive_buffer, prim_buf_ok = create_buffer(
|
||||
device,
|
||||
size_of(Primitive) * BUFFER_INIT_SIZE,
|
||||
sdl.GPUBufferUsageFlags{.GRAPHICS_STORAGE_READ},
|
||||
)
|
||||
if !pb_ok do return pipeline, false
|
||||
if !prim_buf_ok do return pipeline, false
|
||||
|
||||
// Create static 6-vertex unit quad buffer (two triangles, TRIANGLELIST)
|
||||
pipeline.unit_quad_buffer = sdl.CreateGPUBuffer(
|
||||
@@ -297,23 +297,23 @@ create_pipeline_2d_base :: proc(
|
||||
|
||||
// Upload white pixel and unit quad data in a single command buffer
|
||||
white_pixel := [4]u8{255, 255, 255, 255}
|
||||
white_transfer := sdl.CreateGPUTransferBuffer(
|
||||
white_transfer_buf := sdl.CreateGPUTransferBuffer(
|
||||
device,
|
||||
sdl.GPUTransferBufferCreateInfo{usage = .UPLOAD, size = size_of(white_pixel)},
|
||||
)
|
||||
if white_transfer == nil {
|
||||
if white_transfer_buf == nil {
|
||||
log.errorf("Failed to create white pixel transfer buffer: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
defer sdl.ReleaseGPUTransferBuffer(device, white_transfer)
|
||||
defer sdl.ReleaseGPUTransferBuffer(device, white_transfer_buf)
|
||||
|
||||
white_ptr := sdl.MapGPUTransferBuffer(device, white_transfer, false)
|
||||
white_ptr := sdl.MapGPUTransferBuffer(device, white_transfer_buf, false)
|
||||
if white_ptr == nil {
|
||||
log.errorf("Failed to map white pixel transfer buffer: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
mem.copy(white_ptr, &white_pixel, size_of(white_pixel))
|
||||
sdl.UnmapGPUTransferBuffer(device, white_transfer)
|
||||
sdl.UnmapGPUTransferBuffer(device, white_transfer_buf)
|
||||
|
||||
quad_verts := [6]Vertex {
|
||||
{position = {0, 0}},
|
||||
@@ -323,47 +323,47 @@ create_pipeline_2d_base :: proc(
|
||||
{position = {1, 0}},
|
||||
{position = {1, 1}},
|
||||
}
|
||||
quad_transfer := sdl.CreateGPUTransferBuffer(
|
||||
quad_transfer_buf := sdl.CreateGPUTransferBuffer(
|
||||
device,
|
||||
sdl.GPUTransferBufferCreateInfo{usage = .UPLOAD, size = size_of(quad_verts)},
|
||||
)
|
||||
if quad_transfer == nil {
|
||||
if quad_transfer_buf == nil {
|
||||
log.errorf("Failed to create unit quad transfer buffer: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
defer sdl.ReleaseGPUTransferBuffer(device, quad_transfer)
|
||||
defer sdl.ReleaseGPUTransferBuffer(device, quad_transfer_buf)
|
||||
|
||||
quad_ptr := sdl.MapGPUTransferBuffer(device, quad_transfer, false)
|
||||
quad_ptr := sdl.MapGPUTransferBuffer(device, quad_transfer_buf, false)
|
||||
if quad_ptr == nil {
|
||||
log.errorf("Failed to map unit quad transfer buffer: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
mem.copy(quad_ptr, &quad_verts, size_of(quad_verts))
|
||||
sdl.UnmapGPUTransferBuffer(device, quad_transfer)
|
||||
sdl.UnmapGPUTransferBuffer(device, quad_transfer_buf)
|
||||
|
||||
upload_cmd := sdl.AcquireGPUCommandBuffer(device)
|
||||
if upload_cmd == nil {
|
||||
upload_cmd_buffer := sdl.AcquireGPUCommandBuffer(device)
|
||||
if upload_cmd_buffer == nil {
|
||||
log.errorf("Failed to acquire command buffer for init upload: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
upload_pass := sdl.BeginGPUCopyPass(upload_cmd)
|
||||
upload_pass := sdl.BeginGPUCopyPass(upload_cmd_buffer)
|
||||
|
||||
sdl.UploadToGPUTexture(
|
||||
upload_pass,
|
||||
sdl.GPUTextureTransferInfo{transfer_buffer = white_transfer},
|
||||
sdl.GPUTextureTransferInfo{transfer_buffer = white_transfer_buf},
|
||||
sdl.GPUTextureRegion{texture = pipeline.white_texture, w = 1, h = 1, d = 1},
|
||||
false,
|
||||
)
|
||||
|
||||
sdl.UploadToGPUBuffer(
|
||||
upload_pass,
|
||||
sdl.GPUTransferBufferLocation{transfer_buffer = quad_transfer},
|
||||
sdl.GPUTransferBufferLocation{transfer_buffer = quad_transfer_buf},
|
||||
sdl.GPUBufferRegion{buffer = pipeline.unit_quad_buffer, offset = 0, size = size_of(quad_verts)},
|
||||
false,
|
||||
)
|
||||
|
||||
sdl.EndGPUCopyPass(upload_pass)
|
||||
if !sdl.SubmitGPUCommandBuffer(upload_cmd) {
|
||||
if !sdl.SubmitGPUCommandBuffer(upload_cmd_buffer) {
|
||||
log.errorf("Failed to submit init upload command buffer: %s", sdl.GetError())
|
||||
return pipeline, false
|
||||
}
|
||||
@@ -410,16 +410,16 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
|
||||
sdl.GPUBufferUsageFlags{.VERTEX},
|
||||
)
|
||||
|
||||
v_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.vertex_buffer.transfer, false)
|
||||
if v_array == nil {
|
||||
vert_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.vertex_buffer.transfer, false)
|
||||
if vert_array == nil {
|
||||
log.panicf("Failed to map vertex transfer buffer: %s", sdl.GetError())
|
||||
}
|
||||
if shape_vert_size > 0 {
|
||||
mem.copy(v_array, raw_data(GLOB.tmp_shape_verts), int(shape_vert_size))
|
||||
mem.copy(vert_array, raw_data(GLOB.tmp_shape_verts), int(shape_vert_size))
|
||||
}
|
||||
if text_vert_size > 0 {
|
||||
mem.copy(
|
||||
rawptr(uintptr(v_array) + uintptr(shape_vert_size)),
|
||||
rawptr(uintptr(vert_array) + uintptr(shape_vert_size)),
|
||||
raw_data(GLOB.tmp_text_verts),
|
||||
int(text_vert_size),
|
||||
)
|
||||
@@ -446,11 +446,11 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
|
||||
sdl.GPUBufferUsageFlags{.INDEX},
|
||||
)
|
||||
|
||||
i_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.index_buffer.transfer, false)
|
||||
if i_array == nil {
|
||||
idx_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.index_buffer.transfer, false)
|
||||
if idx_array == nil {
|
||||
log.panicf("Failed to map index transfer buffer: %s", sdl.GetError())
|
||||
}
|
||||
mem.copy(i_array, raw_data(GLOB.tmp_text_indices), int(index_size))
|
||||
mem.copy(idx_array, raw_data(GLOB.tmp_text_indices), int(index_size))
|
||||
sdl.UnmapGPUTransferBuffer(device, GLOB.pipeline_2d_base.index_buffer.transfer)
|
||||
|
||||
sdl.UploadToGPUBuffer(
|
||||
@@ -473,11 +473,11 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
|
||||
sdl.GPUBufferUsageFlags{.GRAPHICS_STORAGE_READ},
|
||||
)
|
||||
|
||||
p_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.primitive_buffer.transfer, false)
|
||||
if p_array == nil {
|
||||
prim_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.primitive_buffer.transfer, false)
|
||||
if prim_array == nil {
|
||||
log.panicf("Failed to map primitive transfer buffer: %s", sdl.GetError())
|
||||
}
|
||||
mem.copy(p_array, raw_data(GLOB.tmp_primitives), int(prim_size))
|
||||
mem.copy(prim_array, raw_data(GLOB.tmp_primitives), int(prim_size))
|
||||
sdl.UnmapGPUTransferBuffer(device, GLOB.pipeline_2d_base.primitive_buffer.transfer)
|
||||
|
||||
sdl.UploadToGPUBuffer(
|
||||
@@ -495,8 +495,8 @@ draw_layer :: proc(
|
||||
window: ^sdl.Window,
|
||||
cmd_buffer: ^sdl.GPUCommandBuffer,
|
||||
render_texture: ^sdl.GPUTexture,
|
||||
swapchain_w: u32,
|
||||
swapchain_h: u32,
|
||||
swapchain_width: u32,
|
||||
swapchain_height: u32,
|
||||
clear_color: [4]f32,
|
||||
layer: ^Layer,
|
||||
) {
|
||||
@@ -550,19 +550,19 @@ draw_layer :: proc(
|
||||
)
|
||||
|
||||
// Shorthand aliases for frequently-used pipeline resources
|
||||
main_vbuf := GLOB.pipeline_2d_base.vertex_buffer.gpu
|
||||
main_vert_buf := GLOB.pipeline_2d_base.vertex_buffer.gpu
|
||||
unit_quad := GLOB.pipeline_2d_base.unit_quad_buffer
|
||||
white := GLOB.pipeline_2d_base.white_texture
|
||||
white_texture := GLOB.pipeline_2d_base.white_texture
|
||||
sampler := GLOB.pipeline_2d_base.sampler
|
||||
w := f32(swapchain_w)
|
||||
h := f32(swapchain_h)
|
||||
width := f32(swapchain_width)
|
||||
height := f32(swapchain_height)
|
||||
|
||||
// Initial GPU state: tessellated mode, main vertex buffer, no atlas bound yet
|
||||
push_globals(cmd_buffer, w, h, .Tessellated)
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
|
||||
push_globals(cmd_buffer, width, height, .Tessellated)
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vert_buf, offset = 0}, 1)
|
||||
|
||||
current_mode: Draw_Mode = .Tessellated
|
||||
current_vbuf := main_vbuf
|
||||
current_vert_buf := main_vert_buf
|
||||
current_atlas: ^sdl.GPUTexture
|
||||
|
||||
// Text vertices live after shape vertices in the GPU vertex buffer
|
||||
@@ -575,69 +575,69 @@ draw_layer :: proc(
|
||||
switch batch.kind {
|
||||
case .Shapes:
|
||||
if current_mode != .Tessellated {
|
||||
push_globals(cmd_buffer, w, h, .Tessellated)
|
||||
push_globals(cmd_buffer, width, height, .Tessellated)
|
||||
current_mode = .Tessellated
|
||||
}
|
||||
if current_vbuf != main_vbuf {
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
|
||||
current_vbuf = main_vbuf
|
||||
if current_vert_buf != main_vert_buf {
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vert_buf, offset = 0}, 1)
|
||||
current_vert_buf = main_vert_buf
|
||||
}
|
||||
if current_atlas != white {
|
||||
if current_atlas != white_texture {
|
||||
sdl.BindGPUFragmentSamplers(
|
||||
render_pass,
|
||||
0,
|
||||
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler},
|
||||
&sdl.GPUTextureSamplerBinding{texture = white_texture, sampler = sampler},
|
||||
1,
|
||||
)
|
||||
current_atlas = white
|
||||
current_atlas = white_texture
|
||||
}
|
||||
sdl.DrawGPUPrimitives(render_pass, batch.count, 1, batch.offset, 0)
|
||||
|
||||
case .Text:
|
||||
if current_mode != .Tessellated {
|
||||
push_globals(cmd_buffer, w, h, .Tessellated)
|
||||
push_globals(cmd_buffer, width, height, .Tessellated)
|
||||
current_mode = .Tessellated
|
||||
}
|
||||
if current_vbuf != main_vbuf {
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
|
||||
current_vbuf = main_vbuf
|
||||
if current_vert_buf != main_vert_buf {
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vert_buf, offset = 0}, 1)
|
||||
current_vert_buf = main_vert_buf
|
||||
}
|
||||
chunk := &GLOB.tmp_text_batches[batch.offset]
|
||||
if current_atlas != chunk.atlas_texture {
|
||||
text_batch := &GLOB.tmp_text_batches[batch.offset]
|
||||
if current_atlas != text_batch.atlas_texture {
|
||||
sdl.BindGPUFragmentSamplers(
|
||||
render_pass,
|
||||
0,
|
||||
&sdl.GPUTextureSamplerBinding{texture = chunk.atlas_texture, sampler = sampler},
|
||||
&sdl.GPUTextureSamplerBinding{texture = text_batch.atlas_texture, sampler = sampler},
|
||||
1,
|
||||
)
|
||||
current_atlas = chunk.atlas_texture
|
||||
current_atlas = text_batch.atlas_texture
|
||||
}
|
||||
sdl.DrawGPUIndexedPrimitives(
|
||||
render_pass,
|
||||
chunk.index_count,
|
||||
text_batch.index_count,
|
||||
1,
|
||||
chunk.index_start,
|
||||
i32(text_vertex_gpu_base + chunk.vertex_start),
|
||||
text_batch.index_start,
|
||||
i32(text_vertex_gpu_base + text_batch.vertex_start),
|
||||
0,
|
||||
)
|
||||
|
||||
case .SDF:
|
||||
if current_mode != .SDF {
|
||||
push_globals(cmd_buffer, w, h, .SDF)
|
||||
push_globals(cmd_buffer, width, height, .SDF)
|
||||
current_mode = .SDF
|
||||
}
|
||||
if current_vbuf != unit_quad {
|
||||
if current_vert_buf != unit_quad {
|
||||
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = unit_quad, offset = 0}, 1)
|
||||
current_vbuf = unit_quad
|
||||
current_vert_buf = unit_quad
|
||||
}
|
||||
if current_atlas != white {
|
||||
if current_atlas != white_texture {
|
||||
sdl.BindGPUFragmentSamplers(
|
||||
render_pass,
|
||||
0,
|
||||
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler},
|
||||
&sdl.GPUTextureSamplerBinding{texture = white_texture, sampler = sampler},
|
||||
1,
|
||||
)
|
||||
current_atlas = white
|
||||
current_atlas = white_texture
|
||||
}
|
||||
sdl.DrawGPUPrimitives(render_pass, 6, batch.count, 0, batch.offset)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user