Skip to content

Commit

Permalink
new customresolve sample wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Nov 12, 2024
1 parent d1f7f2d commit 27392a4
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sapp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,20 @@ fips_begin_app(shared-bindings-sapp-ui windowed)
target_compile_definitions(shared-bindings-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

fips_ide_group(Samples)
fips_begin_app(customresolve-sapp windowed)
fips_files(customresolve-sapp.c)
sokol_shader(customresolve-sapp.glsl ${slang})
fips_deps(sokol)
fips_end_app()
fips_ide_group(SamplesWithDebugUI)
fips_begin_app(customresolve-sapp-ui windowed)
fips_files(customresolve-sapp.c)
sokol_shader(customresolve-sapp.glsl ${slang})
fips_deps(sokol dbgui)
target_compile_options(customresolve-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

fips_ide_group(Samples)
fips_begin_app(mipmap-sapp windowed)
fips_files(mipmap-sapp.c)
Expand Down
95 changes: 95 additions & 0 deletions sapp/customresolve-sapp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//------------------------------------------------------------------------------
// customresolve-sapp.c
//
// Demonstrate custom MSAA resolve in a render pass which reads individual
// MSAA samples in the fragment shader.
//------------------------------------------------------------------------------
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "sokol_glue.h"
#include "dbgui/dbgui.h"
#include "customresolve-sapp.glsl.h"

static struct {
struct {
sg_image img;
sg_pipeline pip;
} msaa;
struct {
sg_image img;
sg_pipeline pip;
sg_attachments att;
} resolve;
struct {
sg_pipeline pip;
} display;
} state;

static void init(void) {
sg_setup(&(sg_desc){
.environment = sglue_environment(),
.logger.func = slog_func,
});
__dbgui_setup(sapp_sample_count());

state.msaa.img = sg_make_image(&(sg_image_desc){
.width = 160,
.height = 120,
.pixel_format = SG_PIXELFORMAT_RGBA8,
.sample_count = 4,
.label = "msaa image",
});

state.resolve.img = sg_make_image(&(sg_image_desc){
.width = 160,
.height = 120,
.pixel_format = SG_PIXELFORMAT_RGBA8,
.sample_count = 1,
.label = "resolve image",
});

state.msaa.pip = sg_make_pipeline(&(sg_pipeline_desc){
.shader = sg_make_shader(msaa_shader_desc(sg_query_backend())),
.sample_count = 4,
.colors[0].pixel_format = SG_PIXELFORMAT_RGBA8,
.label = "msaa pipeline",
});

state.resolve.pip = sg_make_pipeline(&(sg_pipeline_desc){
.shader = sg_make_shader(resolve_shader_desc(sg_query_backend())),
.sample_count = 1,
.colors[0].pixel_format = SG_PIXELFORMAT_RGBA8,
.label = "resolve pipeline",
});

state.display.pip = sg_make_pipeline(&(sg_pipeline_desc){
.shader = sg_make_shader(display_shader_desc(sg_query_backend())),
.label = "display pipeline",
});
}

static void frame(void) {

}

static void cleanup(void) {
__dbgui_shutdown();
sg_shutdown();
}

sapp_desc sokol_main(int argc, char* argv[]) {
(void)argc; (void)argv;
return (sapp_desc){
.init_cb = init,
.frame_cb = frame,
.cleanup_cb = cleanup,
.event_cb = __dbgui_event,
.width = 640,
.height = 480,
.sample_count = 1,
.window_title = "customresolve-sapp.c",
.icon.sokol_default = true,
.logger.func = slog_func,
};
}
31 changes: 31 additions & 0 deletions sapp/customresolve-sapp.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@vs triangle_vs

const vec4 colors[3] = {
vec4(1, 1, 0, 1),
vec4(0, 1, 1, 1),
vec4(1, 0, 1, 1),
};
const vec3 positions[3] = {
vec3(0.0, 0.5, 0.5),
vec3(0.5, -0.5, 0.5),
vec3(-0.5, -0.5, 0.5),
};

out vec4 color;

void main() {
gl_Position = vec4(positions[gl_VertexIndex], 1.0);
color = colors[gl_VertexIndex];
}
@end

@fs triangle_fs
in vec4 color;
out vec4 frag_color;

void main() {
frag_color = color;
}
@end

@program msaa triangle_vs triangle_fs

0 comments on commit 27392a4

Please sign in to comment.