[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38027] branches/soc-2011-cucumber/source/ gameengine/Rasterizer: The VBO code from Samuel Anjam was having some problems.

Daniel Stokes kupomail at gmail.com
Sat Jul 2 01:36:44 CEST 2011


Revision: 38027
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38027
Author:   kupoman
Date:     2011-07-01 23:36:44 +0000 (Fri, 01 Jul 2011)
Log Message:
-----------
The VBO code from Samuel Anjam was having some problems. These problems could have been there initially, or could have resulted from my porting of the patch. These problems were difficult to work out since I lacked sufficient knowledge of VBOs. In an attempt to resolve these problems I rewrote the VBO code from scratch (making sure to keep it contained to its own files) using Anjam's patch as a guide. Some of the bugs have been disappeared, but I have a file that still crashes the code. So for now the auto selection ignores VBOs, and I intend to flag the VBOs as "experimental".

Modified Paths:
--------------
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
    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_IRasterizer.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h	2011-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h	2011-07-01 23:36:44 UTC (rev 38027)
@@ -418,10 +418,6 @@
 
 	virtual void	SetBlendingMode(int blendmode)=0;
 	virtual void	SetFrontFace(bool ccw)=0;
-
-	// updates mesh data (vbo addition)
-	virtual void UpdateMeshSlotData(class RAS_MeshSlot *ms,
-		const bool &anim, const bool &zsort)=0;
 	
 	
 #ifdef WITH_CXX_GUARDEDALLOC

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp	2011-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp	2011-07-01 23:36:44 UTC (rev 38027)
@@ -48,27 +48,7 @@
 #include "RAS_MeshObject.h"
 #include "RAS_Deformer.h"	// __NLA
 
-/* vertex buffer object slot */
-RAS_VboSlot::RAS_VboSlot(RAS_IRasterizer *rasty)
-{
-	m_rasty = rasty;
-	m_vertVbo = 0;
-	m_indexVbo = 0;
-	m_normalVbo = 0;
-	m_tangentVbo = 0;
-	m_colorVbo = 0;
-	m_verts = 0;
-	m_texCoordVbo[0] = 0;
-	m_texCoordVbo[1] = 0;
-};
 
-RAS_VboSlot::~RAS_VboSlot()
-{
-	//m_rasty->ClearVboSlot(this);
-	if(m_verts) delete []m_verts;
-}
-
-
 /* mesh slot */
 
 RAS_MeshSlot::RAS_MeshSlot() : SG_QList()
@@ -187,7 +167,6 @@
 
 		it.vertex = &it.array->m_vertex[0];
 		it.index = &it.array->m_index[startindex];
-		it.vboslot = it.array->m_vboSlot;
 		it.startvertex = startvertex;
 		it.endvertex = endvertex;
 		it.totindex = endindex-startindex;
@@ -219,7 +198,6 @@
 
 		it.vertex = &it.array->m_vertex[0];
 		it.index = &it.array->m_index[startindex];
-		it.vboslot = it.array->m_vboSlot;
 		it.startvertex = startvertex;
 		it.endvertex = endvertex;
 		it.totindex = endindex-startindex;
@@ -634,9 +612,6 @@
 	if(IsZSort() && rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
 		ms.m_mesh->SortPolygons(ms, cameratrans*MT_Transform(ms.m_OpenGLMatrix));
 
-	rasty->UpdateMeshSlotData(&ms, (ms.m_pDeformer != 0),
-		(IsZSort() && rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID));
-
 	rendertools->PushMatrix();
 	if (!ms.m_pDeformer || !ms.m_pDeformer->SkipVertexTransform())
 	{

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.h	2011-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.h	2011-07-01 23:36:44 UTC (rev 38027)
@@ -77,33 +77,6 @@
 class RAS_MaterialBucket;
 struct DerivedMesh;
 
-/* Vertex Buffer Object data used for OpenGL drawing */
-class RAS_VboSlot
-{
-public:
-	RAS_IRasterizer *m_rasty;
-	/* vertex buffer object handles for drawing */
-	unsigned int m_vertVbo;
-	unsigned int m_indexVbo;
-	unsigned int m_normalVbo;
-	unsigned int m_tangentVbo;
-	unsigned int m_colorVbo;
-	/* allow up to four texture coordinate sets */
-	unsigned int m_texCoordVbo[2];
-	/* m_verts only exists if the mesh is deformable.
-	glBufferSubDataARB is used for updating the vertices
-	and this function doesn't take stride parameter, so all of
-	the vertice data has to be passed to an new array and THEN
-	uploaded to the vbo. glMapBuffer could be an alternative,
-	but it doesn't return untill the GPU has processed the previous
-	data, so this might be the fastest way. */
-	float *m_verts;
-
-	RAS_VboSlot(RAS_IRasterizer *rasty);
-	~RAS_VboSlot();
-};
-
-
 /* An array with data used for OpenGL drawing */
 
 class RAS_DisplayArray
@@ -114,16 +87,12 @@
 	/* LINE currently isnt used */
 	enum { LINE = 2, TRIANGLE = 3, QUAD = 4 } m_type;
 	//RAS_MeshSlot *m_origSlot;
-	RAS_VboSlot *m_vboSlot;
 	
 	/* Number of RAS_MeshSlot using this array */
 	int m_users;
 
 	enum { BUCKET_MAX_INDEX = 65535 };
 	enum { BUCKET_MAX_VERTEX = 65535 };
-	
-	RAS_DisplayArray() : m_vboSlot(0) {};
-	~RAS_DisplayArray() {if(m_vboSlot) delete m_vboSlot;}
 };
 
 /* Entry of a RAS_MeshObject into RAS_MaterialBucket */
@@ -178,7 +147,6 @@
 	struct iterator {
 		RAS_DisplayArray *array;
 		RAS_TexVert *vertex;
-		RAS_VboSlot *vboslot;
 		unsigned short *index;
 		size_t startvertex;
 		size_t endvertex;

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp	2011-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp	2011-07-01 23:36:44 UTC (rev 38027)
@@ -105,9 +105,9 @@
 	}
 	hinterlace_mask[32] = 0;
 
-	if (m_storage_type == RAS_VBO || m_storage_type == RAS_AUTO_STORAGE && GLEW_ARB_vertex_buffer_object)
+	if (m_storage_type == RAS_VBO /*|| m_storage_type == RAS_AUTO_STORAGE && GLEW_ARB_vertex_buffer_object*/)
 	{
-		m_storage = new RAS_StorageVBO(this, &m_texco_num, m_texco, &m_attrib_num, m_attrib);
+		m_storage = new RAS_StorageVBO(&m_texco_num, m_texco, &m_attrib_num, m_attrib);
 		m_failsafe_storage = new RAS_StorageIM(&m_texco_num, m_texco, &m_attrib_num, m_attrib);
 		m_storage_type = RAS_VBO;
 	}
@@ -305,78 +305,6 @@
 	EndFrame();
 }
 
-void RAS_OpenGLRasterizer::UpdateMeshSlotData(class RAS_MeshSlot *ms,
-	const bool &anim, const bool &zsort)
-{
-	if(m_storage_type != RAS_VBO)
-		return;
-
-	RAS_MeshSlot::iterator it;
-	unsigned int vertnum = 0;
-	unsigned int num = 0;
-	RAS_VboSlot *slot = 0;
-	int usage = 0;
-	float *normals = 0;
-
-	for(ms->begin(it); !ms->end(it); ms->next(it)) {
-		if(it.totindex == 0)
-			continue;
-
-		if(!it.array->m_vboSlot)
-			continue;
-
-		slot = it.array->m_vboSlot;
-
-		if(anim)
-		{
-			if(!slot->m_verts)
-				slot->m_verts = new float[it.array->m_vertex.size()*3];
-
-			normals = new float[it.array->m_vertex.size()*3];
-
-			for(vertnum = 0, num = 0; vertnum < it.array->m_vertex.size(); vertnum++)
-			{
-				memcpy(&slot->m_verts[num], it.array->m_vertex[vertnum].getXYZ(), sizeof(float)*3);
-				memcpy(&normals[num], it.array->m_vertex[vertnum].getNormal(), sizeof(float)*3);
-				num+=3;
-			}
-
-			glBindBufferARB(GL_ARRAY_BUFFER_ARB, slot->m_vertVbo);
-			glBufferDataARB(GL_ARRAY_BUFFER_ARB,
-				sizeof(float)*it.array->m_vertex.size()*3, slot->m_verts, GL_DYNAMIC_DRAW_ARB);
-			glBindBufferARB(GL_ARRAY_BUFFER_ARB, slot->m_normalVbo);
-			glBufferDataARB(GL_ARRAY_BUFFER_ARB,
-				sizeof(float)*it.array->m_vertex.size()*3, normals, GL_DYNAMIC_DRAW_ARB);
-			glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
-
-		}
-
-		if(zsort)
-		{
-			// make sure that we have a dynamic index
-			glGetBufferParameteriv(slot->m_indexVbo, GL_BUFFER_USAGE_ARB, &usage);
-			if(usage != GL_DYNAMIC_DRAW_ARB)
-			{
-				glGenBuffersARB(1, &slot->m_indexVbo);
-				glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, slot->m_indexVbo);
-				glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
-					sizeof(unsigned short)*it.array->m_index.size(),
-					&it.array->m_index[0], GL_DYNAMIC_DRAW_ARB);
-				glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
-			}
-			else
-			{
-				glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, slot->m_indexVbo);
-				glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0,
-					sizeof(unsigned short)*it.array->m_index.size(), &it.array->m_index[0]);
-				glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
-			}
-		}
-	}
-
-	delete[] normals;
-}
-
 bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
 {
 	m_time = time;

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h	2011-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h	2011-07-01 23:36:44 UTC (rev 38027)
@@ -297,10 +297,6 @@
 
 	virtual void	SetBlendingMode(int blendmode);
 	virtual void	SetFrontFace(bool ccw);
-
-	// updates mesh data (vbo addition)
-	virtual void	UpdateMeshSlotData(class RAS_MeshSlot *ms,
-		const bool &anim, const bool &zsort);	
 	
 #ifdef WITH_CXX_GUARDEDALLOC
 public:

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-07-01 21:51:44 UTC (rev 38026)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2011-07-01 23:36:44 UTC (rev 38027)
@@ -30,533 +30,327 @@
 
 #include "GL/glew.h"
 
-RAS_StorageVBO::RAS_StorageVBO(RAS_IRasterizer *rasty, int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib) :
-	m_texco_num(texco_num),
-	m_texco(texco),
-	m_attrib_num(attrib_num),
-	m_attrib(attrib),
-	m_last_texco_num(0),
-	m_last_attrib_num(0),
-	m_rasty(rasty)
+VBO::VBO(RAS_DisplayArray *data, unsigned int indices)
 {
-}
+	GLuint vbo;
+	RAS_MeshSlot::iterator it;
 
-RAS_StorageVBO::~RAS_StorageVBO()
-{
-}
+	this->data = data;
+	this->size = data->m_vertex.size();
+	this->indices = indices;
 
-bool RAS_StorageVBO::Init()
-{
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_NORMAL_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+	//	Determine drawmode
+	if (data->m_type == data->QUAD)
+		this->mode = GL_QUADS;
+	else if (data->m_type == data->TRIANGLE)
+		this->mode = GL_TRIANGLES;
+	else
+		this->mode = GL_LINE;
 
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	// Generate Buffers
+	glGenBuffersARB(1, &this->vertex);
+	glGenBuffersARB(1, &this->normal);
+	glGenBuffersARB(2, this->UV);
+	glGenBuffersARB(1, &this->tangent);
+	glGenBuffersARB(1, &this->ibo);
+	glGenBuffersARB(1, &this->dummy);
 
-	return true;
-}
+	// Fill the buffers with initial data
+	UpdatePositions();
+	UpdateNormals();
+	UpdateUVs();
+	UpdateTangents();
+	UpdateIndices();
 
-void RAS_StorageVBO::Exit()
-{
-	glDisableClientState(GL_VERTEX_ARRAY);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list