2009-03-30 16:07:31 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2009-03-30 16:07:31 +00:00
|
|
|
*
|
2010-03-19 09:55:30 +00:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2009-03-30 16:07:31 +00: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 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-03-30 16:07:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
2011-09-10 08:51:42 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2009-03-30 16:07:31 +00:00
|
|
|
|
2009-05-19 13:44:29 +00:00
|
|
|
#include "cogl-debug.h"
|
2009-03-30 16:07:31 +00:00
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-util.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2010-11-05 12:28:33 +00:00
|
|
|
#include "cogl-winsys-private.h"
|
2009-11-26 19:06:35 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2009-10-26 11:01:33 +00:00
|
|
|
#include "cogl-matrix-private.h"
|
2010-01-22 18:14:57 +00:00
|
|
|
#include "cogl-journal-private.h"
|
2010-03-01 18:08:41 +00:00
|
|
|
#include "cogl-bitmap-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-driver.h"
|
2011-01-20 19:31:53 +00:00
|
|
|
#include "cogl-attribute-private.h"
|
2011-01-05 15:30:04 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2011-07-27 11:30:02 +00:00
|
|
|
#include "cogl-renderer-private.h"
|
2011-08-03 17:15:54 +00:00
|
|
|
#include "cogl-config-private.h"
|
2011-09-14 11:17:09 +00:00
|
|
|
#include "cogl-private.h"
|
2009-03-30 16:07:31 +00:00
|
|
|
|
2011-07-13 17:28:49 +00:00
|
|
|
#ifndef GL_PACK_INVERT_MESA
|
|
|
|
#define GL_PACK_INVERT_MESA 0x8758
|
|
|
|
#endif
|
|
|
|
|
2009-05-19 13:44:29 +00:00
|
|
|
#ifdef COGL_GL_DEBUG
|
2009-03-30 16:07:31 +00:00
|
|
|
/* GL error to string conversion */
|
2009-05-18 18:38:03 +00: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-10 01:57:32 +00:00
|
|
|
const char *error_string;
|
2009-05-18 18:38:03 +00:00
|
|
|
} gl_errors[] = {
|
|
|
|
{ GL_NO_ERROR, "No error" },
|
|
|
|
{ GL_INVALID_ENUM, "Invalid enumeration value" },
|
|
|
|
{ GL_INVALID_VALUE, "Invalid value" },
|
|
|
|
{ GL_INVALID_OPERATION, "Invalid operation" },
|
2011-03-02 11:02:50 +00:00
|
|
|
#ifdef HAVE_COGL_GL
|
2009-05-18 18:38:03 +00:00
|
|
|
{ GL_STACK_OVERFLOW, "Stack overflow" },
|
|
|
|
{ GL_STACK_UNDERFLOW, "Stack underflow" },
|
2011-03-02 11:02:50 +00:00
|
|
|
#endif
|
2009-05-18 18:38:03 +00:00
|
|
|
{ GL_OUT_OF_MEMORY, "Out of memory" },
|
2009-03-30 16:07:31 +00:00
|
|
|
|
|
|
|
#ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
|
2009-05-18 18:38:03 +00:00
|
|
|
{ GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "Invalid framebuffer operation" }
|
2009-03-30 16:07:31 +00: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-10 01:57:32 +00:00
|
|
|
static const unsigned int n_gl_errors = G_N_ELEMENTS (gl_errors);
|
2009-05-18 18:38:03 +00: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-10 01:57:32 +00:00
|
|
|
const char *
|
2009-05-18 18:38:03 +00:00
|
|
|
cogl_gl_error_to_string (GLenum error_code)
|
2009-03-30 16:07:31 +00: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-10 01:57:32 +00:00
|
|
|
int i;
|
2009-05-18 18:38:03 +00: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 13:44:29 +00:00
|
|
|
return "Unknown GL error";
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
2009-05-19 13:44:29 +00:00
|
|
|
#endif /* COGL_GL_DEBUG */
|
2009-03-30 16:07:31 +00: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-28 01:02:02 +00: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-10 01:57:32 +00: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-28 01:02:02 +00:00
|
|
|
{
|
2011-02-25 11:29:08 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
2011-07-27 11:30:02 +00:00
|
|
|
return _cogl_renderer_get_proc_address (ctx->display->renderer, 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-28 01:02:02 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 16:32:19 +00: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-10 01:57:32 +00:00
|
|
|
_cogl_check_extension (const char *name, const gchar *ext)
|
2010-02-05 16:32:19 +00: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-10 01:57:32 +00:00
|
|
|
char *end;
|
|
|
|
int name_len, n;
|
2010-02-05 16:32:19 +00: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-10 01:57:32 +00:00
|
|
|
end = (char*)(ext + strlen(ext));
|
2010-02-05 16:32:19 +00: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);
|
|
|
|
}
|
|
|
|
|
2011-01-05 15:30:04 +00:00
|
|
|
/* XXX: it's expected that we'll deprecated this with
|
|
|
|
* cogl_framebuffer_clear at some point. */
|
2010-11-02 17:15:06 +00:00
|
|
|
void
|
|
|
|
cogl_clear (const CoglColor *color, unsigned long buffers)
|
|
|
|
{
|
2011-08-02 15:27:59 +00:00
|
|
|
cogl_framebuffer_clear (cogl_get_draw_framebuffer (), buffers, color);
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
2010-12-05 18:02:05 +00:00
|
|
|
|
2010-03-19 09:16:08 +00:00
|
|
|
static gboolean
|
|
|
|
toggle_client_flag (CoglContext *ctx,
|
|
|
|
unsigned long new_flags,
|
|
|
|
unsigned long flag,
|
|
|
|
GLenum gl_flag)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
g_return_val_if_fail (ctx->driver != COGL_DRIVER_GLES2, FALSE);
|
|
|
|
|
2009-03-30 16:07:31 +00: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))
|
|
|
|
{
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glEnableClientState (gl_flag) );
|
2009-03-30 16:07:31 +00:00
|
|
|
ctx->enable_flags |= flag;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ctx->enable_flags & flag)
|
|
|
|
{
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glDisableClientState (gl_flag) );
|
2009-03-30 16:07:31 +00:00
|
|
|
ctx->enable_flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
#endif
|
2010-12-05 18:02:05 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
void
|
2010-03-19 09:16:08 +00:00
|
|
|
_cogl_enable (unsigned long flags)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
|
|
|
/* This function essentially caches glEnable state() in the
|
|
|
|
* hope of lessening number GL traffic.
|
|
|
|
*/
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
|
|
|
|
if (ctx->driver != COGL_DRIVER_GLES2)
|
|
|
|
{
|
|
|
|
toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_VERTEX_ARRAY,
|
|
|
|
GL_VERTEX_ARRAY);
|
2009-03-30 16:07:31 +00:00
|
|
|
|
2011-07-07 19:44:56 +00:00
|
|
|
toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_COLOR_ARRAY,
|
|
|
|
GL_COLOR_ARRAY);
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-30 16:07:31 +00: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-10 01:57:32 +00:00
|
|
|
unsigned long
|
2010-03-19 09:16:08 +00:00
|
|
|
_cogl_get_enable (void)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return ctx->enable_flags;
|
|
|
|
}
|
|
|
|
|
2010-05-26 10:33:32 +00:00
|
|
|
/* XXX: This API has been deprecated */
|
2009-03-30 16:07:31 +00:00
|
|
|
void
|
2009-05-26 15:55:11 +00:00
|
|
|
cogl_set_depth_test_enabled (gboolean setting)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
2010-05-26 10:33:32 +00: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 17:46:42 +00:00
|
|
|
|
2010-05-26 10:33:32 +00: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 16:07:31 +00:00
|
|
|
else
|
2010-05-26 10:33:32 +00:00
|
|
|
ctx->legacy_state_set--;
|
2009-05-26 15:55:11 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 10:33:32 +00:00
|
|
|
/* XXX: This API has been deprecated */
|
2009-05-26 15:55:11 +00:00
|
|
|
gboolean
|
|
|
|
cogl_get_depth_test_enabled (void)
|
|
|
|
{
|
2010-05-26 10:33:32 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
return ctx->legacy_depth_test_enabled;
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 15:55:11 +00:00
|
|
|
cogl_set_backface_culling_enabled (gboolean setting)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-09-15 10:25:39 +00:00
|
|
|
if (ctx->legacy_backface_culling_enabled == setting)
|
2009-10-22 18:09:20 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-15 10:25:39 +00:00
|
|
|
ctx->legacy_backface_culling_enabled = setting;
|
[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 17:46:42 +00:00
|
|
|
|
2011-09-15 10:25:39 +00:00
|
|
|
if (ctx->legacy_backface_culling_enabled)
|
|
|
|
ctx->legacy_state_set++;
|
|
|
|
else
|
|
|
|
ctx->legacy_state_set--;
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 15:55:11 +00:00
|
|
|
gboolean
|
|
|
|
cogl_get_backface_culling_enabled (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2011-09-15 10:25:39 +00:00
|
|
|
return ctx->legacy_backface_culling_enabled;
|
2009-10-22 18:01:52 +00:00
|
|
|
}
|
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
void
|
|
|
|
cogl_set_source_color (const CoglColor *color)
|
|
|
|
{
|
2010-11-01 20:27:32 +00:00
|
|
|
CoglPipeline *pipeline;
|
2009-05-09 18:39:01 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-11-01 20:27:32 +00: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 18:39:01 +00:00
|
|
|
|
2010-11-01 20:27:32 +00:00
|
|
|
cogl_set_source (pipeline);
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-03 13:26:58 +00:00
|
|
|
cogl_set_viewport (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
2010-05-27 23:35:47 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 13:34:34 +00:00
|
|
|
|
2009-07-01 11:57:30 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-03-10 21:33:31 +00:00
|
|
|
framebuffer = cogl_get_draw_framebuffer ();
|
2009-07-01 11:57:30 +00:00
|
|
|
|
2011-06-14 23:06:29 +00:00
|
|
|
cogl_framebuffer_set_viewport (framebuffer,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height);
|
2009-09-25 13:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-10 01:57:32 +00:00
|
|
|
cogl_viewport (unsigned int width,
|
|
|
|
unsigned int height)
|
2009-09-25 13:34:34 +00:00
|
|
|
{
|
2009-11-03 13:26:58 +00:00
|
|
|
cogl_set_viewport (0, 0, width, height);
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglFeatureFlags
|
2009-05-28 12:03:19 +00:00
|
|
|
cogl_get_features (void)
|
2009-03-30 16:07:31 +00: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-09-25 13:34:34 +00:00
|
|
|
/* XXX: This function should either be replaced with one returning
|
|
|
|
* integers, or removed/deprecated and make the
|
2009-11-26 19:06:35 +00:00
|
|
|
* _cogl_framebuffer_get_viewport* functions public.
|
2009-09-25 13:34:34 +00:00
|
|
|
*/
|
2009-03-30 16:07:31 +00:00
|
|
|
void
|
2011-02-01 16:51:58 +00:00
|
|
|
cogl_get_viewport (float viewport[4])
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
2010-05-27 23:35:47 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 13:34:34 +00:00
|
|
|
|
2009-07-01 11:57:30 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2009-03-30 16:07:31 +00:00
|
|
|
|
2011-03-10 21:33:31 +00:00
|
|
|
framebuffer = cogl_get_draw_framebuffer ();
|
2011-06-14 23:06:29 +00:00
|
|
|
cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
2009-03-30 16:07:31 +00: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-10 01:57:32 +00:00
|
|
|
cogl_get_bitmasks (int *red,
|
|
|
|
int *green,
|
|
|
|
int *blue,
|
|
|
|
int *alpha)
|
2009-03-30 16:07:31 +00:00
|
|
|
{
|
2010-07-07 13:41:54 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
2010-04-26 17:08:45 +00:00
|
|
|
|
2011-03-10 21:33:31 +00:00
|
|
|
framebuffer = cogl_get_draw_framebuffer ();
|
2009-05-19 13:44:29 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
if (red)
|
2011-06-30 21:50:48 +00:00
|
|
|
*red = cogl_framebuffer_get_red_bits (framebuffer);
|
2009-05-19 13:44:29 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
if (green)
|
2011-06-30 21:50:48 +00:00
|
|
|
*green = cogl_framebuffer_get_green_bits (framebuffer);
|
2009-05-19 13:44:29 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
if (blue)
|
2011-06-30 21:50:48 +00:00
|
|
|
*blue = cogl_framebuffer_get_blue_bits (framebuffer);
|
2009-05-19 13:44:29 +00:00
|
|
|
|
2009-03-30 16:07:31 +00:00
|
|
|
if (alpha)
|
2011-06-30 21:50:48 +00:00
|
|
|
*alpha = cogl_framebuffer_get_alpha_bits (framebuffer);
|
2009-03-30 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_fog (const CoglColor *fog_color,
|
|
|
|
CoglFogMode mode,
|
|
|
|
float density,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
2010-04-26 09:01:43 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-07-06 19:18:26 +00:00
|
|
|
if (ctx->legacy_fog_state.enabled == FALSE)
|
|
|
|
ctx->legacy_state_set++;
|
2010-04-26 09:01:43 +00:00
|
|
|
|
2010-07-06 19:18:26 +00: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 16:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_disable_fog (void)
|
|
|
|
{
|
2010-04-26 09:01:43 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-07-06 19:18:26 +00: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 17:46:42 +00:00
|
|
|
|
2010-07-06 19:18:26 +00:00
|
|
|
ctx->legacy_fog_state.enabled = FALSE;
|
2009-03-30 16:07:31 +00: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 17:46:42 +00:00
|
|
|
void
|
2009-06-29 16:10:34 +00: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 17:46:42 +00:00
|
|
|
{
|
2011-01-06 13:25:45 +00:00
|
|
|
GList *l;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
for (l = ctx->framebuffers; l; l = l->next)
|
|
|
|
_cogl_framebuffer_flush_journal (l->data);
|
[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 17:46:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 13:30:44 +00:00
|
|
|
void
|
2010-11-17 15:38:20 +00: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 13:30:44 +00:00
|
|
|
{
|
2011-03-10 21:33:31 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_read_framebuffer ();
|
2010-07-07 17:44:16 +00:00
|
|
|
int framebuffer_height;
|
|
|
|
int bpp;
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
CoglPixelFormat bmp_format;
|
2011-07-13 17:28:49 +00:00
|
|
|
gboolean pack_invert_set;
|
2009-09-25 13:34:34 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2009-06-17 13:30:44 +00:00
|
|
|
|
|
|
|
g_return_if_fail (source == COGL_READ_PIXELS_COLOR_BUFFER);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
if (width == 1 && height == 1 && !framebuffer->clear_clip_dirty)
|
|
|
|
{
|
|
|
|
/* If everything drawn so far for this frame is still in the
|
|
|
|
* Journal then if all of the rectangles only have a flat
|
|
|
|
* opaque color we have a fast-path for reading a single pixel
|
|
|
|
* that avoids the relatively high cost of flushing primitives
|
|
|
|
* to be drawn on the GPU (considering how simple the geometry
|
|
|
|
* is in this case) and then blocking on the long GPU pipelines
|
|
|
|
* for the result.
|
|
|
|
*/
|
|
|
|
if (_cogl_framebuffer_try_fast_read_pixel (framebuffer,
|
|
|
|
x, y, source, format,
|
|
|
|
pixels))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
/* make sure any batched primitives get emitted to the GL driver
|
|
|
|
* before issuing our read pixels...
|
|
|
|
*
|
|
|
|
* XXX: Note we currently use cogl_flush to ensure *all* journals
|
|
|
|
* are flushed here and not _cogl_journal_flush because we don't
|
|
|
|
* track the dependencies between framebuffers so we don't know if
|
|
|
|
* the current framebuffer depends on the contents of other
|
|
|
|
* framebuffers which could also have associated journal entries.
|
|
|
|
*/
|
2009-11-26 19:06:35 +00:00
|
|
|
cogl_flush ();
|
|
|
|
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_flush_state (cogl_get_draw_framebuffer (),
|
2011-02-02 14:23:53 +00:00
|
|
|
framebuffer,
|
|
|
|
0);
|
2009-11-02 01:10:02 +00:00
|
|
|
|
2011-03-01 23:12:18 +00:00
|
|
|
framebuffer_height = cogl_framebuffer_get_height (framebuffer);
|
2009-06-17 13:30:44 +00:00
|
|
|
|
|
|
|
/* The y co-ordinate should be given in OpenGL's coordinate system
|
2009-11-02 01:12:10 +00: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 19:06:35 +00:00
|
|
|
if (!cogl_is_offscreen (framebuffer))
|
|
|
|
y = framebuffer_height - y - height;
|
2009-11-02 01:11:21 +00:00
|
|
|
|
2010-03-01 18:08:41 +00:00
|
|
|
/* Initialise the CoglBitmap */
|
|
|
|
bpp = _cogl_get_format_bpp (format);
|
2010-07-07 17:44:16 +00:00
|
|
|
bmp_format = format;
|
2010-03-01 18:08:41 +00:00
|
|
|
|
|
|
|
if ((format & COGL_A_BIT))
|
|
|
|
{
|
2010-11-17 17:57:17 +00: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 18:08:41 +00:00
|
|
|
}
|
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
bmp = _cogl_bitmap_new_from_data (pixels,
|
|
|
|
bmp_format, width, height, rowstride,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
ctx->texture_driver->pixel_format_to_gl (format,
|
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2010-03-01 18:08:41 +00:00
|
|
|
|
2011-07-13 17:28:49 +00:00
|
|
|
/* NB: All offscreen rendering is done upside down so there is no need
|
|
|
|
* to flip in this case... */
|
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_MESA_PACK_INVERT) &&
|
|
|
|
!cogl_is_offscreen (framebuffer))
|
|
|
|
{
|
|
|
|
GE (ctx, glPixelStorei (GL_PACK_INVERT_MESA, TRUE));
|
|
|
|
pack_invert_set = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pack_invert_set = FALSE;
|
|
|
|
|
2010-03-26 22:40:53 +00: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 15:38:20 +00: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 */
|
2011-07-07 19:44:56 +00:00
|
|
|
if (ctx->driver != COGL_DRIVER_GL &&
|
|
|
|
(gl_format != GL_RGBA || gl_type != GL_UNSIGNED_BYTE ||
|
|
|
|
rowstride != 4 * width))
|
2010-03-26 22:40:53 +00:00
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
CoglBitmap *tmp_bmp, *dst_bmp;
|
|
|
|
guint8 *tmp_data = g_malloc (width * height * 4);
|
2010-03-26 22:40:53 +00:00
|
|
|
|
2010-07-07 17:44:16 +00:00
|
|
|
tmp_bmp = _cogl_bitmap_new_from_data (tmp_data,
|
2010-11-17 17:57:17 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888 |
|
|
|
|
(bmp_format & COGL_PREMULT_BIT),
|
2010-07-07 17:44:16 +00:00
|
|
|
width, height, 4 * width,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2010-03-26 22:40:53 +00:00
|
|
|
|
2011-07-07 11:48:24 +00:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (4 * width, 4);
|
2010-03-26 22:40:53 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glReadPixels (x, y, width, height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
tmp_data) );
|
2010-03-26 22:40:53 +00: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 17:44:16 +00:00
|
|
|
if ((dst_bmp = _cogl_bitmap_convert_format_and_premult (tmp_bmp,
|
2010-11-17 17:45:27 +00:00
|
|
|
format)))
|
2010-03-26 22:40:53 +00:00
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
_cogl_bitmap_copy_subregion (dst_bmp,
|
|
|
|
bmp,
|
2010-03-26 22:40:53 +00:00
|
|
|
0, 0,
|
|
|
|
0, 0,
|
2010-07-07 17:44:16 +00:00
|
|
|
width, height);
|
|
|
|
cogl_object_unref (dst_bmp);
|
2010-03-26 22:40:53 +00: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 17:44:16 +00:00
|
|
|
cogl_object_unref (tmp_bmp);
|
2010-03-26 22:40:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-07 11:48:24 +00:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
2010-03-26 22:40:53 +00:00
|
|
|
|
2011-07-06 20:51:00 +00:00
|
|
|
GE( ctx, glReadPixels (x, y, width, height, gl_format, gl_type, pixels) );
|
2010-03-01 18:08:41 +00:00
|
|
|
|
2010-03-26 22:40:53 +00: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 17:44:16 +00:00
|
|
|
_cogl_bitmap_convert_premult_status (bmp, format);
|
2010-03-26 22:40:53 +00:00
|
|
|
}
|
2009-06-17 13:30:44 +00:00
|
|
|
|
2011-07-13 17:28:49 +00:00
|
|
|
/* Currently this function owns the pack_invert state and we don't want this
|
|
|
|
* to interfere with other Cogl components so all other code can assume that
|
|
|
|
* we leave the pack_invert state off. */
|
|
|
|
if (pack_invert_set)
|
|
|
|
GE (ctx, glPixelStorei (GL_PACK_INVERT_MESA, FALSE));
|
|
|
|
|
2009-10-22 15:55:07 +00:00
|
|
|
/* NB: All offscreen rendering is done upside down so there is no need
|
|
|
|
* to flip in this case... */
|
2011-07-13 17:28:49 +00:00
|
|
|
if (!cogl_is_offscreen (framebuffer) && !pack_invert_set)
|
2010-03-01 18:08:41 +00:00
|
|
|
{
|
2010-07-07 17:44:16 +00:00
|
|
|
guint8 *temprow = g_alloca (rowstride * sizeof (guint8));
|
2009-10-22 15:55:07 +00:00
|
|
|
|
2010-03-01 18:08:41 +00:00
|
|
|
/* vertically flip the buffer in-place */
|
|
|
|
for (y = 0; y < height / 2; y++)
|
2009-06-17 13:30:44 +00:00
|
|
|
{
|
2010-03-01 18:08:41 +00:00
|
|
|
if (y != height - y - 1) /* skip center row */
|
|
|
|
{
|
|
|
|
memcpy (temprow,
|
2010-07-07 17:44:16 +00:00
|
|
|
pixels + y * rowstride, rowstride);
|
|
|
|
memcpy (pixels + y * rowstride,
|
|
|
|
pixels + (height - y - 1) * rowstride, rowstride);
|
|
|
|
memcpy (pixels + (height - y - 1) * rowstride,
|
2010-03-01 18:08:41 +00:00
|
|
|
temprow,
|
2010-07-07 17:44:16 +00:00
|
|
|
rowstride);
|
2010-03-01 18:08:41 +00:00
|
|
|
}
|
2009-06-17 13:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-07 17:44:16 +00:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
2009-06-17 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 15:38:20 +00: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 21:32:05 +00: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-10 01:57:32 +00:00
|
|
|
unsigned long enable_flags = 0;
|
2010-07-23 16:46:41 +00:00
|
|
|
CoglPipeline *pipeline;
|
2009-06-29 21:32:05 +00: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 13:34:34 +00:00
|
|
|
/* Flush framebuffer state, including clip state, modelview and
|
|
|
|
* projection matrix state
|
|
|
|
*
|
2009-11-26 19:06:35 +00:00
|
|
|
* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
2010-10-27 17:54:57 +00:00
|
|
|
* as the pipeline state) when flushing the clip stack, so should
|
2009-09-25 13:34:34 +00:00
|
|
|
* always be done first when preparing to draw. */
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_flush_state (cogl_get_draw_framebuffer (),
|
|
|
|
_cogl_get_read_framebuffer (),
|
2011-02-02 14:23:53 +00:00
|
|
|
0);
|
2009-06-29 21:32:05 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
/* Setup the state for the current pipeline */
|
2009-06-29 21:32:05 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
/* We considered flushing a specific, minimal pipeline here to try and
|
2009-06-29 21:32:05 +00: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 16:46:41 +00:00
|
|
|
*
|
2010-12-02 21:08:30 +00: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 16:46:41 +00: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 21:32:05 +00:00
|
|
|
*/
|
2010-07-23 16:46:41 +00:00
|
|
|
pipeline = cogl_get_source ();
|
2010-12-02 21:08:30 +00:00
|
|
|
_cogl_pipeline_flush_gl_state (pipeline,
|
|
|
|
FALSE,
|
|
|
|
cogl_pipeline_get_n_layers (pipeline));
|
2009-06-29 21:32:05 +00:00
|
|
|
|
2010-03-19 09:16:08 +00:00
|
|
|
_cogl_enable (enable_flags);
|
2009-06-29 21:32:05 +00:00
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
/* Disable any cached vertex arrays */
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_attribute_disable_cached_arrays ();
|
2009-06-29 21:32:05 +00: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 22:09:42 +00:00
|
|
|
void
|
|
|
|
cogl_push_matrix (void)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pop_matrix (void)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_scale (float x, float y, float z)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_scale (modelview_stack, x, y, z);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translate (float x, float y, float z)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_translate (modelview_stack, x, y, z);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotate (float angle, float x, float y, float z)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_rotate (modelview_stack, angle, x, y, z);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 09:30:59 +00:00
|
|
|
void
|
2010-04-08 13:37:01 +00:00
|
|
|
cogl_transform (const CoglMatrix *matrix)
|
2010-03-19 09:30:59 +00:00
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2010-03-19 09:30:59 +00:00
|
|
|
_cogl_matrix_stack_multiply (modelview_stack, matrix);
|
|
|
|
}
|
|
|
|
|
2009-10-13 22:09:42 +00: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 13:34:34 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (cogl_get_draw_framebuffer ());
|
2009-10-13 22:09:42 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-08-01 19:50:47 +00:00
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
cogl_flush ();
|
|
|
|
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_load_identity (projection_stack);
|
2009-10-13 22:09:42 +00:00
|
|
|
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_frustum (projection_stack,
|
2009-10-13 22:09:42 +00: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 13:34:34 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (cogl_get_draw_framebuffer ());
|
2009-10-13 22:09:42 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-08-01 19:50:47 +00:00
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
cogl_flush ();
|
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
cogl_matrix_init_identity (&ortho);
|
|
|
|
cogl_matrix_ortho (&ortho, left, right, bottom, top, z_near, z_far);
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_set (projection_stack, &ortho);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_get (modelview_stack, matrix);
|
2009-10-26 11:01:33 +00:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_set (modelview_stack, matrix);
|
2009-10-26 11:01:33 +00:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (cogl_get_draw_framebuffer ());
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_get (projection_stack, matrix);
|
2009-10-26 11:01:33 +00:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2011-03-10 21:33:31 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (cogl_get_draw_framebuffer ());
|
2011-08-01 19:50:47 +00:00
|
|
|
|
|
|
|
/* XXX: The projection matrix isn't currently tracked in the journal
|
|
|
|
* so we need to flush all journaled primitives first... */
|
|
|
|
cogl_flush ();
|
|
|
|
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_matrix_stack_set (projection_stack, matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
|
2009-10-26 11:01:33 +00:00
|
|
|
_COGL_MATRIX_DEBUG_PRINT (matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
CoglClipState *
|
2009-09-25 13:34:34 +00:00
|
|
|
_cogl_get_clip_state (void)
|
2009-10-13 22:09:42 +00:00
|
|
|
{
|
2010-05-27 23:35:47 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
2009-09-25 13:34:34 +00:00
|
|
|
|
2011-03-10 21:33:31 +00:00
|
|
|
framebuffer = cogl_get_draw_framebuffer ();
|
2009-11-26 19:06:35 +00:00
|
|
|
return _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-11 13:26:54 +00:00
|
|
|
GQuark
|
|
|
|
_cogl_driver_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-driver-error-quark");
|
|
|
|
}
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
typedef struct _CoglSourceState
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline;
|
2010-10-25 12:25:21 +00:00
|
|
|
int push_count;
|
2011-09-14 11:17:09 +00:00
|
|
|
/* If this is TRUE then the pipeline will be copied and the legacy
|
|
|
|
state will be applied whenever the pipeline is used. This is
|
|
|
|
necessary because some internal Cogl code expects to be able to
|
|
|
|
push a temporary pipeline to put GL into a known state. For that
|
|
|
|
to work it also needs to prevent applying the legacy state */
|
|
|
|
gboolean enable_legacy;
|
2010-10-25 12:25:21 +00:00
|
|
|
} CoglSourceState;
|
|
|
|
|
|
|
|
static void
|
2011-09-14 11:17:09 +00:00
|
|
|
_push_source_real (CoglPipeline *pipeline, gboolean enable_legacy)
|
2010-10-25 12:25:21 +00:00
|
|
|
{
|
|
|
|
CoglSourceState *top = g_slice_new (CoglSourceState);
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
top->pipeline = cogl_object_ref (pipeline);
|
2011-09-14 11:17:09 +00:00
|
|
|
top->enable_legacy = enable_legacy;
|
2010-10-25 12:25:21 +00: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 17:54:57 +00:00
|
|
|
* pipeline, but this would not by symmetric with cogl_pop_source. */
|
2010-03-19 09:55:30 +00:00
|
|
|
void
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_push_source (void *material_or_pipeline)
|
2010-03-19 09:55:30 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline = COGL_PIPELINE (material_or_pipeline);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
2011-09-14 11:17:09 +00:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
|
|
|
|
|
|
|
_cogl_push_source (pipeline, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This internal version of cogl_push_source is the same except it
|
|
|
|
never applies the legacy state. Some parts of Cogl use this
|
|
|
|
internally to set a temporary pipeline with a known state */
|
|
|
|
void
|
|
|
|
_cogl_push_source (CoglPipeline *pipeline, gboolean enable_legacy)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
|
|
|
|
2010-03-19 09:55:30 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
if (ctx->source_stack)
|
|
|
|
{
|
|
|
|
top = ctx->source_stack->data;
|
2011-09-14 11:17:09 +00:00
|
|
|
if (top->pipeline == pipeline && top->enable_legacy == enable_legacy)
|
2010-10-25 12:25:21 +00:00
|
|
|
{
|
|
|
|
top->push_count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2011-09-14 11:17:09 +00:00
|
|
|
_push_source_real (pipeline, enable_legacy);
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-14 11:17:09 +00:00
|
|
|
_push_source_real (pipeline, enable_legacy);
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
/* FIXME: This needs to take a context pointer for Cogl 2.0 */
|
|
|
|
void
|
|
|
|
cogl_pop_source (void)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
g_return_if_fail (ctx->source_stack);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
|
|
|
top->push_count--;
|
|
|
|
if (top->push_count == 0)
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_object_unref (top->pipeline);
|
2010-10-25 12:25:21 +00: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 17:54:57 +00:00
|
|
|
void *
|
2010-10-25 12:25:21 +00: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 17:54:57 +00:00
|
|
|
return top->pipeline;
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 11:17:09 +00:00
|
|
|
gboolean
|
|
|
|
_cogl_get_enable_legacy_state (void)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
g_return_val_if_fail (ctx->source_stack, FALSE);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
|
|
|
return top->enable_legacy;
|
|
|
|
}
|
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
void
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_set_source (void *material_or_pipeline)
|
2010-10-25 12:25:21 +00:00
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline = COGL_PIPELINE (material_or_pipeline);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
g_return_if_fail (cogl_is_pipeline (pipeline));
|
2010-10-25 12:25:21 +00:00
|
|
|
g_return_if_fail (ctx->source_stack);
|
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
2011-09-14 11:17:09 +00:00
|
|
|
if (top->pipeline == pipeline && top->enable_legacy)
|
2010-10-25 12:25:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (top->push_count == 1)
|
|
|
|
{
|
2010-10-27 17:54:57 +00: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;
|
2011-09-14 11:17:09 +00:00
|
|
|
top->enable_legacy = TRUE;
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top->push_count--;
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_push_source (pipeline);
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
2010-03-19 09:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-24 20:30:34 +00:00
|
|
|
cogl_set_source_texture (CoglTexture *texture)
|
2010-03-19 09:55:30 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-08-24 20:30:34 +00:00
|
|
|
g_return_if_fail (texture != NULL);
|
2010-03-19 09:55:30 +00:00
|
|
|
|
2011-08-24 20:30:34 +00:00
|
|
|
cogl_pipeline_set_layer_texture (ctx->texture_pipeline, 0, texture);
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_set_source (ctx->texture_pipeline);
|
2010-03-19 09:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_source_color4ub (guint8 red,
|
|
|
|
guint8 green,
|
|
|
|
guint8 blue,
|
|
|
|
guint8 alpha)
|
|
|
|
{
|
|
|
|
CoglColor c = { 0, };
|
|
|
|
|
2010-09-03 15:55:12 +00:00
|
|
|
cogl_color_init_from_4ub (&c, red, green, blue, alpha);
|
2010-03-19 09:55:30 +00: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 15:55:12 +00:00
|
|
|
cogl_color_init_from_4f (&c, red, green, blue, alpha);
|
2010-03-19 09:55:30 +00:00
|
|
|
cogl_set_source_color (&c);
|
|
|
|
}
|
|
|
|
|
2010-04-22 12:48:49 +00: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 10:33:32 +00:00
|
|
|
|
|
|
|
GQuark
|
|
|
|
_cogl_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-error-quark");
|
|
|
|
}
|
2011-06-14 21:33:44 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_init (void)
|
|
|
|
{
|
|
|
|
static gsize init_status = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&init_status))
|
|
|
|
{
|
2011-09-10 08:51:42 +00:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, COGL_LOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
|
2011-06-14 21:33:44 +00:00
|
|
|
g_type_init ();
|
|
|
|
|
2011-08-03 17:15:54 +00:00
|
|
|
_cogl_config_read ();
|
2011-06-14 21:33:44 +00:00
|
|
|
_cogl_debug_check_environment ();
|
|
|
|
g_once_init_leave (&init_status, 1);
|
|
|
|
}
|
|
|
|
}
|