summaryrefslogtreecommitdiff
path: root/cogl/cogl-attribute.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-02-20 15:59:48 +0000
committerRobert Bragg <robert@linux.intel.com>2012-08-06 14:27:40 +0100
commite3d6bc36d33f2900a92e805355d19d07a9ef2c83 (patch)
tree1a3679cd4e21cc6ed1a4607babf4c165018b37d1 /cogl/cogl-attribute.c
parent882ff5612b1c0e531e061e6d6daeefeb26d77fed (diff)
downloadcogl-e3d6bc36d33f2900a92e805355d19d07a9ef2c83.tar.gz
Re-design the matrix stack using a graph of ops
This re-designs the matrix stack so we now keep track of each separate operation such as rotating, scaling, translating and multiplying as immutable, ref-counted nodes in a graph. Being a "graph" here means that different transformations composed of a sequence of linked operation nodes may share nodes. The first node in a matrix-stack is always a LOAD_IDENTITY operation. As an example consider if an application where to draw three rectangles A, B and C something like this: cogl_framebuffer_scale (fb, 2, 2, 2); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_translate (fb, 10, 0, 0); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_rotate (fb, 45, 0, 0, 1); cogl_framebuffer_draw_rectangle (...); /* A */ cogl_framebuffer_pop_matrix(fb); cogl_framebuffer_draw_rectangle (...); /* B */ cogl_framebuffer_pop_matrix(fb); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_set_modelview_matrix (fb, &mv); cogl_framebuffer_draw_rectangle (...); /* C */ cogl_framebuffer_pop_matrix(fb); That would result in a graph of nodes like this: LOAD_IDENTITY | SCALE / \ SAVE LOAD | | TRANSLATE RECTANGLE(C) | \ SAVE RECTANGLE(B) | ROTATE | RECTANGLE(A) Each push adds a SAVE operation which serves as a marker to rewind too when a corresponding pop is issued and also each SAVE node may also store a cached matrix representing the composition of all its ancestor nodes. This means if we repeatedly need to resolve a real CoglMatrix for a given node then we don't need to repeat the composition. Some advantages of this design are: - A single pointer to any node in the graph can now represent a complete, immutable transformation that can be logged for example into a journal. Previously we were storing a full CoglMatrix in each journal entry which is 16 floats for the matrix itself as well as space for flags and another 16 floats for possibly storing a cache of the inverse. This means that we significantly reduce the size of the journal when drawing lots of primitives and we also avoid copying over 128 bytes per entry. - It becomes much cheaper to check for equality. In cases where some (unlikely) false negatives are allowed simply comparing the pointers of two matrix stack graph entries is enough. Previously we would use memcmp() to compare matrices. - It becomes easier to do comparisons of transformations. By looking for the common ancestry between nodes we can determine the operations that differentiate the transforms and use those to gain a high level understanding of the differences. For example we use this in the journal to be able to efficiently determine when two rectangle transforms only differ by some translation so that we can perform software clipping. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
Diffstat (limited to 'cogl/cogl-attribute.c')
-rw-r--r--cogl/cogl-attribute.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c
index 2b1a986f..57e285db 100644
--- a/cogl/cogl-attribute.c
+++ b/cogl/cogl-attribute.c
@@ -674,7 +674,10 @@ _cogl_flush_attributes_state (CoglFramebuffer *framebuffer,
_cogl_pipeline_apply_legacy_state (pipeline);
}
- _cogl_pipeline_flush_gl_state (pipeline, skip_gl_color, n_tex_coord_attribs);
+ _cogl_pipeline_flush_gl_state (pipeline,
+ framebuffer,
+ skip_gl_color,
+ n_tex_coord_attribs);
_cogl_bitmask_clear_all (&ctx->enable_builtin_attributes_tmp);
_cogl_bitmask_clear_all (&ctx->enable_texcoord_attributes_tmp);