[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20409] branches/bb_dev/source/gameengine/ Rasterizer: Patch:[#17523] BGE VBO patch by Samuel Anjam (toonist)
Dalai Felinto
dfelinto at gmail.com
Mon May 25 23:15:21 CEST 2009
Revision: 20409
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20409
Author: dfelinto
Date: 2009-05-25 23:15:19 +0200 (Mon, 25 May 2009)
Log Message:
-----------
Patch:[#17523] BGE VBO patch by Samuel Anjam (toonist)
- patch updated for recent trunk.
This patch implement a VBO option to handle skinned meshes.
It doesn't give better performance than Display List (at least not in un-skinned meshes).
But this is an important addition to in the near future implement full GLSL skinned objects.
Modified Paths:
--------------
branches/bb_dev/source/gameengine/Rasterizer/RAS_IRasterizer.h
branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.h
branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
Modified: branches/bb_dev/source/gameengine/Rasterizer/RAS_IRasterizer.h
===================================================================
--- branches/bb_dev/source/gameengine/Rasterizer/RAS_IRasterizer.h 2009-05-25 20:48:52 UTC (rev 20408)
+++ branches/bb_dev/source/gameengine/Rasterizer/RAS_IRasterizer.h 2009-05-25 21:15:19 UTC (rev 20409)
@@ -45,6 +45,7 @@
class RAS_ICanvas;
class RAS_IPolyMaterial;
+class RAS_MeshSlot;
typedef vector<unsigned short> KX_IndexArray;
typedef vector<RAS_TexVert> KX_VertexArray;
@@ -407,6 +408,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;
};
#endif //__RAS_IRASTERIZER
Modified: branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
===================================================================
--- branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp 2009-05-25 20:48:52 UTC (rev 20408)
+++ branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp 2009-05-25 21:15:19 UTC (rev 20409)
@@ -40,6 +40,29 @@
#include "RAS_MeshObject.h"
#include "RAS_Deformer.h" // __NLA
+/* vertex buffer object slot */
+
+#include "RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h"
+
+RAS_VboSlot::RAS_VboSlot(RAS_VAOpenGLRasterizer *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()
@@ -158,6 +181,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;
@@ -189,6 +213,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;
@@ -210,6 +235,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;
@@ -602,6 +628,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/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.h
===================================================================
--- branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.h 2009-05-25 20:48:52 UTC (rev 20408)
+++ branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.h 2009-05-25 21:15:19 UTC (rev 20409)
@@ -72,6 +72,35 @@
class RAS_MaterialBucket;
struct DerivedMesh;
+/* Vertex Buffer Object data used for OpenGL drawing */
+
+class RAS_VAOpenGLRasterizer;
+
+class RAS_VboSlot
+{
+public:
+ RAS_VAOpenGLRasterizer *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 fastes way. */
+ float *m_verts;
+
+ RAS_VboSlot(RAS_VAOpenGLRasterizer *rasty);
+ ~RAS_VboSlot();
+};
+
/* An array with data used for OpenGL drawing */
class RAS_DisplayArray
@@ -81,10 +110,14 @@
vector<unsigned short> m_index;
enum { LINE = 2, TRIANGLE = 3, QUAD = 4 } m_type;
//RAS_MeshSlot *m_origSlot;
+ RAS_VboSlot *m_vboSlot;
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 */
@@ -139,6 +172,7 @@
struct iterator {
RAS_DisplayArray *array;
RAS_TexVert *vertex;
+ RAS_VboSlot *vboslot;
unsigned short *index;
size_t startvertex;
size_t endvertex;
Modified: branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
===================================================================
--- branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h 2009-05-25 20:48:52 UTC (rev 20408)
+++ branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h 2009-05-25 21:15:19 UTC (rev 20409)
@@ -289,6 +289,10 @@
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) {};
};
#endif //__RAS_OPENGLRASTERIZER
More information about the Bf-blender-cvs
mailing list