diff --git a/cogl/cogl/cogl-attribute-private.h b/cogl/cogl/cogl-attribute-private.h index 5712065c0..da22d7de7 100644 --- a/cogl/cogl/cogl-attribute-private.h +++ b/cogl/cogl/cogl-attribute-private.h @@ -63,21 +63,11 @@ struct _CoglAttribute const CoglAttributeNameState *name_state; gboolean normalized; - gboolean is_buffered; - - union { - struct { - CoglAttributeBuffer *attribute_buffer; - size_t stride; - size_t offset; - int n_components; - CoglAttributeType type; - } buffered; - struct { - CoglContext *context; - CoglBoxedValue boxed; - } constant; - } d; + CoglAttributeBuffer *attribute_buffer; + size_t stride; + size_t offset; + int n_components; + CoglAttributeType type; }; typedef enum diff --git a/cogl/cogl/cogl-attribute.c b/cogl/cogl/cogl-attribute.c index 804e17ffd..9bd35230c 100644 --- a/cogl/cogl/cogl-attribute.c +++ b/cogl/cogl/cogl-attribute.c @@ -56,11 +56,7 @@ cogl_attribute_dispose (GObject *object) { CoglAttribute *attribute = COGL_ATTRIBUTE (object); - if (attribute->is_buffered) - g_object_unref (attribute->d.buffered.attribute_buffer); - else - _cogl_boxed_value_destroy (&attribute->d.constant.boxed); - + g_clear_object (&attribute->attribute_buffer); G_OBJECT_CLASS (cogl_attribute_parent_class)->dispose (object); } @@ -216,8 +212,6 @@ cogl_attribute_new (CoglAttributeBuffer *attribute_buffer, CoglBuffer *buffer = COGL_BUFFER (attribute_buffer); CoglContext *ctx = buffer->context; - attribute->is_buffered = TRUE; - attribute->name_state = g_hash_table_lookup (ctx->attribute_name_states_hash, name); if (!attribute->name_state) @@ -229,11 +223,11 @@ cogl_attribute_new (CoglAttributeBuffer *attribute_buffer, attribute->name_state = name_state; } - attribute->d.buffered.attribute_buffer = g_object_ref (attribute_buffer); - attribute->d.buffered.stride = stride; - attribute->d.buffered.offset = offset; - attribute->d.buffered.n_components = n_components; - attribute->d.buffered.type = type; + attribute->attribute_buffer = g_object_ref (attribute_buffer); + attribute->stride = stride; + attribute->offset = offset; + attribute->n_components = n_components; + attribute->type = type; if (attribute->name_state->name_id != COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY) { @@ -265,9 +259,8 @@ CoglAttributeBuffer * cogl_attribute_get_buffer (CoglAttribute *attribute) { g_return_val_if_fail (COGL_IS_ATTRIBUTE (attribute), NULL); - g_return_val_if_fail (attribute->is_buffered, NULL); - return attribute->d.buffered.attribute_buffer; + return attribute->attribute_buffer; } static gboolean @@ -388,8 +381,5 @@ _cogl_flush_attributes_state (CoglFramebuffer *framebuffer, int _cogl_attribute_get_n_components (CoglAttribute *attribute) { - if (attribute->is_buffered) - return attribute->d.buffered.n_components; - else - return attribute->d.constant.boxed.size; + return attribute->n_components; } diff --git a/cogl/cogl/driver/gl/cogl-attribute-gl.c b/cogl/cogl/driver/gl/cogl-attribute-gl.c index 7f7a72ebb..abf00f4f4 100644 --- a/cogl/cogl/driver/gl/cogl-attribute-gl.c +++ b/cogl/cogl/driver/gl/cogl-attribute-gl.c @@ -105,63 +105,15 @@ setup_generic_buffered_attribute (CoglContext *context, return; GE( context, glVertexAttribPointer (attrib_location, - attribute->d.buffered.n_components, - attribute->d.buffered.type, + attribute->n_components, + attribute->type, attribute->normalized, - attribute->d.buffered.stride, - base + attribute->d.buffered.offset) ); + attribute->stride, + base + attribute->offset) ); _cogl_bitmask_set (&context->enable_custom_attributes_tmp, attrib_location, TRUE); } -static void -setup_generic_const_attribute (CoglContext *context, - CoglPipeline *pipeline, - CoglAttribute *attribute) -{ - int name_index = attribute->name_state->name_index; - int attrib_location = - _cogl_pipeline_progend_glsl_get_attrib_location (pipeline, name_index); - int columns; - int i; - - if (attrib_location == -1) - return; - - if (attribute->d.constant.boxed.type == COGL_BOXED_MATRIX) - columns = attribute->d.constant.boxed.size; - else - columns = 1; - - /* Note: it's ok to access a COGL_BOXED_FLOAT as a matrix with only - * one column... */ - - switch (attribute->d.constant.boxed.size) - { - case 1: - GE( context, glVertexAttrib1fv (attrib_location, - attribute->d.constant.boxed.v.matrix)); - break; - case 2: - for (i = 0; i < columns; i++) - GE( context, glVertexAttrib2fv (attrib_location + i, - attribute->d.constant.boxed.v.matrix)); - break; - case 3: - for (i = 0; i < columns; i++) - GE( context, glVertexAttrib3fv (attrib_location + i, - attribute->d.constant.boxed.v.matrix)); - break; - case 4: - for (i = 0; i < columns; i++) - GE( context, glVertexAttrib4fv (attrib_location + i, - attribute->d.constant.boxed.v.matrix)); - break; - default: - g_warn_if_reached (); - } -} - static void apply_attribute_enable_updates (CoglContext *context, CoglPipeline *pipeline) @@ -273,29 +225,22 @@ _cogl_gl_flush_attributes_state (CoglDriver *driver, CoglBuffer *buffer; uint8_t *base; - if (attribute->is_buffered) - { - attribute_buffer = cogl_attribute_get_buffer (attribute); - buffer = COGL_BUFFER (attribute_buffer); + attribute_buffer = cogl_attribute_get_buffer (attribute); + buffer = COGL_BUFFER (attribute_buffer); - /* Note: we don't try and catch errors with binding buffers - * here since OOM errors at this point indicate that nothing - * has yet been uploaded to attribute buffer which we - * consider to be a programmer error. - */ - base = - _cogl_buffer_gl_bind (buffer, - COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER, - NULL); + /* Note: we don't try and catch errors with binding buffers + * here since OOM errors at this point indicate that nothing + * has yet been uploaded to attribute buffer which we + * consider to be a programmer error. + */ + base = + _cogl_buffer_gl_bind (buffer, + COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER, + NULL); - setup_generic_buffered_attribute (ctx, pipeline, attribute, base); + setup_generic_buffered_attribute (ctx, pipeline, attribute, base); - _cogl_buffer_gl_unbind (buffer); - } - else - { - setup_generic_const_attribute (ctx, pipeline, attribute); - } + _cogl_buffer_gl_unbind (buffer); } apply_attribute_enable_updates (ctx, pipeline);