Renames the mesh api to the "vertex buffer api".

This better reflects the fact that the api manages sets of vertex attributes,
and the attributes really have no implied form. It is only when you use the
attributes to draw that they become mesh like; when you specify how they should
be interpreted, e.g. as triangle lists or fans etc. This rename frees up the
term "mesh", which can later be applied to a concept slightly more fitting.
E.g. at some point it would be nice to have a higher level abstraction that
sits on top of cogl vertex buffers that adds the concept of faces. (Somthing
like Blender's mesh objects.) There have also been some discussions over
particle engines, and these can be defined in terms of emitter faces; so some
other kind of mesh abstraction might be usefull here.
This commit is contained in:
Robert Bragg 2009-01-20 21:12:44 +00:00
parent 4bc1e567fc
commit e338245827
19 changed files with 845 additions and 822 deletions

View File

@ -1,9 +1,13 @@
/* cogl-mesh.h: Handle extensible arrays of vertex attributes /*
* This file is part of Clutter * Cogl.
*
* An OpenGL/GLES Abstraction/Utility Layer
*
* Vertex Buffer API: Handle extensible arrays of vertex attributes
* *
* Copyright (C) 2008 Intel Corporation. * Copyright (C) 2008 Intel Corporation.
* *
* Authored by: Robert Bragg <bob@o-hand.com> * Authored by: Robert Bragg <robert@linux.intel.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -23,8 +27,8 @@
#error "Only <cogl/cogl.h> can be included directly." #error "Only <cogl/cogl.h> can be included directly."
#endif #endif
#ifndef __COGL_MESH_H__ #ifndef __COGL_VERTEX_BUFFER_H__
#define __COGL_MESH_H__ #define __COGL_VERTEX_BUFFER_H__
#include <glib.h> #include <glib.h>
#include <cogl/cogl-types.h> #include <cogl/cogl-types.h>
@ -32,42 +36,42 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-mesh * SECTION:cogl-vertex-buffer
* @short_description: An API for submitting extensible arrays of vertex * @short_description: An API for submitting extensible arrays of vertex
* attributes to OpenGL in a way that aims to minimise * attributes to OpenGL in a way that aims to minimise
* copying or reformatting of the original data. * copying or reformatting of the original data.
* *
* The Mesh API is designed to be a fairly raw mechanism for developers * The Attributes Buffer API is designed to be a fairly raw mechanism for
* to be able to submit geometry to Cogl in a format that can be directly * developers to be able to submit geometry to Cogl in a format that can be
* consumed by an OpenGL driver and with awareness of the specific hardware * directly consumed by an OpenGL driver and with awareness of the specific
* being used then costly format conversion can also be avoided. * hardware being used then costly format conversion can also be avoided.
* *
* They are designed to work on top of buffer objects and developers should * They are designed to work on top of buffer objects and developers should
* understand that mesh objects are not cheap to create but once they * understand that attribute buffers are not that cheap to create but once they
* have been submitted they are stored in GPU addressable memory and can * have been submitted they can be stored in GPU addressable memory and can
* be quickly reused. * be quickly reused.
* *
* Although this API does allow you to modify mesh objects after they have * Although this API does allow you to modify attribute buffers after they have
* been submitted to the GPU you must note that modification is still * been submitted to the GPU you must note that modification is also not that
* not cheap, so if at all possible think of tricks that let you reuse * cheap, so if at all possible think of tricks that let you reuse a static
* a static buffer. To help with this, it is possible to enable and disable * buffer. To help with this, it is possible to enable and disable individual
* individual attributes cheaply. * attributes cheaply.
* *
* Take for example a mesh representing an elipse. If you were to submit * Take for example attributes representing an elipse. If you were to submit
* a mesh with color attributes, texture coordinates and normals, then * color attributes, texture coordinates and normals, then you would be able
* you would be able to draw an elipses in the following different ways * to draw an elipses in the following different ways without modifying
* without creating a new mesh: * the vertex buffer, only by changing your source material.
* <itemizedlist> * <itemizedlist>
* <listitem>Flat colored elipse</listitem> * <listitem>Flat colored elipse</listitem>
* <listitem>Textured elipse</listitem> * <listitem>Textured elipse</listitem>
* <listitem>Smoothly lit textured elipse blended with the color.</listitem> * <listitem>Smoothly lit textured elipse blended with the color.</listitem>
* </itemizedlist> * </itemizedlist>
*
* Another trick that can be used is submitting a highly detailed mesh
* and then using cogl_mesh_draw_range_elements to sample lower resolution
* geometry out from a fixed mesh.
* *
* The API doesn't currently give you any control over the actual buffer * Another trick that can be used is submitting highly detailed vertices and
* then using cogl_vertex_buffer_draw_range_elements to sample sub-sets of
* the geometry or lower resolution geometry out from a fixed buffer.
*
* The API doesn't currently give you any control over the actual OpenGL buffer
* objects that are created, but you can expect that when you first submit * objects that are created, but you can expect that when you first submit
* your attributes they start off in one or more GL_STATIC_DRAW buffers. * your attributes they start off in one or more GL_STATIC_DRAW buffers.
* If you then update some of your attributes; then these attributes will * If you then update some of your attributes; then these attributes will
@ -75,18 +79,18 @@ G_BEGIN_DECLS
*/ */
/** /**
* cogl_mesh_new: * cogl_vertex_buffer_new:
* @n_vertices: The number of vertices that will make up your mesh. * @n_vertices: The number of vertices that your attributes will correspond to.
* *
* This creates a Cogl handle for a new mesh that you can then start to add * This creates a Cogl handle for a new vertex buffer that you can then start
* attributes too. * to add attributes too.
*/ */
CoglHandle CoglHandle
cogl_mesh_new (guint n_vertices); cogl_vertex_buffer_new (guint n_vertices);
/** /**
* cogl_mesh_add_attribute: * cogl_vertex_buffer_add:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of your attribute. It should be a valid GLSL * @attribute_name: The name of your attribute. It should be a valid GLSL
* variable name and standard attribute types must use one * variable name and standard attribute types must use one
* of following built-in names: (Note: they correspond to the * of following built-in names: (Note: they correspond to the
@ -115,90 +119,106 @@ cogl_mesh_new (guint n_vertices);
* stride for both attributes is 6. The special value 0 means the * stride for both attributes is 6. The special value 0 means the
* values are stored sequentially in memory. * values are stored sequentially in memory.
* @pointer: This addresses the first attribute in the vertex array. (This * @pointer: This addresses the first attribute in the vertex array. (This
* must remain valid until you call cogl_mesh_submit) * must remain valid until you call cogl_vertex_buffer_submit)
* *
* This function lets you add an attribute to a mesh. You either use one * This function lets you add an attribute to a buffer. You either use one
* of the built-in names to add standard attributes, like positions, colors * of the built-in names to add standard attributes, like positions, colors
* and normals or you can add custom attributes for use in shaders. * and normals or you can add custom attributes for use in shaders.
* *
* Note: The number of vertices declared when creating the mesh is used to * Note: The number of vertices declared when first creating the vertex
* determine how many attribute values will be read from the supplied pointer. * buffer is used to determine how many attribute values will be read from the
* supplied pointer.
* *
* Note: the data supplied here isn't copied anywhere until you call * Note: the data supplied here isn't copied anywhere until you call
* cogl_mesh_submit, so the supplied pointer must remain valid until then. * cogl_vertex_buffer_submit, so the supplied pointer must remain valid
* (This is an important optimisation since we can't create a buffer * until then.
* object until we know about all the attributes, and repeatedly copying * (This is an important optimisation since we can't create the underlying
* large buffers of vertex data may be very costly) If you add attributes * OpenGL buffer object until we know about all the attributes, and repeatedly
* after submitting then you will need to re-call cogl_mesh_submit to * copying large buffers of vertex data may be very costly) If you add
* commit the changes to the GPU. (Be carefull to minimize the number of * attributes after submitting then you will need to re-call
* calls to cogl_mesh_submit though) * cogl_vertex_buffer_submit to commit the changes to the GPU. (Be carefull
* to minimize the number of calls to cogl_vertex_buffer_submit though)
* *
* Note: If you are interleving attributes it is assumed that that each * Note: If you are interleving attributes it is assumed that that each
* interleaved attribute starts no farther than +- stride bytes from * interleaved attribute starts no farther than +- stride bytes from the other
* the other attributes it is interleved with. I.e. this is ok: * attributes it is interleved with. I.e. this is ok:
* |-0-0-0-0-0-0-0-0-0-0| * |-0-0-0-0-0-0-0-0-0-0|
* This is not ok: * This is not ok:
* |- - - - -0-0-0-0-0-0 0 0 0 0| * |- - - - -0-0-0-0-0-0 0 0 0 0|
* (Though you can have multiple groups of interleved attributes) * (Though you can have multiple groups of interleved attributes)
*/ */
void void
cogl_mesh_add_attribute (CoglHandle handle, cogl_vertex_buffer_add (CoglHandle handle,
const char *attribute_name, const char *attribute_name,
guint8 n_components, guint8 n_components,
GLenum gl_type, GLenum gl_type,
gboolean normalized, gboolean normalized,
guint16 stride, guint16 stride,
const void *pointer); const void *pointer);
/** /**
* cogl_mesh_delete_attribute: * cogl_vertex_buffer_delete:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of a previously added attribute * @attribute_name: The name of a previously added attribute
* *
* This function deletes an attribute from a mesh. You will need to * This function deletes an attribute from a buffer. You will need to
* call cogl_mesh_submit to commit this change to the GPU. * call cogl_vertex_buffer_submit to commit this change to the GPU.
*/ */
void void
cogl_mesh_delete_attribute (CoglHandle handle, cogl_vertex_buffer_delete (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_enable_attribute: * cogl_vertex_buffer_enable:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @attribute_name: The name of the attribute you want to enable * @attribute_name: The name of the attribute you want to enable
* *
* This function enables a previosuly added attribute * This function enables a previosuly added attribute
* *
* Since it is costly to create new mesh objects, then to make individual mesh * Since it can be costly to add and remove new attributes to buffers; to make
* objects more reuseable it is possible to enable and disable attributes * individual buffers more reuseable it is possible to enable and disable
* before using a mesh for drawing. * attributes before using a buffer for drawing.
* *
* Note: You don't need to call cogl_mesh_submit after using this function * Note: You don't need to call cogl_vertex_buffer_submit after using this
* function
*/ */
void void
cogl_mesh_enable_attribute (CoglHandle handle, cogl_vertex_buffer_enable (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_disable_attribute: * cogl_vertex_buffer_submit:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
*
* This function copies all the user added attributes into buffer objects
* managed by the OpenGL driver.
*
* You should aim to minimize calls to this function.
*/
void
cogl_vertex_buffer_submit (CoglHandle handle);
/**
* cogl_vertex_buffer_disable:
* @handle: A vertex buffer handle
* @attribute_name: The name of the attribute you want to disable * @attribute_name: The name of the attribute you want to disable
* *
* This function disables a previosuly added attribute * This function disables a previosuly added attribute
* *
* Since it is costly to create new mesh objects, then to make individual mesh * Since it can be costly to add and remove new attributes to buffers; to make
* objects more reuseable it is possible to enable and disable attributes * individual buffers more reuseable it is possible to enable and disable
* before using a mesh for drawing. * attributes before using a buffer for drawing.
* *
* Note: You don't need to call cogl_mesh_submit after using this function * Note: You don't need to call cogl_vertex_buffer_submit after using this
* function
*/ */
void void
cogl_mesh_disable_attribute (CoglHandle handle, cogl_vertex_buffer_disable (CoglHandle handle,
const char *attribute_name); const char *attribute_name);
/** /**
* cogl_mesh_draw_arrays: * cogl_vertex_buffer_draw:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @mode: Specifies how the vertices should be interpreted, and should be * @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type: * a valid GL primitive type:
* <itemizedlist> * <itemizedlist>
@ -215,17 +235,17 @@ cogl_mesh_disable_attribute (CoglHandle handle,
* @count: Specifies the number of vertices you want to draw. * @count: Specifies the number of vertices you want to draw.
* *
* This function lets you draw geometry using all or a subset of the * This function lets you draw geometry using all or a subset of the
* vertices in a mesh object. * vertices in a vertex buffer.
*/ */
void void
cogl_mesh_draw_arrays (CoglHandle handle, cogl_vertex_buffer_draw (CoglHandle handle,
GLenum mode, GLenum mode,
GLint first, GLint first,
GLsizei count); GLsizei count);
/** /**
* cogl_mesh_draw_range_elements: * cogl_vertex_buffer_draw_range_elements:
* @handle: A Cogl mesh handle * @handle: A vertex buffer handle
* @mode: Specifies how the vertices should be interpreted, and should be * @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type: * a valid GL primitive type:
* <itemizedlist> * <itemizedlist>
@ -238,11 +258,11 @@ cogl_mesh_draw_arrays (CoglHandle handle,
* <listitem>GL_TRIANGLES</listitem> * <listitem>GL_TRIANGLES</listitem>
* </itemizedlist> * </itemizedlist>
* (Note: only types available in GLES are listed) * (Note: only types available in GLES are listed)
* @start: Specifies the minimum vertex index contained in indices * @min_index: Specifies the minimum vertex index contained in indices
* @end: Specifies the maximum vertex index contained in indices * @max_index: Specifies the maximum vertex index contained in indices
* @count: Specifies the number of vertices you want to draw. * @count: Specifies the number of vertices you want to draw.
* @type: Specifies the data type used for the indices, and must be * @indices_typetype: Specifies the data type used for the indices, and must be
* one of: * one of:
* <itemizedlist> * <itemizedlist>
* <listitem>GL_UNSIGNED_BYTE</listitem> * <listitem>GL_UNSIGNED_BYTE</listitem>
* <listitem>GL_UNSIGNED_SHORT</listitem> * <listitem>GL_UNSIGNED_SHORT</listitem>
@ -251,49 +271,38 @@ cogl_mesh_draw_arrays (CoglHandle handle,
* @indices: Specifies the address of your array of indices * @indices: Specifies the address of your array of indices
* *
* This function lets you use an array of indices to specify the vertices * This function lets you use an array of indices to specify the vertices
* within your mesh pbject that you want to draw. * within your vertex buffer that you want to draw.
*/ */
void void
cogl_mesh_draw_range_elements (CoglHandle handle, cogl_vertex_buffer_draw_range_elements (CoglHandle handle,
GLenum mode, GLenum mode,
GLuint start, GLuint min_index,
GLuint end, GLuint max_index,
GLsizei count, GLsizei count,
GLenum type, GLenum indices_type,
const GLvoid *indices); const GLvoid *indices);
/** /**
* cogl_mesh_submit: * cogl_vertex_buffer_ref:
* @handle: A Cogl mesh handle
*
* This function copies all the user added attributes into a buffer object
* managed by the OpenGL driver.
*
* After the attributes have been submitted, then you may no longer add or
* remove attributes from a mesh, though you can enable or disable them.
*/
void
cogl_mesh_submit (CoglHandle handle);
/**
* cogl_mesh_ref:
* @handle: a @CoglHandle. * @handle: a @CoglHandle.
* *
* Increment the reference count for a cogl mesh. * Increment the reference count for a vertex buffer
* *
* Returns: the @handle. * Returns: the @handle.
*/ */
CoglHandle cogl_mesh_ref (CoglHandle handle); CoglHandle
cogl_vertex_buffer_ref (CoglHandle handle);
/** /**
* cogl_mesh_unref: * cogl_vertex_buffer_unref:
* @handle: a @CoglHandle. * @handle: a @CoglHandle.
* *
* Deccrement the reference count for a cogl mesh. * Decrement the reference count for a vertex buffer
*/ */
void cogl_mesh_unref (CoglHandle handle); void
cogl_vertex_buffer_unref (CoglHandle handle);
G_END_DECLS G_END_DECLS
#endif /* __COGL_MESH_H__ */ #endif /* __COGL_VERTEX_BUFFER_H__ */

View File

@ -32,7 +32,7 @@
#include <cogl/cogl-defines-@CLUTTER_COGL@.h> #include <cogl/cogl-defines-@CLUTTER_COGL@.h>
#include <cogl/cogl-mesh.h> #include <cogl/cogl-vertex-buffer.h>
#include <cogl/cogl-fixed.h> #include <cogl/cogl-fixed.h>
#include <cogl/cogl-color.h> #include <cogl/cogl-color.h>
#include <cogl/cogl-offscreen.h> #include <cogl/cogl-offscreen.h>

View File

@ -30,4 +30,5 @@ libclutter_cogl_common_la_SOURCES = \
cogl-clip-stack.c \ cogl-clip-stack.c \
cogl-fixed.c \ cogl-fixed.c \
cogl-color.c \ cogl-color.c \
cogl-mesh.c cogl-vertex-buffer-private.h \
cogl-vertex-buffer.c

View File

@ -1,143 +0,0 @@
/*
* Clutter COGL
*
* A basic GL/GLES Abstraction/Utility Layer
*
* Authored By Robert Bragg <bob@o-hand.com>
*
* Copyright (C) 2008 Intel
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __COGL_MESH_H
#define __COGL_MESH_H
/* Note we put quite a bit into the flags here to help keep
* the down size of the CoglMeshAttribute struct below. */
typedef enum _CoglMeshAttributeFlags
{
/* Types */
/* NB: update the _TYPE_MASK below if these are changed */
COGL_MESH_ATTRIBUTE_FLAG_COLOR_ARRAY = 1<<0,
COGL_MESH_ATTRIBUTE_FLAG_NORMAL_ARRAY = 1<<1,
COGL_MESH_ATTRIBUTE_FLAG_TEXTURE_COORD_ARRAY = 1<<2,
COGL_MESH_ATTRIBUTE_FLAG_VERTEX_ARRAY = 1<<3,
COGL_MESH_ATTRIBUTE_FLAG_CUSTOM_ARRAY = 1<<4,
COGL_MESH_ATTRIBUTE_FLAG_INVALID = 1<<5,
COGL_MESH_ATTRIBUTE_FLAG_NORMALIZED = 1<<6,
COGL_MESH_ATTRIBUTE_FLAG_ENABLED = 1<<7,
/* Usage hints */
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_MESH_ATTRIBUTE_FLAG_INFREQUENT_RESUBMIT = 1<<8,
COGL_MESH_ATTRIBUTE_FLAG_FREQUENT_RESUBMIT = 1<<9,
/* GL Data types */
/* NB: Update the _GL_TYPE_MASK below if these are changed */
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_BYTE = 1<<10,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_BYTE = 1<<11,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_SHORT = 1<<12,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_SHORT = 1<<13,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_INT = 1<<14,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_INT = 1<<15,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_FLOAT = 1<<16,
COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_DOUBLE = 1<<17,
COGL_MESH_ATTRIBUTE_FLAG_SUBMITTED = 1<<18,
COGL_MESH_ATTRIBUTE_FLAG_UNUSED = 1<<19
/* XXX NB: If we need > 24 bits then look at changing the layout
* of struct _CoglMeshAttribute below */
} CoglMeshAttributeFlags;
#define COGL_MESH_ATTRIBUTE_FLAG_TYPE_MASK \
(COGL_MESH_ATTRIBUTE_FLAG_COLOR_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_NORMAL_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_TEXTURE_COORD_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_VERTEX_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_CUSTOM_ARRAY \
| COGL_MESH_ATTRIBUTE_FLAG_INVALID)
#define COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_MASK \
(COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_BYTE \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_BYTE \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_SHORT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_SHORT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_INT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_UNSIGNED_INT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_FLOAT \
| COGL_MESH_ATTRIBUTE_FLAG_GL_TYPE_DOUBLE)
typedef struct _CoglMeshAttribute
{
/* TODO: look at breaking up the flags into seperate
* bitfields and seperate enums */
CoglMeshAttributeFlags flags:24;
guint8 id;
GQuark name;
union _u
{
const void *pointer;
gsize vbo_offset;
} u;
gsize span_bytes;
guint16 stride;
guint8 n_components;
guint8 texture_unit;
} CoglMeshAttribute;
typedef enum _CoglMeshVBOFlags
{
COGL_MESH_VBO_FLAG_UNSTRIDED = 1<<0,
COGL_MESH_VBO_FLAG_STRIDED = 1<<1,
COGL_MESH_VBO_FLAG_MULTIPACK = 1<<2,
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_MESH_VBO_FLAG_INFREQUENT_RESUBMIT = 1<<3,
COGL_MESH_VBO_FLAG_FREQUENT_RESUBMIT = 1<<4,
COGL_MESH_VBO_FLAG_SUBMITTED = 1<<5
} CoglMeshVBOFlags;
/*
* A CoglMeshVBO represents one or more attributes in a single buffer object
*/
typedef struct _CoglMeshVBO
{
CoglMeshVBOFlags flags;
GLuint vbo_name; /*!< The name of the corresponding buffer object */
gsize vbo_bytes; /*!< The lengh of the allocated buffer object in bytes */
GList *attributes;
} CoglMeshVBO;
typedef struct _CoglMesh
{
guint ref_count;
guint n_vertices; /*!< The number of vertices in the mesh */
GList *submitted_vbos; /* The VBOs currently submitted to the GPU */
/* Note: new_attributes is normally NULL and only valid while
* modifying a mesh object. */
GList *new_attributes; /*!< attributes pending submission */
} CoglMesh;
#endif /* __COGL_MESH_H */

View File

@ -0,0 +1,142 @@
/*
* Cogl.
*
* An OpenGL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2008 Intel Corporation.
*
* Authored By: Robert Bragg <robert@linux.intel.com>
*
* 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/>.
*/
#ifndef __COGL_VERTEX_BUFFER_H
#define __COGL_VERTEX_BUFFER_H
/* Note we put quite a bit into the flags here to help keep
* the down size of the CoglVertexBufferAttrib struct below. */
typedef enum _CoglVertexBufferAttribFlags
{
/* Types */
/* NB: update the _TYPE_MASK below if these are changed */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY = 1<<0,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY = 1<<1,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_TEXTURE_COORD_ARRAY = 1<<2,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_VERTEX_ARRAY = 1<<3,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_CUSTOM_ARRAY = 1<<4,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_INVALID = 1<<5,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMALIZED = 1<<6,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_ENABLED = 1<<7,
/* Usage hints */
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_INFREQUENT_RESUBMIT = 1<<8,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_FREQUENT_RESUBMIT = 1<<9,
/* GL Data types */
/* NB: Update the _GL_TYPE_MASK below if these are changed */
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_BYTE = 1<<10,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_BYTE = 1<<11,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_SHORT = 1<<12,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_SHORT = 1<<13,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_INT = 1<<14,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_INT = 1<<15,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_FLOAT = 1<<16,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_DOUBLE = 1<<17,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_SUBMITTED = 1<<18,
COGL_VERTEX_BUFFER_ATTRIB_FLAG_UNUSED = 1<<19
/* XXX NB: If we need > 24 bits then look at changing the layout
* of struct _CoglVertexBufferAttrib below */
} CoglVertexBufferAttribFlags;
#define COGL_VERTEX_BUFFER_ATTRIB_FLAG_TYPE_MASK \
(COGL_VERTEX_BUFFER_ATTRIB_FLAG_COLOR_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_NORMAL_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_TEXTURE_COORD_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_VERTEX_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_CUSTOM_ARRAY \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_INVALID)
#define COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_MASK \
(COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_BYTE \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_BYTE \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_SHORT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_SHORT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_INT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_UNSIGNED_INT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_FLOAT \
| COGL_VERTEX_BUFFER_ATTRIB_FLAG_GL_TYPE_DOUBLE)
typedef struct _CoglVertexBufferAttrib
{
/* TODO: look at breaking up the flags into seperate
* bitfields and seperate enums */
CoglVertexBufferAttribFlags flags:24;
guint8 id;
GQuark name;
union _u
{
const void *pointer;
gsize vbo_offset;
} u;
gsize span_bytes;
guint16 stride;
guint8 n_components;
guint8 texture_unit;
} CoglVertexBufferAttrib;
typedef enum _CoglVertexBufferVBOFlags
{
COGL_VERTEX_BUFFER_VBO_FLAG_UNSTRIDED = 1<<0,
COGL_VERTEX_BUFFER_VBO_FLAG_STRIDED = 1<<1,
COGL_VERTEX_BUFFER_VBO_FLAG_MULTIPACK = 1<<2,
/* FIXME - flatten into one flag, since its used as a boolean */
COGL_VERTEX_BUFFER_VBO_FLAG_INFREQUENT_RESUBMIT = 1<<3,
COGL_VERTEX_BUFFER_VBO_FLAG_FREQUENT_RESUBMIT = 1<<4,
COGL_VERTEX_BUFFER_VBO_FLAG_SUBMITTED = 1<<5
} CoglVertexBufferVBOFlags;
/*
* A CoglVertexBufferVBO represents one or more attributes in a single
* buffer object
*/
typedef struct _CoglVertexBufferVBO
{
CoglVertexBufferVBOFlags flags;
GLuint vbo_name; /*!< The name of the corresponding buffer object */
gsize vbo_bytes; /*!< The lengh of the allocated buffer object in bytes */
GList *attributes;
} CoglVertexBufferVBO;
typedef struct _CoglVertexBuffer
{
guint ref_count;
guint n_vertices; /*!< The number of vertices in the buffer */
GList *submitted_vbos; /* The VBOs currently submitted to the GPU */
/* Note: new_attributes is normally NULL and only valid while
* modifying a buffer. */
GList *new_attributes; /*!< attributes pending submission */
} CoglVertexBuffer;
#endif /* __COGL_VERTEX_BUFFER_H */

View File

@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \
$(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-mesh.h $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h
INCLUDES = \ INCLUDES = \
-I$(top_srcdir) \ -I$(top_srcdir) \

View File

@ -71,7 +71,7 @@ cogl_create_context ()
_context->program_handles = NULL; _context->program_handles = NULL;
_context->mesh_handles = NULL; _context->vertex_buffer_handles = NULL;
_context->pf_glGenRenderbuffersEXT = NULL; _context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL; _context->pf_glBindRenderbufferEXT = NULL;

View File

@ -85,8 +85,8 @@ typedef struct
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;
/* Mesh */ /* Vertex buffers */
GArray *mesh_handles; GArray *vertex_buffer_handles;
/* Relying on glext.h to define these */ /* Relying on glext.h to define these */
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT; COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;

View File

@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-shader.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \
$(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-mesh.h $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h
INCLUDES = \ INCLUDES = \
-I$(top_srcdir) \ -I$(top_srcdir) \

View File

@ -69,7 +69,7 @@ cogl_create_context ()
_context->shader_handles = NULL; _context->shader_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _context->draw_buffer = COGL_WINDOW_BUFFER;
_context->mesh_handles = NULL; _context->vertex_buffer_handles = NULL;
_context->blend_src_factor = CGL_SRC_ALPHA; _context->blend_src_factor = CGL_SRC_ALPHA;
_context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA; _context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA;

View File

@ -82,8 +82,8 @@ typedef struct
GArray *program_handles; GArray *program_handles;
GArray *shader_handles; GArray *shader_handles;
/* Mesh */ /* Vertex buffers */
GArray *mesh_handles; GArray *vertex_buffer_handles;
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;

View File

@ -60,7 +60,7 @@
<xi:include href="xml/cogl-offscreen.xml"/> <xi:include href="xml/cogl-offscreen.xml"/>
<xi:include href="xml/cogl-fixed.xml"/> <xi:include href="xml/cogl-fixed.xml"/>
<xi:include href="xml/cogl-color.xml"/> <xi:include href="xml/cogl-color.xml"/>
<xi:include href="xml/cogl-mesh.xml"/> <xi:include href="xml/cogl-attributes-buffer.xml"/>
</chapter> </chapter>

View File

@ -279,18 +279,17 @@ cogl_color_get_alpha_float
</SECTION> </SECTION>
<SECTION> <SECTION>
<FILE>cogl-mesh</FILE> <FILE>cogl-attributes-buffer</FILE>
<TITLE>Mesh API</TITLE> <TITLE>Attributes Buffer API</TITLE>
cogl_mesh_new cogl_attributes_buffer_new
cogl_mesh_ref cogl_attributes_buffer_ref
cogl_mesh_unref cogl_attributes_buffer_unref
CoglMeshAttributeFlags cogl_attributes_buffer_add
cogl_mesh_add_attribute cogl_attributes_buffer_delete
cogl_mesh_delete_attribute cogl_attributes_buffer_enable
cogl_mesh_enable_attribute cogl_attributes_buffer_disable
cogl_mesh_disable_attribute cogl_attributes_buffer_submit
cogl_mesh_draw_arrays cogl_attributes_buffer_draw
cogl_mesh_draw_range_elements cogl_attributes_buffer_draw_range_elements
cogl_mesh_submit
</SECTION> </SECTION>

View File

@ -12,9 +12,9 @@ test_conformance_SOURCES = \
test-timeline-rewind.c \ test-timeline-rewind.c \
test-timeline-smoothness.c \ test-timeline-smoothness.c \
test-timeline.c \ test-timeline.c \
test-mesh-contiguous.c \ test-vertex-buffer-contiguous.c \
test-mesh-interleved.c \ test-vertex-buffer-interleved.c \
test-mesh-mutability.c \ test-vertex-buffer-mutability.c \
test-path.c \ test-path.c \
test-pick.c \ test-pick.c \
test-clutter-rectangle.c \ test-clutter-rectangle.c \

View File

@ -46,17 +46,17 @@ main (int argc, char **argv)
#endif #endif
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.openedhand.com/show_bug.cgi?id=%s"); g_test_bug_base ("http://bugzilla.openedhand.com/show_bug.cgi?id=%s");
g_assert (clutter_init (shared_state->argc_addr, shared_state->argv_addr) g_assert (clutter_init (shared_state->argc_addr, shared_state->argv_addr)
== CLUTTER_INIT_SUCCESS); == CLUTTER_INIT_SUCCESS);
/* Initialise the state you need to share with everything. /* Initialise the state you need to share with everything.
*/ */
shared_state->argc_addr = &argc; shared_state->argc_addr = &argc;
shared_state->argv_addr = &argv; shared_state->argv_addr = &argv;
TEST_CONFORM_SIMPLE ("/timeline", test_timeline); TEST_CONFORM_SIMPLE ("/timeline", test_timeline);
if (g_test_slow ()) if (g_test_slow ())
{ {
@ -65,7 +65,7 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/timeline", test_timeline_rewind); TEST_CONFORM_SIMPLE ("/timeline", test_timeline_rewind);
TEST_CONFORM_SIMPLE ("/timeline", test_timeline_smoothness); TEST_CONFORM_SIMPLE ("/timeline", test_timeline_smoothness);
} }
TEST_CONFORM_SIMPLE ("/picking", test_pick); TEST_CONFORM_SIMPLE ("/picking", test_pick);
/* ClutterText */ /* ClutterText */
@ -88,15 +88,15 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color); TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color);
TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants); TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants);
TEST_CONFORM_SIMPLE ("/invariants", test_initial_state); TEST_CONFORM_SIMPLE ("/invariants", test_initial_state);
TEST_CONFORM_SIMPLE ("/invariants", test_realized); TEST_CONFORM_SIMPLE ("/invariants", test_realized);
TEST_CONFORM_SIMPLE ("/invariants", test_mapped); TEST_CONFORM_SIMPLE ("/invariants", test_mapped);
TEST_CONFORM_SIMPLE ("/invariants", test_show_on_set_parent); TEST_CONFORM_SIMPLE ("/invariants", test_show_on_set_parent);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_contiguous); TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_contiguous);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_interleved); TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_interleved);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_mutability); TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_mutability);
TEST_CONFORM_SIMPLE ("/opacity", test_label_opacity); TEST_CONFORM_SIMPLE ("/opacity", test_label_opacity);
TEST_CONFORM_SIMPLE ("/opacity", test_rectangle_opacity); TEST_CONFORM_SIMPLE ("/opacity", test_rectangle_opacity);

View File

@ -4,9 +4,9 @@
#include "test-conform-common.h" #include "test-conform-common.h"
/* This test verifies that the simplest usage of the mesh API, where we add /* This test verifies that the simplest usage of the vertex buffer API,
* contiguous (x,y) GLfloat vertices, and RGBA GLubyte color attributes to a * where we add contiguous (x,y) GLfloat vertices, and RGBA GLubyte color
* mesh object, submit, and draw. * attributes to a buffer, submit, and draw.
* *
* It also tries to verify that the enable/disable attribute APIs are working * It also tries to verify that the enable/disable attribute APIs are working
* too. * too.
@ -17,7 +17,7 @@
typedef struct _TestState typedef struct _TestState
{ {
CoglHandle mesh; CoglHandle buffer;
ClutterGeometry stage_geom; ClutterGeometry stage_geom;
guint frame; guint frame;
} TestState; } TestState;
@ -44,7 +44,7 @@ validate_result (TestState *state)
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]); g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0); g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
/* Should see a red pixel */ /* Should see a red pixel */
glReadPixels (110, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel); glReadPixels (110, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
if (g_test_verbose ()) if (g_test_verbose ())
@ -56,11 +56,11 @@ validate_result (TestState *state)
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("pixel 2 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]); g_print ("pixel 2 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0); g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
#undef RED #undef RED
#undef GREEN #undef GREEN
#undef BLUE #undef BLUE
/* Comment this out if you want visual feedback of what this test /* Comment this out if you want visual feedback of what this test
* paints. * paints.
*/ */
@ -71,35 +71,35 @@ static void
on_paint (ClutterActor *actor, TestState *state) on_paint (ClutterActor *actor, TestState *state)
{ {
/* Draw a faded blue triangle */ /* Draw a faded blue triangle */
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue"); cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* Draw a red triangle */ /* Draw a red triangle */
/* Here we are testing that the disable attribute works; if it doesn't /* Here we are testing that the disable attribute works; if it doesn't
* the triangle will remain faded blue */ * the triangle will remain faded blue */
cogl_translate (100, 0, 0); cogl_translate (100, 0, 0);
cogl_mesh_disable_attribute (state->mesh, "gl_Color::blue"); cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* Draw a faded blue triangle */ /* Draw a faded blue triangle */
/* Here we are testing that the re-enable works; if it doesn't /* Here we are testing that the re-enable works; if it doesn't
* the triangle will remain red */ * the triangle will remain red */
cogl_translate (100, 0, 0); cogl_translate (100, 0, 0);
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue"); cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* XXX: Experiments have shown that for some buggy drivers, when using /* XXX: Experiments have shown that for some buggy drivers, when using
* glReadPixels there is some kind of race, so we delay our test for a * glReadPixels there is some kind of race, so we delay our test for a
* few frames and a few seconds: * few frames and a few seconds:
@ -108,7 +108,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state); validate_result (state);
else else
g_usleep (G_USEC_PER_SEC); g_usleep (G_USEC_PER_SEC);
state->frame++; state->frame++;
} }
@ -121,8 +121,8 @@ queue_redraw (gpointer stage)
} }
void void
test_mesh_contiguous (TestConformSimpleFixture *fixture, test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
gconstpointer data) gconstpointer data)
{ {
TestState state; TestState state;
ClutterActor *stage; ClutterActor *stage;
@ -149,7 +149,7 @@ test_mesh_contiguous (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage); idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state); g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{ {
GLfloat triangle_verts[3][2] = GLfloat triangle_verts[3][2] =
{ {
@ -163,29 +163,29 @@ test_mesh_contiguous (TestConformSimpleFixture *fixture,
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */ {0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */ {0x00, 0x00, 0xff, 0x00} /* transparent blue */
}; };
state.mesh = cogl_mesh_new (3 /* n vertices */); state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Vertex", "gl_Vertex",
2, /* n components */ 2, /* n components */
GL_FLOAT, GL_FLOAT,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_verts); triangle_verts);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Color::blue", "gl_Color::blue",
4, /* n components */ 4, /* n components */
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_colors); triangle_colors);
cogl_mesh_submit (state.mesh); cogl_vertex_buffer_submit (state.buffer);
} }
clutter_actor_show_all (stage); clutter_actor_show_all (stage);
clutter_main (); clutter_main ();
cogl_mesh_unref (state.mesh); cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);

View File

@ -4,9 +4,9 @@
#include "test-conform-common.h" #include "test-conform-common.h"
/* This test verifies that interleved attributes work with the mesh API. /* This test verifies that interleved attributes work with the vertex buffer
* We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color * API. We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
* attributes to a mesh object, submit and draw. * attributes to a buffer, submit and draw.
* *
* If you want visual feedback of what this test paints for debugging purposes, * If you want visual feedback of what this test paints for debugging purposes,
* then remove the call to clutter_main_quit() in validate_result. * then remove the call to clutter_main_quit() in validate_result.
@ -14,7 +14,7 @@
typedef struct _TestState typedef struct _TestState
{ {
CoglHandle mesh; CoglHandle buffer;
ClutterGeometry stage_geom; ClutterGeometry stage_geom;
guint frame; guint frame;
} TestState; } TestState;
@ -51,11 +51,11 @@ validate_result (TestState *state)
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]); g_print ("pixel 0 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0); g_assert (pixel[RED] == 0 && pixel[GREEN] == 0 && pixel[BLUE] != 0);
#undef RED #undef RED
#undef GREEN #undef GREEN
#undef BLUE #undef BLUE
/* Comment this out if you want visual feedback of what this test /* Comment this out if you want visual feedback of what this test
* paints. * paints.
*/ */
@ -66,10 +66,10 @@ static void
on_paint (ClutterActor *actor, TestState *state) on_paint (ClutterActor *actor, TestState *state)
{ {
/* Draw a faded blue triangle */ /* Draw a faded blue triangle */
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* XXX: Experiments have shown that for some buggy drivers, when using /* XXX: Experiments have shown that for some buggy drivers, when using
* glReadPixels there is some kind of race, so we delay our test for a * glReadPixels there is some kind of race, so we delay our test for a
@ -79,7 +79,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state); validate_result (state);
else else
g_usleep (G_USEC_PER_SEC); g_usleep (G_USEC_PER_SEC);
state->frame++; state->frame++;
} }
@ -92,8 +92,8 @@ queue_redraw (gpointer stage)
} }
void void
test_mesh_interleved (TestConformSimpleFixture *fixture, test_vertex_buffer_interleved (TestConformSimpleFixture *fixture,
gconstpointer data) gconstpointer data)
{ {
TestState state; TestState state;
ClutterActor *stage; ClutterActor *stage;
@ -120,7 +120,7 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage); idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state); g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{ {
InterlevedVertex verts[3] = InterlevedVertex verts[3] =
{ {
@ -141,29 +141,29 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
*/ */
g_assert (sizeof (InterlevedVertex) == 12); g_assert (sizeof (InterlevedVertex) == 12);
state.mesh = cogl_mesh_new (3 /* n vertices */); state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Vertex", "gl_Vertex",
2, /* n components */ 2, /* n components */
GL_FLOAT, GL_FLOAT,
FALSE, /* normalized */ FALSE, /* normalized */
12, /* stride */ 12, /* stride */
&verts[0].x); &verts[0].x);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Color", "gl_Color",
4, /* n components */ 4, /* n components */
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
FALSE, /* normalized */ FALSE, /* normalized */
12, /* stride */ 12, /* stride */
&verts[0].r); &verts[0].r);
cogl_mesh_submit (state.mesh); cogl_vertex_buffer_submit (state.buffer);
} }
clutter_actor_show_all (stage); clutter_actor_show_all (stage);
clutter_main (); clutter_main ();
cogl_mesh_unref (state.mesh); cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);

View File

@ -4,7 +4,7 @@
#include "test-conform-common.h" #include "test-conform-common.h"
/* This test verifies that modifying mesh objects works, by updating /* This test verifies that modifying a vertex buffer works, by updating
* vertex positions, and deleting and re-adding different color attributes. * vertex positions, and deleting and re-adding different color attributes.
* *
* If you want visual feedback of what this test paints for debugging purposes, * If you want visual feedback of what this test paints for debugging purposes,
@ -13,7 +13,7 @@
typedef struct _TestState typedef struct _TestState
{ {
CoglHandle mesh; CoglHandle buffer;
ClutterGeometry stage_geom; ClutterGeometry stage_geom;
guint frame; guint frame;
} TestState; } TestState;
@ -47,7 +47,7 @@ validate_result (TestState *state)
#undef RED #undef RED
#undef GREEN #undef GREEN
#undef BLUE #undef BLUE
/* Comment this out if you want visual feedback of what this test /* Comment this out if you want visual feedback of what this test
* paints. * paints.
*/ */
@ -76,41 +76,41 @@ on_paint (ClutterActor *actor, TestState *state)
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff); cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_add_attribute (state->mesh, cogl_vertex_buffer_add (state->buffer,
"gl_Vertex", "gl_Vertex",
2, /* n components */ 2, /* n components */
GL_FLOAT, GL_FLOAT,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_verts); triangle_verts);
cogl_mesh_delete_attribute (state->mesh, "gl_Color"); cogl_vertex_buffer_delete (state->buffer, "gl_Color");
cogl_mesh_submit (state->mesh); cogl_vertex_buffer_submit (state->buffer);
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* /*
* Draw a faded green triangle * Draw a faded green triangle
*/ */
cogl_mesh_add_attribute (state->mesh, cogl_vertex_buffer_add (state->buffer,
"gl_Color", "gl_Color",
4, /* n components */ 4, /* n components */
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_colors); triangle_colors);
cogl_mesh_submit (state->mesh); cogl_vertex_buffer_submit (state->buffer);
cogl_translate (100, 0, 0); cogl_translate (100, 0, 0);
cogl_mesh_draw_arrays (state->mesh, cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */ GL_TRIANGLE_STRIP, /* mode */
0, /* first */ 0, /* first */
3); /* count */ 3); /* count */
/* XXX: Experiments have shown that for some buggy drivers, when using /* XXX: Experiments have shown that for some buggy drivers, when using
* glReadPixels there is some kind of race, so we delay our test for a * glReadPixels there is some kind of race, so we delay our test for a
* few frames and a few seconds: * few frames and a few seconds:
@ -119,7 +119,7 @@ on_paint (ClutterActor *actor, TestState *state)
validate_result (state); validate_result (state);
else else
g_usleep (G_USEC_PER_SEC); g_usleep (G_USEC_PER_SEC);
state->frame++; state->frame++;
} }
@ -132,8 +132,8 @@ queue_redraw (gpointer stage)
} }
void void
test_mesh_mutability (TestConformSimpleFixture *fixture, test_vertex_buffer_mutability (TestConformSimpleFixture *fixture,
gconstpointer data) gconstpointer data)
{ {
TestState state; TestState state;
ClutterActor *stage; ClutterActor *stage;
@ -160,7 +160,7 @@ test_mesh_mutability (TestConformSimpleFixture *fixture,
idle_source = g_idle_add (queue_redraw, stage); idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state); g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{ {
GLfloat triangle_verts[3][2] = GLfloat triangle_verts[3][2] =
{ {
@ -174,29 +174,29 @@ test_mesh_mutability (TestConformSimpleFixture *fixture,
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */ {0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */ {0x00, 0x00, 0xff, 0x00} /* transparent blue */
}; };
state.mesh = cogl_mesh_new (3 /* n vertices */); state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Vertex", "gl_Vertex",
2, /* n components */ 2, /* n components */
GL_FLOAT, GL_FLOAT,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_verts); triangle_verts);
cogl_mesh_add_attribute (state.mesh, cogl_vertex_buffer_add (state.buffer,
"gl_Color", "gl_Color",
4, /* n components */ 4, /* n components */
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
FALSE, /* normalized */ FALSE, /* normalized */
0, /* stride */ 0, /* stride */
triangle_colors); triangle_colors);
cogl_mesh_submit (state.mesh); cogl_vertex_buffer_submit (state.buffer);
} }
clutter_actor_show_all (stage); clutter_actor_show_all (stage);
clutter_main (); clutter_main ();
cogl_mesh_unref (state.mesh); cogl_vertex_buffer_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);