diff options
author | Benjamin Otte <otte@redhat.com> | 2010-05-28 11:03:09 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2010-06-07 13:37:47 +0200 |
commit | 8062fb352e6cd1d961f0fbc660779f4ad94c7508 (patch) | |
tree | da543b7a8e8eba1db86946c086dc87749d42d9a5 | |
parent | 5db362dd6792af20282e0e9a2805ee6f1b921e44 (diff) |
gl: Add an enum for tex units
Instead of hardcoding 0 for source and 1 for mask, use an enum. It's
also clearer when functions take a cairo_gl_tex_t argument instead of a
GLuint.
-rw-r--r-- | src/cairo-gl-composite.c | 20 | ||||
-rw-r--r-- | src/cairo-gl-private.h | 5 | ||||
-rw-r--r-- | src/cairo-gl-shaders.c | 34 |
3 files changed, 27 insertions, 32 deletions
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c index 55154c3a..ecd1b570 100644 --- a/src/cairo-gl-composite.c +++ b/src/cairo-gl-composite.c @@ -607,7 +607,7 @@ _cairo_gl_texture_set_attributes (cairo_gl_context_t *ctx, static void _cairo_gl_context_setup_operand (cairo_gl_context_t *ctx, - GLuint tex_unit, + cairo_gl_tex_t tex_unit, cairo_gl_operand_t *operand, unsigned int vertex_offset) { @@ -660,14 +660,14 @@ _cairo_gl_context_setup_operand (cairo_gl_context_t *ctx, static void _cairo_gl_context_destroy_operand (cairo_gl_context_t *ctx, - GLuint tex_unit) + cairo_gl_tex_t tex_unit) { memset (&ctx->operands[tex_unit], 0, sizeof (cairo_gl_operand_t)); } static void _cairo_gl_operand_setup_fixed (cairo_gl_operand_t *operand, - GLuint tex_unit) + cairo_gl_tex_t tex_unit) { switch (operand->type) { case CAIRO_GL_OPERAND_CONSTANT: @@ -709,7 +709,7 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); - _cairo_gl_operand_setup_fixed (&setup->src, 0); + _cairo_gl_operand_setup_fixed (&setup->src, CAIRO_GL_TEX_SOURCE); } /* Swizzles the source for creating the "source alpha" value @@ -751,7 +751,7 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); - _cairo_gl_operand_setup_fixed (&setup->mask, 1); + _cairo_gl_operand_setup_fixed (&setup->mask, CAIRO_GL_TEX_MASK); } static void @@ -775,7 +775,7 @@ _cairo_gl_set_mask_operand (cairo_gl_context_t *ctx, glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_ALPHA); glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); - _cairo_gl_operand_setup_fixed (&setup->mask, 1); + _cairo_gl_operand_setup_fixed (&setup->mask, CAIRO_GL_TEX_MASK); } static void @@ -1004,8 +1004,8 @@ _cairo_gl_composite_begin (cairo_gl_composite_t *setup, glVertexPointer (2, GL_FLOAT, ctx->vertex_size, NULL); glEnableClientState (GL_VERTEX_ARRAY); - _cairo_gl_context_setup_operand (ctx, 0, &setup->src, dst_size); - _cairo_gl_context_setup_operand (ctx, 1, &setup->mask, dst_size + src_size); + _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_SOURCE, &setup->src, dst_size); + _cairo_gl_context_setup_operand (ctx, CAIRO_GL_TEX_MASK, &setup->mask, dst_size + src_size); _cairo_gl_set_src_operand (ctx, setup); if (setup->has_component_alpha) @@ -1250,8 +1250,8 @@ _cairo_gl_composite_end (cairo_gl_context_t *ctx, glDisable (GL_TEXTURE_1D); glDisable (ctx->tex_target); - _cairo_gl_context_destroy_operand (ctx, 0); - _cairo_gl_context_destroy_operand (ctx, 1); + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_SOURCE); + _cairo_gl_context_destroy_operand (ctx, CAIRO_GL_TEX_MASK); ctx->pre_shader = NULL; diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h index 070f79ce..9e653f48 100644 --- a/src/cairo-gl-private.h +++ b/src/cairo-gl-private.h @@ -88,6 +88,11 @@ typedef struct cairo_gl_glyph_cache { cairo_surface_pattern_t pattern; } cairo_gl_glyph_cache_t; +typedef enum cairo_gl_tex { + CAIRO_GL_TEX_SOURCE = 0, + CAIRO_GL_TEX_MASK = 1 +} cairo_gl_tex_t; + typedef enum cairo_gl_operand_type { CAIRO_GL_OPERAND_NONE, CAIRO_GL_OPERAND_CONSTANT, diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c index fdd4b673..2b551192 100644 --- a/src/cairo-gl-shaders.c +++ b/src/cairo-gl-shaders.c @@ -87,7 +87,7 @@ typedef struct cairo_gl_shader_impl { void (*bind_texture) (cairo_gl_shader_t *shader, const char *name, - GLuint tex_unit); + cairo_gl_tex_t tex_unit); void (*use) (cairo_gl_shader_t *shader); @@ -243,7 +243,7 @@ bind_matrix_arb (cairo_gl_shader_t *shader, static void bind_texture_arb (cairo_gl_shader_t *shader, const char *name, - GLuint tex_unit) + cairo_gl_tex_t tex_unit) { GLint location = glGetUniformLocationARB (shader->program, name); assert (location != -1); @@ -397,7 +397,7 @@ bind_matrix_core_2_0 (cairo_gl_shader_t *shader, const char *name, cairo_matrix_ } static void -bind_texture_core_2_0 (cairo_gl_shader_t *shader, const char *name, GLuint tex_unit) +bind_texture_core_2_0 (cairo_gl_shader_t *shader, const char *name, cairo_gl_tex_t tex_unit) { GLint location = glGetUniformLocation (shader->program, name); assert (location != -1); @@ -559,12 +559,6 @@ _cairo_gl_shader_fini (cairo_gl_context_t *ctx, ctx->shader_impl->destroy_program (shader->program); } -typedef enum cairo_gl_operand_name { - CAIRO_GL_OPERAND_SOURCE, - CAIRO_GL_OPERAND_MASK, - CAIRO_GL_OPERAND_DEST -} cairo_gl_operand_name_t; - static const char *operand_names[] = { "source", "mask", "dest" }; static cairo_gl_var_type_t @@ -589,7 +583,7 @@ cairo_gl_operand_get_var_type (cairo_gl_operand_type_t type) static void cairo_gl_shader_emit_variable (cairo_output_stream_t *stream, cairo_gl_var_type_t type, - cairo_gl_operand_name_t name) + cairo_gl_tex_t name) { switch (type) { default: @@ -612,7 +606,7 @@ cairo_gl_shader_emit_variable (cairo_output_stream_t *stream, static void cairo_gl_shader_emit_vertex (cairo_output_stream_t *stream, cairo_gl_var_type_t type, - cairo_gl_operand_name_t name) + cairo_gl_tex_t name) { switch (type) { default: @@ -643,18 +637,16 @@ cairo_gl_shader_get_vertex_source (cairo_gl_var_type_t src, unsigned int length; cairo_status_t status; - cairo_gl_shader_emit_variable (stream, src, CAIRO_GL_OPERAND_SOURCE); - cairo_gl_shader_emit_variable (stream, mask, CAIRO_GL_OPERAND_MASK); - cairo_gl_shader_emit_variable (stream, dest, CAIRO_GL_OPERAND_DEST); + cairo_gl_shader_emit_variable (stream, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_variable (stream, mask, CAIRO_GL_TEX_MASK); _cairo_output_stream_printf (stream, "void main()\n" "{\n" " gl_Position = ftransform();\n"); - cairo_gl_shader_emit_vertex (stream, src, CAIRO_GL_OPERAND_SOURCE); - cairo_gl_shader_emit_vertex (stream, mask, CAIRO_GL_OPERAND_MASK); - cairo_gl_shader_emit_vertex (stream, dest, CAIRO_GL_OPERAND_DEST); + cairo_gl_shader_emit_vertex (stream, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_vertex (stream, mask, CAIRO_GL_TEX_MASK); _cairo_output_stream_write (stream, "}\n\0", 3); @@ -671,7 +663,7 @@ static void cairo_gl_shader_emit_color (cairo_output_stream_t *stream, GLuint tex_target, cairo_gl_operand_type_t type, - cairo_gl_operand_name_t name) + cairo_gl_tex_t name) { const char *namestr = operand_names[name]; const char *rectstr = (tex_target == GL_TEXTURE_RECTANGLE_EXT ? "Rect" : ""); @@ -781,10 +773,8 @@ cairo_gl_shader_get_fragment_source (GLuint tex_target, unsigned int length; cairo_status_t status; - cairo_gl_shader_emit_color (stream, tex_target, src, CAIRO_GL_OPERAND_SOURCE); - cairo_gl_shader_emit_color (stream, tex_target, mask, CAIRO_GL_OPERAND_MASK); - if (dest != CAIRO_GL_OPERAND_NONE) - cairo_gl_shader_emit_color (stream, tex_target, dest, CAIRO_GL_OPERAND_DEST); + cairo_gl_shader_emit_color (stream, tex_target, src, CAIRO_GL_TEX_SOURCE); + cairo_gl_shader_emit_color (stream, tex_target, mask, CAIRO_GL_TEX_MASK); _cairo_output_stream_printf (stream, "void main()\n" |