diff options
author | Neil Roberts <neil@linux.intel.com> | 2012-04-04 22:20:04 +0100 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2012-04-05 13:47:36 +0100 |
commit | c33ce5fc6bbda0f7c2d8f0e4bb3523948acce0da (patch) | |
tree | 97b49d0e6c360a9b2828d6eca4edb51432afd0ee /cogl/cogl-sampler-cache-private.h | |
parent | 4229d61d3b5368dc169223812e57033f41283223 (diff) | |
download | cogl-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-sampler-cache-private.h')
-rw-r--r-- | cogl/cogl-sampler-cache-private.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/cogl/cogl-sampler-cache-private.h b/cogl/cogl-sampler-cache-private.h new file mode 100644 index 00000000..4eb75039 --- /dev/null +++ b/cogl/cogl-sampler-cache-private.h @@ -0,0 +1,82 @@ +/* + * Cogl + * + * An object oriented GL/GLES Abstraction/Utility Layer + * + * Copyright (C) 2012 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/>. + * + * + */ + +#ifndef __COGL_SAMPLER_CACHE_PRIVATE_H +#define __COGL_SAMPLER_CACHE_PRIVATE_H + +#include "cogl-context.h" +#include "cogl-gl-header.h" + +/* GL_ALWAYS is just used here as a value that is known not to clash + * with any valid GL wrap modes. + * + * XXX: keep the values in sync with the CoglPipelineWrapMode enum + * so no conversion is actually needed. + */ +typedef enum _CoglSamplerCacheWrapMode +{ + COGL_SAMPLER_CACHE_WRAP_MODE_REPEAT = GL_REPEAT, + COGL_SAMPLER_CACHE_WRAP_MODE_MIRRORED_REPEAT = GL_MIRRORED_REPEAT, + COGL_SAMPLER_CACHE_WRAP_MODE_CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE, + COGL_SAMPLER_CACHE_WRAP_MODE_CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER, + COGL_SAMPLER_CACHE_WRAP_MODE_AUTOMATIC = GL_ALWAYS +} CoglSamplerCacheWrapMode; + +typedef struct _CoglSamplerCache CoglSamplerCache; + +typedef struct _CoglSamplerCacheEntry +{ + GLuint sampler_object; + + GLenum min_filter; + GLenum mag_filter; + + CoglSamplerCacheWrapMode wrap_mode_s; + CoglSamplerCacheWrapMode wrap_mode_t; + CoglSamplerCacheWrapMode wrap_mode_p; +} CoglSamplerCacheEntry; + +CoglSamplerCache * +_cogl_sampler_cache_new (CoglContext *context); + +const CoglSamplerCacheEntry * +_cogl_sampler_cache_get_default_entry (CoglSamplerCache *cache); + +const CoglSamplerCacheEntry * +_cogl_sampler_cache_update_wrap_modes (CoglSamplerCache *cache, + const CoglSamplerCacheEntry *old_entry, + CoglSamplerCacheWrapMode wrap_mode_s, + CoglSamplerCacheWrapMode wrap_mode_t, + CoglSamplerCacheWrapMode wrap_mode_p); + +const CoglSamplerCacheEntry * +_cogl_sampler_cache_update_filters (CoglSamplerCache *cache, + const CoglSamplerCacheEntry *old_entry, + GLenum min_filter, + GLenum mag_filter); + +void +_cogl_sampler_cache_free (CoglSamplerCache *cache); + +#endif /* __COGL_SAMPLER_CACHE_PRIVATE_H */ |