glodFillElements - Rather than drawing a patch, this places what
would be drawn into the current OpenGL vertex/normal/color/texcoord
and index arrays.
void glodFillElements(GLuint object_name, GLuint patch_name,
GLenum type, GLvoid* out_elements)
- object_name, patch_name
Selects the object and patch to read back.
Specifies the type of values in indices. May be
GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT or GL_UNSIGNED_INT.
Specifies a pointer to the location where indices will be stored
after this call. You must allocate this pointer yourself.
glodFillElements is used to ``see'' what GLOD will draw if you were to
call glodDrawPatch. To read back the current state of an object using
glodFillElements, you usually:
glodGetObjectParameter(obj, patch, GLOD_PATCH_SIZES,
dst_arry) to obtain the number of vertices and indices (=triangles*3) that
glodFillElements or glodDrawPatch will issue.
Allocate buffers for vertices and any other data that you want to read
back according to the vertex count gotten from the previous
Set the vertx array state (glVertexPointer etc) to match your allocated
Allocate space for the indices that glodFillElements is going to use
according to the index count from the first call
Call glodFillElements with this index array
When this call returns, the currently set array pointers will have
been filled in with the current GLOD cut. It is critical that the
buffers to which the pointers refer are large enough to accomodate the
cut. Otherwise, memory corruption will occur.
The following code reads back the zero-th patch in
object 0. It is
assumed that the object consists of 1 patch and that the zero-th patch
is named zero. If these assumptions do not hold, you will need an
extra layer of indirection that uses the glodGetObjectParamiv
GLOD_NUM_PATCHES and GLOD_PATCH_NAMES feature to make this code fully generic.
// get the size of this patch
GLfloat* vert_buf, *normal_buf; unsigned int* idx_buf;
glodGetObjectParamiv(0, GLOD_PATCH_SIZES, dims);
numIndices = dims;
numVerts = dims; // we ignore this value for glodFillArrays
idx_buf = malloc(sizeof(unsigned int) idx_buf * numIndices);
vert_buf = malloc(sizeof(float) * numVerts);
normal_buf = malloc(sizeof(float) * numVerts);
glVertexPointer(3, GL_FLOAT, 0, vert_buf);
glNormalPointer(GL_FLOAT, 0, normal_buf);
glFillElements(0, 0, GL_UNSIGNED_INT, idx_buf);
// now, vert_buf and normal_buf contain a copy of
// object 0, patch 0's current geometry
// and idx_buf contains triples of triangle indices into these
// arrays just like with glDrawElements