mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
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:
parent
4bc1e567fc
commit
e338245827
@ -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.
|
||||
*
|
||||
* 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
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -23,8 +27,8 @@
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_MESH_H__
|
||||
#define __COGL_MESH_H__
|
||||
#ifndef __COGL_VERTEX_BUFFER_H__
|
||||
#define __COGL_VERTEX_BUFFER_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <cogl/cogl-types.h>
|
||||
@ -32,42 +36,42 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-mesh
|
||||
* SECTION:cogl-vertex-buffer
|
||||
* @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.
|
||||
* The Attributes Buffer 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
|
||||
* understand that attribute buffers are not that cheap to create but once they
|
||||
* have been submitted they can be 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.
|
||||
* Although this API does allow you to modify attribute buffers after they have
|
||||
* been submitted to the GPU you must note that modification is also not that
|
||||
* 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:
|
||||
* Take for example attributes representing an elipse. If you were to submit
|
||||
* color attributes, texture coordinates and normals, then you would be able
|
||||
* to draw an elipses in the following different ways without modifying
|
||||
* the vertex buffer, only by changing your source material.
|
||||
* <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
|
||||
* 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
|
||||
* 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
|
||||
@ -75,18 +79,18 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
|
||||
/**
|
||||
* cogl_mesh_new:
|
||||
* @n_vertices: The number of vertices that will make up your mesh.
|
||||
* cogl_vertex_buffer_new:
|
||||
* @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
|
||||
* attributes too.
|
||||
* This creates a Cogl handle for a new vertex buffer that you can then start
|
||||
* to add attributes too.
|
||||
*/
|
||||
CoglHandle
|
||||
cogl_mesh_new (guint n_vertices);
|
||||
cogl_vertex_buffer_new (guint n_vertices);
|
||||
|
||||
/**
|
||||
* cogl_mesh_add_attribute:
|
||||
* @handle: A Cogl mesh handle
|
||||
* cogl_vertex_buffer_add:
|
||||
* @handle: A vertex buffer 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
|
||||
@ -115,90 +119,106 @@ cogl_mesh_new (guint n_vertices);
|
||||
* 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)
|
||||
* 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
|
||||
* 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 number of vertices declared when first creating the vertex
|
||||
* 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
|
||||
* 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)
|
||||
* cogl_vertex_buffer_submit, so the supplied pointer must remain valid
|
||||
* until then.
|
||||
* (This is an important optimisation since we can't create the underlying
|
||||
* OpenGL 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_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
|
||||
* interleaved attribute starts no farther than +- stride bytes from
|
||||
* the other attributes it is interleved with. I.e. this is ok:
|
||||
* 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_vertex_buffer_add (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
|
||||
* cogl_vertex_buffer_delete:
|
||||
* @handle: A vertex buffer 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.
|
||||
* This function deletes an attribute from a buffer. You will need to
|
||||
* call cogl_vertex_buffer_submit to commit this change to the GPU.
|
||||
*/
|
||||
void
|
||||
cogl_mesh_delete_attribute (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
cogl_vertex_buffer_delete (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
|
||||
/**
|
||||
* cogl_mesh_enable_attribute:
|
||||
* @handle: A Cogl mesh handle
|
||||
* cogl_vertex_buffer_enable:
|
||||
* @handle: A vertex buffer 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.
|
||||
* Since it can be costly to add and remove new attributes to buffers; to make
|
||||
* individual buffers more reuseable it is possible to enable and disable
|
||||
* 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
|
||||
cogl_mesh_enable_attribute (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
cogl_vertex_buffer_enable (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
|
||||
/**
|
||||
* cogl_mesh_disable_attribute:
|
||||
* @handle: A Cogl mesh handle
|
||||
* cogl_vertex_buffer_submit:
|
||||
* @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
|
||||
*
|
||||
* 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.
|
||||
* Since it can be costly to add and remove new attributes to buffers; to make
|
||||
* individual buffers more reuseable it is possible to enable and disable
|
||||
* 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
|
||||
cogl_mesh_disable_attribute (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
cogl_vertex_buffer_disable (CoglHandle handle,
|
||||
const char *attribute_name);
|
||||
|
||||
/**
|
||||
* cogl_mesh_draw_arrays:
|
||||
* @handle: A Cogl mesh handle
|
||||
* cogl_vertex_buffer_draw:
|
||||
* @handle: A vertex buffer handle
|
||||
* @mode: Specifies how the vertices should be interpreted, and should be
|
||||
* a valid GL primitive type:
|
||||
* <itemizedlist>
|
||||
@ -215,17 +235,17 @@ cogl_mesh_disable_attribute (CoglHandle handle,
|
||||
* @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.
|
||||
* vertices in a vertex buffer.
|
||||
*/
|
||||
void
|
||||
cogl_mesh_draw_arrays (CoglHandle handle,
|
||||
GLenum mode,
|
||||
GLint first,
|
||||
GLsizei count);
|
||||
cogl_vertex_buffer_draw (CoglHandle handle,
|
||||
GLenum mode,
|
||||
GLint first,
|
||||
GLsizei count);
|
||||
|
||||
/**
|
||||
* cogl_mesh_draw_range_elements:
|
||||
* @handle: A Cogl mesh handle
|
||||
* cogl_vertex_buffer_draw_range_elements:
|
||||
* @handle: A vertex buffer handle
|
||||
* @mode: Specifies how the vertices should be interpreted, and should be
|
||||
* a valid GL primitive type:
|
||||
* <itemizedlist>
|
||||
@ -238,11 +258,11 @@ cogl_mesh_draw_arrays (CoglHandle handle,
|
||||
* <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
|
||||
* @min_index: Specifies the minimum 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.
|
||||
* @type: Specifies the data type used for the indices, and must be
|
||||
* one of:
|
||||
* @indices_typetype: Specifies the data type used for the indices, and must be
|
||||
* one of:
|
||||
* <itemizedlist>
|
||||
* <listitem>GL_UNSIGNED_BYTE</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
|
||||
*
|
||||
* 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
|
||||
cogl_mesh_draw_range_elements (CoglHandle handle,
|
||||
GLenum mode,
|
||||
GLuint start,
|
||||
GLuint end,
|
||||
GLsizei count,
|
||||
GLenum type,
|
||||
const GLvoid *indices);
|
||||
cogl_vertex_buffer_draw_range_elements (CoglHandle handle,
|
||||
GLenum mode,
|
||||
GLuint min_index,
|
||||
GLuint max_index,
|
||||
GLsizei count,
|
||||
GLenum indices_type,
|
||||
const GLvoid *indices);
|
||||
|
||||
/**
|
||||
* cogl_mesh_submit:
|
||||
* @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:
|
||||
* cogl_vertex_buffer_ref:
|
||||
* @handle: a @CoglHandle.
|
||||
*
|
||||
* Increment the reference count for a cogl mesh.
|
||||
* Increment the reference count for a vertex buffer
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
|
||||
#endif /* __COGL_MESH_H__ */
|
||||
#endif /* __COGL_VERTEX_BUFFER_H__ */
|
@ -32,7 +32,7 @@
|
||||
|
||||
#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-color.h>
|
||||
#include <cogl/cogl-offscreen.h>
|
||||
|
@ -30,4 +30,5 @@ libclutter_cogl_common_la_SOURCES = \
|
||||
cogl-clip-stack.c \
|
||||
cogl-fixed.c \
|
||||
cogl-color.c \
|
||||
cogl-mesh.c
|
||||
cogl-vertex-buffer-private.h \
|
||||
cogl-vertex-buffer.c
|
||||
|
@ -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 */
|
||||
|
142
clutter/cogl/common/cogl-vertex-buffer-private.h
Normal file
142
clutter/cogl/common/cogl-vertex-buffer-private.h
Normal 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 */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
|
||||
$(top_builddir)/clutter/cogl/cogl-shader.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-texture.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-types.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-mesh.h
|
||||
$(top_builddir)/clutter/cogl/cogl-vertex-buffer.h
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir) \
|
||||
|
@ -71,7 +71,7 @@ cogl_create_context ()
|
||||
|
||||
_context->program_handles = NULL;
|
||||
|
||||
_context->mesh_handles = NULL;
|
||||
_context->vertex_buffer_handles = NULL;
|
||||
|
||||
_context->pf_glGenRenderbuffersEXT = NULL;
|
||||
_context->pf_glBindRenderbufferEXT = NULL;
|
||||
|
@ -85,8 +85,8 @@ typedef struct
|
||||
/* Clip stack */
|
||||
CoglClipStackState clip;
|
||||
|
||||
/* Mesh */
|
||||
GArray *mesh_handles;
|
||||
/* Vertex buffers */
|
||||
GArray *vertex_buffer_handles;
|
||||
|
||||
/* Relying on glext.h to define these */
|
||||
COGL_PFNGLGENRENDERBUFFERSEXTPROC pf_glGenRenderbuffersEXT;
|
||||
|
@ -10,7 +10,7 @@ libclutterinclude_HEADERS = \
|
||||
$(top_builddir)/clutter/cogl/cogl-shader.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-texture.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-types.h \
|
||||
$(top_builddir)/clutter/cogl/cogl-mesh.h
|
||||
$(top_builddir)/clutter/cogl/cogl-vertex-buffer.h
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir) \
|
||||
|
@ -69,7 +69,7 @@ cogl_create_context ()
|
||||
_context->shader_handles = NULL;
|
||||
_context->draw_buffer = COGL_WINDOW_BUFFER;
|
||||
|
||||
_context->mesh_handles = NULL;
|
||||
_context->vertex_buffer_handles = NULL;
|
||||
|
||||
_context->blend_src_factor = CGL_SRC_ALPHA;
|
||||
_context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA;
|
||||
|
@ -82,8 +82,8 @@ typedef struct
|
||||
GArray *program_handles;
|
||||
GArray *shader_handles;
|
||||
|
||||
/* Mesh */
|
||||
GArray *mesh_handles;
|
||||
/* Vertex buffers */
|
||||
GArray *vertex_buffer_handles;
|
||||
|
||||
/* Clip stack */
|
||||
CoglClipStackState clip;
|
||||
|
@ -60,7 +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"/>
|
||||
<xi:include href="xml/cogl-attributes-buffer.xml"/>
|
||||
|
||||
</chapter>
|
||||
|
||||
|
@ -279,18 +279,17 @@ cogl_color_get_alpha_float
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>cogl-mesh</FILE>
|
||||
<TITLE>Mesh API</TITLE>
|
||||
cogl_mesh_new
|
||||
cogl_mesh_ref
|
||||
cogl_mesh_unref
|
||||
CoglMeshAttributeFlags
|
||||
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
|
||||
cogl_mesh_submit
|
||||
<FILE>cogl-attributes-buffer</FILE>
|
||||
<TITLE>Attributes Buffer API</TITLE>
|
||||
cogl_attributes_buffer_new
|
||||
cogl_attributes_buffer_ref
|
||||
cogl_attributes_buffer_unref
|
||||
cogl_attributes_buffer_add
|
||||
cogl_attributes_buffer_delete
|
||||
cogl_attributes_buffer_enable
|
||||
cogl_attributes_buffer_disable
|
||||
cogl_attributes_buffer_submit
|
||||
cogl_attributes_buffer_draw
|
||||
cogl_attributes_buffer_draw_range_elements
|
||||
</SECTION>
|
||||
|
||||
|
@ -12,9 +12,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-vertex-buffer-contiguous.c \
|
||||
test-vertex-buffer-interleved.c \
|
||||
test-vertex-buffer-mutability.c \
|
||||
test-path.c \
|
||||
test-pick.c \
|
||||
test-clutter-rectangle.c \
|
||||
|
@ -46,17 +46,17 @@ main (int argc, char **argv)
|
||||
#endif
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
|
||||
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)
|
||||
== CLUTTER_INIT_SUCCESS);
|
||||
|
||||
|
||||
/* Initialise the state you need to share with everything.
|
||||
*/
|
||||
shared_state->argc_addr = &argc;
|
||||
shared_state->argv_addr = &argv;
|
||||
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/timeline", test_timeline);
|
||||
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_smoothness);
|
||||
}
|
||||
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/picking", test_pick);
|
||||
|
||||
/* ClutterText */
|
||||
@ -88,15 +88,15 @@ main (int argc, char **argv)
|
||||
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants);
|
||||
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/invariants", test_initial_state);
|
||||
TEST_CONFORM_SIMPLE ("/invariants", test_realized);
|
||||
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);
|
||||
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_contiguous);
|
||||
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_interleved);
|
||||
TEST_CONFORM_SIMPLE ("/vertex-buffer", test_vertex_buffer_mutability);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/opacity", test_label_opacity);
|
||||
TEST_CONFORM_SIMPLE ("/opacity", test_rectangle_opacity);
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#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.
|
||||
/* This test verifies that the simplest usage of the vertex buffer API,
|
||||
* where we add contiguous (x,y) GLfloat vertices, and RGBA GLubyte color
|
||||
* attributes to a buffer, submit, and draw.
|
||||
*
|
||||
* It also tries to verify that the enable/disable attribute APIs are working
|
||||
* too.
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
typedef struct _TestState
|
||||
{
|
||||
CoglHandle mesh;
|
||||
CoglHandle buffer;
|
||||
ClutterGeometry stage_geom;
|
||||
guint frame;
|
||||
} TestState;
|
||||
@ -44,7 +44,7 @@ validate_result (TestState *state)
|
||||
if (g_test_verbose ())
|
||||
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);
|
||||
if (g_test_verbose ())
|
||||
@ -56,11 +56,11 @@ validate_result (TestState *state)
|
||||
if (g_test_verbose ())
|
||||
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.
|
||||
*/
|
||||
@ -71,35 +71,35 @@ static void
|
||||
on_paint (ClutterActor *actor, TestState *state)
|
||||
{
|
||||
/* 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_mesh_draw_arrays (state->mesh,
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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");
|
||||
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
|
||||
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
||||
cogl_mesh_draw_arrays (state->mesh,
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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");
|
||||
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
|
||||
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
||||
cogl_mesh_draw_arrays (state->mesh,
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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:
|
||||
@ -108,7 +108,7 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
validate_result (state);
|
||||
else
|
||||
g_usleep (G_USEC_PER_SEC);
|
||||
|
||||
|
||||
state->frame++;
|
||||
}
|
||||
|
||||
@ -121,8 +121,8 @@ queue_redraw (gpointer stage)
|
||||
}
|
||||
|
||||
void
|
||||
test_mesh_contiguous (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
TestState state;
|
||||
ClutterActor *stage;
|
||||
@ -149,7 +149,7 @@ test_mesh_contiguous (TestConformSimpleFixture *fixture,
|
||||
idle_source = g_idle_add (queue_redraw, stage);
|
||||
|
||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
||||
|
||||
|
||||
{
|
||||
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 */
|
||||
};
|
||||
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);
|
||||
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Vertex",
|
||||
2, /* n components */
|
||||
GL_FLOAT,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_verts);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Color::blue",
|
||||
4, /* n components */
|
||||
GL_UNSIGNED_BYTE,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_colors);
|
||||
cogl_vertex_buffer_submit (state.buffer);
|
||||
}
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
cogl_mesh_unref (state.mesh);
|
||||
cogl_vertex_buffer_unref (state.buffer);
|
||||
|
||||
g_source_remove (idle_source);
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
#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.
|
||||
/* This test verifies that interleved attributes work with the vertex buffer
|
||||
* API. We add (x,y) GLfloat vertices, interleved with RGBA GLubyte color
|
||||
* attributes to a buffer, 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.
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
typedef struct _TestState
|
||||
{
|
||||
CoglHandle mesh;
|
||||
CoglHandle buffer;
|
||||
ClutterGeometry stage_geom;
|
||||
guint frame;
|
||||
} TestState;
|
||||
@ -51,11 +51,11 @@ validate_result (TestState *state)
|
||||
if (g_test_verbose ())
|
||||
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.
|
||||
*/
|
||||
@ -66,10 +66,10 @@ 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 */
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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
|
||||
@ -79,7 +79,7 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
validate_result (state);
|
||||
else
|
||||
g_usleep (G_USEC_PER_SEC);
|
||||
|
||||
|
||||
state->frame++;
|
||||
}
|
||||
|
||||
@ -92,8 +92,8 @@ queue_redraw (gpointer stage)
|
||||
}
|
||||
|
||||
void
|
||||
test_mesh_interleved (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
test_vertex_buffer_interleved (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
TestState state;
|
||||
ClutterActor *stage;
|
||||
@ -120,7 +120,7 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
|
||||
idle_source = g_idle_add (queue_redraw, stage);
|
||||
|
||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
||||
|
||||
|
||||
{
|
||||
InterlevedVertex verts[3] =
|
||||
{
|
||||
@ -141,29 +141,29 @@ test_mesh_interleved (TestConformSimpleFixture *fixture,
|
||||
*/
|
||||
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);
|
||||
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Vertex",
|
||||
2, /* n components */
|
||||
GL_FLOAT,
|
||||
FALSE, /* normalized */
|
||||
12, /* stride */
|
||||
&verts[0].x);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Color",
|
||||
4, /* n components */
|
||||
GL_UNSIGNED_BYTE,
|
||||
FALSE, /* normalized */
|
||||
12, /* stride */
|
||||
&verts[0].r);
|
||||
cogl_vertex_buffer_submit (state.buffer);
|
||||
}
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
cogl_mesh_unref (state.mesh);
|
||||
cogl_vertex_buffer_unref (state.buffer);
|
||||
|
||||
g_source_remove (idle_source);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#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.
|
||||
*
|
||||
* If you want visual feedback of what this test paints for debugging purposes,
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
typedef struct _TestState
|
||||
{
|
||||
CoglHandle mesh;
|
||||
CoglHandle buffer;
|
||||
ClutterGeometry stage_geom;
|
||||
guint frame;
|
||||
} TestState;
|
||||
@ -47,7 +47,7 @@ validate_result (TestState *state)
|
||||
#undef RED
|
||||
#undef GREEN
|
||||
#undef BLUE
|
||||
|
||||
|
||||
/* Comment this out if you want visual feedback of what this test
|
||||
* paints.
|
||||
*/
|
||||
@ -76,41 +76,41 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
|
||||
cogl_set_source_color4ub (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 */
|
||||
|
||||
cogl_vertex_buffer_add (state->buffer,
|
||||
"gl_Vertex",
|
||||
2, /* n components */
|
||||
GL_FLOAT,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_verts);
|
||||
cogl_vertex_buffer_delete (state->buffer, "gl_Color");
|
||||
cogl_vertex_buffer_submit (state->buffer);
|
||||
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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_vertex_buffer_add (state->buffer,
|
||||
"gl_Color",
|
||||
4, /* n components */
|
||||
GL_UNSIGNED_BYTE,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_colors);
|
||||
cogl_vertex_buffer_submit (state->buffer);
|
||||
|
||||
cogl_translate (100, 0, 0);
|
||||
cogl_mesh_draw_arrays (state->mesh,
|
||||
GL_TRIANGLE_STRIP, /* mode */
|
||||
0, /* first */
|
||||
3); /* count */
|
||||
cogl_vertex_buffer_draw (state->buffer,
|
||||
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:
|
||||
@ -119,7 +119,7 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
validate_result (state);
|
||||
else
|
||||
g_usleep (G_USEC_PER_SEC);
|
||||
|
||||
|
||||
state->frame++;
|
||||
}
|
||||
|
||||
@ -132,8 +132,8 @@ queue_redraw (gpointer stage)
|
||||
}
|
||||
|
||||
void
|
||||
test_mesh_mutability (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
test_vertex_buffer_mutability (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
TestState state;
|
||||
ClutterActor *stage;
|
||||
@ -160,7 +160,7 @@ test_mesh_mutability (TestConformSimpleFixture *fixture,
|
||||
idle_source = g_idle_add (queue_redraw, stage);
|
||||
|
||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
||||
|
||||
|
||||
{
|
||||
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 */
|
||||
};
|
||||
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);
|
||||
state.buffer = cogl_vertex_buffer_new (3 /* n vertices */);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Vertex",
|
||||
2, /* n components */
|
||||
GL_FLOAT,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_verts);
|
||||
cogl_vertex_buffer_add (state.buffer,
|
||||
"gl_Color",
|
||||
4, /* n components */
|
||||
GL_UNSIGNED_BYTE,
|
||||
FALSE, /* normalized */
|
||||
0, /* stride */
|
||||
triangle_colors);
|
||||
cogl_vertex_buffer_submit (state.buffer);
|
||||
}
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
cogl_mesh_unref (state.mesh);
|
||||
cogl_vertex_buffer_unref (state.buffer);
|
||||
|
||||
g_source_remove (idle_source);
|
||||
|
Loading…
Reference in New Issue
Block a user