2010-07-09 21:53:38 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
#ifndef __COGL_PIPELINE_OPENGL_PRIVATE_H
|
|
|
|
#define __COGL_PIPELINE_OPENGL_PRIVATE_H
|
2010-07-09 21:53:38 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-private.h"
|
2010-07-09 21:53:38 -04:00
|
|
|
#include "cogl-matrix-stack.h"
|
|
|
|
|
|
|
|
/*
|
2010-10-27 13:54:57 -04:00
|
|
|
* cogl-pipeline.c owns the GPU's texture unit state so we have some
|
2010-07-09 21:53:38 -04:00
|
|
|
* private structures for describing the current state of a texture
|
|
|
|
* unit that we track in a per context array (ctx->texture_units) that
|
|
|
|
* grows according to the largest texture unit used so far...
|
|
|
|
*
|
|
|
|
* Roughly speaking the members in this structure are of two kinds:
|
|
|
|
* either they are a low level reflection of the state we send to
|
|
|
|
* OpenGL or they are for high level meta data assoicated with the
|
2010-10-27 13:54:57 -04:00
|
|
|
* texture unit when flushing CoglPipelineLayers that is typically
|
2010-07-09 21:53:38 -04:00
|
|
|
* used to optimize subsequent re-flushing of the same layer.
|
|
|
|
*
|
|
|
|
* The low level members are at the top, and the high level members
|
|
|
|
* start with the .layer member.
|
|
|
|
*/
|
|
|
|
typedef struct _CoglTextureUnit
|
|
|
|
{
|
|
|
|
/* The base 0 texture unit index which can be used with
|
|
|
|
* glActiveTexture () */
|
|
|
|
int index;
|
|
|
|
|
2010-11-30 07:48:27 -05:00
|
|
|
/* The GL target currently glEnabled or 0 if nothing is
|
|
|
|
* enabled. This is only used by the fixed pipeline fragend */
|
|
|
|
GLenum enabled_gl_target;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
/* The raw GL texture object name for which we called glBindTexture when
|
|
|
|
* we flushed the last layer. (NB: The CoglTexture associated
|
|
|
|
* with a layer may represent more than one GL texture) */
|
|
|
|
GLuint gl_texture;
|
2010-11-30 07:48:27 -05:00
|
|
|
/* The target of the GL texture object. This is just used so that we
|
|
|
|
* can quickly determine the intended target to flush when
|
|
|
|
* dirty_gl_texture == TRUE */
|
|
|
|
GLenum gl_target;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
/* Foreign textures are those not created or deleted by Cogl. If we ever
|
|
|
|
* call glBindTexture for a foreign texture then the next time we are
|
|
|
|
* asked to glBindTexture we can't try and optimize a redundant state
|
|
|
|
* change because we don't know if the original texture name was deleted
|
|
|
|
* and now we are being asked to bind a recycled name. */
|
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 16:56:40 -04:00
|
|
|
CoglBool is_foreign;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
/* We have many components in Cogl that need to temporarily bind arbitrary
|
|
|
|
* textures e.g. to query texture object parameters and since we don't
|
|
|
|
* want that to result in too much redundant reflushing of layer state
|
|
|
|
* when all that's needed is to re-bind the layer's gl_texture we use this
|
|
|
|
* to track when the unit->gl_texture state is out of sync with the GL
|
|
|
|
* texture object really bound too (GL_TEXTURE0+unit->index).
|
|
|
|
*
|
2010-10-27 13:54:57 -04:00
|
|
|
* XXX: as a further optimization cogl-pipeline.c uses a convention
|
2010-07-09 21:53:38 -04:00
|
|
|
* of always using texture unit 1 for these transient bindings so we
|
|
|
|
* can assume this is only ever TRUE for unit 1.
|
|
|
|
*/
|
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 16:56:40 -04:00
|
|
|
CoglBool dirty_gl_texture;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
/* A matrix stack giving us the means to associate a texture
|
|
|
|
* transform matrix with the texture unit. */
|
|
|
|
CoglMatrixStack *matrix_stack;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Higher level layer state associated with the unit...
|
|
|
|
*/
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
/* The CoglPipelineLayer whos state was flushed to update this
|
2010-07-09 21:53:38 -04:00
|
|
|
* texture unit last.
|
|
|
|
*
|
|
|
|
* This will be set to NULL if the layer is modified or freed which
|
|
|
|
* means when we come to flush a layer; if this pointer is still
|
|
|
|
* valid and == to the layer being flushed we don't need to update
|
|
|
|
* any texture unit state. */
|
2010-10-27 13:54:57 -04:00
|
|
|
CoglPipelineLayer *layer;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
/* To help minimize the state changes required we track the
|
|
|
|
* difference flags associated with the layer whos state was last
|
|
|
|
* flushed to update this texture unit.
|
|
|
|
*
|
|
|
|
* Note: we track this explicitly because .layer may get invalidated
|
|
|
|
* if that layer is modified or deleted. Even if the layer is
|
|
|
|
* invalidated though these flags can be used to optimize the state
|
|
|
|
* flush of the next layer
|
|
|
|
*/
|
|
|
|
unsigned long layer_changes_since_flush;
|
|
|
|
|
|
|
|
/* Whenever a CoglTexture's internal GL texture storage changes
|
2010-10-27 13:54:57 -04:00
|
|
|
* cogl-pipeline.c is notified with a call to
|
|
|
|
* _cogl_pipeline_texture_storage_change_notify which inturn sets
|
2010-07-09 21:53:38 -04:00
|
|
|
* this to TRUE for each texture unit that it is currently bound
|
2010-10-27 13:54:57 -04:00
|
|
|
* too. When we later come to flush some pipeline state then we will
|
2010-07-09 21:53:38 -04:00
|
|
|
* always check this to potentially force an update of the texture
|
2010-10-27 13:54:57 -04:00
|
|
|
* state even if the pipeline hasn't changed. */
|
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 16:56:40 -04:00
|
|
|
CoglBool texture_storage_changed;
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
} CoglTextureUnit;
|
|
|
|
|
|
|
|
CoglTextureUnit *
|
|
|
|
_cogl_get_texture_unit (int index_);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_destroy_texture_units (void);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_set_active_texture_unit (int unit_index);
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_bind_gl_texture_transient (GLenum gl_target,
|
|
|
|
GLuint gl_texture,
|
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 16:56:40 -04:00
|
|
|
CoglBool is_foreign);
|
2010-07-09 21:53:38 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_delete_gl_texture (GLuint gl_texture);
|
|
|
|
|
2010-07-09 22:40:47 -04:00
|
|
|
void
|
2010-10-27 13:54:57 -04:00
|
|
|
_cogl_pipeline_flush_gl_state (CoglPipeline *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 10:59:48 -05:00
|
|
|
CoglFramebuffer *framebuffer,
|
2012-09-27 06:06:16 -04:00
|
|
|
CoglBool skip_gl_state);
|
2010-07-09 22:40:47 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
#endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */
|
2010-07-09 21:53:38 -04:00
|
|
|
|