Permalink
Browse files

Tangent support in VBOs

  • Loading branch information...
1 parent e6a6e49 commit 4d4235dd4067055c2c15636e7b1c47e1700dd841 @ivansafrin committed Jan 23, 2012
@@ -49,13 +49,15 @@ namespace Polycode {
GLuint getTextCoordBufferID();
GLuint getNormalBufferID();
GLuint getColorBufferID();
-
+ GLuint getTangentBufferID();
+
protected:
GLuint vertexBufferID;
GLuint texCoordBufferID;
GLuint normalBufferID;
- GLuint colorBufferID;
+ GLuint colorBufferID;
+ GLuint tangentBufferID;
};
}
@@ -356,6 +356,11 @@ void OpenGLRenderer::drawVertexBuffer(VertexBuffer *buffer) {
glNormalPointer(GL_FLOAT, 0, (char *) NULL );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getTextCoordBufferID());
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
+
+ glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getTangentBufferID());
+ glEnableVertexAttribArrayARB(6);
+ glVertexAttribPointer(6, 3, GL_FLOAT, 0, 0, (char *)NULL);
+
GLenum mode = GL_TRIANGLES;
@@ -125,6 +125,28 @@ OpenGLVertexBuffer::OpenGLVertexBuffer(Mesh *mesh) : VertexBuffer() {
glBufferDataARB(GL_ARRAY_BUFFER_ARB, bufferSize*sizeof(GLfloat), buffer, GL_STATIC_DRAW_ARB);
free(buffer);
+
+
+ glGenBuffersARB(1, &tangentBufferID);
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, tangentBufferID);
+
+ bufferSize = 0;
+ newBufferSize = 0;
+ buffer = (GLfloat*)malloc(1);
+
+ for(int i=0; i < mesh->getPolygonCount(); i++) {
+ for(int j=0; j < mesh->getPolygon(i)->getVertexCount(); j++) {
+ newBufferSize = bufferSize + 3;
+ buffer = (GLfloat*)realloc(buffer, newBufferSize * sizeof(GLfloat));
+ buffer[bufferSize+0] = mesh->getPolygon(i)->getVertex(j)->tangent.x;
+ buffer[bufferSize+1] = mesh->getPolygon(i)->getVertex(j)->tangent.y;
+ buffer[bufferSize+2] = mesh->getPolygon(i)->getVertex(j)->tangent.z;
+ bufferSize = newBufferSize;
+ }
+ }
+
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB, bufferSize*sizeof(GLfloat), buffer, GL_STATIC_DRAW_ARB);
+ free(buffer);
glGenBuffersARB(1, &colorBufferID);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorBufferID);
@@ -172,3 +194,7 @@ GLuint OpenGLVertexBuffer::getTextCoordBufferID() {
GLuint OpenGLVertexBuffer::getVertexBufferID() {
return vertexBufferID;
}
+
+GLuint OpenGLVertexBuffer::getTangentBufferID() {
+ return tangentBufferID;
+}

0 comments on commit 4d4235d

Please sign in to comment.