diff --git a/cogl-material.h b/cogl-material.h index 915e447e5..e8bf65632 100644 --- a/cogl-material.h +++ b/cogl-material.h @@ -446,14 +446,14 @@ void cogl_material_remove_layer (CoglHandle material, */ typedef enum _CoglMaterialLayerCombineFunc { - COGL_MATERIAL_LAYER_COMBINE_FUNC_REPLACE = GL_REPLACE, - COGL_MATERIAL_LAYER_COMBINE_FUNC_MODULATE = GL_MODULATE, - COGL_MATERIAL_LAYER_COMBINE_FUNC_ADD = GL_ADD, - COGL_MATERIAL_LAYER_COMBINE_FUNC_ADD_SIGNED = GL_ADD_SIGNED, - COGL_MATERIAL_LAYER_COMBINE_FUNC_INTERPOLATE = GL_INTERPOLATE, - COGL_MATERIAL_LAYER_COMBINE_FUNC_SUBTRACT = GL_SUBTRACT, - COGL_MATERIAL_LAYER_COMBINE_FUNC_DOT3_RGB = GL_DOT3_RGB, - COGL_MATERIAL_LAYER_COMBINE_FUNC_DOT3_RGBA = GL_DOT3_RGBA + COGL_MATERIAL_LAYER_COMBINE_FUNC_REPLACE = CGL_REPLACE, + COGL_MATERIAL_LAYER_COMBINE_FUNC_MODULATE = CGL_MODULATE, + COGL_MATERIAL_LAYER_COMBINE_FUNC_ADD = CGL_ADD, + COGL_MATERIAL_LAYER_COMBINE_FUNC_ADD_SIGNED = CGL_ADD_SIGNED, + COGL_MATERIAL_LAYER_COMBINE_FUNC_INTERPOLATE = CGL_INTERPOLATE, + COGL_MATERIAL_LAYER_COMBINE_FUNC_SUBTRACT = CGL_SUBTRACT, + COGL_MATERIAL_LAYER_COMBINE_FUNC_DOT3_RGB = CGL_DOT3_RGB, + COGL_MATERIAL_LAYER_COMBINE_FUNC_DOT3_RGBA = CGL_DOT3_RGBA } CoglMaterialLayerCombineFunc; /** @@ -583,9 +583,9 @@ typedef enum _CoglMaterialLayerCombineSrc COGL_MATERIAL_LAYER_COMBINE_SRC_TEXTURE7 = GL_TEXTURE7, /* .. who would ever need more than 8 texture layers.. :-) */ - COGL_MATERIAL_LAYER_COMBINE_SRC_CONSTANT = GL_CONSTANT, - COGL_MATERIAL_LAYER_COMBINE_SRC_PRIMARY_COLOR = GL_PRIMARY_COLOR, - COGL_MATERIAL_LAYER_COMBINE_SRC_PREVIOUS = GL_PREVIOUS + COGL_MATERIAL_LAYER_COMBINE_SRC_CONSTANT = CGL_CONSTANT, + COGL_MATERIAL_LAYER_COMBINE_SRC_PRIMARY_COLOR = CGL_PRIMARY_COLOR, + COGL_MATERIAL_LAYER_COMBINE_SRC_PREVIOUS = CGL_PREVIOUS } CoglMaterialLayerCombineSrc; /** diff --git a/common/cogl-material.c b/common/cogl-material.c index bd2eded36..09a12d107 100644 --- a/common/cogl-material.c +++ b/common/cogl-material.c @@ -9,6 +9,7 @@ #include "cogl-handle.h" #include "cogl-material-private.h" +#include "cogl-texture-private.h" #include #include @@ -18,7 +19,7 @@ */ #ifdef HAVE_COGL_GLES2 -#define glAlphaFunc cogl_wrap_glAlphaFunc +#include "../gles/cogl-gles2-wrapper.h" #endif static void _cogl_material_free (CoglMaterial *tex); diff --git a/common/cogl-vertex-buffer.c b/common/cogl-vertex-buffer.c index 0b617244c..e42c7ba17 100644 --- a/common/cogl-vertex-buffer.c +++ b/common/cogl-vertex-buffer.c @@ -159,14 +159,7 @@ #elif defined (HAVE_COGL_GLES2) -#define glVertexPointer cogl_wrap_glVertexPointer -#define glNormalPointer cogl_wrap_glNormalPointer -#define glTexCoordPointer cogl_wrap_glTexCoordPointer -#define glColorPointer cogl_wrap_glColorPointer -#define glDrawArrays cogl_wrap_glDrawArrays - -#define glEnableClientState cogl_wrap_glEnableClientState -#define glDisableClientState cogl_wrap_glDisableClientState +#include "../gles/cogl-gles2-wrapper.h" #endif diff --git a/gl/cogl-defines.h.in b/gl/cogl-defines.h.in index eea0f3d14..b23cbc681 100644 --- a/gl/cogl-defines.h.in +++ b/gl/cogl-defines.h.in @@ -668,6 +668,9 @@ typedef GLuint COGLuint; #define CGL_COMPRESSED_SLUMINANCE_EXT GL_COMPRESSED_SLUMINANCE_EXT #define CGL_COMPRESSED_SLUMINANCE_ALPHA_EXT GL_COMPRESSED_SLUMINANCE_ALPHA_EXT +#define CGL_DOT3_RGB GL_DOT3_RGB +#define CGL_DOT3_RGBA GL_DOT3_RGBA + /* extras */ #define CGL_TEXTURE_2D GL_TEXTURE_2D diff --git a/gles/cogl-defines.h.in b/gles/cogl-defines.h.in index 3d69a080e..a40d5d610 100644 --- a/gles/cogl-defines.h.in +++ b/gles/cogl-defines.h.in @@ -263,9 +263,6 @@ G_BEGIN_DECLS #define CGL_LIGHT_MODEL_TWO_SIDE GL_LIGHT_MODEL_TWO_SIDE /* LightParameter */ -#define CGL_AMBIENT GL_AMBIENT -#define CGL_DIFFUSE GL_DIFFUSE -#define CGL_SPECULAR GL_SPECULAR #define CGL_POSITION GL_POSITION #define CGL_SPOT_DIRECTION GL_SPOT_DIRECTION #define CGL_SPOT_EXPONENT GL_SPOT_EXPONENT @@ -301,8 +298,6 @@ G_BEGIN_DECLS #define CGL_SET GL_SET /* MaterialParameter */ -#define CGL_EMISSION GL_EMISSION -#define CGL_SHININESS GL_SHININESS #define CGL_AMBIENT_AND_DIFFUSE GL_AMBIENT_AND_DIFFUSE /* MatrixMode */ @@ -354,9 +349,7 @@ G_BEGIN_DECLS #define CGL_EXTENSIONS GL_EXTENSIONS /* TextureEnvMode */ -#define CGL_MODULATE GL_MODULATE #define CGL_DECAL GL_DECAL -#define CGL_ADD GL_ADD /* GL_BLEND */ /* GL_REPLACE */ @@ -410,16 +403,7 @@ G_BEGIN_DECLS #define CGL_BUFFER_SIZE GL_BUFFER_SIZE #define CGL_BUFFER_USAGE GL_BUFFER_USAGE #define CGL_BUFFER_ACCESS GL_BUFFER_ACCESS -#define CGL_SUBTRACT GL_SUBTRACT -#define CGL_COMBINE GL_COMBINE -#define CGL_COMBINE_RGB GL_COMBINE_RGB -#define CGL_COMBINE_ALPHA GL_COMBINE_ALPHA #define CGL_RGB_SCALE GL_RGB_SCALE -#define CGL_ADD_SIGNED GL_ADD_SIGNED -#define CGL_INTERPOLATE GL_INTERPOLATE -#define CGL_CONSTANT GL_CONSTANT -#define CGL_PRIMARY_COLOR GL_PRIMARY_COLOR -#define CGL_PREVIOUS GL_PREVIOUS #define CGL_ALPHA_SCALE GL_ALPHA_SCALE #define CGL_POINT_SPRITE_OES GL_POINT_SPRITE_OES #define CGL_COORD_REPLACE_OES GL_COORD_REPLACE_OES @@ -478,6 +462,189 @@ typedef GLuint COGLuint; #define CLUTTER_COGL_HAS_GLES 1 +/* These aren't always defined under GLES 2 but if they are then we + should probably use the GL_* macro instead of assuming the + number */ +#ifdef GL_MODULATE +#define CGL_MODULATE GL_MODULATE +#else +#define CGL_MODULATE 0x2100 +#endif + +#ifdef GL_ADD +#define CGL_ADD GL_ADD +#else +#define CGL_ADD 0x0104 +#endif + +#ifdef GL_ADD_SIGNED +#define CGL_ADD_SIGNED GL_ADD_SIGNED +#else +#define CGL_ADD_SIGNED 0x8574 +#endif + +#ifdef GL_INTERPOLATE +#define CGL_INTERPOLATE GL_INTERPOLATE +#else +#define CGL_INTERPOLATE 0x8575 +#endif + +#ifdef GL_SUBTRACT +#define CGL_SUBTRACT GL_SUBTRACT +#else +#define CGL_SUBTRACT 0x84e7 +#endif + +#ifdef GL_DOT3_RGB +#define CGL_DOT3_RGB GL_DOT3_RGB +#else +#define CGL_DOT3_RGB 0x86ae +#endif + +#ifdef GL_DOT3_RGBA +#define CGL_DOT3_RGBA GL_DOT3_RGBA +#else +#define CGL_DOT3_RGBA 0x86af +#endif + +#ifdef GL_CONSTANT +#define CGL_CONSTANT GL_CONSTANT +#else +#define CGL_CONSTANT 0x8576 +#endif + +#ifdef GL_PRIMARY_COLOR +#define CGL_PRIMARY_COLOR GL_PRIMARY_COLOR +#else +#define CGL_PRIMARY_COLOR 0x8577 +#endif + +#ifdef GL_PREVIOUS +#define CGL_PREVIOUS GL_PREVIOUS +#else +#define CGL_PREVIOUS 0x8578 +#endif + +#ifdef GL_COMBINE +#define CGL_COMBINE GL_COMBINE +#else +#define CGL_COMBINE 0x8570 +#endif + +#ifdef GL_COMBINE_RGB +#define CGL_COMBINE_RGB GL_COMBINE_RGB +#else +#define CGL_COMBINE_RGB 0x8571 +#endif + +#ifdef GL_COMBINE_ALPHA +#define CGL_COMBINE_ALPHA GL_COMBINE_ALPHA +#else +#define CGL_COMBINE_ALPHA 0x8572 +#endif + +#ifdef GL_SRC0_RGB +#define CGL_SRC0_RGB GL_SRC0_RGB +#else +#define CGL_SRC0_RGB 0x8580 +#endif + +#ifdef GL_OPERAND0_RGB +#define CGL_OPERAND0_RGB GL_OPERAND0_RGB +#else +#define CGL_OPERAND0_RGB 0x8590 +#endif + +#ifdef GL_SRC1_RGB +#define CGL_SRC1_RGB GL_SRC1_RGB +#else +#define CGL_SRC1_RGB 0x8581 +#endif + +#ifdef GL_OPERAND1_RGB +#define CGL_OPERAND1_RGB GL_OPERAND1_RGB +#else +#define CGL_OPERAND1_RGB 0x8591 +#endif + +#ifdef GL_SRC2_RGB +#define CGL_SRC2_RGB GL_SRC2_RGB +#else +#define CGL_SRC2_RGB 0x8582 +#endif + +#ifdef GL_OPERAND2_RGB +#define CGL_OPERAND2_RGB GL_OPERAND2_RGB +#else +#define CGL_OPERAND2_RGB 0x8592 +#endif + +#ifdef GL_SRC0_ALPHA +#define CGL_SRC0_ALPHA GL_SRC0_ALPHA +#else +#define CGL_SRC0_ALPHA 0x8588 +#endif + +#ifdef GL_OPERAND0_ALPHA +#define CGL_OPERAND0_ALPHA GL_OPERAND0_ALPHA +#else +#define CGL_OPERAND0_ALPHA 0x8598 +#endif + +#ifdef GL_SRC1_ALPHA +#define CGL_SRC1_ALPHA GL_SRC1_ALPHA +#else +#define CGL_SRC1_ALPHA 0x8589 +#endif + +#ifdef GL_OPERAND1_ALPHA +#define CGL_OPERAND1_ALPHA GL_OPERAND1_ALPHA +#else +#define CGL_OPERAND1_ALPHA 0x8599 +#endif + +#ifdef GL_SRC2_ALPHA +#define CGL_SRC2_ALPHA GL_SRC2_ALPHA +#else +#define CGL_SRC2_ALPHA 0x858a +#endif + +#ifdef GL_OPERAND2_ALPHA +#define CGL_OPERAND2_ALPHA GL_OPERAND2_ALPHA +#else +#define CGL_OPERAND2_ALPHA 0x859a +#endif + +#ifdef GL_AMBIENT +#define CGL_AMBIENT GL_AMBIENT +#else +#define CGL_AMBIENT 0x1200 +#endif + +#ifdef GL_DIFFUSE +#define CGL_DIFFUSE GL_DIFFUSE +#else +#define CGL_DIFFUSE 0x1201 +#endif + +#ifdef GL_SPECULAR +#define CGL_SPECULAR GL_SPECULAR +#else +#define CGL_SPECULAR 0x1202 +#endif + +#ifdef GL_EMISSION +#define CGL_EMISSION GL_EMISSION +#else +#define CGL_EMISSION 0x1600 +#endif + +#ifdef GL_SHININESS +#define CGL_SHININESS GL_SHININESS +#else +#define CGL_SHININESS 0x1601 +#endif + G_END_DECLS #endif diff --git a/gles/cogl-gles2-wrapper.c b/gles/cogl-gles2-wrapper.c index 387416aaa..7e5686c06 100644 --- a/gles/cogl-gles2-wrapper.c +++ b/gles/cogl-gles2-wrapper.c @@ -31,6 +31,11 @@ #include #include +/* We don't want to get the remaps from the gl* functions to the + cogl_wrap_gl* functions in this file because we need to be able to + call the base version */ +#define COGL_GLES2_WRAPPER_NO_REMAP 1 + #include "cogl.h" #include "cogl-gles2-wrapper.h" #include "cogl-fixed-vertex-shader.h" @@ -803,13 +808,21 @@ cogl_wrap_glMultMatrix (const float *m) void cogl_wrap_glMultMatrixf (const GLfloat *m) { - float new_matrix[16]; - int i; + cogl_wrap_glMultMatrix (m); +} - for (i = 0; i < 16; i++) - new_matrix[i] = (m[i]); +void +cogl_wrap_glLoadMatrixf (const GLfloat *m) +{ + float *old_matrix; - cogl_wrap_glMultMatrix (new_matrix); + _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL); + + old_matrix = cogl_gles2_get_matrix_stack_top (w); + + memcpy (old_matrix, m, sizeof (float) * 16); + + cogl_gles2_wrapper_update_matrix (w, w->matrix_mode); } void @@ -1275,7 +1288,7 @@ cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, } void -cogl_wrap_glTexEnvf (GLenum target, GLenum pname, GLfloat param) +cogl_wrap_glTexEnvi (GLenum target, GLenum pname, GLfloat param) { /* This function is only used to set the texture mode once to GL_MODULATE. The shader is hard-coded to modulate the texture so @@ -1591,6 +1604,13 @@ cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param) glTexParameteri (target, pname, param); } +void +cogl_wrap_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params) +{ + /* FIXME: the GLES 2 backend doesn't yet support lighting so this + function can't do anything */ +} + void _cogl_gles2_clear_cache_for_program (CoglHandle user_program) { diff --git a/gles/cogl-gles2-wrapper.h b/gles/cogl-gles2-wrapper.h index f45b8e635..4ae3370ab 100644 --- a/gles/cogl-gles2-wrapper.h +++ b/gles/cogl-gles2-wrapper.h @@ -259,6 +259,36 @@ struct _CoglGles2WrapperShader #define GL_EXP 0x8000 #define GL_EXP2 0x8001 +#define GL_ADD CGL_ADD +#define GL_ADD_SIGNED CGL_ADD_SIGNED +#define GL_INTERPOLATE CGL_INTERPOLATE +#define GL_SUBTRACT CGL_SUBTRACT +#define GL_DOT3_RGB CGL_DOT3_RGB +#define GL_DOT3_RGBA CGL_DOT3_RGBA +#define GL_CONSTANT CGL_CONSTANT +#define GL_PRIMARY_COLOR CGL_PRIMARY_COLOR +#define GL_PREVIOUS CGL_PREVIOUS +#define GL_COMBINE CGL_COMBINE +#define GL_COMBINE_RGB CGL_COMBINE_RGB +#define GL_COMBINE_ALPHA CGL_COMBINE_ALPHA +#define GL_SRC0_RGB CGL_SRC0_RGB +#define GL_OPERAND0_RGB CGL_OPERAND0_RGB +#define GL_SRC1_RGB CGL_SRC1_RGB +#define GL_OPERAND1_RGB CGL_OPERAND1_RGB +#define GL_SRC2_RGB CGL_SRC2_RGB +#define GL_OPERAND2_RGB CGL_OPERAND2_RGB +#define GL_SRC0_ALPHA CGL_SRC0_ALPHA +#define GL_OPERAND0_ALPHA CGL_OPERAND0_ALPHA +#define GL_SRC1_ALPHA CGL_SRC1_ALPHA +#define GL_OPERAND1_ALPHA CGL_OPERAND1_ALPHA +#define GL_SRC2_ALPHA CGL_SRC2_ALPHA +#define GL_OPERAND2_ALPHA CGL_OPERAND2_ALPHA +#define GL_AMBIENT CGL_AMBIENT +#define GL_DIFFUSE CGL_DIFFUSE +#define GL_SPECULAR CGL_SPECULAR +#define GL_EMISSION CGL_EMISSION +#define GL_SHININESS CGL_SHININESS + #endif /* GL_MODELVIEW */ void cogl_gles2_wrapper_init (CoglGles2Wrapper *wrapper); @@ -269,6 +299,7 @@ void cogl_wrap_glPopMatrix (); void cogl_wrap_glMatrixMode (GLenum mode); void cogl_wrap_glLoadIdentity (); void cogl_wrap_glMultMatrixf (const GLfloat *m); +void cogl_wrap_glLoadMatrixf (const GLfloat *m); void cogl_wrap_glFrustumf (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat z_near, GLfloat z_far); @@ -291,7 +322,7 @@ void cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride, void cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); -void cogl_wrap_glTexEnvf (GLenum target, GLenum pname, GLfloat param); +void cogl_wrap_glTexEnvi (GLenum target, GLenum pname, GLfloat param); void cogl_wrap_glClientActiveTexture (GLenum texture); void cogl_wrap_glActiveTexture (GLenum texture); @@ -319,47 +350,52 @@ void cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param); void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, GLenum internal_format); +void cogl_wrap_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); + /* This function is only available on GLES 2 */ #define cogl_wrap_glGenerateMipmap glGenerateMipmap void _cogl_gles2_clear_cache_for_program (CoglHandle program); +/* Remap the missing GL functions to use the wrappers */ +#ifndef COGL_GLES2_WRAPPER_NO_REMAP +#define glDrawArrays cogl_wrap_glDrawArrays +#define glDrawElements cogl_wrap_glDrawElements +#define glPushMatrix cogl_wrap_glPushMatrix +#define glPopMatrix cogl_wrap_glPopMatrix +#define glMatrixMode cogl_wrap_glMatrixMode +#define glLoadIdentity cogl_wrap_glLoadIdentity +#define glMultMatrixf cogl_wrap_glMultMatrixf +#define glLoadMatrixf cogl_wrap_glLoadMatrixf +#define glFrustumf cogl_wrap_glFrustumf +#define glScalef cogl_wrap_glScalef +#define glTranslatef cogl_wrap_glTranslatef +#define glRotatef cogl_wrap_glRotatef +#define glOrthof cogl_wrap_glOrthof +#define glEnable cogl_wrap_glEnable +#define glDisable cogl_wrap_glDisable +#define glTexCoordPointer cogl_wrap_glTexCoordPointer +#define glVertexPointer cogl_wrap_glVertexPointer +#define glColorPointer cogl_wrap_glColorPointer +#define glNormalPointer cogl_wrap_glNormalPointer +#define glTexEnvi cogl_wrap_glTexEnvi +#define glActiveTexture cogl_wrap_glActiveTexture +#define glClientActiveTexture cogl_wrap_glClientActiveTexture +#define glEnableClientState cogl_wrap_glEnableClientState +#define glDisableClientState cogl_wrap_glDisableClientState +#define glAlphaFunc cogl_wrap_glAlphaFunc +#define glColor4f cogl_wrap_glColor4f +#define glClipPlanef cogl_wrap_glClipPlanef +#define glGetIntegerv cogl_wrap_glGetIntegerv +#define glGetFloatv cogl_wrap_glGetFloatv +#define glFogf cogl_wrap_glFogf +#define glFogfv cogl_wrap_glFogfv +#define glTexParameteri cogl_wrap_glTexParameteri +#define glMaterialfv cogl_wrap_glMaterialfv +#endif /* COGL_GLES2_WRAPPER_NO_REMAP */ + #else /* HAVE_COGL_GLES2 */ -/* If we're not using GL ES 2 then just use the GL functions - directly */ - -#define cogl_wrap_glDrawArrays glDrawArrays -#define cogl_wrap_glDrawElements glDrawElements -#define cogl_wrap_glPushMatrix glPushMatrix -#define cogl_wrap_glPopMatrix glPopMatrix -#define cogl_wrap_glMatrixMode glMatrixMode -#define cogl_wrap_glLoadIdentity glLoadIdentity -#define cogl_wrap_glMultMatrixf glMultMatrixf -#define cogl_wrap_glFrustumf glFrustumf -#define cogl_wrap_glScalef glScalef -#define cogl_wrap_glTranslatef glTranslatef -#define cogl_wrap_glRotatef glRotatef -#define cogl_wrap_glOrthof glOrthof -#define cogl_wrap_glEnable glEnable -#define cogl_wrap_glDisable glDisable -#define cogl_wrap_glTexCoordPointer glTexCoordPointer -#define cogl_wrap_glVertexPointer glVertexPointer -#define cogl_wrap_glColorPointer glColorPointer -#define cogl_wrap_glNormalPointer glNormalPointer -#define cogl_wrap_glTexEnvf glTexEnvf -#define cogl_wrap_glActiveTexture glActiveTexture -#define cogl_wrap_glEnableClientState glEnableClientState -#define cogl_wrap_glDisableClientState glDisableClientState -#define cogl_wrap_glAlphaFunc glAlphaFunc -#define cogl_wrap_glColor4f glColor4f -#define cogl_wrap_glClipPlanef glClipPlanef -#define cogl_wrap_glGetIntegerv glGetIntegerv -#define cogl_wrap_glGetFloatv glGetFloatv -#define cogl_wrap_glFogf glFogf -#define cogl_wrap_glFogfv glFogfv -#define cogl_wrap_glTexParameteri glTexParameteri - /* The extra third parameter of the bind texture wrapper isn't needed so we can just directly call glBindTexture */ #define cogl_gles2_wrapper_bind_texture(target, texture, internal_format) \