-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |