[gtk/wip/baedert/gl-rework: 101/127] gl renderer: Pass linear gradient stops to shaders directly
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/gl-rework: 101/127] gl renderer: Pass linear gradient stops to shaders directly
- Date: Mon, 30 Dec 2019 04:19:27 +0000 (UTC)
commit 68ed65ac9ca2d90c1f572142b34a9904f6ad8c91
Author: Timm Bäder <mail baedert org>
Date: Tue Dec 17 18:11:45 2019 +0100
gl renderer: Pass linear gradient stops to shaders directly
No need to copy them into the render ops like this.
gsk/gl/gskglrenderer.c | 34 +++++++--------------------------
gsk/gl/gskglrenderopsprivate.h | 1 -
gsk/gl/opbuffer.h | 3 +--
gsk/resources/glsl/linear_gradient.glsl | 29 ++++++++++++++++++++++------
gsk/resources/glsl/preamble.vs.glsl | 4 ++++
5 files changed, 35 insertions(+), 36 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 68fcdf6ddb..59e434a41c 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -1137,23 +1137,10 @@ render_linear_gradient_node (GskGLRenderer *self,
const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node);
const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
- int i;
ops_set_program (builder, &self->linear_gradient_program);
-
op = ops_begin (builder, OP_CHANGE_LINEAR_GRADIENT);
-
- for (i = 0; i < n_color_stops; i ++)
- {
- const GskColorStop *stop = stops + i;
-
- op->color_stops[(i * 4) + 0] = stop->color.red;
- op->color_stops[(i * 4) + 1] = stop->color.green;
- op->color_stops[(i * 4) + 2] = stop->color.blue;
- op->color_stops[(i * 4) + 3] = stop->color.alpha;
- op->color_offsets[i] = stop->offset;
- }
-
+ op->color_stops = stops;
op->n_color_stops = n_color_stops;
op->start_point.x = start->x + builder->dx;
op->start_point.y = start->y + builder->dy;
@@ -2561,18 +2548,12 @@ apply_linear_gradient_op (const Program *program,
const OpLinearGradient *op)
{
OP_PRINT (" -> Linear gradient");
- glUniform1i (program->linear_gradient.num_color_stops_location,
- op->n_color_stops);
- glUniform4fv (program->linear_gradient.color_stops_location,
- op->n_color_stops,
- op->color_stops);
- glUniform1fv (program->linear_gradient.color_offsets_location,
- op->n_color_stops,
- op->color_offsets);
- glUniform2f (program->linear_gradient.start_point_location,
- op->start_point.x, op->start_point.y);
- glUniform2f (program->linear_gradient.end_point_location,
- op->end_point.x, op->end_point.y);
+ glUniform1i (program->linear_gradient.num_color_stops_location, op->n_color_stops);
+ glUniform1fv (program->linear_gradient.color_stops_location,
+ op->n_color_stops * 5,
+ (float *)op->color_stops);
+ glUniform2f (program->linear_gradient.start_point_location, op->start_point.x, op->start_point.y);
+ glUniform2f (program->linear_gradient.end_point_location, op->end_point.x, op->end_point.y);
}
static inline void
@@ -2749,7 +2730,6 @@ gsk_gl_renderer_create_programs (GskGLRenderer *self,
/* linear gradient */
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_stops);
- INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, color_offsets);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, num_color_stops);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, start_point);
INIT_PROGRAM_UNIFORM_LOCATION (linear_gradient, end_point);
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 216a457042..83554ab6f3 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -58,7 +58,6 @@ struct _Program
struct {
int num_color_stops_location;
int color_stops_location;
- int color_offsets_location;
int start_point_location;
int end_point_location;
} linear_gradient;
diff --git a/gsk/gl/opbuffer.h b/gsk/gl/opbuffer.h
index e5198bb0b3..4c33babf97 100644
--- a/gsk/gl/opbuffer.h
+++ b/gsk/gl/opbuffer.h
@@ -109,8 +109,7 @@ typedef struct
typedef struct
{
- float color_offsets[8];
- float color_stops[4 * 8];
+ const GskColorStop *color_stops;
graphene_point_t start_point;
graphene_point_t end_point;
int n_color_stops;
diff --git a/gsk/resources/glsl/linear_gradient.glsl b/gsk/resources/glsl/linear_gradient.glsl
index 0b5fefce83..6814eed53f 100644
--- a/gsk/resources/glsl/linear_gradient.glsl
+++ b/gsk/resources/glsl/linear_gradient.glsl
@@ -1,12 +1,16 @@
// VERTEX_SHADER
uniform vec2 u_start_point;
uniform vec2 u_end_point;
+uniform float u_color_stops[8 * 5];
+uniform int u_num_color_stops;
_OUT_ vec2 startPoint;
_OUT_ vec2 endPoint;
_OUT_ float maxDist;
_OUT_ vec2 gradient;
_OUT_ float gradientLength;
+_OUT_ vec4 color_stops[8];
+_OUT_ float color_offsets[8];
void main() {
gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
@@ -18,18 +22,31 @@ void main() {
// Gradient direction
gradient = endPoint - startPoint;
gradientLength = length(gradient);
+
+ for (int i = 0; i < u_num_color_stops; i ++) {
+ color_offsets[i] = u_color_stops[(i * 5) + 0];
+ color_stops[i].r = u_color_stops[(i * 5) + 1];
+ color_stops[i].g = u_color_stops[(i * 5) + 2];
+ color_stops[i].b = u_color_stops[(i * 5) + 3];
+ color_stops[i].a = u_color_stops[(i * 5) + 4];
+ }
}
// FRAGMENT_SHADER:
-uniform vec4 u_color_stops[8];
-uniform float u_color_offsets[8];
+#ifdef GSK_LEGACY
uniform int u_num_color_stops;
+#else
+uniform highp int u_num_color_stops; // Why? Because it works like this.
+#endif
_IN_ vec2 startPoint;
_IN_ vec2 endPoint;
_IN_ float maxDist;
_IN_ vec2 gradient;
_IN_ float gradientLength;
+_IN_ vec4 color_stops[8];
+_IN_ float color_offsets[8];
+
vec4 fragCoord() {
vec4 f = gl_FragCoord;
@@ -49,11 +66,11 @@ void main() {
// Offset of the current pixel
float offset = length(proj) / maxDist;
- vec4 color = u_color_stops[0];
+ vec4 color = color_stops[0];
for (int i = 1; i < u_num_color_stops; i ++) {
- if (offset >= u_color_offsets[i - 1]) {
- float o = (offset - u_color_offsets[i - 1]) / (u_color_offsets[i] - u_color_offsets[i - 1]);
- color = mix(u_color_stops[i - 1], u_color_stops[i], clamp(o, 0.0, 1.0));
+ if (offset >= color_offsets[i - 1]) {
+ float o = (offset - color_offsets[i - 1]) / (color_offsets[i] - color_offsets[i - 1]);
+ color = mix(color_stops[i - 1], color_stops[i], clamp(o, 0.0, 1.0));
}
}
diff --git a/gsk/resources/glsl/preamble.vs.glsl b/gsk/resources/glsl/preamble.vs.glsl
index 887482fee7..94c4f276a4 100644
--- a/gsk/resources/glsl/preamble.vs.glsl
+++ b/gsk/resources/glsl/preamble.vs.glsl
@@ -2,6 +2,10 @@ uniform mat4 u_projection;
uniform mat4 u_modelview;
uniform float u_alpha;
+#ifdef GSK_GLES
+precision highp float;
+#endif
+
#if GSK_GLES
#define _OUT_ varying
#define _IN_ varying
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]