compile fixes, forcing a rename to lowercase

This commit is contained in:
2024-07-01 00:53:19 -04:00
parent 7cbafd42ca
commit 60e90484de
4 changed files with 68 additions and 44 deletions

View File

@@ -31,7 +31,7 @@ Context :: struct {
screen_pass : gfx.Pass,
}
setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_cap : int )
setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ^ve.Context, vert_cap, index_cap : u64 )
{
using ctx
Attachment_Desc :: gfx.Attachment_Desc
@@ -92,10 +92,10 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
}
attrs[ATTR_render_glyph_vs_v_texture] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = size_of(Vec2),
offset = size_of(ve.Vec2),
buffer_index = 0,
}
buffers[0] = VertexBufferLayoutState {
buffers[0] = Vertex_Buffer_Layout_State {
stride = size_of([4]f32),
step_func = Vertex_Step.PER_VERTEX
}
@@ -150,7 +150,7 @@ 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(glyph_rt_color) < ResourceState.FAILED, "Failed to make glyph_pipeline" )
assert( gfx.query_image_state(glyph_rt_color) < Resource_State.FAILED, "Failed to make glyph_pipeline" )
glyph_rt_depth = gfx.make_image( Image_Desc {
type = ._2D,
@@ -172,7 +172,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
wrap_v = .CLAMP_TO_EDGE,
min_lod = -1000.0,
max_lod = 1000.0,
border_color = BorderColor.OPAQUE_BLACK,
border_color = Border_Color.OPAQUE_BLACK,
compare = .NEVER,
max_anisotropy = 1,
})
@@ -221,17 +221,17 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
// atlas_pipeline
{
vs_layout : VertexLayoutState
vs_layout : Vertex_Layout_State
{
using vs_layout
attrs[ATTR_ve_blit_atlas_vs_v_position] = Vertex_Attribute_State {
attrs[ATTR_blit_atlas_vs_v_position] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = 0,
buffer_index = 0,
}
attrs[ATTR_ve_blit_atlas_vs_v_texture] = Vertex_Attribute_State {
attrs[ATTR_blit_atlas_vs_v_texture] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = size_of(Vec2),
offset = size_of(ve.Vec2),
buffer_index = 0,
}
buffers[0] = Vertex_Buffer_Layout_State {
@@ -363,14 +363,14 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
vs_layout : Vertex_Layout_State
{
using vs_layout
attrs[ATTR_ve_draw_text_vs_v_position] = Vertex_Attribute_State {
attrs[ATTR_draw_text_vs_v_position] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = 0,
buffer_index = 0,
}
attrs[ATTR_ve_draw_text_vs_v_texture] = Vertex_Attribute_State {
attrs[ATTR_draw_text_vs_v_texture] = Vertex_Attribute_State {
format = Vertex_Format.FLOAT2,
offset = size_of(Vec2),
offset = size_of(ve.Vec2),
buffer_index = 0,
}
buffers[0] = Vertex_Buffer_Layout_State {
@@ -386,10 +386,10 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
enabled = true,
src_factor_rgb = .SRC_ALPHA,
dst_factor_rgb = .ONE_MINUS_SRC_ALPHA,
op_rgb = BlendOp.ADD,
op_rgb = Blend_Op.ADD,
src_factor_alpha = .SRC_ALPHA,
dst_factor_alpha = .ONE_MINUS_SRC_ALPHA,
op_alpha = BlendOp.ADD,
op_alpha = Blend_Op.ADD,
},
}
@@ -409,7 +409,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
},
cull_mode = .NONE,
})
verify( gfx.query_pipeline_state(screen_pipeline) < Resource_State.FAILED, "Failed to make screen_pipeline" )
assert( gfx.query_pipeline_state(screen_pipeline) < Resource_State.FAILED, "Failed to make screen_pipeline" )
}
// screen_pass
@@ -451,7 +451,7 @@ setup_gfx_objects :: proc( ctx : ^Context, ve_ctx : ve.Context, vert_cap, index_
}
}
render_text_layer :: proc( screen_extent : Vec2, ve_ctx : ^ve.Context, ctx : Context )
render_text_layer :: proc( screen_extent : ve.Vec2, ve_ctx : ^ve.Context, ctx : Context )
{
// profile("VEFontCache: render text layer")
using ctx
@@ -568,7 +568,7 @@ render_text_layer :: proc( screen_extent : Vec2, ve_ctx : ^ve.Context, ctx : Con
// profile("VEFontCache: draw call: target")
pass := screen_pass
pass.swapchain = sokol_glue.swapchain()
pass.swapchain = glue.swapchain()
gfx.begin_pass( pass )
gfx.apply_viewport( 0, 0, screen_width, screen_height, origin_top_left = true )

View File

@@ -4,8 +4,10 @@ import "base:runtime"
import "core:path/filepath"
file_name_from_path :: filepath.short_stem
import "core:fmt"
import "core:math"
import "core:mem"
import "core:os"
import "core:strings"
import ve "../../vefontcache"
import ve_sokol "backend:sokol"
@@ -39,13 +41,16 @@ Font_Provider_Use_Freetype :: false
Font_Largest_Px_Size :: 154
Font_Size_Interval :: 2
Font_Default :: FontID { 0, "" }
Font_Default :: FontID { "" }
Font_Default_Size :: 12.0
Font_Load_Use_Default_Size :: -1
Font_Load_Gen_ID :: ""
Screen_Size : [2]u32 : { 1600, 900 }
// Working directory assumed to be the build folder
Path_Fonts :: "../fonts/"
Screen_Size : [2]f32 : { 1600, 900 }
FontID :: struct {
label : string,
@@ -74,22 +79,24 @@ font_load :: proc(path_file : string,
{
msg := fmt.println("Loading font: %v", path_file)
font_data, read_succeded : = os.read_entire_file( path_file, persistent_allocator() )
assert( b32(read_succeded), fmt.println("Failed to read font file for: %v", path_file) )
font_data, read_succeded : = os.read_entire_file( path_file )
assert( bool(read_succeded), fmt.tprintf("Failed to read font file for: %v", path_file) )
font_data_size := cast(i32) len(font_data)
font_firacode : FontID
desired_id := desired_id
if len(desired_id) == 0 {
fmt.println("desired_key not provided, using file name. Give it a proper name!", LogLevel.Warning)
fmt.println("desired_key not provided, using file name. Give it a proper name!")
desired_id = file_name_from_path(path_file)
}
demo_ctx.font_ids[desired_id] = FontDef {}
def = demo_ctx.font_ids[desired_id]
def := & demo_ctx.font_ids[desired_id]
default_size := default_size
if default_size < 0 {
default_size = Font_Default_Point_Size
default_size = Font_Default_Size
}
def.path_file = path_file
@@ -152,20 +159,32 @@ draw_text_string_pos_norm :: proc( content : string, id : FontID, size : f32, po
// Draw text using a string and extent-based screen coordinates
draw_text_string_pos_extent :: proc( content : string, id : FontID, size : f32, pos : Vec2, color := Color_White )
{
render_pos := pos + ve.vec2(Screen_Size) * 0.5
render_pos := pos + Screen_Size * 0.5
normalized_pos := render_pos * (1.0 / Screen_Size)
draw_text_string_pos_norm( content, id, size, normalized_pos, color )
}
sokol_app_alloc :: proc "c" ( size : u64, user_data : rawptr ) -> rawptr {
context = runtime.default_allocator()
block, error := alloc( int(size), allocator = context.allocator )
assert(error == AllocatorError.None, "sokol_app allocation failed")
context = runtime.default_context()
block, error := mem.alloc( int(size), allocator = context.allocator )
assert(error == .None, "sokol_app allocation failed")
return block
}
sokol_app_free :: proc "c" ( data : rawptr, user_data : rawptr ) {
context = runtime.default_allocator()
context = runtime.default_context()
free(data, allocator = context.allocator)
}
sokol_gfx_alloc :: proc "c" ( size : u64, user_data : rawptr ) -> rawptr {
context = runtime.default_context()
block, error := mem.alloc( int(size), allocator = context.allocator )
assert(error == .None, "sokol_gfx allocation failed")
return block
}
sokol_gfx_free :: proc "c" ( data : rawptr, user_data : rawptr ) {
context = runtime.default_context()
free(data, allocator = context.allocator )
}
@@ -179,8 +198,8 @@ init :: proc "c" ()
shader_pool_size = 32,
pipeline_pool_size = 64,
attachments_pool_size = 16,
uniform_buffer_size = 4 * Megabyte,
max_commit_listeners = Kilo,
uniform_buffer_size = 4 * mem.Megabyte,
max_commit_listeners = 1024,
allocator = { sokol_gfx_alloc, sokol_gfx_free, nil },
logger = { func = slog.func },
environment = glue.environment(),
@@ -199,48 +218,53 @@ init :: proc "c" ()
case .DUMMY: fmt.println(">> using dummy backend")
}
ve.startup( & ve_ctx, .STB_TrueType, allocator = persistent_slab_allocator() )
ve_sokol.setup_gfx_objects( & demo_ctx.render_ctx, demo_ctx.ve_ctx )
ve.startup( & demo_ctx.ve_ctx, .STB_TrueType, allocator = context.allocator )
ve_sokol.setup_gfx_objects( & demo_ctx.render_ctx, & demo_ctx.ve_ctx, vert_cap = 128 * 1024, index_cap = 64 * 1024 )
error : mem.Allocator_Error
demo_ctx.font_ids, error = make( map[string]FontDef, 256 )
assert( error == .None, "Failed to allocate demo_ctx.font_ids" )
path_firacode := strings.concatenate( { Path_Fonts, "FiraCode-Regular.ttf" } )
demo_ctx.font_firacode = font_load( path_firacode, 16.0, "FiraCode" )
}
frame :: proc "c" ()
{
context = runtime.default_context()
pass_action : sg.Pass_Action;
pass_action.colors[0] = { load_action = .CLEAR, clear_value = { 0.1, 0.1, 0.1, 1.0 } }
pass_action : gfx.Pass_Action;
pass_action.colors[0] = { load_action = .CLEAR, clear_value = { 0.18 * 0.18, 0.204 * 0.204, 0.251 * 0.251, 1.0 } }
gfx.begin_pass({ action = pass_action, swapchain = glue.swapchain() })
gfx.end_pass()
{
ve.configure_snap( ve_ctx, Screen_Size.x, Screen_Size.y )
ve.configure_snap( & demo_ctx.ve_ctx, u32(Screen_Size.x), u32(Screen_Size.y) )
draw_text_string_pos_extent( "Hello VEFontCache!", )
draw_text_string_pos_extent( "Hello VEFontCache!", demo_ctx.font_firacode, 24, {0, 0}, Color_White )
ve_sokol.render_text_layer( Screen_Size, demo_ctx.ve_ctx, demo_ctx.render_ctx )
ve_sokol.render_text_layer( Screen_Size, & demo_ctx.ve_ctx, demo_ctx.render_ctx )
}
gfx.commit()
ve.flush_draw_list( & font_provider_ctx.ve_ctx )
ve.flush_draw_list( & demo_ctx.ve_ctx )
}
cleanup :: proc "c" ()
{
context = runtime.default_context()
ve.shutdown( demo_ctx.ve_ctx )
ve.shutdown( & demo_ctx.ve_ctx )
gfx.shutdown()
}
main :: proc() {
sapp.run({
app.run({
init_cb = init,
frame_cb = frame,
cleanup_cb = cleanup,
width = Screen_Size.x,
height = Screen_Size.y,
width = i32(Screen_Size.x),
height = i32(Screen_Size.y),
window_title = "VEFonCache: Sokol Backend Demo",
icon = { sokol_default = true },
logger = { func = slog.func },
allocator = { sokol_app_alloc, sokol_app_free, nil },
})
}

View File

@@ -4,7 +4,7 @@ import "base:runtime"
import "core:simd"
import "core:math"
// import core_log "core:log"
import core_log "core:log"
Colour :: [4]f32
Vec2 :: [2]f32