KGLLib
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
KGLLib::GeometryBuffer Class Reference

Collection of geometry data. More...

#include <geometrybuffer.h>

Inheritance diagram for KGLLib::GeometryBuffer:
KGLLib::GeometryBufferVertexArray KGLLib::GeometryBufferVBO

List of all members.

Classes

struct  AttributeData

Public Member Functions

virtual ~GeometryBuffer ()
virtual void render ()
virtual void renderIndexed (int indices, int offset)=0
virtual void render (int vertices, int offset)=0
virtual bool bind ()
virtual bool unbind ()
void addVertices (void *vertices, int count, int offset=0)
void addColors (void *colors, int count, int offset=0)
void addNormals (void *normals, int count, int offset=0)
void addTexCoords (void *texcoords, int count, int offset=0)
virtual void addIndices (unsigned int *indices, int count, int offset=0)=0
virtual void setPrimitiveType (GLenum type)
GLenum primitiveType () const
const GeometryBufferFormatformat () const

Static Public Member Functions

static GeometryBuffercreateBuffer (const GeometryBufferFormat &format)
static GeometryBuffercreateBuffer (GeometryBufferFormat::Format format, int vertexCount, int indexCount=0)

Protected Member Functions

 GeometryBuffer (const GeometryBufferFormat &format)
virtual void init (const GeometryBufferFormat &format)
int bufferSize () const
int indexBufferSize () const
virtual void addData (void *data, int size, int offset)=0

Protected Attributes

GLenum mPrimitiveType
GeometryBufferFormat mFormat
AttributeData mVertexData
AttributeData mColorData
AttributeData mNormalData
AttributeData mTexCoordData

Detailed Description

Collection of geometry data.

GeometryBuffer object holds vertex and index data and is able to render it. It tries to use the most efficient way for rendering.

Usually you needn't use GeometryBuffer directly: it is used by Batch to store its data.

If you want to create a shared GeometryBuffer and use it for multiple Batch objects, the easiest way is to use Batch::createSharedBuffer() method.

When you specify data for the buffer then an internal copy is made of that data. Thus you can safely delete the data after you have specified it.


Constructor & Destructor Documentation

KGLLib::GeometryBuffer::~GeometryBuffer ( ) [virtual]

Deletes this buffer and frees all allocated resources.

KGLLib::GeometryBuffer::GeometryBuffer ( const GeometryBufferFormat format) [protected]

Member Function Documentation

virtual void KGLLib::GeometryBuffer::addData ( void *  data,
int  size,
int  offset 
) [protected, pure virtual]

Writes data to the internal buffer.

Parameters:
datapointer to the data
sizesize of the data in bytes
offsetoffset of the internal buffer in bytes

Implemented in KGLLib::GeometryBufferVertexArray, and KGLLib::GeometryBufferVBO.

Referenced by addVertices().

virtual void KGLLib::GeometryBuffer::addIndices ( unsigned int *  indices,
int  count,
int  offset = 0 
) [pure virtual]

Sets the indices array to indices. The array must contain at least count entries (if it contains more, then the remaining ones will be unused).

Implemented in KGLLib::GeometryBufferVertexArray, and KGLLib::GeometryBufferVBO.

void KGLLib::GeometryBuffer::addVertices ( void *  vertices,
int  count,
int  offset = 0 
)

Specifies vertex data to be used by this buffer.

Parameters:
verticespointer to the array of vertices.
countnumber of elements in the specified array.
offsetoffset of the first element in the buffer.

This copies count elements from the specified array into the buffer. The first element of the array will be copied to position offset in the buffer.

Each element of the specified array must consist of the same number of floats as specified in the format (GeometryBufferFormat::vertexSize()).

References addData().

virtual bool KGLLib::GeometryBuffer::bind ( ) [inline, virtual]

Binds the buffer. The buffer must be bound before you can use any of the render methods.

See also:
unbind()

Reimplemented in KGLLib::GeometryBufferVertexArray, and KGLLib::GeometryBufferVBO.

int KGLLib::GeometryBuffer::bufferSize ( ) const [protected]
GeometryBuffer * KGLLib::GeometryBuffer::createBuffer ( GeometryBufferFormat::Format  format,
int  vertexCount,
int  indexCount = 0 
) [static]

Creates new GeometryBuffer object, using the specified format and vertex/index counts. This is a convenience method that can be used to avoid creation of the temporary GeometryBufferFormat object.

References createBuffer().

GeometryBuffer * KGLLib::GeometryBuffer::createBuffer ( const GeometryBufferFormat format) [static]

Creates new GeometryBuffer object, using the specified format.

The GeometryBuffer type (subclass) that is used is chosen automatically depending on hardware features.

Static buffer creation helper methods

Referenced by createBuffer().

const GeometryBufferFormat& KGLLib::GeometryBuffer::format ( ) const [inline]
int KGLLib::GeometryBuffer::indexBufferSize ( ) const [protected]

Calculates size of the index buffer (in bytes) according to current format.

References format(), and KGLLib::GeometryBufferFormat::indexCount().

GLenum KGLLib::GeometryBuffer::primitiveType ( ) const [inline]
Returns:
OpenGL primitive mode used to render this batch.
void KGLLib::GeometryBuffer::render ( ) [virtual]

Renders entire contents of the buffer. The buffer must be bound (by calling the bind() method) before it can be used.

See also:
bind(), unbind(), render(int, int), renderIndexed()

References format(), and renderIndexed().

virtual void KGLLib::GeometryBuffer::render ( int  vertices,
int  offset 
) [pure virtual]

Renders a subset of non-indexed buffer data. The buffer must be bound (by calling the bind() method) before it can be used.

Parameters:
indicesnumber of vertices to use.
offsetarray index of the first vertex to use.
See also:
render(), renderIndexed(), bind(), unbind()

Implemented in KGLLib::GeometryBufferVertexArray.

virtual void KGLLib::GeometryBuffer::renderIndexed ( int  indices,
int  offset 
) [pure virtual]

Renders a subset of indexed buffer data. The buffer must be bound (by calling the bind() method) before it can be used.

Parameters:
indicesnumber of indices to use.
offsetarray index of the first index to use.
See also:
render(), render(int, int), bind(), unbind()

Implemented in KGLLib::GeometryBufferVertexArray.

Referenced by render().

void KGLLib::GeometryBuffer::setPrimitiveType ( GLenum  type) [virtual]

Sets the primitive type used to render this batch (e.g. GL_QUADS).

Default value is GL_TRIANGLES.

virtual bool KGLLib::GeometryBuffer::unbind ( ) [inline, virtual]

Unbinds the buffer.

See also:
bind()

Reimplemented in KGLLib::GeometryBufferVertexArray, and KGLLib::GeometryBufferVBO.


The documentation for this class was generated from the following files: