summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-05-17 00:56:21 +0200
committerBenjamin Otte <otte@redhat.com>2010-05-17 01:16:16 +0200
commit0b69e51b526a609a2dc5f1d2fb9c49f240feb57b (patch)
treec9a6b0cd19b577e7d59e4bed0df76be8b0a0b259
parent0bb11e8f5bcdc8a6f8384197b39c2ad48eaab1cd (diff)
gl: Assert that binding values to shaders never fails
As that would be a programming error, we can use an assert and get rid of return values that we weren't checking anyway.
-rw-r--r--src/cairo-gl-composite.c129
-rw-r--r--src/cairo-gl-private.h12
-rw-r--r--src/cairo-gl-shaders.c114
-rw-r--r--src/cairo-gl-surface.c15
4 files changed, 111 insertions, 159 deletions
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index a8ae084b..02afe2fb 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -556,21 +556,19 @@ _cairo_gl_set_tex_combine_constant_color (cairo_gl_context_t *ctx,
{
if (setup->shader) {
const char *uniform_name;
- cairo_status_t status;
if (tex_unit == 0)
uniform_name = "source_constant";
else
uniform_name = "mask_constant";
- status = bind_vec4_to_shader (ctx,
- setup->shader->program,
- uniform_name,
- color[0],
- color[1],
- color[2],
- color[3]);
- assert (! _cairo_status_is_error (status));
+ bind_vec4_to_shader (ctx,
+ setup->shader->program,
+ uniform_name,
+ color[0],
+ color[1],
+ color[2],
+ color[3]);
return;
}
@@ -612,7 +610,6 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
{
cairo_surface_attributes_t *src_attributes;
GLfloat constant_color[4] = {0.0, 0.0, 0.0, 0.0};
- cairo_status_t status;
src_attributes = &setup->src.operand.texture.attributes;
@@ -652,16 +649,14 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
glBindTexture (GL_TEXTURE_1D, setup->src.operand.linear.tex);
glEnable (GL_TEXTURE_1D);
- status = bind_matrix_to_shader (ctx, setup->shader->program,
- "source_matrix",
- &setup->src.operand.linear.m);
- assert (!_cairo_status_is_error (status));
+ bind_matrix_to_shader (ctx, setup->shader->program,
+ "source_matrix",
+ &setup->src.operand.linear.m);
- status = bind_vec2_to_shader (ctx, setup->shader->program,
- "source_segment",
- setup->src.operand.linear.segment_x,
- setup->src.operand.linear.segment_y);
- assert (!_cairo_status_is_error (status));
+ bind_vec2_to_shader (ctx, setup->shader->program,
+ "source_segment",
+ setup->src.operand.linear.segment_x,
+ setup->src.operand.linear.segment_y);
break;
case CAIRO_GL_OPERAND_RADIAL_GRADIENT:
@@ -669,26 +664,22 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
glBindTexture (GL_TEXTURE_1D, setup->src.operand.linear.tex);
glEnable (GL_TEXTURE_1D);
- status = bind_matrix_to_shader (ctx, setup->shader->program,
- "source_matrix",
- &setup->src.operand.radial.m);
- assert (!_cairo_status_is_error (status));
-
- status = bind_vec2_to_shader (ctx, setup->shader->program,
- "source_circle_1",
- setup->src.operand.radial.circle_1_x,
- setup->src.operand.radial.circle_1_y);
- assert (!_cairo_status_is_error (status));
-
- status = bind_float_to_shader (ctx, setup->shader->program,
- "source_radius_0",
- setup->src.operand.radial.radius_0);
- assert (!_cairo_status_is_error (status));
-
- status = bind_float_to_shader (ctx, setup->shader->program,
- "source_radius_1",
- setup->src.operand.radial.radius_1);
- assert (!_cairo_status_is_error (status));
+ bind_matrix_to_shader (ctx, setup->shader->program,
+ "source_matrix",
+ &setup->src.operand.radial.m);
+
+ bind_vec2_to_shader (ctx, setup->shader->program,
+ "source_circle_1",
+ setup->src.operand.radial.circle_1_x,
+ setup->src.operand.radial.circle_1_y);
+
+ bind_float_to_shader (ctx, setup->shader->program,
+ "source_radius_0",
+ setup->src.operand.radial.radius_0);
+
+ bind_float_to_shader (ctx, setup->shader->program,
+ "source_radius_1",
+ setup->src.operand.radial.radius_1);
break;
default:
case CAIRO_GL_OPERAND_COUNT:
@@ -751,57 +742,47 @@ static void
_cairo_gl_set_linear_gradient_mask_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
- cairo_status_t status;
-
assert(setup->shader);
glActiveTexture (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_1D, setup->mask.operand.linear.tex);
glEnable (GL_TEXTURE_1D);
- status = bind_matrix_to_shader (ctx, setup->shader->program,
+ bind_matrix_to_shader (ctx, setup->shader->program,
"mask_matrix", &setup->mask.operand.linear.m);
- assert (!_cairo_status_is_error (status));
- status = bind_vec2_to_shader (ctx, setup->shader->program,
+ bind_vec2_to_shader (ctx, setup->shader->program,
"mask_segment",
setup->mask.operand.linear.segment_x,
setup->mask.operand.linear.segment_y);
- assert (!_cairo_status_is_error (status));
}
static void
_cairo_gl_set_radial_gradient_mask_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
- cairo_status_t status;
-
assert(setup->shader);
glActiveTexture (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_1D, setup->mask.operand.radial.tex);
glEnable (GL_TEXTURE_1D);
- status = bind_matrix_to_shader (ctx, setup->shader->program,
- "mask_matrix",
- &setup->mask.operand.radial.m);
- assert (!_cairo_status_is_error (status));
-
- status = bind_vec2_to_shader (ctx, setup->shader->program,
- "mask_circle_1",
- setup->mask.operand.radial.circle_1_x,
- setup->mask.operand.radial.circle_1_y);
- assert (!_cairo_status_is_error (status));
-
- status = bind_float_to_shader (ctx, setup->shader->program,
- "mask_radius_0",
- setup->mask.operand.radial.radius_0);
- assert (!_cairo_status_is_error (status));
-
- status = bind_float_to_shader (ctx, setup->shader->program,
- "mask_radius_1",
- setup->mask.operand.radial.radius_1);
- assert (!_cairo_status_is_error (status));
+ bind_matrix_to_shader (ctx, setup->shader->program,
+ "mask_matrix",
+ &setup->mask.operand.radial.m);
+
+ bind_vec2_to_shader (ctx, setup->shader->program,
+ "mask_circle_1",
+ setup->mask.operand.radial.circle_1_x,
+ setup->mask.operand.radial.circle_1_y);
+
+ bind_float_to_shader (ctx, setup->shader->program,
+ "mask_radius_0",
+ setup->mask.operand.radial.radius_0);
+
+ bind_float_to_shader (ctx, setup->shader->program,
+ "mask_radius_1",
+ setup->mask.operand.radial.radius_1);
}
/* This is like _cairo_gl_set_src_alpha_operand, for component alpha setup
@@ -831,14 +812,12 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
case CAIRO_GL_OPERAND_CONSTANT:
/* Have to have a dummy texture bound in order to use the combiner unit. */
if (setup->shader) {
- cairo_status_t status;
- status = bind_vec4_to_shader (ctx, setup->shader->program,
- "mask_constant",
- setup->src.operand.constant.color[0],
- setup->src.operand.constant.color[1],
- setup->src.operand.constant.color[2],
- setup->src.operand.constant.color[3]);
- assert (! _cairo_status_is_error (status));
+ bind_vec4_to_shader (ctx, setup->shader->program,
+ "mask_constant",
+ setup->src.operand.constant.color[0],
+ setup->src.operand.constant.color[1],
+ setup->src.operand.constant.color[2],
+ setup->src.operand.constant.color[3]);
} else {
glBindTexture (ctx->tex_target, ctx->dummy_tex);
glActiveTexture (GL_TEXTURE1);
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 3f532204..e9aeeb06 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -420,33 +420,33 @@ create_shader_program (cairo_gl_context_t *ctx,
cairo_gl_var_type_t mask,
const char *fragment_text);
-cairo_private cairo_status_t
+cairo_private void
bind_float_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value);
-cairo_private cairo_status_t
+cairo_private void
bind_vec2_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1);
-cairo_private cairo_status_t
+cairo_private void
bind_vec3_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1,
float value2);
-cairo_private cairo_status_t
+cairo_private void
bind_vec4_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1,
float value2, float value3);
-cairo_private cairo_status_t
+cairo_private void
bind_matrix_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name, cairo_matrix_t* m);
-cairo_private cairo_status_t
+cairo_private void
bind_texture_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name, GLuint tex_unit);
diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index 7511b4eb..c3de05ac 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -49,28 +49,28 @@ typedef struct cairo_gl_shader_impl {
void
(*destroy_program) (GLuint program);
- cairo_status_t
+ void
(*bind_float_to_shader) (GLuint program, const char *name,
float value);
- cairo_status_t
+ void
(*bind_vec2_to_shader) (GLuint program, const char *name,
float value0, float value1);
- cairo_status_t
+ void
(*bind_vec3_to_shader) (GLuint program, const char *name,
float value0, float value1,
float value2);
- cairo_status_t
+ void
(*bind_vec4_to_shader) (GLuint program, const char *name,
float value0, float value1,
float value2, float value3);
- cairo_status_t
+ void
(*bind_matrix_to_shader) (GLuint program, const char *name, cairo_matrix_t* m);
- cairo_status_t
+ void
(*bind_texture_to_shader) (GLuint program, const char *name, GLuint tex_unit);
void
@@ -159,53 +159,45 @@ destroy_program_arb (GLuint shader)
glDeleteObjectARB (shader);
}
-static cairo_status_t
+static void
bind_float_to_shader_arb (GLuint program, const char *name,
float value)
{
GLint location = glGetUniformLocationARB (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform1fARB (location, value);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec2_to_shader_arb (GLuint program, const char *name,
float value0, float value1)
{
GLint location = glGetUniformLocationARB (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform2fARB (location, value0, value1);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec3_to_shader_arb (GLuint program, const char *name,
float value0, float value1,
float value2)
{
GLint location = glGetUniformLocationARB (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform3fARB (location, value0, value1, value2);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec4_to_shader_arb (GLuint program, const char *name,
float value0, float value1,
float value2, float value3)
{
GLint location = glGetUniformLocationARB (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform4fARB (location, value0, value1, value2, value3);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_matrix_to_shader_arb (GLuint program, const char *name, cairo_matrix_t* m)
{
GLint location = glGetUniformLocationARB (program, name);
@@ -215,20 +207,16 @@ bind_matrix_to_shader_arb (GLuint program, const char *name, cairo_matrix_t* m)
0, 0, 1, 0,
0, 0, 0, 1
};
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniformMatrix4fvARB (location, 1, GL_TRUE, gl_m);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_texture_to_shader_arb (GLuint program, const char *name, GLuint tex_unit)
{
GLint location = glGetUniformLocationARB (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform1iARB (location, tex_unit);
- return CAIRO_STATUS_SUCCESS;
}
static void
@@ -321,53 +309,45 @@ destroy_program_core_2_0 (GLuint shader)
glDeleteProgram (shader);
}
-static cairo_status_t
+static void
bind_float_to_shader_core_2_0 (GLuint program, const char *name,
float value)
{
GLint location = glGetUniformLocation (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform1f (location, value);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec2_to_shader_core_2_0 (GLuint program, const char *name,
float value0, float value1)
{
GLint location = glGetUniformLocation (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform2f (location, value0, value1);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec3_to_shader_core_2_0 (GLuint program, const char *name,
float value0, float value1,
float value2)
{
GLint location = glGetUniformLocation (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform3f (location, value0, value1, value2);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_vec4_to_shader_core_2_0 (GLuint program, const char *name,
float value0, float value1,
float value2, float value3)
{
GLint location = glGetUniformLocation (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform4f (location, value0, value1, value2, value3);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_matrix_to_shader_core_2_0 (GLuint program, const char *name, cairo_matrix_t* m)
{
GLint location = glGetUniformLocation (program, name);
@@ -377,20 +357,16 @@ bind_matrix_to_shader_core_2_0 (GLuint program, const char *name, cairo_matrix_t
0, 0, 1, 0,
0, 0, 0, 1
};
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniformMatrix4fv (location, 1, GL_TRUE, gl_m);
- return CAIRO_STATUS_SUCCESS;
}
-static cairo_status_t
+static void
bind_texture_to_shader_core_2_0 (GLuint program, const char *name, GLuint tex_unit)
{
GLint location = glGetUniformLocation (program, name);
- if (location == -1)
- return CAIRO_INT_STATUS_UNSUPPORTED;
+ assert (location != -1);
glUniform1i (location, tex_unit);
- return CAIRO_STATUS_SUCCESS;
}
static void
@@ -826,52 +802,52 @@ create_shader_program (cairo_gl_context_t *ctx,
return CAIRO_INT_STATUS_UNSUPPORTED;
}
-cairo_status_t
+void
bind_float_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value)
{
- return ctx->shader_impl->bind_float_to_shader(program, name, value);
+ ctx->shader_impl->bind_float_to_shader(program, name, value);
}
-cairo_status_t
+void
bind_vec2_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1)
{
- return ctx->shader_impl->bind_vec2_to_shader(program, name, value0, value1);
+ ctx->shader_impl->bind_vec2_to_shader(program, name, value0, value1);
}
-cairo_status_t
+void
bind_vec3_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1,
float value2)
{
- return ctx->shader_impl->bind_vec3_to_shader(program, name, value0, value1, value2);
+ ctx->shader_impl->bind_vec3_to_shader(program, name, value0, value1, value2);
}
-cairo_status_t
+void
bind_vec4_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name,
float value0, float value1,
float value2, float value3)
{
- return ctx->shader_impl->bind_vec4_to_shader(program, name, value0, value1, value2, value3);
+ ctx->shader_impl->bind_vec4_to_shader(program, name, value0, value1, value2, value3);
}
-cairo_status_t
+void
bind_matrix_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name, cairo_matrix_t* m)
{
- return ctx->shader_impl->bind_matrix_to_shader(program, name, m);
+ ctx->shader_impl->bind_matrix_to_shader(program, name, m);
}
-cairo_status_t
+void
bind_texture_to_shader (cairo_gl_context_t *ctx,
GLuint program, const char *name, GLuint tex_unit)
{
- return ctx->shader_impl->bind_texture_to_shader(program, name, tex_unit);
+ ctx->shader_impl->bind_texture_to_shader(program, name, tex_unit);
}
void
@@ -952,14 +928,12 @@ _cairo_gl_get_program (cairo_gl_context_t *ctx,
_cairo_gl_use_program (ctx, &entry->program);
if (source != CAIRO_GL_OPERAND_CONSTANT) {
- status = bind_texture_to_shader (ctx, entry->program.program, "source_sampler", 0);
- assert (!_cairo_status_is_error (status));
+ bind_texture_to_shader (ctx, entry->program.program, "source_sampler", 0);
}
if (mask != CAIRO_GL_OPERAND_CONSTANT &&
mask != CAIRO_GL_OPERAND_SPANS &&
mask != CAIRO_GL_OPERAND_NONE) {
- status = bind_texture_to_shader (ctx, entry->program.program, "mask_sampler", 1);
- assert (!_cairo_status_is_error (status));
+ bind_texture_to_shader (ctx, entry->program.program, "mask_sampler", 1);
}
status = _cairo_cache_insert (&ctx->shaders, &entry->base);
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index eeeac597..154b9253 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1200,14 +1200,13 @@ _cairo_gl_surface_fill_rectangles_glsl (void *abstract_surface,
_cairo_gl_context_set_destination (ctx, surface);
_cairo_gl_set_operator (surface, op, FALSE);
- status = bind_vec4_to_shader (ctx,
- ctx->fill_rectangles_shader.program,
- "color",
- color->red * color->alpha,
- color->green * color->alpha,
- color->blue * color->alpha,
- color->alpha);
- assert (! _cairo_status_is_error (status));
+ bind_vec4_to_shader (ctx,
+ ctx->fill_rectangles_shader.program,
+ "color",
+ color->red * color->alpha,
+ color->green * color->alpha,
+ color->blue * color->alpha,
+ color->alpha);
for (i = 0; i < num_rects; i++) {
vertices[i * 8 + 0] = rects[i].x;