Skip to content

Commit

Permalink
more sapp samples fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Feb 10, 2024
1 parent 90d3d18 commit a426934
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 58 deletions.
12 changes: 7 additions & 5 deletions sapp/noentry-dll-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main() {
void init(void* user_data) {
app_state_t* state = (app_state_t*) user_data;
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});

Expand Down Expand Up @@ -158,10 +158,12 @@ void frame(void* user_data) {
hmm_mat4 model = HMM_MultiplyMat4(rxm, rym);
vs_params.mvp = HMM_MultiplyMat4(view_proj, model);

sg_pass_action pass_action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.5f, 0.25f, 0.75f, 1.0f } }
};
sg_begin_default_pass(&pass_action, (int)w, (int)h);
sg_begin_pass(&(sg_pass){
.action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.5f, 0.25f, 0.75f, 1.0f } }
},
.swapchain = sglue_swapchain()
});
sg_apply_pipeline(state->pip);
sg_apply_bindings(&state->bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
Expand Down
12 changes: 7 additions & 5 deletions sapp/noentry-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
void init(void* user_data) {
app_state_t* state = (app_state_t*) user_data;
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});

Expand Down Expand Up @@ -159,10 +159,12 @@ void frame(void* user_data) {
hmm_mat4 model = HMM_MultiplyMat4(rxm, rym);
vs_params.mvp = HMM_MultiplyMat4(view_proj, model);

sg_pass_action pass_action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.5f, 0.25f, 0.75f, 1.0f } }
};
sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
sg_begin_pass(&(sg_pass){
.action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.5f, 0.25f, 0.75f, 1.0f } }
},
.swapchain = sglue_swapchain(),
});
sg_apply_pipeline(state->pip);
sg_apply_bindings(&state->bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
Expand Down
4 changes: 2 additions & 2 deletions sapp/noninterleaved-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static struct {

void init(void) {
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());
Expand Down Expand Up @@ -117,7 +117,7 @@ void frame(void) {
hmm_mat4 model = HMM_MultiplyMat4(rxm, rym);
vs_params.mvp = HMM_MultiplyMat4(view_proj, model);

sg_begin_default_pass(&state.pass_action, sapp_width(), sapp_height());
sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
sg_apply_pipeline(state.pip);
sg_apply_bindings(&state.bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
Expand Down
14 changes: 7 additions & 7 deletions sapp/nuklear-images-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static struct {
sgl_pipeline sgl_pip;
sg_image color_img;
sg_image depth_img;
sg_pass pass;
sg_attachments atts;
sg_pass_action pass_action;
} offscreen;
struct {
Expand All @@ -55,7 +55,7 @@ static void draw_cube(void);

static void init(void) {
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());
Expand Down Expand Up @@ -103,9 +103,9 @@ static void init(void) {
});

// a render pass object to render into the offscreen render targets
state.offscreen.pass = sg_make_pass(&(sg_pass_desc){
.color_attachments[0].image = state.offscreen.color_img,
.depth_stencil_attachment.image = state.offscreen.depth_img,
state.offscreen.atts = sg_make_attachments(&(sg_attachments_desc){
.colors[0].image = state.offscreen.color_img,
.depth_stencil.image = state.offscreen.depth_img,
});

// a pass-action for the offscreen pass which clears to black
Expand Down Expand Up @@ -189,12 +189,12 @@ static void frame(void) {

// perform sokol-gfx rendering...
// ...first the offscreen pass which renders the sokol-gl scene
sg_begin_pass(state.offscreen.pass, &state.offscreen.pass_action);
sg_begin_pass(&(sg_pass){ .action = state.offscreen.pass_action, .attachments = state.offscreen.atts });
sgl_context_draw(state.offscreen.sgl_ctx);
sg_end_pass();

// then the display pass with the Dear ImGui scene
sg_begin_default_pass(&state.display.pass_action, sapp_width(), sapp_height());
sg_begin_pass(&(sg_pass){ .action = state.display.pass_action, .swapchain = sglue_swapchain() });
snk_render(sapp_width(), sapp_height());
__dbgui_draw();
sg_end_pass();
Expand Down
16 changes: 9 additions & 7 deletions sapp/nuklear-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int draw_demo_ui(struct nk_context* ctx);
void init(void) {
// setup sokol-gfx and sokol-nuklear
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());
Expand All @@ -52,12 +52,14 @@ void frame(void) {
draw_demo_ui(ctx);

// the sokol_gfx draw pass
const sg_pass_action pass_action = {
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.25f, 0.5f, 0.7f, 1.0f }
}
};
sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
sg_begin_pass(&(sg_pass){
.action = {
.colors[0] = {
.load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.25f, 0.5f, 0.7f, 1.0f }
}
},
.swapchain = sglue_swapchain()
});
snk_render(sapp_width(), sapp_height());
__dbgui_draw();
sg_end_pass();
Expand Down
7 changes: 5 additions & 2 deletions sapp/ozz-anim-sapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void init(void) {

// setup sokol-gfx
sg_desc sgdesc = { };
sgdesc.context = sapp_sgcontext();
sgdesc.environment = sglue_environment(),
sgdesc.logger.func = slog_func;
sg_setup(&sgdesc);

Expand Down Expand Up @@ -158,7 +158,10 @@ static void frame(void) {
draw_skeleton();
}

sg_begin_default_pass(&state.pass_action, fb_width, fb_height);
sg_pass pass = { };
pass.action = state.pass_action;
pass.swapchain = sglue_swapchain();
sg_begin_pass(&pass);
sgl_draw();
simgui_render();
sg_end_pass();
Expand Down
7 changes: 5 additions & 2 deletions sapp/ozz-skin-sapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void init(void) {

// setup sokol-gfx
sg_desc sgdesc = { };
sgdesc.context = sapp_sgcontext();
sgdesc.environment = sglue_environment();
sgdesc.logger.func = slog_func;
sg_setup(&sgdesc);

Expand Down Expand Up @@ -384,7 +384,10 @@ static void frame(void) {
simgui_new_frame({ fb_width, fb_height, state.time.frame_time_sec, sapp_dpi_scale() });
draw_ui();

sg_begin_default_pass(&state.pass_action, fb_width, fb_height);
sg_pass pass = {};
pass.action = state.pass_action;
pass.swapchain = sglue_swapchain();
sg_begin_default_pass(&pass);
if (state.loaded.animation && state.loaded.skeleton && state.loaded.mesh) {
if (!state.time.paused) {
state.time.abs_time_sec += state.time.frame_time_sec * state.time.factor;
Expand Down
50 changes: 26 additions & 24 deletions sapp/pixelformats-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ static struct {
sg_pipeline cube_msaa_pip;
sg_pipeline bg_render_pip;
sg_pipeline bg_msaa_pip;
sg_pass render_pass;
sg_pass blend_pass;
sg_pass msaa_pass;
sg_attachments render_atts;
sg_attachments blend_atts;
sg_attachments msaa_atts;
} fmt[_SG_PIXELFORMAT_NUM];
sg_sampler smp_nearest;
sg_sampler smp_linear;
Expand All @@ -50,8 +50,8 @@ static void init(void) {
sg_setup(&(sg_desc){
.pipeline_pool_size = 256,
.image_pool_size = 256,
.pass_pool_size = 128,
.context = sapp_sgcontext(),
.attachments_pool_size = 128,
.environment = sglue_environment(),
.logger.func = slog_func,
});

Expand Down Expand Up @@ -158,7 +158,7 @@ static void init(void) {
}
}

// create non-MSAA render target, pipeline state and pass
// create non-MSAA render target, pipeline state and pass-attachments
if (fmt_info.render) {
sg_image img = sg_make_image(&(sg_image_desc){
.render_target = true,
Expand All @@ -175,12 +175,12 @@ static void init(void) {
bg_render_pip_desc.colors[0].pixel_format = fmt;
state.fmt[i].cube_render_pip = sg_make_pipeline(&cube_render_pip_desc);
state.fmt[i].bg_render_pip = sg_make_pipeline(&bg_render_pip_desc);
state.fmt[i].render_pass = sg_make_pass(&(sg_pass_desc){
.color_attachments[0].image = img,
.depth_stencil_attachment.image = render_depth_img,
state.fmt[i].render_atts = sg_make_attachments(&(sg_attachments_desc){
.colors[0].image = img,
.depth_stencil.image = render_depth_img,
});
}
// create non-MSAA blend render target, pipeline states and pass
// create non-MSAA blend render target, pipeline states and pass-attachments
if (fmt_info.blend) {
sg_image img = sg_make_image(&(sg_image_desc){
.render_target = true,
Expand All @@ -195,9 +195,9 @@ static void init(void) {
});
cube_blend_pip_desc.colors[0].pixel_format = fmt;
state.fmt[i].cube_blend_pip = sg_make_pipeline(&cube_blend_pip_desc);
state.fmt[i].blend_pass = sg_make_pass(&(sg_pass_desc){
.color_attachments[0].image = img,
.depth_stencil_attachment.image = render_depth_img,
state.fmt[i].blend_atts = sg_make_attachments(&(sg_attachments_desc){
.colors[0].image = img,
.depth_stencil.image = render_depth_img,
});
}
// create MSAA render target, resolve texture and matching pipeline state
Expand All @@ -224,10 +224,10 @@ static void init(void) {
bg_msaa_pip_desc.colors[0].pixel_format = fmt;
state.fmt[i].cube_msaa_pip = sg_make_pipeline(&cube_msaa_pip_desc);
state.fmt[i].bg_msaa_pip = sg_make_pipeline(&bg_msaa_pip_desc);
state.fmt[i].msaa_pass = sg_make_pass(&(sg_pass_desc){
.color_attachments[0].image = msaa_img,
.resolve_attachments[0].image = resolve_img,
.depth_stencil_attachment.image = msaa_depth_img,
state.fmt[i].msaa_atts = sg_make_attachments(&(sg_attachments_desc){
.colors[0].image = msaa_img,
.resolves[0].image = resolve_img,
.depth_stencil.image = msaa_depth_img,
});
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ static void frame(void) {
sg_pixel_format fmt = (sg_pixel_format)i;
sg_pixelformat_info fmt_info = sg_query_pixelformat(fmt);
if (fmt_info.render) {
sg_begin_pass(state.fmt[i].render_pass, &(sg_pass_action){0});
sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].render_atts });
sg_apply_pipeline(state.fmt[i].bg_render_pip);
sg_apply_bindings(&state.bg_bindings);
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params));
Expand All @@ -326,7 +326,7 @@ static void frame(void) {
sg_end_pass();
}
if (fmt_info.blend) {
sg_begin_pass(state.fmt[i].blend_pass, &(sg_pass_action){0});
sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].blend_atts });
sg_apply_pipeline(state.fmt[i].bg_render_pip); // not a bug
sg_apply_bindings(&state.bg_bindings); // not a bug
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params));
Expand All @@ -338,7 +338,7 @@ static void frame(void) {
sg_end_pass();
}
if (fmt_info.msaa) {
sg_begin_pass(state.fmt[i].msaa_pass, &(sg_pass_action){ .colors[0].store_action = SG_STOREACTION_DONTCARE });
sg_begin_pass(&(sg_pass){ .attachments = state.fmt[i].msaa_atts, .action = { .colors[0].store_action = SG_STOREACTION_DONTCARE } });
sg_apply_pipeline(state.fmt[i].bg_msaa_pip);
sg_apply_bindings(&state.bg_bindings);
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_bg_fs_params, &SG_RANGE(state.bg_fs_params));
Expand Down Expand Up @@ -393,10 +393,12 @@ static void frame(void) {
igEnd();

// sokol-gfx rendering...
sg_pass_action pass_action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.0f, 0.5f, 0.7f, 1.0f } }
};
sg_begin_default_pass(&pass_action, w, h);
sg_begin_pass(&(sg_pass){
.action = {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.0f, 0.5f, 0.7f, 1.0f } }
},
.swapchain = sglue_swapchain()
});
simgui_render();
sg_end_pass();
sg_commit();
Expand Down
4 changes: 2 additions & 2 deletions sapp/plmpeg-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void init(void) {

// initialize sokol-gfx
sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());
Expand Down Expand Up @@ -249,7 +249,7 @@ static void frame(void) {
vs_params.mvp = HMM_MultiplyMat4(view_proj, model);

// start rendering, but not before the first video frame has been decoded into textures
sg_begin_default_pass(&state.pass_action, sapp_width(), sapp_height());
sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
if (state.bind.fs.images[0].id != SG_INVALID_ID) {
sg_apply_pipeline(state.pip);
sg_apply_bindings(&state.bind);
Expand Down
4 changes: 2 additions & 2 deletions sapp/primtypes-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void init(void) {
state.point_size = 4.0f;

sg_setup(&(sg_desc){
.context = sapp_sgcontext(),
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());
Expand Down Expand Up @@ -151,7 +151,7 @@ static void frame(void) {

print_status_text(w, h);

sg_begin_default_passf(&state.pass_action, w, h);
sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
sg_apply_pipeline(state.prim[state.cur_prim_type].pip);
sg_apply_bindings(&(sg_bindings){
.vertex_buffers[0] = state.vbuf,
Expand Down

0 comments on commit a426934

Please sign in to comment.