KGLLib
batch.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KGLLIB_BATCH_H
00019 #define KGLLIB_BATCH_H
00020
00021 #include "kgllib.h"
00022 #include "geometrybuffer.h"
00023 #include <QList>
00024 #include <Eigen/Core>
00025
00026
00027 namespace KGLLib
00028 {
00029 class GeometryBuffer;
00030
00100 class KGLLIB_EXPORT Batch
00101 {
00102 public:
00110 Batch();
00120 Batch(GeometryBuffer* buffer, int offset, int indexOffset);
00121
00126 virtual ~Batch();
00127
00134 virtual void render();
00135
00141 virtual void bind();
00149 virtual void renderOnce();
00153 virtual void unbind();
00154
00160 void setVertexCount(int count);
00164 int vertexCount() const { return mVertexCount; }
00165
00169 void setVertices(Eigen::Vector2f* vertices) { setVertices(vertices, 2); }
00170 void setVertices(Eigen::Vector3f* vertices) { setVertices(vertices, 3); }
00171 void setVertices(Eigen::Vector4f* vertices) { setVertices(vertices, 4); }
00175 const void* verticesArray() const { return mVertices; }
00179 void setColors(Eigen::Vector3f* colors) { setColors(colors, 3); }
00180 void setColors(Eigen::Vector4f* colors) { setColors(colors, 4); }
00184 const void* colorsArray() const { return mColors; }
00188 void setNormals(Eigen::Vector3f* normals);
00192 const void* normalsArray() const { return mNormals; }
00196 void setTexcoords(float* texcoords) { setTexcoords(texcoords, 1); }
00197 void setTexcoords(Eigen::Vector2f* texcoords) { setTexcoords(texcoords, 2); }
00198 void setTexcoords(Eigen::Vector3f* texcoords) { setTexcoords(texcoords, 3); }
00199 void setTexcoords(Eigen::Vector4f* texcoords) { setTexcoords(texcoords, 4); }
00203 const void* texcoordsArray() const { return mTexcoords; }
00209 void setIndices(unsigned int* indices, int count);
00213 const void* indicesArray() const { return mIndices; }
00217 int indicesCount() const { return mIndexCount; }
00218
00224 virtual void setPrimitiveType(GLenum type);
00228 GLenum primitiveType() const;
00229
00237 virtual void update();
00238
00242 GeometryBuffer* buffer() const { return mBuffer; }
00259 void setBuffer(GeometryBuffer* buffer, int offset, int indexOffset);
00260
00268 GeometryBufferFormat bestBufferFormat() const;
00269
00281 static GeometryBuffer* createSharedBuffer(const QList<Batch*>& batches);
00282
00283 protected:
00284 void setVertices(void* vertices, int size);
00285 void setColors(void* colors, int size);
00286 void setTexcoords(void* texcoords, int size);
00287
00288 void init();
00289
00290 private:
00291
00292 void* mVertices;
00293 void* mColors;
00294 void* mNormals;
00295 void* mTexcoords;
00296
00297 int mVertexSize;
00298 int mColorSize;
00299 int mNormalSize;
00300 int mTexcoordSize;
00301
00302 void* mIndices;
00303
00304 int mVertexCount;
00305 int mIndexCount;
00306
00307 bool mDirty;
00308 GLenum mPrimitiveType;
00309
00310 GeometryBuffer* mBuffer;
00311 int mBufferOffset;
00312 int mBufferIndexOffset;
00313 bool mOwnBuffer;
00314 };
00315
00316 }
00317
00318 #endif