2010-10-12 11:54:07 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-10-12 11:54:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-10-12 11:54:07 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
#include "cogl-util.h"
|
2010-10-12 11:54:07 +00:00
|
|
|
#include "cogl-object-private.h"
|
|
|
|
#include "cogl-primitive.h"
|
|
|
|
#include "cogl-primitive-private.h"
|
2011-01-20 19:31:53 +00:00
|
|
|
#include "cogl-attribute-private.h"
|
2013-07-09 22:47:29 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2013-09-02 15:02:42 +00:00
|
|
|
#include "cogl-gtype-private.h"
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-09-20 00:24:16 +00:00
|
|
|
#include <string.h>
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
static void _cogl_primitive_free (CoglPrimitive *primitive);
|
|
|
|
|
|
|
|
COGL_OBJECT_DEFINE (Primitive, primitive);
|
2013-09-02 15:02:42 +00:00
|
|
|
COGL_GTYPE_DEFINE_CLASS (Primitive, primitive);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
CoglPrimitive *
|
2011-03-03 01:02:12 +00:00
|
|
|
cogl_primitive_new_with_attributes (CoglVerticesMode mode,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
2011-09-20 00:24:16 +00:00
|
|
|
CoglPrimitive *primitive;
|
2010-10-12 11:54:07 +00:00
|
|
|
int i;
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
primitive = g_slice_alloc (sizeof (CoglPrimitive) +
|
|
|
|
sizeof (CoglAttribute *) * (n_attributes - 1));
|
2010-10-12 11:54:07 +00:00
|
|
|
primitive->mode = mode;
|
|
|
|
primitive->first_vertex = 0;
|
|
|
|
primitive->n_vertices = n_vertices;
|
|
|
|
primitive->indices = NULL;
|
2010-10-26 17:57:33 +00:00
|
|
|
primitive->immutable_ref = 0;
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
primitive->n_attributes = n_attributes;
|
|
|
|
primitive->n_embedded_attributes = n_attributes;
|
|
|
|
primitive->attributes = &primitive->embedded_attribute;
|
2011-03-03 01:02:12 +00:00
|
|
|
for (i = 0; i < n_attributes; i++)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute = attributes[i];
|
2010-10-12 11:54:07 +00:00
|
|
|
cogl_object_ref (attribute);
|
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (cogl_is_attribute (attribute), NULL);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
primitive->attributes[i] = attribute;
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _cogl_primitive_object_new (primitive);
|
|
|
|
}
|
|
|
|
|
2010-11-04 16:13:01 +00:00
|
|
|
/* This is just an internal convenience wrapper around
|
|
|
|
new_with_attributes that also unrefs the attributes. It is just
|
|
|
|
used for the builtin struct constructors */
|
|
|
|
static CoglPrimitive *
|
2011-03-03 01:02:12 +00:00
|
|
|
_cogl_primitive_new_with_attributes_unref (CoglVerticesMode mode,
|
|
|
|
int n_vertices,
|
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes)
|
2010-11-04 16:13:01 +00:00
|
|
|
{
|
|
|
|
CoglPrimitive *primitive;
|
|
|
|
int i;
|
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
primitive = cogl_primitive_new_with_attributes (mode,
|
|
|
|
n_vertices,
|
|
|
|
attributes,
|
|
|
|
n_attributes);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-05-16 15:34:48 +00:00
|
|
|
for (i = 0; i < n_attributes; i++)
|
2010-11-04 16:13:01 +00:00
|
|
|
cogl_object_unref (attributes[i]);
|
|
|
|
|
|
|
|
return primitive;
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
CoglPrimitive *
|
|
|
|
cogl_primitive_new (CoglVerticesMode mode,
|
|
|
|
int n_vertices,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int n_attributes;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute **attributes;
|
2010-10-12 11:54:07 +00:00
|
|
|
int i;
|
2011-01-20 19:31:53 +00:00
|
|
|
CoglAttribute *attribute;
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
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:54:07 +00:00
|
|
|
;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-05-16 15:34:48 +00:00
|
|
|
attributes = g_alloca (sizeof (CoglAttribute *) * n_attributes);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
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:54:07 +00:00
|
|
|
attributes[i] = attribute;
|
|
|
|
va_end (ap);
|
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return cogl_primitive_new_with_attributes (mode, n_vertices,
|
|
|
|
attributes,
|
2011-05-16 15:34:48 +00:00
|
|
|
i);
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-04 16:42:11 +00:00
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p2 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
2010-11-04 16:42:11 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP2 *data)
|
2010-11-04 16:42:11 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[1];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP2),
|
|
|
|
offsetof (CoglVertexP2, x),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2010-11-04 16:42:11 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:42:11 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
1);
|
2010-11-04 16:42:11 +00:00
|
|
|
}
|
|
|
|
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p3 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP3 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[1];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP3),
|
|
|
|
offsetof (CoglVertexP3, x),
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
1);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p2c4 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP2C4 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2C4), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[2];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP2C4),
|
|
|
|
offsetof (CoglVertexP2C4, x),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
sizeof (CoglVertexP2C4),
|
|
|
|
offsetof (CoglVertexP2C4, r),
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
2);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p3c4 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP3C4 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3C4), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[2];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP3C4),
|
|
|
|
offsetof (CoglVertexP3C4, x),
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
sizeof (CoglVertexP3C4),
|
|
|
|
offsetof (CoglVertexP3C4, r),
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
2);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p2t2 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP2T2 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP2T2), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[2];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP2T2),
|
|
|
|
offsetof (CoglVertexP2T2, x),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
sizeof (CoglVertexP2T2),
|
|
|
|
offsetof (CoglVertexP2T2, s),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
2);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p3t2 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP3T2 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3T2), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[2];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP3T2),
|
|
|
|
offsetof (CoglVertexP3T2, x),
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
sizeof (CoglVertexP3T2),
|
|
|
|
offsetof (CoglVertexP3T2, s),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
2);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p2t2c4 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP2T2C4 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx,
|
|
|
|
n_vertices * sizeof (CoglVertexP2T2C4), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[3];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP2T2C4),
|
|
|
|
offsetof (CoglVertexP2T2C4, x),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
sizeof (CoglVertexP2T2C4),
|
|
|
|
offsetof (CoglVertexP2T2C4, s),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[2] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
sizeof (CoglVertexP2T2C4),
|
|
|
|
offsetof (CoglVertexP2T2C4, r),
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
3);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPrimitive *
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_primitive_new_p3t2c4 (CoglContext *ctx,
|
|
|
|
CoglVerticesMode mode,
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
int n_vertices,
|
2011-01-20 12:29:49 +00:00
|
|
|
const CoglVertexP3T2C4 *data)
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
{
|
2011-03-02 15:01:41 +00:00
|
|
|
CoglAttributeBuffer *attribute_buffer =
|
2012-02-06 17:08:58 +00:00
|
|
|
cogl_attribute_buffer_new (ctx,
|
|
|
|
n_vertices * sizeof (CoglVertexP3T2C4), data);
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute *attributes[3];
|
2011-01-20 19:31:53 +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",
|
|
|
|
sizeof (CoglVertexP3T2C4),
|
|
|
|
offsetof (CoglVertexP3T2C4, x),
|
|
|
|
3,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[1] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_tex_coord0_in",
|
|
|
|
sizeof (CoglVertexP3T2C4),
|
|
|
|
offsetof (CoglVertexP3T2C4, s),
|
|
|
|
2,
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT);
|
2011-03-02 15:01:41 +00:00
|
|
|
attributes[2] = cogl_attribute_new (attribute_buffer,
|
2011-01-20 19:31:53 +00:00
|
|
|
"cogl_color_in",
|
|
|
|
sizeof (CoglVertexP3T2C4),
|
|
|
|
offsetof (CoglVertexP3T2C4, r),
|
|
|
|
4,
|
|
|
|
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-02 15:01:41 +00:00
|
|
|
cogl_object_unref (attribute_buffer);
|
2010-11-04 16:13:01 +00:00
|
|
|
|
2011-03-03 01:02:12 +00:00
|
|
|
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
|
|
|
|
attributes,
|
|
|
|
3);
|
primitive: Adds convenience constructors
This adds convenience primitive constructors named like:
cogl_primitive_new_p3 or
cogl_primitive_new_p3c4 or
cogl_primitive_new_p3t2c4
where the letters correspond to the interleved vertex attributes layouts
such as CoglP3Vertex which is a struct with 3 float x,y,z members for
the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z
members for the [p]osition, 2 float s,t members for the [t]exture
coordinates and 4 unsigned byte r,g,b,a members for the [c]olor.
The hope is that people will find these convenient enough to replace
cogl_polygon.
2010-10-12 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
static void
|
2011-09-20 00:24:16 +00:00
|
|
|
_cogl_primitive_free (CoglPrimitive *primitive)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
for (i = 0; i < primitive->n_attributes; i++)
|
|
|
|
cogl_object_unref (primitive->attributes[i]);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
if (primitive->attributes != &primitive->embedded_attribute)
|
|
|
|
g_slice_free1 (sizeof (CoglAttribute *) * primitive->n_attributes,
|
|
|
|
primitive->attributes);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2012-08-07 14:25:21 +00:00
|
|
|
if (primitive->indices)
|
|
|
|
cogl_object_unref (primitive->indices);
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
g_slice_free1 (sizeof (CoglPrimitive) +
|
|
|
|
sizeof (CoglAttribute *) *
|
|
|
|
(primitive->n_embedded_attributes - 1), primitive);
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 17:57:33 +00:00
|
|
|
static void
|
|
|
|
warn_about_midscene_changes (void)
|
|
|
|
{
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean seen = FALSE;
|
2010-10-26 17:57:33 +00:00
|
|
|
if (!seen)
|
|
|
|
{
|
2011-09-20 00:24:16 +00:00
|
|
|
g_warning ("Mid-scene modification of primitives has "
|
2010-10-26 17:57:33 +00:00
|
|
|
"undefined results\n");
|
|
|
|
seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
void
|
|
|
|
cogl_primitive_set_attributes (CoglPrimitive *primitive,
|
2011-03-03 01:02:12 +00:00
|
|
|
CoglAttribute **attributes,
|
|
|
|
int n_attributes)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
2010-10-26 17:57:33 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (primitive->immutable_ref))
|
|
|
|
{
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
/* NB: we don't unref the previous attributes before refing the new
|
|
|
|
* in case we would end up releasing the last reference for an
|
2020-08-26 09:49:50 +00:00
|
|
|
* attribute that's actually in the new list too. */
|
2011-03-03 01:02:12 +00:00
|
|
|
for (i = 0; i < n_attributes; i++)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_attribute (attributes[i]));
|
2011-09-20 00:24:16 +00:00
|
|
|
cogl_object_ref (attributes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < primitive->n_attributes; i++)
|
|
|
|
cogl_object_unref (primitive->attributes[i]);
|
|
|
|
|
2020-08-26 09:49:50 +00:00
|
|
|
/* First try to use the embedded storage associated with the
|
2011-09-20 00:24:16 +00:00
|
|
|
* primitive, else fallback to slice allocating separate storage for
|
|
|
|
* the attribute pointers... */
|
|
|
|
|
|
|
|
if (n_attributes <= primitive->n_embedded_attributes)
|
|
|
|
{
|
|
|
|
if (primitive->attributes != &primitive->embedded_attribute)
|
|
|
|
g_slice_free1 (sizeof (CoglAttribute *) * primitive->n_attributes,
|
|
|
|
primitive->attributes);
|
|
|
|
primitive->attributes = &primitive->embedded_attribute;
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
2011-09-20 00:24:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (primitive->attributes != &primitive->embedded_attribute)
|
|
|
|
g_slice_free1 (sizeof (CoglAttribute *) * primitive->n_attributes,
|
|
|
|
primitive->attributes);
|
|
|
|
primitive->attributes =
|
|
|
|
g_slice_alloc (sizeof (CoglAttribute *) * n_attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (primitive->attributes, attributes,
|
|
|
|
sizeof (CoglAttribute *) * n_attributes);
|
|
|
|
|
|
|
|
primitive->n_attributes = n_attributes;
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cogl_primitive_get_first_vertex (CoglPrimitive *primitive)
|
|
|
|
{
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (cogl_is_primitive (primitive), 0);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
return primitive->first_vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_primitive_set_first_vertex (CoglPrimitive *primitive,
|
|
|
|
int first_vertex)
|
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2010-10-26 17:57:33 +00:00
|
|
|
if (G_UNLIKELY (primitive->immutable_ref))
|
|
|
|
{
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
primitive->first_vertex = first_vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cogl_primitive_get_n_vertices (CoglPrimitive *primitive)
|
|
|
|
{
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (cogl_is_primitive (primitive), 0);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
return primitive->n_vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_primitive_set_n_vertices (CoglPrimitive *primitive,
|
|
|
|
int n_vertices)
|
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
primitive->n_vertices = n_vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglVerticesMode
|
|
|
|
cogl_primitive_get_mode (CoglPrimitive *primitive)
|
|
|
|
{
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (cogl_is_primitive (primitive), 0);
|
2010-10-12 11:54:07 +00:00
|
|
|
|
|
|
|
return primitive->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_primitive_set_mode (CoglPrimitive *primitive,
|
|
|
|
CoglVerticesMode mode)
|
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2010-10-26 17:57:33 +00:00
|
|
|
if (G_UNLIKELY (primitive->immutable_ref))
|
|
|
|
{
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
primitive->mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_primitive_set_indices (CoglPrimitive *primitive,
|
2011-10-25 21:34:59 +00:00
|
|
|
CoglIndices *indices,
|
|
|
|
int n_indices)
|
2010-10-12 11:54:07 +00:00
|
|
|
{
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
2010-10-12 11:54:07 +00:00
|
|
|
|
2010-10-26 17:57:33 +00:00
|
|
|
if (G_UNLIKELY (primitive->immutable_ref))
|
|
|
|
{
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-12 11:54:07 +00:00
|
|
|
if (indices)
|
|
|
|
cogl_object_ref (indices);
|
|
|
|
if (primitive->indices)
|
|
|
|
cogl_object_unref (primitive->indices);
|
|
|
|
primitive->indices = indices;
|
2011-10-25 21:34:59 +00:00
|
|
|
primitive->n_vertices = n_indices;
|
2010-10-12 11:54:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 14:01:24 +00:00
|
|
|
CoglIndices *
|
|
|
|
cogl_primitive_get_indices (CoglPrimitive *primitive)
|
|
|
|
{
|
|
|
|
return primitive->indices;
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:52:18 +00:00
|
|
|
CoglPrimitive *
|
|
|
|
cogl_primitive_copy (CoglPrimitive *primitive)
|
|
|
|
{
|
|
|
|
CoglPrimitive *copy;
|
|
|
|
|
|
|
|
copy = cogl_primitive_new_with_attributes (primitive->mode,
|
|
|
|
primitive->n_vertices,
|
|
|
|
primitive->attributes,
|
|
|
|
primitive->n_attributes);
|
|
|
|
|
|
|
|
cogl_primitive_set_indices (copy, primitive->indices, primitive->n_vertices);
|
|
|
|
cogl_primitive_set_first_vertex (copy, primitive->first_vertex);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2010-10-26 17:57:33 +00:00
|
|
|
CoglPrimitive *
|
|
|
|
_cogl_primitive_immutable_ref (CoglPrimitive *primitive)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (cogl_is_primitive (primitive), NULL);
|
2010-10-26 17:57:33 +00:00
|
|
|
|
|
|
|
primitive->immutable_ref++;
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
for (i = 0; i < primitive->n_attributes; i++)
|
|
|
|
_cogl_attribute_immutable_ref (primitive->attributes[i]);
|
2010-10-26 17:57:33 +00:00
|
|
|
|
|
|
|
return primitive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_primitive_immutable_unref (CoglPrimitive *primitive)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-06-17 21:40:06 +00:00
|
|
|
g_return_if_fail (cogl_is_primitive (primitive));
|
|
|
|
g_return_if_fail (primitive->immutable_ref > 0);
|
2010-10-26 17:57:33 +00:00
|
|
|
|
|
|
|
primitive->immutable_ref--;
|
|
|
|
|
2011-09-20 00:24:16 +00:00
|
|
|
for (i = 0; i < primitive->n_attributes; i++)
|
|
|
|
_cogl_attribute_immutable_unref (primitive->attributes[i]);
|
2010-10-26 17:57:33 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 13:29:35 +00:00
|
|
|
void
|
|
|
|
cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
|
|
|
|
CoglPrimitiveAttributeCallback callback,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < primitive->n_attributes; i++)
|
|
|
|
if (!callback (primitive, primitive->attributes[i], user_data))
|
|
|
|
break;
|
|
|
|
}
|
2013-07-09 22:47:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_primitive_draw (CoglPrimitive *primitive,
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglDrawFlags flags)
|
|
|
|
{
|
|
|
|
if (primitive->indices)
|
|
|
|
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
primitive->mode,
|
|
|
|
primitive->first_vertex,
|
|
|
|
primitive->n_vertices,
|
|
|
|
primitive->indices,
|
|
|
|
primitive->attributes,
|
|
|
|
primitive->n_attributes,
|
|
|
|
flags);
|
|
|
|
else
|
|
|
|
_cogl_framebuffer_draw_attributes (framebuffer,
|
|
|
|
pipeline,
|
|
|
|
primitive->mode,
|
|
|
|
primitive->first_vertex,
|
|
|
|
primitive->n_vertices,
|
|
|
|
primitive->attributes,
|
|
|
|
primitive->n_attributes,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_primitive_draw (CoglPrimitive *primitive,
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
CoglPipeline *pipeline)
|
|
|
|
{
|
|
|
|
_cogl_primitive_draw (primitive, framebuffer, pipeline, 0 /* flags */);
|
|
|
|
}
|