00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GLVERTEXARRAY_H
00028 #define GLVERTEXARRAY_H
00029
00030
00034 #include <GL/gl.h>
00035 #include "referencecounted.h"
00036
00037 typedef enum
00038 {
00039 GLVA_NONE = 0,
00040 GLVA_VERTEX = 1,
00041 GLVA_COLOR = 2,
00042 GLVA_INDEX_COLOR = 4,
00043 GLVA_NORMAL = 8,
00044 GLVA_TEXCOORD = 16,
00045 GLVA_EDGE = 32
00046 } GLVAenum;
00047
00048
00049 class GLVertexArray
00050 {
00051 GLfloat* vertecies;
00052 GLfloat* normals;
00053 GLfloat* colors;
00054 GLubyte* indexColors;
00055 GLfloat* texCoords;
00056 GLboolean* edgeFlags;
00057
00058 GLuint* indicies;
00059 GLsizei indexSize;
00060 GLsizei size;
00061
00062 public:
00063 GLVertexArray();
00064 ~GLVertexArray();
00065
00066 inline void setSize(GLsizei s) { size = s; }
00067 inline GLsizei getSize() { return size; }
00068 inline GLsizei getIndexSize() { return indexSize; }
00069
00070 inline GLfloat* getVertecies() const { return vertecies; }
00071 inline void setVertecies( GLfloat* v ) { vertecies = v; }
00072 inline void setVertex(GLuint i, const GLfloat* v)
00073 { vertecies[3*i] = v[0]; vertecies[3*i + 1] = v[1]; vertecies[3*i + 2] = v[2];}
00074
00075 inline GLfloat* getNormals() const { return normals; }
00076 inline void setNormals( GLfloat* n ) { normals = n; }
00077 inline void setNormal(GLuint i, const GLfloat* v)
00078 { normals[3*i] = v[0]; normals[3*i + 1] = v[1]; normals[3*i + 2] = v[2];}
00079
00080 inline GLfloat* getColors() const { return colors; }
00081 inline void setColors( GLfloat* c ) { colors = c; }
00082 inline void setColor(GLuint i, const GLfloat r, const GLfloat g, const GLfloat b, const GLfloat a)
00083 { colors[4*i] = r; colors[4*i + 1] = g; colors[4*i + 2] = b; colors[4*i + 3] = a;}
00084
00085 inline GLubyte* getIndexColors() const { return indexColors; }
00086 inline void setIndexColors( GLubyte* c ) { indexColors = c; }
00087 inline void setIndexColor(GLuint i, const GLubyte col) const
00088 { indexColors[i] = col;}
00089
00090 inline GLfloat* getTexCoords() const { return texCoords; }
00091 inline void setTexCoords( GLfloat* t) { texCoords = t; };
00092 inline void setTexCoord(GLuint i, const GLfloat* t)
00093 { texCoords[2*i] = t[0]; texCoords[2*i + 1] = t[1];}
00094
00095 inline GLboolean* getEdgeFlags() const { return edgeFlags; }
00096 inline void setEdgeFlags( GLboolean* b) { edgeFlags = b; }
00097 inline void setEdgeFlag(GLuint i, const GLboolean b)
00098 { edgeFlags[i] = b; }
00099
00100 inline GLuint* getIndicies() const { return indicies; }
00101 inline void setIndicies( GLuint* ind, GLsizei indSize) { indicies = ind; indexSize = indSize; }
00102 inline void setIndex(GLuint i, const GLuint in)
00103 { indicies[i] = in; }
00104
00106 inline void bindBuffers(void)
00107 {
00108 glVertexPointer(3, GL_FLOAT, 0, vertecies);
00109 glNormalPointer(GL_FLOAT, 0, normals);
00110 glColorPointer(4, GL_FLOAT, 0, colors);
00111 glIndexPointer(GL_UNSIGNED_BYTE, 0, indexColors);
00112 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
00113 glEdgeFlagPointer(0, edgeFlags);
00114 }
00115
00116 void setState(GLVAenum stateMask);
00117
00118 inline void glArrayElement(GLint ith)
00119 { ::glArrayElement(ith); }
00120
00121 inline void glDrawArrays(GLenum mode, GLint first)
00122 { ::glDrawArrays(mode, first, size); }
00123
00124 inline void glDrawElements(GLenum mode)
00125 { ::glDrawElements(mode, indexSize, GL_UNSIGNED_INT, indicies); }
00126
00127 inline void glDrawRangeElements(GLenum mode, GLuint start, GLuint end)
00128
00129 { ::glDrawElements(mode, end - start, GL_UNSIGNED_INT, (indicies+start) ); }
00130
00131 };
00132
00133 #endif