diff --git a/cogl-shader.h b/cogl-shader.h index cd0bc8c8b..59c75ede6 100644 --- a/cogl-shader.h +++ b/cogl-shader.h @@ -42,6 +42,17 @@ G_BEGIN_DECLS * The only supported format is GLSL shaders. */ +/** + * CoglShaderType: + * @COGL_SHADER_TYPE_VERTEX: A program for proccessing vertices + * @COGL_SHADER_TYPE_FRAGMENT: A program for processing fragments + */ +typedef enum _CoglShaderType +{ + COGL_SHADER_TYPE_VERTEX, + COGL_SHADER_TYPE_FRAGMENT +} CoglShaderType; + /** * cogl_create_shader: * @shader_type: CGL_VERTEX_SHADER or CGL_FRAGMENT_SHADER. @@ -51,7 +62,7 @@ G_BEGIN_DECLS * * Returns: a new shader handle. */ -CoglHandle cogl_create_shader (COGLenum shader_type); +CoglHandle cogl_create_shader (CoglShaderType shader_type); /** * cogl_shader_ref: @@ -91,8 +102,8 @@ gboolean cogl_is_shader (CoglHandle handle); * Replaces the current GLSL source associated with a shader with a new * one. */ -void cogl_shader_source (CoglHandle shader, - const gchar *source); +void cogl_shader_source (CoglHandle shader, + const char *source); /** * cogl_shader_compile: * @handle: #CoglHandle for a shader. @@ -113,22 +124,26 @@ void cogl_shader_compile (CoglHandle handle); * messages that caused a shader to not compile correctly, mainly useful for * debugging purposes. */ -void cogl_shader_get_info_log (CoglHandle handle, - guint size, - gchar *buffer); +void cogl_shader_get_info_log (CoglHandle handle, + size_t size, + char *buffer); /** - * cogl_shader_get_parameteriv: + * cogl_shader_get_type: * @handle: #CoglHandle for a shader. - * @pname: the named COGL parameter to retrieve. - * @dest: storage location for COGLint return value. * - * Retrieve a named parameter from a shader can be used to query to compile - * satus of a shader by passing in CGL_OBJECT_COMPILE_STATUS for @pname. + * Returns: COGL_SHADER_TYPE_VERTEX if the shader is a vertex processor + * or COGL_SHADER_TYPE_FRAGMENT if the shader is a frament processor */ -void cogl_shader_get_parameteriv (CoglHandle handle, - COGLenum pname, - COGLint *dest); +CoglShaderType cogl_shader_get_type (CoglHandle handle); + +/** + * cogl_shader_is_compiled: + * @handle: #CoglHandle for a shader. + * + * Returns: TRUE if the shader object has sucessfully be compiled else FALSE + */ +gboolean cogl_shader_is_compiled (CoglHandle handle); /** * cogl_create_program: @@ -213,9 +228,9 @@ void cogl_program_use (CoglHandle handle); * This uniform can be set using cogl_program_uniform_1f() when the * program is in use. */ -COGLint cogl_program_get_uniform_location - (CoglHandle handle, - const gchar *uniform_name); +int cogl_program_get_uniform_location + (CoglHandle handle, + const char *uniform_name); /** * cogl_program_uniform_1f: @@ -225,8 +240,8 @@ COGLint cogl_program_get_uniform_location * Changes the value of a floating point uniform in the currently * used (see cogl_program_use()) shader program. */ -void cogl_program_uniform_1f (COGLint uniform_no, - gfloat value); +void cogl_program_uniform_1f (int uniform_no, + float value); /** * cogl_program_uniform_1i: @@ -236,8 +251,8 @@ void cogl_program_uniform_1f (COGLint uniform_no, * Changes the value of an integer uniform in the currently * used (see cogl_program_use()) shader program. */ -void cogl_program_uniform_1i (COGLint uniform_no, - gint value); +void cogl_program_uniform_1i (int uniform_no, + int value); /** * cogl_program_uniform_float: @@ -249,9 +264,9 @@ void cogl_program_uniform_1i (COGLint uniform_no, * Changes the value of a float vector uniform, or uniform array in the * currently used (see #cogl_program_use) shader program. */ -void cogl_program_uniform_float (COGLint uniform_no, - gint size, - gint count, +void cogl_program_uniform_float (int uniform_no, + int size, + int count, const GLfloat *value); /** @@ -264,10 +279,10 @@ void cogl_program_uniform_float (COGLint uniform_no, * Changes the value of a int vector uniform, or uniform array in the * currently used (see cogl_program_use()) shader program. */ -void cogl_program_uniform_int (COGLint uniform_no, - gint size, - gint count, - const COGLint *value); +void cogl_program_uniform_int (int uniform_no, + int size, + int count, + const int *value); /** * cogl_program_uniform_matrix: @@ -281,11 +296,11 @@ void cogl_program_uniform_int (COGLint uniform_no, * currently used (see cogl_program_use()) shader program. The @size * parameter is used to determine the square size of the matrix. */ -void cogl_program_uniform_matrix (COGLint uniform_no, - gint size, - gint count, - gboolean transpose, - const GLfloat *value); +void cogl_program_uniform_matrix (int uniform_no, + int size, + int count, + gboolean transpose, + const float *value); G_END_DECLS diff --git a/cogl-texture.h b/cogl-texture.h index c63041bbd..6a8b00a01 100644 --- a/cogl-texture.h +++ b/cogl-texture.h @@ -228,6 +228,52 @@ guint cogl_texture_get_rowstride (CoglHandle handle); */ gint cogl_texture_get_max_waste (CoglHandle handle); +/** + * CoglTextureFilter: + * @COGL_TEXTURE_FILTER_NEAREST: Measuring in manhatten distance from the, + * current pixel center, use the nearest texture + * texel. + * @COGL_TEXTURE_FILTER_LINEAR: Use the weighted average of the 4 texels + * nearest the current pixel center. + * @COGL_TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST: Select the mimap level whose + * texel size most closely matches + * the current pixel, and use the + * COGL_TEXTURE_FILTER_NEAREST + * criterion. + * @COGL_TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST: Select the mimap level whose + * texel size most closely matches + * the current pixel, and use the + * COGL_TEXTURE_FILTER_LINEAR + * criterion. + * @COGL_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR: Select the two mimap levels + * whose texel size most closely + * matches the current pixel, use + * the COGL_TEXTURE_FILTER_NEAREST + * criterion on each one and take + * their weighted average. + * @COGL_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR: Select the two mimap levels + * whose texel size most closely + * matches the current pixel, use + * the COGL_TEXTURE_FILTER_LINEAR + * criterion on each one and take + * their weighted average. + * + * Texture filtering is used whenever the current pixel maps either to more + * than one texture element (texel) or less than one. These filter enums + * correspond to different strategies used to come up with a pixel color, by + * possibly referring to multiple neighbouring texels and taking a weighted + * average or simply using the nearest texel. + */ +typedef enum _CoglTextureFilter +{ + COGL_TEXTURE_FILTER_NEAREST = GL_NEAREST, + COGL_TEXTURE_FILTER_LINEAR = GL_LINEAR, + COGL_TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, + COGL_TEXTURE_FILTER_LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, + COGL_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, + COGL_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR +} CoglTextureFilter; + /** * cogl_texture_get_min_filter: * @handle: a #CoglHandle for a texture. @@ -236,7 +282,7 @@ gint cogl_texture_get_max_waste (CoglHandle handle); * * Returns: the current downscaling filter for a cogl texture. */ -COGLenum cogl_texture_get_min_filter (CoglHandle handle); +CoglTextureFilter cogl_texture_get_min_filter (CoglHandle handle); /** * cogl_texture_get_mag_filter: @@ -246,7 +292,7 @@ COGLenum cogl_texture_get_min_filter (CoglHandle handle); * * Returns: the current downscaling filter for a cogl texture. */ -COGLenum cogl_texture_get_mag_filter (CoglHandle handle); +CoglTextureFilter cogl_texture_get_mag_filter (CoglHandle handle); /** * cogl_texture_is_sliced: @@ -307,8 +353,8 @@ gint cogl_texture_get_data (CoglHandle handle, * drawn at other scales than 100%. */ void cogl_texture_set_filters (CoglHandle handle, - COGLenum min_filter, - COGLenum mag_filter); + CoglTextureFilter min_filter, + CoglTextureFilter mag_filter); /** diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index ff8df1cbc..3032a6863 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -149,7 +149,8 @@ cogl_is_shader cogl_shader_source cogl_shader_compile cogl_shader_get_info_log -cogl_shader_get_parameteriv +cogl_shader_get_type +cogl_shader_is_compiled cogl_create_program cogl_program_ref diff --git a/gl/cogl-defines.h.in b/gl/cogl-defines.h.in index 100cd74a0..8e2df9ec3 100644 --- a/gl/cogl-defines.h.in +++ b/gl/cogl-defines.h.in @@ -29,10 +29,6 @@ G_BEGIN_DECLS -typedef GLenum COGLenum; -typedef GLint COGLint; -typedef GLuint COGLuint; - /* FIXME + DOCUMENT */ #define COPENSTEP OPENSTEP @@ -226,7 +222,6 @@ typedef GLuint COGLuint; #define CGL_FOG_INDEX GL_FOG_INDEX #define CGL_FOG_START GL_FOG_START #define CGL_FOG_END GL_FOG_END -#define CGL_LINEAR GL_LINEAR #define CGL_EXP GL_EXP #define CGL_LOGIC_OP GL_LOGIC_OP #define CGL_INDEX_LOGIC_OP GL_INDEX_LOGIC_OP @@ -419,10 +414,6 @@ typedef GLuint COGLuint; #define CGL_TEXTURE_ALPHA_SIZE GL_TEXTURE_ALPHA_SIZE #define CGL_TEXTURE_LUMINANCE_SIZE GL_TEXTURE_LUMINANCE_SIZE #define CGL_TEXTURE_INTENSITY_SIZE GL_TEXTURE_INTENSITY_SIZE -#define CGL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_NEAREST -#define CGL_NEAREST_MIPMAP_LINEAR GL_NEAREST_MIPMAP_LINEAR -#define CGL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST -#define CGL_LINEAR_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR #define CGL_OBJECT_LINEAR GL_OBJECT_LINEAR #define CGL_OBJECT_PLANE GL_OBJECT_PLANE #define CGL_EYE_LINEAR GL_EYE_LINEAR @@ -430,7 +421,6 @@ typedef GLuint COGLuint; #define CGL_SPHERE_MAP GL_SPHERE_MAP #define CGL_DECAL GL_DECAL #define CGL_MODULATE GL_MODULATE -#define CGL_NEAREST GL_NEAREST #define CGL_REPEAT GL_REPEAT #define CGL_CLAMP GL_CLAMP #define CGL_S GL_S @@ -692,9 +682,6 @@ typedef GLuint COGLuint; #define CGL_UNSIGNED_SHORT_8_8_MESA 0 #endif -#define CGL_FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB -#define CGL_VERTEX_SHADER GL_VERTEX_SHADER_ARB - #define CGL_OBJECT_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB #define CLUTTER_COGL_HAS_GL 1 diff --git a/gl/cogl-program.c b/gl/cogl-program.c index 1f652c95e..0a10cd4c4 100644 --- a/gl/cogl-program.c +++ b/gl/cogl-program.c @@ -139,7 +139,7 @@ cogl_program_use (CoglHandle handle) glUseProgramObjectARB (gl_handle); } -COGLint +int cogl_program_get_uniform_location (CoglHandle handle, const gchar *uniform_name) { @@ -155,7 +155,7 @@ cogl_program_get_uniform_location (CoglHandle handle, } void -cogl_program_uniform_1f (COGLint uniform_no, +cogl_program_uniform_1f (int uniform_no, gfloat value) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -163,7 +163,7 @@ cogl_program_uniform_1f (COGLint uniform_no, } void -cogl_program_uniform_1i (COGLint uniform_no, +cogl_program_uniform_1i (int uniform_no, gint value) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -171,7 +171,7 @@ cogl_program_uniform_1i (COGLint uniform_no, } void -cogl_program_uniform_float (COGLint uniform_no, +cogl_program_uniform_float (int uniform_no, gint size, gint count, const GLfloat *value) @@ -198,10 +198,10 @@ cogl_program_uniform_float (COGLint uniform_no, } void -cogl_program_uniform_int (COGLint uniform_no, +cogl_program_uniform_int (int uniform_no, gint size, gint count, - const COGLint *value) + const int *value) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -225,7 +225,7 @@ cogl_program_uniform_int (COGLint uniform_no, } void -cogl_program_uniform_matrix (COGLint uniform_no, +cogl_program_uniform_matrix (int uniform_no, gint size, gint count, gboolean transpose, diff --git a/gl/cogl-shader.c b/gl/cogl-shader.c index 0d0896c09..944e6736f 100644 --- a/gl/cogl-shader.c +++ b/gl/cogl-shader.c @@ -55,21 +55,33 @@ _cogl_shader_free (CoglShader *shader) } CoglHandle -cogl_create_shader (COGLenum shaderType) +cogl_create_shader (CoglShaderType type) { CoglShader *shader; + GLenum gl_type; - _COGL_GET_CONTEXT (ctx, 0); + _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); + + if (type == COGL_SHADER_TYPE_VERTEX) + gl_type = GL_VERTEX_SHADER; + else if (type == COGL_SHADER_TYPE_FRAGMENT) + gl_type = GL_FRAGMENT_SHADER; + else + { + g_warning ("Unexpected shader type (0x%08lX) given to " + "cogl_create_shader", (unsigned long) type); + return COGL_INVALID_HANDLE; + } shader = g_slice_new (CoglShader); - shader->gl_handle = glCreateShaderObjectARB (shaderType); + shader->gl_handle = glCreateShaderObjectARB (gl_type); return _cogl_shader_handle_new (shader); } void cogl_shader_source (CoglHandle handle, - const gchar *source) + const char *source) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -98,11 +110,11 @@ cogl_shader_compile (CoglHandle handle) void cogl_shader_get_info_log (CoglHandle handle, - guint size, - gchar *buffer) + size_t size, + char *buffer) { CoglShader *shader; - COGLint len; + int len; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) @@ -114,18 +126,51 @@ cogl_shader_get_info_log (CoglHandle handle, buffer[len]='\0'; } -void -cogl_shader_get_parameteriv (CoglHandle handle, - COGLenum pname, - COGLint *dest) +CoglShaderType +cogl_shader_get_type (CoglHandle handle) { + GLint type; CoglShader *shader; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + _COGL_GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX); if (!cogl_is_shader (handle)) - return; + { + g_warning ("Non shader handle type passed to cogl_shader_get_type"); + return COGL_SHADER_TYPE_VERTEX; + } shader = _cogl_shader_pointer_from_handle (handle); - glGetObjectParameterivARB (shader->gl_handle, pname, dest); + GE (glGetObjectParameterivARB (shader->gl_handle, GL_SHADER_TYPE, &type)); + if (type == GL_VERTEX_SHADER) + return COGL_SHADER_TYPE_VERTEX; + else if (type == GL_FRAGMENT_SHADER) + return COGL_SHADER_TYPE_VERTEX; + else + { + g_warning ("Unexpected shader type 0x%08lX", (unsigned long)type); + return COGL_SHADER_TYPE_VERTEX; + } } + +gboolean +cogl_shader_is_compiled (CoglHandle handle) +{ + GLint status; + CoglShader *shader; + + _COGL_GET_CONTEXT (ctx, FALSE); + + if (!cogl_is_shader (handle)) + return FALSE; + + shader = _cogl_shader_pointer_from_handle (handle); + + GE (glGetObjectParameterivARB (shader->gl_handle, GL_COMPILE_STATUS, &status)); + if (status == GL_TRUE) + return TRUE; + else + return FALSE; +} + diff --git a/gl/cogl-texture-private.h b/gl/cogl-texture-private.h index cd60528e4..7cf6fe951 100644 --- a/gl/cogl-texture-private.h +++ b/gl/cogl-texture-private.h @@ -68,8 +68,8 @@ struct _CoglTexture GArray *slice_y_spans; GArray *slice_gl_handles; gint max_waste; - COGLenum min_filter; - COGLenum mag_filter; + CoglTextureFilter min_filter; + CoglTextureFilter mag_filter; gboolean is_foreign; GLint wrap_mode; gboolean auto_mipmap; diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 8fb4980f5..cd02bc719 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -1247,8 +1247,8 @@ cogl_texture_new_with_size (guint width, tex->slice_gl_handles = NULL; tex->max_waste = max_waste; - tex->min_filter = CGL_NEAREST; - tex->mag_filter = CGL_NEAREST; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; + tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; /* Find closest GL format match */ tex->bitmap.format = @@ -1308,8 +1308,8 @@ cogl_texture_new_from_data (guint width, tex->slice_gl_handles = NULL; tex->max_waste = max_waste; - tex->min_filter = CGL_NEAREST; - tex->mag_filter = CGL_NEAREST; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; + tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; /* FIXME: If upload fails we should set some kind of * error flag but still return texture handle (this @@ -1365,8 +1365,8 @@ cogl_texture_new_from_bitmap (CoglHandle bmp_handle, tex->slice_gl_handles = NULL; tex->max_waste = max_waste; - tex->min_filter = CGL_NEAREST; - tex->mag_filter = CGL_NEAREST; + tex->min_filter = COGL_TEXTURE_FILTER_NEAREST; + tex->mag_filter = COGL_TEXTURE_FILTER_NEAREST; /* FIXME: If upload fails we should set some kind of * error flag but still return texture handle if the @@ -1693,7 +1693,7 @@ cogl_texture_get_gl_texture (CoglHandle handle, return TRUE; } -COGLenum +CoglTextureFilter cogl_texture_get_min_filter (CoglHandle handle) { CoglTexture *tex; @@ -1706,7 +1706,7 @@ cogl_texture_get_min_filter (CoglHandle handle) return tex->min_filter; } -COGLenum +CoglTextureFilter cogl_texture_get_mag_filter (CoglHandle handle) { CoglTexture *tex; @@ -1721,8 +1721,8 @@ cogl_texture_get_mag_filter (CoglHandle handle) void cogl_texture_set_filters (CoglHandle handle, - COGLenum min_filter, - COGLenum mag_filter) + CoglTextureFilter min_filter, + CoglTextureFilter mag_filter) { CoglTexture *tex; GLuint gl_handle; diff --git a/gles/cogl-defines.h.in b/gles/cogl-defines.h.in index d6010509b..2a356e873 100644 --- a/gles/cogl-defines.h.in +++ b/gles/cogl-defines.h.in @@ -430,10 +430,6 @@ G_BEGIN_DECLS #define CGL_WEIGHT_ARRAY_BUFFER_BINDING_OES GL_WEIGHT_ARRAY_BUFFER_BINDING_OES #define CGL_TEXTURE_CROP_RECT_OES GL_TEXTURE_CROP_RECT_OES -typedef GLenum COGLenum; -typedef GLint COGLint; -typedef GLuint COGLuint; - /* extras */ /* YUV textures also unsupported */ @@ -441,18 +437,6 @@ typedef GLuint COGLuint; #define CGL_UNSIGNED_SHORT_8_8_REV_MESA 0 #define CGL_UNSIGNED_SHORT_8_8_MESA 0 -#ifdef GL_FRAGMENT_SHADER -#define CGL_FRAGMENT_SHADER GL_FRAGMENT_SHADER -#else -#define CGL_FRAGMENT_SHADER 0 -#endif - -#ifdef GL_VERTEX_SHADER -#define CGL_VERTEX_SHADER GL_VERTEX_SHADER -#else -#define CGL_VERTEX_SHADER 0 -#endif - #if defined(GL_OBJECT_COMPILE_STATUS) #define CGL_OBJECT_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS #elif defined(GL_COMPILE_STATUS) diff --git a/gles/cogl-program.c b/gles/cogl-program.c index 317310c32..e8fc6a0f0 100644 --- a/gles/cogl-program.c +++ b/gles/cogl-program.c @@ -122,7 +122,7 @@ cogl_program_use (CoglHandle handle) ctx->gles2.settings_dirty = TRUE; } -COGLint +int cogl_program_get_uniform_location (CoglHandle handle, const gchar *uniform_name) { @@ -155,21 +155,21 @@ cogl_program_get_uniform_location (CoglHandle handle, } void -cogl_program_uniform_1f (COGLint uniform_no, +cogl_program_uniform_1f (int uniform_no, gfloat value) { cogl_program_uniform_float (uniform_no, 1, 1, &value); } void -cogl_program_uniform_1i (COGLint uniform_no, +cogl_program_uniform_1i (int uniform_no, gint value) { cogl_program_uniform_int (uniform_no, 1, 1, &value); } static void -cogl_program_uniform_x (COGLint uniform_no, +cogl_program_uniform_x (int uniform_no, gint size, gint count, CoglBoxedType type, @@ -215,7 +215,7 @@ cogl_program_uniform_x (COGLint uniform_no, } void -cogl_program_uniform_float (COGLint uniform_no, +cogl_program_uniform_float (int uniform_no, gint size, gint count, const GLfloat *value) @@ -225,7 +225,7 @@ cogl_program_uniform_float (COGLint uniform_no, } void -cogl_program_uniform_int (COGLint uniform_no, +cogl_program_uniform_int (int uniform_no, gint size, gint count, const GLint *value) @@ -235,7 +235,7 @@ cogl_program_uniform_int (COGLint uniform_no, } void -cogl_program_uniform_matrix (COGLint uniform_no, +cogl_program_uniform_matrix (int uniform_no, gint size, gint count, gboolean transpose, @@ -296,7 +296,7 @@ cogl_program_use (CoglHandle program_handle) { } -COGLint +int cogl_program_get_uniform_location (CoglHandle program_handle, const gchar *uniform_name) { @@ -304,13 +304,13 @@ cogl_program_get_uniform_location (CoglHandle program_handle, } void -cogl_program_uniform_1f (COGLint uniform_no, +cogl_program_uniform_1f (int uniform_no, gfloat value) { } void -cogl_program_uniform_float (COGLint uniform_no, +cogl_program_uniform_float (int uniform_no, gint size, gint count, const GLfloat *value) @@ -318,15 +318,15 @@ cogl_program_uniform_float (COGLint uniform_no, } void -cogl_program_uniform_int (COGLint uniform_no, +cogl_program_uniform_int (int uniform_no, gint size, gint count, - const COGLint *value) + const int *value) { } void -cogl_program_uniform_matrix (COGLint uniform_no, +cogl_program_uniform_matrix (int uniform_no, gint size, gint count, gboolean transpose, diff --git a/gles/cogl-shader.c b/gles/cogl-shader.c index d261e1a0b..ff5f0c58a 100644 --- a/gles/cogl-shader.c +++ b/gles/cogl-shader.c @@ -48,22 +48,31 @@ _cogl_shader_free (CoglShader *shader) } CoglHandle -cogl_create_shader (COGLenum shaderType) +cogl_create_shader (CoglShaderType type) { CoglShader *shader; + GLenum gl_type; - _COGL_GET_CONTEXT (ctx, 0); + if (type == COGL_SHADER_TYPE_VERTEX) + gl_type = GL_VERTEX_SHADER; + else if (type == COGL_SHADER_TYPE_FRAGMENT) + gl_type = GL_FRAGMENT_SHADER; + else + { + g_warning ("Unexpected shader type (0x%08lX) given to " + "cogl_create_shader", (unsigned long) type); + return COGL_INVALID_HANDLE; + } shader = g_slice_new (CoglShader); - shader->gl_handle = glCreateShader (shaderType); - shader->type = shaderType; + shader->gl_handle = glCreateShader (gl_type); return _cogl_shader_handle_new (shader); } void cogl_shader_source (CoglHandle handle, - const gchar *source) + const char *source) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); @@ -92,11 +101,11 @@ cogl_shader_compile (CoglHandle handle) void cogl_shader_get_info_log (CoglHandle handle, - guint size, - gchar *buffer) + size_t size, + char *buffer) { CoglShader *shader; - COGLint len = 0; + int len = 0; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) @@ -108,20 +117,48 @@ cogl_shader_get_info_log (CoglHandle handle, buffer[len] = '\0'; } -void -cogl_shader_get_parameteriv (CoglHandle handle, - COGLenum pname, - COGLint *dest) +CoglShaderType +cogl_shader_get_type (CoglHandle handle) { + GLint type; CoglShader *shader; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) - return; + { + g_warning ("Non shader handle type passed to cogl_shader_get_type"); + return COGL_SHADER_TYPE_VERTEX; + } shader = _cogl_shader_pointer_from_handle (handle); - glGetShaderiv (shader->gl_handle, pname, dest); + GE (glGetShaderiv (shader->gl_handle, GL_SHADER_TYPE, &type)); + if (type == GL_VERTEX_SHADER) + return COGL_SHADER_TYPE_VERTEX; + else if (type == GL_FRAGMENT_SHADER) + return COGL_SHADER_TYPE_VERTEX; + else + { + g_warning ("Unexpected shader type 0x%08lX", (unsigned long)type); + return COGL_SHADER_TYPE_VERTEX; + } +} + +gboolean +cogl_shader_is_compiled (CoglHandle handle) +{ + GLint status; + CoglShader *shader; + + if (!cogl_is_shader (handle)) + return FALSE; + + shader = _cogl_shader_pointer_from_handle (handle); + + GE (glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status)); + if (status == GL_TRUE) + return TRUE; + else + return FALSE; } #else /* HAVE_COGL_GLES2 */ @@ -129,7 +166,7 @@ cogl_shader_get_parameteriv (CoglHandle handle, /* No support on regular OpenGL 1.1 */ CoglHandle -cogl_create_shader (COGLenum shaderType) +cogl_create_shader (CoglShaderType type) { return COGL_INVALID_HANDLE; } @@ -153,7 +190,7 @@ cogl_shader_unref (CoglHandle handle) void cogl_shader_source (CoglHandle shader, - const gchar *source) + const char *source) { } @@ -164,16 +201,21 @@ cogl_shader_compile (CoglHandle shader_handle) void cogl_shader_get_info_log (CoglHandle handle, - guint size, - gchar *buffer) + size_t size, + char *buffer) { } -void -cogl_shader_get_parameteriv (CoglHandle handle, - COGLenum pname, - COGLint *dest) +CoglShaderType +cogl_shader_get_type (CoglHandle handle) { + return COGL_SHADER_TYPE_VERTEX; +} + +gboolean +cogl_shader_is_compiled (CoglHandle handle) +{ + return FALSE; } #endif /* HAVE_COGL_GLES2 */ diff --git a/gles/cogl-texture-private.h b/gles/cogl-texture-private.h index cd60528e4..7cf6fe951 100644 --- a/gles/cogl-texture-private.h +++ b/gles/cogl-texture-private.h @@ -68,8 +68,8 @@ struct _CoglTexture GArray *slice_y_spans; GArray *slice_gl_handles; gint max_waste; - COGLenum min_filter; - COGLenum mag_filter; + CoglTextureFilter min_filter; + CoglTextureFilter mag_filter; gboolean is_foreign; GLint wrap_mode; gboolean auto_mipmap; diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index 0954798d9..ce5d4fe26 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -1778,7 +1778,7 @@ cogl_texture_get_gl_texture (CoglHandle handle, return TRUE; } -COGLenum +CoglTextureFilter cogl_texture_get_min_filter (CoglHandle handle) { CoglTexture *tex; @@ -1791,7 +1791,7 @@ cogl_texture_get_min_filter (CoglHandle handle) return tex->min_filter; } -COGLenum +CoglTextureFilter cogl_texture_get_mag_filter (CoglHandle handle) { CoglTexture *tex; @@ -1806,8 +1806,8 @@ cogl_texture_get_mag_filter (CoglHandle handle) void cogl_texture_set_filters (CoglHandle handle, - COGLenum min_filter, - COGLenum mag_filter) + CoglTextureFilter min_filter, + CoglTextureFilter mag_filter) { CoglTexture *tex; GLuint gl_handle;