* clutter/cogl/gles/cogl-gles2-wrapper.h (CoglGles2Wrapper): Added

uniforms for alpha testing.

	* clutter/cogl/gles/cogl-gles2-wrapper.c
	(cogl_gles2_wrapper_init): Get the uniforms for alpha testing
	settings.
	(cogl_wrap_glEnable, cogl_wrap_glDisable): Enable/disable alpha
	testing.
	(cogl_wrap_glAlphaFunc): Filled in the wrapper.

	* clutter/cogl/gles/cogl-fixed-fragment-shader.glsl: Added alpha
	testing.

	* clutter/cogl/gles/cogl-gles2-wrapper.h:
	* clutter/cogl/gles/cogl-gles2-wrapper.c
	(cogl_wrap_glGetIntegerv): Added a wrapper for glGetIntegerv so
	that it can report zero clip planes.

	* clutter/cogl/gles/cogl.c:
	* clutter/cogl/gles/cogl-texture.c: Use the wrapped version of
	glGetIntegerv

	* clutter/cogl/gles/cogl-primitives.c (_cogl_path_fill_nodes): Use
	_cogl_features_available to check for the stencil buffer instead
	of an #ifdef. The stencil buffer is available in the default
	profile for the GLES 2 simulator.
This commit is contained in:
Neil Roberts 2008-05-29 13:29:04 +00:00
parent 52b231b0b5
commit 71133b3d0e
7 changed files with 305 additions and 172 deletions

View File

@ -1,3 +1,33 @@
2008-05-29 Neil Roberts <neil@o-hand.com>
* clutter/cogl/gles/cogl-gles2-wrapper.h (CoglGles2Wrapper): Added
uniforms for alpha testing.
* clutter/cogl/gles/cogl-gles2-wrapper.c
(cogl_gles2_wrapper_init): Get the uniforms for alpha testing
settings.
(cogl_wrap_glEnable, cogl_wrap_glDisable): Enable/disable alpha
testing.
(cogl_wrap_glAlphaFunc): Filled in the wrapper.
* clutter/cogl/gles/cogl-fixed-fragment-shader.glsl: Added alpha
testing.
* clutter/cogl/gles/cogl-gles2-wrapper.h:
* clutter/cogl/gles/cogl-gles2-wrapper.c
(cogl_wrap_glGetIntegerv): Added a wrapper for glGetIntegerv so
that it can report zero clip planes.
* clutter/cogl/gles/cogl.c:
* clutter/cogl/gles/cogl-texture.c: Use the wrapped version of
glGetIntegerv
* clutter/cogl/gles/cogl-primitives.c (_cogl_path_fill_nodes): Use
_cogl_features_available to check for the stencil buffer instead
of an #ifdef. The stencil buffer is available in the default
profile for the GLES 2 simulator.
2008-05-29 Emmanuele Bassi <ebassi@openedhand.com> 2008-05-29 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Check the --with switches as soon as we have them, * configure.ac: Check the --with switches as soon as we have them,

View File

@ -12,6 +12,20 @@ uniform bool alpha_only;
uniform bool fog_enabled; uniform bool fog_enabled;
uniform vec4 fog_color; uniform vec4 fog_color;
/* Alpha test options */
uniform bool alpha_test_enabled;
uniform int alpha_test_func;
uniform float alpha_test_ref;
/* Alpha test functions */
const int GL_NEVER = 0x0200;
const int GL_LESS = 0x0201;
const int GL_EQUAL = 0x0202;
const int GL_LEQUAL = 0x0203;
const int GL_GREATER = 0x0204;
const int GL_NOTEQUAL = 0x0205;
const int GL_GEQUAL = 0x0206;
void void
main (void) main (void)
{ {
@ -35,4 +49,41 @@ main (void)
if (fog_enabled) if (fog_enabled)
/* Mix the calculated color with the fog color */ /* Mix the calculated color with the fog color */
gl_FragColor.rgb = mix (fog_color.rgb, gl_FragColor.rgb, fog_amount); gl_FragColor.rgb = mix (fog_color.rgb, gl_FragColor.rgb, fog_amount);
/* Alpha testing */
if (alpha_test_enabled)
{
if (alpha_test_func == GL_NEVER)
discard;
else if (alpha_test_func == GL_LESS)
{
if (gl_FragColor.a >= alpha_test_ref)
discard;
}
else if (alpha_test_func == GL_EQUAL)
{
if (gl_FragColor.a != alpha_test_ref)
discard;
}
else if (alpha_test_func == GL_LEQUAL)
{
if (gl_FragColor.a > alpha_test_ref)
discard;
}
else if (alpha_test_func == GL_GREATER)
{
if (gl_FragColor.a <= alpha_test_ref)
discard;
}
else if (alpha_test_func == GL_NOTEQUAL)
{
if (gl_FragColor.a == alpha_test_ref)
discard;
}
else if (alpha_test_func == GL_GEQUAL)
{
if (gl_FragColor.a < alpha_test_ref)
discard;
}
}
} }

View File

@ -164,6 +164,13 @@ cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
wrapper->fog_color_uniform wrapper->fog_color_uniform
= glGetUniformLocation (wrapper->program, "fog_color"); = glGetUniformLocation (wrapper->program, "fog_color");
wrapper->alpha_test_enabled_uniform
= glGetUniformLocation (wrapper->program, "alpha_test_enabled");
wrapper->alpha_test_func_uniform
= glGetUniformLocation (wrapper->program, "alpha_test_func");
wrapper->alpha_test_ref_uniform
= glGetUniformLocation (wrapper->program, "alpha_test_ref");
/* Always use the first texture unit */ /* Always use the first texture unit */
glUniform1i (wrapper->bound_texture_uniform, 0); glUniform1i (wrapper->bound_texture_uniform, 0);
@ -184,6 +191,10 @@ cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper)
cogl_wrap_glFogx (GL_FOG_START, 0); cogl_wrap_glFogx (GL_FOG_START, 0);
cogl_wrap_glFogx (GL_FOG_END, 1); cogl_wrap_glFogx (GL_FOG_END, 1);
cogl_wrap_glFogxv (GL_FOG_COLOR, default_fog_color); cogl_wrap_glFogxv (GL_FOG_COLOR, default_fog_color);
/* Initialize alpha testing */
cogl_wrap_glDisable (GL_ALPHA_TEST);
cogl_wrap_glAlphaFunc (GL_ALWAYS, 0.0f);
} }
void void
@ -567,6 +578,10 @@ cogl_wrap_glEnable (GLenum cap)
glUniform1i (w->fog_enabled_uniform, GL_TRUE); glUniform1i (w->fog_enabled_uniform, GL_TRUE);
break; break;
case GL_ALPHA_TEST:
glUniform1i (w->alpha_test_enabled_uniform, GL_TRUE);
break;
default: default:
glEnable (cap); glEnable (cap);
} }
@ -587,6 +602,10 @@ cogl_wrap_glDisable (GLenum cap)
glUniform1i (w->fog_enabled_uniform, GL_FALSE); glUniform1i (w->fog_enabled_uniform, GL_FALSE);
break; break;
case GL_ALPHA_TEST:
glUniform1i (w->alpha_test_enabled_uniform, GL_FALSE);
break;
default: default:
glDisable (cap); glDisable (cap);
} }
@ -629,7 +648,15 @@ cogl_wrap_glDisableClientState (GLenum array)
void void
cogl_wrap_glAlphaFunc (GLenum func, GLclampf ref) cogl_wrap_glAlphaFunc (GLenum func, GLclampf ref)
{ {
/* FIXME */ _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
if (ref < 0.0f)
ref = 0.0f;
else if (ref > 1.0f)
ref = 1.0f;
glUniform1i (w->alpha_test_func_uniform, func);
glUniform1f (w->alpha_test_ref_uniform, ref);
} }
void void
@ -656,6 +683,23 @@ cogl_gles2_float_array_to_fixed (int size, const GLfloat *floats,
*(fixeds++) = CLUTTER_FLOAT_TO_FIXED (*(floats++)); *(fixeds++) = CLUTTER_FLOAT_TO_FIXED (*(floats++));
} }
void
cogl_wrap_glGetIntegerv (GLenum pname, GLint *params)
{
_COGL_GET_GLES2_WRAPPER (w, NO_RETVAL);
switch (pname)
{
case GL_MAX_CLIP_PLANES:
*params = 0;
break;
default:
glGetIntegerv (pname, params);
break;
}
}
void void
cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params) cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params)
{ {

View File

@ -57,6 +57,10 @@ struct _CoglGles2Wrapper
GLint fog_end_uniform; GLint fog_end_uniform;
GLint fog_color_uniform; GLint fog_color_uniform;
GLint alpha_test_enabled_uniform;
GLint alpha_test_func_uniform;
GLint alpha_test_ref_uniform;
GLuint matrix_mode; GLuint matrix_mode;
GLfloat modelview_stack[COGL_GLES2_MODELVIEW_STACK_SIZE * 16]; GLfloat modelview_stack[COGL_GLES2_MODELVIEW_STACK_SIZE * 16];
GLuint modelview_stack_pos; GLuint modelview_stack_pos;
@ -149,6 +153,7 @@ void cogl_wrap_glColor4x (GLclampx r, GLclampx g, GLclampx b, GLclampx a);
void cogl_wrap_glClipPlanex (GLenum plane, GLfixed *equation); void cogl_wrap_glClipPlanex (GLenum plane, GLfixed *equation);
void cogl_wrap_glGetIntegerv (GLenum pname, GLint *params);
void cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params); void cogl_wrap_glGetFixedv (GLenum pname, GLfixed *params);
void cogl_wrap_glFogx (GLenum pname, GLfixed param); void cogl_wrap_glFogx (GLenum pname, GLfixed param);
@ -191,6 +196,7 @@ void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture,
#define cogl_wrap_glAlphaFunc glAlphaFunc #define cogl_wrap_glAlphaFunc glAlphaFunc
#define cogl_wrap_glColor4x glColor4x #define cogl_wrap_glColor4x glColor4x
#define cogl_wrap_glClipPlanex glClipPlanex #define cogl_wrap_glClipPlanex glClipPlanex
#define cogl_wrap_glGetIntegerv glGetIntegerv
#define cogl_wrap_glGetFixedv glGetFixedv #define cogl_wrap_glGetFixedv glGetFixedv
#define cogl_wrap_glFogx glFogx #define cogl_wrap_glFogx glFogx
#define cogl_wrap_glFogxv glFogxv #define cogl_wrap_glFogxv glFogxv

View File

@ -172,8 +172,8 @@ _cogl_path_fill_nodes ()
bounds_w = CLUTTER_FIXED_CEIL (ctx->path_nodes_max.x - ctx->path_nodes_min.x); bounds_w = CLUTTER_FIXED_CEIL (ctx->path_nodes_max.x - ctx->path_nodes_min.x);
bounds_h = CLUTTER_FIXED_CEIL (ctx->path_nodes_max.y - ctx->path_nodes_min.y); bounds_h = CLUTTER_FIXED_CEIL (ctx->path_nodes_max.y - ctx->path_nodes_min.y);
#if GOT_WORKING_STENCIL_BUFFER if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{
GE( glClear (GL_STENCIL_BUFFER_BIT) ); GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( cogl_wrap_glEnable (GL_STENCIL_TEST) ); GE( cogl_wrap_glEnable (GL_STENCIL_TEST) );
@ -191,15 +191,16 @@ _cogl_path_fill_nodes ()
GE( glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO) ); GE( glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO) );
GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) ); GE( glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) );
cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h); cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h);
GE( cogl_wrap_glDisable (GL_STENCIL_TEST) ); GE( cogl_wrap_glDisable (GL_STENCIL_TEST) );
#else }
else
{ {
/* This is our edge list it stores intersections between our curve and /* This is our edge list it stores intersections between our
* scanlines, it should probably be implemented with a data structure * curve and scanlines, it should probably be implemented with a
* that has smaller overhead for inserting the curve/scanline intersections. * data structure that has smaller overhead for inserting the
* curve/scanline intersections.
*/ */
GSList *scanlines[bounds_h]; GSList *scanlines[bounds_h];
@ -228,7 +229,7 @@ _cogl_path_fill_nodes ()
gint dy; gint dy;
gint y; gint y;
fill_close: fill_close:
dx = dest_x - prev_x; dx = dest_x - prev_x;
dy = dest_y - prev_y; dy = dest_y - prev_y;
@ -271,7 +272,8 @@ fill_close:
prev_x = dest_x; prev_x = dest_x;
prev_y = dest_y; prev_y = dest_y;
/* if we're on the last knot, fake the first vertex being a next one */ /* if we're on the last knot, fake the first vertex being a
next one */
if (ctx->path_nodes_size == i+1) if (ctx->path_nodes_size == i+1)
{ {
dest_x = first_x; dest_x = first_x;
@ -321,7 +323,8 @@ fill_close:
x1 = CLUTTER_INT_TO_FIXED (GPOINTER_TO_INT (next->data)); x1 = CLUTTER_INT_TO_FIXED (GPOINTER_TO_INT (next->data));
y0 = CLUTTER_INT_TO_FIXED (bounds_y + i); y0 = CLUTTER_INT_TO_FIXED (bounds_y + i);
y1 = CLUTTER_INT_TO_FIXED (bounds_y + i + 1) + 2048; y1 = CLUTTER_INT_TO_FIXED (bounds_y + i + 1) + 2048;
/* render scanlines 1.0625 high to avoid gaps when transformed */ /* render scanlines 1.0625 high to avoid gaps when
transformed */
coords[span_no * 12 + 0] = x0; coords[span_no * 12 + 0] = x0;
coords[span_no * 12 + 1] = y0; coords[span_no * 12 + 1] = y0;
@ -352,6 +355,5 @@ fill_close:
g_free (coords); g_free (coords);
} }
} }
#endif
} }

View File

@ -381,7 +381,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888); bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
/* Viewport needs to have some size and be inside the window for this */ /* Viewport needs to have some size and be inside the window for this */
GE( glGetIntegerv (GL_VIEWPORT, viewport) ); GE( cogl_wrap_glGetIntegerv (GL_VIEWPORT, viewport) );
if (viewport[0] < 0 || viewport[1] < 0 || if (viewport[0] < 0 || viewport[1] < 0 ||
viewport[2] <= 0 || viewport[3] <= 0) viewport[2] <= 0 || viewport[3] <= 0)
@ -422,10 +422,10 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
still doesn't seem to have an alpha buffer. This might be just still doesn't seem to have an alpha buffer. This might be just
a PowerVR issue. a PowerVR issue.
GLint r_bits, g_bits, b_bits, a_bits; GLint r_bits, g_bits, b_bits, a_bits;
GE( glGetIntegerv (GL_ALPHA_BITS, &a_bits) ); GE( cogl_wrap_glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
GE( glGetIntegerv (GL_RED_BITS, &r_bits) ); GE( cogl_wrap_glGetIntegerv (GL_RED_BITS, &r_bits) );
GE( glGetIntegerv (GL_GREEN_BITS, &g_bits) ); GE( cogl_wrap_glGetIntegerv (GL_GREEN_BITS, &g_bits) );
GE( glGetIntegerv (GL_BLUE_BITS, &b_bits) ); GE( cogl_wrap_glGetIntegerv (GL_BLUE_BITS, &b_bits) );
printf ("R bits: %d\n", r_bits); printf ("R bits: %d\n", r_bits);
printf ("G bits: %d\n", g_bits); printf ("G bits: %d\n", g_bits);
printf ("B bits: %d\n", b_bits); printf ("B bits: %d\n", b_bits);

View File

@ -482,11 +482,11 @@ _cogl_features_init ()
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( glGetIntegerv (GL_STENCIL_BITS, &stencil_bits) ); GE( cogl_wrap_glGetIntegerv (GL_STENCIL_BITS, &stencil_bits) );
if (stencil_bits > 0) if (stencil_bits > 0)
flags |= COGL_FEATURE_STENCIL_BUFFER; flags |= COGL_FEATURE_STENCIL_BUFFER;
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) ); GE( cogl_wrap_glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
if (max_clip_planes >= 4) if (max_clip_planes >= 4)
flags |= COGL_FEATURE_FOUR_CLIP_PLANES; flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
@ -538,13 +538,13 @@ void
cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha) cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
{ {
if (red) if (red)
GE( glGetIntegerv(GL_RED_BITS, red) ); GE( cogl_wrap_glGetIntegerv(GL_RED_BITS, red) );
if (green) if (green)
GE( glGetIntegerv(GL_GREEN_BITS, green) ); GE( cogl_wrap_glGetIntegerv(GL_GREEN_BITS, green) );
if (blue) if (blue)
GE( glGetIntegerv(GL_BLUE_BITS, blue) ); GE( cogl_wrap_glGetIntegerv(GL_BLUE_BITS, blue) );
if (alpha) if (alpha)
GE( glGetIntegerv(GL_ALPHA_BITS, alpha ) ); GE( cogl_wrap_glGetIntegerv(GL_ALPHA_BITS, alpha ) );
} }
void void