• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KGLLib

KGLLib::Batch

KGLLib::Batch Class Reference

#include <batch.h>

Inheritance diagram for KGLLib::Batch:

Inheritance graph
[legend]

List of all members.


Detailed Description

A set of geometry.

Batch class contains geometry data which is necessary for rendering something. This data can include vertices, normals, texture coordinates and vertex colors.

Batch object can automatically use VBOs (vertex buffer objects) for improved rendering performance while falling back to traditional vertex arrays on systems where VBOs are not supported.

To use it, you need to construct the Batch object, set the necessary arrays and then call the render() method:

  // Create the Batch object
  Batch* b = new Batch();
  b->setVertices(myvertices);
  b->setTexCoords(mytexcoords);
  b->setPrimitiveType(GL_TRIANGLES);
  ...
  // In your rendering loop:
  b->render();
  // some textured triangles will be rendered.

Modes

Batch uses a GeometryBuffer object to store its data and can be used in two modes: with internal or shared buffer.

With internal buffer

With internal buffer, Batch creates is own GeometryBuffer object when update() is called (which is called automatically by render() and bind() when batch's data has changed).

This is the easiest mode to use: you only need to create the Batch objects, give it some data and then call render() to render the geometry.

With shared buffer

The other mode uses a single GeometryBuffer object which is shared between multiple Batch objects. The advantage of this mode is that bind() and unbind(), which might be expensive operations, only need to be called once per frame instead of once per rendered Batch.

To make multiple batches use a shared buffer, the easiest way is to call createSharedBuffer() method. It will automatically create a large enough buffer and make all the batches use it.

 // First create all batches and specify data (using setVertices() and friends)
 QList<Batch*> models = loadAllModels();
 // Then create a shared GeometryBuffer
 Batch::createSharedBuffer(models);

After that you will need to bind() the buffer or batch only once and then just call renderOnce() for each batch that uses the same buffer. Of course finally unbind() has to be called as well:

 // It doesn't matter which Batch we bind() since they all use the same buffer
 models.first()-> bind();
 // Render all models
 foreach (Batch* b, models) {
     b-> renderOnce();
 }
 // Finally unbind the buffer
 models.first()-> unbind();

See also:
Mesh, GeometryBuffer

Definition at line 100 of file batch.h.


Public Member Functions

 Batch (GeometryBuffer *buffer, int offset, int indexOffset)
 Batch ()
GeometryBufferFormat bestBufferFormat () const
virtual void bind ()
GeometryBuffer * buffer () const
const void * colorsArray () const
const void * indicesArray () const
int indicesCount () const
const void * normalsArray () const
GLenum primitiveType () const
virtual void render ()
virtual void renderOnce ()
void setBuffer (GeometryBuffer *buffer, int offset, int indexOffset)
void setColors (Eigen::Vector4f *colors)
void setColors (Eigen::Vector3f *colors)
void setIndices (unsigned int *indices, int count)
void setNormals (Eigen::Vector3f *normals)
virtual void setPrimitiveType (GLenum type)
void setTexcoords (Eigen::Vector4f *texcoords)
void setTexcoords (Eigen::Vector3f *texcoords)
void setTexcoords (Eigen::Vector2f *texcoords)
void setTexcoords (float *texcoords)
void setVertexCount (int count)
void setVertices (Eigen::Vector4f *vertices)
void setVertices (Eigen::Vector3f *vertices)
void setVertices (Eigen::Vector2f *vertices)
const void * texcoordsArray () const
virtual void unbind ()
virtual void update ()
int vertexCount () const
const void * verticesArray () const
virtual ~Batch ()

Static Public Member Functions

static GeometryBuffer * createSharedBuffer (const QList< Batch * > &batches)

Protected Member Functions

void init ()
void setColors (void *colors, int size)
void setTexcoords (void *texcoords, int size)
void setVertices (void *vertices, int size)

Constructor & Destructor Documentation

KGLLib::Batch::Batch (  ) 

Constructs new Batch object.

An internal GeometryBuffer object will be created before rendering. You will need to set at least vertices array and vertex count before the batch can be rendered.

Definition at line 30 of file batch.cpp.

KGLLib::Batch::Batch ( GeometryBuffer *  buffer,
int  offset,
int  indexOffset 
)

Constructs new Batch object, using a shared GeometryBuffer.

Shared buffers can improve performance since buffers needn't be bound and unbound while rendering.

Parameters:
buffer shared GeometryBuffer object to use
offset offset for the vertex data in the buffer
indexOffset offset for the index data in the buffer

Definition at line 35 of file batch.cpp.

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

Deletes the Batch.

If an internal GeometryBuffer is used then it is also deleted.

Definition at line 56 of file batch.cpp.


Member Function Documentation

GeometryBufferFormat KGLLib::Batch::bestBufferFormat (  )  const

Returns GeometryBufferFormat object that could be used to create a GeometryBuffer object for this Batch.

The returned format contains all attributes (vertices, colors, etc) which are used by this batch.

Definition at line 161 of file batch.cpp.

void KGLLib::Batch::bind (  )  [virtual]

Binds the GeometryBuffer used by this batch.

update() is automatically called if Batch's data has changed.

Reimplemented in KGLLib::Mesh.

Definition at line 124 of file batch.cpp.

GeometryBuffer* KGLLib::Batch::buffer (  )  const [inline]

Returns:
GeometryBuffer object used by this batch

Definition at line 242 of file batch.h.

const void* KGLLib::Batch::colorsArray (  )  const [inline]

Returns:
array of colors used for this batch

Definition at line 184 of file batch.h.

GeometryBuffer * KGLLib::Batch::createSharedBuffer ( const QList< Batch * > &  batches  )  [static]

Creates a GeometryBuffer object shared by the given list of Batch objects.

The created buffer is big enough to hold data of all specified batches. The batches are automatically set to use the created buffer.

All the batches must have the same format, i.e. the GeometryBufferFormat objects returned by their bestBufferFormat() method can only differ in vertex and index counts.

Definition at line 174 of file batch.cpp.

const void* KGLLib::Batch::indicesArray (  )  const [inline]

Returns:
array of indices used for this batch

Definition at line 213 of file batch.h.

int KGLLib::Batch::indicesCount (  )  const [inline]

Returns:
number of indices in this batch

Definition at line 217 of file batch.h.

void KGLLib::Batch::init (  )  [protected]

Definition at line 41 of file batch.cpp.

const void* KGLLib::Batch::normalsArray (  )  const [inline]

Returns:
array of normals used for this batch

Definition at line 192 of file batch.h.

GLenum KGLLib::Batch::primitiveType (  )  const

Returns:
OpenGL primitive mode used to render this batch.

Definition at line 104 of file batch.cpp.

void KGLLib::Batch::render (  )  [virtual]

Renders the batch.

This is same as calling first bind(), then renderOnce() and finally unbind().

Reimplemented in KGLLib::SimpleTerrain.

Definition at line 117 of file batch.cpp.

void KGLLib::Batch::renderOnce (  )  [virtual]

Renders the batch without doing bind and unbind operations on the geometry buffer.

The geometry buffer used by this batch has to be already bound before you can use this method.

Definition at line 133 of file batch.cpp.

void KGLLib::Batch::setBuffer ( GeometryBuffer *  buffer,
int  offset,
int  indexOffset 
)

Changes the GeometryBuffer object used by this batch.

With shared buffer, every Batch uses a subsection of the buffer, limitied by its buffer offsets and vertex/index counts.

If buffer is 0, then an internal buffer will be created and used.

Note that the data isn't copied immediately but the next time when update() or bind() is called. Thus all data specified for this Batch must be valid until then.

Parameters:
buffer shared GeometryBuffer object to use.
offset offset for the vertex data in the buffer.
indexOffset offset for the index data in the buffer.

Definition at line 147 of file batch.cpp.

void KGLLib::Batch::setColors ( void *  colors,
int  size 
) [protected]

Definition at line 76 of file batch.cpp.

void KGLLib::Batch::setColors ( Eigen::Vector4f *  colors  )  [inline]

Definition at line 180 of file batch.h.

void KGLLib::Batch::setColors ( Eigen::Vector3f *  colors  )  [inline]

Sets the per-vertex colors array to colors.

Definition at line 179 of file batch.h.

void KGLLib::Batch::setIndices ( unsigned int *  indices,
int  count 
)

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).

Definition at line 97 of file batch.cpp.

void KGLLib::Batch::setNormals ( Eigen::Vector3f *  normals  ) 

Sets the normals array to normals.

Definition at line 83 of file batch.cpp.

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

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

GL_QUADS).

Default value is GL_TRIANGLES.

Definition at line 109 of file batch.cpp.

void KGLLib::Batch::setTexcoords ( void *  texcoords,
int  size 
) [protected]

Definition at line 90 of file batch.cpp.

void KGLLib::Batch::setTexcoords ( Eigen::Vector4f *  texcoords  )  [inline]

Definition at line 199 of file batch.h.

void KGLLib::Batch::setTexcoords ( Eigen::Vector3f *  texcoords  )  [inline]

Definition at line 198 of file batch.h.

void KGLLib::Batch::setTexcoords ( Eigen::Vector2f *  texcoords  )  [inline]

Definition at line 197 of file batch.h.

void KGLLib::Batch::setTexcoords ( float *  texcoords  )  [inline]

Sets the texture coordinates array to texcoords.

Definition at line 196 of file batch.h.

void KGLLib::Batch::setVertexCount ( int  count  ) 

Set the number of vertices in the batch to count.

Each specified array must contain at least count entries (if they contain more, then the remaining ones will be unused).

Definition at line 63 of file batch.cpp.

void KGLLib::Batch::setVertices ( void *  vertices,
int  size 
) [protected]

Definition at line 69 of file batch.cpp.

void KGLLib::Batch::setVertices ( Eigen::Vector4f *  vertices  )  [inline]

Definition at line 171 of file batch.h.

void KGLLib::Batch::setVertices ( Eigen::Vector3f *  vertices  )  [inline]

Definition at line 170 of file batch.h.

void KGLLib::Batch::setVertices ( Eigen::Vector2f *  vertices  )  [inline]

Sets the vertices array to vertices.

Definition at line 169 of file batch.h.

const void* KGLLib::Batch::texcoordsArray (  )  const [inline]

Returns:
array of texture coordinates used for this batch

Definition at line 203 of file batch.h.

void KGLLib::Batch::unbind (  )  [virtual]

Unbinds the GeometryBuffer used by this batch.

Reimplemented in KGLLib::Mesh.

Definition at line 142 of file batch.cpp.

void KGLLib::Batch::update (  )  [virtual]

Updates the used GeometryBuffer if something has changed.

This method is automatically called from bind() in case something has changed, but you can also call it manually to remove the delay at first rendering.

Definition at line 204 of file batch.cpp.

int KGLLib::Batch::vertexCount (  )  const [inline]

Returns:
number of vertices in this batch

Definition at line 164 of file batch.h.

const void* KGLLib::Batch::verticesArray (  )  const [inline]

Returns:
array of vertices used for this batch

Definition at line 175 of file batch.h.


The documentation for this class was generated from the following files:
  • batch.h
  • batch.cpp

KGLLib

Skip menu "KGLLib"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KGLLib
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal