[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39276] branches/soc-2011-cucumber/source/ gameengine/Rasterizer/RAS_OpenGLRasterizer: Added color to the VBOs, this also happens to fix TexFace mode.

Daniel Stokes kupomail at gmail.com
Wed Aug 10 23:51:04 CEST 2011


Revision: 39276
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39276
Author:   kupoman
Date:     2011-08-10 21:51:03 +0000 (Wed, 10 Aug 2011)
Log Message:
-----------
Added color to the VBOs, this also happens to fix TexFace mode.

Modified Paths:
--------------
    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_OpenGLRasterizer/RAS_StorageVBO.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2011-08-10 21:14:12 UTC (rev 39275)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2011-08-10 21:51:03 UTC (rev 39276)
@@ -52,6 +52,7 @@
 	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);
 
@@ -60,6 +61,7 @@
 	UpdateNormals();
 	UpdateUVs();
 	UpdateTangents();
+	UpdateColors();
 	UpdateIndices();
 
 	// Set up a dummy buffer
@@ -172,7 +174,28 @@
 	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);
@@ -200,6 +223,11 @@
 	glEnableClientState(GL_NORMAL_ARRAY);
 	glNormalPointer(GL_FLOAT, 0, 0);
 
+	// Colors
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->color);
+	glEnableClientState(GL_COLOR_ARRAY);
+	glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
+
 	if (multi)
 	{
 		for (int unit=0; unit<texco_num; ++unit)
@@ -282,6 +310,7 @@
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_NORMAL_ARRAY);
+	glDisableClientState(GL_COLOR_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
 	if (GLEW_ARB_vertex_program)

Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h	2011-08-10 21:14:12 UTC (rev 39275)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h	2011-08-10 21:51:03 UTC (rev 39276)
@@ -50,6 +50,7 @@
 	void	UpdateNormals();
 	void	UpdateUVs();
 	void	UpdateTangents();
+	void	UpdateColors();
 	void	UpdateIndices();
 private:
 	RAS_DisplayArray*	data;
@@ -62,6 +63,7 @@
 	GLuint			normal;
 	GLuint			UV[RAS_TexVert::MAX_UNIT];
 	GLuint			tangent;
+	GLuint			color;
 };
 
 class RAS_StorageVBO : public RAS_IStorage




More information about the Bf-blender-cvs mailing list