mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
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. * 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.
This commit is contained in:
parent
f2b367c092
commit
0e0890a2e9
121
cogl.h.in
121
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);
|
||||
|
||||
|
||||
@ -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:
|
||||
|
@ -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 \
|
||||
|
160
common/cogl-handle.h
Normal file
160
common/cogl-handle.h
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 */
|
@ -109,14 +109,18 @@ cogl_texture_polygon
|
||||
<FILE>cogl-shaders</FILE>
|
||||
<TITLE>Shaders and Programmable Pipeline</TITLE>
|
||||
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
|
||||
<SUBSECTION>
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -61,6 +61,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;
|
||||
_context->pf_glRenderbufferStorageEXT = NULL;
|
||||
@ -100,6 +104,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);
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,12 @@ typedef struct
|
||||
GArray *fbo_handles;
|
||||
CoglBufferTarget draw_buffer;
|
||||
|
||||
/* Shaders */
|
||||
GArray *shader_handles;
|
||||
|
||||
/* Programs */
|
||||
GArray *program_handles;
|
||||
|
||||
/* Relying on glext.h to define these */
|
||||
PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
|
||||
PFNGLBINDRENDERBUFFEREXTPROC pf_glBindRenderbufferEXT;
|
||||
|
@ -42,7 +42,6 @@ G_BEGIN_DECLS
|
||||
typedef GLenum COGLenum;
|
||||
typedef GLint COGLint;
|
||||
typedef GLuint COGLuint;
|
||||
typedef GLhandleARB COGLhandle;
|
||||
|
||||
/* FIXME + DOCUMENT */
|
||||
|
||||
|
120
gl/cogl-fbo.c
120
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);
|
||||
static void _cogl_offscreen_free (CoglFbo *fbo);
|
||||
|
||||
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 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)
|
||||
@ -167,7 +112,9 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
|
||||
fbo->height = y_span->size - y_span->waste;
|
||||
fbo->gl_handle = fbo_gl_handle;
|
||||
|
||||
return _cogl_fbo_handle_new (fbo);
|
||||
COGL_HANDLE_DEBUG_NEW (offscreen, 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;
|
||||
/* Frees FBO resources but its handle is not
|
||||
released! Do that separately before this! */
|
||||
|
||||
/* 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) );
|
||||
|
||||
_cogl_fbo_handle_release (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)
|
||||
|
150
gl/cogl-program.c
Normal file
150
gl/cogl-program.c
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 <glib.h>
|
||||
|
||||
/* 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);
|
||||
}
|
39
gl/cogl-program.h
Normal file
39
gl/cogl-program.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 */
|
136
gl/cogl-shader.c
Normal file
136
gl/cogl-shader.c
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 <glib.h>
|
||||
|
||||
/* 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);
|
||||
}
|
39
gl/cogl-shader.h
Normal file
39
gl/cogl-shader.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Clutter COGL
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
*
|
||||
* 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 */
|
@ -33,6 +33,7 @@
|
||||
#include "cogl-bitmap.h"
|
||||
#include "cogl-texture.h"
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -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)
|
||||
{
|
||||
|
119
gl/cogl.c
119
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);
|
||||
}
|
||||
|
@ -440,7 +440,6 @@ G_BEGIN_DECLS
|
||||
typedef GLenum COGLenum;
|
||||
typedef GLint COGLint;
|
||||
typedef GLuint COGLuint;
|
||||
typedef GLuint COGLhandle;
|
||||
|
||||
/* extras */
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "cogl-bitmap.h"
|
||||
#include "cogl-texture.h"
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -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);
|
||||
static void _cogl_texture_free (CoglTexture *tex);
|
||||
|
||||
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;
|
||||
}
|
||||
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,
|
||||
|
72
gles/cogl.c
72
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user