compiling.. borken tho...

This commit is contained in:
2025-01-10 13:09:52 -05:00
parent f6ea780747
commit 572abf5d86
6 changed files with 1146 additions and 930 deletions

View File

@@ -60,7 +60,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
app_env := glue.environment()
ctx.glyph_shader = gfx.make_shader(render_glyph_shader_desc(backend) )
ctx.atlas_shader = gfx.make_shader(blit_atlas_shader_desc(backend) )
ctx.atlas_shader = gfx.make_shader(ve_blit_atlas_shader_desc(backend) )
ctx.screen_shader = gfx.make_shader(ve_draw_text_shader_desc(backend) )
ctx.draw_list_vbuf = gfx.make_buffer( Buffer_Desciption {
@@ -75,7 +75,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
usage = Buffer_Usage.STREAM,
type = Buffer_Type.INDEXBUFFER,
})
assert( gfx.query_buffer_state( draw_list_ibuf) < Resource_State.FAILED, "Failed to make draw_list_iubuf" )
assert( gfx.query_buffer_state( ctx.draw_list_ibuf) < Resource_State.FAILED, "Failed to make draw_list_iubuf" )
Image_Filter := Filter.LINEAR
@@ -114,8 +114,8 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
},
}
glyph_pipeline = gfx.make_pipeline({
shader = glyph_shader,
ctx.glyph_pipeline = gfx.make_pipeline({
shader = ctx.glyph_shader,
layout = vs_layout,
index_type = Vertex_Index_Type.UINT32,
colors = {
@@ -130,29 +130,29 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
cull_mode = .NONE,
sample_count = 1,
})
assert( gfx.query_pipeline_state(glyph_pipeline) < Resource_State.FAILED, "Failed to make glyph_pipeline" )
assert( gfx.query_pipeline_state(ctx.glyph_pipeline) < Resource_State.FAILED, "Failed to make glyph_pipeline" )
}
// glyph_pass
{
glyph_rt_color = gfx.make_image( Image_Desc {
ctx.glyph_rt_color = gfx.make_image( Image_Desc {
type = ._2D,
render_target = true,
width = i32(ve_ctx.glyph_buffer.width),
height = i32(ve_ctx.glyph_buffer.height),
width = i32(ve_ctx.glyph_buffer.size.x),
height = i32(ve_ctx.glyph_buffer.size.y),
num_slices = 1,
num_mipmaps = 1,
usage = .IMMUTABLE,
pixel_format = .R8,
sample_count = 1,
})
assert( gfx.query_image_state(glyph_rt_color) < Resource_State.FAILED, "Failed to make glyph_pipeline" )
assert( gfx.query_image_state(ctx.glyph_rt_color) < Resource_State.FAILED, "Failed to make glyph_pipeline" )
glyph_rt_depth = gfx.make_image( Image_Desc {
ctx.glyph_rt_depth = gfx.make_image( Image_Desc {
type = ._2D,
render_target = true,
width = i32(ve_ctx.glyph_buffer.width),
height = i32(ve_ctx.glyph_buffer.height),
width = i32(ve_ctx.glyph_buffer.size.x),
height = i32(ve_ctx.glyph_buffer.size.y),
num_slices = 1,
num_mipmaps = 1,
usage = .IMMUTABLE,
@@ -160,22 +160,22 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
sample_count = 1,
})
glyph_rt_sampler = gfx.make_sampler( Sampler_Description {
ctx.glyph_rt_sampler = gfx.make_sampler( Sampler_Description {
min_filter = Image_Filter,
mag_filter = Image_Filter,
mipmap_filter = Filter.NEAREST,
wrap_u = .CLAMP_TO_EDGE,
wrap_v = .CLAMP_TO_EDGE,
min_lod = -1000.0,
max_lod = 1000.0,
min_lod = -1.0,
max_lod = 1.0,
border_color = Border_Color.OPAQUE_BLACK,
compare = .NEVER,
max_anisotropy = 1,
})
assert( gfx.query_sampler_state( glyph_rt_sampler) < Resource_State.FAILED, "Failed to make atlas_rt_sampler" )
assert( gfx.query_sampler_state( ctx.glyph_rt_sampler) < Resource_State.FAILED, "Failed to make atlas_rt_sampler" )
color_attach := Attachment_Desc {
image = glyph_rt_color,
image = ctx.glyph_rt_color,
}
glyph_attachments := gfx.make_attachments({
@@ -183,7 +183,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
0 = color_attach,
},
depth_stencil = {
image = glyph_rt_depth,
image = ctx.glyph_rt_depth,
},
})
assert( gfx.query_attachments_state(glyph_attachments) < Resource_State.FAILED, "Failed to make glyph_attachments" )
@@ -208,7 +208,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
}
}
glyph_pass = gfx.Pass {
ctx.glyph_pass = gfx.Pass {
action = glyph_action,
attachments = glyph_attachments,
// label =
@@ -220,12 +220,12 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
vs_layout : Vertex_Layout_State
{
using vs_layout
attrs[ATTR_blit_atlas_v_position] = Vertex_Attribute_State {
attrs[ATTR_ve_blit_atlas_v_position] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = 0,
buffer_index = 0,
}
attrs[ATTR_blit_atlas_v_texture] = Vertex_Attribute_State {
attrs[ATTR_ve_blit_atlas_v_texture] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = size_of(ve.Vec2),
buffer_index = 0,
@@ -250,8 +250,8 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
},
}
atlas_pipeline = gfx.make_pipeline({
shader = atlas_shader,
ctx.atlas_pipeline = gfx.make_pipeline({
shader = ctx.atlas_shader,
layout = vs_layout,
index_type = Vertex_Index_Type.UINT32,
colors = {
@@ -270,11 +270,11 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
// atlas_pass
{
atlas_rt_color = gfx.make_image( Image_Desc {
ctx.atlas_rt_color = gfx.make_image( Image_Desc {
type = ._2D,
render_target = true,
width = i32(ve_ctx.atlas.width),
height = i32(ve_ctx.atlas.height),
width = i32(ve_ctx.atlas.size.x),
height = i32(ve_ctx.atlas.size.y),
num_slices = 1,
num_mipmaps = 1,
usage = .IMMUTABLE,
@@ -283,22 +283,22 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
// TODO(Ed): Setup labels for debug tracing/logging
// label =
})
assert( gfx.query_image_state(atlas_rt_color) < Resource_State.FAILED, "Failed to make atlas_rt_color")
assert( gfx.query_image_state(ctx.atlas_rt_color) < Resource_State.FAILED, "Failed to make atlas_rt_color")
atlas_rt_depth = gfx.make_image( Image_Desc {
ctx.atlas_rt_depth = gfx.make_image( Image_Desc {
type = ._2D,
render_target = true,
width = i32(ve_ctx.atlas.width),
height = i32(ve_ctx.atlas.height),
width = i32(ve_ctx.atlas.size.x),
height = i32(ve_ctx.atlas.size.y),
num_slices = 1,
num_mipmaps = 1,
usage = .IMMUTABLE,
pixel_format = .DEPTH,
sample_count = 1,
})
assert( gfx.query_image_state(atlas_rt_depth) < Resource_State.FAILED, "Failed to make atlas_rt_depth")
assert( gfx.query_image_state(ctx.atlas_rt_depth) < Resource_State.FAILED, "Failed to make atlas_rt_depth")
atlas_rt_sampler = gfx.make_sampler( Sampler_Description {
ctx.atlas_rt_sampler = gfx.make_sampler( Sampler_Description {
min_filter = Image_Filter,
mag_filter = Image_Filter,
mipmap_filter = Filter.NEAREST,
@@ -310,10 +310,10 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
compare = .NEVER,
max_anisotropy = 1,
})
assert( gfx.query_sampler_state( atlas_rt_sampler) < Resource_State.FAILED, "Failed to make atlas_rt_sampler" )
assert( gfx.query_sampler_state( ctx.atlas_rt_sampler) < Resource_State.FAILED, "Failed to make atlas_rt_sampler" )
color_attach := Attachment_Desc {
image = atlas_rt_color,
image = ctx.atlas_rt_color,
}
atlas_attachments := gfx.make_attachments({
@@ -321,7 +321,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
0 = color_attach,
},
depth_stencil = {
image = atlas_rt_depth,
image = ctx.atlas_rt_depth,
},
})
assert( gfx.query_attachments_state(atlas_attachments) < Resource_State.FAILED, "Failed to make atlas_attachments")
@@ -346,7 +346,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
}
}
atlas_pass = gfx.Pass {
ctx.atlas_pass = gfx.Pass {
action = atlas_action,
attachments = atlas_attachments,
}
@@ -357,12 +357,12 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
vs_layout : Vertex_Layout_State
{
using vs_layout
attrs[ATTR_draw_text_v_position] = Vertex_Attribute_State {
attrs[ATTR_ve_draw_text_v_position] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = 0,
buffer_index = 0,
}
attrs[ATTR_draw_text_v_texture] = Vertex_Attribute_State {
attrs[ATTR_ve_draw_text_v_texture] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = size_of(ve.Vec2),
buffer_index = 0,
@@ -387,8 +387,8 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
},
}
screen_pipeline = gfx.make_pipeline({
shader = screen_shader,
ctx.screen_pipeline = gfx.make_pipeline({
shader = ctx.screen_shader,
layout = vs_layout,
index_type = Vertex_Index_Type.UINT32,
colors = {
@@ -403,7 +403,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
},
cull_mode = .NONE,
})
assert( gfx.query_pipeline_state(screen_pipeline) < Resource_State.FAILED, "Failed to make screen_pipeline" )
assert( gfx.query_pipeline_state(ctx.screen_pipeline) < Resource_State.FAILED, "Failed to make screen_pipeline" )
}
// screen_pass
@@ -438,7 +438,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index
}
}
screen_pass = gfx.Pass {
ctx.screen_pass = gfx.Pass {
action = screen_action,
}
}
@@ -483,8 +483,8 @@ render_text_layer :: proc( screen_extent : ve.Vec2, ve_ctx : ^ve.Context, ctx :
continue
}
width := ve_ctx.glyph_buffer.width
height := ve_ctx.glyph_buffer.height
width := ve_ctx.glyph_buffer.size.x
height := ve_ctx.glyph_buffer.size.y
pass := glyph_pass
if draw_call.clear_before_draw {
@@ -518,8 +518,8 @@ render_text_layer :: proc( screen_extent : ve.Vec2, ve_ctx : ^ve.Context, ctx :
continue
}
width := ve_ctx.atlas.width
height := ve_ctx.atlas.height
width := ve_ctx.atlas.size.x
height := ve_ctx.atlas.size.y
pass := atlas_pass
if draw_call.clear_before_draw {
@@ -534,8 +534,8 @@ render_text_layer :: proc( screen_extent : ve.Vec2, ve_ctx : ^ve.Context, ctx :
gfx.apply_pipeline( atlas_pipeline )
fs_uniform := Ve_Blit_Atlas_Fs_Params {
glyph_buffer_size = glyph_buf_size,
over_sample = glyph_buffer.over_sample.x,
glyph_buffer_size = ve.vec2(ve_ctx.glyph_buffer.size),
over_sample = ve_ctx.glyph_buffer.over_sample.x,
region = cast(i32) draw_call.region,
}
gfx.apply_uniforms( UB_ve_blit_atlas_fs_params, Range { & fs_uniform, size_of(Ve_Blit_Atlas_Fs_Params) })
@@ -575,7 +575,7 @@ render_text_layer :: proc( screen_extent : ve.Vec2, ve_ctx : ^ve.Context, ctx :
fs_target_uniform := Ve_Draw_Text_Fs_Params {
// glyph_buffer_size = glyph_buf_size,
over_sample = glyph_buffer.over_sample.x,
over_sample = ve_ctx.glyph_buffer.over_sample.x,
colour = draw_call.colour,
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
@header import sg "thirdparty:sokol/gfx"
@vs ve_blit_atlas_vs
@include ./ve_source_shared.shdc.glsl
@include ./source_shared.shdc.glsl
@end
@fs ve_blit_atlas_fs

View File

@@ -186,8 +186,7 @@ draw_text_zoomed_norm :: proc(content : string, font : Font_ID, size : f32, pos
text_scale := screen_scale
{
f32_resolved_size := f32(resolved_size)
diff_scalar := 1 + (zoom_adjust_size - f32_resolved_size) / f32_resolved_size
diff_scalar := 1 + (zoom_adjust_size - resolved_size) / resolved_size
text_scale = diff_scalar * screen_scale
text_scale.x = clamp(text_scale.x, 0, 1)
text_scale.y = clamp(text_scale.y, 0, 1)
@@ -198,9 +197,12 @@ draw_text_zoomed_norm :: proc(content : string, font : Font_ID, size : f32, pos
ve.draw_text_normalized_space(& demo_ctx.ve_ctx,
def.ve_id,
resolved_size,
color_norm,
screen_size,
pos,
text_scale,
1.0,
content
)
}
@@ -263,7 +265,7 @@ init :: proc "c" ()
ve_sokol.setup_gfx_objects( & demo_ctx.render_ctx, & demo_ctx.ve_ctx, vert_cap = 1024 * 1024, index_cap = 1024 * 1024 )
error : mem.Allocator_Error
demo_ctx.font_ids, error = make( map[string]FontDef, 256 )
demo_ctx.font_ids, error = make( map[string]Font_Entry, 256 )
assert( error == .None, "Failed to allocate demo_ctx.font_ids" )
path_sawarabi_mincho := strings.concatenate({ PATH_FONTS, "SawarabiMincho-Regular.ttf" })
@@ -323,8 +325,8 @@ frame :: proc "c" ()
gfx.begin_pass({ action = pass_action, swapchain = glue.swapchain() })
gfx.end_pass()
{
ve.configure_snap( & demo_ctx.ve_ctx, u32(demo_ctx.screen_size.x), u32(demo_ctx.screen_size.y) )
ve.set_colour( & demo_ctx.ve_ctx, ve.Colour { 1.0, 1.0, 1.0, 1.0 })
// ve.configure_snap( & demo_ctx.ve_ctx, u32(demo_ctx.screen_size.x), u32(demo_ctx.screen_size.y) )
// ve.set_colour( & demo_ctx.ve_ctx, ve.Colour { 1.0, 1.0, 1.0, 1.0 })
using demo_ctx
@@ -513,11 +515,12 @@ etiam dignissim diam quis enim. Convallis convallis tellus id interdum.`
zoomed_text_base_size : f32 = 12.0
zoom_adjust_size := zoomed_text_base_size * current_zoom
ve_id, resolved_size := font_resolve_draw_id( font_firacode, zoom_adjust_size * OVER_SAMPLE_ZOOM )
// ve_id, resolved_size := font_resolve_draw_id( font_firacode, zoom_adjust_size * OVER_SAMPLE_ZOOM )
resolved_size := zoom_adjust_size
current_zoom_text := fmt.tprintf("Current Zoom : %.2f x\nCurrent Resolved Size: %v px", current_zoom, resolved_size )
draw_text_string_pos_norm(current_zoom_text, font_firacode, 19, {0.2, zoom_info_y}, COLOR_WHITE)
ve.configure_snap( & demo_ctx.ve_ctx, u32(0), u32(0) )
// ve.configure_snap( & demo_ctx.ve_ctx, u32(0), u32(0) )
size := measure_text_size( zoom_text, font_firacode, zoomed_text_base_size, 0 ) * current_zoom
x_offset := (size.x / demo_ctx.screen_size.x) * 0.5
@@ -594,7 +597,7 @@ etiam dignissim diam quis enim. Convallis convallis tellus id interdum.`
draw_text_string_pos_norm(codes[grid[y * GRID_W + x]], font_demo_raincode, 20, {pos_x, pos_y}, code_colour)
}
ve.set_colour(&ve_ctx, {1.0, 1.0, 1.0, 1.0})
// ve.set_colour(&ve_ctx, {1.0, 1.0, 1.0, 1.0})
}
// Cache pressure test

View File

@@ -119,6 +119,10 @@ resize :: proc {
builtin.resize_dynamic_array,
}
round :: proc {
math.round_f32,
}
size :: proc {
size_range2,
}

View File

@@ -94,7 +94,6 @@ Context :: struct {
stack : Scope_Stack,
colour : RGBAN, // Color used in draw interface TODO(Ed): use the stack
cursor_pos : Vec2, // TODO(Ed): Review this, no longer used much at all... (still useful I guess)
// Will apply a boost scalar (1.0 + alpha sharpen) to the colour's alpha which provides some sharpening of the edges.
// Has a boldening side-effect. If overblown will look smeared.
@@ -193,7 +192,6 @@ startup :: proc( ctx : ^Context, parser_kind : Parser_Kind = .STB_TrueType, // N
ctx.backing = allocator
context.allocator = ctx.backing
ctx.colour = { 1, 1, 1, 1 }
ctx.alpha_sharpen = alpha_sharpen
ctx.px_scalar = px_scalar
@@ -663,13 +661,12 @@ resolve_draw_px_size :: #force_inline proc "contextless" ( px_size, default_size
{
interval_quotient := 1.0 / f32(interval)
size := px_size == 0.0 ? default_size : px_size
even_size := math.round(size * interval_quotient) * interval
even_size := round(size * interval_quotient) * interval
resolved_size = clamp( even_size, min, max )
return
}
set_alpha_scalar :: #force_inline proc( ctx : ^Context, scalar : f32 ) { assert(ctx != nil); ctx.alpha_sharpen = scalar }
set_colour :: #force_inline proc( ctx : ^Context, colour : RGBAN ) { assert(ctx != nil); ctx.colour = colour }
set_px_scalar :: #force_inline proc( ctx : ^Context, scalar : f32 ) { assert(ctx != nil); ctx.px_scalar = scalar }
set_snap_glyph_shape_position :: #force_inline proc( ctx : ^Context, should_snap : b32 ) {
@@ -835,7 +832,7 @@ draw_text_view_space :: proc(ctx : ^Context,
ctx.cursor_pos = {}
entry := ctx.entries[ font ]
norm_position := view_position * (1 / view)
norm_position := position * (1 / view)
adjusted_position := get_snapped_position( norm_position, view )