Minor cleanup to current bad impl of font rendering
Just trying to really "get" sokol_gfx.h
This commit is contained in:
@ -12,6 +12,7 @@ RenderState :: struct {
|
||||
pass_actions : PassActions,
|
||||
}
|
||||
|
||||
// TODO(Ed) : Review this and put into space.odin when ready
|
||||
ortho :: proc(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) -> [4][4]f32 {
|
||||
result: [4][4]f32
|
||||
result[0][0] = 2.0 / (right - left)
|
||||
@ -26,6 +27,10 @@ ortho :: proc(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32)
|
||||
|
||||
render :: proc()
|
||||
{
|
||||
Bindings :: sokol_gfx.Bindings
|
||||
Range :: sokol_gfx.Range
|
||||
ShaderStage :: sokol_gfx.Shader_Stage
|
||||
|
||||
state := get_state(); using state
|
||||
using render_data
|
||||
|
||||
@ -67,25 +72,25 @@ render :: proc()
|
||||
{
|
||||
using font_provider_data
|
||||
|
||||
// green_value := debug.gfx_clear_demo_pass_action.colors[0].clear_value.g + 0.01
|
||||
// debug.gfx_clear_demo_pass_action.colors[0].clear_value.g = green_value > 1.0 ? 0.0 : green_value
|
||||
// sokol_gfx.begin_pass( sokol_gfx.Pass {
|
||||
// action = debug.gfx_clear_demo_pass_action,
|
||||
// swapchain = sokol_glue.swapchain()
|
||||
// })
|
||||
sokol_gfx.begin_pass(sokol_gfx.Pass { action = pass_actions.bg_clear_black, swapchain = sokol_glue.swapchain() })
|
||||
green_value := debug.gfx_clear_demo_pass_action.colors[0].clear_value.g + 0.01
|
||||
debug.gfx_clear_demo_pass_action.colors[0].clear_value.g = green_value > 1.0 ? 0.0 : green_value
|
||||
sokol_gfx.begin_pass( sokol_gfx.Pass {
|
||||
action = debug.gfx_clear_demo_pass_action,
|
||||
swapchain = sokol_glue.swapchain()
|
||||
})
|
||||
// sokol_gfx.begin_pass(sokol_gfx.Pass { action = pass_actions.bg_clear_black, swapchain = sokol_glue.swapchain() })
|
||||
sokol_gfx.apply_pipeline( gfx_pipeline )
|
||||
// sokol_gfx.update_buffer( gfx_vbuffer, sokol_gfx.Range{ , Font_Provider_Ggfx_Buffer_Size } )
|
||||
|
||||
projection := ortho( 0, app_window.extent.x * 2, 0, app_window.extent.y * 2, -1, 1 )
|
||||
sokol_gfx.apply_uniforms( sokol_gfx.Shader_Stage.VS, SLOT_vs_params, sokol_gfx.Range{ & projection[0][0] , size_of(projection) })
|
||||
sokol_gfx.apply_uniforms( ShaderStage.VS, SLOT_font_glyph_vs_params, sokol_gfx.Range{ & projection[0][0] , size_of(projection) })
|
||||
|
||||
text_test_str := str_fmt("frametime: %v", frametime_avg_ms)
|
||||
def := hmap_chained_get( font_cache, default_font.key )
|
||||
|
||||
x : f32 = 0.0
|
||||
y : f32 = 25.0
|
||||
scale : f32 = 1.0
|
||||
scale : f32 = 0.5
|
||||
next := 0
|
||||
for codepoint, byte_offset in text_test_str
|
||||
{
|
||||
@ -106,34 +111,49 @@ render :: proc()
|
||||
width := size.x * scale
|
||||
height := size.y * scale
|
||||
|
||||
vertices : [6][4]f32 = {
|
||||
{ pos.x, pos.y + height, 0.0, 0.0 },
|
||||
{ pos.x, pos.y, 0.0, 1.0 },
|
||||
{ pos.x + width, pos.y, 1.0, 1.0 },
|
||||
vertices : [6]Vec2 = {
|
||||
{ pos.x, pos.y + height },
|
||||
{ pos.x, pos.y },
|
||||
{ pos.x + width, pos.y },
|
||||
|
||||
{ pos.x, pos.y + height, 0.0, 0.0 },
|
||||
{ pos.x + width, pos.y, 1.0, 1.0 },
|
||||
{ pos.x + width, pos.y + height, 1.0, 0.0 }
|
||||
{ pos.x, pos.y + height },
|
||||
{ pos.x + width, pos.y },
|
||||
{ pos.x + width, pos.y + height }
|
||||
}
|
||||
|
||||
color : [3]f32 = { 0 = 255, 1 = 255, 2 = 255 }
|
||||
fs_uniform := Fs_Params {
|
||||
uv_coords : [6]Vec2 = {
|
||||
0 = { 0.0, 0.0 },
|
||||
1 = { 0.0, 1.0 },
|
||||
2 = { 1.0, 1.0 },
|
||||
|
||||
3 = { 0.0, 0.0 },
|
||||
4 = { 1.0, 1.0 },
|
||||
5 = { 1.0, 0.0 },
|
||||
}
|
||||
|
||||
color : Vec3 = { 0.2, 0.2, 0.2 }
|
||||
fs_uniform := Font_Glyph_Fs_Params {
|
||||
glyph_color = color
|
||||
}
|
||||
sokol_gfx.apply_uniforms( sokol_gfx.Shader_Stage.FS, SLOT_font_glyph_fs_params, Range{ & fs_uniform, size_of(fs_uniform) })
|
||||
|
||||
vbuf_offset := sokol_gfx.append_buffer( gfx_vbuffer, { & vertices[0][0], size_of(vertices) })
|
||||
// vbuf_offset : i32 = 0
|
||||
vbuf_offset := sokol_gfx.append_buffer( gfx_v_buffer, { & vertices[0], size_of(vertices) })
|
||||
// sokol_gfx.update_buffer( gfx_uv_buffer, { & uv_coords[0], size_of(uv_coords) })
|
||||
|
||||
// bindings := glyph.bindings
|
||||
bindings := sokol_gfx.Bindings {
|
||||
vertex_buffers = { 0 = gfx_vbuffer, },
|
||||
vertex_buffer_offsets = { 0 = vbuf_offset },
|
||||
bindings := Bindings {
|
||||
vertex_buffers = {
|
||||
ATTR_font_glyph_vs_vertex = gfx_v_buffer,
|
||||
ATTR_font_glyph_vs_texture_coord = gfx_uv_buffer,
|
||||
},
|
||||
vertex_buffer_offsets = {
|
||||
ATTR_font_glyph_vs_vertex = vbuf_offset,
|
||||
ATTR_font_glyph_vs_texture_coord = 0,
|
||||
},
|
||||
fs = {
|
||||
images = { 0 = glyph.texture },
|
||||
samplers = { 0 = gfx_sampler }
|
||||
images = { SLOT_glyph_bitmap = glyph.texture },
|
||||
samplers = { SLOT_glyph_bitmap_sampler = gfx_sampler }
|
||||
},
|
||||
}
|
||||
sokol_gfx.apply_uniforms( sokol_gfx.Shader_Stage.FS, SLOT_fs_params, sokol_gfx.Range{ & fs_uniform, size_of(fs_uniform) })
|
||||
sokol_gfx.apply_bindings( bindings )
|
||||
|
||||
sokol_gfx.draw( 0, 6, 1 )
|
||||
@ -145,12 +165,4 @@ render :: proc()
|
||||
sokol_gfx.end_pass()
|
||||
sokol_gfx.commit()
|
||||
}
|
||||
|
||||
// Batching Enqueue Boxes
|
||||
// Mixed with the batching enqueue for text
|
||||
|
||||
//Begin
|
||||
// Flush boxs
|
||||
// flush text
|
||||
// End
|
||||
}
|
Reference in New Issue
Block a user