diff --git a/ChangeLog b/ChangeLog index 00446c419..925a9612d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,53 @@ +2008-04-29 Neil Roberts + + Removed COGLhandle and changed shader and program functions to be + wrapped in reference-counted CoglHandles instead. + + * clutter/cogl/gl/cogl-shader.c: + * clutter/cogl/gl/cogl-shader.h: + * clutter/cogl/gl/cogl-program.c: + * clutter/cogl/gl/cogl-program.h: + New files to hold the shader and program functions. + + * clutter/cogl/gl/cogl.c: Removed shader and program functions. + + * clutter/cogl/common/cogl-handle.h: New header to define + COGL_HANDLE_DEFINE which helps build functions to create + reference-counted handles. This reduces the amount of duplicated + code. + + * clutter/cogl/gl/cogl-texture.c: + * clutter/cogl/gles/cogl-texture.c: + * clutter/cogl/gl/cogl-fbo.c: Converted to use COGL_HANDLE_DEFINE + from cogl-handle.h to avoid duplicating some of the common code. + + * clutter/cogl/gles/cogl-defines.h.in: + * clutter/cogl/gl/cogl-defines.h.in: Removed COGLhandle + + * clutter/cogl/gl/cogl-context.h: Added handle arrays for programs + and shaders. + + * clutter/cogl/gl/cogl-context.c (cogl_create_context): Added + initialisers for shader_handles and program_handles. + (cogl_destroy_context): Added calls to g_array_free for all handle + arrays. + + * clutter/cogl/gl/Makefile.am (libclutter_cogl_la_SOURCES): Added + cogl-{program,shader}.{c,h} + + * clutter/cogl/common/Makefile.am + (libclutter_cogl_common_la_SOURCES): Added cogl-handle.h + + * clutter/cogl/gles/cogl.c: + * clutter/cogl/cogl.h.in: Programs and shaders are now wrapped in + CoglHandles instead of COGLhandles. cogl_program_destroy and + cogl_shader_destroy is now replaced with cogl_program_unref and + cogl_shader_unref. cogl_program_ref and cogl_shader_ref are also + added. + + * clutter/clutter-shader.c: Converted to use CoglHandles for the + programs and shaders instead of COGLhandles. + 2008-04-29 Øyvind Kolås * clutter/cogl/cogl.h.in: renaming of API's in cogl to make the diff --git a/clutter/clutter-shader.c b/clutter/clutter-shader.c index 21fd1bbee..cdec9ce86 100644 --- a/clutter/clutter-shader.c +++ b/clutter/clutter-shader.c @@ -77,10 +77,10 @@ struct _ClutterShaderPrivate gchar *vertex_source; /* GLSL source for vertex shader */ gchar *fragment_source; /* GLSL source for fragment shader */ - COGLhandle program; + CoglHandle program; - COGLhandle vertex_shader; - COGLhandle fragment_shader; + CoglHandle vertex_shader; + CoglHandle fragment_shader; }; enum @@ -281,9 +281,9 @@ clutter_shader_init (ClutterShader *self) priv->vertex_source = NULL; priv->fragment_source = NULL; - priv->program = 0; - priv->vertex_shader = 0; - priv->fragment_shader = 0; + priv->program = COGL_INVALID_HANDLE; + priv->vertex_shader = COGL_INVALID_HANDLE; + priv->fragment_shader = COGL_INVALID_HANDLE; } /** @@ -405,7 +405,7 @@ bind_glsl_shader (ClutterShader *self, priv->program = cogl_create_program (); - if (priv->vertex_is_glsl && priv->vertex_source) + if (priv->vertex_is_glsl && priv->vertex_source != COGL_INVALID_HANDLE) { priv->vertex_shader = cogl_create_shader (CGL_VERTEX_SHADER); @@ -414,7 +414,7 @@ bind_glsl_shader (ClutterShader *self, cogl_program_attach_shader (priv->program, priv->vertex_shader); } - if (priv->fragment_is_glsl && priv->fragment_source) + if (priv->fragment_is_glsl && priv->fragment_source != COGL_INVALID_HANDLE) { GLint compiled = CGL_FALSE; @@ -474,8 +474,8 @@ clutter_shader_compile (ClutterShader *shader, if (priv->compiled) return priv->compiled; - if ((priv->vertex_source && !priv->vertex_is_glsl) || - (priv->fragment_source && !priv->fragment_is_glsl)) + if ((priv->vertex_source != COGL_INVALID_HANDLE && !priv->vertex_is_glsl) || + (priv->fragment_source != COGL_INVALID_HANDLE && !priv->fragment_is_glsl)) { /* XXX: Could remove this check, since we only advertise support for GLSL * shaders anyways. */ @@ -521,20 +521,20 @@ clutter_shader_release (ClutterShader *shader) if (!priv->compiled) return; - g_assert (priv->program); + g_assert (priv->program != COGL_INVALID_HANDLE); - if (priv->vertex_is_glsl && priv->vertex_shader) - cogl_shader_destroy (priv->vertex_shader); + if (priv->vertex_is_glsl && priv->vertex_shader != COGL_INVALID_HANDLE) + cogl_shader_unref (priv->vertex_shader); - if (priv->fragment_is_glsl && priv->fragment_shader) - cogl_shader_destroy (priv->fragment_shader); + if (priv->fragment_is_glsl && priv->fragment_shader != COGL_INVALID_HANDLE) + cogl_shader_unref (priv->fragment_shader); - if (priv->program) - cogl_program_destroy (priv->program); + if (priv->program != COGL_INVALID_HANDLE) + cogl_program_unref (priv->program); - priv->vertex_shader = 0; - priv->fragment_shader = 0; - priv->program = 0; + priv->vertex_shader = COGL_INVALID_HANDLE; + priv->fragment_shader = COGL_INVALID_HANDLE; + priv->program = COGL_INVALID_HANDLE; priv->compiled = FALSE; g_object_notify (G_OBJECT (shader), "compiled"); @@ -603,7 +603,7 @@ clutter_shader_set_is_enabled (ClutterShader *shader, if (priv->is_enabled) cogl_program_use (priv->program); else - cogl_program_use (0); + cogl_program_use (COGL_INVALID_HANDLE); g_object_notify (G_OBJECT (shader), "enabled"); } diff --git a/clutter/cogl/cogl.h.in b/clutter/cogl/cogl.h.in index baf1ab399..a712d4036 100644 --- a/clutter/cogl/cogl.h.in +++ b/clutter/cogl/cogl.h.in @@ -829,7 +829,7 @@ gboolean cogl_texture_set_region (CoglHandle handle, * cogl_texture_ref: * @handle: a @CoglHandle. * - * Increment the reference count for a cogl. + * Increment the reference count for a cogl texture. * * Returns: the @handle. */ @@ -1242,45 +1242,67 @@ void cogl_path_round_rectangle (ClutterFixed x, /** * cogl_create_shader: - * @shader_type: CGL_VERTEX_SHADER og CGL_FRAGMENT_SHADER. + * @shader_type: CGL_VERTEX_SHADER or CGL_FRAGMENT_SHADER. * * Create a new shader handle, use #cogl_shader_source to set the source code * to be used on it. * * Returns: a new shader handle. */ -COGLhandle cogl_create_shader (COGLenum shader_type); +CoglHandle cogl_create_shader (COGLenum shader_type); /** - * cogl_shader_destroy: - * @handle: #COGLhandle for a shader. + * cogl_shader_ref: + * @handle: A #CoglHandle to a shader. * - * Free up the resources used by a cogl shader. + * Add an extra reference to a shader. + * + * Returns: @handle */ -void cogl_shader_destroy (COGLhandle handle); +CoglHandle cogl_shader_ref (CoglHandle handle); + +/** + * cogl_shader_unref: + * @handle: A #CoglHandle to a shader. + * + * Removes a reference to a shader. If it was the last reference the + * shader object will be destroyed. + */ +void cogl_shader_unref (CoglHandle handle); + +/** + * cogl_is_shader: + * @handle: A CoglHandle + * + * Gets whether the given handle references an existing shader object. + * + * Returns: %TRUE if the handle references a shader, + * %FALSE otherwise + */ +gboolean cogl_is_shader (CoglHandle handle); /** * cogl_shader_source: - * @shader: #COGLhandle for a shader. + * @shader: #CoglHandle for a shader. * @source: GLSL shader source. * * Replaces the current GLSL source associated with a shader with a new * one. */ -void cogl_shader_source (COGLhandle shader, +void cogl_shader_source (CoglHandle shader, const gchar *source); /** * cogl_shader_compile: - * @shader_handle: #COGLhandle for a shader. + * @handle: #CoglHandle for a shader. * * Compiles the shader, no return value, but the shader is now ready for * linking into a program. */ -void cogl_shader_compile (COGLhandle shader_handle); +void cogl_shader_compile (CoglHandle handle); /** * cogl_shader_get_info_log: - * @handle: #COGLhandle for a shader. + * @handle: #CoglHandle for a shader. * @size: maximum number of bytes to retrieve. * @buffer: location for info log. * @@ -1289,20 +1311,20 @@ void cogl_shader_compile (COGLhandle shader_handle); * messages that caused a shader to not compile correctly, mainly useful for * debugging purposes. */ -void cogl_shader_get_info_log (COGLhandle handle, +void cogl_shader_get_info_log (CoglHandle handle, guint size, gchar *buffer); /** * cogl_shader_get_parameteriv: - * @handle: #COGLhandle for a shader. + * @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. */ -void cogl_shader_get_parameteriv (COGLhandle handle, +void cogl_shader_get_parameteriv (CoglHandle handle, COGLenum pname, COGLint *dest); @@ -1314,48 +1336,71 @@ void cogl_shader_get_parameteriv (COGLhandle handle, * * Returns: a new cogl program. */ -COGLhandle cogl_create_program (void); +CoglHandle cogl_create_program (void); /** - * cogl_program_destroy: - * @handle: #COGLhandle for a shader. + * cogl_program_ref: + * @handle: A #CoglHandle to a program. * - * Releases all resources held by a cogl program. + * Add an extra reference to a program. + * + * Returns: @handle */ -void cogl_program_destroy (COGLhandle handle); +CoglHandle cogl_program_ref (CoglHandle handle); + +/** + * cogl_program_unref: + * @handle: A #CoglHandle to a program. + * + * Removes a reference to a program. If it was the last reference the + * program object will be destroyed. + */ +void cogl_program_unref (CoglHandle handle); + +/** + * cogl_is_program: + * @handle: A CoglHandle + * + * Gets whether the given handle references an existing program object. + * + * Returns: %TRUE if the handle references a program, + * %FALSE otherwise + */ +gboolean cogl_is_program (CoglHandle handle); /** * cogl_program_attach_shader: - * @program_handle: a #COGLhandle for a shdaer program. - * @shader_handle: a #COGLhandle for a vertex of fragment shader. + * @program_handle: a #CoglHandle for a shdaer program. + * @shader_handle: a #CoglHandle for a vertex of fragment shader. * * Attaches a shader to a program object, a program can have one vertex shader * and one fragment shader attached. */ -void cogl_program_attach_shader (COGLhandle program_handle, - COGLhandle shader_handle); +void cogl_program_attach_shader (CoglHandle program_handle, + CoglHandle shader_handle); /** * cogl_program_link: - * @program_handle: a #COGLhandle for a shader program. + * @handle: a #CoglHandle for a shader program. * * Links a program making it ready for use. */ -void cogl_program_link (COGLhandle program_handle); +void cogl_program_link (CoglHandle handle); /** * cogl_program_use: - * @program_handle: a #COGLhandle for a shader program or 0. + * @handle: a #CoglHandle for a shader program or COGL_INVALID_HANDLE. * - * Activate a specific shader program replacing that part of the GL rendering - * pipeline, if passed in 0 the default behavior of GL is reinstated. + * Activate a specific shader program replacing that part of the GL + * rendering pipeline, if passed in COGL_INVALID_HANDLE the default + * behavior of GL is reinstated. */ -void cogl_program_use (COGLhandle program_handle); +void cogl_program_use (CoglHandle handle); /** * cogl_program_get_uniform_location: - * @program_handle: a #COGLhandle for a shader program. + * @handle: a #CoglHandle for a shader program. * @uniform_name: the name of a uniform. * * Retrieve the location (offset) of a uniform variable in a shader program, a @@ -1366,7 +1411,7 @@ void cogl_program_use (COGLhandle program_handle); * set using #cogl_program_uniform_1f when the program is in use. */ COGLint cogl_program_get_uniform_location - (COGLhandle program_handle, + (CoglHandle handle, const gchar *uniform_name); @@ -1378,8 +1423,8 @@ COGLint cogl_program_get_uniform_location * Changes the value of a 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 (COGLint uniform_no, + gfloat value); /* Offscreen api */ @@ -1407,6 +1452,18 @@ CoglHandle cogl_offscreen_new_multisample(void); */ CoglHandle cogl_offscreen_ref (CoglHandle handle); +/** + * cogl_is_offscreen: + * @handle: A CoglHandle + * + * Gets whether the given handle references an existing offscreen + * buffer object. + * + * Returns: %TRUE if the handle references an offscreen buffer, + * %FALSE otherwise + */ +gboolean cogl_is_offscreen (CoglHandle handle); + /** * cogl_offscreen_unref: * @handle: diff --git a/clutter/cogl/common/Makefile.am b/clutter/cogl/common/Makefile.am index b6dca2df2..835dc3bb6 100644 --- a/clutter/cogl/common/Makefile.am +++ b/clutter/cogl/common/Makefile.am @@ -17,6 +17,7 @@ EXTRA_DIST = stb_image.c libclutter_cogl_common_la_SOURCES = \ cogl-util.h \ cogl-bitmap.h \ + cogl-handle.h \ cogl-util.c \ cogl-bitmap.c \ cogl-bitmap-fallback.c \ diff --git a/clutter/cogl/common/cogl-handle.h b/clutter/cogl/common/cogl-handle.h new file mode 100644 index 000000000..c4ea87beb --- /dev/null +++ b/clutter/cogl/common/cogl-handle.h @@ -0,0 +1,160 @@ +/* + * Clutter COGL + * + * A basic GL/GLES Abstraction/Utility Layer + * + * Authored By Matthew Allum + * + * Copyright (C) 2008 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __COGL_HANDLE_H +#define __COGL_HANDLE_H + +/* Helper macro to encapsulate the common code for COGL reference + counted handles */ + +#if COGL_DEBUG + +#define COGL_HANDLE_DEBUG_NEW(type_name, obj) \ + printf ("COGL " G_STRINGIFY (type_name) " NEW %p %i\n", \ + (obj), (obj)->ref_count) + +#define COGL_HANDLE_DEBUG_REF(type_name, obj) \ + printf ("COGL " G_STRINGIFY (type_name) " REF %p %i\n", \ + (obj), (obj)->ref_count) + +#define COGL_HANDLE_DEBUG_UNREF(type_name, obj) \ + printf ("COGL " G_STRINGIFY (type_name) " UNREF %p %i\n", \ + (obj), (obj)->ref_count - 1) + +#define COGL_HANDLE_DEBUG_FREE(type_name, obj) \ + printf ("COGL " G_STRINGIFY (type_name) " FREE %p\n", (obj)) + +#else /* COGL_DEBUG */ + +#define COGL_HANDLE_DEBUG_NEW(type_name, obj) (void) 0 +#define COGL_HANDLE_DEBUG_REF(type_name, obj) (void) 0 +#define COGL_HANDLE_DEBUG_UNREF(type_name, obj) (void) 0 +#define COGL_HANDLE_DEBUG_FREE(type_name, obj) (void) 0 + +#endif /* COGL_DEBUG */ + +#define COGL_HANDLE_DEFINE(TypeName, type_name, handle_array) \ + \ + static gint \ + _cogl_##type_name##_handle_find (CoglHandle handle) \ + { \ + _COGL_GET_CONTEXT (ctx, -1); \ + \ + gint i; \ + \ + if (ctx->handle_array == NULL) \ + return -1; \ + \ + for (i=0; i < ctx->handle_array->len; ++i) \ + if (g_array_index (ctx->handle_array, \ + CoglHandle, i) == handle) \ + return i; \ + \ + return -1; \ + } \ + \ + static CoglHandle \ + _cogl_##type_name##_handle_new (Cogl##TypeName *obj) \ + { \ + _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); \ + \ + CoglHandle handle = (CoglHandle) obj; \ + \ + if (ctx->handle_array == NULL) \ + ctx->handle_array \ + = g_array_new (FALSE, FALSE, sizeof (CoglHandle)); \ + \ + g_array_append_val (ctx->handle_array, handle); \ + \ + return handle; \ + } \ + \ + static void \ + _cogl_##type_name##_handle_release (CoglHandle handle) \ + { \ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); \ + \ + gint i; \ + \ + if ( (i = _cogl_##type_name##_handle_find (handle)) == -1) \ + return; \ + \ + g_array_remove_index_fast (ctx->handle_array, i); \ + } \ + \ + Cogl##TypeName * \ + _cogl_##type_name##_pointer_from_handle (CoglHandle handle) \ + { \ + return (Cogl##TypeName *) handle; \ + } \ + \ + gboolean \ + cogl_is_##type_name (CoglHandle handle) \ + { \ + if (handle == COGL_INVALID_HANDLE) \ + return FALSE; \ + \ + return _cogl_##type_name##_handle_find (handle) >= 0; \ + } \ + \ + CoglHandle \ + cogl_##type_name##_ref (CoglHandle handle) \ + { \ + Cogl##TypeName *obj; \ + \ + if (!cogl_is_##type_name (handle)) \ + return COGL_INVALID_HANDLE; \ + \ + obj = _cogl_##type_name##_pointer_from_handle (handle); \ + \ + obj->ref_count++; \ + \ + COGL_HANDLE_DEBUG_REF (type_name, obj); \ + \ + return handle; \ + } \ + \ + void \ + cogl_##type_name##_unref (CoglHandle handle) \ + { \ + Cogl##TypeName *obj; \ + \ + if (!cogl_is_##type_name (handle)) \ + return; \ + \ + obj = _cogl_##type_name##_pointer_from_handle (handle); \ + \ + COGL_HANDLE_DEBUG_UNREF (type_name, obj); \ + \ + if (--obj->ref_count < 1) \ + { \ + COGL_HANDLE_DEBUG_FREE (type_name, obj); \ + \ + _cogl_##type_name##_handle_release (obj); \ + _cogl_##type_name##_free (obj); \ + } \ + } + +#endif /* __COGL_HANDLE_H */ diff --git a/clutter/cogl/gl/Makefile.am b/clutter/cogl/gl/Makefile.am index be2e20606..7b019de24 100644 --- a/clutter/cogl/gl/Makefile.am +++ b/clutter/cogl/gl/Makefile.am @@ -25,11 +25,15 @@ libclutter_cogl_la_SOURCES = \ cogl-primitives.h \ cogl-texture.h \ cogl-fbo.h \ + cogl-shader.h \ + cogl-program.h \ cogl-context.h \ cogl.c \ cogl-primitives.c \ cogl-texture.c \ cogl-fbo.c \ + cogl-shader.c \ + cogl-program.c \ cogl-context.c EXTRA_DIST = cogl-defines.h.in diff --git a/clutter/cogl/gl/cogl-context.c b/clutter/cogl/gl/cogl-context.c index 936d7e9bf..50196a7dc 100644 --- a/clutter/cogl/gl/cogl-context.c +++ b/clutter/cogl/gl/cogl-context.c @@ -60,6 +60,10 @@ cogl_create_context () _context->fbo_handles = NULL; _context->draw_buffer = COGL_WINDOW_BUFFER; + + _context->shader_handles = NULL; + + _context->program_handles = NULL; _context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL; @@ -99,6 +103,15 @@ cogl_destroy_context () { if (_context == NULL) return; + + if (_context->texture_handles) + g_array_free (_context->texture_handles, TRUE); + if (_context->fbo_handles) + g_array_free (_context->texture_handles, TRUE); + if (_context->shader_handles) + g_array_free (_context->texture_handles, TRUE); + if (_context->program_handles) + g_array_free (_context->program_handles, TRUE); g_free (_context); } diff --git a/clutter/cogl/gl/cogl-context.h b/clutter/cogl/gl/cogl-context.h index 4e952cc5f..15bb4257c 100644 --- a/clutter/cogl/gl/cogl-context.h +++ b/clutter/cogl/gl/cogl-context.h @@ -53,6 +53,12 @@ typedef struct /* Framebuffer objects */ GArray *fbo_handles; CoglBufferTarget draw_buffer; + + /* Shaders */ + GArray *shader_handles; + + /* Programs */ + GArray *program_handles; /* Relying on glext.h to define these */ PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT; diff --git a/clutter/cogl/gl/cogl-defines.h.in b/clutter/cogl/gl/cogl-defines.h.in index 36a99a806..b3a61e1a0 100644 --- a/clutter/cogl/gl/cogl-defines.h.in +++ b/clutter/cogl/gl/cogl-defines.h.in @@ -42,7 +42,6 @@ G_BEGIN_DECLS typedef GLenum COGLenum; typedef GLint COGLint; typedef GLuint COGLuint; -typedef GLhandleARB COGLhandle; /* FIXME + DOCUMENT */ diff --git a/clutter/cogl/gl/cogl-fbo.c b/clutter/cogl/gl/cogl-fbo.c index f4fb968d5..d920dd96b 100644 --- a/clutter/cogl/gl/cogl-fbo.c +++ b/clutter/cogl/gl/cogl-fbo.c @@ -33,6 +33,7 @@ #include "cogl-texture.h" #include "cogl-fbo.h" #include "cogl-context.h" +#include "cogl-handle.h" /* Expecting EXT functions not to be defined - redirect to pointers in context */ #define glGenRenderbuffersEXT ctx->pf_glGenRenderbuffersEXT @@ -47,65 +48,9 @@ #define glBlitFramebufferEXT ctx->pf_glBlitFramebufferEXT #define glRenderbufferStorageMultisampleEXT ctx->pf_glRenderbufferStorageMultisampleEXT -static gint -_cogl_fbo_handle_find (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, -1); - - gint i; - - if (ctx->fbo_handles == NULL) - return -1; - - for (i=0; i < ctx->fbo_handles->len; ++i) - if (g_array_index (ctx->fbo_handles, CoglHandle, i) == handle) - return i; - - return -1; -} +static void _cogl_offscreen_free (CoglFbo *fbo); -static CoglHandle -_cogl_fbo_handle_new (CoglFbo *fbo) -{ - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); - - CoglHandle handle = (CoglHandle)fbo; - - if (ctx->fbo_handles == NULL) - ctx->fbo_handles = g_array_new (FALSE, FALSE, sizeof (CoglHandle)); - - g_array_append_val (ctx->fbo_handles, handle); - - return handle; -} - -static void -_cogl_fbo_handle_release (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - gint i; - - if ( (i = _cogl_fbo_handle_find (handle)) == -1) - return; - - g_array_remove_index_fast (ctx->fbo_handles, i); -} - -static CoglFbo* -_cogl_fbo_pointer_from_handle (CoglHandle handle) -{ - return (CoglFbo*) handle; -} - -gboolean -cogl_is_offscreen_buffer (CoglHandle handle) -{ - if (handle == COGL_INVALID_HANDLE) - return FALSE; - - return _cogl_fbo_handle_find (handle) >= 0; -} +COGL_HANDLE_DEFINE (Fbo, offscreen, fbo_handles); CoglHandle cogl_offscreen_new_to_texture (CoglHandle texhandle) @@ -166,8 +111,10 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle) fbo->width = x_span->size - x_span->waste; fbo->height = y_span->size - y_span->waste; fbo->gl_handle = fbo_gl_handle; + + COGL_HANDLE_DEBUG_NEW (offscreen, fbo); - return _cogl_fbo_handle_new (fbo); + return _cogl_offscreen_handle_new (fbo); } CoglHandle @@ -179,43 +126,16 @@ cogl_offscreen_new_multisample () return COGL_INVALID_HANDLE; } -CoglHandle -cogl_offscreen_ref (CoglHandle handle) -{ - CoglFbo *fbo; - - if (!cogl_is_offscreen_buffer (handle)) - return COGL_INVALID_HANDLE; - - fbo = _cogl_fbo_pointer_from_handle (handle); - - fbo->ref_count++; - - return handle; -} - -void -cogl_offscreen_unref (CoglHandle handle) +static void +_cogl_offscreen_free (CoglFbo *fbo) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - CoglFbo *fbo; - - /* Make sure this is a valid fbo handle */ - if (!cogl_is_offscreen_buffer (handle)) - return; - - fbo = _cogl_fbo_pointer_from_handle (handle); - if (--fbo->ref_count < 1) - { - /* Release handle and destroy object */ - GE( glDeleteFramebuffersEXT (1, &fbo->gl_handle) ); + /* Frees FBO resources but its handle is not + released! Do that separately before this! */ - _cogl_fbo_handle_release (handle); - - g_free (fbo); - } + GE( glDeleteFramebuffersEXT (1, &fbo->gl_handle) ); + g_free (fbo); } void @@ -239,14 +159,14 @@ cogl_offscreen_blit_region (CoglHandle src_buffer, CoglFbo *dst_fbo; /* Make sure these are valid fbo handles */ - if (!cogl_is_offscreen_buffer (src_buffer)) + if (!cogl_is_offscreen (src_buffer)) return; - if (!cogl_is_offscreen_buffer (dst_buffer)) + if (!cogl_is_offscreen (dst_buffer)) return; - src_fbo = _cogl_fbo_pointer_from_handle (src_buffer); - dst_fbo = _cogl_fbo_pointer_from_handle (dst_buffer); + src_fbo = _cogl_offscreen_pointer_from_handle (src_buffer); + dst_fbo = _cogl_offscreen_pointer_from_handle (dst_buffer); /* Copy (and scale) a region from one to another framebuffer */ GE( glBindFramebufferEXT (GL_READ_FRAMEBUFFER_EXT, src_fbo->gl_handle) ); @@ -269,14 +189,14 @@ cogl_offscreen_blit (CoglHandle src_buffer, CoglFbo *dst_fbo; /* Make sure these are valid fbo handles */ - if (!cogl_is_offscreen_buffer (src_buffer)) + if (!cogl_is_offscreen (src_buffer)) return; - if (!cogl_is_offscreen_buffer (dst_buffer)) + if (!cogl_is_offscreen (dst_buffer)) return; - src_fbo = _cogl_fbo_pointer_from_handle (src_buffer); - dst_fbo = _cogl_fbo_pointer_from_handle (dst_buffer); + src_fbo = _cogl_offscreen_pointer_from_handle (src_buffer); + dst_fbo = _cogl_offscreen_pointer_from_handle (dst_buffer); /* Copy (and scale) whole image from one to another framebuffer */ GE( glBindFramebufferEXT (GL_READ_FRAMEBUFFER_EXT, src_fbo->gl_handle) ); @@ -296,10 +216,10 @@ cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) if (target == COGL_OFFSCREEN_BUFFER) { /* Make sure it is a valid fbo handle */ - if (!cogl_is_offscreen_buffer (offscreen)) + if (!cogl_is_offscreen (offscreen)) return; - fbo = _cogl_fbo_pointer_from_handle (offscreen); + fbo = _cogl_offscreen_pointer_from_handle (offscreen); /* Check current draw buffer target */ if (ctx->draw_buffer != COGL_OFFSCREEN_BUFFER) diff --git a/clutter/cogl/gl/cogl-program.c b/clutter/cogl/gl/cogl-program.c new file mode 100644 index 000000000..40b066870 --- /dev/null +++ b/clutter/cogl/gl/cogl-program.c @@ -0,0 +1,150 @@ +/* + * Clutter COGL + * + * A basic GL/GLES Abstraction/Utility Layer + * + * Authored By Matthew Allum + * + * Copyright (C) 2008 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "cogl.h" +#include "cogl-program.h" +#include "cogl-shader.h" +#include "cogl-internal.h" +#include "cogl-handle.h" +#include "cogl-context.h" + +#include + +/* Expecting ARB functions not to be defined */ +#define glCreateProgramObjectARB ctx->pf_glCreateProgramObjectARB +#define glAttachObjectARB ctx->pf_glAttachObjectARB +#define glUseProgramObjectARB ctx->pf_glUseProgramObjectARB +#define glLinkProgramARB ctx->pf_glLinkProgramARB +#define glGetUniformLocationARB ctx->pf_glGetUniformLocationARB +#define glUniform1fARB ctx->pf_glUniform1fARB +#define glDeleteObjectARB ctx->pf_glDeleteObjectARB + +static void _cogl_program_free (CoglProgram *program); + +COGL_HANDLE_DEFINE (Program, program, program_handles); + +static void +_cogl_program_free (CoglProgram *program) +{ + /* Frees program resources but its handle is not + released! Do that separately before this! */ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + glDeleteObjectARB (program->gl_handle); +} + +CoglHandle +cogl_create_program (void) +{ + CoglProgram *program; + _COGL_GET_CONTEXT (ctx, 0); + + program = g_slice_new (CoglProgram); + program->ref_count = 1; + program->gl_handle = glCreateProgramObjectARB (); + + COGL_HANDLE_DEBUG_NEW (program, program); + + return _cogl_program_handle_new (program); +} + +void +cogl_program_attach_shader (CoglHandle program_handle, + CoglHandle shader_handle) +{ + CoglProgram *program; + CoglShader *shader; + + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle)) + return; + + program = _cogl_program_pointer_from_handle (program_handle); + shader = _cogl_shader_pointer_from_handle (shader_handle); + + glAttachObjectARB (program->gl_handle, shader->gl_handle); +} + +void +cogl_program_link (CoglHandle handle) +{ + CoglProgram *program; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_program (handle)) + return; + + program = _cogl_program_pointer_from_handle (handle); + + glLinkProgramARB (program->gl_handle); +} + +void +cogl_program_use (CoglHandle handle) +{ + CoglProgram *program; + GLhandleARB gl_handle; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (handle != COGL_INVALID_HANDLE && !cogl_is_program (handle)) + return; + + if (handle == COGL_INVALID_HANDLE) + gl_handle = 0; + else + { + program = _cogl_program_pointer_from_handle (handle); + gl_handle = program->gl_handle; + } + + glUseProgramObjectARB (gl_handle); +} + +COGLint +cogl_program_get_uniform_location (CoglHandle handle, + const gchar *uniform_name) +{ + CoglProgram *program; + _COGL_GET_CONTEXT (ctx, 0); + + if (!cogl_is_program (handle)) + return 0; + + program = _cogl_program_pointer_from_handle (handle); + + return glGetUniformLocationARB (program->gl_handle, uniform_name); +} + +void +cogl_program_uniform_1f (COGLint uniform_no, + gfloat value) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + glUniform1fARB (uniform_no, value); +} diff --git a/clutter/cogl/gl/cogl-program.h b/clutter/cogl/gl/cogl-program.h new file mode 100644 index 000000000..6793631d7 --- /dev/null +++ b/clutter/cogl/gl/cogl-program.h @@ -0,0 +1,39 @@ +/* + * Clutter COGL + * + * A basic GL/GLES Abstraction/Utility Layer + * + * Authored By Matthew Allum + * + * Copyright (C) 2008 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __COGL_PROGRAM_H +#define __COGL_PROGRAM_H + +typedef struct _CoglProgram CoglProgram; + +struct _CoglProgram +{ + guint ref_count; + GLhandleARB gl_handle; +}; + +CoglProgram *_cogl_program_pointer_from_handle (CoglHandle handle); + +#endif /* __COGL_PROGRAM_H */ diff --git a/clutter/cogl/gl/cogl-shader.c b/clutter/cogl/gl/cogl-shader.c new file mode 100644 index 000000000..7ef749ed1 --- /dev/null +++ b/clutter/cogl/gl/cogl-shader.c @@ -0,0 +1,136 @@ +/* + * Clutter COGL + * + * A basic GL/GLES Abstraction/Utility Layer + * + * Authored By Matthew Allum + * + * Copyright (C) 2008 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "cogl.h" +#include "cogl-shader.h" +#include "cogl-internal.h" +#include "cogl-context.h" +#include "cogl-handle.h" + +#include + +/* Expecting ARB functions not to be defined */ +#define glCreateShaderObjectARB ctx->pf_glCreateShaderObjectARB +#define glGetObjectParameterivARB ctx->pf_glGetObjectParameterivARB +#define glGetInfoLogARB ctx->pf_glGetInfoLogARB +#define glCompileShaderARB ctx->pf_glCompileShaderARB +#define glShaderSourceARB ctx->pf_glShaderSourceARB +#define glDeleteObjectARB ctx->pf_glDeleteObjectARB + +static void _cogl_shader_free (CoglShader *shader); + +COGL_HANDLE_DEFINE (Shader, shader, shader_handles); + +static void +_cogl_shader_free (CoglShader *shader) +{ + /* Frees shader resources but its handle is not + released! Do that separately before this! */ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + glDeleteObjectARB (shader->gl_handle); +} + +CoglHandle +cogl_create_shader (COGLenum shaderType) +{ + CoglShader *shader; + + _COGL_GET_CONTEXT (ctx, 0); + + shader = g_slice_new (CoglShader); + shader->ref_count = 1; + shader->gl_handle = glCreateShaderObjectARB (shaderType); + + COGL_HANDLE_DEBUG_NEW (shader, shader); + + return _cogl_shader_handle_new (shader); +} + +void +cogl_shader_source (CoglHandle handle, + const gchar *source) +{ + CoglShader *shader; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_shader (handle)) + return; + + shader = _cogl_shader_pointer_from_handle (handle); + + glShaderSourceARB (shader->gl_handle, 1, &source, NULL); +} + +void +cogl_shader_compile (CoglHandle handle) +{ + CoglShader *shader; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_shader (handle)) + return; + + shader = _cogl_shader_pointer_from_handle (handle); + + glCompileShaderARB (shader->gl_handle); +} + +void +cogl_shader_get_info_log (CoglHandle handle, + guint size, + gchar *buffer) +{ + CoglShader *shader; + COGLint len; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_shader (handle)) + return; + + shader = _cogl_shader_pointer_from_handle (handle); + + glGetInfoLogARB (shader->gl_handle, size-1, &len, buffer); + buffer[len]='\0'; +} + +void +cogl_shader_get_parameteriv (CoglHandle handle, + COGLenum pname, + COGLint *dest) +{ + CoglShader *shader; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (!cogl_is_shader (handle)) + return; + + shader = _cogl_shader_pointer_from_handle (handle); + + glGetObjectParameterivARB (shader->gl_handle, pname, dest); +} diff --git a/clutter/cogl/gl/cogl-shader.h b/clutter/cogl/gl/cogl-shader.h new file mode 100644 index 000000000..4b064e420 --- /dev/null +++ b/clutter/cogl/gl/cogl-shader.h @@ -0,0 +1,39 @@ +/* + * Clutter COGL + * + * A basic GL/GLES Abstraction/Utility Layer + * + * Authored By Matthew Allum + * + * Copyright (C) 2008 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __COGL_SHADER_H +#define __COGL_SHADER_H + +typedef struct _CoglShader CoglShader; + +struct _CoglShader +{ + guint ref_count; + GLhandleARB gl_handle; +}; + +CoglShader *_cogl_shader_pointer_from_handle (CoglHandle handle); + +#endif /* __COGL_SHADER_H */ diff --git a/clutter/cogl/gl/cogl-texture.c b/clutter/cogl/gl/cogl-texture.c index 5e4d6ee54..04590da68 100644 --- a/clutter/cogl/gl/cogl-texture.c +++ b/clutter/cogl/gl/cogl-texture.c @@ -33,6 +33,7 @@ #include "cogl-bitmap.h" #include "cogl-texture.h" #include "cogl-context.h" +#include "cogl-handle.h" #include #include @@ -48,6 +49,10 @@ printf("err: 0x%x\n", err); \ } */ +static void _cogl_texture_free (CoglTexture *tex); + +COGL_HANDLE_DEFINE (Texture, texture, texture_handles); + struct _CoglSpanIter { gint index; @@ -65,93 +70,6 @@ struct _CoglSpanIter gboolean intersects; }; -/* - * _cogl_texture_handle_find: - * @handle: A texture handle - * - * Returns the index of the given CoglHandle if found in the - * handle array. - */ -static gint -_cogl_texture_handle_find (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, -1); - - gint i; - - if (ctx->texture_handles == NULL) - return -1; - - for (i=0; i < ctx->texture_handles->len; ++i) - if (g_array_index (ctx->texture_handles, CoglHandle, i) == handle) - return i; - - return -1; -} - -/* - * _cogl_texture_handle_new: - * @tex: A pointer to an allocated CoglTexture structure - * - * Returns a new CoglHandle for the given CoglTexture - * object. - */ -static CoglHandle -_cogl_texture_handle_new (CoglTexture *tex) -{ - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); - - CoglHandle handle = (CoglHandle)tex; - - if (ctx->texture_handles == NULL) - ctx->texture_handles = g_array_new (FALSE, FALSE, sizeof (CoglHandle)); - - g_array_append_val (ctx->texture_handles, handle); - - return handle; -} - -/* - * _cogl_texture_handle_release: - * @handle: A valid CoglHandle - * - * Frees the given CoglHandle for use with another object. - */ -static void -_cogl_texture_handle_release (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - gint i; - - if ( (i = _cogl_texture_handle_find (handle)) == -1) - return; - - g_array_remove_index_fast (ctx->texture_handles, i); -} - -/* - * _cogl_texture_pointer_from_handle: - * @handle: A valid CoglHandle - * - * Returns a pointer to the texture object referenced by - * given handle. - */ -CoglTexture * -_cogl_texture_pointer_from_handle (CoglHandle handle) -{ - return (CoglTexture*) handle; -} - -gboolean -cogl_is_texture (CoglHandle handle) -{ - if (handle == COGL_INVALID_HANDLE) - return FALSE; - - return _cogl_texture_handle_find (handle) >= 0; -} - static void _cogl_texture_bitmap_free (CoglTexture *tex) { @@ -1089,9 +1007,7 @@ cogl_texture_new_with_size (guint width, tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex->ref_count = 1; -#if COGL_DEBUG - printf ("COGL TEX new %p %i\n", tex, tex->ref_count); -#endif + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1153,9 +1069,7 @@ cogl_texture_new_from_data (guint width, tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex->ref_count = 1; -#if COGL_DEBUG - printf ("COGL TEX new %p %i\n", tex, tex->ref_count); -#endif + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1230,9 +1144,7 @@ cogl_texture_new_from_file (const gchar *filename, tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex->ref_count = 1; -#if COGL_DEBUG - printf ("COGL TEX new %p %i\n", tex, tex->ref_count); -#endif + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1377,9 +1289,7 @@ cogl_texture_new_from_foreign (GLuint gl_handle, tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex->ref_count = 1; -#if COGL_DEBUG - printf ("COGL TEX new %p %i\n", tex, tex->ref_count); -#endif + COGL_HANDLE_DEBUG_NEW (texture, tex); /* Setup bitmap info */ tex->is_foreign = TRUE; @@ -1460,51 +1370,6 @@ cogl_texture_new_from_foreign (GLuint gl_handle, return _cogl_texture_handle_new (tex); } -CoglHandle -cogl_texture_ref (CoglHandle handle) -{ - CoglTexture *tex; - - if (!cogl_is_texture (handle)) - return COGL_INVALID_HANDLE; - - tex = _cogl_texture_pointer_from_handle (handle); - - tex->ref_count++; -#if COGL_DEBUG - printf ("COGL TEX ref %p %i\n", tex, tex->ref_count); -#endif - - return handle; -} - -void -cogl_texture_unref (CoglHandle handle) -{ - /* Check if valid texture handle */ - CoglTexture *tex; - - if (!cogl_is_texture (handle)) - return; - - tex = _cogl_texture_pointer_from_handle (handle); - -#if COGL_DEBUG - printf ("COGL TEX unref %p %i\n", tex, tex->ref_count - 1); -#endif - - if (--tex->ref_count < 1) - { -#if COGL_DEBUG - printf ("COGL TEX free %p %i\n", tex, tex->ref_count - 1); -#endif - - /* Free texture handle and resources */ - _cogl_texture_handle_release (tex); - _cogl_texture_free (tex); - } -} - guint cogl_texture_get_width (CoglHandle handle) { diff --git a/clutter/cogl/gl/cogl.c b/clutter/cogl/gl/cogl.c index 3e8fc350b..b9a3734f2 100644 --- a/clutter/cogl/gl/cogl.c +++ b/clutter/cogl/gl/cogl.c @@ -78,22 +78,6 @@ error_string(GLenum errorCode) } #endif - -/* Expecting ARB functions not to be defined */ -#define glCreateProgramObjectARB ctx->pf_glCreateProgramObjectARB -#define glCreateShaderObjectARB ctx->pf_glCreateShaderObjectARB -#define glShaderSourceARB ctx->pf_glShaderSourceARB -#define glCompileShaderARB ctx->pf_glCompileShaderARB -#define glAttachObjectARB ctx->pf_glAttachObjectARB -#define glLinkProgramARB ctx->pf_glLinkProgramARB -#define glUseProgramObjectARB ctx->pf_glUseProgramObjectARB -#define glGetUniformLocationARB ctx->pf_glGetUniformLocationARB -#define glDeleteObjectARB ctx->pf_glDeleteObjectARB -#define glGetInfoLogARB ctx->pf_glGetInfoLogARB -#define glGetObjectParameterivARB ctx->pf_glGetObjectParameterivARB -#define glUniform1fARB ctx->pf_glUniform1fARB - - CoglFuncPtr cogl_get_proc_address (const gchar* name) { @@ -937,106 +921,3 @@ cogl_fog_set (const ClutterColor *fog_color, glFogf (GL_FOG_START, CLUTTER_FIXED_TO_FLOAT (start)); glFogf (GL_FOG_END, CLUTTER_FIXED_TO_FLOAT (stop)); } - -/* Shader Magic follows */ - -COGLhandle -cogl_create_program (void) -{ - _COGL_GET_CONTEXT (ctx, 0); - return glCreateProgramObjectARB (); -} - -COGLhandle -cogl_create_shader (COGLenum shaderType) -{ - _COGL_GET_CONTEXT (ctx, 0); - return glCreateShaderObjectARB (shaderType); -} - -void -cogl_shader_source (COGLhandle shader, - const gchar *source) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glShaderSourceARB (shader, 1, &source, NULL); -} - -void -cogl_shader_compile (COGLhandle shader_handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glCompileShaderARB (shader_handle); -} - -void -cogl_program_attach_shader (COGLhandle program_handle, - COGLhandle shader_handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glAttachObjectARB (program_handle, shader_handle); -} - -void -cogl_program_link (COGLhandle program_handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glLinkProgramARB (program_handle); -} - -void -cogl_program_use (COGLhandle program_handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glUseProgramObjectARB (program_handle); -} - -COGLint -cogl_program_get_uniform_location (COGLhandle program_handle, - const gchar *uniform_name) -{ - _COGL_GET_CONTEXT (ctx, 0); - return glGetUniformLocationARB (program_handle, uniform_name); -} - -void -cogl_program_destroy (COGLhandle handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glDeleteObjectARB (handle); -} - -void -cogl_shader_destroy (COGLhandle handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glDeleteObjectARB (handle); -} - -void -cogl_shader_get_info_log (COGLhandle handle, - guint size, - gchar *buffer) -{ - COGLint len; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glGetInfoLogARB (handle, size-1, &len, buffer); - buffer[len]='\0'; -} - -void -cogl_shader_get_parameteriv (COGLhandle handle, - COGLenum pname, - COGLint *dest) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glGetObjectParameterivARB (handle, pname, dest); -} - -void -cogl_program_uniform_1f (COGLint uniform_no, - gfloat value) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - glUniform1fARB (uniform_no, value); -} diff --git a/clutter/cogl/gles/cogl-defines.h.in b/clutter/cogl/gles/cogl-defines.h.in index b304680f9..d97ab066c 100644 --- a/clutter/cogl/gles/cogl-defines.h.in +++ b/clutter/cogl/gles/cogl-defines.h.in @@ -440,7 +440,6 @@ G_BEGIN_DECLS typedef GLenum COGLenum; typedef GLint COGLint; typedef GLuint COGLuint; -typedef GLuint COGLhandle; /* extras */ diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c index a9b67a034..a28aa9c1c 100644 --- a/clutter/cogl/gles/cogl-texture.c +++ b/clutter/cogl/gles/cogl-texture.c @@ -33,6 +33,7 @@ #include "cogl-bitmap.h" #include "cogl-texture.h" #include "cogl-context.h" +#include "cogl-handle.h" #include #include @@ -64,83 +65,9 @@ struct _CoglSpanIter gboolean intersects; }; -/* - * _cogl_texture_handle_find: - * @handle: A texture handle - * - * Returns the index of the given CoglHandle if found in the - * handle array. - */ -static gint -_cogl_texture_handle_find (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, -1); - - gint i; - - if (ctx->texture_handles == NULL) - return -1; - - for (i=0; i < ctx->texture_handles->len; ++i) - if (g_array_index (ctx->texture_handles, CoglHandle, i) == handle) - return i; - - return -1; -} +static void _cogl_texture_free (CoglTexture *tex); -/* - * _cogl_texture_handle_new: - * @tex: A pointer to an allocated CoglTexture structure - * - * Returns a new CoglHandle for the given CoglTexture - * object. - */ -static CoglHandle -_cogl_texture_handle_new (CoglTexture *tex) -{ - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); - - CoglHandle handle = (CoglHandle)tex; - - if (ctx->texture_handles == NULL) - ctx->texture_handles = g_array_new (FALSE, FALSE, sizeof (CoglHandle)); - - g_array_append_val (ctx->texture_handles, handle); - - return handle; -} - -/* - * _cogl_texture_handle_release: - * @handle: A valid CoglHandle - * - * Frees the given CoglHandle for use with another object. - */ -static void -_cogl_texture_handle_release (CoglHandle handle) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - gint i; - - if ( (i = _cogl_texture_handle_find (handle)) == -1) - return; - - g_array_remove_index_fast (ctx->texture_handles, i); -} - -/* - * _cogl_texture_pointer_from_handle: - * @handle: A valid CoglHandle - * - * Returns a pointer to the texture object referenced by - * given handle. - */ -CoglTexture * -_cogl_texture_pointer_from_handle (CoglHandle handle) -{ - return (CoglTexture*) handle; -} +COGL_HANDLE_DEFINE (Texture, texture, texture_handles); CoglHandle _cogl_texture_handle_from_pointer (CoglTexture *tex) @@ -148,15 +75,6 @@ _cogl_texture_handle_from_pointer (CoglTexture *tex) return (CoglHandle) tex; } -gboolean -cogl_is_texture (CoglHandle handle) -{ - if (handle == COGL_INVALID_HANDLE) - return FALSE; - - return _cogl_texture_handle_find (handle) >= 0; -} - static void _cogl_texture_bitmap_free (CoglTexture *tex) { @@ -1038,6 +956,7 @@ cogl_texture_new_with_size (guint width, tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex->ref_count = 1; + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1098,6 +1017,7 @@ cogl_texture_new_from_data (guint width, tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex->ref_count = 1; + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1172,6 +1092,7 @@ cogl_texture_new_from_file (const gchar *filename, tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex->ref_count = 1; + COGL_HANDLE_DEBUG_NEW (texture, tex); tex->is_foreign = FALSE; @@ -1283,9 +1204,7 @@ cogl_texture_new_from_foreign (GLuint gl_handle, tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex->ref_count = 1; -#if COGL_DEBUG - printf ("COGL TEX new %p %i\n", tex, tex->ref_count); -#endif + COGL_HANDLE_DEBUG_NEW (texture, tex); /* Setup bitmap info */ tex->is_foreign = TRUE; @@ -1354,40 +1273,6 @@ cogl_texture_new_from_foreign (GLuint gl_handle, return _cogl_texture_handle_new (tex); } -CoglHandle -cogl_texture_ref (CoglHandle handle) -{ - CoglTexture *tex; - - if (!cogl_is_texture (handle)) - return COGL_INVALID_HANDLE; - - tex = _cogl_texture_pointer_from_handle (handle); - - tex->ref_count++; - - return handle; -} - -void -cogl_texture_unref (CoglHandle handle) -{ - /* Check if valid texture handle */ - CoglTexture *tex; - - if (!cogl_is_texture (handle)) - return; - - tex = _cogl_texture_pointer_from_handle (handle); - - if (--tex->ref_count < 1) - { - /* Free texture handle and resources */ - _cogl_texture_handle_release (tex); - _cogl_texture_free (tex); - } -} - void cogl_texture_get_properties (CoglHandle handle, guint *out_width, diff --git a/clutter/cogl/gles/cogl.c b/clutter/cogl/gles/cogl.c index 455f80085..739cb9724 100644 --- a/clutter/cogl/gles/cogl.c +++ b/clutter/cogl/gles/cogl.c @@ -562,71 +562,95 @@ cogl_fog_set (const ClutterColor *fog_color, /* Shaders, no support on regular OpenGL 1.1 */ -COGLhandle +CoglHandle cogl_create_program (void) { - return 0; + return COGL_INVALID_HANDLE; } -COGLhandle -cogl_create_shader (COGLenum shaderType) +gboolean +cogl_is_program (CoglHandle handle) { - return 0; + return FALSE; +} + +CoglHandle +cogl_program_ref (CoglHandle handle) +{ + return COGL_INVALID_HANDLE; } void -cogl_shader_source (COGLhandle shader, +cogl_program_unref (CoglHandle handle) +{ +} + +CoglHandle +cogl_create_shader (COGLenum shaderType) +{ + return COGL_INVALID_HANDLE; +} + +gboolean +cogl_is_shader (CoglHandle handle) +{ + return FALSE; +} + +CoglHandle +cogl_shader_ref (CoglHandle handle) +{ + return COGL_INVALID_HANDLE; +} + +void +cogl_shader_unref (CoglHandle handle) +{ +} + +void +cogl_shader_source (CoglHandle shader, const gchar *source) { } void -cogl_shader_compile (COGLhandle shader_handle) +cogl_shader_compile (CoglHandle shader_handle) { } void -cogl_program_attach_shader (COGLhandle program_handle, - COGLhandle shader_handle) +cogl_program_attach_shader (CoglHandle program_handle, + CoglHandle shader_handle) { } void -cogl_program_link (COGLhandle program_handle) +cogl_program_link (CoglHandle program_handle) { } void -cogl_program_use (COGLhandle program_handle) +cogl_program_use (CoglHandle program_handle) { } COGLint -cogl_program_get_uniform_location (COGLhandle program_handle, +cogl_program_get_uniform_location (CoglHandle program_handle, const gchar *uniform_name) { return 0; } void -cogl_program_destroy (COGLhandle handle) -{ -} - -void -cogl_shader_destroy (COGLhandle handle) -{ -} - -void -cogl_shader_get_info_log (COGLhandle handle, +cogl_shader_get_info_log (CoglHandle handle, guint size, gchar *buffer) { } void -cogl_shader_get_parameteriv (COGLhandle handle, +cogl_shader_get_parameteriv (CoglHandle handle, COGLenum pname, COGLint *dest) { diff --git a/doc/reference/ChangeLog b/doc/reference/ChangeLog index 0412bcbd1..94f32d345 100644 --- a/doc/reference/ChangeLog +++ b/doc/reference/ChangeLog @@ -1,3 +1,9 @@ +2008-04-29 Neil Roberts + + * cogl/cogl-sections.txt: Added cogl_shader_ref, + cogl_shader_unref, cogl_is_shader, cogl_program_ref, + cogl_program_unref, cogl_is_program and cogl_is_offscreen. + 2008-04-29 Øyvind Kolås * cogl/cogl-sections.txt: updated after cogl primitives api rename diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index 636d7a779..5e3d2dc2d 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -109,14 +109,18 @@ cogl_texture_polygon cogl-shaders Shaders and Programmable Pipeline cogl_create_shader -cogl_shader_destroy +cogl_shader_ref +cogl_shader_unref +cogl_is_shader cogl_shader_source cogl_shader_compile cogl_shader_get_info_log cogl_shader_get_parameteriv cogl_create_program -cogl_program_destroy +cogl_program_ref +cogl_program_unref +cogl_is_program cogl_program_attach_shader cogl_program_link cogl_program_use @@ -131,6 +135,7 @@ cogl_offscreen_new_to_texture cogl_offscreen_new_multisample cogl_offscreen_ref cogl_offscreen_unref +cogl_is_offscreen cogl_offscreen_blit cogl_offscreen_blit_region cogl_draw_buffer