Minor cleanup to current bad impl of font rendering
Just trying to really "get" sokol_gfx.h
This commit is contained in:
parent
0b819fb8bc
commit
0b74a8115e
@ -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
|
||||
}
|
@ -50,7 +50,6 @@ FontGlyph :: struct {
|
||||
bearing : Vec2i,
|
||||
advance : u32,
|
||||
texture : sokol_gfx.Image,
|
||||
bindings : sokol_gfx.Bindings,
|
||||
}
|
||||
|
||||
FontDef :: struct {
|
||||
@ -60,15 +59,18 @@ FontDef :: struct {
|
||||
}
|
||||
|
||||
FontProviderData :: struct {
|
||||
font_cache : HMapChainedPtr(FontDef),
|
||||
parser : FontParserData,
|
||||
gfx_bindings : sokol_gfx.Bindings,
|
||||
gfx_pipeline : sokol_gfx.Pipeline,
|
||||
gfx_vbuffer : sokol_gfx.Buffer,
|
||||
gfx_sampler : sokol_gfx.Sampler,
|
||||
font_cache : HMapChainedPtr(FontDef),
|
||||
parser : FontParserData,
|
||||
glyph_shader : sokol_gfx.Shader,
|
||||
gfx_bindings : sokol_gfx.Bindings,
|
||||
gfx_pipeline : sokol_gfx.Pipeline,
|
||||
gfx_v_buffer : sokol_gfx.Buffer,
|
||||
gfx_uv_buffer : sokol_gfx.Buffer,
|
||||
gfx_sampler : sokol_gfx.Sampler,
|
||||
}
|
||||
|
||||
Font_Provider_Ggfx_Buffer_Size :: 6 * 4 * size_of(f32) * Kilobyte * 32
|
||||
Font_Quad_Vert_Size :: size_of(Vec2) * 6
|
||||
Font_Provider_Gfx_vBuffer_Size :: Font_Quad_Vert_Size * Kilo * 64
|
||||
|
||||
font_provider_startup :: proc()
|
||||
{
|
||||
@ -92,57 +94,110 @@ font_provider_startup :: proc()
|
||||
|
||||
// Setup Graphics Pipeline
|
||||
{
|
||||
BlendFactor :: sokol_gfx.Blend_Factor
|
||||
BlendOp :: sokol_gfx.Blend_Op
|
||||
BlendState :: sokol_gfx.Blend_State
|
||||
BorderColor :: sokol_gfx.Border_Color
|
||||
BufferDesciption :: sokol_gfx.Buffer_Desc
|
||||
BufferUsage :: sokol_gfx.Usage
|
||||
BufferType :: sokol_gfx.Buffer_Type
|
||||
ColorTargetState :: sokol_gfx.Color_Target_State
|
||||
Filter :: sokol_gfx.Filter
|
||||
Range :: sokol_gfx.Range
|
||||
SamplerDescription :: sokol_gfx.Sampler_Desc
|
||||
Wrap :: sokol_gfx.Wrap
|
||||
VertexAttributeState :: sokol_gfx.Vertex_Attr_State
|
||||
VertexBufferLayoutState :: sokol_gfx.Vertex_Buffer_Layout_State
|
||||
VertexIndexType :: sokol_gfx.Index_Type
|
||||
VertexFormat :: sokol_gfx.Vertex_Format
|
||||
VertexLayoutState :: sokol_gfx.Vertex_Layout_State
|
||||
VertexStep :: sokol_gfx.Vertex_Step
|
||||
|
||||
using font_provider_data
|
||||
backend := sokol_gfx.query_backend()
|
||||
learngl_font_glyph_shader := sokol_gfx.make_shader(learngl_font_glyph_shader_desc(backend))
|
||||
|
||||
gfx_vbuffer = sokol_gfx.make_buffer( sokol_gfx.Buffer_Desc {
|
||||
size = Font_Provider_Ggfx_Buffer_Size, // (6 verts, 4 f32 each) * 32 kilos
|
||||
usage = sokol_gfx.Usage.DYNAMIC,
|
||||
type = sokol_gfx.Buffer_Type.VERTEXBUFFER,
|
||||
glyph_shader = sokol_gfx.make_shader(font_glyph_shader_desc(backend))
|
||||
|
||||
// Glyphs append to a large vertex buffer that must be able to hold all verts per frame, the budget is fixed.
|
||||
// TODO(Ed): Add a way to relase and remake the buffer when an overflow is detected for a frame.
|
||||
gfx_v_buffer = sokol_gfx.make_buffer( BufferDesciption {
|
||||
size = Font_Provider_Gfx_vBuffer_Size,
|
||||
usage = BufferUsage.DYNAMIC,
|
||||
type = BufferType.VERTEXBUFFER,
|
||||
})
|
||||
verify( sokol_gfx.query_buffer_state(gfx_v_buffer) != sokol_gfx.Resource_State.INVALID,
|
||||
"Failed to make font provider's gfx_v_buffer" )
|
||||
|
||||
gfx_sampler = sokol_gfx.make_sampler( sokol_gfx.Sampler_Desc {
|
||||
min_filter = sokol_gfx.Filter.LINEAR,
|
||||
mag_filter = sokol_gfx.Filter.LINEAR,
|
||||
mipmap_filter = sokol_gfx.Filter.NONE,
|
||||
wrap_u = sokol_gfx.Wrap.CLAMP_TO_EDGE,
|
||||
wrap_v = sokol_gfx.Wrap.CLAMP_TO_EDGE,
|
||||
// min_lod = 1.0,
|
||||
// max_lod = 1.0,
|
||||
border_color = sokol_gfx.Border_Color.OPAQUE_BLACK,
|
||||
})
|
||||
uv_coords : [6]Vec2 = {
|
||||
0 = { 0.0, 0.0 },
|
||||
1 = { 0.0, 1.0 },
|
||||
2 = { 1.0, 1.0 },
|
||||
|
||||
glyph_vs_layout : sokol_gfx.Vertex_Layout_State
|
||||
glyph_vs_layout.attrs[ATTR_glyph_vs_vertex] = sokol_gfx.Vertex_Attr_State {
|
||||
format = sokol_gfx.Vertex_Format.FLOAT4,
|
||||
offset = 0,
|
||||
3 = { 0.0, 0.0 },
|
||||
4 = { 1.0, 1.0 },
|
||||
5 = { 1.0, 0.0 },
|
||||
}
|
||||
glyph_vs_layout.buffers[0] = sokol_gfx.Vertex_Buffer_Layout_State {
|
||||
stride = size_of(f32) * 4, // Total stride ( pos2 + tex2 )
|
||||
step_func = sokol_gfx.Vertex_Step.PER_VERTEX,
|
||||
|
||||
// All quads will use the same vertex buffer for texture coordinates.
|
||||
gfx_uv_buffer = sokol_gfx.make_buffer( BufferDesciption {
|
||||
size = 0,
|
||||
usage = BufferUsage.IMMUTABLE,
|
||||
type = BufferType.VERTEXBUFFER,
|
||||
data = Range { & uv_coords[0], size_of(uv_coords) },
|
||||
})
|
||||
verify( sokol_gfx.query_buffer_state(gfx_uv_buffer) != sokol_gfx.Resource_State.INVALID,
|
||||
"Failed to make font provider's gfx_uv_buffer" )
|
||||
|
||||
|
||||
gfx_sampler = sokol_gfx.make_sampler( SamplerDescription {
|
||||
min_filter = Filter.NEAREST,
|
||||
mag_filter = Filter.NEAREST,
|
||||
mipmap_filter = Filter.NONE,
|
||||
wrap_u = Wrap.CLAMP_TO_EDGE,
|
||||
wrap_v = Wrap.CLAMP_TO_EDGE,
|
||||
border_color = BorderColor.OPAQUE_BLACK,
|
||||
})
|
||||
|
||||
glyph_vs_layout : VertexLayoutState
|
||||
{
|
||||
using glyph_vs_layout
|
||||
attrs[ATTR_font_glyph_vs_vertex] = VertexAttributeState {
|
||||
format = VertexFormat.FLOAT2,
|
||||
offset = 0,
|
||||
buffer_index = ATTR_font_glyph_vs_vertex,
|
||||
}
|
||||
buffers[ATTR_font_glyph_vs_vertex] = VertexBufferLayoutState {
|
||||
stride = size_of(Vec2),
|
||||
step_func = VertexStep.PER_VERTEX,
|
||||
}
|
||||
|
||||
attrs[ATTR_font_glyph_vs_texture_coord] = VertexAttributeState {
|
||||
format = VertexFormat.FLOAT2,
|
||||
offset = 0,
|
||||
buffer_index = ATTR_font_glyph_vs_texture_coord,
|
||||
}
|
||||
buffers[ATTR_font_glyph_vs_texture_coord] = VertexBufferLayoutState {
|
||||
stride = size_of(Vec2),
|
||||
step_func = VertexStep.PER_VERTEX,
|
||||
}
|
||||
}
|
||||
|
||||
gfx_pipeline = sokol_gfx.make_pipeline(
|
||||
{
|
||||
shader = learngl_font_glyph_shader,
|
||||
layout = glyph_vs_layout,
|
||||
colors ={
|
||||
0 = sokol_gfx.Color_Target_State \
|
||||
shader = glyph_shader,
|
||||
layout = glyph_vs_layout,
|
||||
index_type = VertexIndexType.NONE,
|
||||
colors = {
|
||||
0 = ColorTargetState \
|
||||
{
|
||||
// pixel_format = sokol_gfx.Pixel_Format.R8,
|
||||
// write_mask = sokol_gfx.Color_Mask.R,
|
||||
blend = sokol_gfx.Blend_State {
|
||||
blend = BlendState {
|
||||
enabled = true,
|
||||
src_factor_rgb = sokol_gfx.Blend_Factor.SRC_ALPHA,
|
||||
dst_factor_rgb = sokol_gfx.Blend_Factor.ONE_MINUS_SRC_ALPHA,
|
||||
// op_rgb = sokol_gfx.Blend_Op.ADD,
|
||||
|
||||
src_factor_alpha= sokol_gfx.Blend_Factor.ONE,
|
||||
dst_factor_alpha = sokol_gfx.Blend_Factor.ZERO,
|
||||
// src_factor_alpha = sokol_gfx.Blend_Factor.ONE,
|
||||
// dst_factor_alpha = sokol_gfx.Blend_Factor.ZERO,
|
||||
// op_alpha = sokol_gfx.Blend_Op.DEFAULT,
|
||||
src_factor_rgb = BlendFactor.SRC_ALPHA,
|
||||
dst_factor_rgb = BlendFactor.ONE_MINUS_SRC_ALPHA,
|
||||
op_rgb = BlendOp.ADD,
|
||||
src_factor_alpha = BlendFactor.ONE,
|
||||
dst_factor_alpha = BlendFactor.ZERO,
|
||||
op_alpha = BlendOp.ADD,
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -157,117 +212,108 @@ font_provider_startup :: proc()
|
||||
font_provider_shutdown :: proc()
|
||||
{
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
|
||||
for & entry in font_cache.lookup
|
||||
{
|
||||
if entry == nil do continue
|
||||
|
||||
def := entry.value
|
||||
// for & px_render in def.size_table {
|
||||
// using px_render
|
||||
// rl.UnloadFontData( glyphs, count )
|
||||
// rl.UnloadTexture ( texture )
|
||||
// rl.MemFree( recs )
|
||||
// }
|
||||
|
||||
// TODO(Ed): Free entry resources.
|
||||
}
|
||||
}
|
||||
|
||||
font_load :: proc(path_file : string,
|
||||
default_size : f32 = Font_Load_Use_Default_Size,
|
||||
desired_id : string = Font_Load_Gen_ID
|
||||
) -> FontID
|
||||
when Font_Provider_Use_Freetype
|
||||
{
|
||||
profile(#procedure)
|
||||
font_load :: proc(path_file : string,
|
||||
default_size : f32 = Font_Load_Use_Default_Size,
|
||||
desired_id : string = Font_Load_Gen_ID
|
||||
) -> FontID
|
||||
{
|
||||
profile(#procedure)
|
||||
|
||||
logf("Loading font: %v", path_file)
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
logf("Loading font: %v", path_file)
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
|
||||
font_data, read_succeded : = os.read_entire_file( path_file )
|
||||
verify( b32(read_succeded), str_fmt("Failed to read font file for: %v", path_file) )
|
||||
font_data_size := cast(i32) len(font_data)
|
||||
font_data, read_succeded : = os.read_entire_file( path_file )
|
||||
verify( b32(read_succeded), str_fmt("Failed to read font file for: %v", path_file) )
|
||||
font_data_size := cast(i32) len(font_data)
|
||||
|
||||
desired_id := desired_id
|
||||
// Use file name as key
|
||||
if len(desired_id) == 0 {
|
||||
// NOTE(Ed): This should never be used except for laziness so I'll be throwing a warning everytime.
|
||||
log("desired_key not provided, using file name. Give it a proper name!", LogLevel.Warning)
|
||||
// desired_id = cast(FontID) file_name_from_path(path_file)
|
||||
desired_id = file_name_from_path(path_file)
|
||||
desired_id := desired_id
|
||||
// Use file name as key
|
||||
if len(desired_id) == 0 {
|
||||
// NOTE(Ed): This should never be used except for laziness so I'll be throwing a warning everytime.
|
||||
log("desired_key not provided, using file name. Give it a proper name!", LogLevel.Warning)
|
||||
// desired_id = cast(FontID) file_name_from_path(path_file)
|
||||
desired_id = file_name_from_path(path_file)
|
||||
}
|
||||
|
||||
key := cast(u64) crc32( transmute([]byte) desired_id )
|
||||
def, set_error := hmap_chained_set(font_cache, key, FontDef{})
|
||||
verify( set_error == AllocatorError.None, "Failed to add new font entry to cache" )
|
||||
|
||||
def.path_file = path_file
|
||||
|
||||
face_index :: 0
|
||||
freetype.new_memory_face( font_provider_data.parser.lib, raw_data(font_data), font_data_size, face_index, & def.parser_info.face )
|
||||
|
||||
// Hardcoding to 24 pt for testing (until we have a proper cached atlas)
|
||||
freetype.set_pixel_sizes( def.parser_info.face, 0, 72 )
|
||||
|
||||
for ascii_code in 0 ..< 128
|
||||
{
|
||||
load_error := freetype.load_char(def.parser_info.face, u32(ascii_code), {freetype.Load_Flag.Render})
|
||||
verify( load_error == .Ok, "Failed to load character using freetype" )
|
||||
|
||||
// using def.parser_info
|
||||
using def
|
||||
// glyph := parser_info.face.glyph
|
||||
// bitmap := & glyph.bitmap
|
||||
using parser_info.face.glyph
|
||||
|
||||
codepoint := rune(ascii_code)
|
||||
if ! unicode.is_print(codepoint) || bitmap.width <= 0 do continue
|
||||
|
||||
ImageDescription :: sokol_gfx.Image_Desc
|
||||
ImageUsage :: sokol_gfx.Usage
|
||||
Range :: sokol_gfx.Range
|
||||
PixelFormat :: sokol_gfx.Pixel_Format
|
||||
|
||||
glyph_data : sokol_gfx.Image_Data
|
||||
glyph_data.subimage[0][0] = Range { bitmap.buffer, u64(bitmap.width * bitmap.rows) }
|
||||
|
||||
desc := sokol_gfx.Image_Desc {
|
||||
type = sokol_gfx.Image_Type._2D,
|
||||
render_target = false,
|
||||
width = i32(bitmap.width),
|
||||
height = i32(bitmap.rows),
|
||||
num_slices = 1,
|
||||
num_mipmaps = 1,
|
||||
usage = ImageUsage.IMMUTABLE,
|
||||
pixel_format = PixelFormat.R8,
|
||||
sample_count = 0,
|
||||
data = glyph_data,
|
||||
label = strings.clone_to_cstring(str_fmt("font_ascii %v", ascii_code))
|
||||
}
|
||||
|
||||
// width := i32(bitmap.width)
|
||||
// rows := i32(bitmap.rows)
|
||||
// logf("font_ascii : %v", ascii_code )
|
||||
// logf("font_ascii glyph: %v", rune(ascii_code) )
|
||||
|
||||
sokol_img := sokol_gfx.make_image( desc )
|
||||
verify( sokol_gfx.query_image_state(sokol_img) != sokol_gfx.Resource_State.INVALID,
|
||||
"Failed to create image on sokol gfx" );
|
||||
|
||||
def.glyphs[ascii_code] = FontGlyph {
|
||||
size = { i32(bitmap.width), i32(bitmap.rows) },
|
||||
bearing = { bitmap_left, bitmap_top },
|
||||
texture = sokol_img,
|
||||
advance = u32(advance.x),
|
||||
}
|
||||
}
|
||||
|
||||
freetype.done_face( def.parser_info.face )
|
||||
|
||||
fid := FontID { key, desired_id }
|
||||
return fid
|
||||
}
|
||||
|
||||
// default_size := default_size
|
||||
// if default_size == Font_Load_Use_Default_Size {
|
||||
// default_size = Font_Default_Point_Size
|
||||
// }
|
||||
|
||||
key := cast(u64) crc32( transmute([]byte) desired_id )
|
||||
def, set_error := hmap_chained_set(font_cache, key, FontDef{})
|
||||
verify( set_error == AllocatorError.None, "Failed to add new font entry to cache" )
|
||||
|
||||
def.path_file = path_file
|
||||
// def.default_size = i32(points_to_pixels(default_size))
|
||||
|
||||
face_index :: 0
|
||||
freetype.new_memory_face( font_provider_data.parser.lib, raw_data(font_data), cast(i32) len(font_data), face_index, & def.parser_info.face )
|
||||
|
||||
// Hardcoding to 24 pt for testing (until we have a proper cached atlas)
|
||||
freetype.set_pixel_sizes( def.parser_info.face, 0, 72 )
|
||||
|
||||
for ascii_code in 0 ..< 128 {
|
||||
load_error := freetype.load_char(def.parser_info.face, u32(ascii_code), {freetype.Load_Flag.Render})
|
||||
verify( load_error == .Ok, "Failed to load character using freetype" )
|
||||
|
||||
using def.parser_info
|
||||
|
||||
codepoint := rune(ascii_code)
|
||||
|
||||
if ! unicode.is_print(codepoint) || face.glyph.bitmap.width <= 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
glyph_data : sokol_gfx.Image_Data
|
||||
glyph_data.subimage[0][0] = sokol_gfx.Range {
|
||||
face.glyph.bitmap.buffer,
|
||||
u64(face.glyph.bitmap.width * face.glyph.bitmap.rows)
|
||||
}
|
||||
desc := sokol_gfx.Image_Desc {
|
||||
type = sokol_gfx.Image_Type._2D,
|
||||
render_target = false,
|
||||
width = i32(face.glyph.bitmap.width),
|
||||
height = i32(face.glyph.bitmap.rows),
|
||||
num_slices = 1,
|
||||
num_mipmaps = 1,
|
||||
usage = sokol_gfx.Usage.IMMUTABLE,
|
||||
pixel_format = sokol_gfx.Pixel_Format.R8,
|
||||
sample_count = 0,
|
||||
data = glyph_data,
|
||||
label = strings.clone_to_cstring(str_fmt("font_ascii %v", ascii_code))
|
||||
}
|
||||
width := i32(face.glyph.bitmap.width)
|
||||
rows := i32(face.glyph.bitmap.rows)
|
||||
logf("font_ascii : %v", ascii_code )
|
||||
logf("font_ascii glyph: %v", rune(ascii_code) )
|
||||
rhi_img := sokol_gfx.make_image( desc )
|
||||
verify( sokol_gfx.query_image_state(rhi_img) != sokol_gfx.Resource_State.INVALID,
|
||||
"Failed to create image on sokol gfx" );
|
||||
|
||||
def_bindings := sokol_gfx.Bindings {
|
||||
vertex_buffers = { ATTR_glyph_vs_vertex = gfx_vbuffer, },
|
||||
fs = {
|
||||
images = { SLOT_glyph_bitmap = rhi_img, },
|
||||
samplers = { SLOT_glyph_bitmap_sampler = gfx_sampler }
|
||||
},
|
||||
}
|
||||
|
||||
def.glyphs[ascii_code] = FontGlyph {
|
||||
size = { i32(face.glyph.bitmap.width), i32(face.glyph.bitmap.rows) },
|
||||
bearing = { face.glyph.bitmap_left, face.glyph.bitmap_top },
|
||||
texture = rhi_img,
|
||||
bindings = def_bindings,
|
||||
advance = u32(face.glyph.advance.x),
|
||||
}
|
||||
}
|
||||
|
||||
fid := FontID { key, desired_id }
|
||||
return fid
|
||||
}
|
||||
|
270
code/sectr/shaders/font_glyph.odin
Normal file
270
code/sectr/shaders/font_glyph.odin
Normal file
@ -0,0 +1,270 @@
|
||||
/*
|
||||
#version:1# (machine generated, don't edit!)
|
||||
|
||||
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
|
||||
|
||||
Cmdline:
|
||||
sokol-shdc --input C:\projects\SectrPrototype\code\sectr\shaders\font_glyph.shdc.glsl --output C:\projects\SectrPrototype\code\sectr\shaders\font_glyph.odin --slang hlsl5 --format=sokol_odin
|
||||
|
||||
Overview:
|
||||
=========
|
||||
Shader program: 'font_glyph':
|
||||
Get shader desc: font_glyph_shader_desc(sg.query_backend())
|
||||
Vertex shader: font_glyph_vs
|
||||
Attributes:
|
||||
ATTR_font_glyph_vs_vertex => 0
|
||||
ATTR_font_glyph_vs_texture_coord => 1
|
||||
Uniform block 'font_glyph_vs_params':
|
||||
Odin struct: Font_Glyph_Vs_Params
|
||||
Bind slot: SLOT_font_glyph_vs_params => 0
|
||||
Fragment shader: font_glyph_fs
|
||||
Uniform block 'font_glyph_fs_params':
|
||||
Odin struct: Font_Glyph_Fs_Params
|
||||
Bind slot: SLOT_font_glyph_fs_params => 0
|
||||
Image 'glyph_bitmap':
|
||||
Image type: ._2D
|
||||
Sample type: .FLOAT
|
||||
Multisampled: false
|
||||
Bind slot: SLOT_glyph_bitmap => 0
|
||||
Sampler 'glyph_bitmap_sampler':
|
||||
Type: .FILTERING
|
||||
Bind slot: SLOT_glyph_bitmap_sampler => 0
|
||||
Image Sampler Pair 'glyph_bitmap_glyph_bitmap_sampler':
|
||||
Image: glyph_bitmap
|
||||
Sampler: glyph_bitmap_sampler
|
||||
*/
|
||||
package sectr
|
||||
import sg "thirdparty:sokol/gfx"
|
||||
|
||||
ATTR_font_glyph_vs_vertex :: 0
|
||||
ATTR_font_glyph_vs_texture_coord :: 1
|
||||
|
||||
SLOT_font_glyph_vs_params :: 0
|
||||
SLOT_font_glyph_fs_params :: 0
|
||||
SLOT_glyph_bitmap :: 0
|
||||
SLOT_glyph_bitmap_sampler :: 0
|
||||
|
||||
Font_Glyph_Vs_Params :: struct #align(16) {
|
||||
using _: struct #packed {
|
||||
projection: [16]f32,
|
||||
},
|
||||
}
|
||||
Font_Glyph_Fs_Params :: struct #align(16) {
|
||||
using _: struct #packed {
|
||||
glyph_color: [3]f32,
|
||||
_: [4]u8,
|
||||
},
|
||||
}
|
||||
/*
|
||||
cbuffer font_glyph_vs_params : register(b0)
|
||||
{
|
||||
row_major float4x4 _19_projection : packoffset(c0);
|
||||
};
|
||||
|
||||
|
||||
static float4 gl_Position;
|
||||
static float2 vertex;
|
||||
static float2 uv;
|
||||
static float2 texture_coord;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 vertex : TEXCOORD0;
|
||||
float2 texture_coord : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = mul(float4(vertex, 0.0f, 1.0f), _19_projection);
|
||||
uv = texture_coord;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vertex = stage_input.vertex;
|
||||
texture_coord = stage_input.texture_coord;
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.uv = uv;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
font_glyph_vs_source_hlsl5 := [803]u8 {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x66,0x6f,0x6e,0x74,0x5f,0x67,0x6c,0x79,
|
||||
0x70,0x68,0x5f,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x72,
|
||||
0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x39,0x5f,0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,
|
||||
0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,
|
||||
0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,
|
||||
0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x32,0x20,0x76,0x65,0x72,0x74,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,
|
||||
0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x3b,0x0a,0x73,0x74,
|
||||
0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x74,
|
||||
0x75,0x72,0x65,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,
|
||||
0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,
|
||||
0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x32,0x20,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,
|
||||
0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,
|
||||
0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x20,0x3a,
|
||||
0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
|
||||
0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,
|
||||
0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,
|
||||
0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x28,0x76,0x65,0x72,0x74,0x65,0x78,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,
|
||||
0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x39,0x5f,0x70,0x72,0x6f,0x6a,0x65,0x63,
|
||||
0x74,0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,
|
||||
0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x7d,
|
||||
0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,
|
||||
0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,
|
||||
0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,
|
||||
0x65,0x72,0x74,0x65,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x70,0x75,0x74,0x2e,0x76,0x65,0x72,0x74,0x65,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,
|
||||
0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x74,0x65,0x78,0x74,
|
||||
0x75,0x72,0x65,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,
|
||||
0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,
|
||||
0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
|
||||
0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x75,0x76,
|
||||
0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
|
||||
0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
|
||||
0x7d,0x0a,0x00,
|
||||
}
|
||||
/*
|
||||
cbuffer font_glyph_fs_params : register(b0)
|
||||
{
|
||||
float3 _33_glyph_color : packoffset(c0);
|
||||
};
|
||||
|
||||
Texture2D<float4> glyph_bitmap : register(t0);
|
||||
SamplerState glyph_bitmap_sampler : register(s0);
|
||||
|
||||
static float2 uv;
|
||||
static float4 color;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 color : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
color = float4(_33_glyph_color, glyph_bitmap.Sample(glyph_bitmap_sampler, uv).x);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
uv = stage_input.uv;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.color = color;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
font_glyph_fs_source_hlsl5 := [658]u8 {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x66,0x6f,0x6e,0x74,0x5f,0x67,0x6c,0x79,
|
||||
0x70,0x68,0x5f,0x66,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x72,
|
||||
0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x33,0x5f,0x67,0x6c,0x79,
|
||||
0x70,0x68,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,
|
||||
0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,
|
||||
0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,
|
||||
0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x20,0x3a,0x20,
|
||||
0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,
|
||||
0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x67,0x6c,0x79,0x70,0x68,
|
||||
0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x5f,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,
|
||||
0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,
|
||||
0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
|
||||
0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
|
||||
0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,
|
||||
0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
|
||||
0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,
|
||||
0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,
|
||||
0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,
|
||||
0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,
|
||||
0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x33,0x33,0x5f,0x67,0x6c,0x79,0x70,
|
||||
0x68,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x62,
|
||||
0x69,0x74,0x6d,0x61,0x70,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x67,0x6c,0x79,
|
||||
0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x5f,0x73,0x61,0x6d,0x70,0x6c,0x65,
|
||||
0x72,0x2c,0x20,0x75,0x76,0x29,0x2e,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,
|
||||
0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,
|
||||
0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,
|
||||
0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,
|
||||
0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x75,0x76,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,
|
||||
0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,
|
||||
0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,
|
||||
0x0a,0x00,
|
||||
}
|
||||
font_glyph_shader_desc :: proc (backend: sg.Backend) -> sg.Shader_Desc {
|
||||
desc: sg.Shader_Desc
|
||||
desc.label = "font_glyph_shader"
|
||||
#partial switch backend {
|
||||
case .D3D11:
|
||||
desc.attrs[0].sem_name = "TEXCOORD"
|
||||
desc.attrs[0].sem_index = 0
|
||||
desc.attrs[1].sem_name = "TEXCOORD"
|
||||
desc.attrs[1].sem_index = 1
|
||||
|
||||
desc.vs.source = transmute(cstring)&font_glyph_vs_source_hlsl5
|
||||
desc.vs.d3d11_target = "vs_5_0"
|
||||
desc.vs.entry = "main"
|
||||
desc.vs.uniform_blocks[0].size = 64
|
||||
desc.vs.uniform_blocks[0].layout = .STD140
|
||||
|
||||
desc.fs.source = transmute(cstring)&font_glyph_fs_source_hlsl5
|
||||
desc.fs.d3d11_target = "ps_5_0"
|
||||
desc.fs.entry = "main"
|
||||
|
||||
desc.fs.uniform_blocks[0].size = 16
|
||||
desc.fs.uniform_blocks[0].layout = .STD140
|
||||
|
||||
desc.fs.images[0].used = true
|
||||
desc.fs.images[0].multisampled = false
|
||||
desc.fs.images[0].image_type = ._2D
|
||||
desc.fs.images[0].sample_type = .FLOAT
|
||||
|
||||
desc.fs.samplers[0].used = true
|
||||
desc.fs.samplers[0].sampler_type = .FILTERING
|
||||
|
||||
desc.fs.image_sampler_pairs[0].used = true
|
||||
desc.fs.image_sampler_pairs[0].image_slot = 0
|
||||
desc.fs.image_sampler_pairs[0].sampler_slot = 0
|
||||
}
|
||||
return desc
|
||||
}
|
36
code/sectr/shaders/font_glyph.shdc.glsl
Normal file
36
code/sectr/shaders/font_glyph.shdc.glsl
Normal file
@ -0,0 +1,36 @@
|
||||
@vs font_glyph_vs
|
||||
in vec2 vertex;
|
||||
in vec2 texture_coord;
|
||||
|
||||
out vec2 uv;
|
||||
|
||||
uniform font_glyph_vs_params {
|
||||
mat4 projection;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * vec4(vertex, 0.0, 1.00);
|
||||
uv = texture_coord;
|
||||
}
|
||||
@end
|
||||
|
||||
@fs font_glyph_fs
|
||||
in vec2 uv;
|
||||
out vec4 color;
|
||||
|
||||
uniform texture2D glyph_bitmap;
|
||||
uniform sampler glyph_bitmap_sampler;
|
||||
|
||||
uniform font_glyph_fs_params {
|
||||
vec3 glyph_color;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
float alpha = texture(sampler2D(glyph_bitmap, glyph_bitmap_sampler), uv).r;
|
||||
color = vec4(glyph_color, alpha);
|
||||
}
|
||||
@end
|
||||
|
||||
@program font_glyph font_glyph_vs font_glyph_fs
|
@ -1,12 +0,0 @@
|
||||
#version 330 core
|
||||
in vec2 TexCoords;
|
||||
out vec4 color;
|
||||
|
||||
uniform sampler2D glyph_bitmap;
|
||||
uniform vec3 glyph_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(glyph_bitmap, TexCoords).r);
|
||||
color = vec4(glyph_color, 1.0) * sampled;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec4 vertex; // <vec2 pos, vec2 tex>
|
||||
|
||||
out vec2 TexCoords;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
|
||||
TexCoords = vertex.zw;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
@vs glyph_vs
|
||||
in vec4 vertex; // <vec2 pos, vec2 tex>
|
||||
|
||||
out vec2 uv;
|
||||
|
||||
uniform vs_params {
|
||||
mat4 projection;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * vec4(vertex.xy, 0.0, 1.00);
|
||||
uv = vertex.zw;
|
||||
}
|
||||
@end
|
||||
|
||||
@fs glyph_fs
|
||||
in vec2 uv;
|
||||
out vec4 color;
|
||||
|
||||
uniform texture2D glyph_bitmap;
|
||||
uniform sampler glyph_bitmap_sampler;
|
||||
|
||||
uniform fs_params {
|
||||
vec3 glyph_color;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(sampler2D(glyph_bitmap, glyph_bitmap_sampler), uv).r);
|
||||
color = vec4(glyph_color, 1.0) * sampled;
|
||||
|
||||
// float alpha = texture( sampler2D(glyph_bitmap, glyph_bitmap_sampler), uv).r;
|
||||
// color = vec4(glyph_color, alpha);
|
||||
}
|
||||
@end
|
||||
|
||||
@program learngl_font_glyph glyph_vs glyph_fs
|
@ -1,248 +0,0 @@
|
||||
/*
|
||||
#version:1# (machine generated, don't edit!)
|
||||
|
||||
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
|
||||
|
||||
Cmdline:
|
||||
sokol-shdc --input C:\projects\SectrPrototype\code\sectr\shaders\learngl_font_glyph_sokol.glsl --output C:\projects\SectrPrototype\code\sectr\shaders\learngl_font_glyph_sokol.odin --slang hlsl5 --format=sokol_odin
|
||||
|
||||
Overview:
|
||||
=========
|
||||
Shader program: 'learngl_font_glyph':
|
||||
Get shader desc: learngl_font_glyph_shader_desc(sg.query_backend())
|
||||
Vertex shader: glyph_vs
|
||||
Attributes:
|
||||
ATTR_glyph_vs_vertex => 0
|
||||
Uniform block 'vs_params':
|
||||
Odin struct: Vs_Params
|
||||
Bind slot: SLOT_vs_params => 0
|
||||
Fragment shader: glyph_fs
|
||||
Uniform block 'fs_params':
|
||||
Odin struct: Fs_Params
|
||||
Bind slot: SLOT_fs_params => 0
|
||||
Image 'glyph_bitmap':
|
||||
Image type: ._2D
|
||||
Sample type: .FLOAT
|
||||
Multisampled: false
|
||||
Bind slot: SLOT_glyph_bitmap => 0
|
||||
Sampler 'glyph_bitmap_sampler':
|
||||
Type: .FILTERING
|
||||
Bind slot: SLOT_glyph_bitmap_sampler => 0
|
||||
Image Sampler Pair 'glyph_bitmap_glyph_bitmap_sampler':
|
||||
Image: glyph_bitmap
|
||||
Sampler: glyph_bitmap_sampler
|
||||
*/
|
||||
package sectr
|
||||
import sg "thirdparty:sokol/gfx"
|
||||
|
||||
ATTR_glyph_vs_vertex :: 0
|
||||
SLOT_vs_params :: 0
|
||||
SLOT_fs_params :: 0
|
||||
SLOT_glyph_bitmap :: 0
|
||||
SLOT_glyph_bitmap_sampler :: 0
|
||||
Vs_Params :: struct #align(16) {
|
||||
using _: struct #packed {
|
||||
projection: [16]f32,
|
||||
},
|
||||
}
|
||||
Fs_Params :: struct #align(16) {
|
||||
using _: struct #packed {
|
||||
glyph_color: [3]f32,
|
||||
_: [4]u8,
|
||||
},
|
||||
}
|
||||
/*
|
||||
cbuffer vs_params : register(b0)
|
||||
{
|
||||
row_major float4x4 _19_projection : packoffset(c0);
|
||||
};
|
||||
|
||||
|
||||
static float4 gl_Position;
|
||||
static float4 vertex;
|
||||
static float2 uv;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float4 vertex : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = mul(float4(vertex.xy, 0.0f, 1.0f), _19_projection);
|
||||
uv = vertex.zw;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vertex = stage_input.vertex;
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.uv = uv;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
glyph_vs_source_hlsl5 := [677]u8 {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x39,0x5f,0x70,0x72,
|
||||
0x6f,0x6a,0x65,0x63,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,
|
||||
0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,
|
||||
0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,
|
||||
0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x65,0x72,0x74,0x65,0x78,0x3b,
|
||||
0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,
|
||||
0x76,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,
|
||||
0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x65,0x72,0x74,0x65,0x78,
|
||||
0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,
|
||||
0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,
|
||||
0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
|
||||
0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,
|
||||
0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x34,0x28,0x76,0x65,0x72,0x74,0x65,0x78,0x2e,0x78,0x79,0x2c,0x20,0x30,0x2e,
|
||||
0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x39,0x5f,0x70,
|
||||
0x72,0x6f,0x6a,0x65,0x63,0x74,0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x75,0x76,0x20,0x3d,0x20,0x76,0x65,0x72,0x74,0x65,0x78,0x2e,0x7a,0x77,0x3b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,
|
||||
0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,
|
||||
0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
|
||||
0x6e,0x70,0x75,0x74,0x2e,0x76,0x65,0x72,0x74,0x65,0x78,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
|
||||
0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,
|
||||
0x75,0x76,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
|
||||
0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,
|
||||
0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
}
|
||||
/*
|
||||
cbuffer fs_params : register(b0)
|
||||
{
|
||||
float3 _35_glyph_color : packoffset(c0);
|
||||
};
|
||||
|
||||
Texture2D<float4> glyph_bitmap : register(t0);
|
||||
SamplerState glyph_bitmap_sampler : register(s0);
|
||||
|
||||
static float2 uv;
|
||||
static float4 color;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 color : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
color = float4(_35_glyph_color, 1.0f) * float4(1.0f, 1.0f, 1.0f, glyph_bitmap.Sample(glyph_bitmap_sampler, uv).x);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
uv = stage_input.uv;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.color = color;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
glyph_fs_source_hlsl5 := [680]u8 {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x66,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,
|
||||
0x35,0x5f,0x67,0x6c,0x79,0x70,0x68,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,
|
||||
0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,
|
||||
0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x3e,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,
|
||||
0x61,0x70,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,
|
||||
0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,
|
||||
0x67,0x6c,0x79,0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x5f,0x73,0x61,0x6d,
|
||||
0x70,0x6c,0x65,0x72,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,
|
||||
0x73,0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x32,0x20,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,
|
||||
0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,
|
||||
0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x32,0x20,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,
|
||||
0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,
|
||||
0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,
|
||||
0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,
|
||||
0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,
|
||||
0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x33,0x35,
|
||||
0x5f,0x67,0x6c,0x79,0x70,0x68,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x31,0x2e,
|
||||
0x30,0x66,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x31,0x2e,0x30,
|
||||
0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x67,
|
||||
0x6c,0x79,0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x2e,0x53,0x61,0x6d,0x70,
|
||||
0x6c,0x65,0x28,0x67,0x6c,0x79,0x70,0x68,0x5f,0x62,0x69,0x74,0x6d,0x61,0x70,0x5f,
|
||||
0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x2c,0x20,0x75,0x76,0x29,0x2e,0x78,0x29,0x3b,
|
||||
0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,
|
||||
0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,
|
||||
0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,
|
||||
0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x75,0x76,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,
|
||||
0x74,0x2e,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,
|
||||
0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,
|
||||
0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,
|
||||
0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,
|
||||
0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
}
|
||||
learngl_font_glyph_shader_desc :: proc (backend: sg.Backend) -> sg.Shader_Desc {
|
||||
desc: sg.Shader_Desc
|
||||
desc.label = "learngl_font_glyph_shader"
|
||||
#partial switch backend {
|
||||
case .D3D11:
|
||||
desc.attrs[0].sem_name = "TEXCOORD"
|
||||
desc.attrs[0].sem_index = 0
|
||||
desc.vs.source = transmute(cstring)&glyph_vs_source_hlsl5
|
||||
desc.vs.d3d11_target = "vs_5_0"
|
||||
desc.vs.entry = "main"
|
||||
desc.vs.uniform_blocks[0].size = 64
|
||||
desc.vs.uniform_blocks[0].layout = .STD140
|
||||
desc.fs.source = transmute(cstring)&glyph_fs_source_hlsl5
|
||||
desc.fs.d3d11_target = "ps_5_0"
|
||||
desc.fs.entry = "main"
|
||||
desc.fs.uniform_blocks[0].size = 16
|
||||
desc.fs.uniform_blocks[0].layout = .STD140
|
||||
desc.fs.images[0].used = true
|
||||
desc.fs.images[0].multisampled = false
|
||||
desc.fs.images[0].image_type = ._2D
|
||||
desc.fs.images[0].sample_type = .FLOAT
|
||||
desc.fs.samplers[0].used = true
|
||||
desc.fs.samplers[0].sampler_type = .FILTERING
|
||||
desc.fs.image_sampler_pairs[0].used = true
|
||||
desc.fs.image_sampler_pairs[0].image_slot = 0
|
||||
desc.fs.image_sampler_pairs[0].sampler_slot = 0
|
||||
}
|
||||
return desc
|
||||
}
|
@ -138,13 +138,18 @@ push-location $path_root
|
||||
|
||||
write-host "`nBuilding Sectr Prototype`n"
|
||||
|
||||
$module_host = join-path $path_code 'host'
|
||||
$module_sectr = join-path $path_code 'sectr'
|
||||
$package_grime = join-path $path_code 'grime'
|
||||
$module_host = join-path $path_code 'host'
|
||||
$module_sectr = join-path $path_code 'sectr'
|
||||
if ($force){
|
||||
mark-ModuleDirty $package_grime
|
||||
mark-ModuleDirty $module_sectr
|
||||
mark-ModuleDirty $module_host
|
||||
}
|
||||
|
||||
$pkg_grime_dirty = check-ModuleForChanges $package_grime
|
||||
|
||||
$pkg_collection_codebase = 'codebase=' + $path_code
|
||||
$pkg_collection_thirdparty = 'thirdparty=' + $path_thirdparty
|
||||
|
||||
$host_process_active = Get-Process | Where-Object {$_.Name -like 'sectr_host*'}
|
||||
@ -160,7 +165,7 @@ push-location $path_root
|
||||
|
||||
function build-sectr
|
||||
{
|
||||
$should_build = check-ModuleForChanges $module_sectr
|
||||
$should_build = (check-ModuleForChanges $module_sectr) -or $pkg_grime_dirty
|
||||
if ( -not( $should_build)) {
|
||||
write-host 'Skipping sectr build, module up to date'
|
||||
return $module_unchanged
|
||||
@ -186,6 +191,7 @@ push-location $path_root
|
||||
$build_args += './sectr'
|
||||
$build_args += $flag_build_mode_dll
|
||||
$build_args += $flag_output_path + $module_dll
|
||||
$build_args += ($flag_collection + $pkg_collection_codebase)
|
||||
$build_args += ($flag_collection + $pkg_collection_thirdparty)
|
||||
# $build_args += $flag_micro_architecture_native
|
||||
# $build_args += $flag_use_separate_modules
|
||||
@ -261,6 +267,7 @@ push-location $path_root
|
||||
$build_args += $command_build
|
||||
$build_args += './host'
|
||||
$build_args += $flag_output_path + $executable
|
||||
$build_args += ($flag_collection + $pkg_collection_codebase)
|
||||
$build_args += ($flag_collection + $pkg_collection_thirdparty)
|
||||
# $build_args += $flag_micro_architecture_native
|
||||
# $build_args += $flag_use_separate_modules
|
||||
|
@ -13,8 +13,8 @@ $path_shaders = join-path $path_sectr 'shaders'
|
||||
|
||||
$sokol_shdc = join-path $path_sokol_tools 'bin/win32/sokol-shdc.exe'
|
||||
|
||||
$shadersrc_learngl_font_glyph = join-path $path_shaders 'learngl_font_glyph_sokol.glsl'
|
||||
$shaderout_learngl_font_glyph = join-path $path_shaders 'learngl_font_glyph_sokol.odin'
|
||||
$shadersrc_learngl_font_glyph = join-path $path_shaders 'font_glyph.shdc.glsl'
|
||||
$shaderout_learngl_font_glyph = join-path $path_shaders 'font_glyph.odin'
|
||||
|
||||
$flag_input = '--input '
|
||||
$flag_output = '--output '
|
||||
|
@ -90,7 +90,7 @@ Update-GitRepo -path $path_sokol -url $url_sokol -build_command '.\build_win
|
||||
|
||||
function clone-gitrepo { param( [string] $path, [string] $url )
|
||||
if (test-path $path) {
|
||||
git -C $path pull
|
||||
# git -C $path pull
|
||||
}
|
||||
else {
|
||||
Write-Host "Cloning $url ..."
|
||||
@ -98,7 +98,6 @@ function clone-gitrepo { param( [string] $path, [string] $url )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
clone-gitrepo $path_backtrace $url_backtrace_repo
|
||||
clone-gitrepo $path_freetype $url_freetype
|
||||
clone-gitrepo $path_ini_parser $url_ini_parser
|
||||
|
Loading…
Reference in New Issue
Block a user