mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
gpu: Introduce gsk_texture() shader function/macro
Due to GLES and old GL not allowing non-constant texture array lookups,we need to turn the array lookup into a big switch statementin those versions, and that requires putting the texture() call into that switch. But with that trick, we can use texture IDs in GLSL.
This commit is contained in:
parent
5ab8fde0bc
commit
b7a8c2207e
@ -52,23 +52,64 @@ gsk_get_float (uint id)
|
||||
return gsk_get_float (int (id));
|
||||
}
|
||||
|
||||
#define gsk_get_texture(id) textures[id]
|
||||
#define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
|
||||
#define gsk_get_uint(id) (floatBitsToUint(gsk_get_float(id)))
|
||||
|
||||
#ifdef GSK_GLES
|
||||
void
|
||||
gsk_set_output_color (vec4 color)
|
||||
vec4
|
||||
gsk_texture (uint id,
|
||||
vec2 pos)
|
||||
{
|
||||
gl_FragColor = color;
|
||||
switch(id)
|
||||
{
|
||||
case 0u:
|
||||
return texture (textures[0], pos);
|
||||
case 1u:
|
||||
return texture (textures[1], pos);
|
||||
case 2u:
|
||||
return texture (textures[2], pos);
|
||||
case 3u:
|
||||
return texture (textures[3], pos);
|
||||
case 4u:
|
||||
return texture (textures[4], pos);
|
||||
case 5u:
|
||||
return texture (textures[5], pos);
|
||||
case 6u:
|
||||
return texture (textures[6], pos);
|
||||
case 7u:
|
||||
return texture (textures[7], pos);
|
||||
case 8u:
|
||||
return texture (textures[8], pos);
|
||||
case 9u:
|
||||
return texture (textures[9], pos);
|
||||
case 10u:
|
||||
return texture (textures[10], pos);
|
||||
case 11u:
|
||||
return texture (textures[11], pos);
|
||||
case 12u:
|
||||
return texture (textures[12], pos);
|
||||
case 13u:
|
||||
return texture (textures[13], pos);
|
||||
case 14u:
|
||||
return texture (textures[14], pos);
|
||||
case 15u:
|
||||
return texture (textures[15], pos);
|
||||
default:
|
||||
return vec4 (1.0, 0.0, 0.8, 1.0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#else /* !GSK_GLES */
|
||||
|
||||
#define gsk_texture(id, pos) texture (textures[id], pos)
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
void
|
||||
gsk_set_output_color (vec4 color)
|
||||
{
|
||||
out_color = color;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -32,7 +32,7 @@ layout(set = 1, binding = 0) readonly buffer FloatBuffers {
|
||||
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
#define gsk_get_texture(id) textures[nonuniformEXT (id)]
|
||||
#define gsk_texture(id, pos) texture (textures[nonuniformEXT (id)], pos)
|
||||
#define gsk_get_buffer(id) buffers[nonuniformEXT (id)]
|
||||
#define gsk_get_float(id) gsk_get_buffer(0).floats[id]
|
||||
#define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
|
||||
|
@ -39,7 +39,7 @@ void
|
||||
run (out vec4 color,
|
||||
out vec2 position)
|
||||
{
|
||||
float alpha = texture (gsk_get_texture (_tex_id), _tex_coord).a * rect_coverage (_rect, _pos);
|
||||
float alpha = gsk_texture (_tex_id, _tex_coord).a * rect_coverage (_rect, _pos);
|
||||
color = _color * alpha;
|
||||
position = _pos;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void
|
||||
run (out vec4 color,
|
||||
out vec2 position)
|
||||
{
|
||||
color = texture (gsk_get_texture (_tex_id), _tex_coord) *
|
||||
color = gsk_texture (_tex_id, _tex_coord) *
|
||||
rect_coverage (_rect, _pos);
|
||||
position = _pos;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ glyphs_pattern (inout uint reader,
|
||||
|
||||
float coverage = rect_coverage (glyph_bounds, pos);
|
||||
if (coverage > 0.0)
|
||||
opacity += coverage * texture (gsk_get_texture (tex_id), (pos - push.scale * tex_rect.xy) / (push.scale * tex_rect.zw)).a;
|
||||
opacity += coverage * gsk_texture (tex_id, (pos - push.scale * tex_rect.xy) / (push.scale * tex_rect.zw)).a;
|
||||
}
|
||||
|
||||
return color * opacity;
|
||||
@ -132,7 +132,7 @@ texture_pattern (inout uint reader,
|
||||
uint tex_id = read_uint (reader);
|
||||
vec4 tex_rect = read_vec4 (reader);
|
||||
|
||||
return texture (gsk_get_texture (tex_id), (pos - push.scale * tex_rect.xy) / (push.scale * tex_rect.zw));
|
||||
return gsk_texture (tex_id, (pos - push.scale * tex_rect.xy) / (push.scale * tex_rect.zw));
|
||||
}
|
||||
|
||||
vec4
|
||||
|
Loading…
Reference in New Issue
Block a user