void OpenGLBatch::draw(){ unsigned int i, nFormats = formats.getCount(); if (GL_ARB_vertex_buffer_object_supported && vertexBuffer != 0){ glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBuffer); } for (i = 0; i < nFormats; i++){ Format format = formats[i]; GLenum type = getGLType(format.attFormat); GLenum array = arrayType[format.attType]; char *basePointer = (vertexBuffer != 0)? NULL : vertices; switch (format.attType){ case ATT_VERTEX: glVertexPointer(format.size, type, vertexSize, basePointer + format.offset); break; case ATT_NORMAL: glNormalPointer(type, vertexSize, basePointer + format.offset); break; case ATT_TEXCOORD: glClientActiveTextureARB(GL_TEXTURE0_ARB + format.index); glTexCoordPointer(format.size, type, vertexSize, basePointer + format.offset); break; case ATT_COLOR: glColorPointer(format.size, type, vertexSize, basePointer + format.offset); break; } glEnableClientState(array); } if (nIndices == 0){ glDrawArrays(getGLPrimitive(primitiveType), 0, nVertices); } else { if (indexBuffer != 0) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexBuffer); glDrawElements(getGLPrimitive(primitiveType), nIndices, indexSize == 2? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (indexBuffer != 0)? NULL : indices); if (indexBuffer != 0) glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } for (i = 0; i < nFormats; i++){ if (formats[i].attType == ATT_TEXCOORD){ glClientActiveTextureARB(GL_TEXTURE0_ARB + formats[i].index); } glDisableClientState(arrayType[formats[i].attType]); } if (GL_ARB_vertex_buffer_object_supported && vertexBuffer != 0){ glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } }
void Renderer::drawIndexed(Geometry::PrimitiveType ePrimitiveType, unsigned int uIndexCount, unsigned int uIndexOffset) { glDrawElements(getGLPrimitive(ePrimitiveType), uIndexCount, GL_UNSIGNED_INT, (const GLvoid*) uIndexOffset); }