sokol gp rectangle demo works!

This commit is contained in:
Edward R. Gonzalez 2024-06-18 17:24:07 -04:00
parent d2d55b210c
commit 05ecad8f56
2 changed files with 64 additions and 51 deletions

View File

@ -11,9 +11,10 @@ import "core:strings"
import "core:time"
import "core:prof/spall"
import sokol_app "thirdparty:sokol/app"
import sokol_gfx "thirdparty:sokol/gfx"
import sokol_app_gfx_glue "thirdparty:sokol/glue"
import sokol_app "thirdparty:sokol/app"
import sokol_gfx "thirdparty:sokol/gfx"
import sokol_glue "thirdparty:sokol/glue"
import sokol_gp "thirdparty:sokol/gp"
Path_Assets :: "../assets/"
Path_Shaders :: "../shaders/"
@ -205,7 +206,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// Setup sokol_gfx
{
glue_env := sokol_app_gfx_glue.environment()
glue_env := sokol_glue.environment()
desc := sokol_gfx.Desc {
buffer_pool_size = 128,
@ -236,51 +237,19 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
case .DUMMY: logf("sokol_gfx: using dummy backend")
}
// Learning examples
{
debug.gfx_clear_demo_pass_action.colors[0] = {
load_action = .CLEAR,
clear_value = { 1, 0, 0, 1 }
}
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,
-0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0,
}
tri_shader_attr_vs_position :: 0
tri_shader_attr_vs_color0 :: 1
using debug.gfx_tri_demo_state
bindings.vertex_buffers[0] = sokol_gfx.make_buffer( sokol_gfx.Buffer_Desc {
data = {
ptr = & triangle_vertices,
size = size_of(triangle_vertices)
}
})
pipeline = sokol_gfx.make_pipeline( sokol_gfx.Pipeline_Desc {
shader = sokol_gfx.make_shader( triangle_shader_desc(backend)),
layout = sokol_gfx.Vertex_Layout_State {
attrs = {
tri_shader_attr_vs_position = { format = .FLOAT3 },
tri_shader_attr_vs_color0 = { format = .FLOAT4 },
}
}
})
pass_action.colors[0] = {
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 }
}
render_data.pass_actions.bg_clear_black.colors[0] = sokol_gfx.Color_Attachment_Action {
load_action = .CLEAR,
clear_value = { 0, 0, 0, 1 }
}
}
// Setup sokol_gp
{
desc := sokol_gp.Desc {}
sokol_gp.setup(desc)
verify( cast(b32) sokol_gp.is_valid(), "Failed to setup sokol gp (graphics painter)" )
}
// Basic Font Setup
if true
{
@ -389,6 +358,8 @@ sectr_shutdown :: proc()
// font_provider_shutdown()
sokol_gp.shutdown()
sokol_gfx.shutdown()
sokol_app.post_client_cleanup()
log("Module shutdown complete")
@ -444,6 +415,9 @@ hot_reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_
slab_reload( persistent_slab, persistent_allocator() )
// input_reload()
// font_provider_reload()
hmap_chained_reload( font_provider_data.font_cache, persistent_allocator())
str_cache_reload( & string_cache, persistent_allocator(), persistent_allocator() )

View File

@ -1,10 +1,13 @@
package sectr
import "core:math"
import "core:time"
import ve "codebase:font/VEFontCache"
import sokol_app "thirdparty:sokol/app"
import sokol_gfx "thirdparty:sokol/gfx"
import sokol_glue "thirdparty:sokol/glue"
import "core:time"
import sokol_gp "thirdparty:sokol/gp"
PassActions :: struct {
bg_clear_black : sokol_gfx.Pass_Action,
@ -78,6 +81,44 @@ render :: proc()
sokol_gfx.commit()
}
width := app_window.extent.x * 2
height := app_window.extent.y * 2
profile_begin("sokol_gp demo pass")
// Hello Sokol GP Demo
{
screen_ratio := width * (1.0 / height)
sokol_gp.begin(i32(width), i32(height))
sokol_gp.viewport(0, 0, i32(width), i32(height))
sokol_gp.project(-screen_ratio, screen_ratio, 1.0, -1.0)
sokol_gp.set_color(0.1, 0.1, 0.1, 1.0)
sokol_gp.clear()
// Draw animated rectangle box that rotates and changes colors
time := f32(f64(sokol_app.frame_count()) * sokol_app.frame_duration())
red := math.sin(time) * 0.5 + 0.5
green := math.cos(time) * 0.5 + 0.5
sokol_gp.set_color(red, green, 0.3, 1.0)
sokol_gp.rotate_at(time, 0.0, 0.0)
sokol_gp.draw_filled_rect(-0.5, -0.5, 1.0, 1.0)
}
// Process sokol gp render depth pass
{
sokol_gfx.begin_pass( sokol_gfx.Pass { action = {}, swapchain = sokol_glue.swapchain() })
sokol_gp.flush()
sokol_gp.end()
sokol_gfx.end_pass()
}
profile_end()
// "Draw text" using immediate mode api
{
@static index : i32
@ -89,8 +130,6 @@ render :: proc()
// font_provider := & state.font_provider_data
fdef := hmap_chained_get( font_cache, default_font.key )
width := app_window.extent.x * 2
height := app_window.extent.y * 2
ve.set_colour( & ve_font_cache, { 1.0, 1.0, 1.0, 1.0 } )
ve.configure_snap( & ve_font_cache, u32(state.app_window.extent.x * 2.0), u32(state.app_window.extent.y * 2.0) )
@ -99,8 +138,8 @@ render :: proc()
}
sokol_gfx.begin_pass(sokol_gfx.Pass { action = pass_actions.bg_clear_black, swapchain = sokol_glue.swapchain() })
sokol_gfx.end_pass();
// sokol_gfx.begin_pass(sokol_gfx.Pass { action = pass_actions.bg_clear_black, swapchain = sokol_glue.swapchain() })
// sokol_gfx.end_pass();
// Process the draw calls for drawing text
if true