Skip to content

Commit

Permalink
fix more samples for bindings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Oct 12, 2024
1 parent 26a986d commit bb71bdc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 84 deletions.
96 changes: 48 additions & 48 deletions sapp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ fips_begin_app(texcube-sapp-ui windowed)
target_compile_definitions(texcube-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

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

fips_ide_group(Samples)
fips_begin_app(offscreen-sapp windowed)
fips_files(offscreen-sapp.c)
Expand Down Expand Up @@ -331,22 +331,22 @@ fips_end_app()
# target_compile_definitions(cubemap-jpeg-sapp-ui PRIVATE USE_DBG_UI)
#fips_end_app()
#
#fips_ide_group(Samples)
#fips_begin_app(basisu-sapp windowed)
# fips_files(basisu-sapp.c)
# fips_deps(sokol basisu)
# fips_dir(data)
# fipsutil_embed(basisu-assets.yml basisu-assets.h)
#fips_end_app()
#fips_ide_group(SamplesWithDebugUI)
#fips_begin_app(basisu-sapp-ui windowed)
# fips_files(basisu-sapp.c)
# fips_deps(sokol basisu dbgui)
# fips_dir(data)
# fipsutil_embed(basisu-assets.yml basisu-assets.h)
# target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI)
#fips_end_app()
#
fips_ide_group(Samples)
fips_begin_app(basisu-sapp windowed)
fips_files(basisu-sapp.c)
fips_deps(sokol basisu)
fips_dir(data)
fipsutil_embed(basisu-assets.yml basisu-assets.h)
fips_end_app()
fips_ide_group(SamplesWithDebugUI)
fips_begin_app(basisu-sapp-ui windowed)
fips_files(basisu-sapp.c)
fips_deps(sokol basisu dbgui)
fips_dir(data)
fipsutil_embed(basisu-assets.yml basisu-assets.h)
target_compile_definitions(basisu-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

fips_ide_group(Samples)
fips_begin_app(blend-sapp windowed)
fips_files(blend-sapp.c)
Expand Down Expand Up @@ -822,24 +822,24 @@ fips_begin_app(plmpeg-sapp-ui windowed)
target_compile_definitions(plmpeg-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

#fips_ide_group(Samples)
#fips_begin_app(cgltf-sapp windowed)
# fips_files(cgltf-sapp.c)
# sokol_shader(cgltf-sapp.glsl ${slang})
# fips_dir(data)
# fipsutil_copy(cgltf-assets.yml)
# fips_deps(sokol basisu fileutil)
#fips_end_app()
#fips_ide_group(SamplesWithDebugUI)
#fips_begin_app(cgltf-sapp-ui windowed)
# fips_files(cgltf-sapp.c)
# sokol_shader(cgltf-sapp.glsl ${slang})
# fips_dir(data)
# fipsutil_copy(cgltf-assets.yml)
# fips_deps(sokol dbgui basisu fileutil)
# target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI)
#fips_end_app()
#
fips_ide_group(Samples)
fips_begin_app(cgltf-sapp windowed)
fips_files(cgltf-sapp.c)
sokol_shader(cgltf-sapp.glsl ${slang})
fips_dir(data)
fipsutil_copy(cgltf-assets.yml)
fips_deps(sokol basisu fileutil)
fips_end_app()
fips_ide_group(SamplesWithDebugUI)
fips_begin_app(cgltf-sapp-ui windowed)
fips_files(cgltf-sapp.c)
sokol_shader(cgltf-sapp.glsl ${slang})
fips_dir(data)
fipsutil_copy(cgltf-assets.yml)
fips_deps(sokol dbgui basisu fileutil)
target_compile_definitions(cgltf-sapp-ui PRIVATE USE_DBG_UI)
fips_end_app()

fips_ide_group(Samples)
fips_begin_app(loadpng-sapp windowed)
fips_files(loadpng-sapp.c)
Expand Down
34 changes: 17 additions & 17 deletions sapp/cgltf-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ typedef struct {
// helper struct to map sokol-gfx buffer bindslots to scene.buffers indices
typedef struct {
int num;
int buffer[SG_MAX_VERTEX_BUFFERS];
int buffer[SG_MAX_VERTEXBUFFER_BINDSLOTS];
} vertex_buffer_mapping_t;

// a 'primitive' (aka submesh) contains everything needed to issue a draw call
Expand Down Expand Up @@ -360,8 +360,8 @@ static void frame(void) {
if (prim->index_buffer != SCENE_INVALID_INDEX) {
bind.index_buffer = state.scene.buffers[prim->index_buffer];
}
sg_apply_uniforms(SG_SHADERSTAGE_VS, SLOT_vs_params, &SG_RANGE(vs_params));
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_light_params, &SG_RANGE(state.point_light));
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
sg_apply_uniforms(UB_light_params, &SG_RANGE(state.point_light));
if (mat->is_metallic) {
sg_image base_color_tex = state.scene.image_samplers[mat->metallic.images.base_color].img;
sg_image metallic_roughness_tex = state.scene.image_samplers[mat->metallic.images.metallic_roughness].img;
Expand Down Expand Up @@ -394,17 +394,17 @@ static void frame(void) {
emissive_tex = state.placeholders.black;
emissive_smp = state.placeholders.smp;
}
bind.fs.images[SLOT_base_color_tex] = base_color_tex;
bind.fs.images[SLOT_metallic_roughness_tex] = metallic_roughness_tex;
bind.fs.images[SLOT_normal_tex] = normal_tex;
bind.fs.images[SLOT_occlusion_tex] = occlusion_tex;
bind.fs.images[SLOT_emissive_tex] = emissive_tex;
bind.fs.samplers[SLOT_base_color_smp] = base_color_smp;
bind.fs.samplers[SLOT_metallic_roughness_smp] = metallic_roughness_smp;
bind.fs.samplers[SLOT_normal_smp] = normal_smp;
bind.fs.samplers[SLOT_occlusion_smp] = occlusion_smp;
bind.fs.samplers[SLOT_emissive_tex] = emissive_smp;
sg_apply_uniforms(SG_SHADERSTAGE_FS, SLOT_metallic_params, &SG_RANGE(mat->metallic.fs_params));
bind.images[IMG_base_color_tex] = base_color_tex;
bind.images[IMG_metallic_roughness_tex] = metallic_roughness_tex;
bind.images[IMG_normal_tex] = normal_tex;
bind.images[IMG_occlusion_tex] = occlusion_tex;
bind.images[IMG_emissive_tex] = emissive_tex;
bind.samplers[SMP_base_color_smp] = base_color_smp;
bind.samplers[SMP_metallic_roughness_smp] = metallic_roughness_smp;
bind.samplers[SMP_normal_smp] = normal_smp;
bind.samplers[SMP_occlusion_smp] = occlusion_smp;
bind.samplers[SMP_emissive_smp] = emissive_smp;
sg_apply_uniforms(UB_metallic_params, &SG_RANGE(mat->metallic.fs_params));
} else {
/*
sg_apply_uniforms(SG_SHADERSTAGE_VS,
Expand Down Expand Up @@ -877,7 +877,7 @@ static sg_index_type gltf_to_index_type(const cgltf_primitive* prim) {
// creates a vertex buffer bind slot mapping for a specific GLTF primitive
static vertex_buffer_mapping_t create_vertex_buffer_mapping_for_gltf_primitive(const cgltf_data* gltf, const cgltf_primitive* prim) {
vertex_buffer_mapping_t map = { 0 };
for (int i = 0; i < SG_MAX_VERTEX_BUFFERS; i++) {
for (int i = 0; i < SG_MAX_VERTEXBUFFER_BINDSLOTS; i++) {
map.buffer[i] = SCENE_INVALID_INDEX;
}
for (cgltf_size attr_index = 0; attr_index < prim->attributes_count; attr_index++) {
Expand All @@ -890,10 +890,10 @@ static vertex_buffer_mapping_t create_vertex_buffer_mapping_for_gltf_primitive(c
break;
}
}
if ((i == map.num) && (map.num < SG_MAX_VERTEX_BUFFERS)) {
if ((i == map.num) && (map.num < SG_MAX_VERTEXBUFFER_BINDSLOTS)) {
map.buffer[map.num++] = buffer_view_index;
}
assert(map.num <= SG_MAX_VERTEX_BUFFERS);
assert(map.num <= SG_MAX_VERTEXBUFFER_BINDSLOTS);
}
return map;
}
Expand Down
27 changes: 13 additions & 14 deletions sapp/cgltf-sapp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@ctype vec3 hmm_vec3

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 model;
mat4 view_proj;
vec3 eye_pos;
Expand Down Expand Up @@ -51,31 +51,31 @@ struct material_info_t {
vec3 specular_color; // color contribution from specular lighting
};

uniform metallic_params {
layout(binding=1) uniform metallic_params {
vec4 base_color_factor;
vec3 emissive_factor;
float metallic_factor;
float roughness_factor;
};

uniform light_params {
layout(binding=2) uniform light_params {
vec3 light_pos;
float light_range;
vec3 light_color;
float light_intensity;
};

uniform texture2D base_color_tex;
uniform texture2D metallic_roughness_tex;
uniform texture2D normal_tex;
uniform texture2D occlusion_tex;
uniform texture2D emissive_tex;
layout(binding=0) uniform texture2D base_color_tex;
layout(binding=1) uniform texture2D metallic_roughness_tex;
layout(binding=2) uniform texture2D normal_tex;
layout(binding=3) uniform texture2D occlusion_tex;
layout(binding=4) uniform texture2D emissive_tex;

uniform sampler base_color_smp;
uniform sampler metallic_roughness_smp;
uniform sampler normal_smp;
uniform sampler occlusion_smp;
uniform sampler emissive_smp;
layout(binding=0) uniform sampler base_color_smp;
layout(binding=1) uniform sampler metallic_roughness_smp;
layout(binding=2) uniform sampler normal_smp;
layout(binding=3) uniform sampler occlusion_smp;
layout(binding=4) uniform sampler emissive_smp;

vec3 linear_to_srgb(vec3 linear) {
return pow(linear, vec3(1.0/2.2));
Expand Down Expand Up @@ -275,4 +275,3 @@ void main() {
@end

@program cgltf_metallic vs metallic_fs

10 changes: 5 additions & 5 deletions sapp/sbuftex-sapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void init(void) {
{ .pos = { 1.0f, 1.0f, 1.0f }, .idx = 5, .uv = { 1.0f, 1.0f } },
{ .pos = { 1.0f, 1.0f, -1.0f }, .idx = 5, .uv = { 0.0f, 1.0f } },
};
state.bind.vs.storage_buffers[SLOT_vertices] = sg_make_buffer(&(sg_buffer_desc){
state.bind.storage_buffers[SBUF_vertices] = sg_make_buffer(&(sg_buffer_desc){
.type = SG_BUFFERTYPE_STORAGEBUFFER,
.data = SG_RANGE(vertices),
.label = "cube-vertices",
Expand Down Expand Up @@ -113,7 +113,7 @@ static void init(void) {
{ .color = { 0.0f, 0.5f, 1.0f, 1.0f } },
{ .color = { 1.0f, 0.5f, 0.0f, 1.0f } },
};
state.bind.fs.storage_buffers[SLOT_colors] = sg_make_buffer(&(sg_buffer_desc){
state.bind.storage_buffers[SBUF_colors] = sg_make_buffer(&(sg_buffer_desc){
.type = SG_BUFFERTYPE_STORAGEBUFFER,
.data = SG_RANGE(colors),
.label = "color-palette",
Expand All @@ -126,7 +126,7 @@ static void init(void) {
{ 0x88, 0x44, 0xFF, 0xCC },
{ 0x44, 0xFF, 0xCC, 0x88 },
};
state.bind.fs.images[SLOT_tex] = sg_make_image(&(sg_image_desc){
state.bind.images[IMG_tex] = sg_make_image(&(sg_image_desc){
.width = 4,
.height = 4,
.pixel_format = SG_PIXELFORMAT_R8,
Expand All @@ -135,7 +135,7 @@ static void init(void) {
});

// ...and a matching sampler
state.bind.fs.samplers[SLOT_smp] = sg_make_sampler(&(sg_sampler_desc){
state.bind.samplers[SMP_smp] = sg_make_sampler(&(sg_sampler_desc){
.min_filter = SG_FILTER_NEAREST,
.mag_filter = SG_FILTER_NEAREST,
.label = "sampler",
Expand Down Expand Up @@ -165,7 +165,7 @@ static void frame(void) {
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));
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
sg_draw(0, 36, 1);
__dbgui_draw();
sg_end_pass();
Expand Down

0 comments on commit bb71bdc

Please sign in to comment.