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"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-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"
|
2010-12-03 12:46:16 -05:00
|
|
|
#include "cogl-vertex-attribute-private.h"
|
2009-03-30 12:07:31 -04:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-11-02 13:15:06 -04:00
|
|
|
/* This version of cogl_clear can be used internally as an alternative
|
|
|
|
to avoid flushing the journal or the framebuffer state. This is
|
|
|
|
needed when doing operations that may be called whiling flushing
|
|
|
|
the journal */
|
2009-03-30 12:07:31 -04:00
|
|
|
void
|
2010-11-02 13:15:06 -04: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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2010-11-02 13:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_clear (const CoglColor *color, unsigned long buffers)
|
|
|
|
{
|
|
|
|
COGL_NOTE (DRAW, "Clear begin");
|
|
|
|
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
|
|
|
/* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
|
|
|
* as the pipeline state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. */
|
|
|
|
_cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);
|
|
|
|
|
|
|
|
_cogl_clear (color, buffers);;
|
2010-01-22 13:14:57 -05:00
|
|
|
|
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-12-05 13:02:05 -05:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
/* Under GLES2 there are no builtin client flags so toggle_client_flag
|
|
|
|
should never be reached */
|
|
|
|
|
|
|
|
#define toggle_client_flag(ctx, new_flags, flag, gl_flag) \
|
|
|
|
g_assert (((new_flags) & (flag)) == 0)
|
|
|
|
|
|
|
|
#else /* HAVE_COGL_GLES2 */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-05 13:02:05 -05:00
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
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_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;
|
|
|
|
}
|
|
|
|
|
2010-05-26 06:33:32 -04:00
|
|
|
/* XXX: This API has been deprecated */
|
2009-03-30 12:07:31 -04:00
|
|
|
void
|
2009-05-26 11:55:11 -04:00
|
|
|
cogl_set_depth_test_enabled (gboolean setting)
|
2009-03-30 12:07:31 -04:00
|
|
|
{
|
2010-05-26 06:33:32 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
[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
|
|
|
|
2010-05-26 06:33:32 -04:00
|
|
|
if (ctx->legacy_depth_test_enabled == setting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ctx->legacy_depth_test_enabled = setting;
|
|
|
|
if (ctx->legacy_depth_test_enabled)
|
|
|
|
ctx->legacy_state_set++;
|
2009-03-30 12:07:31 -04:00
|
|
|
else
|
2010-05-26 06:33:32 -04:00
|
|
|
ctx->legacy_state_set--;
|
2009-05-26 11:55:11 -04:00
|
|
|
}
|
|
|
|
|
2010-05-26 06:33:32 -04:00
|
|
|
/* XXX: This API has been deprecated */
|
2009-05-26 11:55:11 -04:00
|
|
|
gboolean
|
|
|
|
cogl_get_depth_test_enabled (void)
|
|
|
|
{
|
2010-05-26 06:33:32 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
return ctx->legacy_depth_test_enabled;
|
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)
|
|
|
|
{
|
2010-11-01 16:27:32 -04:00
|
|
|
CoglPipeline *pipeline;
|
2009-05-09 14:39:01 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-11-01 16:27:32 -04:00
|
|
|
if (cogl_color_get_alpha_byte (color) == 0xff)
|
|
|
|
{
|
|
|
|
cogl_pipeline_set_color (ctx->opaque_color_pipeline, color);
|
|
|
|
pipeline = ctx->opaque_color_pipeline;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglColor premultiplied = *color;
|
|
|
|
cogl_color_premultiply (&premultiplied);
|
|
|
|
cogl_pipeline_set_color (ctx->blended_color_pipeline, &premultiplied);
|
|
|
|
pipeline = ctx->blended_color_pipeline;
|
|
|
|
}
|
2009-05-09 14:39:01 -04:00
|
|
|
|
2010-11-01 16:27:32 -04:00
|
|
|
cogl_set_source (pipeline);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return ctx->feature_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_features_available (CoglFeatureFlags features)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return (ctx->feature_flags & features) == features;
|
|
|
|
}
|
|
|
|
|
2009-11-14 09:59:59 -05:00
|
|
|
gboolean
|
|
|
|
_cogl_features_available_private (CoglFeatureFlagsPrivate features)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return (ctx->feature_flags_private & 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-07-07 09:41:54 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2010-04-26 13:08:45 -04:00
|
|
|
|
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
2009-05-19 09:44:29 -04:00
|
|
|
|
2009-03-30 12:07:31 -04:00
|
|
|
if (red)
|
2010-05-26 11:31:18 -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-05-26 11:31:18 -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-05-26 11:31:18 -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-05-26 11:31:18 -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)
|
|
|
|
{
|
2010-04-26 05:01:43 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-07-06 15:18:26 -04:00
|
|
|
if (ctx->legacy_fog_state.enabled == FALSE)
|
|
|
|
ctx->legacy_state_set++;
|
2010-04-26 05:01:43 -04:00
|
|
|
|
2010-07-06 15:18:26 -04:00
|
|
|
ctx->legacy_fog_state.enabled = TRUE;
|
|
|
|
ctx->legacy_fog_state.color = *fog_color;
|
|
|
|
ctx->legacy_fog_state.mode = mode;
|
|
|
|
ctx->legacy_fog_state.density = density;
|
|
|
|
ctx->legacy_fog_state.z_near = z_near;
|
|
|
|
ctx->legacy_fog_state.z_far = z_far;
|
2009-03-30 12:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_disable_fog (void)
|
|
|
|
{
|
2010-04-26 05:01:43 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-07-06 15:18:26 -04:00
|
|
|
if (ctx->legacy_fog_state.enabled == TRUE)
|
|
|
|
ctx->legacy_state_set--;
|
[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
|
|
|
|
2010-07-06 15:18:26 -04:00
|
|
|
ctx->legacy_fog_state.enabled = FALSE;
|
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
|
|
|
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
|
2010-11-17 10:38:20 -05:00
|
|
|
_cogl_read_pixels_with_rowstride (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
guint8 *pixels,
|
|
|
|
int rowstride)
|
2009-06-17 09:30:44 -04:00
|
|
|
{
|
2010-05-27 19:35:47 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2010-07-07 13:44:16 -04:00
|
|
|
int framebuffer_height;
|
|
|
|
int bpp;
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
CoglPixelFormat bmp_format;
|
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);
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp_format = format;
|
2010-03-01 13:08:41 -05:00
|
|
|
|
|
|
|
if ((format & COGL_A_BIT))
|
|
|
|
{
|
2010-11-17 12:57:17 -05:00
|
|
|
/* We match the premultiplied state of the target buffer to the
|
|
|
|
* premultiplied state of the framebuffer so that it will get
|
|
|
|
* converted to the right format below */
|
|
|
|
|
|
|
|
if ((framebuffer->format & COGL_PREMULT_BIT))
|
|
|
|
bmp_format |= COGL_PREMULT_BIT;
|
|
|
|
else
|
|
|
|
bmp_format &= ~COGL_PREMULT_BIT;
|
2010-03-01 13:08:41 -05:00
|
|
|
}
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp = _cogl_bitmap_new_from_data (pixels,
|
|
|
|
bmp_format, width, height, rowstride,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2010-03-01 13:08:41 -05:00
|
|
|
_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
|
2010-11-17 10:38:20 -05:00
|
|
|
GL_RGBA/GL_UNSIGNED_BYTE and convert if necessary. We also need
|
|
|
|
to use this intermediate buffer if the rowstride has padding
|
|
|
|
because GLES does not support setting GL_ROW_LENGTH */
|
2010-03-26 18:40:53 -04:00
|
|
|
#ifndef COGL_HAS_GL
|
2010-11-17 10:38:20 -05:00
|
|
|
if (gl_format != GL_RGBA || gl_type != GL_UNSIGNED_BYTE ||
|
|
|
|
rowstride != 4 * width)
|
2010-03-26 18:40:53 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *tmp_bmp, *dst_bmp;
|
|
|
|
guint8 *tmp_data = g_malloc (width * height * 4);
|
2010-03-26 18:40:53 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
tmp_bmp = _cogl_bitmap_new_from_data (tmp_data,
|
2010-11-17 12:57:17 -05:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888 |
|
|
|
|
(bmp_format & COGL_PREMULT_BIT),
|
2010-07-07 13:44:16 -04:00
|
|
|
width, height, 4 * width,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2010-03-26 18:40:53 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (4 * width, 4);
|
2010-03-26 18:40:53 -04:00
|
|
|
|
|
|
|
GE( glReadPixels (x, y, width, height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE,
|
2010-07-07 13:44:16 -04:00
|
|
|
tmp_data) );
|
2010-03-26 18:40:53 -04:00
|
|
|
|
|
|
|
/* CoglBitmap doesn't currently have a way to convert without
|
|
|
|
allocating its own buffer so we have to copy the data
|
|
|
|
again */
|
2010-07-07 13:44:16 -04:00
|
|
|
if ((dst_bmp = _cogl_bitmap_convert_format_and_premult (tmp_bmp,
|
2010-11-17 12:45:27 -05:00
|
|
|
format)))
|
2010-03-26 18:40:53 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_bitmap_copy_subregion (dst_bmp,
|
|
|
|
bmp,
|
2010-03-26 18:40:53 -04:00
|
|
|
0, 0,
|
|
|
|
0, 0,
|
2010-07-07 13:44:16 -04:00
|
|
|
width, height);
|
|
|
|
cogl_object_unref (dst_bmp);
|
2010-03-26 18:40:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: there's no way to report an error here so we'll
|
|
|
|
just have to leave the data initialised */
|
|
|
|
}
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (tmp_bmp);
|
2010-03-26 18:40:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_driver_prep_gl_for_pixels_download (rowstride, bpp);
|
2010-03-26 18:40:53 -04:00
|
|
|
|
|
|
|
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. */
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_bitmap_convert_premult_status (bmp, format);
|
2010-03-26 18:40:53 -04:00
|
|
|
}
|
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))
|
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
guint8 *temprow = g_alloca (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,
|
2010-07-07 13:44:16 -04:00
|
|
|
pixels + y * rowstride, rowstride);
|
|
|
|
memcpy (pixels + y * rowstride,
|
|
|
|
pixels + (height - y - 1) * rowstride, rowstride);
|
|
|
|
memcpy (pixels + (height - y - 1) * rowstride,
|
2010-03-01 13:08:41 -05:00
|
|
|
temprow,
|
2010-07-07 13:44:16 -04:00
|
|
|
rowstride);
|
2010-03-01 13:08:41 -05:00
|
|
|
}
|
2009-06-17 09:30:44 -04:00
|
|
|
}
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
2009-06-17 09:30:44 -04:00
|
|
|
}
|
|
|
|
|
2010-11-17 10:38:20 -05:00
|
|
|
void
|
|
|
|
cogl_read_pixels (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
guint8 *pixels)
|
|
|
|
{
|
|
|
|
_cogl_read_pixels_with_rowstride (x, y, width, height,
|
|
|
|
source, format, pixels,
|
|
|
|
/* rowstride */
|
|
|
|
_cogl_get_format_bpp (format) * width);
|
|
|
|
}
|
|
|
|
|
2009-06-29 17:32:05 -04:00
|
|
|
void
|
|
|
|
cogl_begin_gl (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
|
|
|
unsigned long enable_flags = 0;
|
2010-07-23 12:46:41 -04:00
|
|
|
CoglPipeline *pipeline;
|
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
|
2010-10-27 13:54:57 -04:00
|
|
|
* as the pipeline state) when flushing the clip stack, so should
|
2009-09-25 09:34:34 -04:00
|
|
|
* 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
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
/* Setup the state for the current pipeline */
|
2009-06-29 17:32:05 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
/* We considered flushing a specific, minimal pipeline here to try and
|
2009-06-29 17:32:05 -04:00
|
|
|
* 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.
|
2010-07-23 12:46:41 -04:00
|
|
|
*
|
2010-12-02 16:08:30 -05:00
|
|
|
* XXX: note defining n_tex_coord_attribs using
|
|
|
|
* cogl_pipeline_get_n_layers is a hack, but the problem is that
|
|
|
|
* n_tex_coord_attribs is usually defined when drawing a primitive
|
|
|
|
* which isn't happening here.
|
|
|
|
*
|
2010-07-23 12:46:41 -04:00
|
|
|
* Maybe it would be more useful if this code did flush the
|
|
|
|
* opaque_color_pipeline and then call into cogl-pipeline-opengl.c to then
|
|
|
|
* restore all state for the material's backend back to default OpenGL
|
|
|
|
* values.
|
2009-06-29 17:32:05 -04:00
|
|
|
*/
|
2010-07-23 12:46:41 -04:00
|
|
|
pipeline = cogl_get_source ();
|
2010-12-02 16:08:30 -05:00
|
|
|
_cogl_pipeline_flush_gl_state (pipeline,
|
|
|
|
FALSE,
|
|
|
|
cogl_pipeline_get_n_layers (pipeline));
|
2009-06-29 17:32:05 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-12-03 12:46:16 -05:00
|
|
|
/* Disable any cached vertex arrays */
|
|
|
|
_cogl_vertex_attribute_disable_cached_arrays ();
|
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-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
|
|
|
|
2010-10-25 08:25:21 -04:00
|
|
|
typedef struct _CoglSourceState
|
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipeline *pipeline;
|
2010-10-25 08:25:21 -04:00
|
|
|
int push_count;
|
|
|
|
} CoglSourceState;
|
|
|
|
|
|
|
|
static void
|
2010-10-27 13:54:57 -04:00
|
|
|
_push_source_real (CoglPipeline *pipeline)
|
2010-10-25 08:25:21 -04:00
|
|
|
{
|
|
|
|
CoglSourceState *top = g_slice_new (CoglSourceState);
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
top->pipeline = cogl_object_ref (pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
top->push_count = 1;
|
|
|
|
|
|
|
|
ctx->source_stack = g_list_prepend (ctx->source_stack, top);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: This should take a context pointer for Cogl 2.0 Technically
|
|
|
|
* we could make it so we can retrieve a context reference from the
|
2010-10-27 13:54:57 -04:00
|
|
|
* pipeline, but this would not by symmetric with cogl_pop_source. */
|
2010-03-19 05:55:30 -04:00
|
|
|
void
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_push_source (void *material_or_pipeline)
|
2010-03-19 05:55:30 -04:00
|
|
|
{
|
2010-10-25 08:25:21 -04:00
|
|
|
CoglSourceState *top;
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipeline *pipeline = COGL_PIPELINE (material_or_pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
|
2010-03-19 05:55:30 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2010-03-19 05:55:30 -04:00
|
|
|
|
2010-10-25 08:25:21 -04:00
|
|
|
if (ctx->source_stack)
|
|
|
|
{
|
|
|
|
top = ctx->source_stack->data;
|
2010-10-27 13:54:57 -04:00
|
|
|
if (top->pipeline == pipeline)
|
2010-10-25 08:25:21 -04:00
|
|
|
{
|
|
|
|
top->push_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2010-10-27 13:54:57 -04:00
|
|
|
_push_source_real (pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
}
|
|
|
|
else
|
2010-10-27 13:54:57 -04:00
|
|
|
_push_source_real (pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
}
|
2010-03-19 05:55:30 -04:00
|
|
|
|
2010-10-25 08:25:21 -04:00
|
|
|
/* FIXME: This needs to take a context pointer for Cogl 2.0 */
|
|
|
|
void
|
|
|
|
cogl_pop_source (void)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
2010-03-19 05:55:30 -04:00
|
|
|
|
2010-10-25 08:25:21 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2010-03-19 05:55:30 -04:00
|
|
|
|
2010-10-25 08:25:21 -04:00
|
|
|
g_return_if_fail (ctx->source_stack);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
|
|
|
top->push_count--;
|
|
|
|
if (top->push_count == 0)
|
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_object_unref (top->pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
g_slice_free (CoglSourceState, top);
|
|
|
|
ctx->source_stack = g_list_delete_link (ctx->source_stack,
|
|
|
|
ctx->source_stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: This needs to take a context pointer for Cogl 2.0 */
|
2010-10-27 13:54:57 -04:00
|
|
|
void *
|
2010-10-25 08:25:21 -04:00
|
|
|
cogl_get_source (void)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
|
|
|
g_return_val_if_fail (ctx->source_stack, NULL);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
2010-10-27 13:54:57 -04:00
|
|
|
return top->pipeline;
|
2010-10-25 08:25:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_set_source (void *material_or_pipeline)
|
2010-10-25 08:25:21 -04:00
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipeline *pipeline = COGL_PIPELINE (material_or_pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2010-10-25 08:25:21 -04:00
|
|
|
g_return_if_fail (ctx->source_stack);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
2010-10-27 13:54:57 -04:00
|
|
|
if (top->pipeline == pipeline)
|
2010-10-25 08:25:21 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (top->push_count == 1)
|
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
/* NB: top->pipeline may be only thing keeping pipeline
|
|
|
|
* alive currently so ref pipeline first... */
|
|
|
|
cogl_object_ref (pipeline);
|
|
|
|
cogl_object_unref (top->pipeline);
|
|
|
|
top->pipeline = pipeline;
|
2010-10-25 08:25:21 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top->push_count--;
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_push_source (pipeline);
|
2010-10-25 08:25:21 -04:00
|
|
|
}
|
2010-03-19 05:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_texture (CoglHandle texture_handle)
|
|
|
|
{
|
|
|
|
_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
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_layer_texture (ctx->texture_pipeline, 0, texture_handle);
|
|
|
|
cogl_set_source (ctx->texture_pipeline);
|
2010-03-19 05:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_color4ub (guint8 red,
|
|
|
|
guint8 green,
|
|
|
|
guint8 blue,
|
|
|
|
guint8 alpha)
|
|
|
|
{
|
|
|
|
CoglColor c = { 0, };
|
|
|
|
|
2010-09-03 11:55:12 -04:00
|
|
|
cogl_color_init_from_4ub (&c, red, green, blue, alpha);
|
2010-03-19 05:55:30 -04:00
|
|
|
cogl_set_source_color (&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_color4f (float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
CoglColor c = { 0, };
|
|
|
|
|
2010-09-03 11:55:12 -04:00
|
|
|
cogl_color_init_from_4f (&c, red, green, blue, alpha);
|
2010-03-19 05:55:30 -04:00
|
|
|
cogl_set_source_color (&c);
|
|
|
|
}
|
|
|
|
|
2010-04-22 08:48:49 -04:00
|
|
|
/* Scale from OpenGL normalized device coordinates (ranging from -1 to 1)
|
|
|
|
* to Cogl window/framebuffer coordinates (ranging from 0 to buffer-size) with
|
|
|
|
* (0,0) being top left. */
|
|
|
|
#define VIEWPORT_TRANSFORM_X(x, vp_origin_x, vp_width) \
|
|
|
|
( ( ((x) + 1.0) * ((vp_width) / 2.0) ) + (vp_origin_x) )
|
|
|
|
/* Note: for Y we first flip all coordinates around the X axis while in
|
|
|
|
* normalized device coodinates */
|
|
|
|
#define VIEWPORT_TRANSFORM_Y(y, vp_origin_y, vp_height) \
|
|
|
|
( ( ((-(y)) + 1.0) * ((vp_height) / 2.0) ) + (vp_origin_y) )
|
|
|
|
|
|
|
|
/* Transform a homogeneous vertex position from model space to Cogl
|
|
|
|
* window coordinates (with 0,0 being top left) */
|
|
|
|
void
|
|
|
|
_cogl_transform_point (const CoglMatrix *matrix_mv,
|
|
|
|
const CoglMatrix *matrix_p,
|
|
|
|
const float *viewport,
|
|
|
|
float *x,
|
|
|
|
float *y)
|
|
|
|
{
|
|
|
|
float z = 0;
|
|
|
|
float w = 1;
|
|
|
|
|
|
|
|
/* Apply the modelview matrix transform */
|
|
|
|
cogl_matrix_transform_point (matrix_mv, x, y, &z, &w);
|
|
|
|
|
|
|
|
/* Apply the projection matrix transform */
|
|
|
|
cogl_matrix_transform_point (matrix_p, x, y, &z, &w);
|
|
|
|
|
|
|
|
/* Perform perspective division */
|
|
|
|
*x /= w;
|
|
|
|
*y /= w;
|
|
|
|
|
|
|
|
/* Apply viewport transform */
|
|
|
|
*x = VIEWPORT_TRANSFORM_X (*x, viewport[0], viewport[2]);
|
|
|
|
*y = VIEWPORT_TRANSFORM_Y (*y, viewport[1], viewport[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VIEWPORT_TRANSFORM_X
|
|
|
|
#undef VIEWPORT_TRANSFORM_Y
|
2010-05-26 06:33:32 -04:00
|
|
|
|
|
|
|
GQuark
|
|
|
|
_cogl_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-error-quark");
|
|
|
|
}
|
|
|
|
|