Got text rendering to work with sokol_gfx (learngl text rendering article #1)
Need to todo the altas article next then the optimizing vod
This commit is contained in:
parent
c681370d8b
commit
936c0100ba
@ -218,6 +218,8 @@ State :: struct {
|
||||
app_window : AppWindow,
|
||||
screen_ui : UI_ScreenState,
|
||||
|
||||
render_data : RenderState,
|
||||
|
||||
monitor_id : i32,
|
||||
monitor_refresh_hz : i32,
|
||||
|
||||
|
@ -231,7 +231,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
load_action = .CLEAR,
|
||||
clear_value = { 1, 0, 0, 1 }
|
||||
}
|
||||
vertices := [?]f32 {
|
||||
triangle_vertices := [?]f32 {
|
||||
// positions // colors
|
||||
0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
|
||||
0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
||||
@ -244,8 +244,8 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
using debug.gfx_tri_demo_state
|
||||
bindings.vertex_buffers[0] = sokol_gfx.make_buffer( sokol_gfx.Buffer_Desc {
|
||||
data = {
|
||||
ptr = & vertices,
|
||||
size = size_of(vertices)
|
||||
ptr = & triangle_vertices,
|
||||
size = size_of(triangle_vertices)
|
||||
}
|
||||
})
|
||||
pipeline = sokol_gfx.make_pipeline( sokol_gfx.Pipeline_Desc {
|
||||
@ -261,11 +261,16 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
load_action = .CLEAR,
|
||||
clear_value = { 0, 0, 0, 1 }
|
||||
}
|
||||
|
||||
render_data.pass_actions.bg_clear_black.colors[0] = sokol_gfx.Color_Attachment_Action {
|
||||
load_action = .CLEAR,
|
||||
clear_value = { 0, 0, 0, 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Basic Font Setup
|
||||
if false
|
||||
if true
|
||||
{
|
||||
font_provider_startup()
|
||||
// path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
|
||||
@ -281,7 +286,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
}
|
||||
|
||||
// Setup the screen ui state
|
||||
if true
|
||||
if false
|
||||
{
|
||||
ui_startup( & screen_ui.base, cache_allocator = persistent_slab_allocator() )
|
||||
ui_floating_startup( & screen_ui.floating, persistent_slab_allocator(), 1 * Kilobyte, 1 * Kilobyte, "screen ui floating manager" )
|
||||
@ -296,7 +301,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
|
||||
// Demo project setup
|
||||
// TODO(Ed): This will eventually have to occur when the user either creates or loads a workspace. I don't know
|
||||
if true
|
||||
if false
|
||||
{
|
||||
using project
|
||||
path = str_intern("./")
|
||||
@ -416,7 +421,7 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
|
||||
|
||||
slab_reload( persistent_slab, persistent_allocator() )
|
||||
|
||||
// hmap_chained_reload( font_provider_data.font_cache, persistent_allocator())
|
||||
hmap_chained_reload( font_provider_data.font_cache, persistent_allocator())
|
||||
|
||||
slab_reload( string_cache.slab, persistent_allocator() )
|
||||
hamp_zpl_reload( & string_cache.table, persistent_slab_allocator())
|
||||
@ -424,7 +429,7 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
|
||||
slab_reload( frame_slab, frame_allocator())
|
||||
slab_reload( transient_slab, transient_allocator())
|
||||
|
||||
ui_reload( & get_state().project.workspace.ui, cache_allocator = persistent_slab_allocator() )
|
||||
// ui_reload( & get_state().project.workspace.ui, cache_allocator = persistent_slab_allocator() )
|
||||
|
||||
log("Module reloaded")
|
||||
}
|
||||
@ -483,10 +488,23 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
|
||||
debug.draw_UI_padding_bounds = false
|
||||
debug.draw_ui_content_bounds = false
|
||||
|
||||
config.engine_refresh_hz = 10000
|
||||
|
||||
// config.color_theme = App_Thm_Light
|
||||
// config.color_theme = App_Thm_Dusk
|
||||
config.color_theme = App_Thm_Dark
|
||||
|
||||
sokol_width := sokol_app.widthf()
|
||||
sokol_height := sokol_app.heightf()
|
||||
|
||||
window := & state.app_window
|
||||
// if int(window.extent.x) != int(sokol_width) || int(window.extent.y) != int(sokol_height) {
|
||||
window.resized = true
|
||||
window.extent.x = sokol_width * 0.5
|
||||
window.extent.y = sokol_height * 0.5
|
||||
// log("sokol_app: Event-based frame callback triggered (detected a resize")
|
||||
// }
|
||||
|
||||
should_close |= update( host_delta_time_ms )
|
||||
render()
|
||||
|
||||
|
@ -25,12 +25,12 @@ sokol_app_frame_callback :: proc "c" () {
|
||||
sokol_height := sokol_app.heightf()
|
||||
|
||||
window := & state.app_window
|
||||
if int(window.extent.x) != int(sokol_width) || int(window.extent.y) != int(sokol_height) {
|
||||
// if int(window.extent.x) != int(sokol_width) || int(window.extent.y) != int(sokol_height) {
|
||||
window.resized = true
|
||||
window.extent.x = sokol_width * 0.5
|
||||
window.extent.y = sokol_height * 0.5
|
||||
log("sokol_app: Event-based frame callback triggered (detected a resize")
|
||||
}
|
||||
// log("sokol_app: Event-based frame callback triggered (detected a resize")
|
||||
// }
|
||||
|
||||
// sokol_app is the only good reference for a frame-time at this point.
|
||||
sokol_delta_ms := sokol_app.frame_delta()
|
||||
|
@ -3,15 +3,39 @@ package sectr
|
||||
import sokol_gfx "thirdparty:sokol/gfx"
|
||||
import sokol_glue "thirdparty:sokol/glue"
|
||||
|
||||
PassActions :: struct {
|
||||
bg_clear_black : sokol_gfx.Pass_Action,
|
||||
|
||||
}
|
||||
|
||||
RenderState :: struct {
|
||||
pass_actions : PassActions,
|
||||
}
|
||||
|
||||
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)
|
||||
result[1][1] = 2.0 / (top - bottom)
|
||||
result[2][2] = -2.0 / (far - near)
|
||||
result[3][0] = -(right + left) / (right - left)
|
||||
result[3][1] = -(top + bottom) / (top - bottom)
|
||||
result[3][2] = -(far + near) / (far - near)
|
||||
result[3][3] = 1.0
|
||||
return result
|
||||
}
|
||||
|
||||
render :: proc()
|
||||
{
|
||||
state := get_state(); using state
|
||||
using render_data
|
||||
|
||||
do_nothing : bool
|
||||
do_nothing = false
|
||||
|
||||
// apply_bindings :: sokol_gfx.apply_bindings
|
||||
|
||||
// Clear Demo
|
||||
if true
|
||||
if false
|
||||
{
|
||||
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
|
||||
@ -38,11 +62,93 @@ render :: proc()
|
||||
sokol_gfx.commit()
|
||||
}
|
||||
|
||||
// learnopengl.com/In-Practice/Text-Rendering
|
||||
if true
|
||||
{
|
||||
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() })
|
||||
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) })
|
||||
|
||||
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
|
||||
next := 0
|
||||
for codepoint, byte_offset in text_test_str
|
||||
{
|
||||
using def
|
||||
glyph := & glyphs[ int(codepoint) ]
|
||||
|
||||
if glyph.size.x == 0 do continue
|
||||
// logf("Drawing glyph: %v", codepoint)
|
||||
|
||||
bearing : Vec2 = { f32(glyph.bearing.x), f32(glyph.bearing.y) }
|
||||
size : Vec2 = { f32(glyph.size.x), f32(glyph.size.y) }
|
||||
|
||||
pos := vec2(
|
||||
x + bearing.x * scale,
|
||||
y - (size.y - bearing.y) * scale
|
||||
)
|
||||
|
||||
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 },
|
||||
|
||||
{ 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 }
|
||||
}
|
||||
|
||||
color : [3]f32 = { 0 = 255, 1 = 255, 2 = 255 }
|
||||
fs_uniform := Fs_Params {
|
||||
glyph_color = color
|
||||
}
|
||||
|
||||
vbuf_offset := sokol_gfx.append_buffer( gfx_vbuffer, { & vertices[0][0], size_of(vertices) })
|
||||
// vbuf_offset : i32 = 0
|
||||
|
||||
// bindings := glyph.bindings
|
||||
bindings := sokol_gfx.Bindings {
|
||||
vertex_buffers = { 0 = gfx_vbuffer, },
|
||||
vertex_buffer_offsets = { 0 = vbuf_offset },
|
||||
fs = {
|
||||
images = { 0 = glyph.texture },
|
||||
samplers = { 0 = 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 )
|
||||
next += 6
|
||||
|
||||
x += f32(glyph.advance >> 6) * scale
|
||||
}
|
||||
|
||||
sokol_gfx.end_pass()
|
||||
sokol_gfx.commit()
|
||||
}
|
||||
|
||||
// Batching Enqueue Boxes
|
||||
// Mixed with the batching enqueue for text
|
||||
|
||||
|
||||
//Begin
|
||||
// Flush boxs
|
||||
// flush text
|
||||
|
@ -198,9 +198,10 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
|
||||
// TODO(Ed): We need input buffer so that we can consume input actions based on the UI with priority
|
||||
|
||||
ui_screen_tick()
|
||||
// ui_screen_tick()
|
||||
|
||||
//region WorkspaceImgui Tick
|
||||
if false
|
||||
{
|
||||
profile("Workspace Imgui")
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
/*
|
||||
Yet another port of fontstash.
|
||||
|
||||
I decided t use this instead of the odin port as it already deviated from the original impl.
|
||||
I decided to use this instead of the odin port as it deviated from the original, making it difficult to sift through.
|
||||
So The code was small enough that I mine as well learn it by porting for my use case.
|
||||
|
||||
Original copyright for fonstash.h:
|
||||
TODO(Ed): Add docs here and throughout
|
||||
TODO(Ed): This is unfinished...
|
||||
|
||||
Original author's copyright for fonstash.h:
|
||||
------------------------------------------------------------------------------
|
||||
Copyright (c) 2009-2013 Mikko Mononen memon@inside.org
|
||||
|
||||
@ -27,6 +30,8 @@ package sectr
|
||||
|
||||
import stbtt "vendor:stb/truetype"
|
||||
|
||||
FStash_Use_stb_truetype :: #config(FSTASH_USE_STB_TRUE_TYPE, true)
|
||||
|
||||
Range2_i16 :: struct #raw_union {
|
||||
using pts : Vec2_i16,
|
||||
using xy : struct {
|
||||
@ -36,26 +41,26 @@ Range2_i16 :: struct #raw_union {
|
||||
|
||||
Vec2_i16 :: [2]i16
|
||||
|
||||
FSTASH_Invalid :: -1
|
||||
FStash_Invalid :: -1
|
||||
|
||||
FSTASH_Hash_Lut_Size :: 256
|
||||
FSTASH_Max_Fallbacks :: 20
|
||||
FSTASH_Max_States :: 20
|
||||
FSTASH_Vertex_Count :: 1024
|
||||
FSTASH_Init_Atlas_Nodes :: 256
|
||||
FStash_Hash_Lut_Size :: 256
|
||||
FStash_Max_Fallbacks :: 20
|
||||
FStash_Max_States :: 20
|
||||
FStash_Vertex_Count :: 1024
|
||||
FStash_Init_Atlas_Nodes :: 256
|
||||
|
||||
FSTASH_FontLuts :: [FSTASH_Hash_Lut_Size]i32
|
||||
FSTASH_FontFallbacks :: [FSTASH_Max_Fallbacks]i32
|
||||
FStash_FontLuts :: [FStash_Hash_Lut_Size]i32
|
||||
FStash_FontFallbacks :: [FStash_Max_Fallbacks]i32
|
||||
|
||||
FSTASH_HandleErrorProc :: #type proc( uptr : rawptr, error, val : i32 )
|
||||
FStash_HandleErrorProc :: #type proc( uptr : rawptr, error, val : i32 )
|
||||
|
||||
FSTASH_RenderCreateProc :: #type proc( uptr : rawptr, width, height : i32 )
|
||||
FSTASH_RenderResizeProc :: #type proc( uptr : rawptr, width, height : i32 )
|
||||
FSTASH_RenderUpdateProc :: #type proc( uptr : rawptr, rect : ^i32, data : ^u8 )
|
||||
FSTASH_RenderDrawProc :: #type proc( uptr : rawptr, verts : ^f32, tcoords : ^f32, colors : ^i32, num_verts : i32 )
|
||||
FSTASH_RenderDelete :: #type proc( uptr : rawptr )
|
||||
FStash_RenderCreateProc :: #type proc( uptr : rawptr, width, height : i32 )
|
||||
FStash_RenderResizeProc :: #type proc( uptr : rawptr, width, height : i32 )
|
||||
FStash_RenderUpdateProc :: #type proc( uptr : rawptr, rect : ^i32, data : ^u8 )
|
||||
FStash_RenderDrawProc :: #type proc( uptr : rawptr, verts : ^f32, tcoords : ^f32, colors : ^i32, num_verts : i32 )
|
||||
FStash_RenderDelete :: #type proc( uptr : rawptr )
|
||||
|
||||
FSTASH_AlignFlag :: enum u32 {
|
||||
FStash_AlignFlag :: enum u32 {
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
@ -64,51 +69,42 @@ FSTASH_AlignFlag :: enum u32 {
|
||||
Bottom,
|
||||
Baseline,
|
||||
}
|
||||
FSTASH_AlignFlags :: bit_set[ FSTASH_AlignFlag; u32 ]
|
||||
FStash_AlignFlags :: bit_set[ FStash_AlignFlag; u32 ]
|
||||
|
||||
// FONSflags
|
||||
FSTASH_QuadLocation :: enum u32 {
|
||||
FStash_QuadLocation :: enum u32 {
|
||||
Top_Left = 1,
|
||||
Bottom_Left = 2,
|
||||
}
|
||||
|
||||
FSTASH_Atlas :: struct {
|
||||
FStash_Atlas :: struct {
|
||||
dud : i32,
|
||||
}
|
||||
|
||||
FSTASH_AtlasNode :: struct {
|
||||
FStash_AtlasNode :: struct {
|
||||
x, y, width : i16,
|
||||
}
|
||||
|
||||
FSTASH_ErrorCode :: enum u32 {
|
||||
FStash_ErrorCode :: enum u32 {
|
||||
Atlas_Full,
|
||||
Scratch_Full,
|
||||
States_Overflow,
|
||||
States_Underflow,
|
||||
}
|
||||
|
||||
FSTASH_Quad :: struct {
|
||||
FStash_Quad :: struct {
|
||||
x0, y0, s0, t0 : f32,
|
||||
x1, y1, s1, t1 : f32,
|
||||
}
|
||||
|
||||
FSTASH_Font :: struct {
|
||||
info : stbtt.fontinfo,
|
||||
name : string,
|
||||
data : []byte,
|
||||
free_data : bool,
|
||||
|
||||
ascender : f32,
|
||||
descender : f32,
|
||||
line_height : f32,
|
||||
|
||||
glyphs : Array(FSTASH_Glyph),
|
||||
lut : FSTASH_FontLuts,
|
||||
fallbacks : FSTASH_FontFallbacks,
|
||||
num_fallbacks : i32,
|
||||
when FStash_Use_stb_truetype
|
||||
{
|
||||
FStash_FontParserData :: struct {
|
||||
stbtt_info : stbtt.fontinfo,
|
||||
}
|
||||
}
|
||||
|
||||
FSTASH_Glyph :: struct {
|
||||
FStash_Glyph :: struct {
|
||||
codepoint : rune,
|
||||
index, next : i32,
|
||||
size, blur : i16,
|
||||
@ -117,17 +113,33 @@ FSTASH_Glyph :: struct {
|
||||
offset : Vec2_i16,
|
||||
}
|
||||
|
||||
FSTASH_Params :: struct {
|
||||
width, height : i32,
|
||||
quad_location : FSTASH_QuadLocation, // (flags)
|
||||
render_create : FSTASH_RenderCreateProc,
|
||||
render_resize : FSTASH_RenderResizeProc,
|
||||
render_update : FSTASH_RenderUpdateProc,
|
||||
render_draw : FSTASH_RenderDrawProc,
|
||||
render_delete : FSTASH_RenderDelete,
|
||||
FStash_Font :: struct {
|
||||
parser_data : FStash_FontParserData,
|
||||
name : string,
|
||||
data : []byte,
|
||||
free_data : bool,
|
||||
|
||||
ascender : f32,
|
||||
descender : f32,
|
||||
line_height : f32,
|
||||
|
||||
glyphs : Array(FStash_Glyph),
|
||||
lut : FStash_FontLuts,
|
||||
fallbacks : FStash_FontFallbacks,
|
||||
num_fallbacks : i32,
|
||||
}
|
||||
|
||||
FSTASH_State :: struct {
|
||||
FStash_Params :: struct {
|
||||
width, height : i32,
|
||||
quad_location : FStash_QuadLocation, // (flags)
|
||||
render_create : FStash_RenderCreateProc,
|
||||
render_resize : FStash_RenderResizeProc,
|
||||
render_update : FStash_RenderUpdateProc,
|
||||
render_draw : FStash_RenderDrawProc,
|
||||
render_delete : FStash_RenderDelete,
|
||||
}
|
||||
|
||||
FStash_State :: struct {
|
||||
font : i32,
|
||||
alignment : i32,
|
||||
size : f32,
|
||||
@ -136,14 +148,14 @@ FSTASH_State :: struct {
|
||||
spacing : f32,
|
||||
}
|
||||
|
||||
FSTASH_TextIter :: struct {
|
||||
FStash_TextIter :: struct {
|
||||
x, y : f32,
|
||||
next_x, next_y : f32,
|
||||
scale, spacing : f32,
|
||||
|
||||
isize, iblur : i16,
|
||||
|
||||
font : ^FSTASH_Font,
|
||||
font : ^FStash_Font,
|
||||
prev_glyph_id : i32,
|
||||
|
||||
codepoint : rune,
|
||||
@ -154,28 +166,73 @@ FSTASH_TextIter :: struct {
|
||||
end : string,
|
||||
}
|
||||
|
||||
FSTASH_Context :: struct {
|
||||
params : FSTASH_Params,
|
||||
FStash_Context :: struct {
|
||||
params : FStash_Params,
|
||||
|
||||
// Atlas
|
||||
atlas : Array(FSTASH_AtlasNode),
|
||||
atlas : Array(FStash_AtlasNode),
|
||||
texture_data : []byte,
|
||||
width, height : i32,
|
||||
// ----
|
||||
|
||||
normalized_size : Vec2,
|
||||
|
||||
verts : [FSTASH_Vertex_Count * 2]f32,
|
||||
tcoords : [FSTASH_Vertex_Count * 2]f32,
|
||||
colors : [FSTASH_Vertex_Count ]f32,
|
||||
verts : [FStash_Vertex_Count * 2]f32,
|
||||
tcoords : [FStash_Vertex_Count * 2]f32,
|
||||
colors : [FStash_Vertex_Count ]f32,
|
||||
|
||||
states : [FSTASH_Max_States]FSTASH_State,
|
||||
states : [FStash_Max_States]FStash_State,
|
||||
num_states : i32,
|
||||
|
||||
handle_error : FSTASH_HandleErrorProc,
|
||||
handle_error : FStash_HandleErrorProc,
|
||||
error_uptr : rawptr,
|
||||
}
|
||||
|
||||
when FStash_Use_stb_truetype
|
||||
{
|
||||
fstash_tt_init :: proc( ctx : ^FStash_Context ) -> i32 { return 1 }
|
||||
|
||||
fstash_tt_load_font :: proc( ctx : ^FStash_Context, parser_data : ^FStash_FontParserData, data : []byte ) -> b32
|
||||
{
|
||||
parser_data.stbtt_info.userdata = ctx
|
||||
stb_error := stbtt.InitFont( & parser_data.stbtt_info, & data[0], 0 )
|
||||
return stb_error
|
||||
}
|
||||
|
||||
fstash_tt_get_font_metrics :: proc( parser_data : ^FStash_FontParserData, ascent, descent, line_gap : ^i32 ) {
|
||||
stbtt.GetFontVMetrics( & parser_data.stbtt_info, ascent, descent, line_gap )
|
||||
}
|
||||
|
||||
fstash_tt_get_pixel_height_scale :: proc( parser_data : ^FStash_FontParserData, size : f32 ) -> f32
|
||||
{
|
||||
return stbtt.ScaleForPixelHeight( & parser_data.stbtt_info, size )
|
||||
}
|
||||
|
||||
fstash_tt_get_glyph_index :: proc( parser_data : ^FStash_FontParserData, codepoint : rune ) -> i32
|
||||
{
|
||||
return stbtt.FindGlyphIndex( & parser_data.stbtt_info, codepoint )
|
||||
}
|
||||
|
||||
fstash_tt_build_glyph_bitmap :: proc( parser_data : ^FStash_FontParserData, glyph_index : i32,
|
||||
size, scale : f32, advance, left_side_bearing, x0, y0, x1, y1 : ^i32 ) -> i32
|
||||
{
|
||||
stbtt.GetGlyphHMetrics( & parser_data.stbtt_info, glyph_index, advance, left_side_bearing )
|
||||
stbtt.GetGlyphBitmapBox( & parser_data.stbtt_info, glyph_index, scale, scale, x0, y0, x1, y1 )
|
||||
return 1
|
||||
}
|
||||
|
||||
fstash_tt_render_glyph_bitmap :: proc( parser_data : ^FStash_FontParserData, output : [^]byte,
|
||||
out_width, out_height, out_stride : i32, scale_x, scale_y : f32, glyph_index : i32 )
|
||||
{
|
||||
stbtt.MakeGlyphBitmap( & parser_data.stbtt_info, output, out_width, out_height, out_stride, scale_x, scale_y, glyph_index )
|
||||
}
|
||||
|
||||
fstash_tt_get_glyph_kern_advance :: proc( parser_data : ^FStash_FontParserData, glyph_1, glyph_2 : i32 ) -> i32
|
||||
{
|
||||
return stbtt.GetGlyphKernAdvance( & parser_data.stbtt_info, glyph_1, glyph_2 )
|
||||
}
|
||||
} // when FStash_Use_stb_true-type
|
||||
|
||||
fstash_decode_utf8 :: proc( state : ^rune, codepoint : ^rune, to_decode : byte ) -> bool
|
||||
{
|
||||
UTF8_Accept :: 0
|
||||
@ -214,12 +271,12 @@ fstash_decode_utf8 :: proc( state : ^rune, codepoint : ^rune, to_decode : byte )
|
||||
return (state^) == UTF8_Accept
|
||||
}
|
||||
|
||||
fstash_atlas_delete :: proc ( ctx : ^FSTASH_Context ) {
|
||||
fstash_atlas_delete :: proc ( ctx : ^FStash_Context ) {
|
||||
using ctx
|
||||
array_free( ctx.atlas )
|
||||
}
|
||||
|
||||
fstash_atlas_expand :: proc( ctx : ^FSTASH_Context, width, height : i32 )
|
||||
fstash_atlas_expand :: proc( ctx : ^FStash_Context, width, height : i32 )
|
||||
{
|
||||
if width > ctx.width {
|
||||
fstash_atlas_insert( ctx, ctx.atlas.num, ctx.width, 0, width - ctx.width )
|
||||
@ -229,39 +286,39 @@ fstash_atlas_expand :: proc( ctx : ^FSTASH_Context, width, height : i32 )
|
||||
ctx.height = height
|
||||
}
|
||||
|
||||
fstash_atlas_init :: proc( ctx : ^FSTASH_Context, width, height : i32, num_nodes : u32 = FSTASH_Init_Atlas_Nodes )
|
||||
fstash_atlas_init :: proc( ctx : ^FStash_Context, width, height : i32, num_nodes : u32 = FStash_Init_Atlas_Nodes )
|
||||
{
|
||||
error : AllocatorError
|
||||
ctx.atlas, error = array_init_reserve( FSTASH_AtlasNode, context.allocator, u64(num_nodes), dbg_name = "font atlas" )
|
||||
ctx.atlas, error = array_init_reserve( FStash_AtlasNode, context.allocator, u64(num_nodes), dbg_name = "font atlas" )
|
||||
ensure(error != AllocatorError.None, "Failed to allocate font atlas")
|
||||
|
||||
ctx.width = width
|
||||
ctx.height = height
|
||||
|
||||
array_append( & ctx.atlas, FSTASH_AtlasNode{ width = i16(width)} )
|
||||
array_append( & ctx.atlas, FStash_AtlasNode{ width = i16(width)} )
|
||||
}
|
||||
|
||||
fstash_atlas_insert :: proc( ctx : ^FSTASH_Context, id : u64, x, y, width : i32 ) -> (error : AllocatorError)
|
||||
fstash_atlas_insert :: proc( ctx : ^FStash_Context, id : u64, x, y, width : i32 ) -> (error : AllocatorError)
|
||||
{
|
||||
error = array_append_at( & ctx.atlas, FSTASH_AtlasNode{ i16(x), i16(y), i16(width) }, id )
|
||||
error = array_append_at( & ctx.atlas, FStash_AtlasNode{ i16(x), i16(y), i16(width) }, id )
|
||||
return
|
||||
}
|
||||
|
||||
fstash_atlas_remove :: proc( ctx : ^FSTASH_Context, id : u64 )
|
||||
fstash_atlas_remove :: proc( ctx : ^FStash_Context, id : u64 )
|
||||
{
|
||||
array_remove_at( ctx.atlas, id )
|
||||
}
|
||||
|
||||
fstash_atlas_reset :: proc( ctx : ^FSTASH_Context, width, height : i32 )
|
||||
fstash_atlas_reset :: proc( ctx : ^FStash_Context, width, height : i32 )
|
||||
{
|
||||
ctx.width = width
|
||||
ctx.height = height
|
||||
array_clear( ctx.atlas )
|
||||
|
||||
array_append( & ctx.atlas, FSTASH_AtlasNode{ width = i16(width)} )
|
||||
array_append( & ctx.atlas, FStash_AtlasNode{ width = i16(width)} )
|
||||
}
|
||||
|
||||
fstash_atlas_add_skyline_level :: proc (ctx : ^FSTASH_Context, id : u64, x, y, width, height : i32 ) -> (error : AllocatorError)
|
||||
fstash_atlas_add_skyline_level :: proc (ctx : ^FStash_Context, id : u64, x, y, width, height : i32 ) -> (error : AllocatorError)
|
||||
{
|
||||
insert :: fstash_atlas_insert
|
||||
remove :: fstash_atlas_remove
|
||||
@ -289,7 +346,6 @@ fstash_atlas_add_skyline_level :: proc (ctx : ^FSTASH_Context, id : u64, x, y, w
|
||||
sky_id -= 1
|
||||
}
|
||||
|
||||
|
||||
// Merge same height skyline segments that are next to each other.
|
||||
for sky_id := id; sky_id < ctx.atlas.num - 1;
|
||||
{
|
||||
@ -307,7 +363,7 @@ fstash_atlas_add_skyline_level :: proc (ctx : ^FSTASH_Context, id : u64, x, y, w
|
||||
return
|
||||
}
|
||||
|
||||
fstash_atlas_rect_fits :: proc( ctx : ^FSTASH_Context, location, width, height : i32 ) -> (max_height : i32)
|
||||
fstash_atlas_rect_fits :: proc( ctx : ^FStash_Context, location, width, height : i32 ) -> (max_height : i32)
|
||||
{
|
||||
// Checks if there is enough space at the location of skyline span 'i',
|
||||
// and return the max height of all skyline spans under that at that location,
|
||||
@ -347,7 +403,7 @@ fstash_atlas_rect_fits :: proc( ctx : ^FSTASH_Context, location, width, height :
|
||||
return
|
||||
}
|
||||
|
||||
fstash_atlas_add_rect :: proc( ctx : ^FSTASH_Context, )
|
||||
fstash_atlas_add_rect :: proc( ctx : ^FStash_Context, )
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
package sectr
|
||||
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
import "core:unicode"
|
||||
import sokol_gfx "thirdparty:sokol/gfx"
|
||||
import "thirdparty:freetype"
|
||||
|
||||
Font_Provider_Use_Freetype :: true
|
||||
|
||||
Font_Largest_Px_Size :: 32
|
||||
|
||||
@ -29,16 +35,41 @@ FontTag :: struct {
|
||||
point_size : f32
|
||||
}
|
||||
|
||||
FontDef :: struct {
|
||||
path_file : string,
|
||||
when Font_Provider_Use_Freetype
|
||||
{
|
||||
FontParserFontData :: struct {
|
||||
using face : freetype.Face,
|
||||
}
|
||||
FontParserData :: struct {
|
||||
lib : freetype.Library,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FontGlyph :: struct {
|
||||
size : Vec2i,
|
||||
bearing : Vec2i,
|
||||
advance : u32,
|
||||
texture : sokol_gfx.Image,
|
||||
bindings : sokol_gfx.Bindings,
|
||||
}
|
||||
|
||||
FontDef :: struct {
|
||||
path_file : string,
|
||||
parser_info : FontParserFontData,
|
||||
glyphs : [256]FontGlyph,
|
||||
}
|
||||
|
||||
FontProviderData :: struct {
|
||||
font_cache : HMapChainedPtr(FontDef),
|
||||
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_Provider_Ggfx_Buffer_Size :: 6 * 4 * size_of(f32) * Kilobyte * 32
|
||||
|
||||
font_provider_startup :: proc()
|
||||
{
|
||||
profile(#procedure)
|
||||
@ -50,6 +81,76 @@ font_provider_startup :: proc()
|
||||
verify( font_cache_alloc_error == AllocatorError.None, "Failed to allocate font_cache" )
|
||||
|
||||
log("font_cache created")
|
||||
|
||||
when Font_Provider_Use_Freetype
|
||||
{
|
||||
result := freetype.init_free_type( & font_provider_data.parser.lib )
|
||||
if result != freetype.Error.Ok {
|
||||
fatal( "font_provider_setup: Failed to initialize freetype" )
|
||||
}
|
||||
}
|
||||
|
||||
// Setup Graphics Pipeline
|
||||
{
|
||||
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,
|
||||
})
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
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,
|
||||
}
|
||||
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,
|
||||
}
|
||||
|
||||
gfx_pipeline = sokol_gfx.make_pipeline(
|
||||
{
|
||||
shader = learngl_font_glyph_shader,
|
||||
layout = glyph_vs_layout,
|
||||
colors ={
|
||||
0 = sokol_gfx.Color_Target_State \
|
||||
{
|
||||
// pixel_format = sokol_gfx.Pixel_Format.R8,
|
||||
// write_mask = sokol_gfx.Color_Mask.R,
|
||||
blend = sokol_gfx.Blend_State {
|
||||
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,
|
||||
}
|
||||
},
|
||||
},
|
||||
color_count = 1,
|
||||
sample_count = 1,
|
||||
})
|
||||
}
|
||||
|
||||
log("font_provider initialized")
|
||||
}
|
||||
|
||||
@ -103,10 +204,70 @@ font_load :: proc(path_file : string,
|
||||
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.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 )
|
||||
|
||||
return {}
|
||||
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
|
||||
}
|
||||
|
12
code/sectr/shaders/learngl_font_glyph_glsl330.fs
Normal file
12
code/sectr/shaders/learngl_font_glyph_glsl330.fs
Normal file
@ -0,0 +1,12 @@
|
||||
#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;
|
||||
}
|
12
code/sectr/shaders/learngl_font_glyph_glsl330.vs
Normal file
12
code/sectr/shaders/learngl_font_glyph_glsl330.vs
Normal file
@ -0,0 +1,12 @@
|
||||
#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;
|
||||
}
|
266
code/sectr/shaders/learngl_font_glyph_sokol.bkup
Normal file
266
code/sectr/shaders/learngl_font_glyph_sokol.bkup
Normal file
@ -0,0 +1,266 @@
|
||||
/*
|
||||
#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 text_coords;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float4 vertex : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float2 text_coords : TEXCOORD0;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
gl_Position = mul(float4(vertex.xy, 0.0f, 1.10000002384185791015625f), _19_projection);
|
||||
text_coords = 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.text_coords = text_coords;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
glyph_vs_source_hlsl5 := [744]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,0x74,
|
||||
0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,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,0x74,0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,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,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x32,
|
||||
0x33,0x38,0x34,0x31,0x38,0x35,0x37,0x39,0x31,0x30,0x31,0x35,0x36,0x32,0x35,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,0x74,0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,
|
||||
0x72,0x64,0x73,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,0x74,0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,0x20,0x3d,0x20,0x74,
|
||||
0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,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 text_coords;
|
||||
static float4 color;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float2 text_coords : 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, text_coords).x);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
text_coords = stage_input.text_coords;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.color = color;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
@(private)
|
||||
glyph_fs_source_hlsl5 := [725]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,0x74,0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,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,0x74,0x65,0x78,
|
||||
0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,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,0x74,0x65,0x78,0x74,0x5f,
|
||||
0x63,0x6f,0x6f,0x72,0x64,0x73,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,0x74,0x65,0x78,0x74,
|
||||
0x5f,0x63,0x6f,0x6f,0x72,0x64,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x69,0x6e,0x70,0x75,0x74,0x2e,0x74,0x65,0x78,0x74,0x5f,0x63,0x6f,0x6f,0x72,0x64,
|
||||
0x73,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
|
||||
}
|
38
code/sectr/shaders/learngl_font_glyph_sokol.glsl
Normal file
38
code/sectr/shaders/learngl_font_glyph_sokol.glsl
Normal file
@ -0,0 +1,38 @@
|
||||
@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
|
248
code/sectr/shaders/learngl_font_glyph_sokol.odin
Normal file
248
code/sectr/shaders/learngl_font_glyph_sokol.odin
Normal file
@ -0,0 +1,248 @@
|
||||
/*
|
||||
#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
|
||||
}
|
29
scripts/compile_shaders.ps1
Normal file
29
scripts/compile_shaders.ps1
Normal file
@ -0,0 +1,29 @@
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_code = join-path $path_root 'code'
|
||||
$path_build = join-path $path_root 'build'
|
||||
$path_scripts = join-path $path_root 'scripts'
|
||||
$path_thirdparty = join-path $path_root 'thirdparty'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
$path_odin = join-path $path_toolchain 'odin'
|
||||
|
||||
$path_sokol_tools = join-path $path_thirdparty 'sokol-tools'
|
||||
|
||||
$path_sectr = join-path $path_code 'sectr'
|
||||
$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'
|
||||
|
||||
$flag_input = '--input '
|
||||
$flag_output = '--output '
|
||||
$flag_target_lang = '--slang '
|
||||
$flag_format_odin = '--format=sokol_odin'
|
||||
|
||||
$cmd_args = @()
|
||||
$cmd_args += $flag_input + $shadersrc_learngl_font_glyph
|
||||
$cmd_args += $flag_output + $shaderout_learngl_font_glyph
|
||||
$cmd_args += $flag_target_lang + 'hlsl5'
|
||||
|
||||
& $sokol_shdc --input $shadersrc_learngl_font_glyph --output $shaderout_learngl_font_glyph --slang 'hlsl5' $flag_format_odin
|
@ -7,14 +7,18 @@ $path_thirdparty = join-path $path_root 'thirdparty'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
|
||||
$url_backtrace_repo = 'https://github.com/Ed94/back.git'
|
||||
$url_freetype = 'https://github.com/Ed94/odin-freetype.git'
|
||||
$url_ini_parser = 'https://github.com/laytan/odin-ini-parser.git'
|
||||
$url_odin_repo = 'https://github.com/Ed94/Odin.git'
|
||||
$url_sokol = 'https://github.com/Ed94/sokol-odin.git'
|
||||
$url_sokol_tools = 'https://github.com/floooh/sokol-tools-bin.git'
|
||||
|
||||
$path_backtrace = join-path $path_thirdparty 'backtrace'
|
||||
$path_freetype = join-path $path_thirdparty 'freetype'
|
||||
$path_ini_parser = join-path $path_thirdparty 'ini'
|
||||
$path_odin = join-path $path_toolchain 'Odin'
|
||||
$path_sokol = join-path $path_thirdparty 'sokol'
|
||||
$path_sokol_tools = join-path $path_thirdparty 'sokol-tools'
|
||||
|
||||
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
|
||||
. $incremental_checks
|
||||
@ -84,25 +88,22 @@ push-location $path_thirdparty
|
||||
Update-GitRepo -path $path_odin -url $url_odin_repo -build_command '.\scripts\build.ps1'
|
||||
Update-GitRepo -path $path_sokol -url $url_sokol -build_command '.\build_windows.ps1'
|
||||
|
||||
if (Test-Path -Path $path_ini_parser)
|
||||
{
|
||||
git -C $path_ini_parser pull
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Cloning ini repository..."
|
||||
git clone $url_ini_parser $path_ini_parser
|
||||
function clone-gitrepo { param( [string] $path, [string] $url )
|
||||
if (test-path $path) {
|
||||
git -C $path pull
|
||||
}
|
||||
else {
|
||||
Write-Host "Cloning $url ..."
|
||||
git clone $url $path
|
||||
}
|
||||
}
|
||||
|
||||
if (test-path $path_backtrace)
|
||||
{
|
||||
git -C $path_backtrace pull
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Cloning backtrace repository..."
|
||||
git clone $url_backtrace_repo $path_backtrace
|
||||
}
|
||||
|
||||
clone-gitrepo $path_backtrace $url_backtrace_repo
|
||||
clone-gitrepo $path_freetype $url_freetype
|
||||
clone-gitrepo $path_ini_parser $url_ini_parser
|
||||
clone-gitrepo $path_ini_parser $url_ini_parser
|
||||
clone-gitrepo $path_sokol_tools $url_sokol_tools
|
||||
|
||||
$path_vendor = join-path $path_odin 'vendor'
|
||||
$path_vendor_raylib = join-path $path_vendor 'raylib'
|
||||
|
1
thirdparty/freetype
vendored
Submodule
1
thirdparty/freetype
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 197a1c221ba7015f8d01dc52b108d8f086115999
|
1
thirdparty/sokol-tools
vendored
Submodule
1
thirdparty/sokol-tools
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 3162485457dbe6c7ca8d145bb26db172aed3e44e
|
Loading…
Reference in New Issue
Block a user