Clutter Wiki

Views
From ClutterProject
Jump to: navigation, search

CoglVertexAttribute

Describes the layout of a single vertex attribute within a given CoglVertexArray including:

  • offset
  • stride
  • type
  • n_components
  • normalized

Note: this is named CoglVertexAttribute not CoglAttribute as it was originally because we might want other kinds of "attributes" in the API later and this could end up being confusing.

cogl_vertex_attribute_new (array, name, type, n_components, stride, offset);
  • Unlike OpenGL we don't have allow a special stride value 0, the view being that it causes more confusion than it is convenient.
  • It takes a reference on the given array

#define cogl_vertex_attribute_new_for_vertex_struct (array, name, type, n_components, VertexType, member)

  • It seems that the "convenience" of this macro perhaps isn't worthwhile since it has the same number of arguments as the raw version and by taking type and member args its a bit unusual and potentially confusing.
cogl_vertex_attribute_set_normalized (attrib, TRUE);

How to draw with CoglVertexAttributes:

cogl_vertex_attributes_draw (mode, n_vertices, attrib0, attrib1, ... NULL);
cogl_vertex_attributes_draw_range (mode, first_vertex, n_vertices, attrib0, attrib1, ... NULL);
cogl_vertex_attributes_draw_with_indices (mode, n_vertices, indices, attrib0, attrib1, ... NULL);
cogl_vertex_attributes_draw_range_with_indices (mode, first_vertex, n_vertices, indices, attrib0, attrib1, ... NULL);

Example usage:

attrib = cogl_vertex_attribute_new (array,
                                    "gl_Color",
                                    COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE,
                                    3,
                                    sizeof (MyVertex),
                                    offsetof (MyVertex, red));
cogl_attribute_set_normalized (attrib, TRUE)

/* XXX: I wonder if a macro like this might actually make code a bit confusing to read?
 * I.e. On initial inspection before you know it's a macro you may be trying to find
 * where the "x" variable is defined? It's also the same number of arguments as the
 * raw API which actually seems more self documenting due to the use of "sizeof" and
 * "offsetof".
 */
attrib = attribute_new_for_vertex_struct (array,
					  "gl_Color",
					  COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE,
					  3,
					  MyVertex,
					  x);

Personal tools