summaryrefslogtreecommitdiff
path: root/cogl/cogl-context.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2011-11-24 18:09:53 +0000
committerRobert Bragg <robert@linux.intel.com>2011-12-06 18:51:57 +0000
commit7283e0a49c5eeee9242ccd5857e2a51d6934b792 (patch)
treec50a1652b4ee21195d7457bcd020b59cd3d5fb7b /cogl/cogl-context.c
parent2112af0bc51c5173a4b8fe2c6ea6bdca9274c5b3 (diff)
downloadcogl-7283e0a49c5eeee9242ccd5857e2a51d6934b792.tar.gz
rework enabling of attributes, removing _cogl_enable()
This removes the limited caching of enabled attributes done by _cogl_enable() and replaces it with a more generalized set of bitmasks associated with the context that allow us to efficiently compare the set of attribute locations that are currently enabled vs the new locations that need enabling so we only have to inform OpenGL of the changes in which locations are enabled/disabled. This also adds a per-context hash table for mapping attribute names to global name-state structs which includes a unique name-index for any name as well as pre-validated information about builtin "cogl_" attribute names including whether the attribute is normalized and what texture unit a texture attribute corresponds too. The name-state hash table means that cogl_attribute_new() now only needs to validate names the first time they are seen. CoglAttributes now reference a name-state structure instead of just the attribute name, so now we can efficiently get the name-index for any attribute and we can use that to index into a per-glsl-program cache that maps name indices to real GL attribute locations so when we get asked to draw a set of attributes we can very quickly determine what GL attributes need to be setup and enabled. If we don't have a cached location though we can still quickly access the string name so we can query OpenGL. Reviewed-by: Neil Roberts <neil@linux.intel.com>
Diffstat (limited to 'cogl/cogl-context.c')
-rw-r--r--cogl/cogl-context.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index f4745383..08b527ee 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -43,6 +43,7 @@
#include "cogl-framebuffer-private.h"
#include "cogl-onscreen-private.h"
#include "cogl2-path.h"
+#include "cogl-attribute-private.h"
#include <string.h>
@@ -129,7 +130,6 @@ cogl_context_new (CoglDisplay *display,
{
CoglContext *context;
GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 };
- unsigned long enable_flags = 0;
const CoglWinsysVtable *winsys;
int i;
@@ -221,6 +221,16 @@ cogl_context_new (CoglDisplay *display,
g_assert_not_reached ();
}
+ context->attribute_name_states_hash =
+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ context->attribute_name_index_map = NULL;
+ context->n_attribute_names = 0;
+
+ /* The "cogl_color_in" attribute needs a deterministic name_index
+ * so we make sure it's the first attribute name we register */
+ _cogl_attribute_register_attribute_name (context, "cogl_color_in");
+
+
context->uniform_names =
g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
context->uniform_name_hash = g_hash_table_new (g_str_hash, g_str_equal);
@@ -234,7 +244,6 @@ cogl_context_new (CoglDisplay *display,
_cogl_pipeline_init_state_hash_functions ();
_cogl_pipeline_init_layer_state_hash_functions ();
- context->enable_flags = 0;
context->current_clip_stack_valid = FALSE;
context->current_clip_stack = NULL;
@@ -284,9 +293,13 @@ cogl_context_new (CoglDisplay *display,
context->current_pipeline_changes_since_flush = 0;
context->current_pipeline_skip_gl_color = FALSE;
- _cogl_bitmask_init (&context->arrays_enabled);
- _cogl_bitmask_init (&context->temp_bitmask);
- _cogl_bitmask_init (&context->arrays_to_change);
+ _cogl_bitmask_init (&context->enabled_builtin_attributes);
+ _cogl_bitmask_init (&context->enable_builtin_attributes_tmp);
+ _cogl_bitmask_init (&context->enabled_texcoord_attributes);
+ _cogl_bitmask_init (&context->enable_texcoord_attributes_tmp);
+ _cogl_bitmask_init (&context->enabled_custom_attributes);
+ _cogl_bitmask_init (&context->enable_custom_attributes_tmp);
+ _cogl_bitmask_init (&context->changed_bits_tmp);
context->max_texture_units = -1;
context->max_activateable_texture_units = -1;
@@ -385,7 +398,6 @@ cogl_context_new (CoglDisplay *display,
cogl_push_source (context->opaque_color_pipeline);
_cogl_pipeline_flush_gl_state (context->opaque_color_pipeline, FALSE, 0);
- _cogl_enable (enable_flags);
context->atlases = NULL;
g_hook_list_init (&context->atlas_reorganize_callbacks, sizeof (GHook));
@@ -468,9 +480,13 @@ _cogl_context_free (CoglContext *context)
g_slist_free (context->atlases);
g_hook_list_clear (&context->atlas_reorganize_callbacks);
- _cogl_bitmask_destroy (&context->arrays_enabled);
- _cogl_bitmask_destroy (&context->temp_bitmask);
- _cogl_bitmask_destroy (&context->arrays_to_change);
+ _cogl_bitmask_destroy (&context->enabled_builtin_attributes);
+ _cogl_bitmask_destroy (&context->enable_builtin_attributes_tmp);
+ _cogl_bitmask_destroy (&context->enabled_texcoord_attributes);
+ _cogl_bitmask_destroy (&context->enable_texcoord_attributes_tmp);
+ _cogl_bitmask_destroy (&context->enabled_custom_attributes);
+ _cogl_bitmask_destroy (&context->enable_custom_attributes_tmp);
+ _cogl_bitmask_destroy (&context->changed_bits_tmp);
g_slist_free (context->texture_types);
g_slist_free (context->buffer_types);
@@ -490,6 +506,9 @@ _cogl_context_free (CoglContext *context)
g_ptr_array_free (context->uniform_names, TRUE);
g_hash_table_destroy (context->uniform_name_hash);
+ g_hash_table_destroy (context->attribute_name_states_hash);
+ g_array_free (context->attribute_name_index_map, TRUE);
+
g_byte_array_free (context->buffer_map_fallback_array, TRUE);
cogl_object_unref (context->display);