cogl: Add and use sampler init/free hooks in the CoglDriverVtable
next_fake_sampler_object_number moves to CoglGLContext. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1194
This commit is contained in:
parent
245977e525
commit
e2c2a332e6
8 changed files with 72 additions and 55 deletions
|
@ -35,6 +35,7 @@
|
|||
#include "cogl-offscreen.h"
|
||||
#include "cogl-framebuffer-private.h"
|
||||
#include "cogl-attribute-private.h"
|
||||
#include "cogl-sampler-cache-private.h"
|
||||
|
||||
typedef struct _CoglDriverVtable CoglDriverVtable;
|
||||
|
||||
|
@ -265,6 +266,14 @@ struct _CoglDriverVtable
|
|||
const void *data,
|
||||
unsigned int size,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
(*sampler_init) (CoglContext *context,
|
||||
CoglSamplerCacheEntry *entry);
|
||||
|
||||
void
|
||||
(*sampler_free) (CoglContext *context,
|
||||
CoglSamplerCacheEntry *entry);
|
||||
};
|
||||
|
||||
#define COGL_DRIVER_ERROR (_cogl_driver_error_quark ())
|
||||
|
|
|
@ -34,11 +34,6 @@
|
|||
|
||||
#include "cogl-sampler-cache-private.h"
|
||||
#include "cogl-context-private.h"
|
||||
#include "driver/gl/cogl-util-gl-private.h"
|
||||
|
||||
#ifndef GL_TEXTURE_WRAP_R
|
||||
#define GL_TEXTURE_WRAP_R 0x8072
|
||||
#endif
|
||||
|
||||
struct _CoglSamplerCache
|
||||
{
|
||||
|
@ -54,10 +49,6 @@ struct _CoglSamplerCache
|
|||
GL state. */
|
||||
GHashTable *hash_table_cogl;
|
||||
GHashTable *hash_table_gl;
|
||||
|
||||
/* This is used for generated fake unique sampler object numbers
|
||||
when the sampler object extension is not supported */
|
||||
GLuint next_fake_sampler_object_number;
|
||||
};
|
||||
|
||||
static CoglSamplerCacheWrapMode
|
||||
|
@ -176,22 +167,10 @@ _cogl_sampler_cache_new (CoglContext *context)
|
|||
sampler_state_equal_gl);
|
||||
cache->hash_table_cogl = g_hash_table_new (hash_sampler_state_cogl,
|
||||
sampler_state_equal_cogl);
|
||||
cache->next_fake_sampler_object_number = 1;
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
static void
|
||||
set_wrap_mode (CoglContext *context,
|
||||
GLuint sampler_object,
|
||||
GLenum param,
|
||||
CoglSamplerCacheWrapMode wrap_mode)
|
||||
{
|
||||
GE( context, glSamplerParameteri (sampler_object,
|
||||
param,
|
||||
wrap_mode) );
|
||||
}
|
||||
|
||||
static CoglSamplerCacheEntry *
|
||||
_cogl_sampler_cache_get_entry_gl (CoglSamplerCache *cache,
|
||||
const CoglSamplerCacheEntry *key)
|
||||
|
@ -202,39 +181,9 @@ _cogl_sampler_cache_get_entry_gl (CoglSamplerCache *cache,
|
|||
|
||||
if (entry == NULL)
|
||||
{
|
||||
CoglContext *context = cache->context;
|
||||
|
||||
entry = g_slice_dup (CoglSamplerCacheEntry, key);
|
||||
|
||||
if (_cogl_has_private_feature (context,
|
||||
COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS))
|
||||
{
|
||||
GE( context, glGenSamplers (1, &entry->sampler_object) );
|
||||
|
||||
GE( context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
entry->min_filter) );
|
||||
GE( context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
entry->mag_filter) );
|
||||
|
||||
set_wrap_mode (context,
|
||||
entry->sampler_object,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
entry->wrap_mode_s);
|
||||
set_wrap_mode (context,
|
||||
entry->sampler_object,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
entry->wrap_mode_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If sampler objects aren't supported then we'll invent a
|
||||
unique number so that pipelines can still compare the
|
||||
unique state just by comparing the sampler object
|
||||
numbers */
|
||||
entry->sampler_object = cache->next_fake_sampler_object_number++;
|
||||
}
|
||||
cache->context->driver_vtable->sampler_init (cache->context, entry);
|
||||
|
||||
g_hash_table_insert (cache->hash_table_gl, entry, entry);
|
||||
}
|
||||
|
@ -320,9 +269,7 @@ hash_table_free_gl_cb (void *key,
|
|||
CoglContext *context = user_data;
|
||||
CoglSamplerCacheEntry *entry = value;
|
||||
|
||||
if (_cogl_has_private_feature (context,
|
||||
COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS))
|
||||
GE( context, glDeleteSamplers (1, &entry->sampler_object) );
|
||||
context->driver_vtable->sampler_free (context, entry);
|
||||
|
||||
g_slice_free (CoglSamplerCacheEntry, entry);
|
||||
}
|
||||
|
|
|
@ -155,5 +155,13 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
|
|||
const char **strings_in,
|
||||
const GLint *lengths_in);
|
||||
|
||||
void
|
||||
_cogl_sampler_gl_init (CoglContext *context,
|
||||
CoglSamplerCacheEntry *entry);
|
||||
|
||||
void
|
||||
_cogl_sampler_gl_free (CoglContext *context,
|
||||
CoglSamplerCacheEntry *entry);
|
||||
|
||||
#endif /* __COGL_PIPELINE_OPENGL_PRIVATE_H */
|
||||
|
||||
|
|
|
@ -694,6 +694,48 @@ _cogl_pipeline_layer_forward_wrap_modes (CoglPipelineLayer *layer,
|
|||
gl_wrap_mode_t);
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_sampler_gl_init (CoglContext *context, CoglSamplerCacheEntry *entry)
|
||||
{
|
||||
if (_cogl_has_private_feature (context,
|
||||
COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS))
|
||||
{
|
||||
GE( context, glGenSamplers (1, &entry->sampler_object) );
|
||||
|
||||
GE( context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
entry->min_filter) );
|
||||
GE( context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
entry->mag_filter) );
|
||||
|
||||
GE (context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_WRAP_S,
|
||||
entry->wrap_mode_s) );
|
||||
GE (context, glSamplerParameteri (entry->sampler_object,
|
||||
GL_TEXTURE_WRAP_T,
|
||||
entry->wrap_mode_t) );
|
||||
}
|
||||
else
|
||||
{
|
||||
CoglGLContext *gl_context = context->driver_context;
|
||||
|
||||
/* If sampler objects aren't supported then we'll invent a
|
||||
unique number so that pipelines can still compare the
|
||||
unique state just by comparing the sampler object
|
||||
numbers */
|
||||
entry->sampler_object = gl_context->next_fake_sampler_object_number++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_sampler_gl_free (CoglContext *context, CoglSamplerCacheEntry *entry)
|
||||
{
|
||||
if (_cogl_has_private_feature (context,
|
||||
COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS))
|
||||
GE( context, glDeleteSamplers (1, &entry->sampler_object) );
|
||||
}
|
||||
|
||||
/* OpenGL associates the min/mag filters and repeat modes with the
|
||||
* texture object not the texture unit so we always have to re-assert
|
||||
* the filter and repeat modes whenever we use a texture since it may
|
||||
|
|
|
@ -79,6 +79,10 @@ _cogl_gl_error_to_string (GLenum error_code);
|
|||
typedef struct _CoglGLContext {
|
||||
GArray *texture_units;
|
||||
int active_texture_unit;
|
||||
|
||||
/* This is used for generated fake unique sampler object numbers
|
||||
when the sampler object extension is not supported */
|
||||
GLuint next_fake_sampler_object_number;
|
||||
} CoglGLContext;
|
||||
|
||||
CoglGLContext *
|
||||
|
|
|
@ -93,6 +93,7 @@ _cogl_driver_gl_context_init (CoglContext *context)
|
|||
if (!gl_context)
|
||||
return FALSE;
|
||||
|
||||
gl_context->next_fake_sampler_object_number = 1;
|
||||
gl_context->texture_units =
|
||||
g_array_new (FALSE, FALSE, sizeof (CoglTextureUnit));
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "driver/gl/cogl-attribute-gl-private.h"
|
||||
#include "driver/gl/cogl-clip-stack-gl-private.h"
|
||||
#include "driver/gl/cogl-buffer-gl-private.h"
|
||||
#include "driver/gl/cogl-pipeline-opengl-private.h"
|
||||
|
||||
static gboolean
|
||||
_cogl_driver_gl_real_context_init (CoglContext *context)
|
||||
|
@ -562,4 +563,6 @@ _cogl_driver_gl =
|
|||
_cogl_buffer_gl_map_range,
|
||||
_cogl_buffer_gl_unmap,
|
||||
_cogl_buffer_gl_set_data,
|
||||
_cogl_sampler_gl_init,
|
||||
_cogl_sampler_gl_free,
|
||||
};
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "driver/gl/cogl-attribute-gl-private.h"
|
||||
#include "driver/gl/cogl-clip-stack-gl-private.h"
|
||||
#include "driver/gl/cogl-buffer-gl-private.h"
|
||||
#include "driver/gl/cogl-pipeline-opengl-private.h"
|
||||
|
||||
#ifndef GL_UNSIGNED_INT_24_8
|
||||
#define GL_UNSIGNED_INT_24_8 0x84FA
|
||||
|
@ -426,4 +427,6 @@ _cogl_driver_gles =
|
|||
_cogl_buffer_gl_map_range,
|
||||
_cogl_buffer_gl_unmap,
|
||||
_cogl_buffer_gl_set_data,
|
||||
_cogl_sampler_gl_init,
|
||||
_cogl_sampler_gl_free,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue