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
|
|
|
*/
|
|
|
|
|
2013-03-22 21:18:53 +00:00
|
|
|
#include <config.h>
|
2009-03-30 16:07:31 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-03-22 21:18:53 +00:00
|
|
|
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_4
|
|
|
|
|
2013-04-28 01:42:24 +00:00
|
|
|
#include "cogl-i18n-private.h"
|
2009-05-19 13:44:29 +00:00
|
|
|
#include "cogl-debug.h"
|
2009-03-30 16:07:31 +00:00
|
|
|
#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"
|
2012-02-17 21:46:39 +00:00
|
|
|
#include "cogl1-context.h"
|
2012-02-18 01:19:17 +00:00
|
|
|
#include "cogl-offscreen.h"
|
2012-09-19 21:32:25 +00:00
|
|
|
#include "cogl-attribute-gl-private.h"
|
2012-09-26 19:32:36 +00:00
|
|
|
#include "cogl-clutter.h"
|
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);
|
|
|
|
|
2012-06-20 11:42:31 +00:00
|
|
|
return _cogl_renderer_get_proc_address (ctx->display->renderer, name, FALSE);
|
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
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2012-09-26 19:32:36 +00:00
|
|
|
_cogl_check_extension (const char *name, char * const *ext)
|
2010-02-05 16:32:19 +00:00
|
|
|
{
|
2012-09-26 19:32:36 +00:00
|
|
|
while (*ext)
|
|
|
|
if (!strcmp (name, *ext))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
ext++;
|
2010-02-05 16:32:19 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: This has been deprecated as public API */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2010-02-05 16:32:19 +00:00
|
|
|
cogl_check_extension (const char *name, const char *ext)
|
|
|
|
{
|
2012-09-26 19:32:36 +00:00
|
|
|
return cogl_clutter_check_extension (name, ext);
|
2010-02-05 16:32:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-26 10:33:32 +00:00
|
|
|
/* XXX: This API has been deprecated */
|
2009-03-30 16:07:31 +00:00
|
|
|
void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
cogl_set_depth_test_enabled (CoglBool 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 */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2009-05-26 15:55:11 +00:00
|
|
|
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
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
cogl_set_backface_culling_enabled (CoglBool 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
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2009-05-26 15:55:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2009-03-30 16:07:31 +00:00
|
|
|
cogl_features_available (CoglFeatureFlags features)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return (ctx->feature_flags & features) == features;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2011-10-12 21:31:12 +00:00
|
|
|
cogl_has_feature (CoglContext *ctx, CoglFeatureID feature)
|
|
|
|
{
|
|
|
|
return COGL_FLAGS_GET (ctx->features, feature);
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2011-10-12 21:31:12 +00:00
|
|
|
cogl_has_features (CoglContext *ctx, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
CoglFeatureID feature;
|
|
|
|
|
|
|
|
va_start (args, ctx);
|
|
|
|
while ((feature = va_arg (args, CoglFeatureID)))
|
|
|
|
if (!cogl_has_feature (ctx, feature))
|
|
|
|
return FALSE;
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_foreach_feature (CoglContext *ctx,
|
|
|
|
CoglFeatureCallback callback,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < _COGL_N_FEATURE_IDS; i++)
|
|
|
|
if (COGL_FLAGS_GET (ctx->features, i))
|
|
|
|
callback (i, user_data);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-11-17 15:38:20 +00:00
|
|
|
void
|
|
|
|
cogl_read_pixels (int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglReadPixelsFlags source,
|
|
|
|
CoglPixelFormat format,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *pixels)
|
2010-11-17 15:38:20 +00:00
|
|
|
{
|
2012-02-13 23:02:04 +00:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2012-02-25 19:23:51 +00:00
|
|
|
CoglBitmap *bitmap;
|
|
|
|
|
2012-03-13 14:46:18 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
bitmap = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
bpp * width, /* rowstride */
|
|
|
|
pixels);
|
2012-02-25 19:23:51 +00:00
|
|
|
cogl_framebuffer_read_pixels_into_bitmap (_cogl_get_read_framebuffer (),
|
|
|
|
x, y,
|
|
|
|
source,
|
|
|
|
bitmap);
|
|
|
|
cogl_object_unref (bitmap);
|
2010-11-17 15:38:20 +00:00
|
|
|
}
|
|
|
|
|
2009-06-29 21:32:05 +00:00
|
|
|
void
|
|
|
|
cogl_begin_gl (void)
|
|
|
|
{
|
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)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool shown = FALSE;
|
2009-06-29 21:32:05 +00:00
|
|
|
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-11-21 15:53:40 +00:00
|
|
|
COGL_FRAMEBUFFER_STATE_ALL);
|
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,
|
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate
operation such as rotating, scaling, translating and multiplying as
immutable, ref-counted nodes in a graph.
Being a "graph" here means that different transformations composed of
a sequence of linked operation nodes may share nodes.
The first node in a matrix-stack is always a LOAD_IDENTITY operation.
As an example consider if an application where to draw three rectangles
A, B and C something like this:
cogl_framebuffer_scale (fb, 2, 2, 2);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_translate (fb, 10, 0, 0);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_rotate (fb, 45, 0, 0, 1);
cogl_framebuffer_draw_rectangle (...); /* A */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_draw_rectangle (...); /* B */
cogl_framebuffer_pop_matrix(fb);
cogl_framebuffer_push_matrix(fb);
cogl_framebuffer_set_modelview_matrix (fb, &mv);
cogl_framebuffer_draw_rectangle (...); /* C */
cogl_framebuffer_pop_matrix(fb);
That would result in a graph of nodes like this:
LOAD_IDENTITY
|
SCALE
/ \
SAVE LOAD
| |
TRANSLATE RECTANGLE(C)
| \
SAVE RECTANGLE(B)
|
ROTATE
|
RECTANGLE(A)
Each push adds a SAVE operation which serves as a marker to rewind too
when a corresponding pop is issued and also each SAVE node may also
store a cached matrix representing the composition of all its ancestor
nodes. This means if we repeatedly need to resolve a real CoglMatrix
for a given node then we don't need to repeat the composition.
Some advantages of this design are:
- A single pointer to any node in the graph can now represent a
complete, immutable transformation that can be logged for example
into a journal. Previously we were storing a full CoglMatrix in
each journal entry which is 16 floats for the matrix itself as well
as space for flags and another 16 floats for possibly storing a
cache of the inverse. This means that we significantly reduce
the size of the journal when drawing lots of primitives and we also
avoid copying over 128 bytes per entry.
- It becomes much cheaper to check for equality. In cases where some
(unlikely) false negatives are allowed simply comparing the pointers
of two matrix stack graph entries is enough. Previously we would use
memcmp() to compare matrices.
- It becomes easier to do comparisons of transformations. By looking
for the common ancestry between nodes we can determine the operations
that differentiate the transforms and use those to gain a high level
understanding of the differences. For example we use this in the
journal to be able to efficiently determine when two rectangle
transforms only differ by some translation so that we can perform
software clipping.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
2012-02-20 15:59:48 +00:00
|
|
|
cogl_get_draw_framebuffer (),
|
2012-09-27 10:06:16 +00:00
|
|
|
FALSE);
|
2009-06-29 21:32:05 +00:00
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
/* Disable any cached vertex arrays */
|
2012-09-19 21:32:25 +00:00
|
|
|
_cogl_gl_disable_all_attributes (ctx);
|
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)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool shown = FALSE;
|
2009-06-29 21:32:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_push_matrix (cogl_get_draw_framebuffer ());
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pop_matrix (void)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_pop_matrix (cogl_get_draw_framebuffer ());
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_scale (float x, float y, float z)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_scale (cogl_get_draw_framebuffer (), x, y, z);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translate (float x, float y, float z)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_translate (cogl_get_draw_framebuffer (), x, y, z);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotate (float angle, float x, float y, float z)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_rotate (cogl_get_draw_framebuffer (), 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
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_transform (cogl_get_draw_framebuffer (), matrix);
|
2010-03-19 09:30:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
void
|
|
|
|
cogl_perspective (float fov_y,
|
|
|
|
float aspect,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_perspective (cogl_get_draw_framebuffer (),
|
|
|
|
fov_y, aspect, z_near, z_far);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_frustum (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_frustum (cogl_get_draw_framebuffer (),
|
|
|
|
left, right, bottom, top, z_near, z_far);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_ortho (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
2011-11-18 12:23:49 +00:00
|
|
|
float near,
|
|
|
|
float far)
|
2009-10-13 22:09:42 +00:00
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_orthographic (cogl_get_draw_framebuffer (),
|
|
|
|
left, top, right, bottom, near, far);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_get_modelview_matrix (cogl_get_draw_framebuffer (), matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_set_modelview_matrix (cogl_get_draw_framebuffer (), matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_get_projection_matrix (cogl_get_draw_framebuffer (), matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
2011-11-18 12:23:49 +00:00
|
|
|
cogl_framebuffer_set_projection_matrix (cogl_get_draw_framebuffer (), matrix);
|
2009-10-13 22:09:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-31 18:28:27 +00:00
|
|
|
uint32_t
|
2009-11-11 13:26:54 +00:00
|
|
|
_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 */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool enable_legacy;
|
2010-10-25 12:25:21 +00:00
|
|
|
} CoglSourceState;
|
|
|
|
|
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_push_source_real (CoglPipeline *pipeline, CoglBool 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-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
2011-09-14 11:17:09 +00:00
|
|
|
|
|
|
|
_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
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_push_source (CoglPipeline *pipeline, CoglBool enable_legacy)
|
2011-09-14 11:17:09 +00:00
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
|
|
|
|
2010-03-19 09:55:30 +00:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_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
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->source_stack);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (ctx->source_stack, NULL);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
|
|
|
top = ctx->source_stack->data;
|
2010-10-27 17:54:57 +00:00
|
|
|
return top->pipeline;
|
2010-10-25 12:25:21 +00:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2011-09-14 11:17:09 +00:00
|
|
|
_cogl_get_enable_legacy_state (void)
|
|
|
|
{
|
|
|
|
CoglSourceState *top;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (ctx->source_stack, FALSE);
|
2011-09-14 11:17:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_pipeline (pipeline));
|
|
|
|
_COGL_RETURN_IF_FAIL (ctx->source_stack);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
|
|
|
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-10-13 21:34:30 +00:00
|
|
|
_COGL_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
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
cogl_set_source_color4ub (uint8_t red,
|
|
|
|
uint8_t green,
|
|
|
|
uint8_t blue,
|
|
|
|
uint8_t alpha)
|
2010-03-19 09:55:30 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-08-31 18:28:27 +00:00
|
|
|
uint32_t
|
|
|
|
_cogl_system_error_quark (void)
|
2010-05-26 10:33:32 +00:00
|
|
|
{
|
2012-08-31 18:28:27 +00:00
|
|
|
return g_quark_from_static_string ("cogl-system-error-quark");
|
2010-05-26 10:33:32 +00:00
|
|
|
}
|
2011-06-14 21:33:44 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_init (void)
|
|
|
|
{
|
2012-09-12 22:47:17 +00:00
|
|
|
static CoglBool initialized = FALSE;
|
2011-06-14 21:33:44 +00:00
|
|
|
|
2012-09-12 22:47:17 +00:00
|
|
|
if (initialized == FALSE)
|
2011-06-14 21:33:44 +00:00
|
|
|
{
|
2013-04-28 01:42:24 +00:00
|
|
|
#ifdef ENABLE_NLS
|
2011-09-10 08:51:42 +00:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, COGL_LOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
2013-04-28 01:42:24 +00:00
|
|
|
#endif
|
2011-09-10 08:51:42 +00:00
|
|
|
|
2012-09-15 13:39:29 +00:00
|
|
|
#ifdef COGL_HAS_GTYPE_SUPPORT
|
2011-06-14 21:33:44 +00:00
|
|
|
g_type_init ();
|
2012-09-15 13:39:29 +00:00
|
|
|
#endif
|
2011-06-14 21:33:44 +00:00
|
|
|
|
2011-08-03 17:15:54 +00:00
|
|
|
_cogl_config_read ();
|
2011-06-14 21:33:44 +00:00
|
|
|
_cogl_debug_check_environment ();
|
2012-09-12 22:47:17 +00:00
|
|
|
initialized = TRUE;
|
2011-06-14 21:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-13 23:02:04 +00:00
|
|
|
|
2011-11-21 23:39:49 +00:00
|
|
|
/*
|
|
|
|
* Returns the number of bytes-per-pixel of a given format. The bpp
|
|
|
|
* can be extracted from the least significant nibble of the pixel
|
|
|
|
* format (see CoglPixelFormat).
|
|
|
|
*
|
|
|
|
* The mapping is the following (see discussion on bug #660188):
|
|
|
|
*
|
|
|
|
* 0 = undefined
|
|
|
|
* 1, 8 = 1 bpp (e.g. A_8, G_8)
|
|
|
|
* 2 = 3 bpp, aligned (e.g. 888)
|
|
|
|
* 3 = 4 bpp, aligned (e.g. 8888)
|
|
|
|
* 4-6 = 2 bpp, not aligned (e.g. 565, 4444, 5551)
|
|
|
|
* 7 = undefined yuv
|
|
|
|
* 9 = 2 bpp, aligned
|
|
|
|
* 10 = undefined
|
|
|
|
* 11 = undefined
|
|
|
|
* 12 = 3 bpp, not aligned
|
|
|
|
* 13 = 4 bpp, not aligned (e.g. 2101010)
|
|
|
|
* 14-15 = undefined
|
|
|
|
*/
|
2012-02-13 23:02:04 +00:00
|
|
|
int
|
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (CoglPixelFormat format)
|
|
|
|
{
|
2011-11-21 23:39:49 +00:00
|
|
|
int bpp_lut[] = { 0, 1, 3, 4,
|
|
|
|
2, 2, 2, 0,
|
|
|
|
1, 2, 0, 0,
|
|
|
|
3, 4, 0, 0 };
|
2012-02-13 23:02:04 +00:00
|
|
|
|
|
|
|
return bpp_lut [format & 0xf];
|
|
|
|
}
|
2012-02-13 23:28:28 +00:00
|
|
|
|
|
|
|
/* Note: this also refers to the mapping defined above for
|
|
|
|
* _cogl_pixel_format_get_bytes_per_pixel() */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2012-02-13 23:28:28 +00:00
|
|
|
_cogl_pixel_format_is_endian_dependant (CoglPixelFormat format)
|
|
|
|
{
|
|
|
|
int aligned_lut[] = { -1, 1, 1, 1,
|
|
|
|
0, 0, 0, -1,
|
|
|
|
1, 1, -1, -1,
|
|
|
|
0, 0, -1, -1};
|
|
|
|
int aligned = aligned_lut[format & 0xf];
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (aligned != -1, FALSE);
|
|
|
|
|
|
|
|
/* NB: currently checking whether the format components are aligned
|
|
|
|
* or not determines whether the format is endian dependent or not.
|
|
|
|
* In the future though we might consider adding formats with
|
|
|
|
* aligned components that are also endian independant. */
|
|
|
|
|
|
|
|
return aligned;
|
|
|
|
}
|