From: Neil Roberts Date: Tue, 14 Dec 2010 14:24:17 +0000 (+0000) Subject: cogl-vertex-attribute: Add flags to _cogl_draw_vertex_attributes_array X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=159cd6ddc02b4a9a37fe7e0a61a104d3abab91a6;p=profile%2Fivi%2Fclutter.git cogl-vertex-attribute: Add flags to _cogl_draw_vertex_attributes_array There is an internal version of cogl_draw_vertex_attributes_array which previously just bypassed the framebuffer flushing, journal flushing and pipeline validation so that it could be used to draw the journal. This patch generalises the function so that it takes a set of flags to specify which parts to flush. The public version of the function now just calls the internal version with the flags set to 0. The '_real' version of the function has now been merged into the internal version of the function because it was only called in one place. This simplifies the code somewhat. The common code which flushed the various state has been moved to a separate function. The indexed versions of the functions have had a similar treatment. http://bugzilla.clutter-project.org/show_bug.cgi?id=2481 --- diff --git a/clutter/cogl/cogl/cogl-journal.c b/clutter/cogl/cogl/cogl-journal.c index 8256788..1177077 100644 --- a/clutter/cogl/cogl/cogl-journal.c +++ b/clutter/cogl/cogl/cogl-journal.c @@ -233,6 +233,10 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, { CoglJournalFlushState *state = data; CoglVertexAttribute **attributes; + static const CoglDrawFlags draw_flags = (COGL_DRAW_SKIP_JOURNAL_FLUSH | + COGL_DRAW_SKIP_PIPELINE_VALIDATION | + COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH); + COGL_STATIC_TIMER (time_flush_modelview_and_entries, "flush: pipeline+entries", /* parent */ "flush: modelview+entries", @@ -262,7 +266,8 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, /* XXX: it's rather evil that we sneak in the GL_QUADS enum here... */ _cogl_draw_vertex_attributes_array (GL_QUADS, state->current_vertex, batch_len * 4, - attributes); + attributes, + draw_flags); #else /* HAVE_COGL_GL */ if (batch_len > 1) @@ -271,13 +276,16 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, state->current_vertex * 6 / 4, batch_len * 6, state->indices, - attributes); + attributes, + draw_flags); + } else { _cogl_draw_vertex_attributes_array (COGL_VERTICES_MODE_TRIANGLE_FAN, state->current_vertex, 4, - attributes); + attributes, + draw_flags); } #endif @@ -322,7 +330,8 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start, for (i = 0; i < batch_len; i++) _cogl_draw_vertex_attributes_array (COGL_VERTICES_MODE_LINE_LOOP, 4 * i + state->current_vertex, 4, - loop_attributes); + loop_attributes, + draw_flags); /* Go to the next color */ do diff --git a/clutter/cogl/cogl/cogl-primitives.c b/clutter/cogl/cogl/cogl-primitives.c index ad38812..392a02b 100644 --- a/clutter/cogl/cogl/cogl-primitives.c +++ b/clutter/cogl/cogl/cogl-primitives.c @@ -943,7 +943,11 @@ _cogl_rectangle_immediate (float x_1, _cogl_draw_vertex_attributes_array (COGL_VERTICES_MODE_TRIANGLE_STRIP, 0, /* first_index */ 4, /* n_vertices */ - attributes); + attributes, + COGL_DRAW_SKIP_JOURNAL_FLUSH | + COGL_DRAW_SKIP_PIPELINE_VALIDATION | + COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH); + cogl_object_unref (attributes[0]); cogl_object_unref (vertex_array); diff --git a/clutter/cogl/cogl/cogl-vertex-attribute-private.h b/clutter/cogl/cogl/cogl-vertex-attribute-private.h index 1eaf6f0..ad2777f 100644 --- a/clutter/cogl/cogl/cogl-vertex-attribute-private.h +++ b/clutter/cogl/cogl/cogl-vertex-attribute-private.h @@ -57,6 +57,13 @@ struct _CoglVertexAttribute int immutable_ref; }; +typedef enum +{ + COGL_DRAW_SKIP_JOURNAL_FLUSH = 1 << 0, + COGL_DRAW_SKIP_PIPELINE_VALIDATION = 1 << 1, + COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH = 1 << 2 +} CoglDrawFlags; + CoglVertexAttribute * _cogl_vertex_attribute_immutable_ref (CoglVertexAttribute *vertex_attribute); @@ -67,14 +74,16 @@ void _cogl_draw_vertex_attributes_array (CoglVerticesMode mode, int first_vertex, int n_vertices, - CoglVertexAttribute **attributes); + CoglVertexAttribute **attributes, + CoglDrawFlags flags); void _cogl_draw_indexed_vertex_attributes_array (CoglVerticesMode mode, int first_vertex, int n_vertices, CoglIndices *indices, - CoglVertexAttribute **attributes); + CoglVertexAttribute **attributes, + CoglDrawFlags flags); void _cogl_vertex_attribute_disable_cached_arrays (void); diff --git a/clutter/cogl/cogl/cogl-vertex-attribute.c b/clutter/cogl/cogl/cogl-vertex-attribute.c index b1652bd..73df66b 100644 --- a/clutter/cogl/cogl/cogl-vertex-attribute.c +++ b/clutter/cogl/cogl/cogl-vertex-attribute.c @@ -1028,7 +1028,11 @@ draw_wireframe (CoglVerticesMode mode, _cogl_draw_vertex_attributes_array (COGL_VERTICES_MODE_LINES, 0, n_line_vertices, - wire_attribute); + wire_attribute, + COGL_DRAW_SKIP_JOURNAL_FLUSH | + COGL_DRAW_SKIP_PIPELINE_VALIDATION | + COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH); + cogl_debug_flags |= COGL_DEBUG_WIREFRAME; cogl_pop_source (); @@ -1038,43 +1042,58 @@ draw_wireframe (CoglVerticesMode mode, #endif static void -_cogl_draw_vertex_attributes_array_real (CoglVerticesMode mode, - int first_vertex, - int n_vertices, - CoglVertexAttribute **attributes, - ValidateLayerState *state) +flush_state (CoglDrawFlags flags, + ValidateLayerState *state) { - CoglPipeline *source = enable_gl_state (attributes, state); + if (!(flags & COGL_DRAW_SKIP_JOURNAL_FLUSH)) + _cogl_journal_flush (); - GE (glDrawArrays ((GLenum)mode, first_vertex, n_vertices)); + state->unit = 0; + state->options.flags = 0; + state->fallback_layers = 0; - /* FIXME: we shouldn't be disabling state after drawing we should - * just disable the things not needed after enabling state. */ - disable_gl_state (attributes, source); + if (!(flags & COGL_DRAW_SKIP_PIPELINE_VALIDATION)) + cogl_pipeline_foreach_layer (cogl_get_source (), + validate_layer_cb, + state); -#ifdef COGL_ENABLE_DEBUG - if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_WIREFRAME)) - draw_wireframe (mode, first_vertex, n_vertices, attributes, NULL); -#endif + /* NB: _cogl_framebuffer_flush_state may disrupt various state (such + * as the pipeline state) when flushing the clip stack, so should + * always be done first when preparing to draw. We need to do this + * before setting up the array pointers because setting up the clip + * stack can cause some drawing which would change the array + * pointers. */ + if (!(flags & COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH)) + _cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0); } -/* This can be used by the CoglJournal to draw attributes skipping the - * implicit journal flush, the framebuffer flush and pipeline - * validation. */ +/* This can be called directly by the CoglJournal to draw attributes + * skipping the implicit journal flush, the framebuffer flush and + * pipeline validation. */ void _cogl_draw_vertex_attributes_array (CoglVerticesMode mode, int first_vertex, int n_vertices, - CoglVertexAttribute **attributes) + CoglVertexAttribute **attributes, + CoglDrawFlags flags) { ValidateLayerState state; + CoglPipeline *source; + + flush_state (flags, &state); + + source = enable_gl_state (attributes, &state); + + GE (glDrawArrays ((GLenum)mode, first_vertex, n_vertices)); - state.unit = 0; - state.options.flags = 0; - state.fallback_layers = 0; + /* FIXME: we shouldn't be disabling state after drawing we should + * just disable the things not needed after enabling state. */ + disable_gl_state (attributes, source); - _cogl_draw_vertex_attributes_array_real (mode, first_vertex, n_vertices, - attributes, &state); +#ifdef COGL_ENABLE_DEBUG + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_WIREFRAME)) + draw_wireframe (mode, first_vertex, n_vertices, attributes, NULL); +#endif } void @@ -1083,30 +1102,9 @@ cogl_draw_vertex_attributes_array (CoglVerticesMode mode, int n_vertices, CoglVertexAttribute **attributes) { - ValidateLayerState state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - _cogl_journal_flush (); - - state.unit = 0; - state.options.flags = 0; - state.fallback_layers = 0; - - cogl_pipeline_foreach_layer (cogl_get_source (), - validate_layer_cb, - &state); - - /* NB: _cogl_framebuffer_flush_state may disrupt various state (such - * as the pipeline state) when flushing the clip stack, so should - * always be done first when preparing to draw. We need to do this - * before setting up the array pointers because setting up the clip - * stack can cause some drawing which would change the array - * pointers. */ - _cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0); - - _cogl_draw_vertex_attributes_array_real (mode, first_vertex, n_vertices, - attributes, &state); + _cogl_draw_vertex_attributes_array (mode, first_vertex, + n_vertices, attributes, + 0 /* no flags */); } void @@ -1153,15 +1151,16 @@ sizeof_index_type (CoglIndicesType type) g_return_val_if_reached (0); } -static void -_cogl_draw_indexed_vertex_attributes_array_real (CoglVerticesMode mode, - int first_vertex, - int n_vertices, - CoglIndices *indices, - CoglVertexAttribute **attributes, - ValidateLayerState *state) +void +_cogl_draw_indexed_vertex_attributes_array (CoglVerticesMode mode, + int first_vertex, + int n_vertices, + CoglIndices *indices, + CoglVertexAttribute **attributes, + CoglDrawFlags flags) { - CoglPipeline *source = enable_gl_state (attributes, state); + ValidateLayerState state; + CoglPipeline *source; CoglBuffer *buffer; void *base; size_t array_offset; @@ -1170,6 +1169,10 @@ _cogl_draw_indexed_vertex_attributes_array_real (CoglVerticesMode mode, _COGL_GET_CONTEXT (ctx, NO_RETVAL); + flush_state (flags, &state); + + source = enable_gl_state (attributes, &state); + buffer = COGL_BUFFER (cogl_indices_get_array (indices)); base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_ARRAY); array_offset = cogl_indices_get_offset (indices); @@ -1206,61 +1209,15 @@ _cogl_draw_indexed_vertex_attributes_array_real (CoglVerticesMode mode, } void -_cogl_draw_indexed_vertex_attributes_array (CoglVerticesMode mode, - int first_vertex, - int n_vertices, - CoglIndices *indices, - CoglVertexAttribute **attributes) -{ - ValidateLayerState state; - - state.unit = 0; - state.options.flags = 0; - state.fallback_layers = 0; - - _cogl_draw_indexed_vertex_attributes_array_real (mode, - first_vertex, - n_vertices, - indices, - attributes, - &state); -} - -void cogl_draw_indexed_vertex_attributes_array (CoglVerticesMode mode, int first_vertex, int n_vertices, CoglIndices *indices, CoglVertexAttribute **attributes) { - ValidateLayerState state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - _cogl_journal_flush (); - - state.unit = 0; - state.options.flags = 0; - state.fallback_layers = 0; - - cogl_pipeline_foreach_layer (cogl_get_source (), - validate_layer_cb, - &state); - - /* NB: _cogl_framebuffer_flush_state may disrupt various state (such - * as the pipeline state) when flushing the clip stack, so should - * always be done first when preparing to draw. We need to do this - * before setting up the array pointers because setting up the clip - * stack can cause some drawing which would change the array - * pointers. */ - _cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0); - - _cogl_draw_indexed_vertex_attributes_array_real (mode, - first_vertex, - n_vertices, - indices, - attributes, - &state); + _cogl_draw_indexed_vertex_attributes_array (mode, first_vertex, + n_vertices, indices, attributes, + 0 /* no flags */); } void diff --git a/clutter/cogl/cogl/cogl2-path.c b/clutter/cogl/cogl/cogl2-path.c index fc81de7..5e7d6a2 100644 --- a/clutter/cogl/cogl/cogl2-path.c +++ b/clutter/cogl/cogl/cogl2-path.c @@ -338,11 +338,15 @@ _cogl_path_fill_nodes (CoglPath *path) _cogl_path_build_fill_vbo (path); - _cogl_draw_indexed_vertex_attributes_array (COGL_VERTICES_MODE_TRIANGLES, - 0, /* first_vertex */ - path->data->fill_vbo_n_indices, - path->data->fill_vbo_indices, - path->data->fill_vbo_attributes); + _cogl_draw_indexed_vertex_attributes_array + (COGL_VERTICES_MODE_TRIANGLES, + 0, /* first_vertex */ + path->data->fill_vbo_n_indices, + path->data->fill_vbo_indices, + path->data->fill_vbo_attributes, + COGL_DRAW_SKIP_JOURNAL_FLUSH | + COGL_DRAW_SKIP_PIPELINE_VALIDATION | + COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH); } void