Bug 1164 - Implements the proposed Mesh API

* clutter/cogl/cogl-mesh.h
	* clutter/cogl/cogl-types.h
	* clutter/cogl/cogl.h.in
	* clutter/cogl/common/Makefile.am
	* clutter/cogl/common/cogl-mesh-private.h
	* clutter/cogl/common/cogl-mesh.c
	* clutter/cogl/gl/cogl-context.c
	* clutter/cogl/gl/cogl-context.h
	* clutter/cogl/gl/cogl-defines.h.in
	* clutter/cogl/gl/cogl.c
	* clutter/cogl/gles/cogl-context.c
	* clutter/cogl/gles/cogl-context.h
	* doc/reference/cogl/cogl-docs.sgml
	* doc/reference/cogl/cogl-sections.txt:
	The Mesh API provides a means for submitting an extensible number of
	per vertex attributes to OpenGL in a way that doesn't require format
	conversions and so that the data can be mapped into the GPU (in vertex
	buffer objects) for - hopefully - fast re-use.

	There are a number of things we can potentially use this API for, but
	right now this just provides a foundation to build on. Please read
	the extensive list of TODO items in cogl-mesh.c for examples.

	Please refer to the cogl-mesh section in the reference manual for
	documentation of the API.

	* tests/conform/Makefile.am
	* tests/conform/test-conform-main.c
	* tests/conform/test-mesh-contiguous.c
	* tests/conform/test-mesh-interleved.c
	* tests/conform/test-mesh-mutability.c:
	Privides basic coverage testing for the mesh API.
This commit is contained in:
Robert Bragg 2008-11-10 18:53:14 +00:00
parent acff6d8196
commit 16897e0729
20 changed files with 2780 additions and 6 deletions

View File

@ -33,6 +33,41 @@
* tests/conform/test-mesh-mutability.c:
Privides basic coverage testing for the mesh API.
2008-11-10 Robert Bragg <robert@linux.intel.com>
Bug 1164 - Implements the proposed Mesh API
* clutter/cogl/cogl-mesh.h
* clutter/cogl/cogl-types.h
* clutter/cogl/cogl.h.in
* clutter/cogl/common/Makefile.am
* clutter/cogl/common/cogl-mesh-private.h
* clutter/cogl/common/cogl-mesh.c
* clutter/cogl/gl/cogl-context.c
* clutter/cogl/gl/cogl-context.h
* clutter/cogl/gl/cogl-defines.h.in
* clutter/cogl/gl/cogl.c
* clutter/cogl/gles/cogl-context.c
* clutter/cogl/gles/cogl-context.h:
The Mesh API provides a means for submitting an extensible number of
per vertex attributes to OpenGL in a way that doesn't require format
conversions and so that the data can be mapped into the GPU (in vertex
buffer objects) for - hopefully - fast re-use.
There are a number of things we can potentially use this API for, but
right now this just provides a foundation to build on. Please read
the extensive list of TODO items in cogl-mesh.c for examples.
Please refer to the cogl-mesh section in the reference manual for
documentation of the API.
* tests/conform/Makefile.am
* tests/conform/test-conform-main.c
* tests/conform/test-mesh-contiguous.c
* tests/conform/test-mesh-interleved.c
* tests/conform/test-mesh-mutability.c:
Privides basic coverage testing for the mesh API.
2008-11-10 Robert Bragg <robert@linux.intel.com>
* tests/conform/ADDING_NEW_TESTS

286
clutter/cogl/cogl-mesh.h Normal file
View File

@ -0,0 +1,286 @@
/* cogl-mesh.h: Handle extensible arrays of vertex attributes
* This file is part of Clutter
*
* Copyright (C) 2008 Intel Corporation.
*
* Authored by: Robert Bragg <bob@o-hand.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/>.
*/
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_MESH_H__
#define __COGL_MESH_H__
#include <glib.h>
#include <cogl/cogl-types.h>
G_BEGIN_DECLS
/**
* SECTION:cogl-mesh
* @short_description: An API for submitting extensible arrays of vertex
* attributes to OpenGL in a way that aims to minimise
* copying or reformatting of the original data.
*
* The Mesh API is designed to be a fairly raw mechanism for developers
* to be able to submit geometry to Cogl in a format that can be directly
* consumed by an OpenGL driver and with awareness of the specific hardware
* being used then costly format conversion can also be avoided.
*
* 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
* have been submitted they are stored in GPU addressable memory and can
* be quickly reused.
*
* Although this API does allow you to modify mesh objects after they have
* been submitted to the GPU you must note that modification is still
* not cheap, so if at all possible think of tricks that let you reuse
* a static buffer. To help with this, it is possible to enable and disable
* individual attributes cheaply.
*
* Take for example a mesh representing an elipse. If you were to submit
* a mesh with color attributes, texture coordinates and normals, then
* you would be able to draw an elipses in the following different ways
* without creating a new mesh:
* <itemizedlist>
* <listitem>Flat colored elipse</listitem>
* <listitem>Textured elipse</listitem>
* <listitem>Smoothly lit textured elipse blended with the color.</listitem>
* </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
* 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.
* If you then update some of your attributes; then these attributes will
* normally be moved into new GL_DYNAMIC_DRAW draw buffers.
*/
/**
* cogl_mesh_new:
* @n_vertices: The number of vertices that will make up your mesh.
*
* This creates a Cogl handle for a new mesh that you can then start to add
* attributes too.
*/
CoglHandle
cogl_mesh_new (guint n_vertices);
/**
* cogl_mesh_add_attribute:
* @handle: A Cogl mesh handle
* @attribute_name: The name of your attribute. It should be a valid GLSL
* variable name and standard attribute types must use one
* of following built-in names: (Note: they correspond to the
* built-in names in GLSL)
* <itemizedlist>
* <listitem>"gl_Color"</listitem>
* <listitem>"gl_Normal"</listitem>
* <listitem>"gl_MultiTexCoord0, gl_MultiTexCoord1, ..."</listitem>
* <listitem>"gl_Vertex"</listitem>
* </itemizedlist>
* To support adding multiple variations of the same attribute
* the name can have a detail component, E.g.
* "gl_Color::active" or "gl_Color::inactive"
* @n_components: The number of components per attribute and must be 1,2,3 or 4
* @gl_type: Specifies the data type of each component (GL_BYTE, GL_UNSIGNED_BYTE,
* GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT or
* GL_DOUBLE)
* @normalized: If GL_TRUE, this specifies that values stored in an integer
* format should be mapped into the range [-1.0, 1.0] or [0.1, 1.0]
* for unsigned values. If GL_FALSE they are converted to floats
* directly.
* @stride: This specifies the number of bytes from the start of one attribute
* value to the start of the next value (for the same attribute). So
* for example with a position interleved with color like this:
* XYRGBAXYRGBAXYRGBA, then if each letter represents a byte, the
* stride for both attributes is 6. The special value 0 means the
* values are stored sequentially in memory.
* @pointer: This addresses the first attribute in the vertex array. (This
* must remain valid until you call cogl_mesh_submit)
*
* This function lets you add an attribute to a mesh. You either use one
* of the built-in names to add standard attributes, like positions, colors
* 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
* determine how many attribute values will be read from the supplied pointer.
*
* Note: the data supplied here isn't copied anywhere until you call
* cogl_mesh_submit, so the supplied pointer must remain valid until then.
* (This is an important optimisation since we can't create a buffer
* object until we know about all the attributes, and repeatedly copying
* large buffers of vertex data may be very costly) If you add attributes
* after submitting then you will need to re-call cogl_mesh_submit to
* commit the changes to the GPU. (Be carefull to minimize the number of
* calls to cogl_mesh_submit though)
*
* Note: If you are interleving attributes it is assumed that that each
* interleaved attribute starts no farther than +- stride bytes from
* the other attributes it is interleved with. I.e. this is ok:
* |-0-0-0-0-0-0-0-0-0-0|
* This is not ok:
* |- - - - -0-0-0-0-0-0 0 0 0 0|
* (Though you can have multiple groups of interleved attributes)
*/
void
cogl_mesh_add_attribute (CoglHandle handle,
const char *attribute_name,
guint8 n_components,
GLenum gl_type,
gboolean normalized,
guint16 stride,
const void *pointer);
/**
* cogl_mesh_delete_attribute:
* @handle: A Cogl mesh handle
* @attribute_name: The name of a previously added attribute
*
* This function deletes an attribute from a mesh. You will need to
* call cogl_mesh_submit to commit this change to the GPU.
*/
void
cogl_mesh_delete_attribute (CoglHandle handle,
const char *attribute_name);
/**
* cogl_mesh_enable_attribute:
* @handle: A Cogl mesh handle
* @attribute_name: The name of the attribute you want to enable
*
* This function enables a previosuly added attribute
*
* Since it is costly to create new mesh objects, then to make individual mesh
* objects more reuseable it is possible to enable and disable attributes
* before using a mesh for drawing.
*
* Note: You don't need to call cogl_mesh_submit after using this function
*/
void
cogl_mesh_enable_attribute (CoglHandle handle,
const char *attribute_name);
/**
* cogl_mesh_disable_attribute:
* @handle: A Cogl mesh handle
* @attribute_name: The name of the attribute you want to disable
*
* This function disables a previosuly added attribute
*
* Since it is costly to create new mesh objects, then to make individual mesh
* objects more reuseable it is possible to enable and disable attributes
* before using a mesh for drawing.
*
* Note: You don't need to call cogl_mesh_submit after using this function
*/
void
cogl_mesh_disable_attribute (CoglHandle handle,
const char *attribute_name);
/**
* cogl_mesh_draw_arrays:
* @handle: A Cogl mesh handle
* @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type:
* <itemizedlist>
* <listitem>GL_POINTS</listitem>
* <listitem>GL_LINE_STRIP</listitem>
* <listitem>GL_LINE_LOOP</listitem>
* <listitem>GL_LINES</listitem>
* <listitem>GL_TRIANGLE_STRIP</listitem>
* <listitem>GL_TRIANGLE_FAN</listitem>
* <listitem>GL_TRIANGLES</listitem>
* </itemizedlist>
* (Note: only types available in GLES are listed)
* @first: Specifies the index of the first vertex you want to draw with
* @count: Specifies the number of vertices you want to draw.
*
* This function lets you draw geometry using all or a subset of the
* vertices in a mesh object.
*/
void
cogl_mesh_draw_arrays (CoglHandle handle,
GLenum mode,
GLint first,
GLsizei count);
/**
* cogl_mesh_draw_range_elements:
* @handle: A Cogl mesh handle
* @mode: Specifies how the vertices should be interpreted, and should be
* a valid GL primitive type:
* <itemizedlist>
* <listitem>GL_POINTS</listitem>
* <listitem>GL_LINE_STRIP</listitem>
* <listitem>GL_LINE_LOOP</listitem>
* <listitem>GL_LINES</listitem>
* <listitem>GL_TRIANGLE_STRIP</listitem>
* <listitem>GL_TRIANGLE_FAN</listitem>
* <listitem>GL_TRIANGLES</listitem>
* </itemizedlist>
* (Note: only types available in GLES are listed)
* @start: Specifies the minimum vertex index contained in indices
* @end: Specifies the maximum vertex index contained in indices
* @count: Specifies the number of vertices you want to draw.
* @type: Specifies the data type used for the indices, and must be
* one of:
* <itemizedlist>
* <listitem>GL_UNSIGNED_BYTE</listitem>
* <listitem>GL_UNSIGNED_SHORT</listitem>
* <listitem>GL_UNSIGNED_INT</listitem>
* </itemizedlist>
* @indices: Specifies the address of your array of indices
*
* This function lets you use an array of indices to specify the vertices
* within your mesh pbject that you want to draw.
*/
void
cogl_mesh_draw_range_elements (CoglHandle handle,
GLenum mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const GLvoid *indices);
/**
* cogl_mesh_ref:
* @handle: a @CoglHandle.
*
* Increment the reference count for a cogl mesh.
*
* Returns: the @handle.
*/
CoglHandle cogl_mesh_ref (CoglHandle handle);
/**
* cogl_mesh_unref:
* @handle: a @CoglHandle.
*
* Deccrement the reference count for a cogl mesh.
*/
void cogl_mesh_unref (CoglHandle handle);
G_END_DECLS
#endif /* __COGL_MESH_H__ */

View File

@ -183,6 +183,7 @@ typedef enum
* @COGL_FEATURE_OFFSCREEN_BLIT:
* @COGL_FEATURE_FOUR_CLIP_PLANES:
* @COGL_FEATURE_STENCIL_BUFFER:
* @COGL_FEATURE_VBOS:
*
* Flags for the supported features.
*/
@ -197,7 +198,8 @@ typedef enum
COGL_FEATURE_OFFSCREEN_MULTISAMPLE = (1 << 7),
COGL_FEATURE_OFFSCREEN_BLIT = (1 << 8),
COGL_FEATURE_FOUR_CLIP_PLANES = (1 << 9),
COGL_FEATURE_STENCIL_BUFFER = (1 << 10)
COGL_FEATURE_STENCIL_BUFFER = (1 << 10),
COGL_FEATURE_VBOS = (1 << 11)
} CoglFeatureFlags;
/**

View File

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

View File

@ -28,4 +28,6 @@ libclutter_cogl_common_la_SOURCES = \
cogl-clip-stack.h \
cogl-clip-stack.c \
cogl-fixed.c \
cogl-color.c
cogl-color.c \
cogl-mesh.c \
cogl-mesh.h

View File

@ -0,0 +1,143 @@
/*
* 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 */

File diff suppressed because it is too large Load Diff

View File

@ -68,6 +68,8 @@ cogl_create_context ()
_context->program_handles = NULL;
_context->mesh_handles = NULL;
_context->pf_glGenRenderbuffersEXT = NULL;
_context->pf_glBindRenderbufferEXT = NULL;
_context->pf_glRenderbufferStorageEXT = NULL;

View File

@ -68,6 +68,9 @@ typedef struct
/* Programs */
GArray *program_handles;
/* Mesh */
GArray *mesh_handles;
/* Relying on glext.h to define these */
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
COGL_PFNGLDELETERENDERBUFFERSEXTPROC pf_glDeleteRenderbuffersEXT;
@ -94,6 +97,17 @@ typedef struct
COGL_PFNGLGETINFOLOGARBPROC pf_glGetInfoLogARB;
COGL_PFNGLGETOBJECTPARAMETERIVARBPROC pf_glGetObjectParameterivARB;
COGL_PFNGLUNIFORM1FARBPROC pf_glUniform1fARB;
COGL_PFNGLVERTEXATTRIBPOINTERARBPROC pf_glVertexAttribPointerARB;
COGL_PFNGLENABLEVERTEXATTRIBARRAYARBPROC pf_glEnableVertexAttribArrayARB;
COGL_PFNGLDISABLEVERTEXATTRIBARRAYARBPROC pf_glDisableVertexAttribArrayARB;
COGL_PFNGLGENBUFFERSARBPROC pf_glGenBuffersARB;
COGL_PFNGLBINDBUFFERARBPROC pf_glBindBufferARB;
COGL_PFNGLBUFFERDATAARBPROC pf_glBufferDataARB;
COGL_PFNGLBUFFERDATASUBARBPROC pf_glBufferDataSubARB;
COGL_PFNGLMAPBUFFERARBPROC pf_glMapBufferARB;
COGL_PFNGLUNMAPBUFFERARBPROC pf_glUnmapBufferARB;
COGL_PFNGLDELETEBUFFERSARBPROC pf_glDeleteBuffersARB;
} CoglContext;

View File

@ -842,6 +842,61 @@ typedef void
(GLint location,
GLfloat v0);
typedef void
(APIENTRYP COGL_PFNGLVERTEXATTRIBPOINTERARBPROC)
(GLuint index,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid *pointer);
typedef void
(APIENTRYP COGL_PFNGLENABLEVERTEXATTRIBARRAYARBPROC)
(GLuint index);
typedef void
(APIENTRYP COGL_PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)
(GLuint index);
typedef void
(APIENTRYP COGL_PFNGLGENBUFFERSARBPROC)
(GLuint n,
GLuint *buffers);
typedef void
(APIENTRYP COGL_PFNGLBINDBUFFERARBPROC)
(GLenum target,
GLuint buffer);
typedef void
(APIENTRYP COGL_PFNGLBUFFERDATAARBPROC)
(GLenum target,
GLsizeiptr size,
const GLvoid *data,
GLenum usage);
typedef void
(APIENTRYP COGL_PFNGLBUFFERDATASUBARBPROC)
(GLenum target,
GLintptr offset,
GLsizeiptr size,
const GLvoid *data);
typedef void *
(APIENTRYP COGL_PFNGLMAPBUFFERARBPROC)
(GLenum target,
GLenum access);
typedef GLboolean
(APIENTRYP COGL_PFNGLUNMAPBUFFERARBPROC)
(GLenum target);
typedef void
(APIENTRYP COGL_PFNGLDELETEBUFFERSARBPROC)
(GLsizei n,
const GLuint *buffers);
G_END_DECLS
#endif

View File

@ -1016,6 +1016,18 @@ _cogl_features_init ()
(COGL_PFNGLUNIFORM1FARBPROC)
cogl_get_proc_address ("glUniform1fARB");
ctx->pf_glVertexAttribPointerARB =
(COGL_PFNGLVERTEXATTRIBPOINTERARBPROC)
cogl_get_proc_address ("glVertexAttribPointerARB");
ctx->pf_glEnableVertexAttribArrayARB =
(COGL_PFNGLENABLEVERTEXATTRIBARRAYARBPROC)
cogl_get_proc_address ("glEnableVertexAttribArrayARB");
ctx->pf_glDisableVertexAttribArrayARB =
(COGL_PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)
cogl_get_proc_address ("glDisableVertexAttribArrayARB");
if (ctx->pf_glCreateProgramObjectARB &&
ctx->pf_glCreateShaderObjectARB &&
ctx->pf_glShaderSourceARB &&
@ -1027,7 +1039,10 @@ _cogl_features_init ()
ctx->pf_glDeleteObjectARB &&
ctx->pf_glGetInfoLogARB &&
ctx->pf_glGetObjectParameterivARB &&
ctx->pf_glUniform1fARB)
ctx->pf_glUniform1fARB &&
ctx->pf_glVertexAttribPointerARB &&
ctx->pf_glEnableVertexAttribArrayARB &&
ctx->pf_glDisableVertexAttribArrayARB)
flags |= COGL_FEATURE_SHADERS_GLSL;
}
@ -1116,6 +1131,39 @@ _cogl_features_init ()
if (max_clip_planes >= 4)
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
if (cogl_check_extension ("GL_ARB_vertex_buffer_object", gl_extensions))
{
ctx->pf_glGenBuffersARB =
(COGL_PFNGLGENBUFFERSARBPROC)
cogl_get_proc_address ("glGenBuffersARB");
ctx->pf_glBindBufferARB =
(COGL_PFNGLBINDBUFFERARBPROC)
cogl_get_proc_address ("glBindBufferARB");
ctx->pf_glBufferDataARB =
(COGL_PFNGLBUFFERDATAARBPROC)
cogl_get_proc_address ("glBufferDataARB");
ctx->pf_glBufferDataSubARB =
(COGL_PFNGLBUFFERDATASUBARBPROC)
cogl_get_proc_address ("glBufferDataSubARB");
ctx->pf_glDeleteBuffersARB =
(COGL_PFNGLDELETEBUFFERSARBPROC)
cogl_get_proc_address ("glDeleteBuffersARB");
ctx->pf_glMapBufferARB =
(COGL_PFNGLMAPBUFFERARBPROC)
cogl_get_proc_address ("glMapBufferARB");
ctx->pf_glUnmapBufferARB =
(COGL_PFNGLUNMAPBUFFERARBPROC)
cogl_get_proc_address ("glUnmapBufferARB");
if (ctx->pf_glGenBuffersARB
&& ctx->pf_glBindBufferARB
&& ctx->pf_glBufferDataARB
&& ctx->pf_glBufferDataSubARB
&& ctx->pf_glDeleteBuffersARB
&& ctx->pf_glMapBufferARB
&& ctx->pf_glUnmapBufferARB)
flags |= COGL_FEATURE_VBOS;
}
/* Cache features */
ctx->feature_flags = flags;
ctx->features_cached = TRUE;
@ -1265,3 +1313,4 @@ cogl_fog_set (const CoglColor *fog_color,
glFogf (GL_FOG_START, COGL_FIXED_TO_FLOAT (start));
glFogf (GL_FOG_END, COGL_FIXED_TO_FLOAT (stop));
}

View File

@ -68,6 +68,8 @@ cogl_create_context ()
_context->shader_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER;
_context->mesh_handles = NULL;
_context->blend_src_factor = CGL_SRC_ALPHA;
_context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA;

View File

@ -77,6 +77,9 @@ typedef struct
GArray *program_handles;
GArray *shader_handles;
/* Mesh */
GArray *mesh_handles;
#ifdef HAVE_COGL_GLES2
CoglGles2Wrapper gles2;

View File

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

View File

@ -257,3 +257,18 @@ cogl_color_get_green_float
cogl_color_get_blue_float
cogl_color_get_alpha_float
</SECTION>
<SECTION>
<FILE>cogl-mesh</FILE>
<TITLE>Mesh API</TITLE>
cogl_mesh_new
cogl_mesh_ref
cogl_mesh_unref
cogl_mesh_add_attribute
cogl_mesh_delete_attribute
cogl_mesh_enable_attribute
cogl_mesh_disable_attribute
cogl_mesh_draw_arrays
cogl_mesh_draw_range_elements
</SECTION>

View File

@ -10,6 +10,9 @@ test_conformance_SOURCES = \
test-timeline-rewind.c \
test-timeline-smoothness.c \
test-timeline.c \
test-mesh-contiguous.c \
test-mesh-interleved.c \
test-mesh-mutability.c \
test-pick.c \
test-label-cache.c \
test-clutter-entry.c \

View File

@ -81,6 +81,10 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/invariants", test_mapped);
TEST_CONFORM_SIMPLE ("/invariants", test_show_on_set_parent);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_contiguous);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_interleved);
TEST_CONFORM_SIMPLE ("/mesh", test_mesh_mutability);
g_test_run ();
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,183 @@
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "test-conform-common.h"
/* This test verifies that the simplest usage of the mesh API, where we add
* contiguous (x,y) GLfloat vertices, and RGBA GLubyte color attributes to a
* mesh object, submit, and draw.
*
* It also tries to verify that the enable/disable attribute APIs are working
* too.
*
* If you want visual feedback of what this test paints for debugging purposes,
* then remove the call to clutter_main_quit() in validate_result.
*/
typedef struct _TestState
{
CoglHandle mesh;
ClutterGeometry stage_geom;
guint frame;
} TestState;
static void
validate_result (TestState *state)
{
GLubyte pixel[4];
GLint y_off = state->stage_geom.height - 90;
/* NB: glReadPixels is done in GL screen space so y = 0 is at the bottom */
g_print ("y_off = %d\n", y_off);
/* NB: We ignore the alpha, since we don't know if our render target is
* RGB or RGBA */
#define RED 0
#define GREEN 1
#define BLUE 2
/* Should see a blue pixel */
glReadPixels (10, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
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);
/* Should see a red pixel */
glReadPixels (110, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
g_print ("pixel 1 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] != 0 && pixel[GREEN] == 0 && pixel[BLUE] == 0);
/* Should see a blue pixel */
glReadPixels (210, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
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);
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
clutter_main_quit ();
}
static void
on_paint (ClutterActor *actor, TestState *state)
{
/* Draw a faded blue triangle */
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue");
glColor4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* Draw a red triangle */
/* Here we are testing that the disable attribute works; if it doesn't
* the triangle will remain faded blue */
cogl_translate (100, 0, 0);
cogl_mesh_disable_attribute (state->mesh, "gl_Color::blue");
glColor4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* Draw a faded blue triangle */
/* Here we are testing that the re-enable works; if it doesn't
* the triangle will remain red */
cogl_translate (100, 0, 0);
cogl_mesh_enable_attribute (state->mesh, "gl_Color::blue");
glColor4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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
* few frames and a few seconds:
*/
if (state->frame >= 2)
validate_result (state);
else
sleep (1);
state->frame++;
}
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
void
test_mesh_contiguous (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
ClutterActor *group;
state.frame = 0;
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
clutter_actor_get_geometry (stage, &state.stage_geom);
group = clutter_group_new ();
clutter_actor_set_size (group,
state.stage_geom.width,
state.stage_geom.height);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
/* We force continuous redrawing of the stage, since we need to skip
* the first few frames, and we wont be doing anything else that
* will trigger redrawing. */
g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
GLfloat triangle_verts[3][2] =
{
{0.0, 0.0},
{100.0, 100.0},
{0.0, 100.0}
};
GLbyte triangle_colors[3][4] =
{
{0x00, 0x00, 0xff, 0xff}, /* blue */
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
};
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_add_attribute (state.mesh,
"gl_Color::blue",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state.mesh);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
g_print ("OK\n");
}

View File

@ -0,0 +1,165 @@
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "test-conform-common.h"
/* This test verifies that interleved attributes work with the mesh API.
* We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
* attributes to a mesh object, submit and draw.
*
* If you want visual feedback of what this test paints for debugging purposes,
* then remove the call to clutter_main_quit() in validate_result.
*/
typedef struct _TestState
{
CoglHandle mesh;
ClutterGeometry stage_geom;
guint frame;
} TestState;
typedef struct _InterlevedVertex
{
GLfloat x;
GLfloat y;
GLubyte r;
GLubyte g;
GLubyte b;
GLubyte a;
} InterlevedVertex;
static void
validate_result (TestState *state)
{
GLubyte pixel[4];
GLint y_off = state->stage_geom.height - 90;
/* NB: glReadPixels is done in GL screen space so y = 0 is at the bottom */
/* NB: We ignore the alpha, since we don't know if our render target is
* RGB or RGBA */
#define RED 0
#define GREEN 1
#define BLUE 2
/* Should see a blue pixel */
glReadPixels (10, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
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);
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
clutter_main_quit ();
}
static void
on_paint (ClutterActor *actor, TestState *state)
{
/* Draw a faded blue triangle */
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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
* few frames and a few seconds:
*/
if (state->frame >= 2)
validate_result (state);
else
sleep (1);
state->frame++;
}
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
void
test_mesh_interleved (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
ClutterActor *group;
state.frame = 0;
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
clutter_actor_get_geometry (stage, &state.stage_geom);
group = clutter_group_new ();
clutter_actor_set_size (group,
state.stage_geom.width,
state.stage_geom.height);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
/* We force continuous redrawing of the stage, since we need to skip
* the first few frames, and we wont be doing anything else that
* will trigger redrawing. */
g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
InterlevedVertex verts[3] =
{
{ /* .x = */ 0.0, /* .y = */ 0.0,
/* blue */
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0xff },
{ /* .x = */ 100.0, /* .y = */ 100.0,
/* transparent blue */
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0x00 },
{ /* .x = */ 0.0, /* .y = */ 100.0,
/* transparent blue */
/* .r = */ 0x00, /* .g = */ 0x00, /* .b = */ 0xff, /* .a = */ 0x00 },
};
/* We assume the compiler is doing no funny struct padding for this test:
*/
g_assert (sizeof (InterlevedVertex) == 12);
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
12, /* stride */
&verts[0].x);
cogl_mesh_add_attribute (state.mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
12, /* stride */
&verts[0].r);
cogl_mesh_submit (state.mesh);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
g_print ("OK\n");
}

View File

@ -0,0 +1,198 @@
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "test-conform-common.h"
/* This test verifies that modifying mesh objects works, by updating
* vertex positions, and deleting and re-adding different color attributes.
*
* If you want visual feedback of what this test paints for debugging purposes,
* then remove the call to clutter_main_quit() in validate_result.
*/
typedef struct _TestState
{
CoglHandle mesh;
ClutterGeometry stage_geom;
guint frame;
} TestState;
static void
validate_result (TestState *state)
{
GLubyte pixel[4];
GLint y_off = state->stage_geom.height - 90;
/* NB: glReadPixels is done in GL screen space so y = 0 is at the bottom */
/* NB: We ignore the alpha, since we don't know if our render target is
* RGB or RGBA */
#define RED 0
#define GREEN 1
#define BLUE 2
/* Should see a red pixel */
glReadPixels (110, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
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);
/* Should see a green pixel */
glReadPixels (210, y_off, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
g_print ("pixel 1 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] == 0 && pixel[GREEN] != 0 && pixel[BLUE] == 0);
#undef RED
#undef GREEN
#undef BLUE
/* Comment this out if you want visual feedback of what this test
* paints.
*/
clutter_main_quit ();
}
static void
on_paint (ClutterActor *actor, TestState *state)
{
GLfloat triangle_verts[3][2] =
{
{100.0, 0.0},
{200.0, 100.0},
{100.0, 100.0}
};
GLbyte triangle_colors[3][4] =
{
{0x00, 0xff, 0x00, 0xff}, /* blue */
{0x00, 0xff, 0x00, 0x00}, /* transparent blue */
{0x00, 0xff, 0x00, 0x00} /* transparent blue */
};
/*
* Draw a red triangle
*/
glColor4ub (0xff, 0x00, 0x00, 0xff);
cogl_mesh_add_attribute (state->mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_delete_attribute (state->mesh, "gl_Color");
cogl_mesh_submit (state->mesh);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/*
* Draw a faded green triangle
*/
cogl_mesh_add_attribute (state->mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state->mesh);
cogl_translate (100, 0, 0);
cogl_mesh_draw_arrays (state->mesh,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* 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
* few frames and a few seconds:
*/
if (state->frame >= 2)
validate_result (state);
else
sleep (1);
state->frame++;
}
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
void
test_mesh_mutability (TestConformSimpleFixture *fixture,
gconstpointer data)
{
TestState state;
ClutterActor *stage;
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
ClutterActor *group;
state.frame = 0;
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
clutter_actor_get_geometry (stage, &state.stage_geom);
group = clutter_group_new ();
clutter_actor_set_size (group,
state.stage_geom.width,
state.stage_geom.height);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
/* We force continuous redrawing of the stage, since we need to skip
* the first few frames, and we wont be doing anything else that
* will trigger redrawing. */
g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
{
GLfloat triangle_verts[3][2] =
{
{0.0, 0.0},
{100.0, 100.0},
{0.0, 100.0}
};
GLbyte triangle_colors[3][4] =
{
{0x00, 0x00, 0xff, 0xff}, /* blue */
{0x00, 0x00, 0xff, 0x00}, /* transparent blue */
{0x00, 0x00, 0xff, 0x00} /* transparent blue */
};
state.mesh = cogl_mesh_new (3 /* n vertices */);
cogl_mesh_add_attribute (state.mesh,
"gl_Vertex",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_verts);
cogl_mesh_add_attribute (state.mesh,
"gl_Color",
4, /* n components */
GL_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
triangle_colors);
cogl_mesh_submit (state.mesh);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_mesh_unref (state.mesh);
g_print ("OK\n");
}