2008-04-30 15:05:17 +00:00
|
|
|
/*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Cogl
|
2008-04-30 15:05:17 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2008-04-30 15:05:17 +00: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-10 01:57:32 +00:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2008-04-30 15:05:17 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2008-04-30 15:05:17 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2008-04-30 15:05:17 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2008-04-30 15:05:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-07-25 20:36:41 +00:00
|
|
|
#include "cogl-debug.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2009-09-16 13:01:57 +00:00
|
|
|
#include "cogl-journal-private.h"
|
2009-03-23 12:29:15 +00:00
|
|
|
#include "cogl-texture-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2009-06-01 16:10:22 +00:00
|
|
|
#include "cogl-vertex-buffer-private.h"
|
2009-11-26 19:06:35 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2011-01-20 19:31:53 +00:00
|
|
|
#include "cogl-attribute-private.h"
|
2011-09-14 11:17:09 +00:00
|
|
|
#include "cogl-private.h"
|
2011-10-08 13:13:03 +00:00
|
|
|
#include "cogl-meta-texture.h"
|
2012-01-08 02:59:04 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2012-02-17 21:46:39 +00:00
|
|
|
#include "cogl1-context.h"
|
2012-03-06 18:21:28 +00:00
|
|
|
#include "cogl-primitives-private.h"
|
2008-04-30 15:05:17 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2009-01-20 16:20:54 +00:00
|
|
|
#include <math.h>
|
2008-04-30 15:05:17 +00:00
|
|
|
|
|
|
|
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16
|
|
|
|
|
2009-09-16 10:56:17 +00:00
|
|
|
typedef struct _TextureSlicedQuadState
|
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglFramebuffer *framebuffer;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *main_texture;
|
2009-09-16 10:56:17 +00:00
|
|
|
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;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool flipped_x;
|
|
|
|
CoglBool flipped_y;
|
2009-09-16 10:56:17 +00:00
|
|
|
} TextureSlicedQuadState;
|
|
|
|
|
|
|
|
typedef struct _TextureSlicedPolygonState
|
|
|
|
{
|
2010-01-04 11:43:00 +00:00
|
|
|
const CoglTextureVertex *vertices;
|
2009-09-16 10:56:17 +00:00
|
|
|
int n_vertices;
|
|
|
|
int stride;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes;
|
2009-09-16 10:56:17 +00:00
|
|
|
} TextureSlicedPolygonState;
|
|
|
|
|
2009-03-23 12:29:15 +00:00
|
|
|
static void
|
2011-08-24 20:30:34 +00:00
|
|
|
log_quad_sub_textures_cb (CoglTexture *texture,
|
2009-12-02 17:17:24 +00:00
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
2009-09-16 10:56:17 +00:00
|
|
|
void *user_data)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2009-09-16 10:56:17 +00:00
|
|
|
TextureSlicedQuadState *state = user_data;
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglFramebuffer *framebuffer = state->framebuffer;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture_override;
|
2009-09-16 10:56:17 +00:00
|
|
|
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]);
|
|
|
|
|
2010-11-11 16:18:25 +00:00
|
|
|
/* We only need to override the texture if it's different from the
|
|
|
|
main texture */
|
2011-08-24 20:30:34 +00:00
|
|
|
if (texture == state->main_texture)
|
|
|
|
texture_override = NULL;
|
2010-11-11 16:18:25 +00:00
|
|
|
else
|
2011-08-24 20:30:34 +00:00
|
|
|
texture_override = texture;
|
2010-11-11 16:18:25 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_journal_log_quad (framebuffer->journal,
|
|
|
|
quad_coords,
|
2010-10-27 17:54:57 +00:00
|
|
|
state->pipeline,
|
2009-09-16 10:56:17 +00:00
|
|
|
1, /* one layer */
|
2010-11-11 16:18:25 +00:00
|
|
|
texture_override, /* replace the layer0 texture */
|
2009-09-16 10:56:17 +00:00
|
|
|
subtexture_coords,
|
|
|
|
4);
|
|
|
|
}
|
|
|
|
|
2010-11-01 18:55:48 +00:00
|
|
|
typedef struct _ValidateFirstLayerState
|
|
|
|
{
|
|
|
|
CoglPipeline *override_pipeline;
|
|
|
|
} ValidateFirstLayerState;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-11-01 18:55:48 +00:00
|
|
|
validate_first_layer_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
ValidateFirstLayerState *state = user_data;
|
|
|
|
CoglPipelineWrapMode clamp_to_edge =
|
|
|
|
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
|
2011-10-08 13:13:03 +00:00
|
|
|
CoglPipelineWrapMode wrap_s;
|
|
|
|
CoglPipelineWrapMode wrap_t;
|
2010-11-01 18:55:48 +00:00
|
|
|
|
|
|
|
/* We can't use hardware repeat so we need to set clamp to edge
|
|
|
|
* otherwise it might pull in edge pixels from the other side. By
|
|
|
|
* default WRAP_MODE_AUTOMATIC becomes CLAMP_TO_EDGE so we only need
|
2011-10-12 10:53:31 +00:00
|
|
|
* to override if the wrap mode isn't already automatic or
|
|
|
|
* clamp_to_edge.
|
2010-11-01 18:55:48 +00:00
|
|
|
*/
|
2011-10-12 10:53:31 +00:00
|
|
|
wrap_s = cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index);
|
|
|
|
if (wrap_s != COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE &&
|
|
|
|
wrap_s != COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2010-11-01 18:55:48 +00:00
|
|
|
{
|
|
|
|
if (!state->override_pipeline)
|
|
|
|
state->override_pipeline = cogl_pipeline_copy (pipeline);
|
2011-10-12 10:53:31 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (state->override_pipeline,
|
|
|
|
layer_index, clamp_to_edge);
|
2010-11-01 18:55:48 +00:00
|
|
|
}
|
2011-10-12 10:53:31 +00:00
|
|
|
|
|
|
|
wrap_t = cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index);
|
|
|
|
if (wrap_t != COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE &&
|
|
|
|
wrap_t != COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2010-11-01 18:55:48 +00:00
|
|
|
{
|
|
|
|
if (!state->override_pipeline)
|
|
|
|
state->override_pipeline = cogl_pipeline_copy (pipeline);
|
2011-10-12 10:53:31 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (state->override_pipeline,
|
|
|
|
layer_index, clamp_to_edge);
|
2010-11-01 18:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:56:17 +00:00
|
|
|
/* 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
|
2012-03-16 19:54:13 +00:00
|
|
|
_cogl_texture_quad_multiple_primitives (CoglFramebuffer *framebuffer,
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline,
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglTexture *texture,
|
2011-10-08 13:13:03 +00:00
|
|
|
int layer_index,
|
|
|
|
const float *position,
|
|
|
|
float tx_1,
|
|
|
|
float ty_1,
|
|
|
|
float tx_2,
|
|
|
|
float ty_2)
|
2009-09-16 10:56:17 +00:00
|
|
|
{
|
|
|
|
TextureSlicedQuadState state;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool tex_virtual_flipped_x;
|
|
|
|
CoglBool tex_virtual_flipped_y;
|
|
|
|
CoglBool quad_flipped_x;
|
|
|
|
CoglBool quad_flipped_y;
|
2010-11-01 18:55:48 +00:00
|
|
|
ValidateFirstLayerState validate_first_layer_state;
|
2011-10-08 13:13:03 +00:00
|
|
|
CoglPipelineWrapMode wrap_s, wrap_t;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2011-10-08 13:13:03 +00:00
|
|
|
wrap_s = cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index);
|
|
|
|
wrap_t = cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index);
|
|
|
|
|
2010-11-01 18:55:48 +00:00
|
|
|
validate_first_layer_state.override_pipeline = NULL;
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
|
|
|
validate_first_layer_cb,
|
|
|
|
&validate_first_layer_state);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
state.framebuffer = framebuffer;
|
2011-08-24 20:30:34 +00:00
|
|
|
state.main_texture = texture;
|
2010-11-11 16:18:25 +00:00
|
|
|
|
2010-11-01 18:55:48 +00:00
|
|
|
if (validate_first_layer_state.override_pipeline)
|
|
|
|
state.pipeline = validate_first_layer_state.override_pipeline;
|
|
|
|
else
|
|
|
|
state.pipeline = pipeline;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2009-09-16 10:56:17 +00: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 12:29:15 +00:00
|
|
|
|
2010-02-11 15:33:01 +00:00
|
|
|
#define X0 0
|
|
|
|
#define Y0 1
|
|
|
|
#define X1 2
|
|
|
|
#define Y1 3
|
|
|
|
|
2009-09-16 10:56:17 +00: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 15:33:01 +00: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 10:56:17 +00: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 15:33:01 +00: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 10:56:17 +00: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));
|
|
|
|
|
2011-10-27 13:48:58 +00:00
|
|
|
/* For backwards compatablity the default wrap mode for cogl_rectangle() is
|
|
|
|
* _REPEAT... */
|
|
|
|
if (wrap_s == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2011-10-08 13:13:03 +00:00
|
|
|
wrap_s = COGL_PIPELINE_WRAP_MODE_REPEAT;
|
2011-10-27 13:48:58 +00:00
|
|
|
if (wrap_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2011-10-08 13:13:03 +00:00
|
|
|
wrap_t = COGL_PIPELINE_WRAP_MODE_REPEAT;
|
|
|
|
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture),
|
|
|
|
tx_1, ty_1, tx_2, ty_2,
|
|
|
|
wrap_s,
|
|
|
|
wrap_t,
|
|
|
|
log_quad_sub_textures_cb,
|
|
|
|
&state);
|
2010-11-01 18:55:48 +00:00
|
|
|
|
|
|
|
if (validate_first_layer_state.override_pipeline)
|
|
|
|
cogl_object_unref (validate_first_layer_state.override_pipeline);
|
2009-03-23 12:29:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
typedef struct _ValidateTexCoordsState
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n_layers;
|
|
|
|
const float *user_tex_coords;
|
|
|
|
int user_tex_coords_len;
|
|
|
|
float *final_tex_coords;
|
|
|
|
CoglPipeline *override_pipeline;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool needs_multiple_primitives;
|
2010-11-01 18:33:17 +00:00
|
|
|
} ValidateTexCoordsState;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate the texture coordinates for this rectangle.
|
|
|
|
*/
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-11-01 18:33:17 +00:00
|
|
|
validate_tex_coords_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
ValidateTexCoordsState *state = user_data;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture;
|
2010-11-01 18:33:17 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
state->i++;
|
|
|
|
|
|
|
|
/* FIXME: we should be able to avoid this copying when no
|
|
|
|
* transform is required by the texture backend and the user
|
|
|
|
* has supplied enough coordinates for all the layers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If the user didn't supply texture coordinates for this layer
|
|
|
|
then use the default coords */
|
|
|
|
if (state->i >= state->user_tex_coords_len / 4)
|
|
|
|
in_tex_coords = default_tex_coords;
|
|
|
|
else
|
|
|
|
in_tex_coords = &state->user_tex_coords[state->i * 4];
|
|
|
|
|
|
|
|
out_tex_coords = &state->final_tex_coords[state->i * 4];
|
|
|
|
|
|
|
|
memcpy (out_tex_coords, in_tex_coords, sizeof (float) * 4);
|
|
|
|
|
2012-02-08 15:58:07 +00:00
|
|
|
texture = cogl_pipeline_get_layer_texture (pipeline, layer_index);
|
|
|
|
|
|
|
|
/* NB: NULL textures are handled by _cogl_pipeline_flush_gl_state */
|
|
|
|
if (!texture)
|
|
|
|
return TRUE;
|
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
/* Convert the texture coordinates to GL.
|
|
|
|
*/
|
|
|
|
transform_result =
|
|
|
|
_cogl_texture_transform_quad_coords_to_gl (texture,
|
|
|
|
out_tex_coords);
|
|
|
|
/* If the texture has waste or we are using GL_TEXTURE_RECT we
|
|
|
|
* can't handle texture repeating so we can't use the layer if
|
|
|
|
* repeating is required.
|
|
|
|
*
|
|
|
|
* NB: We already know that no texture matrix is being used if the
|
|
|
|
* texture doesn't support hardware repeat.
|
|
|
|
*/
|
|
|
|
if (transform_result == COGL_TRANSFORM_SOFTWARE_REPEAT)
|
|
|
|
{
|
|
|
|
if (state->i == 0)
|
|
|
|
{
|
|
|
|
if (state->n_layers > 1)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2010-11-01 18:33:17 +00:00
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layers 1..n of your material since "
|
|
|
|
"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 "
|
|
|
|
"layer 0 is the most important one keep");
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->override_pipeline)
|
|
|
|
cogl_object_unref (state->override_pipeline);
|
|
|
|
state->needs_multiple_primitives = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2010-11-01 18:33:17 +00:00
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layer %d of your material "
|
|
|
|
"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.", state->i);
|
|
|
|
warning_seen = TRUE;
|
|
|
|
|
2011-08-24 20:30:34 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, layer_index, NULL);
|
2010-11-01 18:33:17 +00: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 */
|
|
|
|
if (transform_result == COGL_TRANSFORM_HARDWARE_REPEAT)
|
|
|
|
{
|
|
|
|
if (cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index) ==
|
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
if (!state->override_pipeline)
|
|
|
|
state->override_pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (state->override_pipeline,
|
|
|
|
layer_index,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
|
|
|
}
|
|
|
|
if (cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index) ==
|
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
|
|
|
{
|
|
|
|
if (!state->override_pipeline)
|
|
|
|
state->override_pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (state->override_pipeline,
|
|
|
|
layer_index,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:56:17 +00: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.
|
|
|
|
*/
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2012-03-16 19:54:13 +00:00
|
|
|
_cogl_multitexture_quad_single_primitive (CoglFramebuffer *framebuffer,
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline,
|
2012-03-16 19:54:13 +00:00
|
|
|
const float *position,
|
2010-10-27 17:54:57 +00:00
|
|
|
const float *user_tex_coords,
|
2012-03-16 19:54:13 +00:00
|
|
|
int user_tex_coords_len)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2010-11-01 18:33:17 +00:00
|
|
|
int n_layers = cogl_pipeline_get_n_layers (pipeline);
|
|
|
|
ValidateTexCoordsState state;
|
|
|
|
float *final_tex_coords = alloca (sizeof (float) * 4 * n_layers);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
state.i = -1;
|
|
|
|
state.n_layers = n_layers;
|
|
|
|
state.user_tex_coords = user_tex_coords;
|
|
|
|
state.user_tex_coords_len = user_tex_coords_len;
|
|
|
|
state.final_tex_coords = final_tex_coords;
|
|
|
|
state.override_pipeline = NULL;
|
|
|
|
state.needs_multiple_primitives = FALSE;
|
2010-04-01 10:31:33 +00:00
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
|
|
|
validate_tex_coords_cb,
|
|
|
|
&state);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
if (state.needs_multiple_primitives)
|
|
|
|
return FALSE;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-11-01 18:33:17 +00:00
|
|
|
if (state.override_pipeline)
|
|
|
|
pipeline = state.override_pipeline;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_journal_log_quad (framebuffer->journal,
|
|
|
|
position,
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline,
|
2009-03-23 12:29:15 +00:00
|
|
|
n_layers,
|
2011-08-24 20:30:34 +00:00
|
|
|
NULL, /* no texture override */
|
2009-03-23 12:29:15 +00:00
|
|
|
final_tex_coords,
|
|
|
|
n_layers * 4);
|
|
|
|
|
2010-11-01 18:55:48 +00:00
|
|
|
if (state.override_pipeline)
|
|
|
|
cogl_object_unref (state.override_pipeline);
|
|
|
|
|
2009-03-23 12:29:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-11 16:28:45 +00:00
|
|
|
typedef struct _ValidateLayerState
|
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglContext *ctx;
|
2010-11-11 16:28:45 +00:00
|
|
|
int i;
|
|
|
|
int first_layer;
|
|
|
|
CoglPipeline *override_source;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool all_use_sliced_quad_fallback;
|
2010-11-11 16:28:45 +00:00
|
|
|
} ValidateLayerState;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-11-11 16:28:45 +00:00
|
|
|
_cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
ValidateLayerState *state = user_data;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture;
|
2010-11-11 16:28:45 +00:00
|
|
|
|
|
|
|
state->i++;
|
|
|
|
|
|
|
|
/* We need to ensure the mipmaps are ready before deciding
|
|
|
|
* anything else about the texture because the texture storage
|
|
|
|
* could completely change if it needs to be migrated out of the
|
|
|
|
* atlas and will affect how we validate the layer.
|
|
|
|
*
|
|
|
|
* FIXME: this needs to be generalized. There could be any
|
|
|
|
* number of things that might require a shuffling of the
|
|
|
|
* underlying texture storage. We could add two mechanisms to
|
|
|
|
* generalize this a bit...
|
|
|
|
*
|
|
|
|
* 1) add a _cogl_pipeline_layer_update_storage() function that
|
|
|
|
* would for instance consider if mipmapping is necessary and
|
|
|
|
* potentially migrate the texture from an atlas.
|
|
|
|
*
|
|
|
|
* 2) allow setting of transient primitive-flags on a pipeline
|
|
|
|
* that may affect the outcome of _update_storage(). One flag
|
|
|
|
* could indicate that we expect to sample beyond the bounds of
|
|
|
|
* the texture border.
|
|
|
|
*
|
|
|
|
* flags = COGL_PIPELINE_PRIMITIVE_FLAG_VALID_BORDERS;
|
|
|
|
* _cogl_pipeline_layer_assert_primitive_flags (layer, flags)
|
|
|
|
* _cogl_pipeline_layer_update_storage (layer)
|
|
|
|
* enqueue primitive in journal
|
|
|
|
*
|
|
|
|
* when the primitive is dequeued and drawn we should:
|
|
|
|
* _cogl_pipeline_flush_gl_state (pipeline)
|
|
|
|
* draw primitive
|
|
|
|
* _cogl_pipeline_unassert_primitive_flags (layer, flags);
|
|
|
|
*
|
|
|
|
* _cogl_pipeline_layer_update_storage should take into
|
|
|
|
* consideration all the asserted primitive requirements. (E.g.
|
|
|
|
* there could be multiple primitives in the journal - or in a
|
|
|
|
* renderlist in the future - that need mipmaps or that need
|
|
|
|
* valid contents beyond their borders (for cogl_polygon)
|
|
|
|
* meaning they can't work with textures in an atas, so
|
|
|
|
* _cogl_pipeline_layer_update_storage would pass on these
|
|
|
|
* requirements to the texture atlas backend which would make
|
|
|
|
* sure the referenced texture is migrated out of the atlas and
|
|
|
|
* mipmaps are generated.)
|
|
|
|
*/
|
|
|
|
_cogl_pipeline_pre_paint_for_layer (pipeline, layer_index);
|
|
|
|
|
2012-02-05 20:04:14 +00:00
|
|
|
texture = cogl_pipeline_get_layer_texture (pipeline, layer_index);
|
2010-11-11 16:28:45 +00:00
|
|
|
|
2011-08-24 20:30:34 +00:00
|
|
|
/* NULL textures are handled by
|
2010-11-11 16:28:45 +00:00
|
|
|
* _cogl_pipeline_flush_gl_state */
|
2011-08-24 20:30:34 +00:00
|
|
|
if (texture == NULL)
|
2010-11-11 16:28:45 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (state->i == 0)
|
|
|
|
state->first_layer = layer_index;
|
|
|
|
|
|
|
|
/* 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 (texture))
|
|
|
|
{
|
|
|
|
if (state->i == 0)
|
|
|
|
{
|
2011-09-19 14:22:04 +00:00
|
|
|
if (cogl_pipeline_get_n_layers (pipeline) > 1)
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2010-11-11 16:28:45 +00:00
|
|
|
|
2011-09-19 14:22:04 +00:00
|
|
|
if (!state->override_source)
|
|
|
|
state->override_source = cogl_pipeline_copy (pipeline);
|
|
|
|
_cogl_pipeline_prune_to_n_layers (state->override_source, 1);
|
2010-11-11 16:28:45 +00:00
|
|
|
|
2011-09-19 14:22:04 +00:00
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layers 1..n of your pipeline 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->all_use_sliced_quad_fallback = TRUE;
|
2010-11-11 16:28:45 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2012-02-18 14:58:39 +00:00
|
|
|
CoglTexture2D *tex_2d;
|
2010-11-11 16:28:45 +00:00
|
|
|
|
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("Skipping layer %d of your pipeline consisting of "
|
|
|
|
"a sliced texture (unsuported for multi texturing)",
|
|
|
|
state->i);
|
|
|
|
warning_seen = TRUE;
|
|
|
|
|
|
|
|
/* Note: currently only 2D textures can be sliced. */
|
2012-03-16 19:54:13 +00:00
|
|
|
tex_2d = state->ctx->default_gl_texture_2d_tex;
|
2010-11-11 16:28:45 +00:00
|
|
|
cogl_pipeline_set_layer_texture (pipeline, layer_index,
|
2012-02-18 14:58:39 +00:00
|
|
|
COGL_TEXTURE (tex_2d));
|
2010-11-11 16:28:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
|
|
|
/* If the texture can't be repeated with the GPU (e.g. because it has
|
|
|
|
* waste or if using GL_TEXTURE_RECTANGLE_ARB) then if a texture matrix
|
|
|
|
* is also in use we don't know if the result will end up trying
|
|
|
|
* to texture from the waste area.
|
|
|
|
*
|
|
|
|
* Note: we check can_hardware_repeat() first since it's cheaper.
|
|
|
|
*
|
|
|
|
* Note: cases where the texture coordinates will require repeating
|
|
|
|
* will be caught by later validation.
|
|
|
|
*/
|
|
|
|
if (!_cogl_texture_can_hardware_repeat (texture) &&
|
|
|
|
_cogl_pipeline_layer_has_user_matrix (pipeline, layer_index))
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool warning_seen = FALSE;
|
2010-11-11 16:28:45 +00:00
|
|
|
if (!warning_seen)
|
|
|
|
g_warning ("layer %d of your pipeline uses a custom "
|
|
|
|
"texture matrix but because the texture doesn't "
|
|
|
|
"support hardware repeating you may see artefacts "
|
|
|
|
"due to sampling beyond the texture's bounds.",
|
|
|
|
state->i);
|
|
|
|
warning_seen = TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
void
|
|
|
|
_cogl_framebuffer_draw_multitextured_rectangles (
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglMultiTexturedRect *rects,
|
|
|
|
int n_rects,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool disable_legacy_state)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
|
|
|
CoglPipeline *original_pipeline;
|
2010-11-11 16:28:45 +00:00
|
|
|
ValidateLayerState state;
|
2010-10-25 12:25:21 +00:00
|
|
|
int i;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
original_pipeline = pipeline;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
|
|
|
/*
|
2010-10-27 17:54:57 +00:00
|
|
|
* Validate all the layers of the current source pipeline...
|
2009-03-23 12:29:15 +00:00
|
|
|
*/
|
2012-03-16 19:54:13 +00:00
|
|
|
state.ctx = ctx;
|
2010-11-11 16:28:45 +00:00
|
|
|
state.i = -1;
|
|
|
|
state.first_layer = 0;
|
|
|
|
state.override_source = NULL;
|
|
|
|
state.all_use_sliced_quad_fallback = FALSE;
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
|
|
|
_cogl_rectangles_validate_layer_cb,
|
|
|
|
&state);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-11-11 16:28:45 +00:00
|
|
|
if (state.override_source)
|
|
|
|
pipeline = state.override_source;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
if (!disable_legacy_state)
|
2011-09-14 11:17:09 +00:00
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
if (G_UNLIKELY (ctx->legacy_state_set) &&
|
|
|
|
_cogl_get_enable_legacy_state ())
|
|
|
|
{
|
|
|
|
/* If we haven't already made a pipeline copy */
|
|
|
|
if (pipeline == original_pipeline)
|
|
|
|
pipeline = cogl_pipeline_copy (pipeline);
|
|
|
|
_cogl_pipeline_apply_legacy_state (pipeline);
|
|
|
|
}
|
2011-09-14 11:17:09 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 12:29:15 +00:00
|
|
|
/*
|
|
|
|
* Emit geometry for each of the rectangles...
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture;
|
2010-11-11 16:28:45 +00:00
|
|
|
const float default_tex_coords[4] = {0.0, 0.0, 1.0, 1.0};
|
2009-09-16 10:56:17 +00:00
|
|
|
const float *tex_coords;
|
|
|
|
|
2010-11-11 16:28:45 +00:00
|
|
|
if (!state.all_use_sliced_quad_fallback)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool success =
|
2012-03-16 19:54:13 +00:00
|
|
|
_cogl_multitexture_quad_single_primitive (framebuffer,
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline,
|
2012-03-16 19:54:13 +00:00
|
|
|
rects[i].position,
|
2009-09-16 10:56:17 +00:00
|
|
|
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 12:29:15 +00:00
|
|
|
}
|
2009-09-16 10:56:17 +00: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
|
2010-10-27 17:54:57 +00:00
|
|
|
* from the first pipeline layer... */
|
2012-02-05 20:04:14 +00:00
|
|
|
texture = cogl_pipeline_get_layer_texture (pipeline, state.first_layer);
|
2009-09-16 10:56:17 +00:00
|
|
|
|
|
|
|
if (rects[i].tex_coords)
|
|
|
|
tex_coords = rects[i].tex_coords;
|
|
|
|
else
|
|
|
|
tex_coords = default_tex_coords;
|
|
|
|
|
2010-04-01 10:31:33 +00:00
|
|
|
COGL_NOTE (DRAW, "Drawing Tex Quad (Multi-Prim Mode)");
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
_cogl_texture_quad_multiple_primitives (framebuffer,
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline,
|
2012-03-16 19:54:13 +00:00
|
|
|
texture,
|
2011-10-08 13:13:03 +00:00
|
|
|
state.first_layer,
|
2010-02-11 15:33:01 +00:00
|
|
|
rects[i].position,
|
2009-09-16 10:56:17 +00:00
|
|
|
tex_coords[0],
|
|
|
|
tex_coords[1],
|
|
|
|
tex_coords[2],
|
|
|
|
tex_coords[3]);
|
2009-03-23 12:29:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 11:17:09 +00:00
|
|
|
if (pipeline != original_pipeline)
|
2010-11-11 16:28:45 +00:00
|
|
|
cogl_object_unref (pipeline);
|
2009-03-23 12:29:15 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
static void
|
|
|
|
_cogl_rectangles_with_multitexture_coords (
|
|
|
|
CoglMultiTexturedRect *rects,
|
|
|
|
int n_rects)
|
|
|
|
{
|
|
|
|
_cogl_framebuffer_draw_multitextured_rectangles (cogl_get_draw_framebuffer (),
|
|
|
|
cogl_get_source (),
|
|
|
|
rects,
|
|
|
|
n_rects,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
2009-03-23 12:29:15 +00: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-10 01:57:32 +00:00
|
|
|
unsigned int n_rects)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglMultiTexturedRect *rects;
|
2009-03-23 12:29:15 +00:00
|
|
|
int i;
|
|
|
|
|
2010-02-11 15:33:01 +00:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
2012-03-16 19:54:13 +00:00
|
|
|
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
|
2010-02-11 15:33:01 +00:00
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
rects = g_alloca (n_rects * sizeof (CoglMultiTexturedRect));
|
2009-06-16 20:29:21 +00:00
|
|
|
|
2009-03-23 12:29:15 +00:00
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2010-02-11 15:33:01 +00:00
|
|
|
rects[i].position = &verts[i * 4];
|
2009-03-23 12:29:15 +00: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-10 01:57:32 +00:00
|
|
|
unsigned int n_rects)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglMultiTexturedRect *rects;
|
2009-03-23 12:29:15 +00:00
|
|
|
int i;
|
|
|
|
|
2010-02-11 15:33:01 +00:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
2012-03-16 19:54:13 +00:00
|
|
|
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
|
2010-02-11 15:33:01 +00:00
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
rects = g_alloca (n_rects * sizeof (CoglMultiTexturedRect));
|
2009-06-16 20:29:21 +00:00
|
|
|
|
2009-03-23 12:29:15 +00:00
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2010-02-11 15:33:01 +00:00
|
|
|
rects[i].position = &verts[i * 8];
|
2009-03-23 12:29:15 +00: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 15:33:01 +00: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};
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglMultiTexturedRect rect;
|
2010-02-11 15:33:01 +00:00
|
|
|
|
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
2012-03-16 19:54:13 +00:00
|
|
|
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
|
2010-02-11 15:33:01 +00:00
|
|
|
* _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 12:29:15 +00: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-10 01:57:32 +00:00
|
|
|
int user_tex_coords_len)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2010-02-11 15:33:01 +00:00
|
|
|
const float position[4] = {x_1, y_1, x_2, y_2};
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglMultiTexturedRect rect;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-02-11 15:33:01 +00:00
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
2012-03-16 19:54:13 +00:00
|
|
|
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
|
2010-02-11 15:33:01 +00:00
|
|
|
* _cogl_rectangles_with_multitexture_coords.
|
|
|
|
*/
|
|
|
|
|
|
|
|
rect.position = position;
|
2009-03-23 12:29:15 +00: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 12:01:19 +00:00
|
|
|
void
|
2009-01-29 13:31:11 +00:00
|
|
|
cogl_rectangle (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2008-05-05 12:01:19 +00:00
|
|
|
{
|
2010-02-11 15:33:01 +00:00
|
|
|
const float position[4] = {x_1, y_1, x_2, y_2};
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglMultiTexturedRect rect;
|
2010-02-11 15:33:01 +00:00
|
|
|
|
|
|
|
/* XXX: All the cogl_rectangle* APIs normalize their input into an array of
|
2012-03-16 19:54:13 +00:00
|
|
|
* CoglMultiTexturedRect rectangles and pass these on to our work horse;
|
2010-02-11 15:33:01 +00:00
|
|
|
* _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 12:01:19 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 17:15:06 +00:00
|
|
|
void
|
2012-01-08 02:59:04 +00:00
|
|
|
_cogl_rectangle_immediate (CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
float x_1,
|
2010-11-02 17:15:06 +00:00
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
|
|
|
{
|
|
|
|
/* Draw a rectangle using the vertex array API to avoid going
|
|
|
|
through the journal. This should only be used in cases where the
|
|
|
|
code might be called while the journal is already being flushed
|
|
|
|
such as when flushing the clip state */
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglContext *ctx = framebuffer->context;
|
2010-11-02 17:15:06 +00:00
|
|
|
float vertices[8] =
|
|
|
|
{
|
|
|
|
x_1, y_1,
|
|
|
|
x_1, y_2,
|
|
|
|
x_2, y_1,
|
|
|
|
x_2, y_2
|
|
|
|
};
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer;
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[1];
|
2010-11-02 17:15:06 +00:00
|
|
|
|
2012-02-06 17:08:58 +00:00
|
|
|
attribute_buffer =
|
|
|
|
cogl_attribute_buffer_new (ctx, sizeof (vertices), vertices);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[0] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_position_in",
|
|
|
|
sizeof (float) * 2, /* stride */
|
|
|
|
0, /* offset */
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2010-11-02 17:15:06 +00:00
|
|
|
|
2012-01-08 02:59:04 +00:00
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLE_STRIP,
|
|
|
|
0, /* first_index */
|
|
|
|
4, /* n_vertices */
|
|
|
|
attributes,
|
|
|
|
1,
|
|
|
|
COGL_DRAW_SKIP_JOURNAL_FLUSH |
|
|
|
|
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
|
|
|
|
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH |
|
|
|
|
COGL_DRAW_SKIP_LEGACY_STATE);
|
2010-12-14 14:24:17 +00:00
|
|
|
|
2010-11-02 17:15:06 +00:00
|
|
|
|
|
|
|
cogl_object_unref (attributes[0]);
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-02 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
typedef struct _AppendTexCoordsState
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2010-10-18 16:17:22 +00:00
|
|
|
const CoglTextureVertex *vertices_in;
|
|
|
|
int vertex;
|
|
|
|
int layer;
|
|
|
|
float *vertices_out;
|
|
|
|
} AppendTexCoordsState;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-10-27 17:54:57 +00:00
|
|
|
append_tex_coord_attributes_cb (CoglPipeline *pipeline,
|
2010-10-18 16:17:22 +00:00
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
AppendTexCoordsState *state = user_data;
|
2011-08-24 20:30:34 +00:00
|
|
|
CoglTexture *texture;
|
2010-10-18 16:17:22 +00:00
|
|
|
float tx, ty;
|
|
|
|
float *t;
|
2009-09-16 10:56:17 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
tx = state->vertices_in[state->vertex].tx;
|
|
|
|
ty = state->vertices_in[state->vertex].ty;
|
2009-09-16 10:56:17 +00:00
|
|
|
|
2011-08-24 20:30:34 +00:00
|
|
|
/* NULL textures will be handled in
|
2010-10-27 17:54:57 +00:00
|
|
|
* _cogl_pipeline_flush_layers_gl_state but there is no need to worry
|
2010-10-18 16:17:22 +00:00
|
|
|
* about scaling texture coordinates in this case */
|
2012-02-05 20:04:14 +00:00
|
|
|
texture = cogl_pipeline_get_layer_texture (pipeline, layer_index);
|
2011-08-24 20:30:34 +00:00
|
|
|
if (texture != NULL)
|
|
|
|
_cogl_texture_transform_coords_to_gl (texture, &tx, &ty);
|
2009-09-16 10:56:17 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
t = state->vertices_out + 3 + 2 * state->layer;
|
|
|
|
t[0] = tx;
|
|
|
|
t[1] = ty;
|
2010-10-25 12:25:21 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
state->layer++;
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
typedef struct _ValidateState
|
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *original_pipeline;
|
|
|
|
CoglPipeline *pipeline;
|
2010-10-18 16:17:22 +00:00
|
|
|
} ValidateState;
|
2009-09-16 10:56:17 +00:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-11-11 16:28:45 +00:00
|
|
|
_cogl_polygon_validate_layer_cb (CoglPipeline *pipeline,
|
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
2010-10-18 16:17:22 +00:00
|
|
|
{
|
|
|
|
ValidateState *state = user_data;
|
2010-04-01 10:31:33 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
/* By default COGL_PIPELINE_WRAP_MODE_AUTOMATIC becomes
|
2010-10-18 16:17:22 +00:00
|
|
|
* GL_CLAMP_TO_EDGE but we want the polygon API to use GL_REPEAT to
|
|
|
|
* maintain compatibility with previous releases
|
|
|
|
*/
|
2010-04-01 10:31:33 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
if (cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index) ==
|
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2010-04-26 09:01:43 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
if (state->original_pipeline == state->pipeline)
|
|
|
|
state->pipeline = cogl_pipeline_copy (pipeline);
|
2010-04-26 09:01:43 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode_s (state->pipeline, layer_index,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
2010-10-18 16:17:22 +00:00
|
|
|
}
|
2010-05-18 21:42:49 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
if (cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index) ==
|
|
|
|
COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
|
2010-10-18 16:17:22 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
if (state->original_pipeline == state->pipeline)
|
|
|
|
state->pipeline = cogl_pipeline_copy (pipeline);
|
2009-09-16 10:56:17 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_pipeline_set_layer_wrap_mode_t (state->pipeline, layer_index,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
2010-10-18 16:17:22 +00:00
|
|
|
}
|
2010-04-26 09:01:43 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
return TRUE;
|
2009-09-16 10:56:17 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
void
|
|
|
|
cogl_polygon (const CoglTextureVertex *vertices,
|
|
|
|
unsigned int n_vertices,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool use_color)
|
2009-09-16 10:56:17 +00:00
|
|
|
{
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *pipeline;
|
2010-10-18 16:17:22 +00:00
|
|
|
ValidateState validate_state;
|
|
|
|
int n_layers;
|
|
|
|
int n_attributes;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes;
|
2010-10-18 16:17:22 +00:00
|
|
|
int i;
|
|
|
|
unsigned int stride;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
size_t stride_bytes;
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer;
|
2010-10-18 16:17:22 +00:00
|
|
|
float *v;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline = cogl_get_source ();
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
validate_state.original_pipeline = pipeline;
|
|
|
|
validate_state.pipeline = pipeline;
|
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
2010-11-11 16:28:45 +00:00
|
|
|
_cogl_polygon_validate_layer_cb,
|
2010-10-18 16:17:22 +00:00
|
|
|
&validate_state);
|
2010-10-27 17:54:57 +00:00
|
|
|
pipeline = validate_state.pipeline;
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-27 17:54:57 +00:00
|
|
|
n_layers = cogl_pipeline_get_n_layers (pipeline);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
n_attributes = 1 + n_layers + (use_color ? 1 : 0);
|
2011-03-03 01:02:12 +00:00
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * n_attributes);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
/* Our data is arranged like:
|
|
|
|
* [X, Y, Z, TX0, TY0, TX1, TY1..., R, G, B, A,...] */
|
|
|
|
stride = 3 + (2 * n_layers) + (use_color ? 1 : 0);
|
|
|
|
stride_bytes = stride * sizeof (float);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
/* 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->polygon_vertices, n_vertices * stride);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * stride_bytes, NULL);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[0] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_position_in",
|
|
|
|
stride_bytes,
|
|
|
|
0,
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
for (i = 0; i < n_layers; i++)
|
|
|
|
{
|
2011-07-29 16:24:10 +00:00
|
|
|
static const char *names[] = {
|
2010-10-18 16:17:22 +00:00
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
"cogl_tex_coord1_in",
|
|
|
|
"cogl_tex_coord2_in",
|
|
|
|
"cogl_tex_coord3_in",
|
|
|
|
"cogl_tex_coord4_in",
|
|
|
|
"cogl_tex_coord5_in",
|
|
|
|
"cogl_tex_coord6_in",
|
|
|
|
"cogl_tex_coord7_in"
|
|
|
|
};
|
2011-07-29 16:24:10 +00:00
|
|
|
char *allocated_name = NULL;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (i < 8)
|
|
|
|
name = names[i];
|
|
|
|
else
|
|
|
|
name = allocated_name = g_strdup_printf ("cogl_tex_coord%d_in", i);
|
2010-10-18 16:17:22 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[i + 1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
name,
|
|
|
|
stride_bytes,
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
12 + 8 * i,
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-07-29 16:24:10 +00:00
|
|
|
|
|
|
|
g_free (allocated_name);
|
2010-10-18 16:17:22 +00:00
|
|
|
}
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
if (use_color)
|
|
|
|
{
|
|
|
|
attributes[n_attributes - 1] =
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
stride_bytes,
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
|
|
|
12 + 8 * n_layers,
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2010-10-18 16:17:22 +00:00
|
|
|
}
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
/* Convert the vertices into an array of float vertex attributes */
|
|
|
|
v = (float *)ctx->polygon_vertices->data;
|
|
|
|
for (i = 0; i < n_vertices; i++)
|
2009-03-23 12:29:15 +00:00
|
|
|
{
|
2010-10-18 16:17:22 +00:00
|
|
|
AppendTexCoordsState append_tex_coords_state;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *c;
|
2009-03-23 12:29:15 +00: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;
|
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
append_tex_coords_state.vertices_in = vertices;
|
|
|
|
append_tex_coords_state.vertex = i;
|
|
|
|
append_tex_coords_state.layer = 0;
|
|
|
|
append_tex_coords_state.vertices_out = v;
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_pipeline_foreach_layer (pipeline,
|
2010-10-18 16:17:22 +00:00
|
|
|
append_tex_coord_attributes_cb,
|
|
|
|
&append_tex_coords_state);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2009-06-16 21:48:21 +00:00
|
|
|
if (use_color)
|
|
|
|
{
|
|
|
|
/* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
c = (uint8_t *) (v + 3 + 2 * n_layers);
|
2009-06-16 21:48:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2010-04-26 09:01:43 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
v += stride;
|
2009-03-23 12:29:15 +00:00
|
|
|
}
|
2010-01-04 11:43:00 +00:00
|
|
|
|
2010-10-18 16:17:22 +00:00
|
|
|
v = (float *)ctx->polygon_vertices->data;
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_buffer_set_data (COGL_BUFFER (attribute_buffer),
|
2010-10-18 16:17:22 +00:00
|
|
|
0,
|
2010-11-04 16:01:23 +00:00
|
|
|
v,
|
2010-10-18 16:17:22 +00:00
|
|
|
ctx->polygon_vertices->len * sizeof (float));
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2012-01-08 02:59:04 +00:00
|
|
|
/* XXX: although this may seem redundant, we need to do this since
|
|
|
|
* cogl_polygon() can be used with legacy state and its the source stack
|
|
|
|
* which track whether legacy state is enabled.
|
|
|
|
*
|
|
|
|
* (We only have a CoglDrawFlag to disable legacy state not one
|
|
|
|
* to enable it) */
|
2010-10-27 17:54:57 +00:00
|
|
|
cogl_push_source (pipeline);
|
2010-10-25 12:25:21 +00:00
|
|
|
|
2012-01-08 02:59:04 +00:00
|
|
|
_cogl_framebuffer_draw_attributes (cogl_get_draw_framebuffer (),
|
|
|
|
pipeline,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLE_FAN,
|
|
|
|
0, n_vertices,
|
|
|
|
attributes,
|
|
|
|
n_attributes,
|
|
|
|
0 /* no draw flags */);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2010-10-25 12:25:21 +00:00
|
|
|
cogl_pop_source ();
|
2010-11-25 20:12:36 +00:00
|
|
|
|
|
|
|
if (pipeline != validate_state.original_pipeline)
|
|
|
|
cogl_object_unref (pipeline);
|
2009-03-23 12:29:15 +00:00
|
|
|
|
2011-07-29 16:24:10 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
|
|
|
|
|
|
|
for (i = 0; i < n_attributes; i++)
|
|
|
|
cogl_object_unref (attributes[i]);
|
|
|
|
}
|