2008-04-30 11:05:17 -04:00
|
|
|
/*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Cogl
|
2008-04-30 11:05:17 -04:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-04-30 11:05:17 -04:00
|
|
|
*
|
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-09 20:57:32 -05:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2008-04-30 11:05:17 -04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-04-30 11:05:17 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-context.h"
|
2009-09-16 09:01:57 -04:00
|
|
|
#include "cogl-journal-private.h"
|
2009-03-23 08:29:15 -04:00
|
|
|
#include "cogl-texture-private.h"
|
2009-05-23 12:42:10 -04:00
|
|
|
#include "cogl-material-private.h"
|
2009-06-01 12:10:22 -04:00
|
|
|
#include "cogl-vertex-buffer-private.h"
|
2009-11-26 14:06:35 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2008-04-30 11:05:17 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
2009-01-20 11:20:54 -05:00
|
|
|
#include <math.h>
|
2008-04-30 11:05:17 -04:00
|
|
|
|
|
|
|
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16
|
|
|
|
|
2009-10-16 23:06:56 -04:00
|
|
|
#ifdef HAVE_COGL_GL
|
|
|
|
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
|
|
|
#endif
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
typedef struct _TextureSlicedQuadState
|
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
float tex_virtual_origin_x;
|
|
|
|
float tex_virtual_origin_y;
|
|
|
|
float quad_origin_x;
|
|
|
|
float quad_origin_y;
|
|
|
|
float v_to_q_scale_x;
|
|
|
|
float v_to_q_scale_y;
|
|
|
|
float quad_len_x;
|
|
|
|
float quad_len_y;
|
|
|
|
gboolean flipped_x;
|
|
|
|
gboolean flipped_y;
|
2010-04-01 13:35:32 -04:00
|
|
|
CoglMaterialWrapModeOverrides *wrap_mode_overrides;
|
2009-09-16 06:56:17 -04:00
|
|
|
} TextureSlicedQuadState;
|
|
|
|
|
|
|
|
typedef struct _TextureSlicedPolygonState
|
|
|
|
{
|
2010-01-04 06:43:00 -05:00
|
|
|
const CoglTextureVertex *vertices;
|
2009-09-16 06:56:17 -04:00
|
|
|
int n_vertices;
|
|
|
|
int stride;
|
|
|
|
} TextureSlicedPolygonState;
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
static void
|
2009-09-16 06:56:17 -04:00
|
|
|
log_quad_sub_textures_cb (CoglHandle texture_handle,
|
|
|
|
GLuint gl_handle,
|
|
|
|
GLenum gl_target,
|
2009-12-02 12:17:24 -05:00
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
2009-09-16 06:56:17 -04:00
|
|
|
void *user_data)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2009-09-16 06:56:17 -04:00
|
|
|
TextureSlicedQuadState *state = user_data;
|
|
|
|
float quad_coords[4];
|
|
|
|
|
|
|
|
#define TEX_VIRTUAL_TO_QUAD(V, Q, AXIS) \
|
|
|
|
do { \
|
|
|
|
Q = V - state->tex_virtual_origin_##AXIS; \
|
|
|
|
Q *= state->v_to_q_scale_##AXIS; \
|
|
|
|
if (state->flipped_##AXIS) \
|
|
|
|
Q = state->quad_len_##AXIS - Q; \
|
|
|
|
Q += state->quad_origin_##AXIS; \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
TEX_VIRTUAL_TO_QUAD (virtual_coords[0], quad_coords[0], x);
|
|
|
|
TEX_VIRTUAL_TO_QUAD (virtual_coords[1], quad_coords[1], y);
|
|
|
|
|
|
|
|
TEX_VIRTUAL_TO_QUAD (virtual_coords[2], quad_coords[2], x);
|
|
|
|
TEX_VIRTUAL_TO_QUAD (virtual_coords[3], quad_coords[3], y);
|
|
|
|
|
|
|
|
#undef TEX_VIRTUAL_TO_QUAD
|
|
|
|
|
|
|
|
COGL_NOTE (DRAW,
|
|
|
|
"~~~~~ slice\n"
|
|
|
|
"qx1: %f\t"
|
|
|
|
"qy1: %f\n"
|
|
|
|
"qx2: %f\t"
|
|
|
|
"qy2: %f\n"
|
|
|
|
"tx1: %f\t"
|
|
|
|
"ty1: %f\n"
|
|
|
|
"tx2: %f\t"
|
|
|
|
"ty2: %f\n",
|
|
|
|
quad_coords[0], quad_coords[1],
|
|
|
|
quad_coords[2], quad_coords[3],
|
|
|
|
subtexture_coords[0], subtexture_coords[1],
|
|
|
|
subtexture_coords[2], subtexture_coords[3]);
|
|
|
|
|
|
|
|
/* FIXME: when the wrap mode becomes part of the material we need to
|
|
|
|
* be able to override the wrap mode when logging a quad. */
|
2010-02-11 10:33:01 -05:00
|
|
|
_cogl_journal_log_quad (quad_coords,
|
2009-09-16 06:56:17 -04:00
|
|
|
state->material,
|
|
|
|
1, /* one layer */
|
|
|
|
0, /* don't need to use fallbacks */
|
|
|
|
gl_handle, /* replace the layer0 texture */
|
2010-04-01 13:35:32 -04:00
|
|
|
state->wrap_mode_overrides, /* use GL_CLAMP_TO_EDGE */
|
2009-09-16 06:56:17 -04:00
|
|
|
subtexture_coords,
|
|
|
|
4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This path doesn't currently support multitexturing but is used for
|
|
|
|
* CoglTextures that don't support repeating using the GPU so we need to
|
|
|
|
* manually emit extra geometry to fake the repeating. This includes:
|
|
|
|
*
|
|
|
|
* - CoglTexture2DSliced: when made of > 1 slice or if the users given
|
|
|
|
* texture coordinates require repeating,
|
|
|
|
* - CoglTexture2DAtlas: if the users given texture coordinates require
|
|
|
|
* repeating,
|
|
|
|
* - CoglTextureRectangle: if the users given texture coordinates require
|
|
|
|
* repeating,
|
|
|
|
* - CoglTexturePixmap: if the users given texture coordinates require
|
|
|
|
* repeating
|
|
|
|
*/
|
|
|
|
/* TODO: support multitexturing */
|
|
|
|
static void
|
|
|
|
_cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
|
|
|
|
CoglHandle material,
|
2010-04-01 06:31:33 -04:00
|
|
|
gboolean clamp_s,
|
|
|
|
gboolean clamp_t,
|
2010-02-11 10:33:01 -05:00
|
|
|
const float *position,
|
2009-09-16 06:56:17 -04:00
|
|
|
float tx_1,
|
|
|
|
float ty_1,
|
|
|
|
float tx_2,
|
|
|
|
float ty_2)
|
|
|
|
{
|
|
|
|
TextureSlicedQuadState state;
|
2010-04-01 13:35:32 -04:00
|
|
|
CoglMaterialWrapModeOverrides wrap_mode_overrides;
|
2009-09-16 06:56:17 -04:00
|
|
|
gboolean tex_virtual_flipped_x;
|
|
|
|
gboolean tex_virtual_flipped_y;
|
|
|
|
gboolean quad_flipped_x;
|
|
|
|
gboolean quad_flipped_y;
|
2010-04-01 13:35:32 -04:00
|
|
|
CoglHandle first_layer;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-04-01 06:31:33 -04:00
|
|
|
/* If the wrap mode is clamp to edge then we'll recursively draw the
|
|
|
|
stretched part and replace the coordinates */
|
|
|
|
if (clamp_s && tx_1 != tx_2)
|
|
|
|
{
|
|
|
|
float *replacement_position = g_newa (float, 4);
|
|
|
|
float old_tx_1 = tx_1, old_tx_2 = tx_2;
|
|
|
|
|
|
|
|
memcpy (replacement_position, position, sizeof (float) * 4);
|
|
|
|
|
|
|
|
tx_1 = CLAMP (tx_1, 0.0f, 1.0f);
|
|
|
|
tx_2 = CLAMP (tx_2, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
if (old_tx_1 != tx_1)
|
|
|
|
{
|
|
|
|
/* Draw the left part of the quad as a stretched copy of tx_1 */
|
|
|
|
float tmp_position[] =
|
|
|
|
{ position[0], position[1],
|
|
|
|
(position[0] +
|
|
|
|
(position[2] - position[0]) *
|
|
|
|
(tx_1 - old_tx_1) / (old_tx_2 - old_tx_1)),
|
|
|
|
position[3] };
|
|
|
|
_cogl_texture_quad_multiple_primitives (tex_handle, material,
|
|
|
|
FALSE, clamp_t,
|
|
|
|
tmp_position,
|
|
|
|
tx_1, ty_1, tx_1, ty_2);
|
|
|
|
replacement_position[0] = tmp_position[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_tx_2 != tx_2)
|
|
|
|
{
|
|
|
|
/* Draw the right part of the quad as a stretched copy of tx_2 */
|
|
|
|
float tmp_position[] =
|
|
|
|
{ (position[0] +
|
|
|
|
(position[2] - position[0]) *
|
|
|
|
(tx_2 - old_tx_1) / (old_tx_2 - old_tx_1)),
|
|
|
|
position[1], position[2], position[3] };
|
|
|
|
_cogl_texture_quad_multiple_primitives (tex_handle, material,
|
|
|
|
FALSE, clamp_t,
|
|
|
|
tmp_position,
|
|
|
|
tx_2, ty_1, tx_2, ty_2);
|
|
|
|
replacement_position[2] = tmp_position[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's no main part left then we don't need to continue */
|
|
|
|
if (tx_1 == tx_2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
position = replacement_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clamp_t && ty_1 != ty_2)
|
|
|
|
{
|
|
|
|
float *replacement_position = g_newa (float, 4);
|
|
|
|
float old_ty_1 = ty_1, old_ty_2 = ty_2;
|
|
|
|
|
|
|
|
memcpy (replacement_position, position, sizeof (float) * 4);
|
|
|
|
|
|
|
|
ty_1 = CLAMP (ty_1, 0.0f, 1.0f);
|
|
|
|
ty_2 = CLAMP (ty_2, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
if (old_ty_1 != ty_1)
|
|
|
|
{
|
|
|
|
/* Draw the top part of the quad as a stretched copy of ty_1 */
|
|
|
|
float tmp_position[] =
|
|
|
|
{ position[0], position[1], position[2],
|
|
|
|
(position[1] +
|
|
|
|
(position[3] - position[1]) *
|
|
|
|
(ty_1 - old_ty_1) / (old_ty_2 - old_ty_1)) };
|
|
|
|
_cogl_texture_quad_multiple_primitives (tex_handle, material,
|
|
|
|
clamp_s, FALSE,
|
|
|
|
tmp_position,
|
|
|
|
tx_1, ty_1, tx_2, ty_1);
|
|
|
|
replacement_position[1] = tmp_position[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_ty_2 != ty_2)
|
|
|
|
{
|
|
|
|
/* Draw the bottom part of the quad as a stretched copy of ty_2 */
|
|
|
|
float tmp_position[] =
|
|
|
|
{ position[0],
|
|
|
|
(position[1] +
|
|
|
|
(position[3] - position[1]) *
|
|
|
|
(ty_2 - old_ty_1) / (old_ty_2 - old_ty_1)),
|
|
|
|
position[2], position[3] };
|
|
|
|
_cogl_texture_quad_multiple_primitives (tex_handle, material,
|
|
|
|
clamp_s, FALSE,
|
|
|
|
tmp_position,
|
|
|
|
tx_1, ty_2, tx_2, ty_2);
|
|
|
|
replacement_position[3] = tmp_position[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's no main part left then we don't need to continue */
|
|
|
|
if (ty_1 == ty_2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
position = replacement_position;
|
|
|
|
}
|
|
|
|
|
2010-04-01 13:35:32 -04:00
|
|
|
state.wrap_mode_overrides = NULL;
|
2010-04-01 06:31:33 -04:00
|
|
|
memset (&state.wrap_mode_overrides, 0, sizeof (state.wrap_mode_overrides));
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
/* We can't use hardware repeat so we need to set clamp to edge
|
2010-04-01 13:35:32 -04:00
|
|
|
otherwise it might pull in edge pixels from the other side. By
|
|
|
|
default WRAP_MODE_AUTOMATIC becomes CLAMP_TO_EDGE so we only need
|
|
|
|
to override if the wrap mode is repeat */
|
|
|
|
first_layer = cogl_material_get_layers (material)->data;
|
|
|
|
if (cogl_material_layer_get_wrap_mode_s (first_layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_REPEAT)
|
|
|
|
{
|
|
|
|
state.wrap_mode_overrides = &wrap_mode_overrides;
|
|
|
|
wrap_mode_overrides.values[0].s =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_CLAMP_TO_EDGE;
|
|
|
|
}
|
|
|
|
if (cogl_material_layer_get_wrap_mode_t (first_layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_REPEAT)
|
|
|
|
{
|
|
|
|
state.wrap_mode_overrides = &wrap_mode_overrides;
|
|
|
|
wrap_mode_overrides.values[0].t =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_CLAMP_TO_EDGE;
|
|
|
|
}
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
state.material = material;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
/* Get together the data we need to transform the virtual texture
|
|
|
|
* coordinates of each slice into quad coordinates...
|
|
|
|
*
|
|
|
|
* NB: We need to consider that the quad coordinates and the texture
|
|
|
|
* coordinates may be inverted along the x or y axis, and must preserve the
|
|
|
|
* inversions when we emit the final geometry.
|
|
|
|
*/
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
#define X0 0
|
|
|
|
#define Y0 1
|
|
|
|
#define X1 2
|
|
|
|
#define Y1 3
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
tex_virtual_flipped_x = (tx_1 > tx_2) ? TRUE : FALSE;
|
|
|
|
tex_virtual_flipped_y = (ty_1 > ty_2) ? TRUE : FALSE;
|
|
|
|
state.tex_virtual_origin_x = tex_virtual_flipped_x ? tx_2 : tx_1;
|
|
|
|
state.tex_virtual_origin_y = tex_virtual_flipped_y ? ty_2 : ty_1;
|
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
quad_flipped_x = (position[X0] > position[X1]) ? TRUE : FALSE;
|
|
|
|
quad_flipped_y = (position[Y0] > position[Y1]) ? TRUE : FALSE;
|
|
|
|
state.quad_origin_x = quad_flipped_x ? position[X1] : position[X0];
|
|
|
|
state.quad_origin_y = quad_flipped_y ? position[Y1] : position[Y0];
|
2009-09-16 06:56:17 -04:00
|
|
|
|
|
|
|
/* flatten the two forms of coordinate inversion into one... */
|
|
|
|
state.flipped_x = tex_virtual_flipped_x ^ quad_flipped_x;
|
|
|
|
state.flipped_y = tex_virtual_flipped_y ^ quad_flipped_y;
|
|
|
|
|
|
|
|
/* We use the _len_AXIS naming here instead of _width and _height because
|
|
|
|
* log_quad_slice_cb uses a macro with symbol concatenation to handle both
|
|
|
|
* axis, so this is more convenient... */
|
2010-02-11 10:33:01 -05:00
|
|
|
state.quad_len_x = fabs (position[X1] - position[X0]);
|
|
|
|
state.quad_len_y = fabs (position[Y1] - position[Y0]);
|
|
|
|
|
|
|
|
#undef X0
|
|
|
|
#undef Y0
|
|
|
|
#undef X1
|
|
|
|
#undef Y1
|
2009-09-16 06:56:17 -04:00
|
|
|
|
|
|
|
state.v_to_q_scale_x = fabs (state.quad_len_x / (tx_2 - tx_1));
|
|
|
|
state.v_to_q_scale_y = fabs (state.quad_len_y / (ty_2 - ty_1));
|
|
|
|
|
|
|
|
_cogl_texture_foreach_sub_texture_in_region (tex_handle,
|
|
|
|
tx_1, ty_1, tx_2, ty_2,
|
|
|
|
log_quad_sub_textures_cb,
|
|
|
|
&state);
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
/* This path supports multitexturing but only when each of the layers is
|
|
|
|
* handled with a single GL texture. Also if repeating is necessary then
|
|
|
|
* _cogl_texture_can_hardware_repeat() must return TRUE.
|
|
|
|
* This includes layers made from:
|
|
|
|
*
|
|
|
|
* - CoglTexture2DSliced: if only comprised of a single slice with optional
|
|
|
|
* waste, assuming the users given texture coordinates don't require
|
|
|
|
* repeating.
|
|
|
|
* - CoglTexture{1D,2D,3D}: always.
|
|
|
|
* - CoglTexture2DAtlas: assuming the users given texture coordinates don't
|
|
|
|
* require repeating.
|
|
|
|
* - CoglTextureRectangle: assuming the users given texture coordinates don't
|
|
|
|
* require repeating.
|
|
|
|
* - CoglTexturePixmap: assuming the users given texture coordinates don't
|
|
|
|
* require repeating.
|
|
|
|
*/
|
2009-03-23 08:29:15 -04:00
|
|
|
static gboolean
|
2010-02-11 10:33:01 -05:00
|
|
|
_cogl_multitexture_quad_single_primitive (const float *position,
|
2009-09-16 06:56:17 -04:00
|
|
|
CoglHandle material,
|
|
|
|
guint32 fallback_layers,
|
|
|
|
const float *user_tex_coords,
|
|
|
|
int user_tex_coords_len)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
int n_layers = cogl_material_get_n_layers (material);
|
|
|
|
float *final_tex_coords = alloca (sizeof (float) * 4 * n_layers);
|
2009-03-23 08:29:15 -04:00
|
|
|
const GList *layers;
|
|
|
|
GList *tmp;
|
|
|
|
int i;
|
2010-04-01 06:31:33 -04:00
|
|
|
CoglMaterialWrapModeOverrides wrap_mode_overrides;
|
2010-04-01 13:35:32 -04:00
|
|
|
/* This will be set to point to wrap_mode_overrides when an override
|
|
|
|
is needed */
|
|
|
|
CoglMaterialWrapModeOverrides *wrap_mode_overrides_p = NULL;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
2010-04-01 06:31:33 -04:00
|
|
|
memset (&wrap_mode_overrides, 0, sizeof (wrap_mode_overrides));
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
/*
|
|
|
|
* Validate the texture coordinates for this rectangle.
|
|
|
|
*/
|
|
|
|
layers = cogl_material_get_layers (material);
|
|
|
|
for (tmp = (GList *)layers, i = 0; tmp != NULL; tmp = tmp->next, i++)
|
|
|
|
{
|
2010-03-01 16:49:04 -05:00
|
|
|
CoglHandle layer = (CoglHandle)tmp->data;
|
|
|
|
CoglHandle tex_handle;
|
|
|
|
const float *in_tex_coords;
|
|
|
|
float *out_tex_coords;
|
|
|
|
float default_tex_coords[4] = {0.0, 0.0, 1.0, 1.0};
|
|
|
|
CoglTransformResult transform_result;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-06-19 07:15:12 -04:00
|
|
|
tex_handle = cogl_material_layer_get_texture (layer);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-06-19 07:15:12 -04:00
|
|
|
/* COGL_INVALID_HANDLE textures are handled by
|
|
|
|
* _cogl_material_flush_gl_state */
|
|
|
|
if (tex_handle == COGL_INVALID_HANDLE)
|
|
|
|
continue;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-11-27 10:47:22 -05:00
|
|
|
/* If the user didn't supply texture coordinates for this layer
|
|
|
|
then use the default coords */
|
|
|
|
if (i >= user_tex_coords_len / 4)
|
|
|
|
in_tex_coords = default_tex_coords;
|
|
|
|
else
|
|
|
|
in_tex_coords = &user_tex_coords[i * 4];
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
out_tex_coords = &final_tex_coords[i * 4];
|
|
|
|
|
2009-11-27 10:47:22 -05:00
|
|
|
memcpy (out_tex_coords, in_tex_coords, sizeof (GLfloat) * 4);
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
/* Convert the texture coordinates to GL.
|
|
|
|
*/
|
|
|
|
transform_result =
|
|
|
|
_cogl_texture_transform_quad_coords_to_gl (tex_handle,
|
|
|
|
out_tex_coords);
|
2009-03-23 08:29:15 -04:00
|
|
|
/* If the texture has waste or we are using GL_TEXTURE_RECT we
|
2009-11-27 10:47:22 -05:00
|
|
|
* can't handle texture repeating so we can't use the layer if
|
|
|
|
* repeating is required.
|
2009-09-16 06:56:17 -04:00
|
|
|
*
|
|
|
|
* NB: We already know that no texture matrix is being used if the
|
|
|
|
* texture doesn't support hardware repeat.
|
2009-03-23 08:29:15 -04:00
|
|
|
*/
|
2010-03-01 16:49:04 -05:00
|
|
|
if (transform_result == COGL_TRANSFORM_SOFTWARE_REPEAT)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
if (n_layers > 1)
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layers 1..n of your material since "
|
2009-09-16 06:56:17 -04:00
|
|
|
"the first layer doesn't support hardware "
|
|
|
|
"repeat (e.g. because of waste or use of "
|
|
|
|
"GL_TEXTURE_RECTANGLE_ARB) and you supplied "
|
|
|
|
"texture coordinates outside the range [0,1]."
|
|
|
|
"Falling back to software repeat assuming "
|
2009-03-23 08:29:15 -04:00
|
|
|
"layer 0 is the most important one keep");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layer %d of your material "
|
2009-09-16 06:56:17 -04:00
|
|
|
"since you have supplied texture coords "
|
|
|
|
"outside the range [0,1] but the texture "
|
|
|
|
"doesn't support hardware repeat (e.g. "
|
|
|
|
"because of waste or use of "
|
|
|
|
"GL_TEXTURE_RECTANGLE_ARB). This isn't "
|
|
|
|
"supported with multi-texturing.", i);
|
2009-03-23 08:29:15 -04:00
|
|
|
warning_seen = TRUE;
|
|
|
|
|
|
|
|
/* NB: marking for fallback will replace the layer with
|
|
|
|
* a default transparent texture */
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers |= (1 << i);
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-01 13:35:32 -04:00
|
|
|
/* By default WRAP_MODE_AUTOMATIC becomes to CLAMP_TO_EDGE. If
|
|
|
|
the texture coordinates need repeating then we'll override
|
|
|
|
this to GL_REPEAT. Otherwise we'll leave it at CLAMP_TO_EDGE
|
|
|
|
so that it won't blend in pixels from the opposite side when
|
|
|
|
the full texture is drawn with GL_LINEAR filter mode */
|
2010-03-01 16:49:04 -05:00
|
|
|
if (transform_result == COGL_TRANSFORM_HARDWARE_REPEAT)
|
2010-04-01 13:35:32 -04:00
|
|
|
{
|
|
|
|
if (cogl_material_layer_get_wrap_mode_s (layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
wrap_mode_overrides.values[i].s
|
|
|
|
= COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
|
|
|
|
wrap_mode_overrides_p = &wrap_mode_overrides;
|
|
|
|
}
|
|
|
|
if (cogl_material_layer_get_wrap_mode_t (layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
wrap_mode_overrides.values[i].t
|
|
|
|
= COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
|
|
|
|
wrap_mode_overrides_p = &wrap_mode_overrides;
|
|
|
|
}
|
|
|
|
}
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
_cogl_journal_log_quad (position,
|
2009-03-23 08:29:15 -04:00
|
|
|
material,
|
|
|
|
n_layers,
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers,
|
2009-03-23 08:29:15 -04:00
|
|
|
0, /* don't replace the layer0 texture */
|
2010-04-01 13:35:32 -04:00
|
|
|
wrap_mode_overrides_p,
|
2009-03-23 08:29:15 -04:00
|
|
|
final_tex_coords,
|
|
|
|
n_layers * 4);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct _CoglMutiTexturedRect
|
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
const float *position; /* x0,y0,x1,y1 */
|
|
|
|
const float *tex_coords; /* (tx0,ty0,tx1,ty1)(tx0,ty0,tx1,ty1)(... */
|
|
|
|
int tex_coords_len; /* number of floats in tex_coords? */
|
2009-03-23 08:29:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_rectangles_with_multitexture_coords (
|
|
|
|
struct _CoglMutiTexturedRect *rects,
|
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-09 20:57:32 -05:00
|
|
|
int n_rects)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
const GList *layers;
|
|
|
|
int n_layers;
|
|
|
|
const GList *tmp;
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
guint32 fallback_layers = 0;
|
2009-03-23 08:29:15 -04:00
|
|
|
gboolean all_use_sliced_quad_fallback = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
material = ctx->source_material;
|
|
|
|
|
|
|
|
layers = cogl_material_get_layers (material);
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
n_layers = cogl_material_get_n_layers (material);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate all the layers of the current source material...
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (tmp = layers, i = 0; tmp != NULL; tmp = tmp->next, i++)
|
|
|
|
{
|
|
|
|
CoglHandle layer = tmp->data;
|
2009-06-19 07:15:12 -04:00
|
|
|
CoglHandle tex_handle;
|
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-09 20:57:32 -05:00
|
|
|
unsigned long flags;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
if (cogl_material_layer_get_type (layer)
|
|
|
|
!= COGL_MATERIAL_LAYER_TYPE_TEXTURE)
|
|
|
|
continue;
|
|
|
|
|
2010-01-14 12:57:43 -05:00
|
|
|
/* We need to ensure the mipmaps are ready before deciding
|
|
|
|
anything else about the texture because it could become
|
|
|
|
something completely different if it needs to be migrated out
|
|
|
|
of the atlas */
|
|
|
|
_cogl_material_layer_ensure_mipmaps (layer);
|
|
|
|
|
2009-06-19 07:15:12 -04:00
|
|
|
tex_handle = cogl_material_layer_get_texture (layer);
|
|
|
|
|
|
|
|
/* COGL_INVALID_HANDLE textures are handled by
|
|
|
|
* _cogl_material_flush_gl_state */
|
|
|
|
if (tex_handle == COGL_INVALID_HANDLE)
|
|
|
|
continue;
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
/* XXX:
|
|
|
|
* For now, if the first layer is sliced then all other layers are
|
|
|
|
* ignored since we currently don't support multi-texturing with
|
|
|
|
* sliced textures. If the first layer is not sliced then any other
|
|
|
|
* layers found to be sliced will be skipped. (with a warning)
|
|
|
|
*
|
|
|
|
* TODO: Add support for multi-texturing rectangles with sliced
|
|
|
|
* textures if no texture matrices are in use.
|
|
|
|
*/
|
|
|
|
if (cogl_texture_is_sliced (tex_handle))
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers = ~1; /* fallback all except the first layer */
|
2009-03-23 08:29:15 -04:00
|
|
|
all_use_sliced_quad_fallback = TRUE;
|
|
|
|
if (tmp->next)
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layers 1..n of your material since "
|
|
|
|
"the first layer is sliced. We don't currently "
|
|
|
|
"support any multi-texturing with sliced "
|
|
|
|
"textures but assume layer 0 is the most "
|
|
|
|
"important to keep");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layer %d of your material consisting of "
|
|
|
|
"a sliced texture (unsuported for multi texturing)",
|
|
|
|
i);
|
|
|
|
warning_seen = TRUE;
|
|
|
|
|
|
|
|
/* NB: marking for fallback will replace the layer with
|
|
|
|
* a default transparent texture */
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers |= (1 << i);
|
2009-03-23 08:29:15 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
/* If the texture can't be repeated with the GPU (e.g. because it has
|
|
|
|
* waste or if using GL_TEXTURE_RECTANGLE_ARB) then we don't support
|
|
|
|
* multi texturing since we don't know if the result will end up trying
|
|
|
|
* to texture from the waste area. */
|
2009-05-23 12:42:10 -04:00
|
|
|
flags = _cogl_material_layer_get_flags (layer);
|
2009-03-23 08:29:15 -04:00
|
|
|
if (flags & COGL_MATERIAL_LAYER_FLAG_HAS_USER_MATRIX
|
2009-09-16 06:56:17 -04:00
|
|
|
&& !_cogl_texture_can_hardware_repeat (tex_handle))
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
2009-09-16 06:56:17 -04:00
|
|
|
g_warning ("Skipping layer %d of your material since a custom "
|
|
|
|
"texture matrix was given for a texture that can't be "
|
|
|
|
"repeated using the GPU and the result may try to "
|
|
|
|
"sample beyond the bounds of the texture ",
|
|
|
|
i);
|
2009-03-23 08:29:15 -04:00
|
|
|
warning_seen = TRUE;
|
|
|
|
|
|
|
|
/* NB: marking for fallback will replace the layer with
|
|
|
|
* a default transparent texture */
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers |= (1 << i);
|
2009-03-23 08:29:15 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit geometry for each of the rectangles...
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2009-09-16 06:56:17 -04:00
|
|
|
CoglHandle first_layer, tex_handle;
|
|
|
|
const float default_tex_coords[4] = {0.0, 0.0, 1.0, 1.0};
|
|
|
|
const float *tex_coords;
|
2010-04-01 06:31:33 -04:00
|
|
|
gboolean clamp_s, clamp_t;
|
2009-09-16 06:56:17 -04:00
|
|
|
|
|
|
|
if (!all_use_sliced_quad_fallback)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2009-09-16 06:56:17 -04:00
|
|
|
gboolean success =
|
2010-02-11 10:33:01 -05:00
|
|
|
_cogl_multitexture_quad_single_primitive (rects[i].position,
|
2009-09-16 06:56:17 -04:00
|
|
|
material,
|
|
|
|
fallback_layers,
|
|
|
|
rects[i].tex_coords,
|
|
|
|
rects[i].tex_coords_len);
|
|
|
|
|
|
|
|
/* NB: If _cogl_multitexture_quad_single_primitive fails then it
|
|
|
|
* means the user tried to use texture repeat with a texture that
|
|
|
|
* can't be repeated by the GPU (e.g. due to waste or use of
|
|
|
|
* GL_TEXTURE_RECTANGLE_ARB) */
|
|
|
|
if (success)
|
|
|
|
continue;
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
2009-09-16 06:56:17 -04:00
|
|
|
|
|
|
|
/* If multitexturing failed or we are drawing with a sliced texture
|
|
|
|
* then we only support a single layer so we pluck out the texture
|
|
|
|
* from the first material layer... */
|
|
|
|
first_layer = layers->data;
|
|
|
|
tex_handle = cogl_material_layer_get_texture (first_layer);
|
|
|
|
|
|
|
|
if (rects[i].tex_coords)
|
|
|
|
tex_coords = rects[i].tex_coords;
|
|
|
|
else
|
|
|
|
tex_coords = default_tex_coords;
|
|
|
|
|
2010-04-01 06:31:33 -04:00
|
|
|
clamp_s = (cogl_material_layer_get_wrap_mode_s (first_layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
clamp_t = (cogl_material_layer_get_wrap_mode_t (first_layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
COGL_NOTE (DRAW, "Drawing Tex Quad (Multi-Prim Mode)");
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
_cogl_texture_quad_multiple_primitives (tex_handle,
|
|
|
|
material,
|
2010-04-01 06:31:33 -04:00
|
|
|
clamp_s, clamp_t,
|
2010-02-11 10:33:01 -05:00
|
|
|
rects[i].position,
|
2009-09-16 06:56:17 -04:00
|
|
|
tex_coords[0],
|
|
|
|
tex_coords[1],
|
|
|
|
tex_coords[2],
|
|
|
|
tex_coords[3]);
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
#if 0
|
|
|
|
/* XXX: The current journal doesn't handle changes to the model view matrix
|
|
|
|
* so for now we force a flush at the end of every primitive. */
|
2009-03-23 08:29:15 -04:00
|
|
|
_cogl_journal_flush ();
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
#endif
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rectangles (const float *verts,
|
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-09 20:57:32 -05:00
|
|
|
unsigned int n_rects)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2009-06-16 16:29:21 -04:00
|
|
|
struct _CoglMutiTexturedRect *rects;
|
2009-03-23 08:29:15 -04:00
|
|
|
int i;
|
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
|
|
|
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
|
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
2009-06-16 16:29:21 -04:00
|
|
|
rects = g_alloca (n_rects * sizeof (struct _CoglMutiTexturedRect));
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
rects[i].position = &verts[i * 4];
|
2009-03-23 08:29:15 -04:00
|
|
|
rects[i].tex_coords = NULL;
|
|
|
|
rects[i].tex_coords_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_rectangles_with_multitexture_coords (rects, n_rects);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rectangles_with_texture_coords (const float *verts,
|
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-09 20:57:32 -05:00
|
|
|
unsigned int n_rects)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2009-06-16 16:29:21 -04:00
|
|
|
struct _CoglMutiTexturedRect *rects;
|
2009-03-23 08:29:15 -04:00
|
|
|
int i;
|
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
|
|
|
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
|
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
2009-06-16 16:29:21 -04:00
|
|
|
rects = g_alloca (n_rects * sizeof (struct _CoglMutiTexturedRect));
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
rects[i].position = &verts[i * 8];
|
2009-03-23 08:29:15 -04:00
|
|
|
rects[i].tex_coords = &verts[i * 8 + 4];
|
|
|
|
rects[i].tex_coords_len = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_rectangles_with_multitexture_coords (rects, n_rects);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rectangle_with_texture_coords (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
|
|
|
float tx_1,
|
|
|
|
float ty_1,
|
|
|
|
float tx_2,
|
|
|
|
float ty_2)
|
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
const float position[4] = {x_1, y_1, x_2, y_2};
|
|
|
|
const float tex_coords[4] = {tx_1, ty_1, tx_2, ty_2};
|
|
|
|
struct _CoglMutiTexturedRect rect;
|
|
|
|
|
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
|
|
|
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
|
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rect.position = position;
|
|
|
|
rect.tex_coords = tex_coords;
|
|
|
|
rect.tex_coords_len = 4;
|
|
|
|
|
|
|
|
_cogl_rectangles_with_multitexture_coords (&rect, 1);
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rectangle_with_multitexture_coords (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
|
|
|
const float *user_tex_coords,
|
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-09 20:57:32 -05:00
|
|
|
int user_tex_coords_len)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
const float position[4] = {x_1, y_1, x_2, y_2};
|
2009-03-23 08:29:15 -04:00
|
|
|
struct _CoglMutiTexturedRect rect;
|
|
|
|
|
2010-02-11 10:33:01 -05:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
|
|
|
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
|
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rect.position = position;
|
2009-03-23 08:29:15 -04:00
|
|
|
rect.tex_coords = user_tex_coords;
|
|
|
|
rect.tex_coords_len = user_tex_coords_len;
|
|
|
|
|
|
|
|
_cogl_rectangles_with_multitexture_coords (&rect, 1);
|
|
|
|
}
|
|
|
|
|
2008-05-05 08:01:19 -04:00
|
|
|
void
|
2009-01-29 08:31:11 -05:00
|
|
|
cogl_rectangle (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2008-05-05 08:01:19 -04:00
|
|
|
{
|
2010-02-11 10:33:01 -05:00
|
|
|
const float position[4] = {x_1, y_1, x_2, y_2};
|
|
|
|
struct _CoglMutiTexturedRect rect;
|
|
|
|
|
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
|
|
|
* _CoglMutiTexturedRect rectangles and pass these on to our work horse;
|
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rect.position = position;
|
|
|
|
rect.tex_coords = NULL;
|
|
|
|
rect.tex_coords_len = 0;
|
|
|
|
|
|
|
|
_cogl_rectangles_with_multitexture_coords (&rect, 1);
|
2008-05-05 08:01:19 -04:00
|
|
|
}
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
void
|
|
|
|
draw_polygon_sub_texture_cb (CoglHandle tex_handle,
|
2009-12-02 12:17:24 -05:00
|
|
|
GLuint gl_handle,
|
|
|
|
GLenum gl_target,
|
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
|
|
|
void *user_data)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2009-09-16 06:56:17 -04:00
|
|
|
TextureSlicedPolygonState *state = user_data;
|
|
|
|
GLfloat *v;
|
|
|
|
int i;
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
CoglMaterialFlushOptions options;
|
2009-09-16 06:56:17 -04:00
|
|
|
float slice_origin_x;
|
|
|
|
float slice_origin_y;
|
|
|
|
float virtual_origin_x;
|
|
|
|
float virtual_origin_y;
|
|
|
|
float v_to_s_scale_x;
|
|
|
|
float v_to_s_scale_y;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
slice_origin_x = subtexture_coords[0];
|
|
|
|
slice_origin_y = subtexture_coords[1];
|
|
|
|
virtual_origin_x = virtual_coords[0];
|
|
|
|
virtual_origin_y = virtual_coords[1];
|
|
|
|
v_to_s_scale_x = ((virtual_coords[2] - virtual_coords[0]) /
|
|
|
|
(subtexture_coords[2] - subtexture_coords[0]));
|
|
|
|
v_to_s_scale_y = ((virtual_coords[3] - virtual_coords[1]) /
|
|
|
|
(subtexture_coords[3] - subtexture_coords[1]));
|
|
|
|
|
|
|
|
/* Convert the vertices into an array of GLfloats ready to pass to
|
|
|
|
* OpenGL */
|
|
|
|
v = (GLfloat *)ctx->logged_vertices->data;
|
|
|
|
for (i = 0; i < state->n_vertices; i++)
|
|
|
|
{
|
|
|
|
/* NB: layout = [X,Y,Z,TX,TY,R,G,B,A,...] */
|
|
|
|
GLfloat *t = v + 3;
|
|
|
|
|
|
|
|
t[0] = ((state->vertices[i].tx - virtual_origin_x) * v_to_s_scale_x
|
|
|
|
+ slice_origin_x);
|
|
|
|
t[1] = ((state->vertices[i].ty - virtual_origin_y) * v_to_s_scale_y
|
|
|
|
+ slice_origin_y);
|
|
|
|
|
|
|
|
v += state->stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.flags =
|
|
|
|
COGL_MATERIAL_FLUSH_DISABLE_MASK |
|
2010-04-01 06:31:33 -04:00
|
|
|
COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE |
|
|
|
|
COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
|
2009-09-16 06:56:17 -04:00
|
|
|
/* disable all except the first layer */
|
|
|
|
options.disable_layers = (guint32)~1;
|
|
|
|
options.layer0_override_texture = gl_handle;
|
|
|
|
|
2010-04-01 06:31:33 -04:00
|
|
|
/* Override the wrapping mode on all of the slices to use a
|
|
|
|
transparent border so that we can draw the full polygon for
|
|
|
|
each slice. Coordinates outside the texture will be transparent
|
|
|
|
so only the part of the polygon that intersects the slice will
|
|
|
|
be visible. This is a fairly hacky fallback and it relies on
|
|
|
|
the blending function working correctly */
|
|
|
|
|
|
|
|
memset (&options.wrap_mode_overrides, 0,
|
|
|
|
sizeof (options.wrap_mode_overrides));
|
|
|
|
options.wrap_mode_overrides.values[0].s =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_CLAMP_TO_BORDER;
|
|
|
|
options.wrap_mode_overrides.values[0].t =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_CLAMP_TO_BORDER;
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
_cogl_material_flush_gl_state (ctx->source_material, &options);
|
|
|
|
|
|
|
|
GE (glDrawArrays (GL_TRIANGLE_FAN, 0, state->n_vertices));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handles 2d-sliced textures with > 1 slice */
|
|
|
|
static void
|
2010-01-04 06:43:00 -05:00
|
|
|
_cogl_texture_polygon_multiple_primitives (const CoglTextureVertex *vertices,
|
2009-09-16 06:56:17 -04:00
|
|
|
unsigned int n_vertices,
|
|
|
|
unsigned int stride,
|
|
|
|
gboolean use_color)
|
|
|
|
{
|
|
|
|
const GList *layers;
|
|
|
|
CoglHandle layer0;
|
|
|
|
CoglHandle tex_handle;
|
|
|
|
GLfloat *v;
|
|
|
|
int i;
|
|
|
|
TextureSlicedPolygonState state;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* We can assume in this case that we have at least one layer in the
|
|
|
|
* material that corresponds to a sliced cogl texture */
|
|
|
|
layers = cogl_material_get_layers (ctx->source_material);
|
|
|
|
layer0 = (CoglHandle)layers->data;
|
|
|
|
tex_handle = cogl_material_layer_get_texture (layer0);
|
|
|
|
|
|
|
|
v = (GLfloat *)ctx->logged_vertices->data;
|
|
|
|
for (i = 0; i < n_vertices; i++)
|
|
|
|
{
|
2009-06-16 17:48:21 -04:00
|
|
|
guint8 *c;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
v[0] = vertices[i].x;
|
|
|
|
v[1] = vertices[i].y;
|
|
|
|
v[2] = vertices[i].z;
|
|
|
|
|
2009-06-16 17:48:21 -04:00
|
|
|
if (use_color)
|
|
|
|
{
|
|
|
|
/* NB: [X,Y,Z,TX,TY,R,G,B,A,...] */
|
|
|
|
c = (guint8 *) (v + 5);
|
|
|
|
c[0] = cogl_color_get_red_byte (&vertices[i].color);
|
|
|
|
c[1] = cogl_color_get_green_byte (&vertices[i].color);
|
|
|
|
c[2] = cogl_color_get_blue_byte (&vertices[i].color);
|
|
|
|
c[3] = cogl_color_get_alpha_byte (&vertices[i].color);
|
|
|
|
}
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
v += stride;
|
|
|
|
}
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
state.stride = stride;
|
|
|
|
state.vertices = vertices;
|
|
|
|
state.n_vertices = n_vertices;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
_cogl_texture_foreach_sub_texture_in_region (tex_handle,
|
|
|
|
0, 0, 1, 1,
|
|
|
|
draw_polygon_sub_texture_cb,
|
|
|
|
&state);
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-01-04 06:43:00 -05:00
|
|
|
_cogl_multitexture_polygon_single_primitive (const CoglTextureVertex *vertices,
|
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-09 20:57:32 -05:00
|
|
|
unsigned int n_vertices,
|
|
|
|
unsigned int n_layers,
|
|
|
|
unsigned int stride,
|
2009-09-16 06:56:17 -04:00
|
|
|
gboolean use_color,
|
2010-04-01 13:35:32 -04:00
|
|
|
guint32 fallback_layers,
|
|
|
|
CoglMaterialWrapModeOverrides *
|
|
|
|
wrap_mode_overrides)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
const GList *layers;
|
|
|
|
int i;
|
|
|
|
GList *tmp;
|
|
|
|
GLfloat *v;
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
CoglMaterialFlushOptions options;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
material = ctx->source_material;
|
|
|
|
layers = cogl_material_get_layers (material);
|
|
|
|
|
|
|
|
/* Convert the vertices into an array of GLfloats ready to pass to
|
|
|
|
OpenGL */
|
|
|
|
for (v = (GLfloat *)ctx->logged_vertices->data, i = 0;
|
|
|
|
i < n_vertices;
|
|
|
|
v += stride, i++)
|
|
|
|
{
|
2009-06-16 17:48:21 -04:00
|
|
|
guint8 *c;
|
|
|
|
int j;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
v[0] = vertices[i].x;
|
|
|
|
v[1] = vertices[i].y;
|
|
|
|
v[2] = vertices[i].z;
|
|
|
|
|
|
|
|
for (tmp = (GList *)layers, j = 0; tmp != NULL; tmp = tmp->next, j++)
|
|
|
|
{
|
|
|
|
CoglHandle layer = (CoglHandle)tmp->data;
|
|
|
|
CoglHandle tex_handle;
|
|
|
|
GLfloat *t;
|
|
|
|
float tx, ty;
|
|
|
|
|
|
|
|
tex_handle = cogl_material_layer_get_texture (layer);
|
2009-06-19 07:15:12 -04:00
|
|
|
|
|
|
|
/* COGL_INVALID_HANDLE textures will be handled in
|
|
|
|
* _cogl_material_flush_layers_gl_state but there is no need to worry
|
|
|
|
* about scaling texture coordinates in this case */
|
|
|
|
if (tex_handle == COGL_INVALID_HANDLE)
|
|
|
|
continue;
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
tx = vertices[i].tx;
|
|
|
|
ty = vertices[i].ty;
|
|
|
|
_cogl_texture_transform_coords_to_gl (tex_handle, &tx, &ty);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
t = v + 3 + 2 * j;
|
|
|
|
t[0] = tx;
|
|
|
|
t[1] = ty;
|
|
|
|
}
|
|
|
|
|
2009-06-16 17:48:21 -04:00
|
|
|
if (use_color)
|
|
|
|
{
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
c = (guint8 *) (v + 3 + 2 * n_layers);
|
|
|
|
c[0] = cogl_color_get_red_byte (&vertices[i].color);
|
|
|
|
c[1] = cogl_color_get_green_byte (&vertices[i].color);
|
|
|
|
c[2] = cogl_color_get_blue_byte (&vertices[i].color);
|
|
|
|
c[3] = cogl_color_get_alpha_byte (&vertices[i].color);
|
|
|
|
}
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
options.flags = COGL_MATERIAL_FLUSH_FALLBACK_MASK;
|
|
|
|
if (use_color)
|
|
|
|
options.flags |= COGL_MATERIAL_FLUSH_SKIP_GL_COLOR;
|
|
|
|
options.fallback_layers = fallback_layers;
|
2010-04-01 13:35:32 -04:00
|
|
|
if (wrap_mode_overrides)
|
|
|
|
{
|
|
|
|
options.flags |= COGL_MATERIAL_FLUSH_WRAP_MODE_OVERRIDES;
|
|
|
|
options.wrap_mode_overrides = *wrap_mode_overrides;
|
|
|
|
}
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
_cogl_material_flush_gl_state (ctx->source_material, &options);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
GE (glDrawArrays (GL_TRIANGLE_FAN, 0, n_vertices));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-04 06:43:00 -05:00
|
|
|
cogl_polygon (const CoglTextureVertex *vertices,
|
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-09 20:57:32 -05:00
|
|
|
unsigned int n_vertices,
|
2010-01-04 06:43:00 -05:00
|
|
|
gboolean use_color)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
CoglHandle material;
|
2010-01-04 06:43:00 -05:00
|
|
|
const GList *layers, *tmp;
|
2009-03-23 08:29:15 -04:00
|
|
|
int n_layers;
|
|
|
|
gboolean use_sliced_polygon_fallback = FALSE;
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
guint32 fallback_layers = 0;
|
2009-03-23 08:29:15 -04:00
|
|
|
int i;
|
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-09 20:57:32 -05:00
|
|
|
unsigned long enable_flags;
|
|
|
|
unsigned int stride;
|
2009-03-23 08:29:15 -04:00
|
|
|
gsize stride_bytes;
|
|
|
|
GLfloat *v;
|
2010-04-01 13:35:32 -04:00
|
|
|
CoglMaterialWrapModeOverrides wrap_mode_overrides;
|
|
|
|
CoglMaterialWrapModeOverrides *wrap_mode_overrides_p = NULL;
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
_cogl_journal_flush ();
|
2009-09-25 09:34:34 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
/* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
2009-09-25 09:34:34 -04:00
|
|
|
* as the material state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. */
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_flush_state (_cogl_get_framebuffer (), 0);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
material = ctx->source_material;
|
|
|
|
layers = cogl_material_get_layers (ctx->source_material);
|
|
|
|
n_layers = g_list_length ((GList *)layers);
|
|
|
|
|
2010-04-01 13:35:32 -04:00
|
|
|
memset (&wrap_mode_overrides, 0, sizeof (wrap_mode_overrides));
|
|
|
|
|
2010-01-04 06:43:00 -05:00
|
|
|
for (tmp = layers, i = 0; tmp != NULL; tmp = tmp->next, i++)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
2010-01-04 06:43:00 -05:00
|
|
|
CoglHandle layer = tmp->data;
|
|
|
|
CoglHandle tex_handle = cogl_material_layer_get_texture (layer);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
2009-06-19 07:15:12 -04:00
|
|
|
/* COGL_INVALID_HANDLE textures will be handled in
|
|
|
|
* _cogl_material_flush_layers_gl_state */
|
|
|
|
if (tex_handle == COGL_INVALID_HANDLE)
|
|
|
|
continue;
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
/* Give the texture a chance to know that we're rendering
|
|
|
|
non-quad shaped primitives. If the texture is in an atlas it
|
|
|
|
will be migrated */
|
|
|
|
_cogl_texture_ensure_non_quad_rendering (tex_handle);
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
if (i == 0 && cogl_texture_is_sliced (tex_handle))
|
|
|
|
{
|
|
|
|
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GLES2)
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("cogl_polygon does not work for sliced textures "
|
|
|
|
"on GL ES");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (n_layers > 1)
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
{
|
|
|
|
g_warning ("Disabling layers 1..n since multi-texturing with "
|
|
|
|
"cogl_polygon isn't supported when using sliced "
|
|
|
|
"textures\n");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 06:43:00 -05:00
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
use_sliced_polygon_fallback = TRUE;
|
|
|
|
n_layers = 1;
|
|
|
|
|
2009-06-04 11:04:57 -04:00
|
|
|
if (cogl_material_layer_get_min_filter (layer) != GL_NEAREST
|
|
|
|
|| cogl_material_layer_get_mag_filter (layer) != GL_NEAREST)
|
2009-03-23 08:29:15 -04:00
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
{
|
|
|
|
g_warning ("cogl_texture_polygon does not work for sliced textures "
|
|
|
|
"when the minification and magnification filters are not "
|
2010-01-12 09:43:36 -05:00
|
|
|
"COGL_MATERIAL_FILTER_NEAREST");
|
2009-03-23 08:29:15 -04:00
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cogl_texture_is_sliced (tex_handle))
|
|
|
|
{
|
|
|
|
static gboolean warning_seen = FALSE;
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Disabling layer %d of the current source material, "
|
|
|
|
"because texturing with the vertex buffer API is not "
|
|
|
|
"currently supported using sliced textures, or "
|
|
|
|
"textures with waste\n", i);
|
|
|
|
warning_seen = TRUE;
|
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
fallback_layers |= (1 << i);
|
2009-03-23 08:29:15 -04:00
|
|
|
continue;
|
|
|
|
}
|
2010-04-01 13:35:32 -04:00
|
|
|
|
|
|
|
/* By default COGL_MATERIAL_WRAP_MODE_AUTOMATIC becomes
|
|
|
|
GL_CLAMP_TO_EDGE but we want the polygon API to use GL_REPEAT
|
|
|
|
to maintain compatibility with previous releases */
|
|
|
|
if (cogl_material_layer_get_wrap_mode_s (layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
wrap_mode_overrides.values[i].s =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
|
|
|
|
wrap_mode_overrides_p = &wrap_mode_overrides;
|
|
|
|
}
|
|
|
|
if (cogl_material_layer_get_wrap_mode_t (layer) ==
|
|
|
|
COGL_MATERIAL_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
wrap_mode_overrides.values[i].t =
|
|
|
|
COGL_MATERIAL_WRAP_MODE_OVERRIDE_REPEAT;
|
|
|
|
wrap_mode_overrides_p = &wrap_mode_overrides;
|
|
|
|
}
|
2009-03-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Our data is arranged like:
|
|
|
|
* [X, Y, Z, TX0, TY0, TX1, TY1..., R, G, B, A,...] */
|
2009-06-16 17:48:21 -04:00
|
|
|
stride = 3 + (2 * n_layers) + (use_color ? 1 : 0);
|
2009-03-23 08:29:15 -04:00
|
|
|
stride_bytes = stride * sizeof (GLfloat);
|
|
|
|
|
|
|
|
/* Make sure there is enough space in the global vertex
|
|
|
|
array. This is used so we can render the polygon with a single
|
|
|
|
call to OpenGL but still support any number of vertices */
|
|
|
|
g_array_set_size (ctx->logged_vertices, n_vertices * stride);
|
|
|
|
v = (GLfloat *)ctx->logged_vertices->data;
|
|
|
|
|
|
|
|
/* Prepare GL state */
|
|
|
|
enable_flags = COGL_ENABLE_VERTEX_ARRAY;
|
2009-05-23 12:42:10 -04:00
|
|
|
enable_flags |= _cogl_material_get_cogl_enable_flags (ctx->source_material);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
if (ctx->enable_backface_culling)
|
|
|
|
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
|
|
|
|
|
|
|
|
if (use_color)
|
|
|
|
{
|
2009-10-27 09:18:51 -04:00
|
|
|
enable_flags |= COGL_ENABLE_COLOR_ARRAY | COGL_ENABLE_BLEND;
|
2009-06-16 17:48:21 -04:00
|
|
|
GE( glColorPointer (4, GL_UNSIGNED_BYTE,
|
2009-03-23 08:29:15 -04:00
|
|
|
stride_bytes,
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
v + 3 + 2 * n_layers) );
|
|
|
|
}
|
|
|
|
|
2010-03-19 05:16:08 -04:00
|
|
|
_cogl_enable (enable_flags);
|
2009-10-22 14:01:52 -04:00
|
|
|
_cogl_flush_face_winding ();
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
GE (glVertexPointer (3, GL_FLOAT, stride_bytes, v));
|
|
|
|
|
|
|
|
for (i = 0; i < n_layers; i++)
|
|
|
|
{
|
|
|
|
GE (glClientActiveTexture (GL_TEXTURE0 + i));
|
|
|
|
GE (glEnableClientState (GL_TEXTURE_COORD_ARRAY));
|
|
|
|
GE (glTexCoordPointer (2, GL_FLOAT,
|
|
|
|
stride_bytes,
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
v + 3 + 2 * i));
|
|
|
|
}
|
2010-01-04 06:43:00 -05:00
|
|
|
|
2010-05-24 07:40:11 -04:00
|
|
|
_cogl_bitmask_clear_all (&ctx->temp_bitmask);
|
|
|
|
_cogl_bitmask_set_range (&ctx->temp_bitmask, n_layers, TRUE);
|
|
|
|
_cogl_disable_other_texcoord_arrays (&ctx->temp_bitmask);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
if (use_sliced_polygon_fallback)
|
2009-09-16 06:56:17 -04:00
|
|
|
_cogl_texture_polygon_multiple_primitives (vertices,
|
|
|
|
n_vertices,
|
|
|
|
stride,
|
|
|
|
use_color);
|
2009-03-23 08:29:15 -04:00
|
|
|
else
|
2009-09-16 06:56:17 -04:00
|
|
|
_cogl_multitexture_polygon_single_primitive (vertices,
|
|
|
|
n_vertices,
|
|
|
|
n_layers,
|
|
|
|
stride,
|
|
|
|
use_color,
|
2010-04-01 13:35:32 -04:00
|
|
|
fallback_layers,
|
|
|
|
wrap_mode_overrides_p);
|
2009-03-23 08:29:15 -04:00
|
|
|
|
|
|
|
/* Reset the size of the logged vertex array because rendering
|
|
|
|
rectangles expects it to start at 0 */
|
|
|
|
g_array_set_size (ctx->logged_vertices, 0);
|
|
|
|
}
|
|
|
|
|