2010-10-12 11:53:10 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl-context.h"
|
|
|
|
#include "cogl-object-private.h"
|
|
|
|
#include "cogl-journal-private.h"
|
2011-01-20 19:31:53 +00:00
|
|
|
#include "cogl-attribute.h"
|
|
|
|
#include "cogl-attribute-private.h"
|
2010-10-27 17:54:57 +00:00
|
|
|
#include "cogl-pipeline.h"
|
|
|
|
#include "cogl-pipeline-private.h"
|
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2010-10-12 11:53:10 +00:00
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-framebuffer-private.h"
|
|
|
|
#include "cogl-indices-private.h"
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
#include "cogl-pipeline-progend-glsl-private.h"
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#if defined (HAVE_COGL_GL)
|
|
|
|
|
|
|
|
#define glGenBuffers ctx->drv.pf_glGenBuffers
|
|
|
|
#define glBindBuffer ctx->drv.pf_glBindBuffer
|
|
|
|
#define glBufferData ctx->drv.pf_glBufferData
|
|
|
|
#define glBufferSubData ctx->drv.pf_glBufferSubData
|
|
|
|
#define glGetBufferSubData ctx->drv.pf_glGetBufferSubData
|
|
|
|
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffers
|
|
|
|
#define glMapBuffer ctx->drv.pf_glMapBuffer
|
|
|
|
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
|
|
|
|
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
|
|
|
#ifndef GL_ARRAY_BUFFER
|
|
|
|
#define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define glVertexAttribPointer ctx->drv.pf_glVertexAttribPointer
|
|
|
|
#define glEnableVertexAttribArray ctx->drv.pf_glEnableVertexAttribArray
|
|
|
|
#define glDisableVertexAttribArray ctx->drv.pf_glDisableVertexAttribArray
|
|
|
|
#define MAY_HAVE_PROGRAMABLE_GL
|
|
|
|
|
|
|
|
#define glDrawRangeElements(mode, start, end, count, type, indices) \
|
|
|
|
ctx->drv.pf_glDrawRangeElements (mode, start, end, count, type, indices)
|
|
|
|
|
|
|
|
#else /* GLES 1/2 */
|
|
|
|
|
|
|
|
/* GLES doesn't have glDrawRangeElements, so we simply pretend it does
|
|
|
|
* but that it makes no use of the start, end constraints: */
|
|
|
|
#define glDrawRangeElements(mode, start, end, count, type, indices) \
|
|
|
|
glDrawElements (mode, count, type, indices)
|
|
|
|
|
|
|
|
/* This isn't defined in the GLES headers */
|
|
|
|
#ifndef GL_UNSIGNED_INT
|
|
|
|
#define GL_UNSIGNED_INT 0x1405
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
#define MAY_HAVE_PROGRAMABLE_GL
|
|
|
|
|
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
static void _cogl_attribute_free (CoglAttribute *attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
COGL_OBJECT_DEFINE (Attribute, attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
gboolean
|
|
|
|
validate_gl_attribute (const char *name,
|
|
|
|
int n_components,
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttributeNameID *name_id,
|
2010-10-12 11:53:10 +00:00
|
|
|
gboolean *normalized,
|
|
|
|
unsigned int *texture_unit)
|
|
|
|
{
|
|
|
|
name = name + 3; /* skip past "gl_" */
|
|
|
|
|
|
|
|
*normalized = FALSE;
|
|
|
|
*texture_unit = 0;
|
|
|
|
|
|
|
|
if (strcmp (name, "Vertex") == 0)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components == 1))
|
|
|
|
{
|
|
|
|
g_critical ("glVertexPointer doesn't allow 1 component vertex "
|
|
|
|
"positions so we currently only support \"gl_Vertex\" "
|
|
|
|
"attributes where n_components == 2, 3 or 4");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (name, "Color") == 0)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components != 3 && n_components != 4))
|
|
|
|
{
|
|
|
|
g_critical ("glColorPointer expects 3 or 4 component colors so we "
|
|
|
|
"currently only support \"gl_Color\" attributes where "
|
|
|
|
"n_components == 3 or 4");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
*normalized = TRUE;
|
|
|
|
}
|
|
|
|
else if (strncmp (name, "MultiTexCoord", strlen ("MultiTexCoord")) == 0)
|
|
|
|
{
|
|
|
|
if (sscanf (gl_attribute, "MultiTexCoord%u", texture_unit) != 1)
|
|
|
|
{
|
|
|
|
g_warning ("gl_MultiTexCoord attributes should include a\n"
|
|
|
|
"texture unit number, E.g. gl_MultiTexCoord0\n");
|
|
|
|
unit = 0;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
else if (strncmp (name, "Normal") == 0)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components != 3))
|
|
|
|
{
|
|
|
|
g_critical ("glNormalPointer expects 3 component normals so we "
|
|
|
|
"currently only support \"gl_Normal\" attributes where "
|
|
|
|
"n_components == 3");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
*normalized = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Unknown gl_* attribute name gl_%s\n", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
validate_cogl_attribute (const char *name,
|
|
|
|
int n_components,
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttributeNameID *name_id,
|
2010-10-12 11:53:10 +00:00
|
|
|
gboolean *normalized,
|
|
|
|
unsigned int *texture_unit)
|
|
|
|
{
|
|
|
|
name = name + 5; /* skip "cogl_" */
|
|
|
|
|
|
|
|
*normalized = FALSE;
|
|
|
|
*texture_unit = 0;
|
|
|
|
|
|
|
|
if (strcmp (name, "position_in") == 0)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components == 1))
|
|
|
|
{
|
|
|
|
g_critical ("glVertexPointer doesn't allow 1 component vertex "
|
|
|
|
"positions so we currently only support \"cogl_vertex\" "
|
|
|
|
"attributes where n_components == 2, 3 or 4");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (name, "color_in") == 0)
|
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components != 3 && n_components != 4))
|
|
|
|
{
|
|
|
|
g_critical ("glColorPointer expects 3 or 4 component colors so we "
|
|
|
|
"currently only support \"cogl_color\" attributes where "
|
|
|
|
"n_components == 3 or 4");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (name, "tex_coord_in") == 0)
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
else if (strncmp (name, "tex_coord", strlen ("tex_coord")) == 0)
|
|
|
|
{
|
|
|
|
if (sscanf (name, "tex_coord%u_in", texture_unit) != 1)
|
|
|
|
{
|
|
|
|
g_warning ("Texture coordinate attributes should either be named "
|
|
|
|
"\"cogl_tex_coord\" or named with a texture unit index "
|
|
|
|
"like \"cogl_tex_coord2_in\"\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
2010-12-22 01:45:09 +00:00
|
|
|
else if (strcmp (name, "normal_in") == 0)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
if (G_UNLIKELY (n_components != 3))
|
|
|
|
{
|
|
|
|
g_critical ("glNormalPointer expects 3 component normals so we "
|
|
|
|
"currently only support \"cogl_normal\" attributes "
|
|
|
|
"where n_components == 3");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-20 19:31:53 +00:00
|
|
|
*name_id = COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
*normalized = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Unknown cogl_* attribute name cogl_%s\n", name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *
|
|
|
|
cogl_attribute_new (CoglVertexArray *array,
|
|
|
|
const char *name,
|
|
|
|
gsize stride,
|
|
|
|
gsize offset,
|
|
|
|
int n_components,
|
|
|
|
CoglAttributeType type)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute = g_slice_new (CoglAttribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
gboolean status;
|
|
|
|
|
|
|
|
attribute->array = cogl_object_ref (array);
|
|
|
|
attribute->name = g_strdup (name);
|
|
|
|
attribute->stride = stride;
|
|
|
|
attribute->offset = offset;
|
|
|
|
attribute->n_components = n_components;
|
|
|
|
attribute->type = type;
|
|
|
|
attribute->immutable_ref = 0;
|
|
|
|
|
|
|
|
if (strncmp (name, "cogl_", 5) == 0)
|
|
|
|
status = validate_cogl_attribute (attribute->name,
|
|
|
|
n_components,
|
|
|
|
&attribute->name_id,
|
|
|
|
&attribute->normalized,
|
|
|
|
&attribute->texture_unit);
|
|
|
|
#if 0
|
|
|
|
else if (strncmp (name, "gl_", 3) == 0)
|
|
|
|
status = validate_gl_attribute (attribute->name,
|
|
|
|
n_components,
|
|
|
|
&attribute->name_id,
|
|
|
|
&attribute->normalized,
|
|
|
|
&attribute->texture_unit);
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
attribute->name_id = COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY;
|
2010-10-12 11:53:10 +00:00
|
|
|
attribute->normalized = FALSE;
|
|
|
|
attribute->texture_unit = 0;
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_attribute_free (attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
return _cogl_attribute_object_new (attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_attribute_get_normalized (CoglAttribute *attribute)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_val_if_fail (cogl_is_attribute (attribute), FALSE);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
return attribute->normalized;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
warn_about_midscene_changes (void)
|
|
|
|
{
|
|
|
|
static gboolean seen = FALSE;
|
|
|
|
if (!seen)
|
|
|
|
{
|
|
|
|
g_warning ("Mid-scene modification of attributes has "
|
|
|
|
"undefined results\n");
|
|
|
|
seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_attribute_set_normalized (CoglAttribute *attribute,
|
2010-10-12 11:53:10 +00:00
|
|
|
gboolean normalized)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_if_fail (cogl_is_attribute (attribute));
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (attribute->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
|
|
|
|
attribute->normalized = normalized;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglVertexArray *
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_attribute_get_array (CoglAttribute *attribute)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_val_if_fail (cogl_is_attribute (attribute), NULL);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
return attribute->array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_attribute_set_array (CoglAttribute *attribute,
|
2010-10-12 11:53:10 +00:00
|
|
|
CoglVertexArray *array)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_if_fail (cogl_is_attribute (attribute));
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (attribute->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
|
|
|
|
cogl_object_ref (array);
|
|
|
|
|
|
|
|
cogl_object_unref (attribute->array);
|
|
|
|
attribute->array = array;
|
|
|
|
}
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *
|
|
|
|
_cogl_attribute_immutable_ref (CoglAttribute *attribute)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_val_if_fail (cogl_is_attribute (attribute), NULL);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attribute->immutable_ref++;
|
|
|
|
_cogl_buffer_immutable_ref (COGL_BUFFER (attribute->array));
|
|
|
|
return attribute;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_attribute_immutable_unref (CoglAttribute *attribute)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
g_return_if_fail (cogl_is_attribute (attribute));
|
|
|
|
g_return_if_fail (attribute->immutable_ref > 0);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attribute->immutable_ref--;
|
|
|
|
_cogl_buffer_immutable_unref (COGL_BUFFER (attribute->array));
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_attribute_free (CoglAttribute *attribute)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
g_free (attribute->name);
|
|
|
|
cogl_object_unref (attribute->array);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
g_slice_free (CoglAttribute, attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int unit;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipelineFlushOptions options;
|
2010-10-12 11:53:10 +00:00
|
|
|
guint32 fallback_layers;
|
|
|
|
} ValidateLayerState;
|
|
|
|
|
|
|
|
static gboolean
|
2010-10-27 17:54:57 +00:00
|
|
|
validate_layer_cb (CoglPipeline *pipeline,
|
2010-10-12 11:53:10 +00:00
|
|
|
int layer_index,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglHandle texture =
|
2010-10-27 17:54:57 +00:00
|
|
|
_cogl_pipeline_get_layer_texture (pipeline, layer_index);
|
2010-10-12 11:53:10 +00:00
|
|
|
ValidateLayerState *state = user_data;
|
|
|
|
gboolean status = TRUE;
|
|
|
|
|
|
|
|
/* invalid textures will be handled correctly in
|
2010-10-27 17:54:57 +00:00
|
|
|
* _cogl_pipeline_flush_layers_gl_state */
|
2010-10-12 11:53:10 +00:00
|
|
|
if (texture == COGL_INVALID_HANDLE)
|
|
|
|
goto validated;
|
|
|
|
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_texture_flush_journal_rendering (texture);
|
|
|
|
|
2010-10-12 11:53:10 +00: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 (texture);
|
|
|
|
|
|
|
|
/* We need to ensure the mipmaps are ready before deciding
|
|
|
|
* anything else about the texture because the texture storate
|
|
|
|
* could completely change if it needs to be migrated out of the
|
|
|
|
* atlas and will affect how we validate the layer.
|
|
|
|
*/
|
2010-10-27 17:54:57 +00:00
|
|
|
_cogl_pipeline_pre_paint_for_layer (pipeline, layer_index);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
if (!_cogl_texture_can_hardware_repeat (texture))
|
|
|
|
{
|
|
|
|
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", layer_index);
|
|
|
|
|
|
|
|
/* XXX: maybe we can add a mechanism for users to forcibly use
|
|
|
|
* textures with waste where it would be their responsability to use
|
|
|
|
* texture coords in the range [0,1] such that sampling outside isn't
|
|
|
|
* required. We can then use a texture matrix (or a modification of
|
|
|
|
* the users own matrix) to map 1 to the edge of the texture data.
|
|
|
|
*
|
|
|
|
* Potentially, given the same guarantee as above we could also
|
|
|
|
* support a single sliced layer too. We would have to redraw the
|
|
|
|
* vertices once for each layer, each time with a fiddled texture
|
|
|
|
* matrix.
|
|
|
|
*/
|
|
|
|
state->fallback_layers |= (1 << state->unit);
|
2010-10-27 17:54:57 +00:00
|
|
|
state->options.flags |= COGL_PIPELINE_FLUSH_FALLBACK_MASK;
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validated:
|
|
|
|
state->unit++;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
static void
|
|
|
|
toggle_enabled_cb (int bit_num, void *user_data)
|
|
|
|
{
|
|
|
|
const CoglBitmask *new_values = user_data;
|
|
|
|
gboolean enabled = _cogl_bitmask_get (new_values, bit_num);
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
GE( glEnableVertexAttribArray (bit_num) );
|
|
|
|
else
|
|
|
|
GE( glDisableVertexAttribArray (bit_num) );
|
|
|
|
|
|
|
|
#else /* HAVE_COGL_GLES2 */
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
GE( glClientActiveTexture (GL_TEXTURE0 + bit_num) );
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
GE( glEnableClientState (GL_TEXTURE_COORD_ARRAY) );
|
|
|
|
else
|
|
|
|
GE( glDisableClientState (GL_TEXTURE_COORD_ARRAY) );
|
|
|
|
|
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_enabled_arrays (CoglBitmask *value_cache,
|
|
|
|
const CoglBitmask *new_values)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* Get the list of bits that are different */
|
|
|
|
_cogl_bitmask_clear_all (&ctx->arrays_to_change);
|
|
|
|
_cogl_bitmask_set_bits (&ctx->arrays_to_change, value_cache);
|
|
|
|
_cogl_bitmask_xor_bits (&ctx->arrays_to_change, new_values);
|
|
|
|
|
|
|
|
/* Iterate over each bit to change */
|
|
|
|
_cogl_bitmask_foreach (&ctx->arrays_to_change,
|
|
|
|
toggle_enabled_cb,
|
|
|
|
(void *) new_values);
|
|
|
|
|
|
|
|
/* Store the new values */
|
|
|
|
_cogl_bitmask_clear_all (value_cache);
|
|
|
|
_cogl_bitmask_set_bits (value_cache, new_values);
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
static CoglHandle
|
2010-12-14 14:44:45 +00:00
|
|
|
enable_gl_state (CoglDrawFlags flags,
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes,
|
2010-10-12 11:53:10 +00:00
|
|
|
ValidateLayerState *state)
|
|
|
|
{
|
2011-02-02 14:23:53 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_draw_buffer ();
|
2010-10-12 11:53:10 +00:00
|
|
|
int i;
|
|
|
|
#ifdef MAY_HAVE_PROGRAMABLE_GL
|
|
|
|
GLuint generic_index = 0;
|
|
|
|
#endif
|
|
|
|
unsigned long enable_flags = 0;
|
|
|
|
gboolean skip_gl_color = FALSE;
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *source;
|
|
|
|
CoglPipeline *copy = NULL;
|
2010-12-02 21:08:30 +00:00
|
|
|
int n_tex_coord_attribs = 0;
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
|
|
|
|
2011-01-12 22:12:41 +00:00
|
|
|
/* In cogl_read_pixels we have a fast-path when reading a single
|
|
|
|
* pixel and the scene is just comprised of simple rectangles still
|
|
|
|
* in the journal. For this optimization to work we need to track
|
|
|
|
* when the framebuffer really does get drawn to. */
|
|
|
|
_cogl_framebuffer_dirty (framebuffer);
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
source = cogl_get_source ();
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
/* Iterate the attributes to work out whether blending needs to be
|
|
|
|
enabled and how many texture coords there are. We need to do this
|
|
|
|
before flushing the pipeline. */
|
|
|
|
for (i = 0; attributes[i]; i++)
|
|
|
|
switch (attributes[i]->name_id)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
|
2010-12-14 14:44:45 +00:00
|
|
|
if ((flags & COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE) == 0 &&
|
|
|
|
!_cogl_pipeline_get_real_blend_enabled (source))
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
|
|
|
CoglPipelineBlendEnable blend_enable =
|
|
|
|
COGL_PIPELINE_BLEND_ENABLE_ENABLED;
|
|
|
|
copy = cogl_pipeline_copy (source);
|
|
|
|
_cogl_pipeline_set_blend_enabled (copy, blend_enable);
|
|
|
|
source = copy;
|
|
|
|
}
|
|
|
|
skip_gl_color = TRUE;
|
|
|
|
break;
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
|
2010-12-03 17:46:16 +00:00
|
|
|
n_tex_coord_attribs++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (state->options.flags))
|
|
|
|
{
|
|
|
|
/* If we haven't already created a derived pipeline... */
|
|
|
|
if (!copy)
|
|
|
|
{
|
|
|
|
copy = cogl_pipeline_copy (source);
|
|
|
|
source = copy;
|
|
|
|
}
|
|
|
|
_cogl_pipeline_apply_overrides (source, &state->options);
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* overrides = cogl_pipeline_get_data (pipeline,
|
|
|
|
* last_overrides_key);
|
|
|
|
* if (overrides)
|
|
|
|
* {
|
|
|
|
* age = cogl_pipeline_get_age (pipeline);
|
|
|
|
* XXX: actually we also need to check for legacy_state
|
|
|
|
* and blending overrides for use of glColorPointer...
|
|
|
|
* if (overrides->ags != age ||
|
|
|
|
* memcmp (&overrides->options, &options,
|
|
|
|
* sizeof (options) != 0)
|
|
|
|
* {
|
|
|
|
* cogl_object_unref (overrides->weak_pipeline);
|
|
|
|
* g_slice_free (Overrides, overrides);
|
|
|
|
* overrides = NULL;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* if (!overrides)
|
|
|
|
* {
|
|
|
|
* overrides = g_slice_new (Overrides);
|
|
|
|
* overrides->weak_pipeline =
|
|
|
|
* cogl_pipeline_weak_copy (cogl_get_source ());
|
|
|
|
* _cogl_pipeline_apply_overrides (overrides->weak_pipeline,
|
|
|
|
* &options);
|
|
|
|
*
|
|
|
|
* cogl_pipeline_set_data (pipeline, last_overrides_key,
|
|
|
|
* weak_overrides,
|
|
|
|
* free_overrides_cb,
|
|
|
|
* NULL);
|
|
|
|
* }
|
|
|
|
* source = overrides->weak_pipeline;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:13:41 +00:00
|
|
|
if (G_UNLIKELY (ctx->legacy_state_set) &&
|
|
|
|
(flags & COGL_DRAW_SKIP_LEGACY_STATE) == 0)
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
|
|
|
/* If we haven't already created a derived pipeline... */
|
|
|
|
if (!copy)
|
|
|
|
{
|
|
|
|
copy = cogl_pipeline_copy (source);
|
|
|
|
source = copy;
|
|
|
|
}
|
|
|
|
_cogl_pipeline_apply_legacy_state (source);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_pipeline_flush_gl_state (source, skip_gl_color, n_tex_coord_attribs);
|
|
|
|
|
|
|
|
if (ctx->enable_backface_culling)
|
|
|
|
enable_flags |= COGL_ENABLE_BACKFACE_CULLING;
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
_cogl_bitmask_clear_all (&ctx->temp_bitmask);
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
/* Bind the attribute pointers. We need to do this after the
|
|
|
|
pipeline is flushed because on GLES2 that is the only point when
|
|
|
|
we can determine the attribute locations */
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
for (i = 0; attributes[i]; i++)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute = attributes[i];
|
2010-10-12 11:53:10 +00:00
|
|
|
CoglVertexArray *vertex_array;
|
|
|
|
CoglBuffer *buffer;
|
2011-02-15 12:43:26 +00:00
|
|
|
guint8 *base;
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
int attrib_location;
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
vertex_array = cogl_attribute_get_array (attribute);
|
2010-10-12 11:53:10 +00:00
|
|
|
buffer = COGL_BUFFER (vertex_array);
|
|
|
|
base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
switch (attribute->name_id)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
attrib_location =
|
|
|
|
_cogl_pipeline_progend_glsl_get_color_attribute (source);
|
|
|
|
if (attrib_location != -1)
|
|
|
|
{
|
|
|
|
GE( glVertexAttribPointer (attrib_location,
|
|
|
|
attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
TRUE, /* normalize */
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset) );
|
|
|
|
|
|
|
|
_cogl_bitmask_set (&ctx->temp_bitmask, attrib_location, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
enable_flags |= COGL_ENABLE_COLOR_ARRAY;
|
|
|
|
/* GE (glEnableClientState (GL_COLOR_ARRAY)); */
|
|
|
|
GE (glColorPointer (attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset));
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY:
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
attrib_location =
|
|
|
|
_cogl_pipeline_progend_glsl_get_normal_attribute (source);
|
|
|
|
if (attrib_location != -1)
|
|
|
|
{
|
|
|
|
GE( glVertexAttribPointer (attrib_location,
|
|
|
|
attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
TRUE, /* normalize */
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset) );
|
|
|
|
_cogl_bitmask_set (&ctx->temp_bitmask, attrib_location, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
/* FIXME: go through cogl cache to enable normal array */
|
|
|
|
GE (glEnableClientState (GL_NORMAL_ARRAY));
|
|
|
|
GE (glNormalPointer (attribute->type,
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset));
|
2010-12-03 17:46:16 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
attrib_location = _cogl_pipeline_progend_glsl_get_tex_coord_attribute
|
|
|
|
(source, attribute->texture_unit);
|
|
|
|
if (attrib_location != -1)
|
|
|
|
{
|
|
|
|
GE( glVertexAttribPointer (attrib_location,
|
|
|
|
attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
FALSE, /* normalize */
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset) );
|
|
|
|
_cogl_bitmask_set (&ctx->temp_bitmask, attrib_location, TRUE);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
GE (glClientActiveTexture (GL_TEXTURE0 +
|
|
|
|
attribute->texture_unit));
|
|
|
|
GE (glTexCoordPointer (attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset));
|
|
|
|
_cogl_bitmask_set (&ctx->temp_bitmask,
|
|
|
|
attribute->texture_unit, TRUE);
|
2010-12-03 17:46:16 +00:00
|
|
|
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY:
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
|
|
|
|
attrib_location =
|
|
|
|
_cogl_pipeline_progend_glsl_get_position_attribute (source);
|
|
|
|
if (attrib_location != -1)
|
|
|
|
{
|
|
|
|
GE( glVertexAttribPointer (attrib_location,
|
|
|
|
attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
FALSE, /* normalize */
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset) );
|
|
|
|
_cogl_bitmask_set (&ctx->temp_bitmask, attrib_location, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
enable_flags |= COGL_ENABLE_VERTEX_ARRAY;
|
|
|
|
/* GE (glEnableClientState (GL_VERTEX_ARRAY)); */
|
|
|
|
GE (glVertexPointer (attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset));
|
2010-12-03 17:46:16 +00:00
|
|
|
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
#ifdef MAY_HAVE_PROGRAMABLE_GL
|
2010-12-03 17:46:16 +00:00
|
|
|
/* FIXME: go through cogl cache to enable generic array. */
|
|
|
|
/* FIXME: this is going to end up just using the builtins
|
|
|
|
on GLES 2 */
|
2010-10-12 11:53:10 +00:00
|
|
|
GE (glEnableVertexAttribArray (generic_index++));
|
|
|
|
GE (glVertexAttribPointer (generic_index,
|
|
|
|
attribute->n_components,
|
|
|
|
attribute->type,
|
|
|
|
attribute->normalized,
|
|
|
|
attribute->stride,
|
|
|
|
base + attribute->offset));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("Unrecognised attribute type 0x%08x", attribute->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_buffer_unbind (buffer);
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
/* Flush the state of the attribute arrays */
|
|
|
|
set_enabled_arrays (&ctx->arrays_enabled, &ctx->temp_bitmask);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
_cogl_enable (enable_flags);
|
|
|
|
_cogl_flush_face_winding ();
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:46:16 +00:00
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_attribute_disable_cached_arrays (void)
|
2010-12-03 17:46:16 +00:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
_cogl_bitmask_clear_all (&ctx->temp_bitmask);
|
|
|
|
set_enabled_arrays (&ctx->arrays_enabled, &ctx->temp_bitmask);
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
/* FIXME: we shouldn't be disabling state after drawing we should
|
|
|
|
* just disable the things not needed after enabling state. */
|
|
|
|
static void
|
2011-01-20 19:31:53 +00:00
|
|
|
disable_gl_state (CoglAttribute **attributes,
|
2010-10-27 17:54:57 +00:00
|
|
|
CoglPipeline *source)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
#ifdef MAY_HAVE_PROGRAMABLE_GL
|
|
|
|
GLuint generic_index = 0;
|
|
|
|
#endif
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (source != cogl_get_source ()))
|
|
|
|
cogl_object_unref (source);
|
|
|
|
|
|
|
|
for (i = 0; attributes[i]; i++)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute = attributes[i];
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
switch (attribute->name_id)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
/* GE (glDisableClientState (GL_COLOR_ARRAY)); */
|
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
/* FIXME: go through cogl cache to enable normal array */
|
2010-12-03 17:46:16 +00:00
|
|
|
#ifndef HAVE_COGL_GLES2
|
2010-10-12 11:53:10 +00:00
|
|
|
GE (glDisableClientState (GL_NORMAL_ARRAY));
|
2010-12-03 17:46:16 +00:00
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
/* The enabled state of the texture coord arrays is
|
|
|
|
cached in ctx->enabled_texcoord_arrays so we don't
|
|
|
|
need to do anything here. The array will be disabled
|
|
|
|
by the next drawing primitive if it is not
|
|
|
|
required */
|
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
/* GE (glDisableClientState (GL_VERTEX_ARRAY)); */
|
|
|
|
break;
|
2011-01-20 19:31:53 +00:00
|
|
|
case COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY:
|
2010-10-12 11:53:10 +00:00
|
|
|
#ifdef MAY_HAVE_PROGRAMABLE_GL
|
|
|
|
/* FIXME: go through cogl cache to enable generic array */
|
|
|
|
GE (glDisableVertexAttribArray (generic_index++));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("Unrecognised attribute type 0x%08x", attribute->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 13:06:08 +00:00
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
|
|
|
static int
|
|
|
|
get_index (void *indices,
|
|
|
|
CoglIndicesType type,
|
|
|
|
int _index)
|
|
|
|
{
|
|
|
|
if (!indices)
|
|
|
|
return _index;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
|
|
|
|
return ((guint8 *)indices)[_index];
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
|
|
|
|
return ((guint16 *)indices)[_index];
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_INT:
|
|
|
|
return ((guint32 *)indices)[_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_line (void *vertices,
|
|
|
|
void *indices,
|
|
|
|
CoglIndicesType indices_type,
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute,
|
2010-11-16 13:06:08 +00:00
|
|
|
int start,
|
|
|
|
int end,
|
2011-01-20 12:29:49 +00:00
|
|
|
CoglVertexP3 *lines,
|
2010-11-16 13:06:08 +00:00
|
|
|
int *n_line_vertices)
|
|
|
|
{
|
|
|
|
int start_index = get_index (indices, indices_type, start);
|
|
|
|
int end_index = get_index (indices, indices_type, end);
|
|
|
|
float *v0 = (float *)((guint8 *)vertices + start_index * attribute->stride);
|
|
|
|
float *v1 = (float *)((guint8 *)vertices + end_index * attribute->stride);
|
|
|
|
float *o = (float *)(&lines[*n_line_vertices]);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < attribute->n_components; i++)
|
|
|
|
*(o++) = *(v0++);
|
|
|
|
for (;i < 3; i++)
|
|
|
|
*(o++) = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < attribute->n_components; i++)
|
|
|
|
*(o++) = *(v1++);
|
|
|
|
for (;i < 3; i++)
|
|
|
|
*(o++) = 0;
|
|
|
|
|
|
|
|
*n_line_vertices += 2;
|
|
|
|
}
|
|
|
|
|
2011-01-20 12:29:49 +00:00
|
|
|
static CoglVertexP3 *
|
2011-01-20 19:31:53 +00:00
|
|
|
get_wire_lines (CoglAttribute *attribute,
|
2010-11-16 13:06:08 +00:00
|
|
|
CoglVerticesMode mode,
|
|
|
|
int n_vertices_in,
|
|
|
|
int *n_vertices_out,
|
|
|
|
CoglIndices *_indices)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglVertexArray *vertex_array = cogl_attribute_get_array (attribute);
|
2010-11-16 13:06:08 +00:00
|
|
|
void *vertices;
|
|
|
|
CoglIndexArray *index_array;
|
|
|
|
void *indices;
|
|
|
|
CoglIndicesType indices_type;
|
|
|
|
int i;
|
|
|
|
int n_lines;
|
2011-02-15 12:31:12 +00:00
|
|
|
CoglVertexP3 *out = NULL;
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
vertices = cogl_buffer_map (COGL_BUFFER (vertex_array),
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
if (_indices)
|
|
|
|
{
|
|
|
|
index_array = cogl_indices_get_array (_indices);
|
|
|
|
indices = cogl_buffer_map (COGL_BUFFER (index_array),
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0);
|
|
|
|
indices_type = cogl_indices_get_type (_indices);
|
|
|
|
}
|
|
|
|
else
|
2011-02-15 12:31:12 +00:00
|
|
|
{
|
|
|
|
index_array = NULL;
|
|
|
|
indices = NULL;
|
|
|
|
indices_type = COGL_INDICES_TYPE_UNSIGNED_BYTE;
|
|
|
|
}
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
*n_vertices_out = 0;
|
|
|
|
|
|
|
|
if (mode == COGL_VERTICES_MODE_TRIANGLES &&
|
|
|
|
(n_vertices_in % 3) == 0)
|
|
|
|
{
|
|
|
|
n_lines = n_vertices_in;
|
2011-01-20 12:29:49 +00:00
|
|
|
out = g_new (CoglVertexP3, n_lines * 2);
|
2010-11-16 13:06:08 +00:00
|
|
|
for (i = 0; i < n_vertices_in; i += 3)
|
|
|
|
{
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i, i+1, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i+1, i+2, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i+2, i, out, n_vertices_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_FAN &&
|
|
|
|
n_vertices_in >= 3)
|
|
|
|
{
|
|
|
|
n_lines = 2 * n_vertices_in - 3;
|
2011-01-20 12:29:49 +00:00
|
|
|
out = g_new (CoglVertexP3, n_lines * 2);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
0, 1, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
1, 2, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
0, 2, out, n_vertices_out);
|
|
|
|
|
|
|
|
for (i = 3; i < n_vertices_in; i++)
|
|
|
|
{
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i - 1, i, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
0, i, out, n_vertices_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == COGL_VERTICES_MODE_TRIANGLE_STRIP &&
|
|
|
|
n_vertices_in >= 3)
|
|
|
|
{
|
|
|
|
n_lines = 2 * n_vertices_in - 3;
|
2011-01-20 12:29:49 +00:00
|
|
|
out = g_new (CoglVertexP3, n_lines * 2);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
0, 1, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
1, 2, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
0, 2, out, n_vertices_out);
|
|
|
|
|
|
|
|
for (i = 3; i < n_vertices_in; i++)
|
|
|
|
{
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i - 1, i, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i - 2, i, out, n_vertices_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* In the journal we are a bit sneaky and actually use GL_QUADS
|
|
|
|
* which isn't actually a valid CoglVerticesMode! */
|
|
|
|
#ifdef HAVE_COGL_GL
|
|
|
|
else if (mode == GL_QUADS && (n_vertices_in % 4) == 0)
|
|
|
|
{
|
|
|
|
n_lines = n_vertices_in;
|
2011-01-20 12:29:49 +00:00
|
|
|
out = g_new (CoglVertexP3, n_lines * 2);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_vertices_in; i += 4)
|
|
|
|
{
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i, i + 1, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i + 1, i + 2, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i + 2, i + 3, out, n_vertices_out);
|
|
|
|
add_line (vertices, indices, indices_type, attribute,
|
|
|
|
i + 3, i, out, n_vertices_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-15 12:31:12 +00:00
|
|
|
if (vertices != NULL)
|
2010-11-16 13:06:08 +00:00
|
|
|
cogl_buffer_unmap (COGL_BUFFER (vertex_array));
|
2011-02-15 12:31:12 +00:00
|
|
|
|
|
|
|
if (indices != NULL)
|
2010-11-16 13:06:08 +00:00
|
|
|
cogl_buffer_unmap (COGL_BUFFER (index_array));
|
2011-02-15 12:31:12 +00:00
|
|
|
|
2010-11-16 13:06:08 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_wireframe (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes,
|
2010-11-16 13:06:08 +00:00
|
|
|
CoglIndices *indices)
|
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *position = NULL;
|
2010-11-16 13:06:08 +00:00
|
|
|
int i;
|
|
|
|
int n_line_vertices;
|
|
|
|
static CoglPipeline *wire_pipeline;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *wire_attribute[2];
|
2011-01-20 12:29:49 +00:00
|
|
|
CoglVertexP3 *lines;
|
2010-11-16 13:06:08 +00:00
|
|
|
CoglVertexArray *array;
|
|
|
|
|
|
|
|
for (i = 0; attributes[i]; i++)
|
|
|
|
{
|
|
|
|
if (strcmp (attributes[i]->name, "cogl_position_in") == 0)
|
|
|
|
{
|
|
|
|
position = attributes[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!position)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lines = get_wire_lines (position,
|
|
|
|
mode,
|
|
|
|
n_vertices,
|
|
|
|
&n_line_vertices,
|
|
|
|
indices);
|
2011-01-20 12:29:49 +00:00
|
|
|
array = cogl_vertex_array_new (sizeof (CoglVertexP3) * n_line_vertices,
|
2010-11-16 13:06:08 +00:00
|
|
|
lines);
|
|
|
|
wire_attribute[0] =
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_attribute_new (array, "cogl_position_in",
|
|
|
|
sizeof (CoglVertexP3),
|
|
|
|
0,
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2010-11-16 13:06:08 +00:00
|
|
|
wire_attribute[1] = NULL;
|
|
|
|
cogl_object_unref (array);
|
|
|
|
|
|
|
|
if (!wire_pipeline)
|
|
|
|
{
|
|
|
|
wire_pipeline = cogl_pipeline_new ();
|
|
|
|
cogl_pipeline_set_color4ub (wire_pipeline,
|
|
|
|
0x00, 0xff, 0x00, 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_push_source (wire_pipeline);
|
|
|
|
|
|
|
|
/* temporarily disable the wireframe to avoid recursion! */
|
2011-01-24 14:28:00 +00:00
|
|
|
COGL_DEBUG_CLEAR_FLAG (COGL_DEBUG_WIREFRAME);
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_draw_attributes_array (COGL_VERTICES_MODE_LINES,
|
|
|
|
0,
|
|
|
|
n_line_vertices,
|
|
|
|
wire_attribute,
|
|
|
|
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
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
COGL_DEBUG_SET_FLAG (COGL_DEBUG_WIREFRAME);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
cogl_pop_source ();
|
|
|
|
|
|
|
|
cogl_object_unref (wire_attribute[0]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
static void
|
2010-12-14 14:24:17 +00:00
|
|
|
flush_state (CoglDrawFlags flags,
|
|
|
|
ValidateLayerState *state)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2010-12-14 14:24:17 +00:00
|
|
|
if (!(flags & COGL_DRAW_SKIP_JOURNAL_FLUSH))
|
2011-01-06 13:25:45 +00:00
|
|
|
{
|
2011-02-02 14:23:53 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_draw_buffer ();
|
2011-01-06 13:25:45 +00:00
|
|
|
_cogl_journal_flush (framebuffer->journal, framebuffer);
|
|
|
|
}
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
state->unit = 0;
|
|
|
|
state->options.flags = 0;
|
|
|
|
state->fallback_layers = 0;
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
if (!(flags & COGL_DRAW_SKIP_PIPELINE_VALIDATION))
|
|
|
|
cogl_pipeline_foreach_layer (cogl_get_source (),
|
|
|
|
validate_layer_cb,
|
|
|
|
state);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
/* NB: _cogl_framebuffer_flush_state may disrupt various state (such
|
|
|
|
* as the pipeline state) when flushing the clip stack, so should
|
|
|
|
* always be done first when preparing to draw. We need to do this
|
|
|
|
* before setting up the array pointers because setting up the clip
|
|
|
|
* stack can cause some drawing which would change the array
|
|
|
|
* pointers. */
|
|
|
|
if (!(flags & COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH))
|
2011-02-02 14:23:53 +00:00
|
|
|
_cogl_framebuffer_flush_state (_cogl_get_draw_buffer (),
|
|
|
|
_cogl_get_read_buffer (),
|
|
|
|
0);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
/* This can be called directly by the CoglJournal to draw attributes
|
|
|
|
* skipping the implicit journal flush, the framebuffer flush and
|
|
|
|
* pipeline validation. */
|
2010-10-12 11:53:10 +00:00
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_draw_attributes_array (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
CoglDrawFlags flags)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
ValidateLayerState state;
|
2010-12-14 14:24:17 +00:00
|
|
|
CoglPipeline *source;
|
|
|
|
|
|
|
|
flush_state (flags, &state);
|
|
|
|
|
2010-12-14 14:44:45 +00:00
|
|
|
source = enable_gl_state (flags, attributes, &state);
|
2010-12-14 14:24:17 +00:00
|
|
|
|
|
|
|
GE (glDrawArrays ((GLenum)mode, first_vertex, n_vertices));
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
/* FIXME: we shouldn't be disabling state after drawing we should
|
|
|
|
* just disable the things not needed after enabling state. */
|
|
|
|
disable_gl_state (attributes, source);
|
2010-10-12 11:53:10 +00:00
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_WIREFRAME)))
|
2010-12-14 14:24:17 +00:00
|
|
|
draw_wireframe (mode, first_vertex, n_vertices, attributes, NULL);
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_attributes_array (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_draw_attributes_array (mode, first_vertex,
|
|
|
|
n_vertices, attributes,
|
|
|
|
0 /* no flags */);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_attributes (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
...)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int n_attributes;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute;
|
|
|
|
CoglAttribute **attributes;
|
2010-10-12 11:53:10 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start (ap, n_vertices);
|
2011-01-20 19:31:53 +00:00
|
|
|
for (n_attributes = 0; va_arg (ap, CoglAttribute *); n_attributes++)
|
2010-10-12 11:53:10 +00:00
|
|
|
;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * (n_attributes + 1));
|
2010-10-12 11:53:10 +00:00
|
|
|
attributes[n_attributes] = NULL;
|
|
|
|
|
|
|
|
va_start (ap, n_vertices);
|
2011-01-20 19:31:53 +00:00
|
|
|
for (i = 0; (attribute = va_arg (ap, CoglAttribute *)); i++)
|
2010-10-12 11:53:10 +00:00
|
|
|
attributes[i] = attribute;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_attributes_array (mode, first_vertex, n_vertices,
|
|
|
|
attributes);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
sizeof_index_type (CoglIndicesType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
|
|
|
|
return 1;
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
|
|
|
|
return 2;
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_INT:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
g_return_val_if_reached (0);
|
|
|
|
}
|
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
CoglDrawFlags flags)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2010-12-14 14:24:17 +00:00
|
|
|
ValidateLayerState state;
|
|
|
|
CoglPipeline *source;
|
2010-10-12 11:53:10 +00:00
|
|
|
CoglBuffer *buffer;
|
2011-02-15 12:43:26 +00:00
|
|
|
guint8 *base;
|
2010-10-12 11:53:10 +00:00
|
|
|
size_t array_offset;
|
|
|
|
size_t index_size;
|
2010-11-06 18:12:41 +00:00
|
|
|
GLenum indices_gl_type = 0;
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-12-14 14:24:17 +00:00
|
|
|
flush_state (flags, &state);
|
|
|
|
|
2010-12-14 14:44:45 +00:00
|
|
|
source = enable_gl_state (flags, attributes, &state);
|
2010-12-14 14:24:17 +00:00
|
|
|
|
2010-11-16 08:41:29 +00:00
|
|
|
buffer = COGL_BUFFER (cogl_indices_get_array (indices));
|
2010-10-12 11:53:10 +00:00
|
|
|
base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_ARRAY);
|
|
|
|
array_offset = cogl_indices_get_offset (indices);
|
|
|
|
index_size = sizeof_index_type (cogl_indices_get_type (indices));
|
|
|
|
|
|
|
|
switch (cogl_indices_get_type (indices))
|
|
|
|
{
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_BYTE:
|
|
|
|
indices_gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_SHORT:
|
|
|
|
indices_gl_type = GL_UNSIGNED_SHORT;
|
|
|
|
break;
|
|
|
|
case COGL_INDICES_TYPE_UNSIGNED_INT:
|
|
|
|
indices_gl_type = GL_UNSIGNED_INT;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-06 18:12:41 +00:00
|
|
|
|
2010-10-12 11:53:10 +00:00
|
|
|
GE (glDrawElements ((GLenum)mode,
|
|
|
|
n_vertices,
|
|
|
|
indices_gl_type,
|
|
|
|
base + array_offset + index_size * first_vertex));
|
|
|
|
|
|
|
|
_cogl_buffer_unbind (buffer);
|
|
|
|
|
|
|
|
/* FIXME: we shouldn't be disabling state after drawing we should
|
|
|
|
* just disable the things not needed after enabling state. */
|
|
|
|
disable_gl_state (attributes, source);
|
2010-11-16 13:06:08 +00:00
|
|
|
|
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2011-01-24 14:28:00 +00:00
|
|
|
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_WIREFRAME)))
|
2010-11-16 13:06:08 +00:00
|
|
|
draw_wireframe (mode, first_vertex, n_vertices, attributes, indices);
|
|
|
|
#endif
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
CoglAttribute **attributes)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
_cogl_draw_indexed_attributes_array (mode, first_vertex,
|
|
|
|
n_vertices, indices, attributes,
|
|
|
|
0 /* no flags */);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_indexed_attributes (CoglVerticesMode mode,
|
|
|
|
int first_vertex,
|
|
|
|
int n_vertices,
|
|
|
|
CoglIndices *indices,
|
|
|
|
...)
|
2010-10-12 11:53:10 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int n_attributes;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes;
|
2010-10-12 11:53:10 +00:00
|
|
|
int i;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute;
|
2010-10-12 11:53:10 +00:00
|
|
|
|
|
|
|
va_start (ap, indices);
|
2011-01-20 19:31:53 +00:00
|
|
|
for (n_attributes = 0; va_arg (ap, CoglAttribute *); n_attributes++)
|
2010-10-12 11:53:10 +00:00
|
|
|
;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * (n_attributes + 1));
|
2010-10-12 11:53:10 +00:00
|
|
|
attributes[n_attributes] = NULL;
|
|
|
|
|
|
|
|
va_start (ap, indices);
|
2011-01-20 19:31:53 +00:00
|
|
|
for (i = 0; (attribute = va_arg (ap, CoglAttribute *)); i++)
|
2010-10-12 11:53:10 +00:00
|
|
|
attributes[i] = attribute;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-01-20 19:31:53 +00:00
|
|
|
cogl_draw_indexed_attributes_array (mode,
|
|
|
|
first_vertex,
|
|
|
|
n_vertices,
|
|
|
|
indices,
|
|
|
|
attributes);
|
2010-10-12 11:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|