gpu: Add radial gradients

This commit is contained in:
Benjamin Otte 2023-09-07 14:51:43 +02:00
parent 7473617ffb
commit 72a5927d38
4 changed files with 62 additions and 4 deletions

View File

@ -792,6 +792,33 @@ gsk_gpu_node_processor_create_linear_gradient_pattern (GskGpuNodeProcessor *self
return TRUE;
}
static gboolean
gsk_gpu_node_processor_create_radial_gradient_pattern (GskGpuNodeProcessor *self,
GskGpuBufferWriter *writer,
GskRenderNode *node,
GskGpuShaderImage *images,
gsize n_images,
gsize *out_n_images)
{
if (gsk_render_node_get_node_type (node) == GSK_REPEATING_RADIAL_GRADIENT_NODE)
gsk_gpu_buffer_writer_append_uint (writer, GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT);
else
gsk_gpu_buffer_writer_append_uint (writer, GSK_GPU_PATTERN_RADIAL_GRADIENT);
gsk_gpu_buffer_writer_append_point (writer,
gsk_radial_gradient_node_get_center (node),
&self->offset);
gsk_gpu_buffer_writer_append_float (writer, gsk_radial_gradient_node_get_hradius (node));
gsk_gpu_buffer_writer_append_float (writer, gsk_radial_gradient_node_get_vradius (node));
gsk_gpu_buffer_writer_append_float (writer, gsk_radial_gradient_node_get_start (node));
gsk_gpu_buffer_writer_append_float (writer, gsk_radial_gradient_node_get_end (node));
gsk_gpu_buffer_writer_append_color_stops (writer,
gsk_radial_gradient_node_get_color_stops (node, NULL),
gsk_radial_gradient_node_get_n_color_stops (node));
return TRUE;
}
static gboolean
gsk_gpu_node_processor_create_glyph_pattern (GskGpuNodeProcessor *self,
GskGpuBufferWriter *writer,
@ -980,13 +1007,13 @@ static const struct
},
[GSK_RADIAL_GRADIENT_NODE] = {
0,
NULL,
NULL,
gsk_gpu_node_processor_add_node_as_pattern,
gsk_gpu_node_processor_create_radial_gradient_pattern,
},
[GSK_REPEATING_RADIAL_GRADIENT_NODE] = {
0,
NULL,
NULL,
gsk_gpu_node_processor_add_node_as_pattern,
gsk_gpu_node_processor_create_radial_gradient_pattern,
},
[GSK_CONIC_GRADIENT_NODE] = {
0,

View File

@ -36,5 +36,7 @@ typedef enum {
GSK_GPU_PATTERN_GLYPHS,
GSK_GPU_PATTERN_LINEAR_GRADIENT,
GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT,
GSK_GPU_PATTERN_RADIAL_GRADIENT,
GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT,
} GskGpuPatternType;

View File

@ -13,5 +13,7 @@
#define GSK_GPU_PATTERN_GLYPHS 5u
#define GSK_GPU_PATTERN_LINEAR_GRADIENT 6u
#define GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT 7u
#define GSK_GPU_PATTERN_RADIAL_GRADIENT 8u
#define GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT 9u
#endif

View File

@ -144,6 +144,27 @@ linear_gradient_pattern (inout uint reader,
return gradient_get_color (gradient, offset - d_offset, offset + d_offset);
}
vec4
radial_gradient_pattern (inout uint reader,
vec2 pos,
bool repeating)
{
vec2 center = read_vec2 (reader) * push.scale;
vec2 radius = read_vec2 (reader) * push.scale;
float start = read_float (reader);
float end = read_float (reader);
Gradient gradient = read_gradient (reader);
float offset = length ((pos - center) / radius);
offset = (offset - start) / (end - start);
float d_offset = 0.5 * fwidth (offset);
if (repeating)
return gradient_get_color_repeating (gradient, offset - d_offset, offset + d_offset);
else
return gradient_get_color (gradient, offset - d_offset, offset + d_offset);
}
vec4
color_pattern (inout uint reader)
{
@ -187,6 +208,12 @@ pattern (uint reader,
case GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT:
color = linear_gradient_pattern (reader, pos, true);
break;
case GSK_GPU_PATTERN_RADIAL_GRADIENT:
color = radial_gradient_pattern (reader, pos, false);
break;
case GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT:
color = radial_gradient_pattern (reader, pos, true);
break;
}
}
}