[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37942] branches/soc-2011-cucumber/source/ gameengine: Ported the VBO code from the bb_dev25 branch.
Daniel Stokes
kupomail at gmail.com
Wed Jun 29 09:20:30 CEST 2011
Revision: 37942
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37942
Author: kupoman
Date: 2011-06-29 07:20:29 +0000 (Wed, 29 Jun 2011)
Log Message:
-----------
Ported the VBO code from the bb_dev25 branch.
Notes from the bb_dev25 VBO commit:
"
20409 - Patch:[#17523] BGE VBO patch by Samuel Anjam (toonist)
20411 - Missing files from last commit (Patch:[ #17523] BGE VBO patch by Samuel Anjam (toonist))
20549 - Don' t create VBO at the same time as Display list.
20662 - Fix for: Normals are not being updated in VBO.
20663 - BGE VBO updates
To do:
1) check if we need to update the tangent matrix as well
2) create the buffers only when necessary
"The buffers for all the texture coordinates are [currently] created unconditionally even if some are not used during the render. Which buffer is used depends on the wireframe, GLSL/multitexture and the texture coordinate used by the material. RAS_VAOpenGLRasterizer::TexCoordPtr(), RAS_VAOpenGLRasterizer::IndexPrimitivesMulti() and RAS_VAOpenGLRasterizer::IndexPrimitives() show the buffers that are actually bound to. Only those buffers should be created."
Note:
VBO doesn't necessarly means better performance than Display List. They can perform faster in Skinned objects (where DisplayList is not being used). But it uses less memory than DisplayList and is a more modern Game Engine technology.
Thanks again to Samuel Anjam (toonist) for the original patch.
"
Modified Paths:
--------------
branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
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_IStorage.h
branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.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/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp 2011-06-29 07:20:29 UTC (rev 37942)
@@ -198,11 +198,15 @@
RAS_IRasterizer* rasterizer = NULL;
if(displaylists) {
- if (GLEW_VERSION_1_1 && !novertexarrays)
- rasterizer = new RAS_ListRasterizer(canvas, true, true);
+ if (GLEW_ARB_vertex_buffer_object)
+ rasterizer = new RAS_ListRasterizer(canvas, true, RAS_VBO);
+ else if (GLEW_VERSION_1_1 && !novertexarrays)
+ rasterizer = new RAS_ListRasterizer(canvas, true, RAS_VA);
else
- rasterizer = new RAS_ListRasterizer(canvas);
+ rasterizer = new RAS_ListRasterizer(canvas, RAS_IMMEDIATE);
}
+ if (GLEW_ARB_vertex_buffer_object)
+ rasterizer = new RAS_OpenGLRasterizer(canvas, RAS_VBO);
else if (GLEW_VERSION_1_1 && !novertexarrays)
rasterizer = new RAS_OpenGLRasterizer(canvas, RAS_VA);
else
Modified: branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/GamePlayer/ghost/GPG_Application.cpp 2011-06-29 07:20:29 UTC (rev 37942)
@@ -567,11 +567,15 @@
goto initFailed;
if(useLists) {
- if(GLEW_VERSION_1_1)
- m_rasterizer = new RAS_ListRasterizer(m_canvas, true);
+ if (GLEW_ARB_vertex_buffer_object)
+ m_rasterizer = new RAS_ListRasterizer(m_canvas, RAS_VBO);
+ else if(GLEW_VERSION_1_1)
+ m_rasterizer = new RAS_ListRasterizer(m_canvas, RAS_VA);
else
- m_rasterizer = new RAS_ListRasterizer(m_canvas);
+ m_rasterizer = new RAS_ListRasterizer(m_canvas, RAS_IMMEDIATE);
}
+ else if (GLEW_ARB_vertex_buffer_object)
+ m_rasterizer = new RAS_OpenGLRasterizer(m_canvas, RAS_VBO);
else if (GLEW_VERSION_1_1)
m_rasterizer = new RAS_OpenGLRasterizer(m_canvas, RAS_VA);
else
Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h 2011-06-29 07:20:29 UTC (rev 37942)
@@ -54,6 +54,7 @@
class RAS_ICanvas;
class RAS_IPolyMaterial;
+class RAS_MeshSlot;
typedef vector<unsigned short> KX_IndexArray;
typedef vector<RAS_TexVert> KX_VertexArray;
@@ -417,6 +418,10 @@
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-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp 2011-06-29 07:20:29 UTC (rev 37942)
@@ -48,6 +48,27 @@
#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()
@@ -166,6 +187,7 @@
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;
@@ -197,6 +219,7 @@
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;
@@ -218,6 +241,7 @@
RAS_DisplayArrayList::iterator it;
RAS_DisplayArray *darray = NULL;
+ // find an array which doesn't contain the max amount of indices/vertices
for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
darray = *it;
@@ -610,6 +634,9 @@
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-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MaterialBucket.h 2011-06-29 07:20:29 UTC (rev 37942)
@@ -77,6 +77,33 @@
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
@@ -87,12 +114,16 @@
/* 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 */
@@ -147,6 +178,7 @@
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_IStorage.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h 2011-06-29 07:20:29 UTC (rev 37942)
@@ -34,7 +34,8 @@
enum RAS_STORAGE_TYPE {
RAS_IMMEDIATE,
- RAS_VA
+ RAS_VA,
+ RAS_VBO
};
class RAS_IStorage
Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp 2011-06-29 07:20:29 UTC (rev 37942)
@@ -106,8 +106,8 @@
-RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays, bool lock)
-: RAS_OpenGLRasterizer(canvas, (useVertexArrays) ? RAS_VA : RAS_IMMEDIATE),
+RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool lock, int storage)
+: RAS_OpenGLRasterizer(canvas, storage),
mATI(false)
{
if (!strcmp((const char*)glGetString(GL_VENDOR), "ATI Technologies Inc."))
Modified: branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h 2011-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h 2011-06-29 07:20:29 UTC (rev 37942)
@@ -61,7 +61,7 @@
public:
void RemoveListSlot(RAS_ListSlot* list);
- RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays=false, bool lock=false);
+ RAS_ListRasterizer(RAS_ICanvas* canvas, bool lock=false, int storage=RAS_IMMEDIATE);
virtual ~RAS_ListRasterizer();
virtual void IndexPrimitives(class RAS_MeshSlot& ms);
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-06-29 06:14:15 UTC (rev 37941)
+++ branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp 2011-06-29 07:20:29 UTC (rev 37942)
@@ -91,7 +91,8 @@
m_attrib_num(0),
//m_last_blendmode(GPU_BLEND_SOLID),
m_last_frontface(true),
- m_materialCachingInfo(0)
+ m_materialCachingInfo(0),
+ m_storage_type(storage)
{
m_viewmatrix.setIdentity();
m_viewinvmatrix.setIdentity();
@@ -103,8 +104,13 @@
hinterlace_mask[i] = (i&1)*0xFFFFFFFF;
}
hinterlace_mask[32] = 0;
- if (storage == RAS_VA)
+ if (m_storage_type == RAS_VBO)
{
+ m_storage = new RAS_StorageVBO(this, &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);
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list