[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39296] branches/soc-2011-cucumber/source/ gameengine/Rasterizer: VBOs now update when necessary.

Daniel Stokes kupomail at gmail.com
Thu Aug 11 09:24:39 CEST 2011


Revision: 39296
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39296
Author:   kupoman
Date:     2011-08-11 07:24:39 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
VBOs now update when necessary.
VBOs are now interleaved to avoid iterating over the vertex list more than is necessary.
Removed some allocation/deallocation in the update code that was causing some slow downs.

Modified Paths:
--------------
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp	2011-08-11 07:19:37 UTC (rev 39295)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp	2011-08-11 07:24:39 UTC (rev 39296)
@@ -605,7 +605,8 @@
 
 	if (ms.m_pDeformer)
 	{
-		ms.m_pDeformer->Apply(m_material);
+		if (ms.m_pDeformer->Apply(m_material));
+			ms.m_mesh->SetMeshModified(true);
 	//	KX_ReInstanceShapeFromMesh(ms.m_mesh); // Recompute the physics mesh. (Can't call KX_* from RAS_)
 	}
 	
@@ -648,10 +649,9 @@
 	else
 		rasty->IndexPrimitives(ms);
 
-	if(rasty->QueryLists())
-		if(ms.m_DisplayList)
-			ms.m_mesh->SetMeshModified(false);
 
+	ms.m_mesh->SetMeshModified(false);
+
 	rendertools->PopMatrix();
 }
 

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2011-08-11 07:19:37 UTC (rev 39295)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2011-08-11 07:24:39 UTC (rev 39296)
@@ -27,17 +27,16 @@
  */
 
 #include "RAS_StorageVBO.h"
+#include "RAS_MeshObject.h"
 
 #include "GL/glew.h"
 
 VBO::VBO(RAS_DisplayArray *data, unsigned int indices)
 {
-	GLuint vbo;
-	RAS_MeshSlot::iterator it;
-
 	this->data = data;
 	this->size = data->m_vertex.size();
 	this->indices = indices;
+	this->stride = 28*sizeof(GLfloat);
 
 	//	Determine drawmode
 	if (data->m_type == data->QUAD)
@@ -48,154 +47,56 @@
 		this->mode = GL_LINE;
 
 	// Generate Buffers
-	glGenBuffersARB(1, &this->vertex);
-	glGenBuffersARB(1, &this->normal);
-	glGenBuffersARB(RAS_TexVert::MAX_UNIT, this->UV);
-	glGenBuffersARB(1, &this->tangent);
-	glGenBuffersARB(1, &this->color);
 	glGenBuffersARB(1, &this->ibo);
-	glGenBuffersARB(1, &this->dummy);
+	glGenBuffersARB(1, &this->vbo_id);
 
+	// Allocate some space to gather data into before uploading to GPU
+	this->vbo = new GLfloat[this->stride*this->size];
+
 	// Fill the buffers with initial data
-	UpdatePositions();
-	UpdateNormals();
-	UpdateUVs();
-	UpdateTangents();
-	UpdateColors();
 	UpdateIndices();
+	UpdateData();
 
-	// Set up a dummy buffer
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->dummy);
-	GLshort* dummy = new GLshort [this->size];
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(GLshort), dummy, GL_STATIC_DRAW_ARB);
-	delete dummy;
+	// Establish offsets
+	this->vertex_offset = 0;
+	this->normal_offset = (void*)(3*sizeof(GLfloat));
+	this->tangent_offset = (void*)(6*sizeof(GLfloat));
+	this->color_offset = (void*)(10*sizeof(GLfloat));
+	this->uv_offset = (void*)(11*sizeof(GLfloat));
+	this->dummy_offset = (void*)(27*sizeof(GLfloat));
 }
 
 VBO::~VBO()
 {
 	glDeleteBuffersARB(1, &this->ibo);
-	glDeleteBuffersARB(1, &this->vertex);
-	glDeleteBuffersARB(1, &this->normal);
-	glDeleteBuffersARB(2, this->UV);
-	glDeleteBuffersARB(1, &this->tangent);
-}
+	glDeleteBuffersARB(1, &this->vbo_id);
 
-void VBO::UpdatePositions()
-{
-	int space = this->size*3*sizeof(GLfloat);
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vertex);
-
-	// Lets the video card know we are done with the old VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
-
-	// Gather position data
-	GLfloat* positions = new GLfloat[this->size*3];
-	for (unsigned int i=0, j=0; i<data->m_vertex.size(); ++i, j+=3)
-	{
-		memcpy(&positions[j], data->m_vertex[i].getXYZ(), sizeof(float)*3);
-	}
-
-	// Upload Data to VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, space, positions, GL_DYNAMIC_DRAW_ARB);
-
-	// Clean up
-	delete positions;
+	delete this->vbo;
 }
 
-void VBO::UpdateNormals()
+void VBO::UpdateData()
 {
-	int space = this->size*3*sizeof(GLfloat);
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->normal);
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 
 	// Lets the video card know we are done with the old VBO
 	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
 
-	// Gather normal data
-	GLfloat* normals = new GLfloat[this->size*3];
-	for (unsigned int i=0, j=0; i<data->m_vertex.size(); ++i, j+=3)
+	// Gather data
+	for (unsigned int i=0, j=0; i<data->m_vertex.size(); i++, j+=this->stride/sizeof(GLfloat))
 	{
-		memcpy(&normals[j], data->m_vertex[i].getNormal(), sizeof(float)*3);
-	}
+		memcpy(&this->vbo[j], data->m_vertex[i].getXYZ(), sizeof(float)*3);
+		memcpy(&this->vbo[j+3], data->m_vertex[i].getNormal(), sizeof(float)*3);
+		memcpy(&this->vbo[j+6], data->m_vertex[i].getTangent(), sizeof(float)*4);
+		memcpy(&this->vbo[j+10], data->m_vertex[i].getRGBA(), sizeof(char)*4);
 
-	// Upload Data to VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, space, normals, GL_DYNAMIC_DRAW_ARB);
-
-	// Clean up
-	delete normals;
-}
-
-void VBO::UpdateUVs()
-{
-	GLfloat* uvs;
-
-	int space = this->size*2*sizeof(GLfloat);
-
-	for (int uv=0; uv<RAS_TexVert::MAX_UNIT; ++uv)
-	{
-		glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->UV[uv]);
-
-		// Lets the video card know we are done with the old VBO
-		glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
-
-		// Gather uv data
-		uvs = new GLfloat[this->size*2];
-		for (unsigned int i=0, j=0; i<data->m_vertex.size(); ++i, j+=2)
-		{
-			memcpy(&uvs[j], data->m_vertex[i].getUV(uv), sizeof(float)*2);
-		}
-
-		// Upload Data to VBO
-		glBufferDataARB(GL_ARRAY_BUFFER_ARB, space, uvs, GL_DYNAMIC_DRAW_ARB);
+		for (unsigned int k=0; k<RAS_TexVert::MAX_UNIT; k+=2)
+			memcpy(&this->vbo[j+11+k], data->m_vertex[i].getUV(k), sizeof(float)*2);
 	}
 
-	// Clean up
-	delete uvs;
+	// Upload Data to GPU
+	glBufferDataARB(GL_ARRAY_BUFFER_ARB, this->size*this->stride, this->vbo, GL_DYNAMIC_DRAW_ARB);
 }
 
-void VBO::UpdateTangents()
-{
-	int space = this->size*4*sizeof(GLfloat);
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->tangent);
-
-	// Lets the video card know we are done with the old VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
-
-	// Gather tangent data
-	GLfloat* tangents = new GLfloat[this->size*4];
-	for (unsigned int i=0, j=0; i<data->m_vertex.size(); ++i, j+=4)
-	{
-		memcpy(&tangents[j], data->m_vertex[i].getTangent(), sizeof(float)*4);
-	}
-
-	// Upload Data to VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, space, tangents, GL_DYNAMIC_DRAW_ARB);
-
-	// Clean up
-	delete tangents;
-}
-
-void VBO::UpdateColors()
-{
-	int space = this->size*4*sizeof(GLchar);
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->color);
-
-	// Lets the video card know we are done with the old VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
-
-	// Gather position data
-	GLchar* colors = new GLchar[this->size*4];
-	for (unsigned int i=0, j=0; i<data->m_vertex.size(); ++i, j+=4)
-	{
-		memcpy(&colors[j], data->m_vertex[i].getRGBA(), sizeof(char)*4);
-	}
-
-	// Upload Data to VBO
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, space, colors, GL_DYNAMIC_DRAW_ARB);
-
-	// Clean up
-	delete colors;
-}
-
 void VBO::UpdateIndices()
 {
 	int space = data->m_index.size() * sizeof(GLushort);
@@ -210,23 +111,21 @@
 
 void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, bool multi)
 {
-	// Indices
+	// Bind buffers
 	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo);
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 
 	// Vertexes
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vertex);
 	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(3, GL_FLOAT, 0, 0);
+	glVertexPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
 
 	// Normals
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->normal);
 	glEnableClientState(GL_NORMAL_ARRAY);
-	glNormalPointer(GL_FLOAT, 0, 0);
+	glNormalPointer(GL_FLOAT, this->stride, this->normal_offset);
 
 	// Colors
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->color);
 	glEnableClientState(GL_COLOR_ARRAY);
-	glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
+	glColorPointer(4, GL_UNSIGNED_BYTE, this->stride, this->color_offset);
 
 	if (multi)
 	{
@@ -238,38 +137,38 @@
 			{
 				case RAS_IRasterizer::RAS_TEXCO_ORCO:
 				case RAS_IRasterizer::RAS_TEXCO_GLOB:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vertex);
+					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(3, GL_FLOAT, 0, 0);
+					glTexCoordPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
 					break;
 				case RAS_IRasterizer::RAS_TEXCO_UV:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->UV[unit]);
+					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(2, GL_FLOAT, 0, 0);
+					glTexCoordPointer(2, GL_FLOAT, this->stride, (void*)((int)this->uv_offset+(sizeof(GLfloat)*2*unit)));
 					break;
 				case RAS_IRasterizer::RAS_TEXCO_NORM:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->normal);
+					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(3, GL_FLOAT, 0, 0);
+					glTexCoordPointer(3, GL_FLOAT, this->stride, this->normal_offset);
 					break;
 				case RAS_IRasterizer::RAS_TEXTANGENT:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->tangent);
+					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(4, GL_FLOAT, 0, 0);
+					glTexCoordPointer(4, GL_FLOAT, this->stride, this->tangent_offset);
 					break;
 				default:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->dummy);
+					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(1, GL_SHORT, 0, 0);
+					glTexCoordPointer(1, GL_SHORT, this->stride, this->dummy_offset);
 					break;
 			}
 		}
 	}
 	else //TexFace
 	{
-		glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->UV[0]);
+		glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
 		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-		glTexCoordPointer(2, GL_FLOAT, 0, 0);
+		glTexCoordPointer(2, GL_FLOAT, this->stride, this->uv_offset);
 	}
 
 	if (GLEW_ARB_vertex_program)
@@ -281,23 +180,23 @@
 			{
 				case RAS_IRasterizer::RAS_TEXCO_ORCO:
 				case RAS_IRasterizer::RAS_TEXCO_GLOB:
-					glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vertex);
-					glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, 0, 0);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list