summaryrefslogtreecommitdiff
path: root/cogl/cogl-pipeline-layer.c
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-04-04 22:20:04 +0100
committerNeil Roberts <neil@linux.intel.com>2012-04-05 13:47:36 +0100
commitc33ce5fc6bbda0f7c2d8f0e4bb3523948acce0da (patch)
tree97b49d0e6c360a9b2828d6eca4edb51432afd0ee /cogl/cogl-pipeline-layer.c
parent4229d61d3b5368dc169223812e57033f41283223 (diff)
downloadcogl-c33ce5fc6bbda0f7c2d8f0e4bb3523948acce0da.tar.gz
Use GL_ARB_sampler_objects
GL_ARB_sampler_objects provides a GL object which overrides the sampler state part of a texture object with different values. The sampler state that Cogl currently exposes is the wrap modes and filters. Cogl exposes the state as part of the pipeline layer state but without this extension GL only exposes it as part of the texture object state. This means that it won't work to use a single texture multiple times in one primitive with different sampler states. It also makes switching between different sampler states with a single texture not terribly efficient because it has to change the texture object state every time. This patch adds a cache for sampler states in a shared hash table attached to the CoglContext. The entire set of parameters for the sampler state is used as the key for the hash table. When a unique state is encountered the sampler cache will create a new entry, otherwise it will return a const pointer to an existing entry. That means we can have a single pointer to represent any combination of sampler state. Pipeline layers now just store this single pointer rather than storing all of the sampler state. The two separate state flags for wrap modes and filters have now been combined into one. It should be faster to compare the sampler state now because instead of comparing each value it can just compare the pointers to the cached sampler entries. The hash table of cached sampler states should only need to perform its more expensive hash on the state when a property is changed on a pipeline, not every time it is flushed. When the sampler objects extension is available each cached sampler state will also get a sampler object to represent it. The common code to flush the GL state will now simply bind this object to a unit instead of flushing the state though the CoglTexture when possible. Reviewed-by: Robert Bragg <robert@linux.intel.com>
Diffstat (limited to 'cogl/cogl-pipeline-layer.c')
-rw-r--r--cogl/cogl-pipeline-layer.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/cogl/cogl-pipeline-layer.c b/cogl/cogl-pipeline-layer.c
index 558a8b61..9093a043 100644
--- a/cogl/cogl-pipeline-layer.c
+++ b/cogl/cogl-pipeline-layer.c
@@ -170,21 +170,13 @@ _cogl_pipeline_layer_init_multi_property_sparse_state (
case COGL_PIPELINE_LAYER_STATE_POINT_SPRITE_COORDS:
case COGL_PIPELINE_LAYER_STATE_USER_MATRIX:
case COGL_PIPELINE_LAYER_STATE_COMBINE_CONSTANT:
+ case COGL_PIPELINE_LAYER_STATE_SAMPLER:
g_return_if_reached ();
/* XXX: technically we could probably even consider these as
* single property state-groups from the pov that currently the
* corresponding property setters always update all of the values
* at the same time. */
- case COGL_PIPELINE_LAYER_STATE_FILTERS:
- layer->min_filter = authority->min_filter;
- layer->mag_filter = authority->mag_filter;
- break;
- case COGL_PIPELINE_LAYER_STATE_WRAP_MODES:
- layer->wrap_mode_s = authority->wrap_mode_s;
- layer->wrap_mode_t = authority->wrap_mode_t;
- layer->wrap_mode_p = authority->wrap_mode_p;
- break;
case COGL_PIPELINE_LAYER_STATE_COMBINE:
{
int n_args;
@@ -576,16 +568,10 @@ _cogl_pipeline_layer_equal (CoglPipelineLayer *layer0,
_cogl_pipeline_layer_combine_constant_equal))
return FALSE;
- if (layers_difference & COGL_PIPELINE_LAYER_STATE_FILTERS &&
- !layer_state_equal (COGL_PIPELINE_LAYER_STATE_FILTERS_INDEX,
- authorities0, authorities1,
- _cogl_pipeline_layer_filters_equal))
- return FALSE;
-
- if (layers_difference & COGL_PIPELINE_LAYER_STATE_WRAP_MODES &&
- !layer_state_equal (COGL_PIPELINE_LAYER_STATE_WRAP_MODES_INDEX,
+ if (layers_difference & COGL_PIPELINE_LAYER_STATE_SAMPLER &&
+ !layer_state_equal (COGL_PIPELINE_LAYER_STATE_SAMPLER_INDEX,
authorities0, authorities1,
- _cogl_pipeline_layer_wrap_modes_equal))
+ _cogl_pipeline_layer_sampler_equal))
return FALSE;
if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX &&
@@ -657,12 +643,8 @@ _cogl_pipeline_init_default_layers (void)
layer->texture = NULL;
layer->texture_type = COGL_TEXTURE_TYPE_2D;
- layer->mag_filter = COGL_PIPELINE_FILTER_LINEAR;
- layer->min_filter = COGL_PIPELINE_FILTER_LINEAR;
-
- layer->wrap_mode_s = COGL_PIPELINE_WRAP_MODE_AUTOMATIC;
- layer->wrap_mode_t = COGL_PIPELINE_WRAP_MODE_AUTOMATIC;
- layer->wrap_mode_p = COGL_PIPELINE_WRAP_MODE_AUTOMATIC;
+ layer->sampler_cache_entry =
+ _cogl_sampler_cache_get_default_entry (ctx->sampler_cache);
layer->big_state = big_state;
layer->has_big_state = TRUE;