Make the CoglContext structure a bit more maintainable

This moves most of cogl-context.{c.h} to cogl/common with some driver
specific members now living in a CoglContextDriver struct.  Driver specific
context initialization and typedefs now live in
cogl/{gl,gles}/cogl-context-driver.{c,h}

Driver specific members can be found under ctx->drv.stuff
This commit is contained in:
Robert Bragg 2009-07-28 01:34:33 +01:00
parent 739b460c7a
commit b85af722f4
25 changed files with 417 additions and 601 deletions

View File

@ -58,6 +58,8 @@ libclutter_cogl_common_la_SOURCES = \
$(top_builddir)/clutter/cogl/common/cogl-enum-types.h \
$(top_builddir)/clutter/cogl/common/cogl-enum-types.c \
cogl-handle.h \
cogl-context.h \
cogl-context.c \
cogl-internal.h \
cogl.c \
cogl-util.h \

View File

@ -243,7 +243,7 @@ validate_blend_statements (CoglBlendStringStatement *statements,
if (n_statements == 2)
{
/* glBlendEquationSeperate is GL 2.0 only */
if (!ctx->pf_glBlendEquationSeparate &&
if (!ctx->drv.pf_glBlendEquationSeparate &&
statements[0].function->type != statements[1].function->type)
{
error_string = "Separate blend functions for the RGB an A "

View File

@ -32,15 +32,16 @@
#include "cogl-texture-private.h"
#include "cogl-material-private.h"
#include "cogl-gles2-wrapper.h"
#include <string.h>
extern void
_cogl_create_context_driver (CoglContext *context);
static CoglContext *_context = NULL;
static gboolean gl_is_indirect = FALSE;
static gboolean
cogl_create_context ()
cogl_create_context (void)
{
GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 };
gulong enable_flags = 0;
@ -68,15 +69,14 @@ cogl_create_context ()
_context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
_context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
_context->texture_download_material = COGL_INVALID_HANDLE;
_context->journal = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry));
_context->logged_vertices = g_array_new (FALSE, FALSE, sizeof (GLfloat));
_context->polygon_vertices = g_array_new (FALSE, FALSE,
sizeof (CoglTextureGLVertex));
_context->current_material = NULL;
_context->current_material_flags = 0;
memset (&_context->current_material_flush_options,
0, sizeof (CoglMaterialFlushOptions));
_context->current_layers = g_array_new (FALSE, FALSE,
sizeof (CoglLayerInfo));
_context->n_texcoord_arrays_enabled = 0;
@ -91,10 +91,14 @@ cogl_create_context ()
_context->last_path = 0;
_context->stencil_material = cogl_material_new ();
/* Init the GLES2 wrapper */
#ifdef HAVE_COGL_GLES2
cogl_gles2_wrapper_init (&_context->gles2);
#endif
_context->in_begin_gl_block = FALSE;
_context->viewport_width = 0;
_context->viewport_height = 0;
_context->quad_indices_byte = COGL_INVALID_HANDLE;
_context->quad_indices_short = COGL_INVALID_HANDLE;
_context->quad_indices_short_len = 0;
/* Initialise the clip stack */
_cogl_clip_stack_state_init ();
@ -102,23 +106,26 @@ cogl_create_context ()
/* Initialise matrix stack */
_cogl_current_matrix_state_init ();
/* Initialise the driver specific state */
_cogl_create_context_driver (_context);
/* Create default textures used for fall backs */
_context->default_gl_texture_2d_tex =
cogl_texture_new_from_data (1, /* width */
1, /* height */
COGL_TEXTURE_NO_SLICING, /* flags */
COGL_PIXEL_FORMAT_RGBA_8888, /* data format */
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
/* internal format */
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* auto calc row stride */
default_texture_data);
_context->default_gl_texture_rect_tex =
cogl_texture_new_from_data (1, /* width */
1, /* height */
COGL_TEXTURE_NO_SLICING, /* flags */
COGL_PIXEL_FORMAT_RGBA_8888, /* data format */
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
/* internal format */
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* auto calc row stride */
default_texture_data);
@ -128,10 +135,6 @@ cogl_create_context ()
_cogl_material_get_cogl_enable_flags (_context->source_material);
cogl_enable (enable_flags);
_context->quad_indices_byte = COGL_INVALID_HANDLE;
_context->quad_indices_short = COGL_INVALID_HANDLE;
_context->quad_indices_short_len = 0;
return TRUE;
}
@ -161,8 +164,6 @@ _cogl_destroy_context ()
if (_context->logged_vertices)
g_array_free (_context->logged_vertices, TRUE);
if (_context->polygon_vertices)
g_array_free (_context->polygon_vertices, TRUE);
if (_context->current_layers)
g_array_free (_context->current_layers, TRUE);

View File

@ -24,12 +24,12 @@
#ifndef __COGL_CONTEXT_H
#define __COGL_CONTEXT_H
#include "cogl-context-driver.h"
#include "cogl-primitives.h"
#include "cogl-clip-stack.h"
#include "cogl-matrix-stack.h"
#include "cogl-current-matrix.h"
#include "cogl-material-private.h"
#include "cogl-gles2-wrapper.h"
typedef struct
{
@ -48,15 +48,15 @@ typedef struct
{
/* Features cache */
CoglFeatureFlags feature_flags;
gboolean features_cached;
/* Enable cache */
gulong enable_flags;
guint8 color_alpha;
guint features_cached : 1;
guint enable_backface_culling : 1;
guint indirect : 1;
guint in_begin_gl_block : 1;
gboolean enable_backface_culling;
gboolean indirect;
/* Client-side matrix stack or NULL if none */
CoglMatrixMode matrix_mode;
@ -73,7 +73,6 @@ typedef struct
/* Textures */
CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex;
CoglHandle texture_download_material;
/* Batching geometry... */
/* We journal the texture rectangles we want to submit to OpenGL so
@ -111,16 +110,12 @@ typedef struct
guint quad_indices_short_len;
CoglHandle quad_indices_short;
gfloat viewport_width;
gfloat viewport_height;
gboolean in_begin_gl_block;
#ifdef HAVE_COGL_GLES2
CoglGles2Wrapper gles2;
guint viewport_width;
guint viewport_height;
/* Viewport store for FBOs. Needed because glPushAttrib() isn't
supported */
GLint viewport_store[4];
#endif
CoglContextDriver drv;
} CoglContext;
CoglContext *

View File

@ -49,12 +49,12 @@
#endif
#ifdef HAVE_COGL_GL
#define glActiveTexture ctx->pf_glActiveTexture
#define glClientActiveTexture ctx->pf_glClientActiveTexture
#define glBlendFuncSeparate ctx->pf_glBlendFuncSeparate
#define glBlendEquation ctx->pf_glBlendEquation
#define glBlendColor ctx->pf_glBlendColor
#define glBlendEquationSeparate ctx->pf_glBlendEquationSeparate
#define glActiveTexture ctx->drv.pf_glActiveTexture
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#define glBlendFuncSeparate ctx->drv.pf_glBlendFuncSeparate
#define glBlendEquation ctx->drv.pf_glBlendEquation
#define glBlendColor ctx->drv.pf_glBlendColor
#define glBlendEquationSeparate ctx->drv.pf_glBlendEquationSeparate
#endif
static void _cogl_material_free (CoglMaterial *tex);
@ -1547,7 +1547,7 @@ _cogl_material_flush_base_gl_state (CoglMaterial *material,
gboolean have_blend_equation_seperate = TRUE;
#elif defined (HAVE_COGL_GL)
gboolean have_blend_equation_seperate = FALSE;
if (ctx->pf_glBlendEquationSeparate) /* Only GL 2.0 + */
if (ctx->drv.pf_glBlendEquationSeparate) /* Only GL 2.0 + */
have_blend_equation_seperate = TRUE;
#endif

View File

@ -40,12 +40,12 @@
#ifdef HAVE_COGL_GL
#define glGenBuffers ctx->pf_glGenBuffersARB
#define glBindBuffer ctx->pf_glBindBufferARB
#define glBufferData ctx->pf_glBufferDataARB
#define glBufferSubData ctx->pf_glBufferSubDataARB
#define glDeleteBuffers ctx->pf_glDeleteBuffersARB
#define glClientActiveTexture ctx->pf_glClientActiveTexture
#define glGenBuffers ctx->drv.pf_glGenBuffersARB
#define glBindBuffer ctx->drv.pf_glBindBufferARB
#define glBufferData ctx->drv.pf_glBufferDataARB
#define glBufferSubData ctx->drv.pf_glBufferSubDataARB
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffersARB
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#elif defined (HAVE_COGL_GLES2)

View File

@ -149,15 +149,15 @@
#if defined (HAVE_COGL_GL)
#define glGenBuffers ctx->pf_glGenBuffersARB
#define glBindBuffer ctx->pf_glBindBufferARB
#define glBufferData ctx->pf_glBufferDataARB
#define glBufferSubData ctx->pf_glBufferSubDataARB
#define glDeleteBuffers ctx->pf_glDeleteBuffersARB
#define glMapBuffer ctx->pf_glMapBufferARB
#define glUnmapBuffer ctx->pf_glUnmapBufferARB
#define glActiveTexture ctx->pf_glActiveTexture
#define glClientActiveTexture ctx->pf_glClientActiveTexture
#define glGenBuffers ctx->drv.pf_glGenBuffersARB
#define glBindBuffer ctx->drv.pf_glBindBufferARB
#define glBufferData ctx->drv.pf_glBufferDataARB
#define glBufferSubData ctx->drv.pf_glBufferSubDataARB
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffersARB
#define glMapBuffer ctx->drv.pf_glMapBufferARB
#define glUnmapBuffer ctx->drv.pf_glUnmapBufferARB
#define glActiveTexture ctx->drv.pf_glActiveTexture
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#ifndef GL_ARRAY_BUFFER
#define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
#endif
@ -174,9 +174,9 @@
#if defined (HAVE_COGL_GL)
#define glVertexAttribPointer ctx->pf_glVertexAttribPointerARB
#define glEnableVertexAttribArray ctx->pf_glEnableVertexAttribArrayARB
#define glDisableVertexAttribArray ctx->pf_glEnableVertexAttribArrayARB
#define glVertexAttribPointer ctx->drv.pf_glVertexAttribPointerARB
#define glEnableVertexAttribArray ctx->drv.pf_glEnableVertexAttribArrayARB
#define glDisableVertexAttribArray ctx->drv.pf_glEnableVertexAttribArrayARB
#define MAY_HAVE_PROGRAMABLE_GL
#elif defined (HAVE_COGL_GLES2)
@ -197,7 +197,7 @@
#else /* HAVE_COGL_GL */
#define glDrawRangeElements(mode, start, end, count, type, indices) \
ctx->pf_glDrawRangeElements (mode, start, end, count, type, indices)
ctx->drv.pf_glDrawRangeElements (mode, start, end, count, type, indices)
#endif /* HAVE_COGL_GL */

View File

@ -49,7 +49,7 @@ typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#endif
#ifdef HAVE_COGL_GL
#define glClientActiveTexture ctx->pf_glClientActiveTexture
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
#endif
#ifdef COGL_GL_DEBUG

View File

@ -33,7 +33,7 @@ cogl_sources = \
cogl-fbo.c \
cogl-shader.c \
cogl-program.c \
cogl-context.c \
cogl-context-driver.c \
$(NULL)
INCLUDES = \

84
gl/cogl-context-driver.c Normal file
View File

@ -0,0 +1,84 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2007,2008,2009 Intel Corporation.
*
* 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-context.h"
void
_cogl_create_context_driver (CoglContext *_context)
{
_context->drv.pf_glGenRenderbuffersEXT = NULL;
_context->drv.pf_glBindRenderbufferEXT = NULL;
_context->drv.pf_glRenderbufferStorageEXT = NULL;
_context->drv.pf_glGenFramebuffersEXT = NULL;
_context->drv.pf_glBindFramebufferEXT = NULL;
_context->drv.pf_glFramebufferTexture2DEXT = NULL;
_context->drv.pf_glFramebufferRenderbufferEXT = NULL;
_context->drv.pf_glCheckFramebufferStatusEXT = NULL;
_context->drv.pf_glDeleteFramebuffersEXT = NULL;
_context->drv.pf_glBlitFramebufferEXT = NULL;
_context->drv.pf_glRenderbufferStorageMultisampleEXT = NULL;
_context->drv.pf_glCreateProgramObjectARB = NULL;
_context->drv.pf_glCreateShaderObjectARB = NULL;
_context->drv.pf_glShaderSourceARB = NULL;
_context->drv.pf_glCompileShaderARB = NULL;
_context->drv.pf_glAttachObjectARB = NULL;
_context->drv.pf_glLinkProgramARB = NULL;
_context->drv.pf_glUseProgramObjectARB = NULL;
_context->drv.pf_glGetUniformLocationARB = NULL;
_context->drv.pf_glDeleteObjectARB = NULL;
_context->drv.pf_glGetInfoLogARB = NULL;
_context->drv.pf_glGetObjectParameterivARB = NULL;
_context->drv.pf_glUniform1fARB = NULL;
_context->drv.pf_glUniform2fARB = NULL;
_context->drv.pf_glUniform3fARB = NULL;
_context->drv.pf_glUniform4fARB = NULL;
_context->drv.pf_glUniform1fvARB = NULL;
_context->drv.pf_glUniform2fvARB = NULL;
_context->drv.pf_glUniform3fvARB = NULL;
_context->drv.pf_glUniform4fvARB = NULL;
_context->drv.pf_glUniform1iARB = NULL;
_context->drv.pf_glUniform2iARB = NULL;
_context->drv.pf_glUniform3iARB = NULL;
_context->drv.pf_glUniform4iARB = NULL;
_context->drv.pf_glUniform1ivARB = NULL;
_context->drv.pf_glUniform2ivARB = NULL;
_context->drv.pf_glUniform3ivARB = NULL;
_context->drv.pf_glUniform4ivARB = NULL;
_context->drv.pf_glUniformMatrix2fvARB = NULL;
_context->drv.pf_glUniformMatrix3fvARB = NULL;
_context->drv.pf_glUniformMatrix4fvARB = NULL;
_context->drv.pf_glDrawRangeElements = NULL;
_context->drv.pf_glActiveTexture = NULL;
_context->drv.pf_glClientActiveTexture = NULL;
_context->drv.pf_glBlendFuncSeparate = NULL;
_context->drv.pf_glBlendEquationSeparate = NULL;
}

View File

@ -21,99 +21,13 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_CONTEXT_H
#define __COGL_CONTEXT_H
#ifndef __COGL_CONTEXT_DRIVER_H
#define __COGL_CONTEXT_DRIVER_H
#include "cogl-primitives.h"
#include "cogl-clip-stack.h"
#include "cogl-matrix-stack.h"
#include "cogl-current-matrix.h"
#include "cogl-material-private.h"
#include "cogl.h"
typedef struct
typedef struct _CoglContextDriver
{
GLfloat v[3];
GLfloat t[2];
GLubyte c[4];
} CoglTextureGLVertex;
typedef struct
{
CoglBufferTarget target;
CoglHandle offscreen;
} CoglDrawBufferState;
typedef struct
{
/* Features cache */
CoglFeatureFlags feature_flags;
gboolean features_cached;
/* Enable cache */
gulong enable_flags;
guint8 color_alpha;
gboolean enable_backface_culling;
gboolean indirect;
/* Client-side matrix stack or NULL if none */
CoglMatrixMode matrix_mode;
CoglMatrixStack *modelview_stack;
CoglMatrixStack *projection_stack;
/* Cache of inverse projection matrix */
float inverse_projection[16];
/* Materials */
CoglHandle default_material;
CoglHandle source_material;
/* Textures */
CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex;
/* Batching geometry... */
/* We journal the texture rectangles we want to submit to OpenGL so
* we have an oppertunity to optimise the final order so that we
* can batch things together. */
GArray *journal;
GArray *logged_vertices;
/* Some simple caching, to minimize state changes... */
CoglHandle current_material;
gulong current_material_flags;
CoglMaterialFlushOptions current_material_flush_options;
GArray *current_layers;
guint n_texcoord_arrays_enabled;
/* Framebuffer objects */
GSList *draw_buffer_stack;
/* Clip stack */
CoglClipStackState clip;
/* Primitives */
floatVec2 path_start;
floatVec2 path_pen;
GArray *path_nodes;
guint last_path;
floatVec2 path_nodes_min;
floatVec2 path_nodes_max;
CoglHandle stencil_material;
/* Pre-generated VBOs containing indices to generate GL_TRIANGLES
out of a vertex array of quads */
CoglHandle quad_indices_byte;
guint quad_indices_short_len;
CoglHandle quad_indices_short;
gboolean in_begin_gl_block;
guint viewport_width;
guint viewport_height;
/* Relying on glext.h to define these */
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
COGL_PFNGLDELETERENDERBUFFERSEXTPROC pf_glDeleteRenderbuffersEXT;
@ -182,16 +96,8 @@ typedef struct
COGL_PFNGLBLENDCOLORPROC pf_glBlendColor;
COGL_PFNGLBLENDFUNCSEPARATEPROC pf_glBlendFuncSeparate;
COGL_PFNGLBLENDEQUATIONSEPARATEPROC pf_glBlendEquationSeparate;
} CoglContext;
CoglContext *
_cogl_context_get_default ();
} CoglContextDriver;
/* Obtains the context and returns retval if NULL */
#define _COGL_GET_CONTEXT(ctxvar, retval) \
CoglContext *ctxvar = _cogl_context_get_default (); \
if (ctxvar == NULL) return retval;
#endif /* __COGL_CONTEXT_DRIVER_H */
#define NO_RETVAL
#endif /* __COGL_CONTEXT_H */

View File

@ -1,259 +0,0 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2007,2008,2009 Intel Corporation.
*
* 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-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
#include "cogl-texture-private.h"
#include "cogl-material-private.h"
#include <string.h>
static CoglContext *_context = NULL;
static gboolean gl_is_indirect = FALSE;
static gboolean
cogl_create_context ()
{
GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 };
gulong enable_flags = 0;
CoglDrawBufferState *draw_buffer;
if (_context != NULL)
return FALSE;
/* Allocate context memory */
_context = (CoglContext*) g_malloc (sizeof (CoglContext));
/* Init default values */
_context->feature_flags = 0;
_context->features_cached = FALSE;
_context->enable_flags = 0;
_context->color_alpha = 0;
_context->enable_backface_culling = FALSE;
_context->indirect = gl_is_indirect;
_context->default_material = cogl_material_new ();
_context->source_material = NULL;
_context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
_context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
_context->journal = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry));
_context->logged_vertices = g_array_new (FALSE, FALSE, sizeof (GLfloat));
_context->current_material = NULL;
_context->current_material_flags = 0;
memset (&_context->current_material_flush_options,
0, sizeof (CoglMaterialFlushOptions));
_context->current_layers = g_array_new (FALSE, FALSE,
sizeof (CoglLayerInfo));
_context->n_texcoord_arrays_enabled = 0;
draw_buffer = g_slice_new0 (CoglDrawBufferState);
draw_buffer->target = COGL_WINDOW_BUFFER;
draw_buffer->offscreen = COGL_INVALID_HANDLE;
_context->draw_buffer_stack =
g_slist_prepend (NULL, draw_buffer);
_context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
_context->last_path = 0;
_context->stencil_material = cogl_material_new ();
_context->in_begin_gl_block = FALSE;
_context->viewport_width = 0;
_context->viewport_height = 0;
_context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL;
_context->pf_glRenderbufferStorageEXT = NULL;
_context->pf_glGenFramebuffersEXT = NULL;
_context->pf_glBindFramebufferEXT = NULL;
_context->pf_glFramebufferTexture2DEXT = NULL;
_context->pf_glFramebufferRenderbufferEXT = NULL;
_context->pf_glCheckFramebufferStatusEXT = NULL;
_context->pf_glDeleteFramebuffersEXT = NULL;
_context->pf_glBlitFramebufferEXT = NULL;
_context->pf_glRenderbufferStorageMultisampleEXT = NULL;
_context->pf_glCreateProgramObjectARB = NULL;
_context->pf_glCreateShaderObjectARB = NULL;
_context->pf_glShaderSourceARB = NULL;
_context->pf_glCompileShaderARB = NULL;
_context->pf_glAttachObjectARB = NULL;
_context->pf_glLinkProgramARB = NULL;
_context->pf_glUseProgramObjectARB = NULL;
_context->pf_glGetUniformLocationARB = NULL;
_context->pf_glDeleteObjectARB = NULL;
_context->pf_glGetInfoLogARB = NULL;
_context->pf_glGetObjectParameterivARB = NULL;
_context->pf_glUniform1fARB = NULL;
_context->pf_glUniform2fARB = NULL;
_context->pf_glUniform3fARB = NULL;
_context->pf_glUniform4fARB = NULL;
_context->pf_glUniform1fvARB = NULL;
_context->pf_glUniform2fvARB = NULL;
_context->pf_glUniform3fvARB = NULL;
_context->pf_glUniform4fvARB = NULL;
_context->pf_glUniform1iARB = NULL;
_context->pf_glUniform2iARB = NULL;
_context->pf_glUniform3iARB = NULL;
_context->pf_glUniform4iARB = NULL;
_context->pf_glUniform1ivARB = NULL;
_context->pf_glUniform2ivARB = NULL;
_context->pf_glUniform3ivARB = NULL;
_context->pf_glUniform4ivARB = NULL;
_context->pf_glUniformMatrix2fvARB = NULL;
_context->pf_glUniformMatrix3fvARB = NULL;
_context->pf_glUniformMatrix4fvARB = NULL;
_context->pf_glDrawRangeElements = NULL;
_context->pf_glActiveTexture = NULL;
_context->pf_glClientActiveTexture = NULL;
_context->pf_glBlendFuncSeparate = NULL;
_context->pf_glBlendEquationSeparate = NULL;
/* Initialise the clip stack */
_cogl_clip_stack_state_init ();
/* Initialise matrix stack */
_cogl_current_matrix_state_init ();
/* Create default textures used for fall backs */
_context->default_gl_texture_2d_tex =
cogl_texture_new_from_data (1, /* width */
1, /* height */
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
/* internal format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* auto calc row stride */
default_texture_data);
_context->default_gl_texture_rect_tex =
cogl_texture_new_from_data (1, /* width */
1, /* height */
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* data format */
/* internal format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* auto calc row stride */
default_texture_data);
cogl_set_source (_context->default_material);
_cogl_material_flush_gl_state (_context->source_material, NULL);
enable_flags =
_cogl_material_get_cogl_enable_flags (_context->source_material);
cogl_enable (enable_flags);
_context->quad_indices_byte = COGL_INVALID_HANDLE;
_context->quad_indices_short = COGL_INVALID_HANDLE;
_context->quad_indices_short_len = 0;
return TRUE;
}
void
_cogl_destroy_context ()
{
if (_context == NULL)
return;
_cogl_clip_stack_state_destroy ();
_cogl_current_matrix_state_destroy ();
if (_context->path_nodes)
g_array_free (_context->path_nodes, TRUE);
if (_context->default_gl_texture_2d_tex)
cogl_handle_unref (_context->default_gl_texture_2d_tex);
if (_context->default_gl_texture_rect_tex)
cogl_handle_unref (_context->default_gl_texture_rect_tex);
if (_context->default_material)
cogl_handle_unref (_context->default_material);
if (_context->journal)
g_array_free (_context->journal, TRUE);
if (_context->logged_vertices)
g_array_free (_context->logged_vertices, TRUE);
if (_context->current_layers)
g_array_free (_context->current_layers, TRUE);
if (_context->quad_indices_byte)
cogl_handle_unref (_context->quad_indices_byte);
if (_context->quad_indices_short)
cogl_handle_unref (_context->quad_indices_short);
g_free (_context);
}
CoglContext *
_cogl_context_get_default ()
{
/* Create if doesn't exist yet */
if (_context == NULL)
cogl_create_context ();
return _context;
}
/**
* _cogl_set_indirect_context:
* @indirect: TRUE if GL context is indirect
*
* Advises COGL that the GL context is indirect (commands are sent
* over a socket). COGL uses this information to try to avoid
* round-trips in its use of GL, for example.
*
* This function cannot be called "on the fly," only before COGL
* initializes.
*/
void
_cogl_set_indirect_context (gboolean indirect)
{
/* we get called multiple times if someone creates
* more than the default stage
*/
if (_context != NULL)
{
if (indirect != _context->indirect)
g_warning ("Right now all stages will be treated as "
"either direct or indirect, ignoring attempt "
"to change to indirect=%d", indirect);
return;
}
gl_is_indirect = indirect;
}

View File

@ -34,18 +34,18 @@
#include "cogl-handle.h"
/* Expecting EXT functions not to be defined - redirect to pointers in context */
#define glGenRenderbuffersEXT ctx->pf_glGenRenderbuffersEXT
#define glDeleteRenderbuffersEXT ctx->pf_glDeleteRenderbuffersEXT
#define glBindRenderbufferEXT ctx->pf_glBindRenderbufferEXT
#define glRenderbufferStorageEXT ctx->pf_glRenderbufferStorageEXT
#define glGenFramebuffersEXT ctx->pf_glGenFramebuffersEXT
#define glBindFramebufferEXT ctx->pf_glBindFramebufferEXT
#define glFramebufferTexture2DEXT ctx->pf_glFramebufferTexture2DEXT
#define glFramebufferRenderbufferEXT ctx->pf_glFramebufferRenderbufferEXT
#define glCheckFramebufferStatusEXT ctx->pf_glCheckFramebufferStatusEXT
#define glDeleteFramebuffersEXT ctx->pf_glDeleteFramebuffersEXT
#define glBlitFramebufferEXT ctx->pf_glBlitFramebufferEXT
#define glRenderbufferStorageMultisampleEXT ctx->pf_glRenderbufferStorageMultisampleEXT
#define glGenRenderbuffersEXT ctx->drv.pf_glGenRenderbuffersEXT
#define glDeleteRenderbuffersEXT ctx->drv.pf_glDeleteRenderbuffersEXT
#define glBindRenderbufferEXT ctx->drv.pf_glBindRenderbufferEXT
#define glRenderbufferStorageEXT ctx->drv.pf_glRenderbufferStorageEXT
#define glGenFramebuffersEXT ctx->drv.pf_glGenFramebuffersEXT
#define glBindFramebufferEXT ctx->drv.pf_glBindFramebufferEXT
#define glFramebufferTexture2DEXT ctx->drv.pf_glFramebufferTexture2DEXT
#define glFramebufferRenderbufferEXT ctx->drv.pf_glFramebufferRenderbufferEXT
#define glCheckFramebufferStatusEXT ctx->drv.pf_glCheckFramebufferStatusEXT
#define glDeleteFramebuffersEXT ctx->drv.pf_glDeleteFramebuffersEXT
#define glBlitFramebufferEXT ctx->drv.pf_glBlitFramebufferEXT
#define glRenderbufferStorageMultisampleEXT ctx->drv.pf_glRenderbufferStorageMultisampleEXT
#ifndef GL_READ_FRAMEBUFFER_EXT
#define GL_READ_FRAMEBUFFER_EXT 0x8CA8

View File

@ -37,7 +37,7 @@
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16
#define glClientActiveTexture ctx->pf_glClientActiveTexture
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
void
_cogl_path_add_node (gboolean new_sub_path,

View File

@ -35,31 +35,31 @@
#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 glUniform2fARB ctx->pf_glUniform2fARB
#define glUniform3fARB ctx->pf_glUniform3fARB
#define glUniform4fARB ctx->pf_glUniform4fARB
#define glUniform1fvARB ctx->pf_glUniform1fvARB
#define glUniform2fvARB ctx->pf_glUniform2fvARB
#define glUniform3fvARB ctx->pf_glUniform3fvARB
#define glUniform4fvARB ctx->pf_glUniform4fvARB
#define glUniform1iARB ctx->pf_glUniform1iARB
#define glUniform2iARB ctx->pf_glUniform2iARB
#define glUniform3iARB ctx->pf_glUniform3iARB
#define glUniform4iARB ctx->pf_glUniform4iARB
#define glUniform1ivARB ctx->pf_glUniform1ivARB
#define glUniform2ivARB ctx->pf_glUniform2ivARB
#define glUniform3ivARB ctx->pf_glUniform3ivARB
#define glUniform4ivARB ctx->pf_glUniform4ivARB
#define glUniformMatrix2fvARB ctx->pf_glUniformMatrix2fvARB
#define glUniformMatrix3fvARB ctx->pf_glUniformMatrix3fvARB
#define glUniformMatrix4fvARB ctx->pf_glUniformMatrix4fvARB
#define glDeleteObjectARB ctx->pf_glDeleteObjectARB
#define glCreateProgramObjectARB ctx->drv.pf_glCreateProgramObjectARB
#define glAttachObjectARB ctx->drv.pf_glAttachObjectARB
#define glUseProgramObjectARB ctx->drv.pf_glUseProgramObjectARB
#define glLinkProgramARB ctx->drv.pf_glLinkProgramARB
#define glGetUniformLocationARB ctx->drv.pf_glGetUniformLocationARB
#define glUniform1fARB ctx->drv.pf_glUniform1fARB
#define glUniform2fARB ctx->drv.pf_glUniform2fARB
#define glUniform3fARB ctx->drv.pf_glUniform3fARB
#define glUniform4fARB ctx->drv.pf_glUniform4fARB
#define glUniform1fvARB ctx->drv.pf_glUniform1fvARB
#define glUniform2fvARB ctx->drv.pf_glUniform2fvARB
#define glUniform3fvARB ctx->drv.pf_glUniform3fvARB
#define glUniform4fvARB ctx->drv.pf_glUniform4fvARB
#define glUniform1iARB ctx->drv.pf_glUniform1iARB
#define glUniform2iARB ctx->drv.pf_glUniform2iARB
#define glUniform3iARB ctx->drv.pf_glUniform3iARB
#define glUniform4iARB ctx->drv.pf_glUniform4iARB
#define glUniform1ivARB ctx->drv.pf_glUniform1ivARB
#define glUniform2ivARB ctx->drv.pf_glUniform2ivARB
#define glUniform3ivARB ctx->drv.pf_glUniform3ivARB
#define glUniform4ivARB ctx->drv.pf_glUniform4ivARB
#define glUniformMatrix2fvARB ctx->drv.pf_glUniformMatrix2fvARB
#define glUniformMatrix3fvARB ctx->drv.pf_glUniformMatrix3fvARB
#define glUniformMatrix4fvARB ctx->drv.pf_glUniformMatrix4fvARB
#define glDeleteObjectARB ctx->drv.pf_glDeleteObjectARB
static void _cogl_program_free (CoglProgram *program);

View File

@ -34,12 +34,12 @@
#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
#define glCreateShaderObjectARB ctx->drv.pf_glCreateShaderObjectARB
#define glGetObjectParameterivARB ctx->drv.pf_glGetObjectParameterivARB
#define glGetInfoLogARB ctx->drv.pf_glGetInfoLogARB
#define glCompileShaderARB ctx->drv.pf_glCompileShaderARB
#define glShaderSourceARB ctx->drv.pf_glShaderSourceARB
#define glDeleteObjectARB ctx->drv.pf_glDeleteObjectARB
static void _cogl_shader_free (CoglShader *shader);

View File

@ -45,7 +45,7 @@
#include <stdlib.h>
#include <math.h>
#define glGenerateMipmap ctx->pf_glGenerateMipmapEXT
#define glGenerateMipmap ctx->drv.pf_glGenerateMipmapEXT
void
_cogl_texture_driver_bind (GLenum gl_target,

224
gl/cogl.c
View File

@ -188,251 +188,251 @@ _cogl_features_init (void)
cogl_check_extension ("GL_ARB_vertex_shader", gl_extensions) &&
cogl_check_extension ("GL_ARB_fragment_shader", gl_extensions))
{
ctx->pf_glCreateProgramObjectARB =
ctx->drv.pf_glCreateProgramObjectARB =
(COGL_PFNGLCREATEPROGRAMOBJECTARBPROC)
cogl_get_proc_address ("glCreateProgramObjectARB");
ctx->pf_glCreateShaderObjectARB =
ctx->drv.pf_glCreateShaderObjectARB =
(COGL_PFNGLCREATESHADEROBJECTARBPROC)
cogl_get_proc_address ("glCreateShaderObjectARB");
ctx->pf_glShaderSourceARB =
ctx->drv.pf_glShaderSourceARB =
(COGL_PFNGLSHADERSOURCEARBPROC)
cogl_get_proc_address ("glShaderSourceARB");
ctx->pf_glCompileShaderARB =
ctx->drv.pf_glCompileShaderARB =
(COGL_PFNGLCOMPILESHADERARBPROC)
cogl_get_proc_address ("glCompileShaderARB");
ctx->pf_glAttachObjectARB =
ctx->drv.pf_glAttachObjectARB =
(COGL_PFNGLATTACHOBJECTARBPROC)
cogl_get_proc_address ("glAttachObjectARB");
ctx->pf_glLinkProgramARB =
ctx->drv.pf_glLinkProgramARB =
(COGL_PFNGLLINKPROGRAMARBPROC)
cogl_get_proc_address ("glLinkProgramARB");
ctx->pf_glUseProgramObjectARB =
ctx->drv.pf_glUseProgramObjectARB =
(COGL_PFNGLUSEPROGRAMOBJECTARBPROC)
cogl_get_proc_address ("glUseProgramObjectARB");
ctx->pf_glGetUniformLocationARB =
ctx->drv.pf_glGetUniformLocationARB =
(COGL_PFNGLGETUNIFORMLOCATIONARBPROC)
cogl_get_proc_address ("glGetUniformLocationARB");
ctx->pf_glDeleteObjectARB =
ctx->drv.pf_glDeleteObjectARB =
(COGL_PFNGLDELETEOBJECTARBPROC)
cogl_get_proc_address ("glDeleteObjectARB");
ctx->pf_glGetInfoLogARB =
ctx->drv.pf_glGetInfoLogARB =
(COGL_PFNGLGETINFOLOGARBPROC)
cogl_get_proc_address ("glGetInfoLogARB");
ctx->pf_glGetObjectParameterivARB =
ctx->drv.pf_glGetObjectParameterivARB =
(COGL_PFNGLGETOBJECTPARAMETERIVARBPROC)
cogl_get_proc_address ("glGetObjectParameterivARB");
ctx->pf_glUniform1fARB =
ctx->drv.pf_glUniform1fARB =
(COGL_PFNGLUNIFORM1FARBPROC)
cogl_get_proc_address ("glUniform1fARB");
ctx->pf_glVertexAttribPointerARB =
ctx->drv.pf_glVertexAttribPointerARB =
(COGL_PFNGLVERTEXATTRIBPOINTERARBPROC)
cogl_get_proc_address ("glVertexAttribPointerARB");
ctx->pf_glEnableVertexAttribArrayARB =
ctx->drv.pf_glEnableVertexAttribArrayARB =
(COGL_PFNGLENABLEVERTEXATTRIBARRAYARBPROC)
cogl_get_proc_address ("glEnableVertexAttribArrayARB");
ctx->pf_glDisableVertexAttribArrayARB =
ctx->drv.pf_glDisableVertexAttribArrayARB =
(COGL_PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)
cogl_get_proc_address ("glDisableVertexAttribArrayARB");
ctx->pf_glUniform2fARB =
ctx->drv.pf_glUniform2fARB =
(COGL_PFNGLUNIFORM2FARBPROC)
cogl_get_proc_address ("glUniform2fARB");
ctx->pf_glUniform3fARB =
ctx->drv.pf_glUniform3fARB =
(COGL_PFNGLUNIFORM3FARBPROC)
cogl_get_proc_address ("glUniform3fARB");
ctx->pf_glUniform4fARB =
ctx->drv.pf_glUniform4fARB =
(COGL_PFNGLUNIFORM4FARBPROC)
cogl_get_proc_address ("glUniform4fARB");
ctx->pf_glUniform1fvARB =
ctx->drv.pf_glUniform1fvARB =
(COGL_PFNGLUNIFORM1FVARBPROC)
cogl_get_proc_address ("glUniform1fvARB");
ctx->pf_glUniform2fvARB =
ctx->drv.pf_glUniform2fvARB =
(COGL_PFNGLUNIFORM2FVARBPROC)
cogl_get_proc_address ("glUniform2fvARB");
ctx->pf_glUniform3fvARB =
ctx->drv.pf_glUniform3fvARB =
(COGL_PFNGLUNIFORM3FVARBPROC)
cogl_get_proc_address ("glUniform3fvARB");
ctx->pf_glUniform4fvARB =
ctx->drv.pf_glUniform4fvARB =
(COGL_PFNGLUNIFORM4FVARBPROC)
cogl_get_proc_address ("glUniform4fvARB");
ctx->pf_glUniform1iARB =
ctx->drv.pf_glUniform1iARB =
(COGL_PFNGLUNIFORM1IARBPROC)
cogl_get_proc_address ("glUniform1iARB");
ctx->pf_glUniform2iARB =
ctx->drv.pf_glUniform2iARB =
(COGL_PFNGLUNIFORM2IARBPROC)
cogl_get_proc_address ("glUniform2iARB");
ctx->pf_glUniform3iARB =
ctx->drv.pf_glUniform3iARB =
(COGL_PFNGLUNIFORM3IARBPROC)
cogl_get_proc_address ("glUniform3iARB");
ctx->pf_glUniform4iARB =
ctx->drv.pf_glUniform4iARB =
(COGL_PFNGLUNIFORM4IARBPROC)
cogl_get_proc_address ("glUniform4iARB");
ctx->pf_glUniform1ivARB =
ctx->drv.pf_glUniform1ivARB =
(COGL_PFNGLUNIFORM1IVARBPROC)
cogl_get_proc_address ("glUniform1ivARB");
ctx->pf_glUniform2ivARB =
ctx->drv.pf_glUniform2ivARB =
(COGL_PFNGLUNIFORM2IVARBPROC)
cogl_get_proc_address ("glUniform2ivARB");
ctx->pf_glUniform3ivARB =
ctx->drv.pf_glUniform3ivARB =
(COGL_PFNGLUNIFORM3IVARBPROC)
cogl_get_proc_address ("glUniform3ivARB");
ctx->pf_glUniform4ivARB =
ctx->drv.pf_glUniform4ivARB =
(COGL_PFNGLUNIFORM4IVARBPROC)
cogl_get_proc_address ("glUniform4ivARB");
ctx->pf_glUniformMatrix2fvARB =
ctx->drv.pf_glUniformMatrix2fvARB =
(COGL_PFNGLUNIFORMMATRIX2FVARBPROC)
cogl_get_proc_address ("glUniformMatrix2fvARB");
ctx->pf_glUniformMatrix3fvARB =
ctx->drv.pf_glUniformMatrix3fvARB =
(COGL_PFNGLUNIFORMMATRIX3FVARBPROC)
cogl_get_proc_address ("glUniformMatrix3fvARB");
ctx->pf_glUniformMatrix4fvARB =
ctx->drv.pf_glUniformMatrix4fvARB =
(COGL_PFNGLUNIFORMMATRIX4FVARBPROC)
cogl_get_proc_address ("glUniformMatrix4fvARB");
if (ctx->pf_glCreateProgramObjectARB &&
ctx->pf_glCreateShaderObjectARB &&
ctx->pf_glShaderSourceARB &&
ctx->pf_glCompileShaderARB &&
ctx->pf_glAttachObjectARB &&
ctx->pf_glLinkProgramARB &&
ctx->pf_glUseProgramObjectARB &&
ctx->pf_glGetUniformLocationARB &&
ctx->pf_glDeleteObjectARB &&
ctx->pf_glGetInfoLogARB &&
ctx->pf_glGetObjectParameterivARB &&
ctx->pf_glUniform1fARB &&
ctx->pf_glUniform2fARB &&
ctx->pf_glUniform3fARB &&
ctx->pf_glUniform4fARB &&
ctx->pf_glUniform1fvARB &&
ctx->pf_glUniform2fvARB &&
ctx->pf_glUniform3fvARB &&
ctx->pf_glUniform4fvARB &&
ctx->pf_glUniform1iARB &&
ctx->pf_glUniform2iARB &&
ctx->pf_glUniform3iARB &&
ctx->pf_glUniform4iARB &&
ctx->pf_glUniform1ivARB &&
ctx->pf_glUniform2ivARB &&
ctx->pf_glUniform3ivARB &&
ctx->pf_glUniform4ivARB &&
ctx->pf_glUniformMatrix2fvARB &&
ctx->pf_glUniformMatrix3fvARB &&
ctx->pf_glUniformMatrix4fvARB &&
ctx->pf_glVertexAttribPointerARB &&
ctx->pf_glEnableVertexAttribArrayARB &&
ctx->pf_glDisableVertexAttribArrayARB)
if (ctx->drv.pf_glCreateProgramObjectARB &&
ctx->drv.pf_glCreateShaderObjectARB &&
ctx->drv.pf_glShaderSourceARB &&
ctx->drv.pf_glCompileShaderARB &&
ctx->drv.pf_glAttachObjectARB &&
ctx->drv.pf_glLinkProgramARB &&
ctx->drv.pf_glUseProgramObjectARB &&
ctx->drv.pf_glGetUniformLocationARB &&
ctx->drv.pf_glDeleteObjectARB &&
ctx->drv.pf_glGetInfoLogARB &&
ctx->drv.pf_glGetObjectParameterivARB &&
ctx->drv.pf_glUniform1fARB &&
ctx->drv.pf_glUniform2fARB &&
ctx->drv.pf_glUniform3fARB &&
ctx->drv.pf_glUniform4fARB &&
ctx->drv.pf_glUniform1fvARB &&
ctx->drv.pf_glUniform2fvARB &&
ctx->drv.pf_glUniform3fvARB &&
ctx->drv.pf_glUniform4fvARB &&
ctx->drv.pf_glUniform1iARB &&
ctx->drv.pf_glUniform2iARB &&
ctx->drv.pf_glUniform3iARB &&
ctx->drv.pf_glUniform4iARB &&
ctx->drv.pf_glUniform1ivARB &&
ctx->drv.pf_glUniform2ivARB &&
ctx->drv.pf_glUniform3ivARB &&
ctx->drv.pf_glUniform4ivARB &&
ctx->drv.pf_glUniformMatrix2fvARB &&
ctx->drv.pf_glUniformMatrix3fvARB &&
ctx->drv.pf_glUniformMatrix4fvARB &&
ctx->drv.pf_glVertexAttribPointerARB &&
ctx->drv.pf_glEnableVertexAttribArrayARB &&
ctx->drv.pf_glDisableVertexAttribArrayARB)
flags |= COGL_FEATURE_SHADERS_GLSL;
}
if (cogl_check_extension ("GL_EXT_framebuffer_object", gl_extensions) ||
cogl_check_extension ("GL_ARB_framebuffer_object", gl_extensions))
{
ctx->pf_glGenRenderbuffersEXT =
ctx->drv.pf_glGenRenderbuffersEXT =
(COGL_PFNGLGENRENDERBUFFERSEXTPROC)
cogl_get_proc_address ("glGenRenderbuffersEXT");
ctx->pf_glDeleteRenderbuffersEXT =
ctx->drv.pf_glDeleteRenderbuffersEXT =
(COGL_PFNGLDELETERENDERBUFFERSEXTPROC)
cogl_get_proc_address ("glDeleteRenderbuffersEXT");
ctx->pf_glBindRenderbufferEXT =
ctx->drv.pf_glBindRenderbufferEXT =
(COGL_PFNGLBINDRENDERBUFFEREXTPROC)
cogl_get_proc_address ("glBindRenderbufferEXT");
ctx->pf_glRenderbufferStorageEXT =
ctx->drv.pf_glRenderbufferStorageEXT =
(COGL_PFNGLRENDERBUFFERSTORAGEEXTPROC)
cogl_get_proc_address ("glRenderbufferStorageEXT");
ctx->pf_glGenFramebuffersEXT =
ctx->drv.pf_glGenFramebuffersEXT =
(COGL_PFNGLGENFRAMEBUFFERSEXTPROC)
cogl_get_proc_address ("glGenFramebuffersEXT");
ctx->pf_glBindFramebufferEXT =
ctx->drv.pf_glBindFramebufferEXT =
(COGL_PFNGLBINDFRAMEBUFFEREXTPROC)
cogl_get_proc_address ("glBindFramebufferEXT");
ctx->pf_glFramebufferTexture2DEXT =
ctx->drv.pf_glFramebufferTexture2DEXT =
(COGL_PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)
cogl_get_proc_address ("glFramebufferTexture2DEXT");
ctx->pf_glFramebufferRenderbufferEXT =
ctx->drv.pf_glFramebufferRenderbufferEXT =
(COGL_PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)
cogl_get_proc_address ("glFramebufferRenderbufferEXT");
ctx->pf_glCheckFramebufferStatusEXT =
ctx->drv.pf_glCheckFramebufferStatusEXT =
(COGL_PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)
cogl_get_proc_address ("glCheckFramebufferStatusEXT");
ctx->pf_glDeleteFramebuffersEXT =
ctx->drv.pf_glDeleteFramebuffersEXT =
(COGL_PFNGLDELETEFRAMEBUFFERSEXTPROC)
cogl_get_proc_address ("glDeleteFramebuffersEXT");
ctx->pf_glGenerateMipmapEXT =
ctx->drv.pf_glGenerateMipmapEXT =
(COGL_PFNGLGENERATEMIPMAPEXTPROC)
cogl_get_proc_address ("glGenerateMipmapEXT");
if (ctx->pf_glGenRenderbuffersEXT &&
ctx->pf_glBindRenderbufferEXT &&
ctx->pf_glRenderbufferStorageEXT &&
ctx->pf_glGenFramebuffersEXT &&
ctx->pf_glBindFramebufferEXT &&
ctx->pf_glFramebufferTexture2DEXT &&
ctx->pf_glFramebufferRenderbufferEXT &&
ctx->pf_glCheckFramebufferStatusEXT &&
ctx->pf_glDeleteFramebuffersEXT &&
ctx->pf_glGenerateMipmapEXT)
if (ctx->drv.pf_glGenRenderbuffersEXT &&
ctx->drv.pf_glBindRenderbufferEXT &&
ctx->drv.pf_glRenderbufferStorageEXT &&
ctx->drv.pf_glGenFramebuffersEXT &&
ctx->drv.pf_glBindFramebufferEXT &&
ctx->drv.pf_glFramebufferTexture2DEXT &&
ctx->drv.pf_glFramebufferRenderbufferEXT &&
ctx->drv.pf_glCheckFramebufferStatusEXT &&
ctx->drv.pf_glDeleteFramebuffersEXT &&
ctx->drv.pf_glGenerateMipmapEXT)
flags |= COGL_FEATURE_OFFSCREEN;
}
if (cogl_check_extension ("GL_EXT_framebuffer_blit", gl_extensions))
{
ctx->pf_glBlitFramebufferEXT =
ctx->drv.pf_glBlitFramebufferEXT =
(COGL_PFNGLBLITFRAMEBUFFEREXTPROC)
cogl_get_proc_address ("glBlitFramebufferEXT");
if (ctx->pf_glBlitFramebufferEXT)
if (ctx->drv.pf_glBlitFramebufferEXT)
flags |= COGL_FEATURE_OFFSCREEN_BLIT;
}
if (cogl_check_extension ("GL_EXT_framebuffer_multisample", gl_extensions))
{
ctx->pf_glRenderbufferStorageMultisampleEXT =
ctx->drv.pf_glRenderbufferStorageMultisampleEXT =
(COGL_PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)
cogl_get_proc_address ("glRenderbufferStorageMultisampleEXT");
if (ctx->pf_glRenderbufferStorageMultisampleEXT)
if (ctx->drv.pf_glRenderbufferStorageMultisampleEXT)
flags |= COGL_FEATURE_OFFSCREEN_MULTISAMPLE;
}
@ -447,64 +447,64 @@ _cogl_features_init (void)
if (cogl_check_extension ("GL_ARB_vertex_buffer_object", gl_extensions))
{
ctx->pf_glGenBuffersARB =
ctx->drv.pf_glGenBuffersARB =
(COGL_PFNGLGENBUFFERSARBPROC)
cogl_get_proc_address ("glGenBuffersARB");
ctx->pf_glBindBufferARB =
ctx->drv.pf_glBindBufferARB =
(COGL_PFNGLBINDBUFFERARBPROC)
cogl_get_proc_address ("glBindBufferARB");
ctx->pf_glBufferDataARB =
ctx->drv.pf_glBufferDataARB =
(COGL_PFNGLBUFFERDATAARBPROC)
cogl_get_proc_address ("glBufferDataARB");
ctx->pf_glBufferSubDataARB =
ctx->drv.pf_glBufferSubDataARB =
(COGL_PFNGLBUFFERSUBDATAARBPROC)
cogl_get_proc_address ("glBufferSubDataARB");
ctx->pf_glDeleteBuffersARB =
ctx->drv.pf_glDeleteBuffersARB =
(COGL_PFNGLDELETEBUFFERSARBPROC)
cogl_get_proc_address ("glDeleteBuffersARB");
ctx->pf_glMapBufferARB =
ctx->drv.pf_glMapBufferARB =
(COGL_PFNGLMAPBUFFERARBPROC)
cogl_get_proc_address ("glMapBufferARB");
ctx->pf_glUnmapBufferARB =
ctx->drv.pf_glUnmapBufferARB =
(COGL_PFNGLUNMAPBUFFERARBPROC)
cogl_get_proc_address ("glUnmapBufferARB");
if (ctx->pf_glGenBuffersARB
&& ctx->pf_glBindBufferARB
&& ctx->pf_glBufferDataARB
&& ctx->pf_glBufferSubDataARB
&& ctx->pf_glDeleteBuffersARB
&& ctx->pf_glMapBufferARB
&& ctx->pf_glUnmapBufferARB)
if (ctx->drv.pf_glGenBuffersARB
&& ctx->drv.pf_glBindBufferARB
&& ctx->drv.pf_glBufferDataARB
&& ctx->drv.pf_glBufferSubDataARB
&& ctx->drv.pf_glDeleteBuffersARB
&& ctx->drv.pf_glMapBufferARB
&& ctx->drv.pf_glUnmapBufferARB)
flags |= COGL_FEATURE_VBOS;
}
/* These should always be available because they are defined in GL
1.2, but we can't call it directly because under Windows
functions > 1.1 aren't exported */
ctx->pf_glDrawRangeElements =
ctx->drv.pf_glDrawRangeElements =
(COGL_PFNGLDRAWRANGEELEMENTSPROC)
cogl_get_proc_address ("glDrawRangeElements");
ctx->pf_glActiveTexture =
ctx->drv.pf_glActiveTexture =
(COGL_PFNGLACTIVETEXTUREPROC)
cogl_get_proc_address ("glActiveTexture");
ctx->pf_glClientActiveTexture =
ctx->drv.pf_glClientActiveTexture =
(COGL_PFNGLCLIENTACTIVETEXTUREPROC)
cogl_get_proc_address ("glClientActiveTexture");
ctx->pf_glBlendEquation =
ctx->drv.pf_glBlendEquation =
(COGL_PFNGLBLENDEQUATIONPROC)
cogl_get_proc_address ("glBlendEquation");
ctx->pf_glBlendColor =
ctx->drv.pf_glBlendColor =
(COGL_PFNGLBLENDCOLORPROC)
cogl_get_proc_address ("glBlendColor");
/* Available in 1.4 */
ctx->pf_glBlendFuncSeparate =
ctx->drv.pf_glBlendFuncSeparate =
(COGL_PFNGLBLENDFUNCSEPARATEPROC)
cogl_get_proc_address ("glBlendFuncSeparate");
/* Available in 2.0 */
ctx->pf_glBlendEquationSeparate =
ctx->drv.pf_glBlendEquationSeparate =
(COGL_PFNGLBLENDEQUATIONSEPARATEPROC)
cogl_get_proc_address ("glBlendEquationSeparate");

View File

@ -54,7 +54,7 @@ libclutter_cogl_gles_la_SOURCES = \
cogl-primitives.c \
cogl-texture-driver.c \
cogl-fbo.c \
cogl-context.c \
cogl-context-driver.c \
cogl-gles2-wrapper.h \
cogl-program.h \
cogl-program.c \

View File

@ -0,0 +1,41 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2007,2008,2009 Intel Corporation.
*
* 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-context.h"
#include "cogl-gles2-wrapper.h"
void
_cogl_create_context_driver (CoglContext *context)
{
context->drv.texture_download_material = COGL_INVALID_HANDLE;
/* Init the GLES2 wrapper */
#ifdef HAVE_COGL_GLES2
cogl_gles2_wrapper_init (&context->drv.gles2);
#endif
}

View File

@ -0,0 +1,44 @@
/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2007,2008,2009 Intel Corporation.
*
* 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_CONTEXT_DRIVER_H
#define __COGL_CONTEXT_DRIVER_H
#include "cogl-gles2-wrapper.h"
typedef struct _CoglContextDriver
{
CoglHandle texture_download_material;
#ifdef HAVE_COGL_GLES2
CoglGles2Wrapper gles2;
/* Viewport store for FBOs. Needed because glPushAttrib() isn't
supported */
GLint viewport_store[4];
#endif
} CoglContextDriver;
#endif /* __COGL_CONTEXT_DRIVER_H */

View File

@ -170,7 +170,7 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
{
/* Push the viewport and matrix setup if redirecting
from a non-screen buffer */
GE( glGetIntegerv (GL_VIEWPORT, ctx->viewport_store) );
GE( glGetIntegerv (GL_VIEWPORT, ctx->drv.viewport_store) );
_cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
_cogl_current_matrix_push ();
@ -223,8 +223,10 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
{
/* Pop viewport and matrices if redirecting back
from an offscreen buffer */
GE( glViewport (ctx->viewport_store[0], ctx->viewport_store[1],
ctx->viewport_store[2], ctx->viewport_store[3]) );
GE( glViewport (ctx->drv.viewport_store[0],
ctx->drv.viewport_store[1],
ctx->drv.viewport_store[2],
ctx->drv.viewport_store[3]) );
_cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
_cogl_current_matrix_pop ();

View File

@ -48,7 +48,7 @@
{ \
CoglContext *__ctxvar = _cogl_context_get_default (); \
if (__ctxvar == NULL) return retval; \
wvar = &__ctxvar->gles2; \
wvar = &__ctxvar->drv.gles2; \
}
#define _COGL_GLES2_CHANGE_SETTING(w, var, val) \

View File

@ -56,10 +56,10 @@ _cogl_program_free (CoglProgram *program)
_cogl_gles2_clear_cache_for_program ((CoglHandle) program);
if (ctx->gles2.settings.user_program == (CoglHandle) program)
if (ctx->drv.gles2.settings.user_program == (CoglHandle) program)
{
ctx->gles2.settings.user_program = COGL_INVALID_HANDLE;
ctx->gles2.settings_dirty = TRUE;
ctx->drv.gles2.settings.user_program = COGL_INVALID_HANDLE;
ctx->drv.gles2.settings_dirty = TRUE;
}
for (i = 0; i < COGL_GLES2_NUM_CUSTOM_UNIFORMS; i++)
@ -118,8 +118,8 @@ cogl_program_use (CoglHandle handle)
if (handle != COGL_INVALID_HANDLE && !cogl_is_program (handle))
return;
ctx->gles2.settings.user_program = handle;
ctx->gles2.settings_dirty = TRUE;
ctx->drv.gles2.settings.user_program = handle;
ctx->drv.gles2.settings_dirty = TRUE;
}
int
@ -181,7 +181,7 @@ cogl_program_uniform_x (int uniform_no,
if (uniform_no >= 0 && uniform_no < COGL_GLES2_NUM_CUSTOM_UNIFORMS
&& size >= 1 && size <= 4 && count >= 1)
{
CoglBoxedValue *bv = ctx->gles2.custom_uniforms + uniform_no;
CoglBoxedValue *bv = ctx->drv.gles2.custom_uniforms + uniform_no;
if (count == 1)
{
@ -210,7 +210,7 @@ cogl_program_uniform_x (int uniform_no,
bv->size = size;
bv->count = count;
ctx->gles2.dirty_custom_uniforms |= 1 << uniform_no;
ctx->drv.gles2.dirty_custom_uniforms |= 1 << uniform_no;
}
}
@ -245,7 +245,7 @@ cogl_program_uniform_matrix (int uniform_no,
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
bv = ctx->gles2.custom_uniforms + uniform_no;
bv = ctx->drv.gles2.custom_uniforms + uniform_no;
cogl_program_uniform_x (uniform_no, size, count, COGL_BOXED_MATRIX,
sizeof (float) * size * size, value);

View File

@ -252,20 +252,20 @@ _cogl_texture_driver_download_from_gl (CoglTexture *tex,
/* Direct copy operation */
if (ctx->texture_download_material == COGL_INVALID_HANDLE)
if (ctx->drv.texture_download_material == COGL_INVALID_HANDLE)
{
ctx->texture_download_material = cogl_material_new ();
cogl_material_set_blend (ctx->texture_download_material,
ctx->drv.texture_download_material = cogl_material_new ();
cogl_material_set_blend (ctx->drv.texture_download_material,
"RGBA = ADD (SRC_COLOR, 0)",
NULL);
}
prev_source = cogl_handle_ref (ctx->source_material);
cogl_set_source (ctx->texture_download_material);
cogl_set_source (ctx->drv.texture_download_material);
cogl_material_set_layer (ctx->texture_download_material, 0, tex);
cogl_material_set_layer (ctx->drv.texture_download_material, 0, tex);
cogl_material_set_layer_combine (ctx->texture_download_material,
cogl_material_set_layer_combine (ctx->drv.texture_download_material,
0, /* layer */
"RGBA = REPLACE (TEXTURE)",
NULL);
@ -302,7 +302,7 @@ _cogl_texture_driver_download_from_gl (CoglTexture *tex,
alpha_bmp.height);
/* Draw alpha values into RGB channels */
cogl_material_set_layer_combine (ctx->texture_download_material,
cogl_material_set_layer_combine (ctx->drv.texture_download_material,
0, /* layer */
"RGBA = REPLACE (TEXTURE[A])",
NULL);