[cairo-commit] 3 commits - src/cairo-gl-composite.c
Benjamin Otte
company at kemper.freedesktop.org
Thu May 20 04:53:45 PDT 2010
src/cairo-gl-composite.c | 141 +++++++++++++++++------------------------------
1 file changed, 51 insertions(+), 90 deletions(-)
New commits:
commit 1586f7740ad436447ac75c6b869da7446172a63c
Author: Benjamin Otte <otte at gnome.org>
Date: Thu May 20 13:17:52 2010 +0200
gl: Refactor fixed function setup code
In particular get rid of the _cairo_gl_set_tex_combine_constant_color()
function by inlining it and move common glTexEnv calls out of the
switch statement.
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 3ecc6b6..d75ce85 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -658,37 +658,6 @@ _cairo_gl_operand_setup_texture (cairo_gl_context_t *ctx,
}
static void
-_cairo_gl_set_tex_combine_constant_color (cairo_gl_context_t *ctx,
- cairo_gl_composite_t *setup,
- int tex_unit,
- GLfloat *color)
-{
- glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- if (tex_unit == 0) {
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
- } else {
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
- }
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_CONSTANT);
- if (tex_unit == 0) {
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
- } else {
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_ALPHA);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
-
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
- }
-}
-
-static void
_cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
@@ -699,18 +668,22 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
glActiveTexture (GL_TEXTURE0);
+ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
+
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
- _cairo_gl_set_tex_combine_constant_color (ctx, setup, 0,
- setup->src.constant.color);
+ glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, setup->src.constant.color);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_CONSTANT);
break;
case CAIRO_GL_OPERAND_TEXTURE:
/* Set up the constant color we use to set color to 0 if needed. */
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant_color);
/* Set up the combiner to just set color to the sampled texture. */
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
/* Force the src color to 0 if the surface should be
* alpha-only. We may have a teximage with color bits if
@@ -722,8 +695,6 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
else
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
break;
default:
@@ -752,21 +723,24 @@ _cairo_gl_set_src_alpha_operand (cairo_gl_context_t *ctx,
glActiveTexture (GL_TEXTURE0);
+ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
+
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
constant_color[0] = setup->src.constant.color[3];
constant_color[1] = setup->src.constant.color[3];
constant_color[2] = setup->src.constant.color[3];
constant_color[3] = setup->src.constant.color[3];
- _cairo_gl_set_tex_combine_constant_color (ctx, setup, 0,
- constant_color);
+ glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant_color);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
break;
case CAIRO_GL_OPERAND_TEXTURE:
/* Set up the combiner to just set color to the sampled texture. */
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
-
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_ALPHA);
@@ -801,8 +775,11 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
+
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
@@ -811,10 +788,8 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
setup->mask.constant.color);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_CONSTANT);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT);
break;
case CAIRO_GL_OPERAND_TEXTURE:
/* Set up the constant color we use to set color to 0 if needed. */
@@ -826,12 +801,10 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
*/
if (setup->mask.texture.surface == NULL ||
setup->mask.texture.surface->base.content != CAIRO_CONTENT_ALPHA)
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE1);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE1);
else
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE1);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE1);
break;
case CAIRO_GL_OPERAND_LINEAR_GRADIENT:
@@ -854,50 +827,39 @@ _cairo_gl_set_mask_operand (cairo_gl_context_t *ctx,
glActiveTexture (GL_TEXTURE1);
+ glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
+ glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
+
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
+
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_ALPHA);
+ glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
+
switch (setup->mask.type) {
case CAIRO_GL_OPERAND_CONSTANT:
- _cairo_gl_set_tex_combine_constant_color (ctx, setup, 1,
- setup->mask.constant.color);
+ glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, setup->mask.constant.color);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
+ glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT);
break;
-
case CAIRO_GL_OPERAND_TEXTURE:
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
-
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
-
/* IN: dst.argb = src.argb * mask.aaaa */
glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE1);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE1);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_ALPHA);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
- break;
- case CAIRO_GL_OPERAND_LINEAR_GRADIENT:
- case CAIRO_GL_OPERAND_RADIAL_GRADIENT:
- case CAIRO_GL_OPERAND_NONE:
break;
case CAIRO_GL_OPERAND_SPANS:
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
-
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
-
glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
glTexEnvi (GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PRIMARY_COLOR);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_ALPHA);
- glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
break;
case CAIRO_GL_OPERAND_COUNT:
default:
ASSERT_NOT_REACHED;
+ case CAIRO_GL_OPERAND_LINEAR_GRADIENT:
+ case CAIRO_GL_OPERAND_RADIAL_GRADIENT:
+ case CAIRO_GL_OPERAND_NONE:
break;
}
}
commit 4889090c76bdab5e4eb887593caf5d5a34f90864
Author: Benjamin Otte <otte at gnome.org>
Date: Thu May 20 12:13:43 2010 +0200
gl: set the active texture before fiddling with with glTexEnv
fixes the fixed function pipeline
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 13c4fb7..3ecc6b6 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -697,6 +697,8 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
if (ctx->current_shader)
return;
+ glActiveTexture (GL_TEXTURE0);
+
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
_cairo_gl_set_tex_combine_constant_color (ctx, setup, 0,
@@ -748,6 +750,8 @@ _cairo_gl_set_src_alpha_operand (cairo_gl_context_t *ctx,
if (ctx->current_shader)
return;
+ glActiveTexture (GL_TEXTURE0);
+
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
constant_color[0] = setup->src.constant.color[3];
@@ -791,6 +795,8 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
if (ctx->current_shader)
return;
+ glActiveTexture (GL_TEXTURE1);
+
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
@@ -846,6 +852,8 @@ _cairo_gl_set_mask_operand (cairo_gl_context_t *ctx,
if (ctx->current_shader)
return;
+ glActiveTexture (GL_TEXTURE1);
+
switch (setup->mask.type) {
case CAIRO_GL_OPERAND_CONSTANT:
_cairo_gl_set_tex_combine_constant_color (ctx, setup, 1,
commit 3cff2da912150868390bf4b9df166c88b3dfcf2e
Author: Benjamin Otte <otte at gnome.org>
Date: Thu May 20 12:03:18 2010 +0200
gl: Remove unused variables
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 0df0502..13c4fb7 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -692,14 +692,11 @@ static void
_cairo_gl_set_src_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
- cairo_surface_attributes_t *src_attributes;
GLfloat constant_color[4] = {0.0, 0.0, 0.0, 0.0};
if (ctx->current_shader)
return;
- src_attributes = &setup->src.texture.attributes;
-
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
_cairo_gl_set_tex_combine_constant_color (ctx, setup, 0,
@@ -747,13 +744,10 @@ _cairo_gl_set_src_alpha_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
GLfloat constant_color[4] = {0.0, 0.0, 0.0, 0.0};
- cairo_surface_attributes_t *src_attributes;
if (ctx->current_shader)
return;
- src_attributes = &setup->src.texture.attributes;
-
switch (setup->src.type) {
case CAIRO_GL_OPERAND_CONSTANT:
constant_color[0] = setup->src.constant.color[3];
@@ -792,14 +786,11 @@ static void
_cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx,
cairo_gl_composite_t *setup)
{
- cairo_surface_attributes_t *mask_attributes;
GLfloat constant_color[4] = {0.0, 0.0, 0.0, 0.0};
if (ctx->current_shader)
return;
- mask_attributes = &setup->mask.texture.attributes;
-
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
More information about the cairo-commit
mailing list