[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49321] branches/soc-2012-swiss_cheese/ source/gameengine/Rasterizer/RAS_OpenGLRasterizer: Converting GE VBO to gpu API which allows greater compatibility between different OpenGL .

Alexander Kuznetsov kuzsasha at gmail.com
Sat Jul 28 06:03:34 CEST 2012


Revision: 49321
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49321
Author:   alexk
Date:     2012-07-28 04:03:31 +0000 (Sat, 28 Jul 2012)
Log Message:
-----------
Converting GE VBO to gpu API which allows greater compatibility between different OpenGL.
Allows to use OpenGL ES on Android.
No need for glEnableClientState. gpu functions handles it.
No #ifdef GLES and no weird #include REAL_GL_MODE

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
    branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2012-07-28 03:16:20 UTC (rev 49320)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp	2012-07-28 04:03:31 UTC (rev 49321)
@@ -25,11 +25,18 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+
+
 #include "RAS_StorageVBO.h"
 #include "RAS_MeshObject.h"
 
-#include <GL/glew.h>
+#include "GPU_extensions.h"
+#include "GPU_matrix.h"
 
+#include "GPU_object.h"
+#include "GPU_functions.h"
+
+
 VBO::VBO(RAS_DisplayArray *data, unsigned int indices)
 {
 	this->data = data;
@@ -46,8 +53,8 @@
 		this->mode = GL_LINE;
 
 	// Generate Buffers
-	glGenBuffersARB(1, &this->ibo);
-	glGenBuffersARB(1, &this->vbo_id);
+	gpuGenBuffers(1, &this->ibo);
+	gpuGenBuffers(1, &this->vbo_id);
 
 	// Allocate some space to gather data into before uploading to GPU
 	this->vbo = new GLfloat[this->stride*this->size];
@@ -67,8 +74,8 @@
 
 VBO::~VBO()
 {
-	glDeleteBuffersARB(1, &this->ibo);
-	glDeleteBuffersARB(1, &this->vbo_id);
+	gpuDeleteBuffers(1, &this->ibo);
+	gpuDeleteBuffers(1, &this->vbo_id);
 
 	delete this->vbo;
 }
@@ -77,10 +84,10 @@
 {
 	unsigned int i, j, k;
 	
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
+	gpuBindBuffer(GL_ARRAY_BUFFER, 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);
+	gpuBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_DYNAMIC_DRAW);
 
 	// Gather data
 	for (i = 0, j = 0; i < data->m_vertex.size(); i++, j += this->stride/sizeof(GLfloat))
@@ -95,81 +102,75 @@
 	}
 
 	// Upload Data to GPU
-	glBufferDataARB(GL_ARRAY_BUFFER_ARB, this->size*this->stride, this->vbo, GL_DYNAMIC_DRAW_ARB);
+	gpuBufferData(GL_ARRAY_BUFFER, this->size*this->stride, this->vbo, GL_DYNAMIC_DRAW);
 }
 
 void VBO::UpdateIndices()
 {
 	int space = data->m_index.size() * sizeof(GLushort);
-	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo);
+	gpuBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->ibo);
 
 	// Lets the video card know we are done with the old VBO
-	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, NULL, GL_DYNAMIC_DRAW_ARB);
+	gpuBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, NULL, GL_DYNAMIC_DRAW);
 
 	// Upload Data to VBO
-	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, space, &data->m_index[0], GL_DYNAMIC_DRAW_ARB);
+	gpuBufferData(GL_ELEMENT_ARRAY_BUFFER, space, &data->m_index[0], GL_DYNAMIC_DRAW);
 }
 
 void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, bool multi)
 {
 	int unit;
-	
+
 	// Bind buffers
-	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo);
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
+	gpuBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->ibo);
+	gpuBindBuffer(GL_ARRAY_BUFFER, this->vbo_id);
 
-	// Vertexes
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glVertexPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
+	// Vertexes	
+	gpugameobj.gpuVertexPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
 
 	// Normals
-	glEnableClientState(GL_NORMAL_ARRAY);
-	glNormalPointer(GL_FLOAT, this->stride, this->normal_offset);
+	gpugameobj.gpuNormalPointer(GL_FLOAT, this->stride, this->normal_offset);
 
 	// Colors
-	glEnableClientState(GL_COLOR_ARRAY);
-	glColorPointer(4, GL_UNSIGNED_BYTE, this->stride, this->color_offset);
+	gpugameobj.gpuColorPointer(4, GL_UNSIGNED_BYTE, this->stride, this->color_offset);
 
-	if (multi)
+	if(GPU_GLTYPE_FIXED_ENABLED)
 	{
-		for (unit = 0; unit < texco_num; ++unit)
+		if (multi)
 		{
-			glClientActiveTexture(GL_TEXTURE0_ARB + unit);
-			switch (texco[unit])
+			for (unit = 0; unit < texco_num; ++unit)
 			{
-				case RAS_IRasterizer::RAS_TEXCO_ORCO:
-				case RAS_IRasterizer::RAS_TEXCO_GLOB:
-					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
-					break;
-				case RAS_IRasterizer::RAS_TEXCO_UV:
-					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(2, GL_FLOAT, this->stride, (void*)((intptr_t)this->uv_offset+(sizeof(GLfloat)*2*unit)));
-					break;
-				case RAS_IRasterizer::RAS_TEXCO_NORM:
-					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(3, GL_FLOAT, this->stride, this->normal_offset);
-					break;
-				case RAS_IRasterizer::RAS_TEXTANGENT:
-					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(4, GL_FLOAT, this->stride, this->tangent_offset);
-					break;
-				default:
-					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-					glTexCoordPointer(1, GL_SHORT, this->stride, this->dummy_offset);
-					break;
+				gpugameobj.gpuClientActiveTexture(GL_TEXTURE0 + unit);
+				switch (texco[unit])
+				{
+					case RAS_IRasterizer::RAS_TEXCO_ORCO:
+					case RAS_IRasterizer::RAS_TEXCO_GLOB:
+						gpugameobj.gpuTexCoordPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
+						break;
+					case RAS_IRasterizer::RAS_TEXCO_UV:
+						gpugameobj.gpuTexCoordPointer(2, GL_FLOAT, this->stride, (void*)((intptr_t)this->uv_offset+(sizeof(GLfloat)*2*unit)));
+						break;
+					case RAS_IRasterizer::RAS_TEXCO_NORM:
+						gpugameobj.gpuTexCoordPointer(3, GL_FLOAT, this->stride, this->normal_offset);
+						break;
+					case RAS_IRasterizer::RAS_TEXTANGENT:
+						gpugameobj.gpuTexCoordPointer(4, GL_FLOAT, this->stride, this->tangent_offset);
+						break;
+					default:
+						gpugameobj.gpuTexCoordPointer(1, GL_SHORT, this->stride, this->dummy_offset);
+						break;
+				}
 			}
+			gpugameobj.gpuClientActiveTexture(GL_TEXTURE0);
 		}
-		glClientActiveTexture(GL_TEXTURE0_ARB);
+		else //TexFace
+		{
+			gpugameobj.gpuClientActiveTexture(GL_TEXTURE0);
+			gpugameobj.gpuTexCoordPointer(2, GL_FLOAT, this->stride, this->uv_offset);
+		}
 	}
-	else //TexFace
-	{
-		glClientActiveTexture(GL_TEXTURE0_ARB);
-		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-		glTexCoordPointer(2, GL_FLOAT, this->stride, this->uv_offset);
-	}
 
-	if (GLEW_ARB_vertex_program)
+	if (GPU_EXT_GLSL_VERTEX_ENABLED)
 	{
 		int uv = 0;
 		for (unit = 0; unit < attrib_num; ++unit)
@@ -178,43 +179,40 @@
 			{
 				case RAS_IRasterizer::RAS_TEXCO_ORCO:
 				case RAS_IRasterizer::RAS_TEXCO_GLOB:
-					glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, this->stride, this->vertex_offset);
-					glEnableVertexAttribArrayARB(unit);
+					gpuVertexAttribPointer(unit, 3, GL_FLOAT, GL_FALSE, this->stride, this->vertex_offset);
+					gpuEnableVertexAttribArray(unit);
 					break;
 				case RAS_IRasterizer::RAS_TEXCO_UV:
-					glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+uv));
+					gpuVertexAttribPointer(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+uv));
 					uv += sizeof(GLfloat)*2;
-					glEnableVertexAttribArrayARB(unit);
+					gpuEnableVertexAttribArray(unit);
 					break;
 				case RAS_IRasterizer::RAS_TEXCO_NORM:
-					glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, stride, this->normal_offset);
-					glEnableVertexAttribArrayARB(unit);
+					gpuVertexAttribPointer(unit, 2, GL_FLOAT, GL_FALSE, stride, this->normal_offset);
+					gpuEnableVertexAttribArray(unit);
 					break;
 				case RAS_IRasterizer::RAS_TEXTANGENT:
-					glVertexAttribPointerARB(unit, 4, GL_FLOAT, GL_FALSE, this->stride, this->tangent_offset);
-					glEnableVertexAttribArrayARB(unit);
+					gpuVertexAttribPointer(unit, 4, GL_FLOAT, GL_FALSE, this->stride, this->tangent_offset);
+					gpuEnableVertexAttribArray(unit);
 					break;
 				default:
 					break;
 			}
 		}
-	}
+	}	
+	glDrawElements(this->mode, this->indices, GL_UNSIGNED_SHORT, 0);
 	
-	glDrawElements(this->mode, this->indices, GL_UNSIGNED_SHORT, 0);
+	gpugameobj.gpuCleanupAfterDraw();
 
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_NORMAL_ARRAY);
-	glDisableClientState(GL_COLOR_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
-	if (GLEW_ARB_vertex_program)
+	if (GPU_EXT_GLSL_VERTEX_ENABLED)
 	{
 		for (int i = 0; i < attrib_num; ++i)
-			glDisableVertexAttribArrayARB(i);
+			gpuDisableVertexAttribArray(i);
 	}
 
-	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
-	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+	gpuBindBuffer(GL_ARRAY_BUFFER, 0);
+	gpuBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
  }
 
 RAS_StorageVBO::RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib):
@@ -253,6 +251,8 @@
 {
 	RAS_MeshSlot::iterator it;
 	VBO *vbo;
+
+	gpuMatrixCommit();
 	
 	for (ms.begin(it); !ms.end(it); ms.next(it))
 	{

Modified: branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h	2012-07-28 03:16:20 UTC (rev 49320)
+++ branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h	2012-07-28 04:03:31 UTC (rev 49321)
@@ -29,7 +29,11 @@
 #define __KX_VERTEXBUFFEROBJECTSTORAGE
 
 #include <map>
+#ifdef GLES
+#include <GLES2/gl2.h>
+#else
 #include <GL/glew.h>
+#endif
 
 #include "RAS_IStorage.h"
 #include "RAS_IRasterizer.h"




More information about the Bf-blender-cvs mailing list