1
0
Fork 0

cogl: Remove CoglVertexBuffer

It was deprecated, relied on deprecated API (implicit framebuffers,
mateiarls etc), and was unused. Lets remove it.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/935
This commit is contained in:
Jonas Ådahl 2019-11-20 14:58:02 +01:00 committed by Georges Basile Stavracas Neto
parent 49c8d42317
commit 98c0fe934b
15 changed files with 3 additions and 3278 deletions

View file

@ -40,8 +40,7 @@ G_BEGIN_DECLS
* @short_description: Functions that draw various primitive 3D shapes
*
* The primitives API provides utilities for drawing some
* common 3D shapes in a more convenient way than the CoglVertexBuffer
* API provides.
* common 3D shapes.
*/
/**

View file

@ -88,7 +88,6 @@
#include <cogl/deprecated/cogl-auto-texture.h>
#include <cogl/deprecated/cogl-shader.h>
#include <cogl/deprecated/cogl-material-compat.h>
#include <cogl/deprecated/cogl-vertex-buffer.h>
#ifdef COGL_ENABLE_MUTTER_API
#include <cogl/cogl-mutter.h>

View file

@ -160,8 +160,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
* data is actually allocated.
*
* Sub textures have undefined behaviour texture coordinates outside
* of the range [0,1] are used. They also do not work with
* CoglVertexBuffers.
* of the range [0,1] are used.
*
* The sub texture will keep a reference to the full texture so you do
* not need to keep one separately if you only want to use the sub

View file

@ -1,165 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2008,2009 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_VERTEX_BUFFER_H
#define __COGL_VERTEX_BUFFER_H
#include "cogl-object-private.h"
#include "cogl-primitive.h"
#include <glib.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)
typedef struct _CoglVertexBufferAttrib
{
/* TODO: look at breaking up the flags into seperate
* bitfields and seperate enums */
CoglVertexBufferAttribFlags flags:24;
uint8_t id;
GQuark name;
char *name_without_detail;
union _u
{
const void *pointer;
size_t vbo_offset;
} u;
CoglAttributeType type;
size_t span_bytes;
uint16_t stride;
uint8_t n_components;
uint8_t texture_unit;
int attribute_first;
CoglAttribute *attribute;
} CoglVertexBufferAttrib;
typedef enum _CoglVertexBufferVBOFlags
{
COGL_VERTEX_BUFFER_VBO_FLAG_STRIDED = 1<<0,
COGL_VERTEX_BUFFER_VBO_FLAG_MULTIPACK = 1<<1,
/* 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;
CoglAttributeBuffer *attribute_buffer;
size_t buffer_bytes;
GList *attributes;
} CoglVertexBufferVBO;
typedef struct _CoglVertexBufferIndices
{
CoglHandleObject _parent;
CoglIndices *indices;
} CoglVertexBufferIndices;
typedef struct _CoglVertexBuffer
{
CoglHandleObject _parent;
int 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 */
gboolean dirty_attributes;
CoglPrimitive *primitive;
} CoglVertexBuffer;
#endif /* __COGL_VERTEX_BUFFER_H */

File diff suppressed because it is too large Load diff

View file

@ -1,425 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2008,2009 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*
* Authors:
* Robert Bragg <robert@linux.intel.com>
*/
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_VERTEX_BUFFER_H__
#define __COGL_VERTEX_BUFFER_H__
#include <glib.h>
#include <cogl/cogl-defines.h>
#include <cogl/cogl-types.h>
#include <cogl/cogl-macros.h>
G_BEGIN_DECLS
/**
* SECTION:cogl-vertex-buffer
* @short_description: An API for submitting extensible arrays of vertex
* attributes to be mapped into the GPU for fast drawing.
*
* For example to describe a textured triangle, you could create a new cogl
* vertex buffer with 3 vertices, and then you might add 2 attributes for each
* vertex:
* <orderedlist>
* <listitem>
* a "gl_Position" describing the (x,y,z) position for each vertex.
* </listitem>
* <listitem>
* a "gl_MultiTexCoord0" describing the (tx,ty) texture coordinates for each
* vertex.
* </listitem>
* </orderedlist>
*
* The Vertex 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 mapped into your GPU for fast
* re-use. It is designed to avoid repeated validation of the attributes by the
* driver; to minimize transport costs (e.g. considering indirect GLX
* use-cases) and to potentially avoid repeated format conversions when
* attributes are supplied in a format that is not natively supported by the
* GPU.
*
* Although this API does allow you to modify attributes after they have been
* submitted to the GPU you should be aware that modification is not that
* cheap, since it implies validating the new data and potentially the
* OpenGL driver will need to reformat it for the GPU.
*
* If at all possible think of tricks that let you re-use static attributes,
* and if you do need to repeatedly update attributes (e.g. for some kind of
* morphing geometry) then only update and re-submit the specific attributes
* that have changed.
*/
/**
* cogl_vertex_buffer_new:
* @n_vertices: The number of vertices that your attributes will correspond to.
*
* Creates a new vertex buffer that you can use to add attributes.
*
* Return value: a new #CoglHandle
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
CoglHandle
cogl_vertex_buffer_new (unsigned int n_vertices);
/**
* cogl_vertex_buffer_get_n_vertices:
* @handle: A vertex buffer handle
*
* Retrieves the number of vertices that @handle represents
*
* Return value: the number of vertices
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
unsigned int
cogl_vertex_buffer_get_n_vertices (CoglHandle 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 built-in names of 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
* @type: a #CoglAttributeType specifying the data type of each component.
* @normalized: If %TRUE, this specifies that values stored in an integer
* format should be mapped into the range [-1.0, 1.0] or [0.0, 1.0]
* for unsigned values. If %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 either call cogl_vertex_buffer_submit() or
* issue a draw call.
*
* Adds an attribute to a buffer, or replaces a previously added
* attribute with the same name.
*
* You either can use one of the built-in names such as "gl_Vertex", or
* "gl_MultiTexCoord0" to add standard attributes, like positions, colors
* and normals, or you can add custom attributes for use in shaders.
*
* The number of vertices declared when calling cogl_vertex_buffer_new()
* determines how many attribute values will be read from the supplied
* @pointer.
*
* The data for your attribute isn't copied anywhere until you call
* cogl_vertex_buffer_submit(), or issue a draw call which automatically
* submits pending attribute changes. so the supplied pointer must remain
* valid until then. If you are updating an existing attribute (done by
* re-adding it) then you still 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 each interleaved
* attribute starts no farther than +- stride bytes from the other attributes
* it is interleved with. I.e. this is ok:
* <programlisting>
* |-0-0-0-0-0-0-0-0-0-0|
* </programlisting>
* This is not ok:
* <programlisting>
* |- - - - -0-0-0-0-0-0 0 0 0 0|
* </programlisting>
* (Though you can have multiple groups of interleved attributes)</note>
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_add (CoglHandle handle,
const char *attribute_name,
uint8_t n_components,
CoglAttributeType type,
gboolean normalized,
uint16_t stride,
const void *pointer);
/**
* cogl_vertex_buffer_delete:
* @handle: A vertex buffer handle
* @attribute_name: The name of a previously added attribute
*
* Deletes an attribute from a buffer. You will need to call
* cogl_vertex_buffer_submit() or issue a draw call to commit this
* change to the GPU.
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_delete (CoglHandle handle,
const char *attribute_name);
/**
* cogl_vertex_buffer_submit:
* @handle: A vertex buffer handle
*
* Submits all the user added attributes to the GPU; once submitted, the
* attributes can be used for drawing.
*
* You should aim to minimize calls to this function since it implies
* validating your data; it potentially incurs a transport cost (especially if
* you are using GLX indirect rendering) and potentially a format conversion
* cost if the GPU doesn't natively support any of the given attribute formats.
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
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
*
* Disables a previosuly added attribute.
*
* 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.
*
* You don't need to call cogl_vertex_buffer_submit() after using this
* function.
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_disable (CoglHandle handle,
const char *attribute_name);
/**
* cogl_vertex_buffer_enable:
* @handle: A vertex buffer handle
* @attribute_name: The name of the attribute you want to enable
*
* Enables a previosuly disabled attribute.
*
* 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.
*
* You don't need to call cogl_vertex_buffer_submit() after using this function
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_enable (CoglHandle handle,
const char *attribute_name);
/**
* cogl_vertex_buffer_draw:
* @handle: A vertex buffer handle
* @mode: A #CoglVerticesMode specifying how the vertices should be
* interpreted.
* @first: Specifies the index of the first vertex you want to draw with
* @count: Specifies the number of vertices you want to draw.
*
* Allows you to draw geometry using all or a subset of the
* vertices in a vertex buffer.
*
* Any un-submitted attribute changes are automatically submitted before
* drawing.
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_draw (CoglHandle handle,
CoglVerticesMode mode,
int first,
int count);
/**
* cogl_vertex_buffer_indices_new: (skip)
* @indices_type: a #CoglIndicesType specifying the data type used for
* the indices.
* @indices_array: (array length=indices_len): Specifies the address of
* your array of indices
* @indices_len: The number of indices in indices_array
*
* Depending on how much geometry you are submitting it can be worthwhile
* optimizing the number of redundant vertices you submit. Using an index
* array allows you to reference vertices multiple times, for example
* during triangle strips.
*
* Return value: A CoglHandle for the indices which you can pass to
* cogl_vertex_buffer_draw_elements().
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
CoglHandle
cogl_vertex_buffer_indices_new (CoglIndicesType indices_type,
const void *indices_array,
int indices_len);
/**
* cogl_vertex_buffer_indices_get_type:
* @indices: An indices handle
*
* Queries back the data type used for the given indices
*
* Returns: The CoglIndicesType used
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
CoglIndicesType
cogl_vertex_buffer_indices_get_type (CoglHandle indices);
/**
* cogl_vertex_buffer_draw_elements:
* @handle: A vertex buffer handle
* @mode: A #CoglVerticesMode specifying how the vertices should be
* interpreted.
* @indices: A CoglHandle for a set of indices allocated via
* cogl_vertex_buffer_indices_new ()
* @min_index: Specifies the minimum vertex index contained in indices
* @max_index: Specifies the maximum vertex index contained in indices
* @indices_offset: An offset into named indices. The offset marks the first
* index to use for drawing.
* @count: Specifies the number of vertices you want to draw.
*
* This function lets you use an array of indices to specify the vertices
* within your vertex buffer that you want to draw. The indices themselves
* are created by calling cogl_vertex_buffer_indices_new ()
*
* Any un-submitted attribute changes are automatically submitted before
* drawing.
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
void
cogl_vertex_buffer_draw_elements (CoglHandle handle,
CoglVerticesMode mode,
CoglHandle indices,
int min_index,
int max_index,
int indices_offset,
int count);
/**
* cogl_vertex_buffer_indices_get_for_quads:
* @n_indices: the number of indices in the vertex buffer.
*
* Creates a vertex buffer containing the indices needed to draw pairs
* of triangles from a list of vertices grouped as quads. There will
* be at least @n_indices entries in the buffer (but there may be
* more).
*
* The indices will follow this pattern:
*
* 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7 ... etc
*
* For example, if you submit vertices for a quad like like that shown
* in <xref linkend="quad-indices-order"/> then you can request 6
* indices to render two triangles like those shown in <xref
* linkend="quad-indices-triangles"/>.
*
* <figure id="quad-indices-order">
* <title>Example of vertices submitted to form a quad</title>
* <graphic fileref="quad-indices-order.png" format="PNG"/>
* </figure>
*
* <figure id="quad-indices-triangles">
* <title>Illustration of the triangle indices that will be generated</title>
* <graphic fileref="quad-indices-triangles.png" format="PNG"/>
* </figure>
*
* Returns: A %CoglHandle containing the indices. The handled is
* owned by Cogl and should not be modified or unref'd.
*
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
CoglHandle
cogl_vertex_buffer_indices_get_for_quads (unsigned int n_indices);
/**
* cogl_is_vertex_buffer:
* @handle: a #CoglHandle for a vertex buffer object
*
* Checks whether @handle is a Vertex Buffer Object
*
* Return value: %TRUE if the handle is a VBO, and %FALSE
* otherwise
*
* Since: 1.0
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
gboolean
cogl_is_vertex_buffer (CoglHandle handle);
/**
* cogl_is_vertex_buffer_indices:
* @handle: a #CoglHandle
*
* Checks whether @handle is a handle to the indices for a vertex
* buffer object
*
* Return value: %TRUE if the handle is indices, and %FALSE
* otherwise
*
* Since: 1.4
* Deprecated: 1.16: Use the #CoglPrimitive api instead
*/
COGL_DEPRECATED_FOR (cogl_primitive_API)
gboolean
cogl_is_vertex_buffer_indices (CoglHandle handle);
G_END_DECLS
#endif /* __COGL_VERTEX_BUFFER_H__ */

View file

@ -985,7 +985,7 @@ fragend_add_layer_cb (CoglPipelineLayer *layer,
*
* Currently for textured rectangles we manually calculate the texture
* coords for each slice based on the users given coords, but this solution
* isn't ideal, and can't be used with CoglVertexBuffers.
* isn't ideal.
*/
void
_cogl_pipeline_flush_gl_state (CoglContext *ctx,

View file

@ -65,7 +65,6 @@ built_headers += [cogl_gl_header_h]
cogl_deprecated_headers = [
'deprecated/cogl-material-compat.h',
'deprecated/cogl-vertex-buffer.h',
'deprecated/cogl-shader.h',
'deprecated/cogl-clutter.h',
'deprecated/cogl-type-casts.h',
@ -352,8 +351,6 @@ cogl_sources = [
'cogl-closure-list.c',
'cogl-fence.c',
'cogl-fence-private.h',
'deprecated/cogl-vertex-buffer-private.h',
'deprecated/cogl-vertex-buffer.c',
'deprecated/cogl-material-compat.c',
'deprecated/cogl-program.c',
'deprecated/cogl-program-private.h',

View file

@ -54,8 +54,6 @@ cogl_test_conformance_sources = [
# "test-readpixels.c",
# "test-texture-mipmaps.c",
# "test-texture-pixmap-x11.c",",
# "test-vertex-buffer-contiguous.c",
# "test-vertex-buffer-interleved.c",
#]
cogl_test_conformance_includes = [

View file

@ -1,259 +0,0 @@
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "test-conform-common.h"
/* 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.
*
* 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 buffer;
CoglHandle texture;
CoglHandle material;
ClutterGeometry stage_geom;
} TestState;
static void
validate_result (TestState *state)
{
GLubyte pixel[4];
GLint y_off = 90;
if (cogl_test_verbose ())
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 */
cogl_read_pixels (10, y_off, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_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 */
cogl_read_pixels (110, y_off, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_test_verbose ())
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 */
cogl_read_pixels (210, y_off, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_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);
/* Should see a green pixel, at bottom of 4th triangle */
cogl_read_pixels (310, y_off, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_test_verbose ())
g_print ("pixel 3 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[GREEN] > pixel[RED] && pixel[GREEN] > pixel[BLUE]);
/* Should see a red pixel, at top of 4th triangle */
cogl_read_pixels (310, y_off - 70, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_test_verbose ())
g_print ("pixel 4 = %x, %x, %x\n", pixel[RED], pixel[GREEN], pixel[BLUE]);
g_assert (pixel[RED] > pixel[GREEN] && pixel[RED] > pixel[BLUE]);
#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,
ClutterPaintContext *paint_context,
TestState *state)
{
/* Draw a faded blue triangle */
cogl_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
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_vertex_buffer_disable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
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_vertex_buffer_enable (state->buffer, "gl_Color::blue");
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
/* Draw a textured triangle */
cogl_translate (100, 0, 0);
cogl_vertex_buffer_disable (state->buffer, "gl_Color::blue");
cogl_set_source (state->material);
cogl_material_set_color4ub (state->material, 0xff, 0xff, 0xff, 0xff);
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
validate_result (state);
}
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
return TRUE;
}
void
test_vertex_buffer_contiguous (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;
ClutterActor *stage;
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
ClutterActor *group;
unsigned int idle_source;
guchar tex_data[] = {
0xff, 0x00, 0x00, 0xff,
0xff, 0x00, 0x00, 0xff,
0x00, 0xff, 0x00, 0xff,
0x00, 0xff, 0x00, 0xff
};
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 incase someone comments out the
* clutter_main_quit and wants visual feedback for the test since we
* wont be doing anything else that will trigger redrawing. */
idle_source = g_idle_add (queue_redraw, stage);
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
state.texture = cogl_texture_new_from_data (2, 2,
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
0, /* auto calc row stride */
tex_data);
state.material = cogl_material_new ();
cogl_material_set_color4ub (state.material, 0x00, 0xff, 0x00, 0xff);
cogl_material_set_layer (state.material, 0, state.texture);
{
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 */
};
GLfloat triangle_tex_coords[3][2] =
{
{0.0, 0.0},
{1.0, 1.0},
{0.0, 1.0}
};
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_add (state.buffer,
"gl_MultiTexCoord0",
2, /* n components */
GL_FLOAT,
FALSE, /* normalized */
0, /* stride */
triangle_tex_coords);
cogl_vertex_buffer_submit (state.buffer);
}
clutter_actor_show_all (stage);
clutter_main ();
cogl_object_unref (state.buffer);
cogl_object_unref (state.material);
cogl_object_unref (state.texture);
g_clear_handle_id (&idle_source, g_source_remove);
if (cogl_test_verbose ())
g_print ("OK\n");
}

View file

@ -1,164 +0,0 @@
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "test-conform-common.h"
/* 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.
*/
typedef struct _TestState
{
CoglHandle buffer;
ClutterGeometry stage_geom;
} 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 = 90;
/* 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 */
cogl_read_pixels (10, y_off, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (cogl_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.
*/
clutter_main_quit ();
}
static void
on_paint (ClutterActor *actor,
ClutterPaintContext *paint_context,
TestState *state)
{
/* Draw a faded blue triangle */
cogl_vertex_buffer_draw (state->buffer,
GL_TRIANGLE_STRIP, /* mode */
0, /* first */
3); /* count */
validate_result (state);
}
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
return TRUE;
}
void
test_vertex_buffer_interleved (TestUtilsGTestFixture *fixture,
void *data)
{
TestState state;
ClutterActor *stage;
ClutterColor stage_clr = {0x0, 0x0, 0x0, 0xff};
ClutterActor *group;
unsigned int idle_source;
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 incase someone comments out the
* clutter_main_quit and wants visual feedback for the test since we
* wont be doing anything else that will trigger redrawing. */
idle_source = 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.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_object_unref (state.buffer);
g_clear_handle_id (&idle_source, g_source_remove);
if (cogl_test_verbose ())
g_print ("OK\n");
}

View file

@ -139,43 +139,6 @@ draw_tests_polygon (TestState *state)
}
}
static void
draw_tests_vbo (TestState *state)
{
CoglHandle vbo;
int i;
vbo = cogl_vertex_buffer_new (4);
cogl_vertex_buffer_add (vbo, "gl_Vertex", 3,
COGL_ATTRIBUTE_TYPE_FLOAT, FALSE,
sizeof (vertices[0]),
&vertices[0].x);
cogl_vertex_buffer_add (vbo, "gl_MultiTexCoord0", 2,
COGL_ATTRIBUTE_TYPE_FLOAT, FALSE,
sizeof (vertices[0]),
&vertices[0].tx);
cogl_vertex_buffer_submit (vbo);
for (i = 0; i < G_N_ELEMENTS (wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
CoglPipeline *pipeline;
wrap_mode_s = wrap_modes[i];
wrap_mode_t = wrap_modes[i + 1];
pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (pipeline);
cogl_object_unref (pipeline);
cogl_push_matrix ();
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f);
/* Render the pipeline at four times the size of the texture */
cogl_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_TRIANGLE_FAN, 0, 4);
cogl_pop_matrix ();
}
cogl_object_unref (vbo);
}
static void
validate_set (TestState *state, int offset)
{
@ -232,7 +195,6 @@ validate_result (TestState *state)
validate_set (state, 1); /* atlased rectangle */
#endif
validate_set (state, 2); /* cogl_polygon */
validate_set (state, 3); /* vertex buffer */
}
static void
@ -260,14 +222,6 @@ paint (TestState *state)
cogl_pop_matrix ();
cogl_object_unref (state->texture);
/* Draw the tests using a vertex buffer */
state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS);
cogl_push_matrix ();
cogl_translate (0.0f, TEX_SIZE * 6.0f, 0.0f);
draw_tests_vbo (state);
cogl_pop_matrix ();
cogl_object_unref (state->texture);
validate_result (state);
}

View file

@ -36,7 +36,6 @@ clutter_tests_interactive_test_sources = [
'test-text-field.c',
'test-cairo-clock.c',
'test-cairo-flowers.c',
'test-cogl-vertex-buffer.c',
'test-stage-sizing.c',
'test-scrolling.c',
'test-swipe-action.c',

View file

@ -102,7 +102,6 @@ paint_cb (ClutterActor *stage,
CoglMatrix old_matrix, new_matrix;
int i;
float diff_time;
CoglHandle vbo;
cogl_get_projection_matrix (&old_matrix);
/* Use an orthogonal projection from -1 -> 1 in both axes */
@ -197,22 +196,6 @@ paint_cb (ClutterActor *stage,
g_timer_reset (data->last_spark_time);
}
vbo = cogl_vertex_buffer_new (N_SPARKS);
cogl_vertex_buffer_add (vbo, "gl_Vertex", 2,
COGL_ATTRIBUTE_TYPE_FLOAT, FALSE,
sizeof (Spark),
&data->sparks[0].x);
cogl_vertex_buffer_add (vbo, "gl_Color", 4,
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE, TRUE,
sizeof (Spark),
&data->sparks[0].color.red);
cogl_vertex_buffer_submit (vbo);
cogl_set_source (data->material);
cogl_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_POINTS, 0, N_SPARKS);
cogl_object_unref (vbo);
cogl_set_projection_matrix (&old_matrix);
cogl_pop_matrix ();
}

View file

@ -1,398 +0,0 @@
#include <glib.h>
#include <gmodule.h>
#include <stdlib.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <math.h>
/* Defines the size and resolution of the quad mesh we morph:
*/
#define MESH_WIDTH 100.0 /* number of quads along x axis */
#define MESH_HEIGHT 100.0 /* number of quads along y axis */
#define QUAD_WIDTH 5.0 /* width in pixels of a single quad */
#define QUAD_HEIGHT 5.0 /* height in pixels of a single quad */
/* Defines a sine wave that sweeps across the mesh:
*/
#define WAVE_DEPTH ((MESH_WIDTH * QUAD_WIDTH) / 16.0) /* peak amplitude */
#define WAVE_PERIODS 4.0
#define WAVE_SPEED 10.0
/* Defines a rippling sine wave emitted from a point:
*/
#define RIPPLE_CENTER_X ((MESH_WIDTH / 2.0) * QUAD_WIDTH)
#define RIPPLE_CENTER_Y ((MESH_HEIGHT / 2.0) * QUAD_HEIGHT)
#define RIPPLE_RADIUS (MESH_WIDTH * QUAD_WIDTH)
#define RIPPLE_DEPTH ((MESH_WIDTH * QUAD_WIDTH) / 16.0) /* peak amplitude */
#define RIPPLE_PERIODS 4.0
#define RIPPLE_SPEED -10.0
/* Defines the width of the gaussian bell used to fade out the alpha
* towards the edges of the mesh (starting from the ripple center):
*/
#define GAUSSIAN_RADIUS ((MESH_WIDTH * QUAD_WIDTH) / 6.0)
/* Our hues lie in the range [0, 1], and this defines how we map amplitude
* to hues (before scaling by {WAVE,RIPPLE}_DEPTH)
* As we are interferring two sine waves together; amplitudes lie in the
* range [-2, 2]
*/
#define HSL_OFFSET 0.5 /* the hue that we map an amplitude of 0 too */
#define HSL_SCALE 0.25
typedef struct _TestState
{
ClutterActor *dummy;
CoglHandle buffer;
float *quad_mesh_verts;
guint8 *quad_mesh_colors;
guint16 *static_indices;
guint n_static_indices;
CoglHandle indices;
ClutterTimeline *timeline;
guint frame_id;
} TestState;
int
test_cogl_vertex_buffer_main (int argc, char *argv[]);
const char *
test_cogl_vertex_buffer_describe (void);
static void
frame_cb (ClutterTimeline *timeline,
gint elapsed_msecs,
TestState *state)
{
guint x, y;
float period_progress = clutter_timeline_get_progress (timeline);
float period_progress_sin = sinf (period_progress);
float wave_shift = period_progress * WAVE_SPEED;
float ripple_shift = period_progress * RIPPLE_SPEED;
for (y = 0; y <= MESH_HEIGHT; y++)
for (x = 0; x <= MESH_WIDTH; x++)
{
guint vert_index = (MESH_WIDTH + 1) * y + x;
float *vert = &state->quad_mesh_verts[3 * vert_index];
float real_x = x * QUAD_WIDTH;
float real_y = y * QUAD_HEIGHT;
float wave_offset = (float)x / (MESH_WIDTH + 1);
float wave_angle =
(WAVE_PERIODS * 2 * G_PI * wave_offset) + wave_shift;
float wave_sin = sinf (wave_angle);
float a_sqr = (RIPPLE_CENTER_X - real_x) * (RIPPLE_CENTER_X - real_x);
float b_sqr = (RIPPLE_CENTER_Y - real_y) * (RIPPLE_CENTER_Y - real_y);
float ripple_offset = sqrtf (a_sqr + b_sqr) / RIPPLE_RADIUS;
float ripple_angle =
(RIPPLE_PERIODS * 2 * G_PI * ripple_offset) + ripple_shift;
float ripple_sin = sinf (ripple_angle);
float h, s, l;
guint8 *color;
vert[2] = (wave_sin * WAVE_DEPTH) + (ripple_sin * RIPPLE_DEPTH);
/* Burn some CPU time picking a pretty color... */
h = (HSL_OFFSET
+ wave_sin
+ ripple_sin
+ period_progress_sin) * HSL_SCALE;
s = 0.5;
l = 0.25 + (period_progress_sin + 1.0) / 4.0;
color = &state->quad_mesh_colors[4 * vert_index];
/* A bit of a sneaky cast, but it seems safe to assume the ClutterColor
* typedef is set in stone... */
clutter_color_from_hls ((ClutterColor *)color, h * 360.0, l, s);
color[0] = (color[0] * color[3] + 128) / 255;
color[1] = (color[1] * color[3] + 128) / 255;
color[2] = (color[2] * color[3] + 128) / 255;
}
cogl_vertex_buffer_add (state->buffer,
"gl_Vertex",
3, /* n components */
COGL_ATTRIBUTE_TYPE_FLOAT,
FALSE, /* normalized */
0, /* stride */
state->quad_mesh_verts);
cogl_vertex_buffer_add (state->buffer,
"gl_Color",
4, /* n components */
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
state->quad_mesh_colors);
cogl_vertex_buffer_submit (state->buffer);
clutter_actor_set_rotation (state->dummy,
CLUTTER_Z_AXIS,
360 * period_progress,
(MESH_WIDTH * QUAD_WIDTH) / 2,
(MESH_HEIGHT * QUAD_HEIGHT) / 2,
0);
clutter_actor_set_rotation (state->dummy,
CLUTTER_X_AXIS,
360 * period_progress,
(MESH_WIDTH * QUAD_WIDTH) / 2,
(MESH_HEIGHT * QUAD_HEIGHT) / 2,
0);
}
static void
on_paint (ClutterActor *actor,
ClutterPaintContext *paint_context,
TestState *state)
{
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
cogl_vertex_buffer_draw_elements (state->buffer,
COGL_VERTICES_MODE_TRIANGLE_STRIP,
state->indices,
0, /* min index */
(MESH_WIDTH + 1) *
(MESH_HEIGHT + 1) - 1, /* max index */
0, /* indices offset */
state->n_static_indices);
}
static void
init_static_index_arrays (TestState *state)
{
guint n_indices;
int x, y;
guint16 *i;
guint dir;
/* - Each row takes (2 + 2 * MESH_WIDTH indices)
* - Thats 2 to start the triangle strip then 2 indices to add 2 triangles
* per mesh quad.
* - We have MESH_HEIGHT rows
* - It takes one extra index for linking between rows (MESH_HEIGHT - 1)
* - A 2 x 3 mesh == 20 indices... */
n_indices = (2 + 2 * MESH_WIDTH) * MESH_HEIGHT + (MESH_HEIGHT - 1);
state->static_indices = g_malloc (sizeof (guint16) * n_indices);
state->n_static_indices = n_indices;
#define MESH_INDEX(X, Y) (Y) * (MESH_WIDTH + 1) + (X)
i = state->static_indices;
/* NB: front facing == anti-clockwise winding */
i[0] = MESH_INDEX (0, 0);
i[1] = MESH_INDEX (0, 1);
i += 2;
#define LEFT 0
#define RIGHT 1
dir = RIGHT;
for (y = 0; y < MESH_HEIGHT; y++)
{
for (x = 0; x < MESH_WIDTH; x++)
{
/* Add 2 triangles per mesh quad... */
if (dir == RIGHT)
{
i[0] = MESH_INDEX (x + 1, y);
i[1] = MESH_INDEX (x + 1, y + 1);
}
else
{
i[0] = MESH_INDEX (MESH_WIDTH - x - 1, y);
i[1] = MESH_INDEX (MESH_WIDTH - x - 1, y + 1);
}
i += 2;
}
/* Link rows... */
if (y == (MESH_HEIGHT - 1))
break;
if (dir == RIGHT)
{
i[0] = MESH_INDEX (MESH_WIDTH, y + 1);
i[1] = MESH_INDEX (MESH_WIDTH, y + 1);
i[2] = MESH_INDEX (MESH_WIDTH, y + 2);
}
else
{
i[0] = MESH_INDEX (0, y + 1);
i[1] = MESH_INDEX (0, y + 1);
i[2] = MESH_INDEX (0, y + 2);
}
i += 3;
dir = !dir;
}
#undef MESH_INDEX
state->indices =
cogl_vertex_buffer_indices_new (COGL_INDICES_TYPE_UNSIGNED_SHORT,
state->static_indices,
state->n_static_indices);
}
static float
gaussian (float x, float y)
{
/* Bell width */
float c = GAUSSIAN_RADIUS;
/* Peak amplitude */
float a = 1.0;
/* float a = 1.0 / (c * sqrtf (2.0 * G_PI)); */
/* Center offset */
float b = 0.0;
float dist;
x = x - RIPPLE_CENTER_X;
y = y - RIPPLE_CENTER_Y;
dist = sqrtf (x*x + y*y);
return a * exp ((- ((dist - b) * (dist - b))) / (2.0 * c * c));
}
static void
init_quad_mesh (TestState *state)
{
int x, y;
float *vert;
guint8 *color;
/* Note: we maintain the minimum number of vertices possible. This minimizes
* the work required when we come to morph the geometry.
*
* We use static indices into our mesh so that we can treat the data like a
* single triangle list and drawing can be done in one operation (Note: We
* are using degenerate triangles at the edges to link to the next row)
*/
state->quad_mesh_verts =
g_malloc0 (sizeof (float) * 3 * (MESH_WIDTH + 1) * (MESH_HEIGHT + 1));
state->quad_mesh_colors =
g_malloc0 (sizeof (guint8) * 4 * (MESH_WIDTH + 1) * (MESH_HEIGHT + 1));
vert = state->quad_mesh_verts;
color = state->quad_mesh_colors;
for (y = 0; y <= MESH_HEIGHT; y++)
for (x = 0; x <= MESH_WIDTH; x++)
{
vert[0] = x * QUAD_WIDTH;
vert[1] = y * QUAD_HEIGHT;
vert += 3;
color[3] = gaussian (x * QUAD_WIDTH,
y * QUAD_HEIGHT) * 255.0;
color += 4;
}
state->buffer = cogl_vertex_buffer_new ((MESH_WIDTH + 1)*(MESH_HEIGHT + 1));
cogl_vertex_buffer_add (state->buffer,
"gl_Vertex",
3, /* n components */
COGL_ATTRIBUTE_TYPE_FLOAT,
FALSE, /* normalized */
0, /* stride */
state->quad_mesh_verts);
cogl_vertex_buffer_add (state->buffer,
"gl_Color",
4, /* n components */
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE,
FALSE, /* normalized */
0, /* stride */
state->quad_mesh_colors);
cogl_vertex_buffer_submit (state->buffer);
init_static_index_arrays (state);
}
/* This creates an actor that has a specific size but that does not result
* in any drawing so we can do our own drawing using Cogl... */
static ClutterActor *
create_dummy_actor (guint width, guint height)
{
ClutterActor *group, *rect;
ClutterColor clr = { 0xff, 0xff, 0xff, 0xff};
group = clutter_group_new ();
rect = clutter_rectangle_new_with_color (&clr);
clutter_actor_set_size (rect, width, height);
clutter_actor_hide (rect);
clutter_container_add_actor (CLUTTER_CONTAINER (group), rect);
return group;
}
static void
stop_and_quit (ClutterActor *actor,
TestState *state)
{
clutter_timeline_stop (state->timeline);
clutter_main_quit ();
}
G_MODULE_EXPORT int
test_cogl_vertex_buffer_main (int argc, char *argv[])
{
TestState state;
ClutterActor *stage;
gfloat stage_w, stage_h;
gint dummy_width, dummy_height;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
stage = clutter_stage_new ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Vertex Buffers");
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
g_signal_connect (stage, "destroy", G_CALLBACK (stop_and_quit), &state);
clutter_actor_get_size (stage, &stage_w, &stage_h);
dummy_width = MESH_WIDTH * QUAD_WIDTH;
dummy_height = MESH_HEIGHT * QUAD_HEIGHT;
state.dummy = create_dummy_actor (dummy_width, dummy_height);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), state.dummy);
clutter_actor_set_position (state.dummy,
(stage_w / 2.0) - (dummy_width / 2.0),
(stage_h / 2.0) - (dummy_height / 2.0));
state.timeline = clutter_timeline_new (1000);
clutter_timeline_set_loop (state.timeline, TRUE);
state.frame_id = g_signal_connect (state.timeline,
"new-frame",
G_CALLBACK (frame_cb),
&state);
g_signal_connect (state.dummy, "paint", G_CALLBACK (on_paint), &state);
init_quad_mesh (&state);
clutter_actor_show_all (stage);
clutter_timeline_start (state.timeline);
clutter_main ();
cogl_object_unref (state.buffer);
cogl_object_unref (state.indices);
return 0;
}
G_MODULE_EXPORT const char *
test_cogl_vertex_buffer_describe (void)
{
return "Vertex buffers support in Cogl.";
}