cogl-vertex-attribute: Add flags to _cogl_draw_vertex_attributes_array
authorNeil Roberts <neil@linux.intel.com>
Tue, 14 Dec 2010 14:24:17 +0000 (14:24 +0000)
committerNeil Roberts <neil@linux.intel.com>
Mon, 10 Jan 2011 17:11:41 +0000 (17:11 +0000)
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

clutter/cogl/cogl/cogl-journal.c
clutter/cogl/cogl/cogl-primitives.c
clutter/cogl/cogl/cogl-vertex-attribute-private.h
clutter/cogl/cogl/cogl-vertex-attribute.c
clutter/cogl/cogl/cogl2-path.c

index 8256788..1177077 100644 (file)
@@ -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
index ad38812..392a02b 100644 (file)
@@ -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);
index 1eaf6f0..ad2777f 100644 (file)
@@ -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);
index b1652bd..73df66b 100644 (file)
@@ -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
index fc81de7..5e7d6a2 100644 (file)
@@ -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