2009-03-30 12:07:31 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2009-03-30 12:07:31 -04:00
|
|
|
*
|
2010-03-19 05:55:30 -04:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2009-03-30 12:07:31 -04:00
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-03-30 12:07:31 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
#include <gmodule.h>
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2009-05-19 09:44:29 -04:00
|
|
|
#include "cogl-debug.h"
|
2009-03-30 12:07:31 -04:00
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-context.h"
|
2009-05-23 12:42:10 -04:00
|
|
|
#include "cogl-material-private.h"
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
#include "cogl-winsys.h"
|
2009-11-26 14:06:35 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2009-10-26 07:01:33 -04:00
|
|
|
#include "cogl-matrix-private.h"
|
2010-01-22 13:14:57 -05:00
|
|
|
#include "cogl-journal-private.h"
|
2010-03-01 13:08:41 -05:00
|
|
|
#include "cogl-bitmap-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-driver.h"
|
2009-03-30 12:07:31 -04:00
|
|
|
|
|
|
|
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
|
|
|
#include "cogl-gles2-wrapper.h"
|
|
|
|
#endif
|
|
|
|
|
2009-07-01 10:27:11 -04:00
|
|
|
#ifdef HAVE_COGL_GL
|
2009-07-27 20:34:33 -04:00
|
|
|
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
2009-07-01 10:27:11 -04:00
|
|
|
#endif
|
|
|
|
|
2009-05-19 09:44:29 -04:00
|
|
|
#ifdef COGL_GL_DEBUG
|
2009-03-30 12:07:31 -04:00
|
|
|
/* GL error to string conversion */
|
2009-05-18 14:38:03 -04:00
|
|
|
static const struct {
|
|
|
|
GLuint error_code;
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
const char *error_string;
|
2009-05-18 14:38:03 -04:00
|
|
|
} gl_errors[] = {
|
|
|
|
{ GL_NO_ERROR, "No error" },
|
|
|
|
{ GL_INVALID_ENUM, "Invalid enumeration value" },
|
|
|
|
{ GL_INVALID_VALUE, "Invalid value" },
|
|
|
|
{ GL_INVALID_OPERATION, "Invalid operation" },
|
|
|
|
{ GL_STACK_OVERFLOW, "Stack overflow" },
|
|
|
|
{ GL_STACK_UNDERFLOW, "Stack underflow" },
|
|
|
|
{ GL_OUT_OF_MEMORY, "Out of memory" },
|
2009-03-30 12:07:31 -04:00
|
|
|
|
|
|
|
#ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
|
2009-05-18 14:38:03 -04:00
|
|
|
{ GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "Invalid framebuffer operation" }
|
2009-03-30 12:07:31 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
static const unsigned int n_gl_errors = G_N_ELEMENTS (gl_errors);
|
2009-05-18 14:38:03 -04:00
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
const char *
|
2009-05-18 14:38:03 -04:00
|
|
|
cogl_gl_error_to_string (GLenum error_code)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
int i;
|
2009-05-18 14:38:03 -04:00
|
|
|
|
|
|
|
for (i = 0; i < n_gl_errors; i++)
|
|
|
|
{
|
|
|
|
if (gl_errors[i].error_code == error_code)
|
|
|
|
return gl_errors[i].error_string;
|
|
|
|
}
|
|
|
|
|
2009-05-19 09:44:29 -04:00
|
|
|
return "Unknown GL error";
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
2009-05-19 09:44:29 -04:00
|
|
|
#endif /* COGL_GL_DEBUG */
|
2009-03-30 12:07:31 -04:00
|
|
|
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
CoglFuncPtr
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
cogl_get_proc_address (const char* name)
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
{
|
|
|
|
void *address;
|
|
|
|
static GModule *module = NULL;
|
|
|
|
|
|
|
|
address = _cogl_winsys_get_proc_address (name);
|
|
|
|
if (address)
|
|
|
|
return address;
|
|
|
|
|
|
|
|
/* this should find the right function if the program is linked against a
|
|
|
|
* library providing it */
|
2009-11-06 09:04:36 -05:00
|
|
|
if (G_UNLIKELY (module == NULL))
|
|
|
|
module = g_module_open (NULL, 0);
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-27 21:02:02 -04:00
|
|
|
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
gpointer symbol;
|
|
|
|
|
|
|
|
if (g_module_symbol (module, name, &symbol))
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-05 11:32:19 -05:00
|
|
|
gboolean
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
_cogl_check_extension (const char *name, const gchar *ext)
|
2010-02-05 11:32:19 -05:00
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
char *end;
|
|
|
|
int name_len, n;
|
2010-02-05 11:32:19 -05:00
|
|
|
|
|
|
|
if (name == NULL || ext == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
end = (char*)(ext + strlen(ext));
|
2010-02-05 11:32:19 -05:00
|
|
|
|
|
|
|
name_len = strlen(name);
|
|
|
|
|
|
|
|
while (ext < end)
|
|
|
|
{
|
|
|
|
n = strcspn(ext, " ");
|
|
|
|
|
|
|
|
if ((name_len == n) && (!strncmp(name, ext, n)))
|
|
|
|
return TRUE;
|
|
|
|
ext += (n + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: This has been deprecated as public API */
|
|
|
|
gboolean
|
|
|
|
cogl_check_extension (const char *name, const char *ext)
|
|
|
|
{
|
|
|
|
return _cogl_check_extension (name, ext);
|
|
|
|
}
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
void
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
cogl_clear (const CoglColor *color, unsigned long buffers)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
2009-04-24 13:09:52 -04:00
|
|
|
GLbitfield gl_buffers = 0;
|
|
|
|
|
2009-05-19 09:44:29 -04:00
|
|
|
COGL_NOTE (DRAW, "Clear begin");
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
2009-09-25 09:34:34 -04:00
|
|
|
* as the material state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. */
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);
|
2009-05-08 11:32:01 -04:00
|
|
|
|
2009-04-24 13:09:52 -04:00
|
|
|
if (buffers & COGL_BUFFER_BIT_COLOR)
|
|
|
|
{
|
|
|
|
GE( glClearColor (cogl_color_get_red_float (color),
|
|
|
|
cogl_color_get_green_float (color),
|
|
|
|
cogl_color_get_blue_float (color),
|
2009-08-11 08:49:12 -04:00
|
|
|
cogl_color_get_alpha_float (color)) );
|
2009-04-24 13:09:52 -04:00
|
|
|
gl_buffers |= GL_COLOR_BUFFER_BIT;
|
|
|
|
}
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-04-24 13:09:52 -04:00
|
|
|
if (buffers & COGL_BUFFER_BIT_DEPTH)
|
|
|
|
gl_buffers |= GL_DEPTH_BUFFER_BIT;
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-04-24 13:09:52 -04:00
|
|
|
if (buffers & COGL_BUFFER_BIT_STENCIL)
|
|
|
|
gl_buffers |= GL_STENCIL_BUFFER_BIT;
|
|
|
|
|
|
|
|
if (!gl_buffers)
|
|
|
|
{
|
|
|
|
static gboolean shown = FALSE;
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-04-24 13:09:52 -04:00
|
|
|
if (!shown)
|
2009-05-19 09:44:29 -04:00
|
|
|
{
|
|
|
|
g_warning ("You should specify at least one auxiliary buffer "
|
|
|
|
"when calling cogl_clear");
|
|
|
|
}
|
|
|
|
|
2009-04-24 13:09:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 07:10:16 -04:00
|
|
|
GE (glClear (gl_buffers));
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2010-01-22 13:14:57 -05:00
|
|
|
/* This is a debugging variable used to visually display the quad
|
|
|
|
batches from the journal. It is reset here to increase the
|
|
|
|
chances of getting the same colours for each frame during an
|
|
|
|
animation */
|
|
|
|
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_RECTANGLES))
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
|
|
|
|
ctxt->journal_rectangles_color = 1;
|
|
|
|
}
|
|
|
|
|
2009-05-19 09:44:29 -04:00
|
|
|
COGL_NOTE (DRAW, "Clear end");
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
static gboolean
|
|
|
|
toggle_flag (CoglContext *ctx,
|
|
|
|
unsigned long new_flags,
|
|
|
|
unsigned long flag,
|
|
|
|
GLenum gl_flag)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
/* Toggles and caches a single enable flag on or off
|
|
|
|
* by comparing to current state
|
|
|
|
*/
|
|
|
|
if (new_flags & flag)
|
|
|
|
{
|
|
|
|
if (!(ctx->enable_flags & flag))
|
|
|
|
{
|
|
|
|
GE( glEnable (gl_flag) );
|
|
|
|
ctx->enable_flags |= flag;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ctx->enable_flags & flag)
|
|
|
|
{
|
|
|
|
GE( glDisable (gl_flag) );
|
|
|
|
ctx->enable_flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
static gboolean
|
|
|
|
toggle_client_flag (CoglContext *ctx,
|
|
|
|
unsigned long new_flags,
|
|
|
|
unsigned long flag,
|
|
|
|
GLenum gl_flag)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
/* Toggles and caches a single client-side enable flag
|
|
|
|
* on or off by comparing to current state
|
|
|
|
*/
|
|
|
|
if (new_flags & flag)
|
|
|
|
{
|
|
|
|
if (!(ctx->enable_flags & flag))
|
|
|
|
{
|
|
|
|
GE( glEnableClientState (gl_flag) );
|
|
|
|
ctx->enable_flags |= flag;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ctx->enable_flags & flag)
|
|
|
|
{
|
|
|
|
GE( glDisableClientState (gl_flag) );
|
|
|
|
ctx->enable_flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-19 05:16:08 -04:00
|
|
|
_cogl_enable (unsigned long flags)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
/* This function essentially caches glEnable state() in the
|
|
|
|
* hope of lessening number GL traffic.
|
|
|
|
*/
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
toggle_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_BLEND,
|
|
|
|
GL_BLEND);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
toggle_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_BACKFACE_CULLING,
|
|
|
|
GL_CULL_FACE);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_VERTEX_ARRAY,
|
|
|
|
GL_VERTEX_ARRAY);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_COLOR_ARRAY,
|
|
|
|
GL_COLOR_ARRAY);
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
unsigned long
|
2010-03-19 05:16:08 -04:00
|
|
|
_cogl_get_enable (void)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return ctx->enable_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 11:55:11 -04:00
|
|
|
cogl_set_depth_test_enabled (gboolean setting)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
/* Currently the journal can't track changes to depth state... */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (setting)
|
|
|
|
{
|
|
|
|
glEnable (GL_DEPTH_TEST);
|
|
|
|
glDepthFunc (GL_LEQUAL);
|
|
|
|
}
|
|
|
|
else
|
2009-05-26 11:55:11 -04:00
|
|
|
glDisable (GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_get_depth_test_enabled (void)
|
|
|
|
{
|
|
|
|
return glIsEnabled (GL_DEPTH_TEST) == GL_TRUE ? TRUE : FALSE;
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 11:55:11 -04:00
|
|
|
cogl_set_backface_culling_enabled (gboolean setting)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-10-22 14:09:20 -04:00
|
|
|
if (ctx->enable_backface_culling == setting)
|
|
|
|
return;
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
/* Currently the journal can't track changes to backface culling state... */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
ctx->enable_backface_culling = setting;
|
|
|
|
}
|
|
|
|
|
2009-05-26 11:55:11 -04:00
|
|
|
gboolean
|
|
|
|
cogl_get_backface_culling_enabled (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
return ctx->enable_backface_culling;
|
|
|
|
}
|
|
|
|
|
2009-10-22 14:01:52 -04:00
|
|
|
void
|
|
|
|
_cogl_flush_face_winding (void)
|
|
|
|
{
|
|
|
|
CoglFrontWinding winding;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* The front face winding doesn't matter if we aren't performing any
|
|
|
|
* backface culling... */
|
|
|
|
if (!ctx->enable_backface_culling)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* NB: We use a clockwise face winding order when drawing offscreen because
|
|
|
|
* all offscreen rendering is done upside down resulting in reversed winding
|
|
|
|
* for all triangles.
|
|
|
|
*/
|
2009-11-26 14:06:35 -05:00
|
|
|
if (cogl_is_offscreen (_cogl_get_framebuffer ()))
|
2009-10-22 14:01:52 -04:00
|
|
|
winding = COGL_FRONT_WINDING_CLOCKWISE;
|
|
|
|
else
|
|
|
|
winding = COGL_FRONT_WINDING_COUNTER_CLOCKWISE;
|
|
|
|
|
|
|
|
if (winding != ctx->flushed_front_winding)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (winding == COGL_FRONT_WINDING_CLOCKWISE)
|
|
|
|
GE (glFrontFace (GL_CW));
|
|
|
|
else
|
|
|
|
GE (glFrontFace (GL_CCW));
|
|
|
|
ctx->flushed_front_winding = winding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
void
|
|
|
|
cogl_set_source_color (const CoglColor *color)
|
|
|
|
{
|
2009-05-09 14:39:01 -04:00
|
|
|
CoglColor premultiplied;
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* In case cogl_set_source_texture was previously used... */
|
2009-11-11 07:50:48 -05:00
|
|
|
cogl_material_remove_layer (ctx->simple_material, 0);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2009-05-09 14:39:01 -04:00
|
|
|
premultiplied = *color;
|
|
|
|
cogl_color_premultiply (&premultiplied);
|
2009-11-11 07:50:48 -05:00
|
|
|
cogl_material_set_color (ctx->simple_material, &premultiplied);
|
2009-05-09 14:39:01 -04:00
|
|
|
|
2009-11-11 07:50:48 -05:00
|
|
|
cogl_set_source (ctx->simple_material);
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-03 08:26:58 -05:00
|
|
|
cogl_set_viewport (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
2010-05-27 19:35:47 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2009-07-01 07:57:30 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
2009-07-01 07:57:30 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_set_viewport (framebuffer,
|
2009-09-25 09:34:34 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: This should be deprecated, and we should expose a way to also
|
|
|
|
* specify an x and y viewport offset */
|
|
|
|
void
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
cogl_viewport (unsigned int width,
|
|
|
|
unsigned int height)
|
2009-09-25 09:34:34 -04:00
|
|
|
{
|
2009-11-03 08:26:58 -05:00
|
|
|
cogl_set_viewport (0, 0, width, height);
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
_cogl_setup_viewport (unsigned int width,
|
|
|
|
unsigned int height,
|
2009-05-28 08:03:19 -04:00
|
|
|
float fovy,
|
|
|
|
float aspect,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
float z_camera;
|
|
|
|
CoglMatrix projection_matrix;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack;
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-11-03 08:26:58 -05:00
|
|
|
cogl_set_viewport (0, 0, width, height);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
|
|
|
/* For Ortho projection.
|
2009-10-13 18:09:42 -04:00
|
|
|
* _cogl_matrix_stack_ortho (projection_stack, 0, width, 0, height, -1, 1);
|
2009-03-30 12:07:31 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
cogl_perspective (fovy, aspect, z_near, z_far);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In theory, we can compute the camera distance from screen as:
|
|
|
|
*
|
|
|
|
* 0.5 * tan (FOV)
|
|
|
|
*
|
|
|
|
* However, it's better to compute the z_camera from our projection
|
|
|
|
* matrix so that we get a 1:1 mapping at the screen distance. Consider
|
|
|
|
* the upper-left corner of the screen. It has object coordinates
|
|
|
|
* (0,0,0), so by the transform below, ends up with eye coordinate
|
|
|
|
*
|
|
|
|
* x_eye = x_object / width - 0.5 = - 0.5
|
|
|
|
* y_eye = (height - y_object) / width - 0.5 = 0.5
|
|
|
|
* z_eye = z_object / width - z_camera = - z_camera
|
|
|
|
*
|
|
|
|
* From cogl_perspective(), we know that the projection matrix has
|
|
|
|
* the form:
|
|
|
|
*
|
|
|
|
* (x, 0, 0, 0)
|
|
|
|
* (0, y, 0, 0)
|
|
|
|
* (0, 0, c, d)
|
|
|
|
* (0, 0, -1, 0)
|
|
|
|
*
|
|
|
|
* Applied to the above, we get clip coordinates of
|
|
|
|
*
|
|
|
|
* x_clip = x * (- 0.5)
|
|
|
|
* y_clip = y * 0.5
|
|
|
|
* w_clip = - 1 * (- z_camera) = z_camera
|
|
|
|
*
|
|
|
|
* Dividing through by w to get normalized device coordinates, we
|
|
|
|
* have, x_nd = x * 0.5 / z_camera, y_nd = - y * 0.5 / z_camera.
|
|
|
|
* The upper left corner of the screen has normalized device coordinates,
|
|
|
|
* (-1, 1), so to have the correct 1:1 mapping, we have to have:
|
|
|
|
*
|
|
|
|
* z_camera = 0.5 * x = 0.5 * y
|
|
|
|
*
|
|
|
|
* If x != y, then we have a non-uniform aspect ration, and a 1:1 mapping
|
|
|
|
* doesn't make sense.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cogl_get_projection_matrix (&projection_matrix);
|
|
|
|
z_camera = 0.5 * projection_matrix.xx;
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_load_identity (modelview_stack);
|
|
|
|
_cogl_matrix_stack_translate (modelview_stack, -0.5f, -0.5f, -z_camera);
|
|
|
|
_cogl_matrix_stack_scale (modelview_stack,
|
2009-10-13 18:09:42 -04:00
|
|
|
1.0f / width, -1.0f / height, 1.0f / width);
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_translate (modelview_stack,
|
2009-10-13 18:09:42 -04:00
|
|
|
0.0f, -1.0 * height, 0.0f);
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglFeatureFlags
|
2009-05-28 08:03:19 -04:00
|
|
|
cogl_get_features (void)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
2010-02-17 12:53:28 -05:00
|
|
|
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_VBOS))
|
2009-06-16 20:46:06 -04:00
|
|
|
ctx->feature_flags &= ~COGL_FEATURE_VBOS;
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
return ctx->feature_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_features_available (CoglFeatureFlags features)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
if (!ctx->features_cached)
|
|
|
|
_cogl_features_init ();
|
|
|
|
|
|
|
|
return (ctx->feature_flags & features) == features;
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* XXX: This function should either be replaced with one returning
|
|
|
|
* integers, or removed/deprecated and make the
|
2009-11-26 14:06:35 -05:00
|
|
|
* _cogl_framebuffer_get_viewport* functions public.
|
2009-09-25 09:34:34 -04:00
|
|
|
*/
|
2009-03-30 12:07:31 -04:00
|
|
|
void
|
|
|
|
cogl_get_viewport (float v[4])
|
|
|
|
{
|
2010-05-27 19:35:47 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
int viewport[4];
|
|
|
|
int i;
|
|
|
|
|
2009-07-01 07:57:30 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2009-03-30 12:07:31 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
_cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
v[i] = viewport[i];
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
cogl_get_bitmasks (int *red,
|
|
|
|
int *green,
|
|
|
|
int *blue,
|
|
|
|
int *alpha)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
2010-04-26 13:08:45 -04:00
|
|
|
CoglHandle framebuffer;
|
|
|
|
|
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (red)
|
2010-04-26 13:08:45 -04:00
|
|
|
*red = cogl_framebuffer_get_red_bits (framebuffer);
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (green)
|
2010-04-26 13:08:45 -04:00
|
|
|
*green = cogl_framebuffer_get_green_bits (framebuffer);
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (blue)
|
2010-04-26 13:08:45 -04:00
|
|
|
*blue = cogl_framebuffer_get_blue_bits (framebuffer);
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (alpha)
|
2010-04-26 13:08:45 -04:00
|
|
|
*alpha = cogl_framebuffer_get_alpha_bits (framebuffer);
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_fog (const CoglColor *fog_color,
|
|
|
|
CoglFogMode mode,
|
|
|
|
float density,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
GLfloat fogColor[4];
|
|
|
|
GLenum gl_mode = GL_LINEAR;
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
/* The cogl journal doesn't currently track fog state changes */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
fogColor[0] = cogl_color_get_red_float (fog_color);
|
|
|
|
fogColor[1] = cogl_color_get_green_float (fog_color);
|
|
|
|
fogColor[2] = cogl_color_get_blue_float (fog_color);
|
|
|
|
fogColor[3] = cogl_color_get_alpha_float (fog_color);
|
|
|
|
|
|
|
|
glEnable (GL_FOG);
|
|
|
|
|
|
|
|
glFogfv (GL_FOG_COLOR, fogColor);
|
|
|
|
|
|
|
|
#if HAVE_COGL_GLES
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case COGL_FOG_MODE_LINEAR:
|
|
|
|
gl_mode = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
case COGL_FOG_MODE_EXPONENTIAL:
|
|
|
|
gl_mode = GL_EXP;
|
|
|
|
break;
|
|
|
|
case COGL_FOG_MODE_EXPONENTIAL_SQUARED:
|
|
|
|
gl_mode = GL_EXP2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* TODO: support other modes for GLES2 */
|
|
|
|
|
|
|
|
/* NB: GLES doesn't have glFogi */
|
|
|
|
glFogf (GL_FOG_MODE, gl_mode);
|
|
|
|
glHint (GL_FOG_HINT, GL_NICEST);
|
|
|
|
|
|
|
|
glFogf (GL_FOG_DENSITY, (GLfloat) density);
|
|
|
|
glFogf (GL_FOG_START, (GLfloat) z_near);
|
|
|
|
glFogf (GL_FOG_END, (GLfloat) z_far);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_disable_fog (void)
|
|
|
|
{
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
/* Currently the journal can't track changes to fog state... */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
glDisable (GL_FOG);
|
|
|
|
}
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
void
|
2009-06-29 12:10:34 -04:00
|
|
|
cogl_flush (void)
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
{
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
}
|
|
|
|
|
2009-06-17 09:30:44 -04:00
|
|
|
void
|
|
|
|
cogl_read_pixels (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
guint8 *pixels)
|
|
|
|
{
|
2010-05-27 19:35:47 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-11-26 14:06:35 -05:00
|
|
|
int framebuffer_height;
|
2010-03-01 13:08:41 -05:00
|
|
|
int bpp;
|
|
|
|
CoglBitmap bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2009-06-17 09:30:44 -04:00
|
|
|
|
|
|
|
g_return_if_fail (source == COGL_READ_PIXELS_COLOR_BUFFER);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* make sure any batched primitives get emitted to the GL driver before
|
|
|
|
* issuing our read pixels... */
|
|
|
|
cogl_flush ();
|
|
|
|
|
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
2009-11-01 20:10:02 -05:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_flush_state (framebuffer, 0);
|
2009-11-01 20:10:02 -05:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer_height = _cogl_framebuffer_get_height (framebuffer);
|
2009-06-17 09:30:44 -04:00
|
|
|
|
|
|
|
/* The y co-ordinate should be given in OpenGL's coordinate system
|
2009-11-01 20:12:10 -05:00
|
|
|
* so 0 is the bottom row
|
|
|
|
*
|
|
|
|
* NB: all offscreen rendering is done upside down so no conversion
|
|
|
|
* is necissary in this case.
|
|
|
|
*/
|
2009-11-26 14:06:35 -05:00
|
|
|
if (!cogl_is_offscreen (framebuffer))
|
|
|
|
y = framebuffer_height - y - height;
|
2009-11-01 20:11:21 -05:00
|
|
|
|
2010-03-01 13:08:41 -05:00
|
|
|
/* Initialise the CoglBitmap */
|
|
|
|
bpp = _cogl_get_format_bpp (format);
|
|
|
|
bmp.format = format;
|
|
|
|
bmp.data = pixels;
|
|
|
|
bmp.width = width;
|
|
|
|
bmp.height = height;
|
|
|
|
bmp.rowstride = bpp * width;
|
|
|
|
|
|
|
|
if ((format & COGL_A_BIT))
|
|
|
|
{
|
|
|
|
/* FIXME: We are assuming glReadPixels will always give us
|
|
|
|
premultiplied data so we'll set the premult flag on the
|
|
|
|
bitmap format. This will usually be correct because the
|
|
|
|
result of the default blending operations for Cogl ends up
|
|
|
|
with premultiplied data in the framebuffer. However it is
|
|
|
|
possible for the framebuffer to be in whatever format
|
|
|
|
depending on what CoglMaterial is used to render to
|
|
|
|
it. Eventually we may want to add a way for an application to
|
|
|
|
inform Cogl that the framebuffer is not premultiplied in case
|
|
|
|
it is being used for some special purpose. */
|
|
|
|
bmp.format |= COGL_PREMULT_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_pixel_format_to_gl (format, &gl_intformat, &gl_format, &gl_type);
|
|
|
|
|
2010-03-26 18:40:53 -04:00
|
|
|
/* Under GLES only GL_RGBA with GL_UNSIGNED_BYTE as well as an
|
|
|
|
implementation specific format under
|
|
|
|
GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES and
|
|
|
|
GL_IMPLEMENTATION_COLOR_READ_TYPE_OES is supported. We could try
|
|
|
|
to be more clever and check if the requested type matches that
|
|
|
|
but we would need some reliable functions to convert from GL
|
|
|
|
types to Cogl types. For now, lets just always read in
|
|
|
|
GL_RGBA/GL_UNSIGNED_BYTE and convert if necessary */
|
|
|
|
#ifndef COGL_HAS_GL
|
|
|
|
if (gl_format != GL_RGBA || gl_type != GL_UNSIGNED_BYTE)
|
|
|
|
{
|
|
|
|
CoglBitmap tmp_bmp, dst_bmp;
|
|
|
|
|
|
|
|
tmp_bmp.format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
tmp_bmp.data = g_malloc (width * height * 4);
|
|
|
|
tmp_bmp.width = width;
|
|
|
|
tmp_bmp.height = height;
|
|
|
|
tmp_bmp.rowstride = 4 * width;
|
|
|
|
|
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (tmp_bmp.rowstride, 4);
|
|
|
|
|
|
|
|
GE( glReadPixels (x, y, width, height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
tmp_bmp.data) );
|
|
|
|
|
|
|
|
/* CoglBitmap doesn't currently have a way to convert without
|
|
|
|
allocating its own buffer so we have to copy the data
|
|
|
|
again */
|
|
|
|
if (_cogl_bitmap_convert_format_and_premult (&tmp_bmp,
|
|
|
|
&dst_bmp,
|
|
|
|
bmp.format))
|
|
|
|
{
|
|
|
|
_cogl_bitmap_copy_subregion (&dst_bmp,
|
|
|
|
&bmp,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
bmp.width, bmp.height);
|
|
|
|
g_free (dst_bmp.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: there's no way to report an error here so we'll
|
|
|
|
just have to leave the data initialised */
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (tmp_bmp.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (bmp.rowstride, bpp);
|
|
|
|
|
|
|
|
GE( glReadPixels (x, y, width, height, gl_format, gl_type, pixels) );
|
2010-03-01 13:08:41 -05:00
|
|
|
|
2010-03-26 18:40:53 -04:00
|
|
|
/* Convert to the premult format specified by the caller
|
|
|
|
in-place. This will do nothing if the premult status is already
|
|
|
|
correct. */
|
|
|
|
_cogl_bitmap_convert_premult_status (&bmp, format);
|
|
|
|
}
|
2009-06-17 09:30:44 -04:00
|
|
|
|
2009-10-22 11:55:07 -04:00
|
|
|
/* NB: All offscreen rendering is done upside down so there is no need
|
|
|
|
* to flip in this case... */
|
2010-03-01 13:08:41 -05:00
|
|
|
if (!cogl_is_offscreen (framebuffer))
|
|
|
|
{
|
|
|
|
guint8 *temprow = g_alloca (bmp.rowstride * sizeof (guint8));
|
2009-10-22 11:55:07 -04:00
|
|
|
|
2010-03-01 13:08:41 -05:00
|
|
|
/* TODO: consider using the GL_MESA_pack_invert extension in the future
|
|
|
|
* to avoid this flip... */
|
2009-06-17 09:30:44 -04:00
|
|
|
|
2010-03-01 13:08:41 -05:00
|
|
|
/* vertically flip the buffer in-place */
|
|
|
|
for (y = 0; y < height / 2; y++)
|
2009-06-17 09:30:44 -04:00
|
|
|
{
|
2010-03-01 13:08:41 -05:00
|
|
|
if (y != height - y - 1) /* skip center row */
|
|
|
|
{
|
|
|
|
memcpy (temprow,
|
|
|
|
pixels + y * bmp.rowstride, bmp.rowstride);
|
|
|
|
memcpy (pixels + y * bmp.rowstride,
|
|
|
|
pixels + (height - y - 1) * bmp.rowstride, bmp.rowstride);
|
|
|
|
memcpy (pixels + (height - y - 1) * bmp.rowstride,
|
|
|
|
temprow,
|
|
|
|
bmp.rowstride);
|
|
|
|
}
|
2009-06-17 09:30:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
static void
|
|
|
|
_cogl_disable_other_texcoord_arrays_cb (int texcoord_array_num, gpointer data)
|
2010-05-19 19:16:49 -04:00
|
|
|
{
|
2010-05-24 07:40:11 -04:00
|
|
|
CoglContext *ctx = data;
|
|
|
|
|
|
|
|
GE (glClientActiveTexture (GL_TEXTURE0 + texcoord_array_num));
|
|
|
|
GE (glDisableClientState (GL_TEXTURE_COORD_ARRAY));
|
|
|
|
}
|
2010-05-19 19:16:49 -04:00
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
void
|
|
|
|
_cogl_disable_other_texcoord_arrays (const CoglBitmask *mask)
|
|
|
|
{
|
2010-05-19 19:16:49 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
/* Set texcoord_arrays_to_disable to only contain the arrays we want
|
|
|
|
to disable */
|
|
|
|
_cogl_bitmask_clear_all (&ctx->texcoord_arrays_to_disable);
|
|
|
|
_cogl_bitmask_set_bits (&ctx->texcoord_arrays_to_disable,
|
|
|
|
&ctx->texcoord_arrays_enabled);
|
|
|
|
_cogl_bitmask_clear_bits (&ctx->texcoord_arrays_to_disable, mask);
|
2010-05-19 19:16:49 -04:00
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
_cogl_bitmask_foreach (&ctx->texcoord_arrays_to_disable,
|
|
|
|
_cogl_disable_other_texcoord_arrays_cb, ctx);
|
2010-05-19 19:16:49 -04:00
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
/* Update the mask of arrays that are enabled */
|
|
|
|
_cogl_bitmask_clear_bits (&ctx->texcoord_arrays_enabled,
|
|
|
|
&ctx->texcoord_arrays_to_disable);
|
2010-05-27 09:51:44 -04:00
|
|
|
_cogl_bitmask_set_bits (&ctx->texcoord_arrays_enabled, mask);
|
2010-05-19 19:16:49 -04:00
|
|
|
}
|
|
|
|
|
2009-06-29 17:32:05 -04:00
|
|
|
void
|
|
|
|
cogl_begin_gl (void)
|
|
|
|
{
|
|
|
|
CoglMaterialFlushOptions options;
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
unsigned long enable_flags = 0;
|
2009-06-29 17:32:05 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->in_begin_gl_block)
|
|
|
|
{
|
|
|
|
static gboolean shown = FALSE;
|
|
|
|
if (!shown)
|
|
|
|
g_warning ("You should not nest cogl_begin_gl/cogl_end_gl blocks");
|
|
|
|
shown = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->in_begin_gl_block = TRUE;
|
|
|
|
|
|
|
|
/* Flush all batched primitives */
|
|
|
|
cogl_flush ();
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* Flush framebuffer state, including clip state, modelview and
|
|
|
|
* projection matrix state
|
|
|
|
*
|
2009-11-26 14:06:35 -05:00
|
|
|
* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
2009-09-25 09:34:34 -04:00
|
|
|
* as the material state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. */
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);
|
2009-06-29 17:32:05 -04:00
|
|
|
|
|
|
|
/* Setup the state for the current material */
|
|
|
|
|
|
|
|
/* We considered flushing a specific, minimal material here to try and
|
|
|
|
* simplify the GL state, but decided to avoid special cases and second
|
|
|
|
* guessing what would be actually helpful.
|
|
|
|
*
|
|
|
|
* A user should instead call cogl_set_source_color4ub() before
|
|
|
|
* cogl_begin_gl() to simplify the state flushed.
|
|
|
|
*/
|
|
|
|
options.flags = 0;
|
|
|
|
_cogl_material_flush_gl_state (ctx->source_material, &options);
|
|
|
|
|
|
|
|
/* FIXME: This api is a bit yukky, ideally it will be removed if we
|
2010-03-19 05:16:08 -04:00
|
|
|
* re-work the _cogl_enable mechanism */
|
2009-06-29 17:32:05 -04:00
|
|
|
enable_flags |= _cogl_material_get_cogl_enable_flags (ctx->source_material);
|
|
|
|
|
|
|
|
if (ctx->enable_backface_culling)
|
|
|
|
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
|
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
_cogl_enable (enable_flags);
|
2009-10-22 14:01:52 -04:00
|
|
|
_cogl_flush_face_winding ();
|
2009-06-29 17:32:05 -04:00
|
|
|
|
|
|
|
/* Disable all client texture coordinate arrays */
|
2010-05-24 07:40:11 -04:00
|
|
|
_cogl_bitmask_clear_all (&ctx->temp_bitmask);
|
|
|
|
_cogl_disable_other_texcoord_arrays (&ctx->temp_bitmask);
|
2009-06-29 17:32:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_end_gl (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (!ctx->in_begin_gl_block)
|
|
|
|
{
|
|
|
|
static gboolean shown = FALSE;
|
|
|
|
if (!shown)
|
|
|
|
g_warning ("cogl_end_gl is being called before cogl_begin_gl");
|
|
|
|
shown = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->in_begin_gl_block = FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-28 21:58:27 -04:00
|
|
|
static CoglTextureUnit *
|
2009-11-15 14:54:17 -05:00
|
|
|
_cogl_texture_unit_new (int index_)
|
2009-09-28 21:58:27 -04:00
|
|
|
{
|
|
|
|
CoglTextureUnit *unit = g_new0 (CoglTextureUnit, 1);
|
|
|
|
unit->matrix_stack = _cogl_matrix_stack_new ();
|
2009-11-15 14:54:17 -05:00
|
|
|
unit->index = index_;
|
2009-09-28 21:58:27 -04:00
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_unit_free (CoglTextureUnit *unit)
|
|
|
|
{
|
|
|
|
_cogl_matrix_stack_destroy (unit->matrix_stack);
|
|
|
|
g_free (unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTextureUnit *
|
|
|
|
_cogl_get_texture_unit (int index_)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
CoglTextureUnit *unit;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
|
|
|
for (l = ctx->texture_units; l; l = l->next)
|
|
|
|
{
|
|
|
|
unit = l->data;
|
|
|
|
|
|
|
|
if (unit->index == index_)
|
|
|
|
return unit;
|
|
|
|
|
|
|
|
/* The units are always sorted, so at this point we know this unit
|
|
|
|
* doesn't exist */
|
|
|
|
if (unit->index > index_)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* NB: if we now insert a new layer before l, that will maintain order.
|
|
|
|
*/
|
|
|
|
|
2009-11-15 14:54:17 -05:00
|
|
|
unit = _cogl_texture_unit_new (index_);
|
2009-09-28 21:58:27 -04:00
|
|
|
|
|
|
|
/* Note: see comment after for() loop above */
|
|
|
|
ctx->texture_units =
|
|
|
|
g_list_insert_before (ctx->texture_units, l, unit);
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_destroy_texture_units (void)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
for (l = ctx->texture_units; l; l = l->next)
|
|
|
|
_cogl_texture_unit_free (l->data);
|
|
|
|
g_list_free (ctx->texture_units);
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:47:25 -05:00
|
|
|
/*
|
|
|
|
* This is more complicated than that, another pass needs to be done when
|
|
|
|
* cogl have a neat way of saying if we are using the fixed function pipeline
|
|
|
|
* or not (for the GL case):
|
|
|
|
* MAX_TEXTURE_UNITS: fixed function pipeline, a texture unit has both a
|
|
|
|
* sampler and a set of texture coordinates
|
|
|
|
* MAX_TEXTURE_IMAGE_UNITS: number of samplers one can use from a fragment
|
|
|
|
* program/shader (ARBfp1.0 asm/GLSL)
|
|
|
|
* MAX_VERTEX_TEXTURE_UNITS: number of samplers one can use from a vertex
|
|
|
|
* program/shader (can be 0)
|
|
|
|
* MAX_COMBINED_TEXTURE_IMAGE_UNITS: Maximum samplers one can use, counting both
|
|
|
|
* the vertex and fragment shaders
|
|
|
|
*
|
|
|
|
* If both the vertex shader and the fragment processing stage access the same
|
|
|
|
* texture image unit, then that counts as using two texture image units
|
|
|
|
* against the latter limit: http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml
|
|
|
|
*
|
|
|
|
* Note that, for now, we use GL_MAX_TEXTURE_UNITS as we are exposing the
|
|
|
|
* fixed function pipeline.
|
|
|
|
*/
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
unsigned int
|
2010-01-26 13:47:25 -05:00
|
|
|
_cogl_get_max_texture_image_units (void)
|
|
|
|
{
|
2010-02-12 09:26:33 -05:00
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
2010-01-26 13:47:25 -05:00
|
|
|
|
2010-02-12 09:26:33 -05:00
|
|
|
/* This function is called quite often so we cache the value to
|
|
|
|
avoid too many GL calls */
|
|
|
|
if (ctx->max_texture_units == -1)
|
|
|
|
{
|
|
|
|
ctx->max_texture_units = 1;
|
|
|
|
GE( glGetIntegerv (GL_MAX_TEXTURE_UNITS, &ctx->max_texture_units) );
|
|
|
|
}
|
2010-01-26 13:47:25 -05:00
|
|
|
|
2010-02-12 09:26:33 -05:00
|
|
|
return ctx->max_texture_units;
|
2010-01-26 13:47:25 -05:00
|
|
|
}
|
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
void
|
|
|
|
cogl_push_matrix (void)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pop_matrix (void)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_scale (float x, float y, float z)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_scale (modelview_stack, x, y, z);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translate (float x, float y, float z)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_translate (modelview_stack, x, y, z);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotate (float angle, float x, float y, float z)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_rotate (modelview_stack, angle, x, y, z);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
2010-03-19 05:30:59 -04:00
|
|
|
void
|
2010-04-08 09:37:01 -04:00
|
|
|
cogl_transform (const CoglMatrix *matrix)
|
2010-03-19 05:30:59 -04:00
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
|
|
|
_cogl_matrix_stack_multiply (modelview_stack, matrix);
|
|
|
|
}
|
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
void
|
|
|
|
cogl_perspective (float fov_y,
|
|
|
|
float aspect,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
float ymax = z_near * tanf (fov_y * G_PI / 360.0);
|
|
|
|
|
|
|
|
cogl_frustum (-ymax * aspect, /* left */
|
|
|
|
ymax * aspect, /* right */
|
|
|
|
-ymax, /* bottom */
|
|
|
|
ymax, /* top */
|
|
|
|
z_near,
|
|
|
|
z_far);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_frustum (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (_cogl_get_framebuffer ());
|
2009-10-13 18:09:42 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_load_identity (projection_stack);
|
2009-10-13 18:09:42 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_frustum (projection_stack,
|
2009-10-13 18:09:42 -04:00
|
|
|
left,
|
|
|
|
right,
|
|
|
|
bottom,
|
|
|
|
top,
|
|
|
|
z_near,
|
|
|
|
z_far);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_ortho (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
CoglMatrix ortho;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (_cogl_get_framebuffer ());
|
2009-10-13 18:09:42 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
cogl_matrix_init_identity (&ortho);
|
|
|
|
cogl_matrix_ortho (&ortho, left, right, bottom, top, z_near, z_far);
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_set (projection_stack, &ortho);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_get (modelview_stack, matrix);
|
2009-10-26 07:01:33 -04:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_set (modelview_stack, matrix);
|
2009-10-26 07:01:33 -04:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_get (projection_stack, matrix);
|
2009-10-26 07:01:33 -04:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_set (projection_stack, matrix);
|
2009-10-13 18:09:42 -04:00
|
|
|
|
|
|
|
/* FIXME: Update the inverse projection matrix!! Presumably use
|
|
|
|
* of clip planes must currently be broken if this API is used. */
|
2009-10-26 07:01:33 -04:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
2010-04-14 14:41:08 -04:00
|
|
|
CoglClipState *
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_get_clip_state (void)
|
2009-10-13 18:09:42 -04:00
|
|
|
{
|
2010-05-27 19:35:47 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
return _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-10-13 18:09:42 -04:00
|
|
|
}
|
|
|
|
|
2009-11-11 08:26:54 -05:00
|
|
|
GQuark
|
|
|
|
_cogl_driver_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-driver-error-quark");
|
|
|
|
}
|
2010-03-19 05:55:30 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source (CoglHandle material_handle)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
g_return_if_fail (cogl_is_material (material_handle));
|
|
|
|
|
|
|
|
if (ctx->source_material == material_handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cogl_handle_ref (material_handle);
|
|
|
|
|
|
|
|
if (ctx->source_material)
|
|
|
|
cogl_handle_unref (ctx->source_material);
|
|
|
|
|
|
|
|
ctx->source_material = material_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_texture (CoglHandle texture_handle)
|
|
|
|
{
|
|
|
|
CoglColor white;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-05-27 19:35:47 -04:00
|
|
|
g_return_if_fail (texture_handle != NULL);
|
2010-03-19 05:55:30 -04:00
|
|
|
|
|
|
|
cogl_material_set_layer (ctx->simple_material, 0, texture_handle);
|
|
|
|
cogl_color_set_from_4ub (&white, 0xff, 0xff, 0xff, 0xff);
|
|
|
|
cogl_material_set_color (ctx->simple_material, &white);
|
|
|
|
cogl_set_source (ctx->simple_material);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_color4ub (guint8 red,
|
|
|
|
guint8 green,
|
|
|
|
guint8 blue,
|
|
|
|
guint8 alpha)
|
|
|
|
{
|
|
|
|
CoglColor c = { 0, };
|
|
|
|
|
|
|
|
cogl_color_set_from_4ub (&c, red, green, blue, alpha);
|
|
|
|
cogl_set_source_color (&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_color4f (float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
CoglColor c = { 0, };
|
|
|
|
|
|
|
|
cogl_color_set_from_4f (&c, red, green, blue, alpha);
|
|
|
|
cogl_set_source_color (&c);
|
|
|
|
}
|
|
|
|
|