2009-09-16 13:01:57 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-09-16 13:01:57 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2009-09-16 13:01:57 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-07-25 20:36:41 +00:00
|
|
|
#include "cogl-debug.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2009-09-16 13:01:57 +00:00
|
|
|
#include "cogl-journal-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline-private.h"
|
2009-11-26 19:06:35 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2009-07-03 15:22:35 +00:00
|
|
|
#include "cogl-profile.h"
|
2011-01-20 19:31:53 +00:00
|
|
|
#include "cogl-attribute-private.h"
|
2011-01-12 22:12:41 +00:00
|
|
|
#include "cogl-point-in-poly-private.h"
|
2011-09-14 11:17:09 +00:00
|
|
|
#include "cogl-private.h"
|
2012-02-17 21:46:39 +00:00
|
|
|
#include "cogl1-context.h"
|
2018-05-21 19:57:38 +00:00
|
|
|
#include "driver/gl/cogl-pipeline-opengl-private.h"
|
|
|
|
#include "deprecated/cogl-vertex-buffer-private.h"
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* XXX NB:
|
2010-11-25 21:08:45 +00:00
|
|
|
* The data logged in logged_vertices is formatted as follows:
|
|
|
|
*
|
|
|
|
* Per entry:
|
|
|
|
* 4 RGBA GLubytes for the color
|
|
|
|
* 2 floats for the top left position
|
|
|
|
* 2 * n_layers floats for the top left texture coordinates
|
|
|
|
* 2 floats for the bottom right position
|
|
|
|
* 2 * n_layers floats for the bottom right texture coordinates
|
|
|
|
*/
|
|
|
|
#define GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS(N_LAYERS) \
|
|
|
|
(N_LAYERS * 2 + 2)
|
|
|
|
|
|
|
|
/* XXX NB:
|
|
|
|
* Once in the vertex array, the journal's vertex data is arranged as follows:
|
2009-09-16 13:01:57 +00:00
|
|
|
* 4 vertices per quad:
|
|
|
|
* 2 or 3 GLfloats per position (3 when doing software transforms)
|
|
|
|
* 4 RGBA GLubytes,
|
|
|
|
* 2 GLfloats per tex coord * n_layers
|
|
|
|
*
|
2010-10-27 17:54:57 +00:00
|
|
|
* Where n_layers corresponds to the number of pipeline layers enabled
|
2009-09-16 13:01:57 +00:00
|
|
|
*
|
|
|
|
* To avoid frequent changes in the stride of our vertex data we always pad
|
|
|
|
* n_layers to be >= 2
|
|
|
|
*
|
2010-11-25 21:08:45 +00:00
|
|
|
* There will be four vertices per quad in the vertex array
|
|
|
|
*
|
2009-09-16 13:01:57 +00:00
|
|
|
* When we are transforming quads in software we need to also track the z
|
|
|
|
* coordinate of transformed vertices.
|
|
|
|
*
|
|
|
|
* So for a given number of layers this gets the stride in 32bit words:
|
|
|
|
*/
|
2011-01-24 14:28:00 +00:00
|
|
|
#define SW_TRANSFORM (!(COGL_DEBUG_ENABLED \
|
|
|
|
(COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))
|
2009-09-16 13:01:57 +00:00
|
|
|
#define POS_STRIDE (SW_TRANSFORM ? 3 : 2) /* number of 32bit words */
|
|
|
|
#define N_POS_COMPONENTS POS_STRIDE
|
|
|
|
#define COLOR_STRIDE 1 /* number of 32bit words */
|
|
|
|
#define TEX_STRIDE 2 /* number of 32bit words */
|
|
|
|
#define MIN_LAYER_PADING 2
|
|
|
|
#define GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS(N_LAYERS) \
|
|
|
|
(POS_STRIDE + COLOR_STRIDE + \
|
|
|
|
TEX_STRIDE * (N_LAYERS < MIN_LAYER_PADING ? MIN_LAYER_PADING : N_LAYERS))
|
|
|
|
|
2010-11-09 19:18:37 +00:00
|
|
|
/* If a batch is longer than this threshold then we'll assume it's not
|
|
|
|
worth doing software clipping and it's cheaper to program the GPU
|
|
|
|
to do the clip */
|
|
|
|
#define COGL_JOURNAL_HARDWARE_CLIP_THRESHOLD 8
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
typedef struct _CoglJournalFlushState
|
|
|
|
{
|
2012-11-09 00:57:14 +00:00
|
|
|
CoglContext *ctx;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglJournal *journal;
|
2011-01-06 13:25:45 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
GArray *attributes;
|
|
|
|
int current_attribute;
|
2010-10-26 18:22:57 +00:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t stride;
|
|
|
|
size_t array_offset;
|
|
|
|
GLuint current_vertex;
|
2011-07-07 19:44:56 +00:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglIndices *indices;
|
|
|
|
size_t indices_type_size;
|
2011-07-07 19:44:56 +00:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglPipeline *pipeline;
|
2009-09-16 13:01:57 +00:00
|
|
|
} CoglJournalFlushState;
|
|
|
|
|
|
|
|
typedef void (*CoglJournalBatchCallback) (CoglJournalEntry *start,
|
|
|
|
int n_entries,
|
|
|
|
void *data);
|
2018-11-24 12:04:47 +00:00
|
|
|
typedef gboolean (*CoglJournalBatchTest) (CoglJournalEntry *entry0,
|
2009-09-16 13:01:57 +00:00
|
|
|
CoglJournalEntry *entry1);
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
static void _cogl_journal_free (CoglJournal *journal);
|
|
|
|
|
2012-03-06 18:21:28 +00:00
|
|
|
COGL_OBJECT_INTERNAL_DEFINE (Journal, journal);
|
2011-01-06 13:25:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_journal_free (CoglJournal *journal)
|
|
|
|
{
|
2011-06-01 13:30:45 +00:00
|
|
|
int i;
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
if (journal->entries)
|
|
|
|
g_array_free (journal->entries, TRUE);
|
|
|
|
if (journal->vertices)
|
|
|
|
g_array_free (journal->vertices, TRUE);
|
2011-06-01 13:30:45 +00:00
|
|
|
|
|
|
|
for (i = 0; i < COGL_JOURNAL_VBO_POOL_SIZE; i++)
|
|
|
|
if (journal->vbo_pool[i])
|
|
|
|
cogl_object_unref (journal->vbo_pool[i]);
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
g_slice_free (CoglJournal, journal);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglJournal *
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_journal_new (CoglFramebuffer *framebuffer)
|
2011-01-06 13:25:45 +00:00
|
|
|
{
|
|
|
|
CoglJournal *journal = g_slice_new0 (CoglJournal);
|
|
|
|
|
2012-03-16 17:26:30 +00:00
|
|
|
/* The journal keeps a pointer back to the framebuffer because there
|
|
|
|
is effectively a 1:1 mapping between journals and framebuffers.
|
|
|
|
However, to avoid a circular reference the journal doesn't take a
|
|
|
|
reference unless it is non-empty. The framebuffer has a special
|
|
|
|
unref implementation to ensure that the journal is flushed when
|
|
|
|
the journal is the only thing keeping it alive */
|
|
|
|
journal->framebuffer = framebuffer;
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
journal->entries = g_array_new (FALSE, FALSE, sizeof (CoglJournalEntry));
|
|
|
|
journal->vertices = g_array_new (FALSE, FALSE, sizeof (float));
|
|
|
|
|
2013-06-08 22:03:25 +00:00
|
|
|
_cogl_list_init (&journal->pending_fences);
|
2013-01-11 01:13:34 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
return _cogl_journal_object_new (journal);
|
|
|
|
}
|
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_journal_dump_logged_quad (uint8_t *data, int n_layers)
|
2010-11-25 21:08:45 +00:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t stride = GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS (n_layers);
|
2010-11-25 21:08:45 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_print ("n_layers = %d; rgba=0x%02X%02X%02X%02X\n",
|
|
|
|
n_layers, data[0], data[1], data[2], data[3]);
|
|
|
|
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
float *v = (float *)data + (i * stride);
|
|
|
|
int j;
|
|
|
|
|
|
|
|
g_print ("v%d: x = %f, y = %f", i, v[0], v[1]);
|
|
|
|
|
|
|
|
for (j = 0; j < n_layers; j++)
|
|
|
|
{
|
|
|
|
float *t = v + 2 + TEX_STRIDE * j;
|
|
|
|
g_print (", tx%d = %f, ty%d = %f", j, t[0], j, t[1]);
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_journal_dump_quad_vertices (uint8_t *data, int n_layers)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t stride = GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS (n_layers);
|
2009-09-16 13:01:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_print ("n_layers = %d; stride = %d; pos stride = %d; color stride = %d; "
|
|
|
|
"tex stride = %d; stride in bytes = %d\n",
|
|
|
|
n_layers, (int)stride, POS_STRIDE, COLOR_STRIDE,
|
|
|
|
TEX_STRIDE, (int)stride * 4);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
float *v = (float *)data + (i * stride);
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *c = data + (POS_STRIDE * 4) + (i * stride * 4);
|
2009-09-16 13:01:57 +00:00
|
|
|
int j;
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED
|
|
|
|
(COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))
|
2009-09-16 13:01:57 +00:00
|
|
|
g_print ("v%d: x = %f, y = %f, rgba=0x%02X%02X%02X%02X",
|
|
|
|
i, v[0], v[1], c[0], c[1], c[2], c[3]);
|
|
|
|
else
|
|
|
|
g_print ("v%d: x = %f, y = %f, z = %f, rgba=0x%02X%02X%02X%02X",
|
|
|
|
i, v[0], v[1], v[2], c[0], c[1], c[2], c[3]);
|
|
|
|
for (j = 0; j < n_layers; j++)
|
|
|
|
{
|
|
|
|
float *t = v + POS_STRIDE + COLOR_STRIDE + TEX_STRIDE * j;
|
|
|
|
g_print (", tx%d = %f, ty%d = %f", j, t[0], j, t[1]);
|
|
|
|
}
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_journal_dump_quad_batch (uint8_t *data, int n_layers, int n_quads)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t byte_stride = GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS (n_layers) * 4;
|
2009-09-16 13:01:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
g_print ("_cogl_journal_dump_quad_batch: n_layers = %d, n_quads = %d\n",
|
|
|
|
n_layers, n_quads);
|
|
|
|
for (i = 0; i < n_quads; i++)
|
2010-11-25 21:08:45 +00:00
|
|
|
_cogl_journal_dump_quad_vertices (data + byte_stride * 2 * i, n_layers);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
batch_and_call (CoglJournalEntry *entries,
|
|
|
|
int n_entries,
|
|
|
|
CoglJournalBatchTest can_batch_callback,
|
|
|
|
CoglJournalBatchCallback batch_callback,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int batch_len = 1;
|
|
|
|
CoglJournalEntry *batch_start = entries;
|
|
|
|
|
2009-12-03 17:13:44 +00:00
|
|
|
if (n_entries < 1)
|
|
|
|
return;
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
for (i = 1; i < n_entries; i++)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *entry0 = &entries[i - 1];
|
|
|
|
CoglJournalEntry *entry1 = entry0 + 1;
|
|
|
|
|
|
|
|
if (can_batch_callback (entry0, entry1))
|
|
|
|
{
|
|
|
|
batch_len++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
batch_callback (batch_start, batch_len, data);
|
|
|
|
|
|
|
|
batch_start = entry1;
|
|
|
|
batch_len = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The last batch... */
|
|
|
|
batch_callback (batch_start, batch_len, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
|
|
|
|
int batch_len,
|
|
|
|
void *data)
|
|
|
|
{
|
2010-10-26 18:22:57 +00:00
|
|
|
CoglJournalFlushState *state = data;
|
2012-11-09 00:57:14 +00:00
|
|
|
CoglContext *ctx = state->ctx;
|
2012-03-16 17:26:30 +00:00
|
|
|
CoglFramebuffer *framebuffer = state->journal->framebuffer;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes;
|
2010-12-14 14:44:45 +00:00
|
|
|
CoglDrawFlags draw_flags = (COGL_DRAW_SKIP_JOURNAL_FLUSH |
|
|
|
|
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
|
2012-01-08 02:59:04 +00:00
|
|
|
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH |
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
2010-12-14 14:24:17 +00:00
|
|
|
|
2010-07-26 14:21:18 +00:00
|
|
|
COGL_STATIC_TIMER (time_flush_modelview_and_entries,
|
2010-10-27 17:54:57 +00:00
|
|
|
"flush: pipeline+entries", /* parent */
|
2010-07-26 14:21:18 +00:00
|
|
|
"flush: modelview+entries",
|
|
|
|
"The time spent flushing modelview + entries",
|
|
|
|
0 /* no application private data */);
|
2010-10-26 18:22:57 +00:00
|
|
|
|
2010-07-26 14:21:18 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context, time_flush_modelview_and_entries);
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_BATCHING)))
|
2010-11-02 17:35:17 +00:00
|
|
|
g_print ("BATCHING: modelview batch len = %d\n", batch_len);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
_cogl_context_set_current_modelview_entry (ctx,
|
|
|
|
batch_start->modelview_entry);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attributes = (CoglAttribute **)state->attributes->data;
|
2010-10-26 18:22:57 +00:00
|
|
|
|
2012-01-08 03:00:57 +00:00
|
|
|
if (!_cogl_pipeline_get_real_blend_enabled (state->pipeline))
|
2010-12-14 14:44:45 +00:00
|
|
|
draw_flags |= COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE;
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
#ifdef HAVE_COGL_GL
|
2013-11-25 16:11:36 +00:00
|
|
|
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_QUADS))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2011-07-07 19:44:56 +00:00
|
|
|
/* XXX: it's rather evil that we sneak in the GL_QUADS enum here... */
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
2012-01-08 03:00:57 +00:00
|
|
|
state->pipeline,
|
2012-01-08 02:59:04 +00:00
|
|
|
GL_QUADS,
|
|
|
|
state->current_vertex, batch_len * 4,
|
|
|
|
attributes,
|
|
|
|
state->attributes->len,
|
|
|
|
draw_flags);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
2011-07-07 19:44:56 +00:00
|
|
|
else
|
|
|
|
#endif /* HAVE_COGL_GL */
|
|
|
|
{
|
|
|
|
if (batch_len > 1)
|
|
|
|
{
|
2012-01-08 02:59:04 +00:00
|
|
|
CoglVerticesMode mode = COGL_VERTICES_MODE_TRIANGLES;
|
|
|
|
int first_vertex = state->current_vertex * 6 / 4;
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
|
2012-01-08 03:00:57 +00:00
|
|
|
state->pipeline,
|
2012-01-08 02:59:04 +00:00
|
|
|
mode,
|
|
|
|
first_vertex,
|
|
|
|
batch_len * 6,
|
|
|
|
state->indices,
|
|
|
|
attributes,
|
|
|
|
state->attributes->len,
|
|
|
|
draw_flags);
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
2012-01-08 03:00:57 +00:00
|
|
|
state->pipeline,
|
2012-01-08 02:59:04 +00:00
|
|
|
COGL_VERTICES_MODE_TRIANGLE_FAN,
|
|
|
|
state->current_vertex, 4,
|
|
|
|
attributes,
|
|
|
|
state->attributes->len,
|
|
|
|
draw_flags);
|
2011-07-07 19:44:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-01-22 18:14:57 +00:00
|
|
|
/* DEBUGGING CODE XXX: This path will cause all rectangles to be
|
|
|
|
* drawn with a coloured outline. Each batch will be rendered with
|
|
|
|
* the same color. This may e.g. help with debugging texture slicing
|
|
|
|
* issues, visually seeing what is batched and debugging blending
|
|
|
|
* issues, plus it looks quite cool.
|
2009-09-16 13:01:57 +00:00
|
|
|
*/
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_RECTANGLES)))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
static CoglPipeline *outline = NULL;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t color_intensity;
|
2009-09-16 13:01:57 +00:00
|
|
|
int i;
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *loop_attributes[1];
|
2010-01-22 18:14:57 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
if (outline == NULL)
|
2012-11-09 00:57:14 +00:00
|
|
|
outline = cogl_pipeline_new (ctx);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-01-22 18:14:57 +00:00
|
|
|
/* The least significant three bits represent the three
|
|
|
|
components so that the order of colours goes red, green,
|
|
|
|
yellow, blue, magenta, cyan. Black and white are skipped. The
|
|
|
|
next two bits give four scales of intensity for those colours
|
|
|
|
in the order 0xff, 0xcc, 0x99, and 0x66. This gives a total
|
|
|
|
of 24 colours. If there are more than 24 batches on the stage
|
|
|
|
then it will wrap around */
|
2012-11-09 00:57:14 +00:00
|
|
|
color_intensity = 0xff - 0x33 * (ctx->journal_rectangles_color >> 3);
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_pipeline_set_color4ub (outline,
|
2012-11-09 00:57:14 +00:00
|
|
|
(ctx->journal_rectangles_color & 1) ?
|
2010-01-22 18:14:57 +00:00
|
|
|
color_intensity : 0,
|
2012-11-09 00:57:14 +00:00
|
|
|
(ctx->journal_rectangles_color & 2) ?
|
2010-01-22 18:14:57 +00:00
|
|
|
color_intensity : 0,
|
2012-11-09 00:57:14 +00:00
|
|
|
(ctx->journal_rectangles_color & 4) ?
|
2010-01-22 18:14:57 +00:00
|
|
|
color_intensity : 0,
|
|
|
|
0xff);
|
2010-10-26 18:22:57 +00:00
|
|
|
|
|
|
|
loop_attributes[0] = attributes[0]; /* we just want the position */
|
2010-01-22 18:14:57 +00:00
|
|
|
for (i = 0; i < batch_len; i++)
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
2012-01-08 02:59:04 +00:00
|
|
|
outline,
|
|
|
|
COGL_VERTICES_MODE_LINE_LOOP,
|
|
|
|
4 * i + state->current_vertex, 4,
|
|
|
|
loop_attributes,
|
|
|
|
1,
|
|
|
|
draw_flags);
|
2010-01-22 18:14:57 +00:00
|
|
|
|
|
|
|
/* Go to the next color */
|
|
|
|
do
|
2012-11-09 00:57:14 +00:00
|
|
|
ctx->journal_rectangles_color = ((ctx->journal_rectangles_color + 1) &
|
|
|
|
((1 << 5) - 1));
|
2010-01-22 18:14:57 +00:00
|
|
|
/* We don't want to use black or white */
|
2012-11-09 00:57:14 +00:00
|
|
|
while ((ctx->journal_rectangles_color & 0x07) == 0
|
|
|
|
|| (ctx->journal_rectangles_color & 0x07) == 0x07);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 18:22:57 +00:00
|
|
|
state->current_vertex += (4 * batch_len);
|
|
|
|
|
2010-07-26 14:21:18 +00:00
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, time_flush_modelview_and_entries);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2009-09-16 13:01:57 +00:00
|
|
|
compare_entry_modelviews (CoglJournalEntry *entry0,
|
|
|
|
CoglJournalEntry *entry1)
|
|
|
|
{
|
|
|
|
/* Batch together quads with the same model view matrix */
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
return entry0->modelview_entry == entry1->modelview_entry;
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point we have a run of quads that we know have compatible
|
2010-10-27 17:54:57 +00:00
|
|
|
* pipelines, but they may not all have the same modelview matrix */
|
2009-09-16 13:01:57 +00:00
|
|
|
static void
|
2010-10-27 17:54:57 +00:00
|
|
|
_cogl_journal_flush_pipeline_and_entries (CoglJournalEntry *batch_start,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
int batch_len,
|
2009-09-16 13:01:57 +00:00
|
|
|
void *data)
|
|
|
|
{
|
2010-10-26 18:22:57 +00:00
|
|
|
CoglJournalFlushState *state = data;
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_STATIC_TIMER (time_flush_pipeline_entries,
|
|
|
|
"flush: texcoords+pipeline+entries", /* parent */
|
|
|
|
"flush: pipeline+entries",
|
|
|
|
"The time spent flushing pipeline + entries",
|
2010-07-26 14:21:18 +00:00
|
|
|
0 /* no application private data */);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context, time_flush_pipeline_entries);
|
2010-07-26 14:21:18 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_BATCHING)))
|
2010-11-02 17:35:17 +00:00
|
|
|
g_print ("BATCHING: pipeline batch len = %d\n", batch_len);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2012-01-08 03:00:57 +00:00
|
|
|
state->pipeline = batch_start->pipeline;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
/* If we haven't transformed the quads in software then we need to also break
|
|
|
|
* up batches according to changes in the modelview matrix... */
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
|
|
|
batch_and_call (batch_start,
|
|
|
|
batch_len,
|
|
|
|
compare_entry_modelviews,
|
|
|
|
_cogl_journal_flush_modelview_and_entries,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_cogl_journal_flush_modelview_and_entries (batch_start, batch_len, data);
|
2010-07-26 14:21:18 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, time_flush_pipeline_entries);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2010-10-27 17:54:57 +00:00
|
|
|
compare_entry_pipelines (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
/* batch rectangles using compatible pipelines */
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
if (_cogl_pipeline_equal (entry0->pipeline,
|
|
|
|
entry1->pipeline,
|
2010-12-03 11:36:49 +00:00
|
|
|
(COGL_PIPELINE_STATE_ALL &
|
|
|
|
~COGL_PIPELINE_STATE_COLOR),
|
|
|
|
COGL_PIPELINE_LAYER_STATE_ALL,
|
|
|
|
0))
|
2009-09-16 13:01:57 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-27 10:06:16 +00:00
|
|
|
typedef struct _CreateAttributeState
|
|
|
|
{
|
|
|
|
int current;
|
|
|
|
CoglJournalFlushState *flush_state;
|
|
|
|
} CreateAttributeState;
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-09-27 10:06:16 +00:00
|
|
|
create_attribute_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_number,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CreateAttributeState *state = user_data;
|
|
|
|
CoglJournalFlushState *flush_state = state->flush_state;
|
|
|
|
CoglAttribute **attribute_entry =
|
|
|
|
&g_array_index (flush_state->attributes,
|
|
|
|
CoglAttribute *,
|
|
|
|
state->current + 2);
|
|
|
|
const char *names[] = {
|
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
"cogl_tex_coord1_in",
|
|
|
|
"cogl_tex_coord2_in",
|
|
|
|
"cogl_tex_coord3_in",
|
|
|
|
"cogl_tex_coord4_in",
|
|
|
|
"cogl_tex_coord5_in",
|
|
|
|
"cogl_tex_coord6_in",
|
|
|
|
"cogl_tex_coord7_in"
|
|
|
|
};
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
/* XXX NB:
|
|
|
|
* Our journal's vertex data is arranged as follows:
|
|
|
|
* 4 vertices per quad:
|
|
|
|
* 2 or 3 floats per position (3 when doing software transforms)
|
|
|
|
* 4 RGBA bytes,
|
|
|
|
* 2 floats per tex coord * n_layers
|
|
|
|
* (though n_layers may be padded; see definition of
|
|
|
|
* GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS for details)
|
|
|
|
*/
|
|
|
|
name = layer_number < 8 ? (char *)names[layer_number] :
|
|
|
|
g_strdup_printf ("cogl_tex_coord%d_in", layer_number);
|
|
|
|
|
|
|
|
/* XXX: it may be worth having some form of static initializer for
|
|
|
|
* attributes... */
|
|
|
|
*attribute_entry =
|
|
|
|
cogl_attribute_new (flush_state->attribute_buffer,
|
|
|
|
name,
|
|
|
|
flush_state->stride,
|
|
|
|
flush_state->array_offset +
|
|
|
|
(POS_STRIDE + COLOR_STRIDE) * 4 +
|
|
|
|
TEX_STRIDE * 4 * state->current,
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
|
|
|
|
if (layer_number >= 8)
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
state->current++;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
/* Since the stride may not reflect the number of texture layers in use
|
|
|
|
* (due to padding) we deal with texture coordinate offsets separately
|
|
|
|
* from vertex and color offsets... */
|
|
|
|
static void
|
|
|
|
_cogl_journal_flush_texcoord_vbo_offsets_and_entries (
|
|
|
|
CoglJournalEntry *batch_start,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
int batch_len,
|
2009-09-16 13:01:57 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglJournalFlushState *state = data;
|
2012-09-27 10:06:16 +00:00
|
|
|
CreateAttributeState create_attrib_state;
|
|
|
|
int i;
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_STATIC_TIMER (time_flush_texcoord_pipeline_entries,
|
|
|
|
"flush: vbo+texcoords+pipeline+entries", /* parent */
|
|
|
|
"flush: texcoords+pipeline+entries",
|
|
|
|
"The time spent flushing texcoord offsets + pipeline "
|
2010-07-26 14:21:18 +00:00
|
|
|
"+ entries",
|
|
|
|
0 /* no application private data */);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context, time_flush_texcoord_pipeline_entries);
|
2010-07-26 14:21:18 +00:00
|
|
|
|
2010-10-26 18:22:57 +00:00
|
|
|
/* NB: attributes 0 and 1 are position and color */
|
|
|
|
|
|
|
|
for (i = 2; i < state->attributes->len; i++)
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i));
|
2010-10-26 18:22:57 +00:00
|
|
|
|
|
|
|
g_array_set_size (state->attributes, batch_start->n_layers + 2);
|
|
|
|
|
2012-09-27 10:06:16 +00:00
|
|
|
create_attrib_state.current = 0;
|
|
|
|
create_attrib_state.flush_state = state;
|
|
|
|
|
|
|
|
cogl_pipeline_foreach_layer (batch_start->pipeline,
|
|
|
|
create_attribute_cb,
|
|
|
|
&create_attrib_state);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
batch_and_call (batch_start,
|
|
|
|
batch_len,
|
2010-10-27 17:54:57 +00:00
|
|
|
compare_entry_pipelines,
|
|
|
|
_cogl_journal_flush_pipeline_and_entries,
|
2009-09-16 13:01:57 +00:00
|
|
|
data);
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, time_flush_texcoord_pipeline_entries);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-09-27 10:06:16 +00:00
|
|
|
compare_entry_layer_numbers (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2012-09-27 10:06:16 +00:00
|
|
|
if (_cogl_pipeline_layer_numbers_equal (entry0->pipeline, entry1->pipeline))
|
2009-09-16 13:01:57 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point we know the stride has changed from the previous batch
|
|
|
|
* of journal entries */
|
|
|
|
static void
|
|
|
|
_cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
int batch_len,
|
2009-09-16 13:01:57 +00:00
|
|
|
void *data)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglJournalFlushState *state = data;
|
|
|
|
CoglContext *ctx = state->journal->framebuffer->context;
|
|
|
|
size_t stride;
|
|
|
|
int i;
|
|
|
|
CoglAttribute **attribute_entry;
|
2010-10-27 17:54:57 +00:00
|
|
|
COGL_STATIC_TIMER (time_flush_vbo_texcoord_pipeline_entries,
|
2010-11-02 17:35:17 +00:00
|
|
|
"flush: clip+vbo+texcoords+pipeline+entries", /* parent */
|
2010-10-27 17:54:57 +00:00
|
|
|
"flush: vbo+texcoords+pipeline+entries",
|
2010-07-26 14:21:18 +00:00
|
|
|
"The time spent flushing vbo + texcoord offsets + "
|
2010-10-27 17:54:57 +00:00
|
|
|
"pipeline + entries",
|
2010-07-26 14:21:18 +00:00
|
|
|
0 /* no application private data */);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-07-26 14:21:18 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context,
|
2010-10-27 17:54:57 +00:00
|
|
|
time_flush_vbo_texcoord_pipeline_entries);
|
2010-07-26 14:21:18 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_BATCHING)))
|
2010-11-02 17:35:17 +00:00
|
|
|
g_print ("BATCHING: vbo offset batch len = %d\n", batch_len);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
/* XXX NB:
|
|
|
|
* Our journal's vertex data is arranged as follows:
|
|
|
|
* 4 vertices per quad:
|
|
|
|
* 2 or 3 GLfloats per position (3 when doing software transforms)
|
|
|
|
* 4 RGBA GLubytes,
|
|
|
|
* 2 GLfloats per tex coord * n_layers
|
|
|
|
* (though n_layers may be padded; see definition of
|
|
|
|
* GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS for details)
|
|
|
|
*/
|
|
|
|
stride = GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS (batch_start->n_layers);
|
2010-10-26 18:22:57 +00:00
|
|
|
stride *= sizeof (float);
|
2009-09-16 13:01:57 +00:00
|
|
|
state->stride = stride;
|
|
|
|
|
2010-10-26 18:22:57 +00:00
|
|
|
for (i = 0; i < state->attributes->len; i++)
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i));
|
2010-10-26 18:22:57 +00:00
|
|
|
|
|
|
|
g_array_set_size (state->attributes, 2);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attribute_entry = &g_array_index (state->attributes, CoglAttribute *, 0);
|
2011-03-02 15:01:41 +00:00
|
|
|
*attribute_entry = cogl_attribute_new (state->attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_position_in",
|
|
|
|
stride,
|
|
|
|
state->array_offset,
|
|
|
|
N_POS_COMPONENTS,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
|
|
|
|
|
|
|
attribute_entry = &g_array_index (state->attributes, CoglAttribute *, 1);
|
2010-10-26 18:22:57 +00:00
|
|
|
*attribute_entry =
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_attribute_new (state->attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
stride,
|
|
|
|
state->array_offset + (POS_STRIDE * 4),
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2013-11-25 16:11:36 +00:00
|
|
|
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_QUADS))
|
2012-02-06 17:08:58 +00:00
|
|
|
state->indices = cogl_get_rectangle_indices (ctx, batch_len);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
/* We only create new Attributes when the stride within the
|
2011-03-02 15:01:41 +00:00
|
|
|
* AttributeBuffer changes. (due to a change in the number of pipeline
|
2011-01-20 19:31:53 +00:00
|
|
|
* layers) While the stride remains constant we walk forward through
|
2011-03-02 15:01:41 +00:00
|
|
|
* the above AttributeBuffer using a vertex offset passed to
|
2011-01-20 19:31:53 +00:00
|
|
|
* cogl_draw_attributes
|
2010-10-26 18:22:57 +00:00
|
|
|
*/
|
|
|
|
state->current_vertex = 0;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2015-09-23 11:20:43 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_JOURNAL)) &&
|
|
|
|
cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_READ))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *verts;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
/* Mapping a buffer for read is probably a really bad thing to
|
|
|
|
do but this will only happen during debugging so it probably
|
|
|
|
doesn't matter */
|
2012-11-08 17:54:10 +00:00
|
|
|
verts = ((uint8_t *)_cogl_buffer_map (COGL_BUFFER (state->attribute_buffer),
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0,
|
|
|
|
NULL) +
|
2010-11-25 21:08:45 +00:00
|
|
|
state->array_offset);
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
_cogl_journal_dump_quad_batch (verts,
|
|
|
|
batch_start->n_layers,
|
|
|
|
batch_len);
|
2010-11-25 21:08:45 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_buffer_unmap (COGL_BUFFER (state->attribute_buffer));
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
batch_and_call (batch_start,
|
|
|
|
batch_len,
|
2012-09-27 10:06:16 +00:00
|
|
|
compare_entry_layer_numbers,
|
2009-09-16 13:01:57 +00:00
|
|
|
_cogl_journal_flush_texcoord_vbo_offsets_and_entries,
|
|
|
|
data);
|
|
|
|
|
|
|
|
/* progress forward through the VBO containing all our vertices */
|
2010-10-26 18:22:57 +00:00
|
|
|
state->array_offset += (stride * 4 * batch_len);
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_JOURNAL)))
|
2010-10-26 18:22:57 +00:00
|
|
|
g_print ("new vbo offset = %lu\n", (unsigned long)state->array_offset);
|
2010-07-26 14:21:18 +00:00
|
|
|
|
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context,
|
2010-10-27 17:54:57 +00:00
|
|
|
time_flush_vbo_texcoord_pipeline_entries);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2009-09-16 13:01:57 +00:00
|
|
|
compare_entry_strides (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
|
|
|
{
|
|
|
|
/* Currently the only thing that affects the stride for our vertex arrays
|
2010-10-27 17:54:57 +00:00
|
|
|
* is the number of pipeline layers. We need to update our VBO offsets
|
2009-09-16 13:01:57 +00:00
|
|
|
* whenever the stride changes. */
|
|
|
|
/* TODO: We should be padding the n_layers == 1 case as if it were
|
|
|
|
* n_layers == 2 so we can reduce the need to split batches. */
|
|
|
|
if (entry0->n_layers == entry1->n_layers ||
|
|
|
|
(entry0->n_layers <= MIN_LAYER_PADING &&
|
|
|
|
entry1->n_layers <= MIN_LAYER_PADING))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-02 17:35:17 +00:00
|
|
|
/* At this point we know the batch has a unique clip stack */
|
|
|
|
static void
|
|
|
|
_cogl_journal_flush_clip_stacks_and_entries (CoglJournalEntry *batch_start,
|
|
|
|
int batch_len,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglJournalFlushState *state = data;
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
CoglFramebuffer *framebuffer = state->journal->framebuffer;
|
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
CoglMatrixStack *projection_stack;
|
2010-11-02 17:35:17 +00:00
|
|
|
|
|
|
|
COGL_STATIC_TIMER (time_flush_clip_stack_pipeline_entries,
|
|
|
|
"Journal Flush", /* parent */
|
|
|
|
"flush: clip+vbo+texcoords+pipeline+entries",
|
|
|
|
"The time spent flushing clip + vbo + texcoord offsets + "
|
|
|
|
"pipeline + entries",
|
|
|
|
0 /* no application private data */);
|
|
|
|
|
|
|
|
COGL_TIMER_START (_cogl_uprof_context,
|
|
|
|
time_flush_clip_stack_pipeline_entries);
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_BATCHING)))
|
2010-11-02 17:35:17 +00:00
|
|
|
g_print ("BATCHING: clip stack batch len = %d\n", batch_len);
|
|
|
|
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
_cogl_clip_stack_flush (batch_start->clip_stack, framebuffer);
|
2010-11-02 17:35:17 +00:00
|
|
|
|
2011-11-21 15:53:40 +00:00
|
|
|
/* XXX: Because we are manually flushing clip state here we need to
|
|
|
|
* make sure that the clip state gets updated the next time we flush
|
|
|
|
* framebuffer state by marking the current framebuffer's clip state
|
|
|
|
* as changed. */
|
|
|
|
ctx->current_draw_buffer_changes |= COGL_FRAMEBUFFER_STATE_CLIP;
|
|
|
|
|
2010-11-02 17:35:17 +00:00
|
|
|
/* If we have transformed all our quads at log time then we ensure
|
|
|
|
* no further model transform is applied by loading the identity
|
|
|
|
* matrix here. We need to do this after flushing the clip stack
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
* because the clip stack flushing code can modify the current
|
|
|
|
* modelview matrix entry */
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM))))
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
_cogl_context_set_current_modelview_entry (ctx, &ctx->identity_entry);
|
2010-11-02 17:35:17 +00:00
|
|
|
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
/* Setting up the clip state can sometimes also update the current
|
|
|
|
* projection matrix entry so we should update it again. This will have
|
|
|
|
* no affect if the clip code didn't modify the projection */
|
|
|
|
projection_stack =
|
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
|
|
|
_cogl_context_set_current_projection_entry (ctx,
|
|
|
|
projection_stack->last_entry);
|
2010-11-02 17:35:17 +00:00
|
|
|
|
|
|
|
batch_and_call (batch_start,
|
|
|
|
batch_len,
|
|
|
|
compare_entry_strides,
|
|
|
|
_cogl_journal_flush_vbo_offsets_and_entries, /* callback */
|
|
|
|
data);
|
|
|
|
|
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context,
|
|
|
|
time_flush_clip_stack_pipeline_entries);
|
|
|
|
}
|
|
|
|
|
2010-11-09 19:18:37 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float x_1, y_1;
|
|
|
|
float x_2, y_2;
|
|
|
|
} ClipBounds;
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2011-01-12 22:12:41 +00:00
|
|
|
can_software_clip_entry (CoglJournalEntry *journal_entry,
|
|
|
|
CoglJournalEntry *prev_journal_entry,
|
|
|
|
CoglClipStack *clip_stack,
|
|
|
|
ClipBounds *clip_bounds_out)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline = journal_entry->pipeline;
|
|
|
|
CoglClipStack *clip_entry;
|
|
|
|
int layer_num;
|
|
|
|
|
|
|
|
clip_bounds_out->x_1 = -G_MAXFLOAT;
|
|
|
|
clip_bounds_out->y_1 = -G_MAXFLOAT;
|
|
|
|
clip_bounds_out->x_2 = G_MAXFLOAT;
|
|
|
|
clip_bounds_out->y_2 = G_MAXFLOAT;
|
|
|
|
|
|
|
|
/* Check the pipeline is usable. We can short-cut here for
|
|
|
|
entries using the same pipeline as the previous entry */
|
|
|
|
if (prev_journal_entry == NULL || pipeline != prev_journal_entry->pipeline)
|
|
|
|
{
|
|
|
|
/* If the pipeline has a user program then we can't reliably modify
|
|
|
|
the texture coordinates */
|
|
|
|
if (cogl_pipeline_get_user_program (pipeline))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If any of the pipeline layers have a texture matrix then we can't
|
|
|
|
reliably modify the texture coordinates */
|
|
|
|
for (layer_num = cogl_pipeline_get_n_layers (pipeline) - 1;
|
|
|
|
layer_num >= 0;
|
|
|
|
layer_num--)
|
|
|
|
if (_cogl_pipeline_layer_has_user_matrix (pipeline, layer_num))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we need to verify that each clip entry's matrix is just a
|
|
|
|
translation of the journal entry's modelview matrix. We can
|
|
|
|
also work out the bounds of the clip in modelview space using
|
|
|
|
this translation */
|
|
|
|
for (clip_entry = clip_stack; clip_entry; clip_entry = clip_entry->parent)
|
|
|
|
{
|
|
|
|
float rect_x1, rect_y1, rect_x2, rect_y2;
|
|
|
|
CoglClipStackRect *clip_rect;
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
float tx, ty, tz;
|
|
|
|
CoglMatrixEntry *modelview_entry;
|
2011-01-12 22:12:41 +00:00
|
|
|
|
|
|
|
clip_rect = (CoglClipStackRect *) clip_entry;
|
|
|
|
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
modelview_entry = journal_entry->modelview_entry;
|
2012-11-20 17:08:43 +00:00
|
|
|
if (!cogl_matrix_entry_calculate_translation (clip_rect->matrix_entry,
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
modelview_entry,
|
|
|
|
&tx, &ty, &tz))
|
2011-01-12 22:12:41 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (clip_rect->x0 < clip_rect->x1)
|
|
|
|
{
|
|
|
|
rect_x1 = clip_rect->x0;
|
|
|
|
rect_x2 = clip_rect->x1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect_x1 = clip_rect->x1;
|
|
|
|
rect_x2 = clip_rect->x0;
|
|
|
|
}
|
|
|
|
if (clip_rect->y0 < clip_rect->y1)
|
|
|
|
{
|
|
|
|
rect_y1 = clip_rect->y0;
|
|
|
|
rect_y2 = clip_rect->y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect_y1 = clip_rect->y1;
|
|
|
|
rect_y2 = clip_rect->y0;
|
|
|
|
}
|
|
|
|
|
|
|
|
clip_bounds_out->x_1 = MAX (clip_bounds_out->x_1, rect_x1 - tx);
|
|
|
|
clip_bounds_out->y_1 = MAX (clip_bounds_out->y_1, rect_y1 - ty);
|
|
|
|
clip_bounds_out->x_2 = MIN (clip_bounds_out->x_2, rect_x2 - tx);
|
|
|
|
clip_bounds_out->y_2 = MIN (clip_bounds_out->y_2, rect_y2 - ty);
|
|
|
|
}
|
|
|
|
|
2011-09-14 10:13:30 +00:00
|
|
|
if (clip_bounds_out->x_2 <= clip_bounds_out->x_1 ||
|
|
|
|
clip_bounds_out->y_2 <= clip_bounds_out->y_1)
|
|
|
|
memset (clip_bounds_out, 0, sizeof (ClipBounds));
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-09 19:18:37 +00:00
|
|
|
static void
|
2011-01-12 22:12:41 +00:00
|
|
|
software_clip_entry (CoglJournalEntry *journal_entry,
|
|
|
|
float *verts,
|
|
|
|
ClipBounds *clip_bounds)
|
|
|
|
{
|
|
|
|
size_t stride =
|
|
|
|
GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS (journal_entry->n_layers);
|
|
|
|
float rx1, ry1, rx2, ry2;
|
|
|
|
float vx1, vy1, vx2, vy2;
|
|
|
|
int layer_num;
|
|
|
|
|
|
|
|
/* Remove the clip on the entry */
|
|
|
|
_cogl_clip_stack_unref (journal_entry->clip_stack);
|
|
|
|
journal_entry->clip_stack = NULL;
|
|
|
|
|
|
|
|
vx1 = verts[0];
|
|
|
|
vy1 = verts[1];
|
|
|
|
vx2 = verts[stride];
|
|
|
|
vy2 = verts[stride + 1];
|
|
|
|
|
|
|
|
if (vx1 < vx2)
|
|
|
|
{
|
|
|
|
rx1 = vx1;
|
|
|
|
rx2 = vx2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rx1 = vx2;
|
|
|
|
rx2 = vx1;
|
|
|
|
}
|
|
|
|
if (vy1 < vy2)
|
|
|
|
{
|
|
|
|
ry1 = vy1;
|
|
|
|
ry2 = vy2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ry1 = vy2;
|
|
|
|
ry2 = vy1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rx1 = CLAMP (rx1, clip_bounds->x_1, clip_bounds->x_2);
|
|
|
|
ry1 = CLAMP (ry1, clip_bounds->y_1, clip_bounds->y_2);
|
|
|
|
rx2 = CLAMP (rx2, clip_bounds->x_1, clip_bounds->x_2);
|
|
|
|
ry2 = CLAMP (ry2, clip_bounds->y_1, clip_bounds->y_2);
|
|
|
|
|
|
|
|
/* Check if the rectangle intersects the clip at all */
|
|
|
|
if (rx1 == rx2 || ry1 == ry2)
|
|
|
|
/* Will set all of the vertex data to 0 in the hope that this
|
|
|
|
will create a degenerate rectangle and the GL driver will
|
|
|
|
be able to clip it quickly */
|
|
|
|
memset (verts, 0, sizeof (float) * stride * 2);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (vx1 > vx2)
|
|
|
|
{
|
|
|
|
float t = rx1;
|
|
|
|
rx1 = rx2;
|
|
|
|
rx2 = t;
|
|
|
|
}
|
|
|
|
if (vy1 > vy2)
|
|
|
|
{
|
|
|
|
float t = ry1;
|
|
|
|
ry1 = ry2;
|
|
|
|
ry2 = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
verts[0] = rx1;
|
|
|
|
verts[1] = ry1;
|
|
|
|
verts[stride] = rx2;
|
|
|
|
verts[stride + 1] = ry2;
|
|
|
|
|
|
|
|
/* Convert the rectangle coordinates to a fraction of the original
|
|
|
|
rectangle */
|
|
|
|
rx1 = (rx1 - vx1) / (vx2 - vx1);
|
|
|
|
ry1 = (ry1 - vy1) / (vy2 - vy1);
|
|
|
|
rx2 = (rx2 - vx1) / (vx2 - vx1);
|
|
|
|
ry2 = (ry2 - vy1) / (vy2 - vy1);
|
|
|
|
|
|
|
|
for (layer_num = 0; layer_num < journal_entry->n_layers; layer_num++)
|
|
|
|
{
|
|
|
|
float *t = verts + 2 + 2 * layer_num;
|
|
|
|
float tx1 = t[0], ty1 = t[1];
|
|
|
|
float tx2 = t[stride], ty2 = t[stride + 1];
|
|
|
|
t[0] = rx1 * (tx2 - tx1) + tx1;
|
|
|
|
t[1] = ry1 * (ty2 - ty1) + ty1;
|
|
|
|
t[stride] = rx2 * (tx2 - tx1) + tx1;
|
|
|
|
t[stride + 1] = ry2 * (ty2 - ty1) + ty1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
maybe_software_clip_entries (CoglJournalEntry *batch_start,
|
|
|
|
int batch_len,
|
|
|
|
CoglJournalFlushState *state)
|
2010-11-09 19:18:37 +00:00
|
|
|
{
|
2012-11-09 00:57:14 +00:00
|
|
|
CoglContext *ctx;
|
|
|
|
CoglJournal *journal;
|
2010-11-09 19:18:37 +00:00
|
|
|
CoglClipStack *clip_stack, *clip_entry;
|
|
|
|
int entry_num;
|
|
|
|
|
|
|
|
/* This tries to find cases where the entry is logged with a clip
|
|
|
|
but it would be faster to modify the vertex and texture
|
|
|
|
coordinates rather than flush the clip so that it can batch
|
|
|
|
better */
|
|
|
|
|
|
|
|
/* If the batch is reasonably long then it's worthwhile programming
|
|
|
|
the GPU to do the clip */
|
|
|
|
if (batch_len >= COGL_JOURNAL_HARDWARE_CLIP_THRESHOLD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clip_stack = batch_start->clip_stack;
|
|
|
|
|
|
|
|
if (clip_stack == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Verify that all of the clip stack entries are a simple rectangle
|
|
|
|
clip */
|
|
|
|
for (clip_entry = clip_stack; clip_entry; clip_entry = clip_entry->parent)
|
|
|
|
if (clip_entry->type != COGL_CLIP_STACK_RECT)
|
|
|
|
return;
|
|
|
|
|
2012-11-09 00:57:14 +00:00
|
|
|
ctx = state->ctx;
|
|
|
|
journal = state->journal;
|
|
|
|
|
2010-11-09 19:18:37 +00:00
|
|
|
/* This scratch buffer is used to store the translation for each
|
|
|
|
entry in the journal. We store it in a separate buffer because
|
|
|
|
it's expensive to calculate but at this point we still don't know
|
|
|
|
whether we can clip all of the entries so we don't want to do the
|
|
|
|
rest of the dependant calculations until we're sure we can. */
|
|
|
|
if (ctx->journal_clip_bounds == NULL)
|
|
|
|
ctx->journal_clip_bounds = g_array_new (FALSE, FALSE, sizeof (ClipBounds));
|
|
|
|
g_array_set_size (ctx->journal_clip_bounds, batch_len);
|
|
|
|
|
|
|
|
for (entry_num = 0; entry_num < batch_len; entry_num++)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *journal_entry = batch_start + entry_num;
|
2011-01-12 22:12:41 +00:00
|
|
|
CoglJournalEntry *prev_journal_entry =
|
|
|
|
entry_num ? batch_start + (entry_num - 1) : NULL;
|
2010-11-09 19:18:37 +00:00
|
|
|
ClipBounds *clip_bounds = &g_array_index (ctx->journal_clip_bounds,
|
|
|
|
ClipBounds, entry_num);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
if (!can_software_clip_entry (journal_entry, prev_journal_entry,
|
|
|
|
clip_stack,
|
|
|
|
clip_bounds))
|
|
|
|
return;
|
2010-11-09 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we make it here then we know we can software clip the entire batch */
|
|
|
|
|
2011-01-24 16:36:56 +00:00
|
|
|
COGL_NOTE (CLIPPING, "Software clipping a batch of length %i", batch_len);
|
|
|
|
|
2010-11-09 19:18:37 +00:00
|
|
|
for (entry_num = 0; entry_num < batch_len; entry_num++)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *journal_entry = batch_start + entry_num;
|
2011-01-06 13:25:45 +00:00
|
|
|
float *verts = &g_array_index (journal->vertices, float,
|
2010-11-09 19:18:37 +00:00
|
|
|
journal_entry->array_offset + 1);
|
|
|
|
ClipBounds *clip_bounds = &g_array_index (ctx->journal_clip_bounds,
|
|
|
|
ClipBounds, entry_num);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
software_clip_entry (journal_entry, verts, clip_bounds);
|
2010-11-09 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_journal_maybe_software_clip_entries (CoglJournalEntry *batch_start,
|
|
|
|
int batch_len,
|
|
|
|
void *data)
|
2010-11-09 19:18:37 +00:00
|
|
|
{
|
|
|
|
CoglJournalFlushState *state = data;
|
|
|
|
|
|
|
|
COGL_STATIC_TIMER (time_check_software_clip,
|
|
|
|
"Journal Flush", /* parent */
|
2011-01-12 22:12:41 +00:00
|
|
|
"flush: software clipping",
|
|
|
|
"Time spent software clipping",
|
2010-11-09 19:18:37 +00:00
|
|
|
0 /* no application private data */);
|
|
|
|
|
|
|
|
COGL_TIMER_START (_cogl_uprof_context,
|
|
|
|
time_check_software_clip);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
maybe_software_clip_entries (batch_start, batch_len, state);
|
2010-11-09 19:18:37 +00:00
|
|
|
|
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context,
|
|
|
|
time_check_software_clip);
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2010-11-02 17:35:17 +00:00
|
|
|
compare_entry_clip_stacks (CoglJournalEntry *entry0, CoglJournalEntry *entry1)
|
|
|
|
{
|
|
|
|
return entry0->clip_stack == entry1->clip_stack;
|
|
|
|
}
|
|
|
|
|
2011-06-01 13:30:45 +00:00
|
|
|
/* Gets a new vertex array from the pool. A reference is taken on the
|
|
|
|
array so it can be treated as if it was just newly allocated */
|
|
|
|
static CoglAttributeBuffer *
|
|
|
|
create_attribute_buffer (CoglJournal *journal,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t n_bytes)
|
2011-06-01 13:30:45 +00:00
|
|
|
{
|
|
|
|
CoglAttributeBuffer *vbo;
|
2012-11-09 00:57:14 +00:00
|
|
|
CoglContext *ctx = journal->framebuffer->context;
|
2011-10-13 08:36:46 +00:00
|
|
|
|
2011-06-01 13:30:45 +00:00
|
|
|
/* If CoglBuffers are being emulated with malloc then there's not
|
|
|
|
really any point in using the pool so we'll just allocate the
|
|
|
|
buffer directly */
|
2013-11-25 16:11:36 +00:00
|
|
|
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_VBOS))
|
2012-11-27 20:38:42 +00:00
|
|
|
return cogl_attribute_buffer_new_with_size (ctx, n_bytes);
|
2011-06-01 13:30:45 +00:00
|
|
|
|
|
|
|
vbo = journal->vbo_pool[journal->next_vbo_in_pool];
|
|
|
|
|
|
|
|
if (vbo == NULL)
|
|
|
|
{
|
2012-11-08 17:54:10 +00:00
|
|
|
vbo = cogl_attribute_buffer_new_with_size (ctx, n_bytes);
|
2011-06-01 13:30:45 +00:00
|
|
|
journal->vbo_pool[journal->next_vbo_in_pool] = vbo;
|
|
|
|
}
|
|
|
|
else if (cogl_buffer_get_size (COGL_BUFFER (vbo)) < n_bytes)
|
|
|
|
{
|
|
|
|
/* If the buffer is too small then we'll just recreate it */
|
|
|
|
cogl_object_unref (vbo);
|
2012-11-08 17:54:10 +00:00
|
|
|
vbo = cogl_attribute_buffer_new_with_size (ctx, n_bytes);
|
2011-06-01 13:30:45 +00:00
|
|
|
journal->vbo_pool[journal->next_vbo_in_pool] = vbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
journal->next_vbo_in_pool = ((journal->next_vbo_in_pool + 1) %
|
|
|
|
COGL_JOURNAL_VBO_POOL_SIZE);
|
|
|
|
|
|
|
|
return cogl_object_ref (vbo);
|
|
|
|
}
|
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
static CoglAttributeBuffer *
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
upload_vertices (CoglJournal *journal,
|
2011-06-01 13:30:45 +00:00
|
|
|
const CoglJournalEntry *entries,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
int n_entries,
|
|
|
|
size_t needed_vbo_len,
|
|
|
|
GArray *vertices)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer;
|
2010-10-26 18:22:57 +00:00
|
|
|
CoglBuffer *buffer;
|
2010-11-25 21:08:45 +00:00
|
|
|
const float *vin;
|
|
|
|
float *vout;
|
|
|
|
int entry_num;
|
|
|
|
int i;
|
2012-04-03 12:32:47 +00:00
|
|
|
CoglMatrixEntry *last_modelview_entry = NULL;
|
|
|
|
CoglMatrix modelview;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
g_assert (needed_vbo_len);
|
2010-10-26 18:22:57 +00:00
|
|
|
|
2011-06-01 13:30:45 +00:00
|
|
|
attribute_buffer = create_attribute_buffer (journal, needed_vbo_len * 4);
|
2011-03-02 15:01:41 +00:00
|
|
|
buffer = COGL_BUFFER (attribute_buffer);
|
2017-04-29 11:24:04 +00:00
|
|
|
cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_DYNAMIC);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2012-10-17 20:36:10 +00:00
|
|
|
vout = _cogl_buffer_map_range_for_fill_or_fallback (buffer,
|
|
|
|
0, /* offset */
|
|
|
|
needed_vbo_len * 4);
|
2010-11-25 21:08:45 +00:00
|
|
|
vin = &g_array_index (vertices, float, 0);
|
|
|
|
|
|
|
|
/* Expand the number of vertices from 2 to 4 while uploading */
|
|
|
|
for (entry_num = 0; entry_num < n_entries; entry_num++)
|
|
|
|
{
|
|
|
|
const CoglJournalEntry *entry = entries + entry_num;
|
|
|
|
size_t vb_stride = GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS (entry->n_layers);
|
|
|
|
size_t array_stride =
|
|
|
|
GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS (entry->n_layers);
|
|
|
|
|
|
|
|
/* Copy the color to all four of the vertices */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
memcpy (vout + vb_stride * i + POS_STRIDE, vin, 4);
|
|
|
|
vin++;
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))
|
2010-11-25 21:08:45 +00:00
|
|
|
{
|
|
|
|
vout[vb_stride * 0] = vin[0];
|
|
|
|
vout[vb_stride * 0 + 1] = vin[1];
|
|
|
|
vout[vb_stride * 1] = vin[0];
|
|
|
|
vout[vb_stride * 1 + 1] = vin[array_stride + 1];
|
|
|
|
vout[vb_stride * 2] = vin[array_stride];
|
|
|
|
vout[vb_stride * 2 + 1] = vin[array_stride + 1];
|
|
|
|
vout[vb_stride * 3] = vin[array_stride];
|
|
|
|
vout[vb_stride * 3 + 1] = vin[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float v[8];
|
|
|
|
|
|
|
|
v[0] = vin[0];
|
|
|
|
v[1] = vin[1];
|
|
|
|
v[2] = vin[0];
|
|
|
|
v[3] = vin[array_stride + 1];
|
|
|
|
v[4] = vin[array_stride];
|
|
|
|
v[5] = vin[array_stride + 1];
|
|
|
|
v[6] = vin[array_stride];
|
|
|
|
v[7] = vin[1];
|
|
|
|
|
2012-04-03 12:32:47 +00:00
|
|
|
if (entry->modelview_entry != last_modelview_entry)
|
2012-11-20 17:08:43 +00:00
|
|
|
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
cogl_matrix_transform_points (&modelview,
|
2010-11-25 21:08:45 +00:00
|
|
|
2, /* n_components */
|
|
|
|
sizeof (float) * 2, /* stride_in */
|
|
|
|
v, /* points_in */
|
|
|
|
/* strideout */
|
|
|
|
vb_stride * sizeof (float),
|
|
|
|
vout, /* points_out */
|
|
|
|
4 /* n_points */);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < entry->n_layers; i++)
|
|
|
|
{
|
|
|
|
const float *tin = vin + 2;
|
|
|
|
float *tout = vout + POS_STRIDE + COLOR_STRIDE;
|
|
|
|
|
|
|
|
tout[vb_stride * 0 + i * 2] = tin[i * 2];
|
|
|
|
tout[vb_stride * 0 + 1 + i * 2] = tin[i * 2 + 1];
|
|
|
|
tout[vb_stride * 1 + i * 2] = tin[i * 2];
|
|
|
|
tout[vb_stride * 1 + 1 + i * 2] = tin[array_stride + i * 2 + 1];
|
|
|
|
tout[vb_stride * 2 + i * 2] = tin[array_stride + i * 2];
|
|
|
|
tout[vb_stride * 2 + 1 + i * 2] = tin[array_stride + i * 2 + 1];
|
|
|
|
tout[vb_stride * 3 + i * 2] = tin[array_stride + i * 2];
|
|
|
|
tout[vb_stride * 3 + 1 + i * 2] = tin[i * 2 + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
vin += array_stride * 2;
|
|
|
|
vout += vb_stride * 4;
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:35:30 +00:00
|
|
|
_cogl_buffer_unmap_for_fill_or_fallback (buffer);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
return attribute_buffer;
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
void
|
|
|
|
_cogl_journal_discard (CoglJournal *journal)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-03-16 17:26:30 +00:00
|
|
|
if (journal->entries->len <= 0)
|
|
|
|
return;
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
for (i = 0; i < journal->entries->len; i++)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *entry =
|
|
|
|
&g_array_index (journal->entries, CoglJournalEntry, i);
|
|
|
|
_cogl_pipeline_journal_unref (entry->pipeline);
|
2012-11-20 17:08:43 +00:00
|
|
|
cogl_matrix_entry_unref (entry->modelview_entry);
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_clip_stack_unref (entry->clip_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_set_size (journal->entries, 0);
|
|
|
|
g_array_set_size (journal->vertices, 0);
|
|
|
|
journal->needed_vbo_len = 0;
|
|
|
|
journal->fast_read_pixel_count = 0;
|
2012-01-24 18:16:03 +00:00
|
|
|
|
|
|
|
/* The journal only holds a reference to the framebuffer while the
|
|
|
|
journal is not empty */
|
2012-03-16 17:26:30 +00:00
|
|
|
cogl_object_unref (journal->framebuffer);
|
2011-01-12 22:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: A return value of FALSE doesn't mean 'no' it means
|
|
|
|
* 'unknown' */
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_journal_all_entries_within_bounds (CoglJournal *journal,
|
|
|
|
float clip_x0,
|
|
|
|
float clip_y0,
|
|
|
|
float clip_x1,
|
|
|
|
float clip_y1)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *entry = (CoglJournalEntry *)journal->entries->data;
|
|
|
|
CoglClipStack *clip_entry;
|
|
|
|
CoglClipStack *reference = NULL;
|
|
|
|
int bounds_x0;
|
|
|
|
int bounds_y0;
|
|
|
|
int bounds_x1;
|
|
|
|
int bounds_y1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (journal->entries->len == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Find the shortest clip_stack ancestry that leaves us in the
|
|
|
|
* required bounds */
|
|
|
|
for (clip_entry = entry->clip_stack;
|
|
|
|
clip_entry;
|
|
|
|
clip_entry = clip_entry->parent)
|
|
|
|
{
|
|
|
|
_cogl_clip_stack_get_bounds (clip_entry,
|
|
|
|
&bounds_x0, &bounds_y0,
|
|
|
|
&bounds_x1, &bounds_y1);
|
|
|
|
|
|
|
|
if (bounds_x0 >= clip_x0 && bounds_y0 >= clip_y0 &&
|
|
|
|
bounds_x1 <= clip_x1 && bounds_y1 <= clip_y1)
|
|
|
|
reference = clip_entry;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reference)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* For the remaining journal entries we will only verify they share
|
|
|
|
* 'reference' as an ancestor in their clip stack since that's
|
|
|
|
* enough to know that they would be within the required bounds.
|
|
|
|
*/
|
|
|
|
for (i = 1; i < journal->entries->len; i++)
|
|
|
|
{
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean found_reference = FALSE;
|
2011-01-12 22:12:41 +00:00
|
|
|
entry = &g_array_index (journal->entries, CoglJournalEntry, i);
|
|
|
|
|
|
|
|
for (clip_entry = entry->clip_stack;
|
|
|
|
clip_entry;
|
|
|
|
clip_entry = clip_entry->parent)
|
|
|
|
{
|
|
|
|
if (clip_entry == reference)
|
|
|
|
{
|
|
|
|
found_reference = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_reference)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-11 01:13:34 +00:00
|
|
|
static void
|
|
|
|
post_fences (CoglJournal *journal)
|
|
|
|
{
|
2013-06-08 22:03:25 +00:00
|
|
|
CoglFenceClosure *fence, *tmp;
|
2013-01-11 01:13:34 +00:00
|
|
|
|
2013-06-08 22:03:25 +00:00
|
|
|
_cogl_list_for_each_safe (fence, tmp, &journal->pending_fences, link)
|
2013-01-11 01:13:34 +00:00
|
|
|
{
|
2013-06-08 22:03:25 +00:00
|
|
|
_cogl_list_remove (&fence->link);
|
2013-01-11 01:13:34 +00:00
|
|
|
_cogl_fence_submit (fence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
/* XXX NB: When _cogl_journal_flush() returns all state relating
|
2010-10-27 17:54:57 +00:00
|
|
|
* to pipelines, all glEnable flags and current matrix state
|
2009-09-16 13:01:57 +00:00
|
|
|
* is undefined.
|
|
|
|
*/
|
|
|
|
void
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_journal_flush (CoglJournal *journal)
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
|
|
|
CoglContext *ctx;
|
2009-09-16 13:01:57 +00:00
|
|
|
CoglJournalFlushState state;
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
int i;
|
2009-07-03 15:22:35 +00:00
|
|
|
COGL_STATIC_TIMER (flush_timer,
|
|
|
|
"Mainloop", /* parent */
|
|
|
|
"Journal Flush",
|
|
|
|
"The time spent flushing the Cogl journal",
|
|
|
|
0 /* no application private data */);
|
2012-08-27 18:44:11 +00:00
|
|
|
COGL_STATIC_TIMER (discard_timer,
|
|
|
|
"Journal Flush", /* parent */
|
|
|
|
"flush: discard",
|
|
|
|
"The time spent discarding the Cogl journal after a flush",
|
|
|
|
0 /* no application private data */);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
if (journal->entries->len == 0)
|
2013-01-11 01:13:34 +00:00
|
|
|
{
|
|
|
|
post_fences (journal);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-16 13:01:57 +00:00
|
|
|
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
framebuffer = journal->framebuffer;
|
|
|
|
ctx = framebuffer->context;
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
/* The entries in this journal may depend on images in other
|
|
|
|
* framebuffers which may require that we flush the journals
|
|
|
|
* associated with those framebuffers before we can flush
|
|
|
|
* this journal... */
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
_cogl_framebuffer_flush_dependency_journals (framebuffer);
|
2011-01-06 13:25:45 +00:00
|
|
|
|
2011-01-21 17:38:14 +00:00
|
|
|
/* Note: we start the timer after flushing dependency journals so
|
|
|
|
* that the timer isn't started recursively. */
|
|
|
|
COGL_TIMER_START (_cogl_uprof_context, flush_timer);
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_BATCHING)))
|
2011-01-06 13:25:45 +00:00
|
|
|
g_print ("BATCHING: journal len = %d\n", journal->entries->len);
|
|
|
|
|
|
|
|
/* NB: the journal deals with flushing the modelview stack and clip
|
|
|
|
state manually */
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
_cogl_framebuffer_flush_state (framebuffer,
|
|
|
|
framebuffer,
|
2011-11-21 15:53:40 +00:00
|
|
|
COGL_FRAMEBUFFER_STATE_ALL &
|
|
|
|
~(COGL_FRAMEBUFFER_STATE_MODELVIEW |
|
|
|
|
COGL_FRAMEBUFFER_STATE_CLIP));
|
2011-01-06 13:25:45 +00:00
|
|
|
|
2013-02-18 18:21:39 +00:00
|
|
|
/* We need to mark the current modelview state of the framebuffer as
|
|
|
|
* dirty because we are going to manually replace it */
|
|
|
|
ctx->current_draw_buffer_changes |= COGL_FRAMEBUFFER_STATE_MODELVIEW;
|
|
|
|
|
2012-11-09 00:57:14 +00:00
|
|
|
state.ctx = ctx;
|
2011-01-06 13:25:45 +00:00
|
|
|
state.journal = journal;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-10-26 18:22:57 +00:00
|
|
|
state.attributes = ctx->journal_flush_attributes_array;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY ((COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_CLIP)) == 0))
|
2010-11-10 14:02:31 +00:00
|
|
|
{
|
|
|
|
/* We do an initial walk of the journal to analyse the clip stack
|
|
|
|
batches to see if we can do software clipping. We do this as a
|
|
|
|
separate walk of the journal because we can modify entries and
|
|
|
|
this may end up joining together clip stack batches in the next
|
|
|
|
iteration. */
|
2011-01-06 13:25:45 +00:00
|
|
|
batch_and_call ((CoglJournalEntry *)journal->entries->data, /* first entry */
|
|
|
|
journal->entries->len, /* max number of entries to consider */
|
2010-11-10 14:02:31 +00:00
|
|
|
compare_entry_clip_stacks,
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_journal_maybe_software_clip_entries, /* callback */
|
2010-11-10 14:02:31 +00:00
|
|
|
&state); /* data */
|
|
|
|
}
|
2010-11-09 19:18:37 +00:00
|
|
|
|
|
|
|
/* We upload the vertices after the clip stack pass in case it
|
|
|
|
modifies the entries */
|
2011-06-01 13:30:45 +00:00
|
|
|
state.attribute_buffer =
|
|
|
|
upload_vertices (journal,
|
|
|
|
&g_array_index (journal->entries, CoglJournalEntry, 0),
|
|
|
|
journal->entries->len,
|
|
|
|
journal->needed_vbo_len,
|
|
|
|
journal->vertices);
|
2010-11-09 19:18:37 +00:00
|
|
|
state.array_offset = 0;
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
/* batch_and_call() batches a list of journal entries according to some
|
|
|
|
* given criteria and calls a callback once for each determined batch.
|
|
|
|
*
|
|
|
|
* The process of flushing the journal is staggered to reduce the amount
|
|
|
|
* of driver/GPU state changes necessary:
|
2010-11-02 17:35:17 +00:00
|
|
|
* 1) We split the entries according to the clip state.
|
|
|
|
* 2) We split the entries according to the stride of the vertices:
|
2009-09-16 13:01:57 +00:00
|
|
|
* Each time the stride of our vertex data changes we need to call
|
|
|
|
* gl{Vertex,Color}Pointer to inform GL of new VBO offsets.
|
|
|
|
* Currently the only thing that affects the stride of our vertex data
|
2010-10-27 17:54:57 +00:00
|
|
|
* is the number of pipeline layers.
|
2010-11-02 17:35:17 +00:00
|
|
|
* 3) We split the entries explicitly by the number of pipeline layers:
|
2009-09-16 13:01:57 +00:00
|
|
|
* We pad our vertex data when the number of layers is < 2 so that we
|
|
|
|
* can minimize changes in stride. Each time the number of layers
|
|
|
|
* changes we need to call glTexCoordPointer to inform GL of new VBO
|
|
|
|
* offsets.
|
2010-11-02 17:35:17 +00:00
|
|
|
* 4) We then split according to compatible Cogl pipelines:
|
2010-10-27 17:54:57 +00:00
|
|
|
* This is where we flush pipeline state
|
2010-11-02 17:35:17 +00:00
|
|
|
* 5) Finally we split according to modelview matrix changes:
|
2009-09-16 13:01:57 +00:00
|
|
|
* This is when we finally tell GL to draw something.
|
|
|
|
* Note: Splitting by modelview changes is skipped when are doing the
|
|
|
|
* vertex transformation in software at log time.
|
|
|
|
*/
|
2011-01-06 13:25:45 +00:00
|
|
|
batch_and_call ((CoglJournalEntry *)journal->entries->data, /* first entry */
|
|
|
|
journal->entries->len, /* max number of entries to consider */
|
2010-11-02 17:35:17 +00:00
|
|
|
compare_entry_clip_stacks,
|
|
|
|
_cogl_journal_flush_clip_stacks_and_entries, /* callback */
|
2009-09-16 13:01:57 +00:00
|
|
|
&state); /* data */
|
|
|
|
|
2010-11-15 06:32:42 +00:00
|
|
|
for (i = 0; i < state.attributes->len; i++)
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_object_unref (g_array_index (state.attributes, CoglAttribute *, i));
|
2010-11-15 06:32:42 +00:00
|
|
|
g_array_set_size (state.attributes, 0);
|
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (state.attribute_buffer);
|
2010-11-15 06:32:42 +00:00
|
|
|
|
2012-08-27 18:44:11 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context, discard_timer);
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_journal_discard (journal);
|
2012-08-27 18:44:11 +00:00
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, discard_timer);
|
2011-01-06 13:25:45 +00:00
|
|
|
|
2013-01-11 01:13:34 +00:00
|
|
|
post_fences (journal);
|
|
|
|
|
2009-07-03 15:22:35 +00:00
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, flush_timer);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2011-01-06 13:25:45 +00:00
|
|
|
add_framebuffer_deps_cb (CoglPipelineLayer *layer, void *user_data)
|
2009-09-25 13:34:34 +00:00
|
|
|
{
|
2011-01-06 13:25:45 +00:00
|
|
|
CoglFramebuffer *framebuffer = user_data;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture = _cogl_pipeline_layer_get_texture_real (layer);
|
2011-01-06 13:25:45 +00:00
|
|
|
const GList *l;
|
2010-11-25 21:08:45 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
if (!texture)
|
|
|
|
return TRUE;
|
2009-09-25 13:34:34 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
for (l = _cogl_texture_get_associated_framebuffers (texture); l; l = l->next)
|
|
|
|
_cogl_framebuffer_add_dependency (framebuffer, l->data);
|
2010-11-25 21:08:45 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
return TRUE;
|
2009-09-25 13:34:34 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
void
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_journal_log_quad (CoglJournal *journal,
|
|
|
|
const float *position,
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline,
|
2009-09-16 13:01:57 +00:00
|
|
|
int n_layers,
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *layer0_override_texture,
|
2009-12-02 17:17:24 +00:00
|
|
|
const float *tex_coords,
|
2009-09-16 13:01:57 +00:00
|
|
|
unsigned int tex_coords_len)
|
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglFramebuffer *framebuffer = journal->framebuffer;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t stride;
|
2012-03-16 19:54:13 +00:00
|
|
|
int next_vert;
|
|
|
|
float *v;
|
|
|
|
int i;
|
|
|
|
int next_entry;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint32_t disable_layers;
|
2009-09-16 13:01:57 +00:00
|
|
|
CoglJournalEntry *entry;
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglPipeline *final_pipeline;
|
|
|
|
CoglClipStack *clip_stack;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipelineFlushOptions flush_options;
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
CoglMatrixStack *modelview_stack;
|
2009-07-03 15:22:35 +00:00
|
|
|
COGL_STATIC_TIMER (log_timer,
|
|
|
|
"Mainloop", /* parent */
|
|
|
|
"Journal Log",
|
|
|
|
"The time spent logging in the Cogl journal",
|
|
|
|
0 /* no application private data */);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2009-07-03 15:22:35 +00:00
|
|
|
COGL_TIMER_START (_cogl_uprof_context, log_timer);
|
|
|
|
|
2013-05-17 14:13:41 +00:00
|
|
|
/* Adding something to the journal should mean that we are in the
|
|
|
|
* middle of the scene. Although this will also end up being set
|
|
|
|
* when the journal is actually flushed, we set it here explicitly
|
|
|
|
* so that we will know sooner */
|
|
|
|
_cogl_framebuffer_mark_mid_scene (framebuffer);
|
|
|
|
|
2012-01-24 18:16:03 +00:00
|
|
|
/* If the framebuffer was previously empty then we'll take a
|
|
|
|
reference to the current framebuffer. This reference will be
|
2012-03-16 17:26:30 +00:00
|
|
|
removed when the journal is flushed */
|
2012-01-24 18:16:03 +00:00
|
|
|
if (journal->vertices->len == 0)
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_object_ref (framebuffer);
|
2012-01-24 18:16:03 +00:00
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
/* The vertex data is logged into a separate array. The data needs
|
|
|
|
to be copied into a vertex array before it's given to GL so we
|
|
|
|
only store two vertices per quad and expand it to four while
|
|
|
|
uploading. */
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
/* XXX: See definition of GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS for details
|
2009-09-16 13:01:57 +00:00
|
|
|
* about how we pack our vertex data */
|
2010-11-25 21:08:45 +00:00
|
|
|
stride = GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS (n_layers);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
next_vert = journal->vertices->len;
|
|
|
|
g_array_set_size (journal->vertices, next_vert + 2 * stride + 1);
|
|
|
|
v = &g_array_index (journal->vertices, float, next_vert);
|
2010-11-25 21:08:45 +00:00
|
|
|
|
|
|
|
/* We calculate the needed size of the vbo as we go because it
|
|
|
|
depends on the number of layers in each entry and it's not easy
|
|
|
|
calculate based on the length of the logged vertices array */
|
2011-01-06 13:25:45 +00:00
|
|
|
journal->needed_vbo_len += GET_JOURNAL_VB_STRIDE_FOR_N_LAYERS (n_layers) * 4;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
|
|
|
/* XXX: All the jumping around to fill in this strided buffer doesn't
|
|
|
|
* seem ideal. */
|
|
|
|
|
|
|
|
/* FIXME: This is a hacky optimization, since it will break if we
|
|
|
|
* change the definition of CoglColor: */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_pipeline_get_colorubv (pipeline, (uint8_t *) v);
|
2010-11-25 21:08:45 +00:00
|
|
|
v++;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-11-25 21:08:45 +00:00
|
|
|
memcpy (v, position, sizeof (float) * 2);
|
|
|
|
memcpy (v + stride, position + 2, sizeof (float) * 2);
|
2010-02-11 15:33:01 +00:00
|
|
|
|
2009-09-16 13:01:57 +00:00
|
|
|
for (i = 0; i < n_layers; i++)
|
|
|
|
{
|
2010-11-25 21:08:45 +00:00
|
|
|
/* XXX: See definition of GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS
|
|
|
|
* for details about how we pack our vertex data */
|
|
|
|
GLfloat *t = v + 2 + i * 2;
|
|
|
|
|
|
|
|
memcpy (t, tex_coords + i * 4, sizeof (float) * 2);
|
|
|
|
memcpy (t + stride, tex_coords + i * 4 + 2, sizeof (float) * 2);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_JOURNAL)))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
|
|
|
g_print ("Logged new quad:\n");
|
2011-01-06 13:25:45 +00:00
|
|
|
v = &g_array_index (journal->vertices, float, next_vert);
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_journal_dump_logged_quad ((uint8_t *)v, n_layers);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
next_entry = journal->entries->len;
|
|
|
|
g_array_set_size (journal->entries, next_entry + 1);
|
|
|
|
entry = &g_array_index (journal->entries, CoglJournalEntry, next_entry);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-05-18 21:42:49 +00:00
|
|
|
entry->n_layers = n_layers;
|
2010-11-09 19:18:37 +00:00
|
|
|
entry->array_offset = next_vert;
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2012-01-08 03:00:57 +00:00
|
|
|
final_pipeline = pipeline;
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2010-05-18 22:38:33 +00:00
|
|
|
flush_options.flags = 0;
|
2010-10-27 17:54:57 +00:00
|
|
|
if (G_UNLIKELY (cogl_pipeline_get_n_layers (pipeline) != n_layers))
|
2010-05-18 21:42:49 +00:00
|
|
|
{
|
|
|
|
disable_layers = (1 << n_layers) - 1;
|
|
|
|
disable_layers = ~disable_layers;
|
|
|
|
flush_options.disable_layers = disable_layers;
|
2010-10-27 17:54:57 +00:00
|
|
|
flush_options.flags |= COGL_PIPELINE_FLUSH_DISABLE_MASK;
|
2010-05-18 21:42:49 +00:00
|
|
|
}
|
|
|
|
if (G_UNLIKELY (layer0_override_texture))
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
flush_options.flags |= COGL_PIPELINE_FLUSH_LAYER0_OVERRIDE;
|
2010-05-18 21:42:49 +00:00
|
|
|
flush_options.layer0_override_texture = layer0_override_texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (flush_options.flags))
|
2009-09-16 13:01:57 +00:00
|
|
|
{
|
2012-01-08 03:00:57 +00:00
|
|
|
final_pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
_cogl_pipeline_apply_overrides (final_pipeline, &flush_options);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2012-01-08 03:00:57 +00:00
|
|
|
entry->pipeline = _cogl_pipeline_journal_ref (final_pipeline);
|
2011-01-12 19:30:30 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
clip_stack = _cogl_framebuffer_get_clip_stack (framebuffer);
|
2011-01-12 19:30:30 +00:00
|
|
|
entry->clip_stack = _cogl_clip_stack_ref (clip_stack);
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2012-01-08 03:00:57 +00:00
|
|
|
if (G_UNLIKELY (final_pipeline != pipeline))
|
2012-04-16 13:14:10 +00:00
|
|
|
cogl_object_unref (final_pipeline);
|
2010-05-18 21:42:49 +00:00
|
|
|
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
modelview_stack =
|
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2012-11-20 17:08:43 +00:00
|
|
|
entry->modelview_entry = cogl_matrix_entry_ref (modelview_stack->last_entry);
|
2009-09-16 13:01:57 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_pipeline_foreach_layer_internal (pipeline,
|
|
|
|
add_framebuffer_deps_cb,
|
2012-03-16 19:54:13 +00:00
|
|
|
framebuffer);
|
2011-01-06 13:25:45 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_BATCHING)))
|
2012-03-16 17:26:30 +00:00
|
|
|
_cogl_journal_flush (journal);
|
2009-07-03 15:22:35 +00:00
|
|
|
|
|
|
|
COGL_TIMER_STOP (_cogl_uprof_context, log_timer);
|
2009-09-16 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
static void
|
2012-01-24 18:16:03 +00:00
|
|
|
entry_to_screen_polygon (CoglFramebuffer *framebuffer,
|
|
|
|
const CoglJournalEntry *entry,
|
2011-01-12 22:12:41 +00:00
|
|
|
float *vertices,
|
|
|
|
float *poly)
|
|
|
|
{
|
|
|
|
size_t array_stride =
|
|
|
|
GET_JOURNAL_ARRAY_STRIDE_FOR_N_LAYERS (entry->n_layers);
|
|
|
|
CoglMatrixStack *projection_stack;
|
|
|
|
CoglMatrix projection;
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
CoglMatrix modelview;
|
2011-01-12 22:12:41 +00:00
|
|
|
int i;
|
2011-02-01 16:51:58 +00:00
|
|
|
float viewport[4];
|
2011-01-12 22:12:41 +00:00
|
|
|
|
|
|
|
poly[0] = vertices[0];
|
|
|
|
poly[1] = vertices[1];
|
|
|
|
poly[2] = 0;
|
|
|
|
poly[3] = 1;
|
|
|
|
|
|
|
|
poly[4] = vertices[0];
|
|
|
|
poly[5] = vertices[array_stride + 1];
|
|
|
|
poly[6] = 0;
|
|
|
|
poly[7] = 1;
|
|
|
|
|
|
|
|
poly[8] = vertices[array_stride];
|
|
|
|
poly[9] = vertices[array_stride + 1];
|
|
|
|
poly[10] = 0;
|
|
|
|
poly[11] = 1;
|
|
|
|
|
|
|
|
poly[12] = vertices[array_stride];
|
|
|
|
poly[13] = vertices[1];
|
|
|
|
poly[14] = 0;
|
|
|
|
poly[15] = 1;
|
|
|
|
|
|
|
|
/* TODO: perhaps split the following out into a more generalized
|
|
|
|
* _cogl_transform_points utility...
|
|
|
|
*/
|
|
|
|
|
2012-11-20 17:08:43 +00:00
|
|
|
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
|
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)
2012-02-20 15:59:48 +00:00
|
|
|
cogl_matrix_transform_points (&modelview,
|
2011-01-12 22:12:41 +00:00
|
|
|
2, /* n_components */
|
|
|
|
sizeof (float) * 4, /* stride_in */
|
|
|
|
poly, /* points_in */
|
|
|
|
/* strideout */
|
|
|
|
sizeof (float) * 4,
|
|
|
|
poly, /* points_out */
|
|
|
|
4 /* n_points */);
|
|
|
|
|
|
|
|
projection_stack =
|
2012-01-24 18:16:03 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2012-11-20 17:08:43 +00:00
|
|
|
cogl_matrix_stack_get (projection_stack, &projection);
|
2011-01-12 22:12:41 +00:00
|
|
|
|
|
|
|
cogl_matrix_project_points (&projection,
|
|
|
|
3, /* n_components */
|
|
|
|
sizeof (float) * 4, /* stride_in */
|
|
|
|
poly, /* points_in */
|
|
|
|
/* strideout */
|
|
|
|
sizeof (float) * 4,
|
|
|
|
poly, /* points_out */
|
|
|
|
4 /* n_points */);
|
|
|
|
|
2012-01-24 18:16:03 +00:00
|
|
|
cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
2011-01-12 22:12:41 +00:00
|
|
|
|
|
|
|
/* Scale from OpenGL normalized device coordinates (ranging from -1 to 1)
|
|
|
|
* to Cogl window/framebuffer coordinates (ranging from 0 to buffer-size) with
|
|
|
|
* (0,0) being top left. */
|
|
|
|
#define VIEWPORT_TRANSFORM_X(x, vp_origin_x, vp_width) \
|
|
|
|
( ( ((x) + 1.0) * ((vp_width) / 2.0) ) + (vp_origin_x) )
|
|
|
|
/* Note: for Y we first flip all coordinates around the X axis while in
|
|
|
|
* normalized device coodinates */
|
|
|
|
#define VIEWPORT_TRANSFORM_Y(y, vp_origin_y, vp_height) \
|
|
|
|
( ( ((-(y)) + 1.0) * ((vp_height) / 2.0) ) + (vp_origin_y) )
|
|
|
|
|
|
|
|
/* Scale from normalized device coordinates (in range [-1,1]) to
|
|
|
|
* window coordinates ranging [0,window-size] ... */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
float w = poly[4 * i + 3];
|
|
|
|
|
|
|
|
/* Perform perspective division */
|
|
|
|
poly[4 * i] /= w;
|
|
|
|
poly[4 * i + 1] /= w;
|
|
|
|
|
|
|
|
/* Apply viewport transform */
|
|
|
|
poly[4 * i] = VIEWPORT_TRANSFORM_X (poly[4 * i],
|
|
|
|
viewport[0], viewport[2]);
|
|
|
|
poly[4 * i + 1] = VIEWPORT_TRANSFORM_Y (poly[4 * i + 1],
|
|
|
|
viewport[1], viewport[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VIEWPORT_TRANSFORM_X
|
|
|
|
#undef VIEWPORT_TRANSFORM_Y
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-01-24 18:16:03 +00:00
|
|
|
try_checking_point_hits_entry_after_clipping (CoglFramebuffer *framebuffer,
|
|
|
|
CoglJournalEntry *entry,
|
2011-01-12 22:12:41 +00:00
|
|
|
float *vertices,
|
|
|
|
float x,
|
|
|
|
float y,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean *hit)
|
2011-01-12 22:12:41 +00:00
|
|
|
{
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean can_software_clip = TRUE;
|
|
|
|
gboolean needs_software_clip = FALSE;
|
2011-01-12 22:12:41 +00:00
|
|
|
CoglClipStack *clip_entry;
|
|
|
|
|
|
|
|
*hit = TRUE;
|
|
|
|
|
|
|
|
/* Verify that all of the clip stack entries are simple rectangle
|
|
|
|
* clips */
|
|
|
|
for (clip_entry = entry->clip_stack;
|
|
|
|
clip_entry;
|
|
|
|
clip_entry = clip_entry->parent)
|
|
|
|
{
|
|
|
|
if (x < clip_entry->bounds_x0 ||
|
|
|
|
x >= clip_entry->bounds_x1 ||
|
|
|
|
y < clip_entry->bounds_y0 ||
|
|
|
|
y >= clip_entry->bounds_y1)
|
|
|
|
{
|
|
|
|
*hit = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clip_entry->type == COGL_CLIP_STACK_WINDOW_RECT)
|
|
|
|
{
|
|
|
|
/* XXX: technically we could still run the software clip in
|
|
|
|
* this case because for our purposes we know this clip
|
|
|
|
* can be ignored now, but [can_]sofware_clip_entry() doesn't
|
|
|
|
* know this and will bail out. */
|
|
|
|
can_software_clip = FALSE;
|
|
|
|
}
|
|
|
|
else if (clip_entry->type == COGL_CLIP_STACK_RECT)
|
|
|
|
{
|
|
|
|
CoglClipStackRect *rect_entry = (CoglClipStackRect *)entry;
|
|
|
|
|
|
|
|
if (rect_entry->can_be_scissor == FALSE)
|
|
|
|
needs_software_clip = TRUE;
|
|
|
|
/* If can_be_scissor is TRUE then we know it's screen
|
|
|
|
* aligned and the hit test we did above has determined
|
|
|
|
* that we are inside this clip. */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needs_software_clip)
|
|
|
|
{
|
|
|
|
ClipBounds clip_bounds;
|
|
|
|
float poly[16];
|
|
|
|
|
2011-01-20 14:41:51 +00:00
|
|
|
if (!can_software_clip)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
if (!can_software_clip_entry (entry, NULL,
|
|
|
|
entry->clip_stack, &clip_bounds))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
software_clip_entry (entry, vertices, &clip_bounds);
|
2012-01-24 18:16:03 +00:00
|
|
|
entry_to_screen_polygon (framebuffer, entry, vertices, poly);
|
2011-01-12 22:12:41 +00:00
|
|
|
|
2011-03-03 23:19:30 +00:00
|
|
|
*hit = _cogl_util_point_in_screen_poly (x, y, poly, sizeof (float) * 4, 4);
|
2011-01-12 22:12:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean
|
2011-01-12 22:12:41 +00:00
|
|
|
_cogl_journal_try_read_pixel (CoglJournal *journal,
|
|
|
|
int x,
|
|
|
|
int y,
|
2012-02-25 19:23:51 +00:00
|
|
|
CoglBitmap *bitmap,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean *found_intersection)
|
2011-01-12 22:12:41 +00:00
|
|
|
{
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglContext *ctx;
|
2012-02-25 19:23:51 +00:00
|
|
|
CoglPixelFormat format;
|
2011-01-12 22:12:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* XXX: this number has been plucked out of thin air, but the idea
|
|
|
|
* is that if so many pixels are being read from the same un-changed
|
|
|
|
* journal than we expect that it will be more efficient to fail
|
|
|
|
* here so we end up flushing and rendering the journal so that
|
|
|
|
* further reads can directly read from the framebuffer. There will
|
|
|
|
* be a bit more lag to flush the render but if there are going to
|
|
|
|
* continue being lots of arbitrary single pixel reads they will end
|
|
|
|
* up faster in the end. */
|
|
|
|
if (journal->fast_read_pixel_count > 50)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-25 20:18:05 +00:00
|
|
|
format = cogl_bitmap_get_format (bitmap);
|
2012-02-25 19:23:51 +00:00
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
if (format != COGL_PIXEL_FORMAT_RGBA_8888_PRE &&
|
|
|
|
format != COGL_PIXEL_FORMAT_RGBA_8888)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
ctx = _cogl_bitmap_get_context (bitmap);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
*found_intersection = FALSE;
|
|
|
|
|
|
|
|
/* NB: The most recently added journal entry is the last entry, and
|
|
|
|
* assuming this is a simple scene only comprised of opaque coloured
|
|
|
|
* rectangles with no special pipelines involved (e.g. enabling
|
|
|
|
* depth testing) then we can assume painter's algorithm for the
|
|
|
|
* entries and so our fast read-pixel just needs to walk backwards
|
|
|
|
* through the journal entries trying to intersect each entry with
|
|
|
|
* the given point of interest. */
|
|
|
|
for (i = journal->entries->len - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
CoglJournalEntry *entry =
|
|
|
|
&g_array_index (journal->entries, CoglJournalEntry, i);
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *color = (uint8_t *)&g_array_index (journal->vertices, float,
|
2011-01-12 22:12:41 +00:00
|
|
|
entry->array_offset);
|
|
|
|
float *vertices = (float *)color + 1;
|
|
|
|
float poly[16];
|
2012-01-24 18:16:03 +00:00
|
|
|
CoglFramebuffer *framebuffer = journal->framebuffer;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *pixel;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *ignore_error;
|
2011-01-12 22:12:41 +00:00
|
|
|
|
2012-01-24 18:16:03 +00:00
|
|
|
entry_to_screen_polygon (framebuffer, entry, vertices, poly);
|
2011-01-12 22:12:41 +00:00
|
|
|
|
2011-03-03 23:19:30 +00:00
|
|
|
if (!_cogl_util_point_in_screen_poly (x, y, poly, sizeof (float) * 4, 4))
|
2011-01-12 22:12:41 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (entry->clip_stack)
|
|
|
|
{
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean hit;
|
2011-01-12 22:12:41 +00:00
|
|
|
|
2012-01-24 18:16:03 +00:00
|
|
|
if (!try_checking_point_hits_entry_after_clipping (framebuffer,
|
|
|
|
entry,
|
|
|
|
vertices,
|
2011-01-12 22:12:41 +00:00
|
|
|
x, y, &hit))
|
|
|
|
return FALSE; /* hit couldn't be determined */
|
|
|
|
|
|
|
|
if (!hit)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*found_intersection = TRUE;
|
|
|
|
|
|
|
|
/* If we find that the rectangle the point of interest
|
|
|
|
* intersects has any state more complex than a constant opaque
|
|
|
|
* color then we bail out. */
|
|
|
|
if (!_cogl_pipeline_equal (ctx->opaque_color_pipeline, entry->pipeline,
|
|
|
|
(COGL_PIPELINE_STATE_ALL &
|
|
|
|
~COGL_PIPELINE_STATE_COLOR),
|
|
|
|
COGL_PIPELINE_LAYER_STATE_ALL,
|
|
|
|
0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
/* we currently only care about cases where the premultiplied or
|
|
|
|
* unpremultipled colors are equivalent... */
|
|
|
|
if (color[3] != 0xff)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-25 19:23:51 +00:00
|
|
|
pixel = _cogl_bitmap_map (bitmap,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
2012-11-08 17:54:10 +00:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD,
|
|
|
|
&ignore_error);
|
2012-02-25 19:23:51 +00:00
|
|
|
if (pixel == NULL)
|
2012-11-08 17:54:10 +00:00
|
|
|
{
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (ignore_error);
|
2012-11-08 17:54:10 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-02-25 19:23:51 +00:00
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
pixel[0] = color[0];
|
|
|
|
pixel[1] = color[1];
|
|
|
|
pixel[2] = color[2];
|
|
|
|
pixel[3] = color[3];
|
|
|
|
|
2012-02-25 19:23:51 +00:00
|
|
|
_cogl_bitmap_unmap (bitmap);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
|
|
|
|
success:
|
|
|
|
journal->fast_read_pixel_count++;
|
|
|
|
return TRUE;
|
|
|
|
}
|