From e5440737e94f3e9deaf714bb7cd395f1d91b90aa Mon Sep 17 00:00:00 2001 From: skejeton Date: Tue, 5 Mar 2024 19:35:42 -0300 Subject: [PATCH] Premultiplied alpha (#161) --- etc/shader.glsl | 6 +++ src/canvas.c | 9 ++++- src/image.c | 18 ++++++--- src/shader-web.glsl.h | 90 +++++++++++++++++++++++++++++++++---------- src/shader.glsl.h | 86 ++++++++++++++++++++++++++++++++--------- src/staembed.c | 4 +- src/tophat.h | 1 + tests/imaget.um | 6 +-- 8 files changed, 168 insertions(+), 52 deletions(-) diff --git a/etc/shader.glsl b/etc/shader.glsl index ee973752..3444e9e5 100644 --- a/etc/shader.glsl +++ b/etc/shader.glsl @@ -16,6 +16,9 @@ void main() { @end @fs th_fs +uniform th_fs_params { + float premultiply; +}; uniform texture2D tex; uniform sampler smp; layout (location = 0) out vec4 frag_color; @@ -24,6 +27,9 @@ in vec4 color; void main() { frag_color = color * texture(sampler2D(tex, smp), uv); + if (premultiply > 0.5) { + frag_color.rgb *= frag_color.a; + } } @end diff --git a/src/canvas.c b/src/canvas.c index df138ebf..766ba04c 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -223,9 +223,9 @@ th_canvas_init() { .enabled = true, .src_factor_alpha = SG_BLENDFACTOR_ONE, - .dst_factor_alpha = SG_BLENDFACTOR_ZERO, + .dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, .op_alpha = SG_BLENDOP_ADD, - .src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA, + .src_factor_rgb = SG_BLENDFACTOR_ONE, .dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, .op_rgb = SG_BLENDOP_ADD, }, @@ -260,13 +260,18 @@ th_canvas_flush() sg_update_buffer(buf, &SG_RANGE(thg->canvas_batch)); thg->canvas_bind.vertex_buffers[0] = buf; finalize_last_phase(); + th_fs_params_t fs_params = {0}; for (size_t i = 0; i < phases_len; i++) { 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; + // 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_draw( phs->start / BATCH_VERTEX, (phs->end - phs->start) / BATCH_VERTEX, 1); break; diff --git a/src/image.c b/src/image.c index cb0d7e10..8b880472 100644 --- a/src/image.c +++ b/src/image.c @@ -144,6 +144,8 @@ th_image_create_render_target(int width, int height, int filter) .depth_stencil_attachment.image = t->depth, .label = "offscreen-pass"}); + t->image->target = true; + return t; } @@ -360,10 +362,14 @@ th_image_remove_render_target(th_render_target *t, th_vf2 wp) void th_image_init() { - thg->offscreen_pass_action = - (sg_pass_action){.colors[0] = {.store_action = SG_STOREACTION_STORE, - .load_action = SG_LOADACTION_CLEAR, - .clear_value = {0, 0, 0, 0}}}; + thg->offscreen_pass_action = (sg_pass_action){ + .colors[0] = + { + .store_action = SG_STOREACTION_STORE, + .load_action = SG_LOADACTION_CLEAR, + .clear_value = {0, 0, 0, 0}, + }, + }; thg->image_pip = sg_make_pipeline(&(sg_pipeline_desc){.shader = thg->main_shader, .layout = {.attrs = { @@ -381,9 +387,9 @@ th_image_init() { .enabled = true, .src_factor_alpha = SG_BLENDFACTOR_ONE, - .dst_factor_alpha = SG_BLENDFACTOR_ZERO, + .dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, .op_alpha = SG_BLENDOP_ADD, - .src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA, + .src_factor_rgb = SG_BLENDFACTOR_ONE, .dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, .op_rgb = SG_BLENDOP_ADD, }, diff --git a/src/shader-web.glsl.h b/src/shader-web.glsl.h index fd301298..2d29f8d8 100644 --- a/src/shader-web.glsl.h +++ b/src/shader-web.glsl.h @@ -16,6 +16,9 @@ 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': Type: SG_IMAGETYPE_2D Sample Type: SG_IMAGESAMPLETYPE_FLOAT @@ -53,6 +56,13 @@ SLOT_smp = 0; + Bind slot and C-struct for uniform block 'th_fs_params': + + th_fs_params_t th_fs_params = { + .premultiply = ...; + }; + sg_apply_uniforms(SG_SHADERSTAGE_[VS|FS], SLOT_th_fs_params, &SG_RANGE(th_fs_params)); + */ #include #include @@ -70,15 +80,22 @@ #define ATTR_th_vs_color0 (2) #define SLOT_tex (0) #define SLOT_smp (0) +#define SLOT_th_fs_params (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct th_fs_params_t { + float premultiply; + uint8_t _pad_4[12]; +} th_fs_params_t; +#pragma pack(pop) /* #version 300 es - + layout(location = 0) in vec2 pos; out vec2 uv; layout(location = 1) in vec2 uv0; out vec4 color; layout(location = 2) in vec4 color0; - + void main() { vec2 _15 = pos * 2.0; @@ -87,7 +104,7 @@ uv = uv0; color = color0; } - + */ static const char th_vs_source_glsl300es[342] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, @@ -117,36 +134,64 @@ static const char th_vs_source_glsl300es[342] = { #version 300 es precision mediump float; precision highp int; - + + uniform highp vec4 th_fs_params[1]; uniform highp sampler2D tex_smp; - + layout(location = 0) out highp vec4 frag_color; in highp vec4 color; in highp vec2 uv; - + void main() { frag_color = color * texture(tex_smp, uv); + if (th_fs_params[0].x > 0.5) + { + highp float _46 = frag_color.w; + highp vec4 _48 = frag_color; + highp vec3 _50 = _48.xyz * _46; + frag_color.x = _50.x; + frag_color.y = _50.y; + frag_color.z = _50.z; + } } - + */ -static const char th_fs_source_glsl300es[250] = { +static const char th_fs_source_glsl300es[538] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75, - 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20, - 0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63, - 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76, - 0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, - 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c, - 0x20,0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63, + 0x34,0x20,0x74,0x68,0x5f,0x66,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31, + 0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, + 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69, + 0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, + 0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67, + 0x68,0x70,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x74,0x68,0x5f,0x66,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30, + 0x5d,0x2e,0x78,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x36,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x20, + 0x3d,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x35,0x30,0x20,0x3d,0x20,0x5f,0x34,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x5f,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72, + 0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x35,0x30, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x35,0x30,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x7a,0x20,0x3d,0x20,0x5f,0x35,0x30,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, }; #if !defined(SOKOL_GFX_INCLUDED) #error "Please include sokol_gfx.h before shader-web.glsl.h" @@ -164,6 +209,11 @@ static inline const sg_shader_desc* th_shader_desc(sg_backend backend) { desc.vs.entry = "main"; desc.fs.source = 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; diff --git a/src/shader.glsl.h b/src/shader.glsl.h index dba69c68..136335aa 100644 --- a/src/shader.glsl.h +++ b/src/shader.glsl.h @@ -16,6 +16,9 @@ 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': Type: SG_IMAGETYPE_2D Sample Type: SG_IMAGESAMPLETYPE_FLOAT @@ -53,6 +56,13 @@ SLOT_smp = 0; + Bind slot and C-struct for uniform block 'th_fs_params': + + th_fs_params_t th_fs_params = { + .premultiply = ...; + }; + sg_apply_uniforms(SG_SHADERSTAGE_[VS|FS], SLOT_th_fs_params, &SG_RANGE(th_fs_params)); + */ #include #include @@ -70,15 +80,22 @@ #define ATTR_th_vs_color0 (2) #define SLOT_tex (0) #define SLOT_smp (0) +#define SLOT_th_fs_params (0) +#pragma pack(push,1) +SOKOL_SHDC_ALIGN(16) typedef struct th_fs_params_t { + float premultiply; + uint8_t _pad_4[12]; +} th_fs_params_t; +#pragma pack(pop) /* #version 330 - + layout(location = 0) in vec2 pos; out vec2 uv; layout(location = 1) in vec2 uv0; out vec4 color; layout(location = 2) in vec4 color0; - + void main() { vec2 _15 = pos * 2.0; @@ -87,7 +104,7 @@ uv = uv0; color = color0; } - + */ static const char th_vs_source_glsl330[339] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x6c,0x61, @@ -115,32 +132,58 @@ static const char th_vs_source_glsl330[339] = { }; /* #version 330 - + + uniform vec4 th_fs_params[1]; uniform sampler2D tex_smp; - + layout(location = 0) out vec4 frag_color; in vec4 color; in vec2 uv; - + void main() { frag_color = color * texture(tex_smp, uv); + if (th_fs_params[0].x > 0.5) + { + float _46 = frag_color.w; + vec4 _48 = frag_color; + vec3 _50 = _48.xyz * _46; + frag_color.x = _50.x; + frag_color.y = _50.y; + frag_color.z = _50.z; + } } - + */ -static const char th_fs_source_glsl330[177] = { +static const char th_fs_source_glsl330[441] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, - 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, - 0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x00, + 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x74,0x68,0x5f,0x66,0x73, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x75,0x6e,0x69,0x66, + 0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x2a,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x74,0x68,0x5f,0x66,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b, + 0x30,0x5d,0x2e,0x78,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x34,0x36,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x34,0x38,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x35,0x30,0x20,0x3d,0x20,0x5f,0x34,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x5f,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x5f,0x35,0x30,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x79,0x20,0x3d,0x20,0x5f,0x35,0x30,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x7a,0x20,0x3d,0x20,0x5f,0x35,0x30,0x2e,0x7a,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x7d,0x0a,0x0a,0x00, }; #if !defined(SOKOL_GFX_INCLUDED) #error "Please include sokol_gfx.h before shader.glsl.h" @@ -158,6 +201,11 @@ static inline const sg_shader_desc* th_shader_desc(sg_backend backend) { desc.vs.entry = "main"; desc.fs.source = th_fs_source_glsl330; 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; diff --git a/src/staembed.c b/src/staembed.c index eccd05cf..f2debde1 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -1,4 +1,4 @@ -#include "tophat.h" +#include "tophat.h" const char *th_em_modulesrc[] = { "\n" "import (\n" @@ -3879,7 +3879,7 @@ const char *th_em_misc[] = { "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" "", -"v1.3\n" +"v1.3.1\n" "", }; const char *th_em_moduledocs[] = { diff --git a/src/tophat.h b/src/tophat.h index cee8b220..cc2bef99 100644 --- a/src/tophat.h +++ b/src/tophat.h @@ -82,6 +82,7 @@ typedef struct th_quad crop; char flipv; char fliph; + bool target; } th_image; typedef struct diff --git a/tests/imaget.um b/tests/imaget.um index b4eaa29f..56107146 100644 --- a/tests/imaget.um +++ b/tests/imaget.um @@ -85,7 +85,7 @@ fn init*() { placeholders.test.draw(th.Transform{ s: th.Vf2{4, 4}, p: p, - r: 0}) + r: 0}, 0xFFFFFF99) p.y += img.getDims().mulf(4).y @@ -101,10 +101,10 @@ fn init*() { p.y += 12 target.begin() - canvas.drawLine(0xff, th.Vf2{0, 0}, th.Vf2{50, 50}, 0.1) + canvas.drawLine(0xFF, th.Vf2{0, 0}, th.Vf2{50, 50}, 0.1) img.draw(th.Transform{ s: th.Vf2{0.5, 0.5}, - p: th.Vf2{0, 0}}) + p: th.Vf2{0, 0}}, 0xFFFFFF99) target.end(window.wp) target.toImage().draw(th.Transform{s: th.Vf2{10, 10}, p: p})