mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 01:50:42 -05:00
material: split the texture unit management out
In general cogl-material.c has become far to large to manage in one source file. As one of the ways to try and break it down this patch starts to move some of lower level texture unit state management out into cogl-material-opengl.c. The naming is such because the plan is to follow up and migrate the very GL specific state flushing code into the same file.
This commit is contained in:
parent
9e893e684e
commit
ddb9016be4
@ -120,6 +120,8 @@ cogl_sources_c = \
|
||||
$(srcdir)/cogl-matrix-stack.h \
|
||||
$(srcdir)/cogl-material.c \
|
||||
$(srcdir)/cogl-material-private.h \
|
||||
$(srcdir)/cogl-material-opengl.c \
|
||||
$(srcdir)/cogl-material-opengl-private.h \
|
||||
$(srcdir)/cogl-material-glsl.c \
|
||||
$(srcdir)/cogl-material-glsl-private.h \
|
||||
$(srcdir)/cogl-material-arbfp.c \
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "cogl-texture-driver.h"
|
||||
#include "cogl-atlas.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-path-private.h"
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#endif
|
||||
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#ifdef COGL_MATERIAL_BACKEND_FIXED
|
||||
|
||||
|
148
clutter/cogl/cogl/cogl-material-opengl-private.h
Normal file
148
clutter/cogl/cogl/cogl-material-opengl-private.h
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_MATERIAL_OPENGL_PRIVATE_H
|
||||
#define __COGL_MATERIAL_OPENGL_PRIVATE_H
|
||||
|
||||
#include "cogl.h"
|
||||
|
||||
#include "cogl-matrix-stack.h"
|
||||
|
||||
/*
|
||||
* cogl-material.c owns the GPU's texture unit state so we have some
|
||||
* 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
|
||||
* texture unit when flushing CoglMaterialLayers that is typically
|
||||
* 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;
|
||||
|
||||
/* Whether or not the corresponding gl_target has been glEnabled */
|
||||
gboolean enabled;
|
||||
|
||||
/* The GL target currently glEnabled or the target last enabled
|
||||
* if .enabled == FALSE */
|
||||
GLenum current_gl_target;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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. */
|
||||
gboolean is_foreign;
|
||||
|
||||
/* 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).
|
||||
*
|
||||
* XXX: as a further optimization cogl-material.c uses a convention
|
||||
* of always using texture unit 1 for these transient bindings so we
|
||||
* can assume this is only ever TRUE for unit 1.
|
||||
*/
|
||||
gboolean dirty_gl_texture;
|
||||
|
||||
/* 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...
|
||||
*/
|
||||
|
||||
/* The CoglMaterialLayer whos state was flushed to update this
|
||||
* 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. */
|
||||
CoglMaterialLayer *layer;
|
||||
|
||||
/* 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
|
||||
* cogl-material.c is notified with a call to
|
||||
* _cogl_material_texture_storage_change_notify which inturn sets
|
||||
* this to TRUE for each texture unit that it is currently bound
|
||||
* too. When we later come to flush some material state then we will
|
||||
* always check this to potentially force an update of the texture
|
||||
* state even if the material hasn't changed. */
|
||||
gboolean texture_storage_changed;
|
||||
|
||||
} CoglTextureUnit;
|
||||
|
||||
CoglTextureUnit *
|
||||
_cogl_get_texture_unit (int index_);
|
||||
|
||||
void
|
||||
_cogl_destroy_texture_units (void);
|
||||
|
||||
void
|
||||
_cogl_disable_texture_unit (int unit_index);
|
||||
|
||||
void
|
||||
_cogl_set_active_texture_unit (int unit_index);
|
||||
|
||||
void
|
||||
_cogl_bind_gl_texture_transient (GLenum gl_target,
|
||||
GLuint gl_texture,
|
||||
gboolean is_foreign);
|
||||
|
||||
void
|
||||
_cogl_delete_gl_texture (GLuint gl_texture);
|
||||
|
||||
#endif /* __COGL_MATERIAL_OPENGL_PRIVATE_H */
|
||||
|
230
clutter/cogl/cogl/cogl-material-opengl.c
Normal file
230
clutter/cogl/cogl/cogl-material-opengl.c
Normal file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* An object oriented GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Copyright (C) 2008,2009,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>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "cogl.h"
|
||||
|
||||
#include "cogl-material-opengl-private.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-context.h"
|
||||
|
||||
static void
|
||||
texture_unit_init (CoglTextureUnit *unit, int index_)
|
||||
{
|
||||
unit->index = index_;
|
||||
unit->enabled = FALSE;
|
||||
unit->current_gl_target = 0;
|
||||
unit->gl_texture = 0;
|
||||
unit->is_foreign = FALSE;
|
||||
unit->dirty_gl_texture = FALSE;
|
||||
unit->matrix_stack = _cogl_matrix_stack_new ();
|
||||
|
||||
unit->layer = NULL;
|
||||
unit->layer_changes_since_flush = 0;
|
||||
unit->texture_storage_changed = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
texture_unit_free (CoglTextureUnit *unit)
|
||||
{
|
||||
if (unit->layer)
|
||||
cogl_object_unref (unit->layer);
|
||||
_cogl_matrix_stack_destroy (unit->matrix_stack);
|
||||
}
|
||||
|
||||
CoglTextureUnit *
|
||||
_cogl_get_texture_unit (int index_)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
if (ctx->texture_units->len < (index_ + 1))
|
||||
{
|
||||
int i;
|
||||
int prev_len = ctx->texture_units->len;
|
||||
ctx->texture_units = g_array_set_size (ctx->texture_units, index_ + 1);
|
||||
for (i = prev_len; i <= index_; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
texture_unit_init (unit, i);
|
||||
}
|
||||
}
|
||||
|
||||
return &g_array_index (ctx->texture_units, CoglTextureUnit, index_);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_destroy_texture_units (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
texture_unit_free (unit);
|
||||
}
|
||||
g_array_free (ctx->texture_units, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_set_active_texture_unit (int unit_index)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (ctx->active_texture_unit != unit_index)
|
||||
{
|
||||
GE (glActiveTexture (GL_TEXTURE0 + unit_index));
|
||||
ctx->active_texture_unit = unit_index;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_disable_texture_unit (int unit_index)
|
||||
{
|
||||
CoglTextureUnit *unit;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
unit = &g_array_index (ctx->texture_units, CoglTextureUnit, unit_index);
|
||||
|
||||
if (unit->enabled)
|
||||
{
|
||||
_cogl_set_active_texture_unit (unit_index);
|
||||
GE (glDisable (unit->current_gl_target));
|
||||
unit->enabled = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Note: _cogl_bind_gl_texture_transient conceptually has slightly
|
||||
* different semantics to OpenGL's glBindTexture because Cogl never
|
||||
* cares about tracking multiple textures bound to different targets
|
||||
* on the same texture unit.
|
||||
*
|
||||
* glBindTexture lets you bind multiple textures to a single texture
|
||||
* unit if they are bound to different targets. So it does something
|
||||
* like:
|
||||
* unit->current_texture[target] = texture;
|
||||
*
|
||||
* Cogl only lets you associate one texture with the currently active
|
||||
* texture unit, so the target is basically a redundant parameter
|
||||
* that's implicitly set on that texture.
|
||||
*
|
||||
* Technically this is just a thin wrapper around glBindTexture so
|
||||
* actually it does have the GL semantics but it seems worth
|
||||
* mentioning the conceptual difference in case anyone wonders why we
|
||||
* don't associate the gl_texture with a gl_target in the
|
||||
* CoglTextureUnit.
|
||||
*/
|
||||
void
|
||||
_cogl_bind_gl_texture_transient (GLenum gl_target,
|
||||
GLuint gl_texture,
|
||||
gboolean is_foreign)
|
||||
{
|
||||
CoglTextureUnit *unit;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* We choose to always make texture unit 1 active for transient
|
||||
* binds so that in the common case where multitexturing isn't used
|
||||
* we can simply ignore the state of this texture unit. Notably we
|
||||
* didn't use a large texture unit (.e.g. (GL_MAX_TEXTURE_UNITS - 1)
|
||||
* in case the driver doesn't have a sparse data structure for
|
||||
* texture units.
|
||||
*/
|
||||
_cogl_set_active_texture_unit (1);
|
||||
unit = _cogl_get_texture_unit (1);
|
||||
|
||||
/* NB: If we have previously bound a foreign texture to this texture
|
||||
* unit we don't know if that texture has since been deleted and we
|
||||
* are seeing the texture name recycled */
|
||||
if (unit->gl_texture == gl_texture &&
|
||||
!unit->dirty_gl_texture &&
|
||||
!unit->is_foreign)
|
||||
return;
|
||||
|
||||
GE (glBindTexture (gl_target, gl_texture));
|
||||
|
||||
unit->dirty_gl_texture = TRUE;
|
||||
unit->is_foreign = is_foreign;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_delete_gl_texture (GLuint gl_texture)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
if (unit->gl_texture == gl_texture)
|
||||
{
|
||||
unit->gl_texture = 0;
|
||||
unit->dirty_gl_texture = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
GE (glDeleteTextures (1, &gl_texture));
|
||||
}
|
||||
|
||||
/* Whenever the underlying GL texture storage of a CoglTexture is
|
||||
* changed (e.g. due to migration out of a texture atlas) then we are
|
||||
* notified. This lets us ensure that we reflush that texture's state
|
||||
* if it reused again with the same texture unit.
|
||||
*/
|
||||
void
|
||||
_cogl_material_texture_storage_change_notify (CoglHandle texture)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
if (unit->layer &&
|
||||
unit->layer->texture == texture)
|
||||
unit->texture_storage_changed = TRUE;
|
||||
|
||||
/* NB: the texture may be bound to multiple texture units so
|
||||
* we continue to check the rest */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,114 +32,10 @@
|
||||
|
||||
#include "cogl-material.h"
|
||||
#include "cogl-matrix.h"
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-handle.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/*
|
||||
* cogl-material.c owns the GPU's texture unit state so we have some
|
||||
* 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
|
||||
* texture unit when flushing CoglMaterialLayers that is typically
|
||||
* 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;
|
||||
|
||||
/* Whether or not the corresponding gl_target has been glEnabled */
|
||||
gboolean enabled;
|
||||
|
||||
/* The GL target currently glEnabled or the target last enabled
|
||||
* if .enabled == FALSE */
|
||||
GLenum current_gl_target;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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. */
|
||||
gboolean is_foreign;
|
||||
|
||||
/* 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).
|
||||
*
|
||||
* XXX: as a further optimization cogl-material.c uses a convention
|
||||
* of always using texture unit 1 for these transient bindings so we
|
||||
* can assume this is only ever TRUE for unit 1.
|
||||
*/
|
||||
gboolean dirty_gl_texture;
|
||||
|
||||
/* 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...
|
||||
*/
|
||||
|
||||
/* The CoglMaterialLayer whos state was flushed to update this
|
||||
* 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. */
|
||||
CoglMaterialLayer *layer;
|
||||
|
||||
/* 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
|
||||
* cogl-material.c is notified with a call to
|
||||
* _cogl_material_texture_storage_change_notify which inturn sets
|
||||
* this to TRUE for each texture unit that it is currently bound
|
||||
* too. When we later come to flush some material state then we will
|
||||
* always check this to potentially force an update of the texture
|
||||
* state even if the material hasn't changed. */
|
||||
gboolean texture_storage_changed;
|
||||
|
||||
} CoglTextureUnit;
|
||||
|
||||
CoglTextureUnit *
|
||||
_cogl_get_texture_unit (int index_);
|
||||
|
||||
void
|
||||
_cogl_destroy_texture_units (void);
|
||||
|
||||
void
|
||||
_cogl_bind_gl_texture_transient (GLenum gl_target,
|
||||
GLuint gl_texture,
|
||||
gboolean is_foreign);
|
||||
|
||||
#if defined (HAVE_COGL_GL)
|
||||
|
||||
/* NB: material->backend is currently a 3bit unsigned int bitfield */
|
||||
@ -775,12 +671,6 @@ typedef struct _CoglMaterialFlushOptions
|
||||
} CoglMaterialFlushOptions;
|
||||
|
||||
|
||||
void
|
||||
_cogl_set_active_texture_unit (int unit_index);
|
||||
|
||||
void
|
||||
_cogl_delete_gl_texture (GLuint gl_texture);
|
||||
|
||||
int
|
||||
_cogl_get_max_texture_image_units (void);
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "cogl-object.h"
|
||||
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
#include "cogl-texture-private.h"
|
||||
#include "cogl-blend-string.h"
|
||||
#include "cogl-journal-private.h"
|
||||
@ -119,181 +120,6 @@ COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (material);
|
||||
so that the cogl_is_* function won't get defined */
|
||||
COGL_OBJECT_INTERNAL_DEFINE (MaterialLayer, material_layer);
|
||||
|
||||
static void
|
||||
texture_unit_init (CoglTextureUnit *unit, int index_)
|
||||
{
|
||||
unit->index = index_;
|
||||
unit->enabled = FALSE;
|
||||
unit->current_gl_target = 0;
|
||||
unit->gl_texture = 0;
|
||||
unit->is_foreign = FALSE;
|
||||
unit->dirty_gl_texture = FALSE;
|
||||
unit->matrix_stack = _cogl_matrix_stack_new ();
|
||||
|
||||
unit->layer = NULL;
|
||||
unit->layer_changes_since_flush = 0;
|
||||
unit->texture_storage_changed = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
texture_unit_free (CoglTextureUnit *unit)
|
||||
{
|
||||
if (unit->layer)
|
||||
cogl_object_unref (unit->layer);
|
||||
_cogl_matrix_stack_destroy (unit->matrix_stack);
|
||||
}
|
||||
|
||||
CoglTextureUnit *
|
||||
_cogl_get_texture_unit (int index_)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
|
||||
if (ctx->texture_units->len < (index_ + 1))
|
||||
{
|
||||
int i;
|
||||
int prev_len = ctx->texture_units->len;
|
||||
ctx->texture_units = g_array_set_size (ctx->texture_units, index_ + 1);
|
||||
for (i = prev_len; i <= index_; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
texture_unit_init (unit, i);
|
||||
}
|
||||
}
|
||||
|
||||
return &g_array_index (ctx->texture_units, CoglTextureUnit, index_);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_destroy_texture_units (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
texture_unit_free (unit);
|
||||
}
|
||||
g_array_free (ctx->texture_units, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_set_active_texture_unit (int unit_index)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (ctx->active_texture_unit != unit_index)
|
||||
{
|
||||
GE (glActiveTexture (GL_TEXTURE0 + unit_index));
|
||||
ctx->active_texture_unit = unit_index;
|
||||
}
|
||||
}
|
||||
|
||||
/* Note: _cogl_bind_gl_texture_transient conceptually has slightly
|
||||
* different semantics to OpenGL's glBindTexture because Cogl never
|
||||
* cares about tracking multiple textures bound to different targets
|
||||
* on the same texture unit.
|
||||
*
|
||||
* glBindTexture lets you bind multiple textures to a single texture
|
||||
* unit if they are bound to different targets. So it does something
|
||||
* like:
|
||||
* unit->current_texture[target] = texture;
|
||||
*
|
||||
* Cogl only lets you associate one texture with the currently active
|
||||
* texture unit, so the target is basically a redundant parameter
|
||||
* that's implicitly set on that texture.
|
||||
*
|
||||
* Technically this is just a thin wrapper around glBindTexture so
|
||||
* actually it does have the GL semantics but it seems worth
|
||||
* mentioning the conceptual difference in case anyone wonders why we
|
||||
* don't associate the gl_texture with a gl_target in the
|
||||
* CoglTextureUnit.
|
||||
*/
|
||||
void
|
||||
_cogl_bind_gl_texture_transient (GLenum gl_target,
|
||||
GLuint gl_texture,
|
||||
gboolean is_foreign)
|
||||
{
|
||||
CoglTextureUnit *unit;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* We choose to always make texture unit 1 active for transient
|
||||
* binds so that in the common case where multitexturing isn't used
|
||||
* we can simply ignore the state of this texture unit. Notably we
|
||||
* didn't use a large texture unit (.e.g. (GL_MAX_TEXTURE_UNITS - 1)
|
||||
* in case the driver doesn't have a sparse data structure for
|
||||
* texture units.
|
||||
*/
|
||||
_cogl_set_active_texture_unit (1);
|
||||
unit = _cogl_get_texture_unit (1);
|
||||
|
||||
/* NB: If we have previously bound a foreign texture to this texture
|
||||
* unit we don't know if that texture has since been deleted and we
|
||||
* are seeing the texture name recycled */
|
||||
if (unit->gl_texture == gl_texture &&
|
||||
!unit->dirty_gl_texture &&
|
||||
!unit->is_foreign)
|
||||
return;
|
||||
|
||||
GE (glBindTexture (gl_target, gl_texture));
|
||||
|
||||
unit->dirty_gl_texture = TRUE;
|
||||
unit->is_foreign = is_foreign;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_delete_gl_texture (GLuint gl_texture)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
if (unit->gl_texture == gl_texture)
|
||||
{
|
||||
unit->gl_texture = 0;
|
||||
unit->dirty_gl_texture = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
GE (glDeleteTextures (1, &gl_texture));
|
||||
}
|
||||
|
||||
/* Whenever the underlying GL texture storage of a CoglTexture is
|
||||
* changed (e.g. due to migration out of a texture atlas) then we are
|
||||
* notified. This lets us ensure that we reflush that texture's state
|
||||
* if it reused again with the same texture unit.
|
||||
*/
|
||||
void
|
||||
_cogl_material_texture_storage_change_notify (CoglHandle texture)
|
||||
{
|
||||
int i;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
for (i = 0; i < ctx->texture_units->len; i++)
|
||||
{
|
||||
CoglTextureUnit *unit =
|
||||
&g_array_index (ctx->texture_units, CoglTextureUnit, i);
|
||||
|
||||
if (unit->layer &&
|
||||
unit->layer->texture == texture)
|
||||
unit->texture_storage_changed = TRUE;
|
||||
|
||||
/* NB: the texture may be bound to multiple texture units so
|
||||
* we continue to check the rest */
|
||||
}
|
||||
}
|
||||
|
||||
GQuark
|
||||
_cogl_material_error_quark (void)
|
||||
{
|
||||
@ -5252,23 +5078,6 @@ cogl_material_set_point_size (CoglHandle handle,
|
||||
_cogl_material_point_size_equal);
|
||||
}
|
||||
|
||||
static void
|
||||
disable_texture_unit (int unit_index)
|
||||
{
|
||||
CoglTextureUnit *unit;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
unit = &g_array_index (ctx->texture_units, CoglTextureUnit, unit_index);
|
||||
|
||||
if (unit->enabled)
|
||||
{
|
||||
_cogl_set_active_texture_unit (unit_index);
|
||||
GE (glDisable (unit->current_gl_target));
|
||||
unit->enabled = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_gl_use_program_wrapper (GLuint program)
|
||||
{
|
||||
@ -5832,7 +5641,7 @@ _cogl_material_flush_common_gl_state (CoglMaterial *material,
|
||||
|
||||
/* Disable additional texture units that may have previously been in use.. */
|
||||
for (; state.i < ctx->texture_units->len; state.i++)
|
||||
disable_texture_unit (state.i);
|
||||
_cogl_disable_texture_unit (state.i);
|
||||
}
|
||||
|
||||
/* Re-assert the layer's wrap modes on the given CoglTexture.
|
||||
@ -5995,7 +5804,7 @@ backend_add_layer_cb (CoglMaterialLayer *layer,
|
||||
{
|
||||
int j;
|
||||
for (j = unit_index; j < ctx->texture_units->len; j++)
|
||||
disable_texture_unit (j);
|
||||
_cogl_disable_texture_unit (j);
|
||||
/* TODO: although this isn't considered an error that
|
||||
* warrants falling back to a different backend we
|
||||
* should print a warning here. */
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-spans.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-journal-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-primitives.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-xlib.h"
|
||||
#include "cogl-material-opengl-private.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
Loading…
Reference in New Issue
Block a user