diff --git a/etc/shader.glsl b/etc/shader.glsl index 3444e9e..da748eb 100644 --- a/etc/shader.glsl +++ b/etc/shader.glsl @@ -16,11 +16,11 @@ void main() { @end @fs th_fs -uniform th_fs_params { +layout(binding=0) uniform th_fs_params { float premultiply; }; -uniform texture2D tex; -uniform sampler smp; +layout(binding=0) uniform texture2D tex; +layout(binding=0) uniform sampler smp; layout (location = 0) out vec4 frag_color; in vec2 uv; in vec4 color; diff --git a/lib/sokol b/lib/sokol index a693ad0..789d970 160000 --- a/lib/sokol +++ b/lib/sokol @@ -1 +1 @@ -Subproject commit a693ad02c8629254e0ebfb75b1ed3a4acbda6777 +Subproject commit 789d97071d17cbab4e3835a0b0b8b379e98c114f diff --git a/src/canvas.c b/src/canvas.c index 397ac72..e69e6d0 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -234,9 +234,9 @@ th_canvas_init() uint32_t white = 0xffffffff; th_image_from_data(&white_img, &white, (th_vf2){.w = 1, .h = 1}); - thg->canvas_bind.fs.images[SLOT_tex] = white_img.tex; + thg->canvas_bind.images[0] = white_img.tex; thg->canvas_image = &white_img; - thg->canvas_bind.fs.samplers[SLOT_smp] = white_img.smp; + thg->canvas_bind.samplers[0] = white_img.smp; } void @@ -265,13 +265,12 @@ th_canvas_flush() phase *phs = &phases[i]; switch (phs->scissor_stage) { case SCISSOR_NONE: - thg->canvas_bind.fs.images[SLOT_tex] = phs->img->tex; - thg->canvas_bind.fs.samplers[SLOT_smp] = phs->img->smp; + thg->canvas_bind.images[0] = phs->img->tex; + thg->canvas_bind.samplers[0] = phs->img->smp; // Targets are premultiplied fs_params.premultiply = phs->img->target ? 0 : 1; sg_apply_bindings(&thg->canvas_bind); - sg_apply_uniforms( - SG_SHADERSTAGE_FS, SLOT_th_fs_params, &SG_RANGE(fs_params)); + sg_apply_uniforms(0, &SG_RANGE(fs_params)); sg_draw( phs->start / BATCH_VERTEX, (phs->end - phs->start) / BATCH_VERTEX, 1); break; diff --git a/src/shader-web.glsl.h b/src/shader-web.glsl.h index af062fc..6aa999b 100644 --- a/src/shader-web.glsl.h +++ b/src/shader-web.glsl.h @@ -11,26 +11,24 @@ ========= Shader program: 'th': Get shader desc: th_shader_desc(sg_query_backend()); - Vertex shader: th_vs - Attributes: - ATTR_th_vs_pos => 0 - ATTR_th_vs_uv0 => 1 - ATTR_th_vs_color0 => 2 - Fragment shader: th_fs - Uniform block 'th_fs_params': - C struct: th_fs_params_t - Bind slot: SLOT_th_fs_params => 0 - Image 'tex': - Image type: SG_IMAGETYPE_2D - Sample type: SG_IMAGESAMPLETYPE_FLOAT - Multisampled: false - Bind slot: SLOT_tex => 0 - Sampler 'smp': - Type: SG_SAMPLERTYPE_FILTERING - Bind slot: SLOT_smp => 0 - Image Sampler Pair 'tex_smp': - Image: tex - Sampler: smp + Vertex Shader: th_vs + Fragment Shader: th_fs + Attributes: + ATTR_th_pos => 0 + ATTR_th_uv0 => 1 + ATTR_th_color0 => 2 + Bindings: + Uniform block 'th_fs_params': + C struct: th_fs_params_t + Bind slot: UB_th_fs_params => 0 + Image 'tex': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: IMG_tex => 0 + Sampler 'smp': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_smp => 0 */ #if !defined(SOKOL_GFX_INCLUDED) #error "Please include sokol_gfx.h before shader-web.glsl.h" @@ -42,12 +40,12 @@ #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) #endif #endif -#define ATTR_th_vs_pos (0) -#define ATTR_th_vs_uv0 (1) -#define ATTR_th_vs_color0 (2) -#define SLOT_th_fs_params (0) -#define SLOT_tex (0) -#define SLOT_smp (0) +#define ATTR_th_pos (0) +#define ATTR_th_uv0 (1) +#define ATTR_th_color0 (2) +#define UB_th_fs_params (0) +#define IMG_tex (0) +#define SMP_smp (0) #pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct th_fs_params_t { float premultiply; @@ -166,28 +164,29 @@ static inline const sg_shader_desc* th_shader_desc(sg_backend backend) { static bool valid; if (!valid) { valid = true; - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "uv0"; - desc.attrs[2].name = "color0"; - desc.vs.source = (const char*)th_vs_source_glsl300es; - desc.vs.entry = "main"; - desc.fs.source = (const char*)th_fs_source_glsl300es; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; - desc.fs.uniform_blocks[0].uniforms[0].name = "th_fs_params"; - desc.fs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = SG_IMAGETYPE_2D; - desc.fs.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + desc.vertex_func.source = (const char*)th_vs_source_glsl300es; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)th_fs_source_glsl300es; + desc.fragment_func.entry = "main"; + desc.attrs[0].glsl_name = "pos"; + desc.attrs[1].glsl_name = "uv0"; + desc.attrs[2].glsl_name = "color0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "th_fs_params"; + desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.images[0].image_type = SG_IMAGETYPE_2D; + desc.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.images[0].multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.image_sampler_pairs[0].image_slot = 0; + desc.image_sampler_pairs[0].sampler_slot = 0; + desc.image_sampler_pairs[0].glsl_name = "tex_smp"; desc.label = "th_shader"; } return &desc; diff --git a/src/shader.glsl.h b/src/shader.glsl.h index 46e993f..dd54aea 100644 --- a/src/shader.glsl.h +++ b/src/shader.glsl.h @@ -11,26 +11,24 @@ ========= Shader program: 'th': Get shader desc: th_shader_desc(sg_query_backend()); - Vertex shader: th_vs - Attributes: - ATTR_th_vs_pos => 0 - ATTR_th_vs_uv0 => 1 - ATTR_th_vs_color0 => 2 - Fragment shader: th_fs - Uniform block 'th_fs_params': - C struct: th_fs_params_t - Bind slot: SLOT_th_fs_params => 0 - Image 'tex': - Image type: SG_IMAGETYPE_2D - Sample type: SG_IMAGESAMPLETYPE_FLOAT - Multisampled: false - Bind slot: SLOT_tex => 0 - Sampler 'smp': - Type: SG_SAMPLERTYPE_FILTERING - Bind slot: SLOT_smp => 0 - Image Sampler Pair 'tex_smp': - Image: tex - Sampler: smp + Vertex Shader: th_vs + Fragment Shader: th_fs + Attributes: + ATTR_th_pos => 0 + ATTR_th_uv0 => 1 + ATTR_th_color0 => 2 + Bindings: + Uniform block 'th_fs_params': + C struct: th_fs_params_t + Bind slot: UB_th_fs_params => 0 + Image 'tex': + Image type: SG_IMAGETYPE_2D + Sample type: SG_IMAGESAMPLETYPE_FLOAT + Multisampled: false + Bind slot: IMG_tex => 0 + Sampler 'smp': + Type: SG_SAMPLERTYPE_FILTERING + Bind slot: SMP_smp => 0 */ #if !defined(SOKOL_GFX_INCLUDED) #error "Please include sokol_gfx.h before shader.glsl.h" @@ -42,12 +40,12 @@ #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) #endif #endif -#define ATTR_th_vs_pos (0) -#define ATTR_th_vs_uv0 (1) -#define ATTR_th_vs_color0 (2) -#define SLOT_th_fs_params (0) -#define SLOT_tex (0) -#define SLOT_smp (0) +#define ATTR_th_pos (0) +#define ATTR_th_uv0 (1) +#define ATTR_th_color0 (2) +#define UB_th_fs_params (0) +#define IMG_tex (0) +#define SMP_smp (0) #pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct th_fs_params_t { float premultiply; @@ -163,28 +161,29 @@ static inline const sg_shader_desc* th_shader_desc(sg_backend backend) { static bool valid; if (!valid) { valid = true; - desc.attrs[0].name = "pos"; - desc.attrs[1].name = "uv0"; - desc.attrs[2].name = "color0"; - desc.vs.source = (const char*)th_vs_source_glsl410; - desc.vs.entry = "main"; - desc.fs.source = (const char*)th_fs_source_glsl410; - desc.fs.entry = "main"; - desc.fs.uniform_blocks[0].size = 16; - desc.fs.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; - desc.fs.uniform_blocks[0].uniforms[0].name = "th_fs_params"; - desc.fs.uniform_blocks[0].uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.fs.uniform_blocks[0].uniforms[0].array_count = 1; - desc.fs.images[0].used = true; - desc.fs.images[0].multisampled = false; - desc.fs.images[0].image_type = SG_IMAGETYPE_2D; - desc.fs.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT; - desc.fs.samplers[0].used = true; - desc.fs.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; - desc.fs.image_sampler_pairs[0].used = true; - desc.fs.image_sampler_pairs[0].image_slot = 0; - desc.fs.image_sampler_pairs[0].sampler_slot = 0; - desc.fs.image_sampler_pairs[0].glsl_name = "tex_smp"; + desc.vertex_func.source = (const char*)th_vs_source_glsl410; + desc.vertex_func.entry = "main"; + desc.fragment_func.source = (const char*)th_fs_source_glsl410; + desc.fragment_func.entry = "main"; + desc.attrs[0].glsl_name = "pos"; + desc.attrs[1].glsl_name = "uv0"; + desc.attrs[2].glsl_name = "color0"; + desc.uniform_blocks[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; + desc.uniform_blocks[0].size = 16; + desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; + desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "th_fs_params"; + desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.images[0].image_type = SG_IMAGETYPE_2D; + desc.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT; + desc.images[0].multisampled = false; + desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; + desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; + desc.image_sampler_pairs[0].image_slot = 0; + desc.image_sampler_pairs[0].sampler_slot = 0; + desc.image_sampler_pairs[0].glsl_name = "tex_smp"; desc.label = "th_shader"; } return &desc;