|
KGLLib
|
00001 /* 00002 * Copyright (C) 2008 Rivo Laks <rivolaks@hot.ee> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this program. If not, see <http://www.gnu.org/licenses/>. 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 // Pointers to corresponding arrays 00292 void* mVertices; 00293 void* mColors; 00294 void* mNormals; 00295 void* mTexcoords; 00296 // How many float components does each element have 00297 int mVertexSize; 00298 int mColorSize; 00299 int mNormalSize; 00300 int mTexcoordSize; 00301 // Indices array 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
1.7.4