Commit 2ca8282e authored by lukeph's avatar lukeph

-- added VBO support --

-so far only the openGL driver is supported, will add dx tomorrow or the next day

-right now to use, go: MeshBuffer->setHardwareMappingHint(EHM_STATIC); but this will be automatic when complete

-code needs a clean up, and the design isn't fixed, I just wanted to get stuff happening :)

-works well with hardware skinning :)

(design: http://img220.imageshack.us/img220/1931/vbo8xy8.png)

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1095 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 51f7a358
...@@ -18,7 +18,7 @@ namespace scene ...@@ -18,7 +18,7 @@ namespace scene
{ {
public: public:
//! constructor //! constructor
CMeshBuffer() // everything's default constructed CMeshBuffer():ChangedID(1),MappingHint(EHM_NEVER) // everything's default constructed
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("SMeshBuffer"); setDebugName("SMeshBuffer");
...@@ -41,13 +41,13 @@ namespace scene ...@@ -41,13 +41,13 @@ namespace scene
virtual const void* getVertices() const virtual const void* getVertices() const
{ {
return Vertices.const_pointer(); return Vertices.const_pointer();
} }
//! returns pointer to vertices //! returns pointer to vertices
virtual void* getVertices() virtual void* getVertices()
{ {
return Vertices.pointer(); return Vertices.pointer();
} }
//! returns amount of vertices //! returns amount of vertices
virtual u32 getVertexCount() const virtual u32 getVertexCount() const
...@@ -109,27 +109,27 @@ namespace scene ...@@ -109,27 +109,27 @@ namespace scene
virtual const core::vector3df& getPosition(u32 i) const virtual const core::vector3df& getPosition(u32 i) const
{ {
return Vertices[i].Pos; return Vertices[i].Pos;
} }
//! returns position of vertex i //! returns position of vertex i
virtual core::vector3df& getPosition(u32 i) virtual core::vector3df& getPosition(u32 i)
{ {
return Vertices[i].Pos; return Vertices[i].Pos;
} }
//! returns normal of vertex i //! returns normal of vertex i
virtual const core::vector3df& getNormal(u32 i) const virtual const core::vector3df& getNormal(u32 i) const
{ {
return Vertices[i].Normal; return Vertices[i].Normal;
} }
//! returns normal of vertex i //! returns normal of vertex i
virtual core::vector3df& getNormal(u32 i) virtual core::vector3df& getNormal(u32 i)
{ {
return Vertices[i].Normal; return Vertices[i].Normal;
} }
//! append the vertices and indices to the current buffer //! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices)
{ {
...@@ -170,6 +170,29 @@ namespace scene ...@@ -170,6 +170,29 @@ namespace scene
BoundingBox.addInternalBox(other->getBoundingBox()); BoundingBox.addInternalBox(other->getBoundingBox());
} }
//! get the current hardware mapping hint
virtual const E_HARDWARE_MAPPING getHardwareMappingHint() const
{
return MappingHint;
}
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
{
MappingHint=NewMappingHint;
}
//! flags the mesh as changed, reloads hardware buffers
virtual void setDirty() {ChangedID++;}
virtual const u32 getChangedID() const {return ChangedID;}
u32 ChangedID;
//! hardware mapping hint
E_HARDWARE_MAPPING MappingHint;
//! Material for this meshbuffer. //! Material for this meshbuffer.
video::SMaterial Material; video::SMaterial Material;
//! Vertices of this buffer //! Vertices of this buffer
......
...@@ -55,6 +55,20 @@ namespace scene ...@@ -55,6 +55,20 @@ namespace scene
}; };
enum E_HARDWARE_MAPPING
{
//! Don't load in hardware
EHM_NEVER=0,
//! Rarely changed
EHM_STATIC,
//! Sometimes changed
EHM_DYNAMIC,
//! Always changed
EHM_STREAM
};
//! Struct for holding a mesh with a single material //! Struct for holding a mesh with a single material
/** SMeshBuffer is a simple implementation of a MeshBuffer. */ /** SMeshBuffer is a simple implementation of a MeshBuffer. */
...@@ -76,11 +90,11 @@ namespace scene ...@@ -76,11 +90,11 @@ namespace scene
//! returns pointer to vertex data. The data is an array of vertices. Which vertex //! returns pointer to vertex data. The data is an array of vertices. Which vertex
//! type is used can be determined with getVertexType(). //! type is used can be determined with getVertexType().
virtual const void* getVertices() const = 0; virtual const void* getVertices() const = 0;
//! returns pointer to vertex data. The data is an array of vertices. Which vertex //! returns pointer to vertex data. The data is an array of vertices. Which vertex
//! type is used can be determined with getVertexType(). //! type is used can be determined with getVertexType().
virtual void* getVertices() = 0; virtual void* getVertices() = 0;
//! returns amount of vertices //! returns amount of vertices
virtual u32 getVertexCount() const = 0; virtual u32 getVertexCount() const = 0;
...@@ -120,6 +134,21 @@ namespace scene ...@@ -120,6 +134,21 @@ namespace scene
//! append the meshbuffer to the current buffer //! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) = 0; virtual void append(const IMeshBuffer* const other) = 0;
//! get the current hardware mapping hint
virtual const E_HARDWARE_MAPPING getHardwareMappingHint() const = 0;
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint ) = 0;
//! flags the mesh as changed, reloads hardware buffers
virtual void setDirty() = 0;
virtual const u32 getChangedID() const = 0;
u32 HardwareHint;
}; };
} // end namespace scene } // end namespace scene
......
...@@ -16,7 +16,7 @@ namespace scene ...@@ -16,7 +16,7 @@ namespace scene
struct SSharedMeshBuffer : public IMeshBuffer struct SSharedMeshBuffer : public IMeshBuffer
{ {
//! constructor //! constructor
SSharedMeshBuffer() : IMeshBuffer(), Vertices(0) SSharedMeshBuffer() : IMeshBuffer(), ChangedID(1),MappingHint(Never), Vertices(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("SSharedMeshBuffer"); setDebugName("SSharedMeshBuffer");
...@@ -127,6 +127,31 @@ namespace scene ...@@ -127,6 +127,31 @@ namespace scene
//! append the meshbuffer to the current buffer //! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) {} virtual void append(const IMeshBuffer* const other) {}
//! get the current hardware mapping hint
virtual const E_HARDWARE_MAPPING getHardwareMappingHint() const
{
return MappingHint;
}
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
{
MappingHint=NewMappingHint;
}
//! flags the mesh as changed, reloads hardware buffers
virtual void setDirty() {ChangedID++;}
virtual const u32 getChangedID() const {return ChangedID;}
u32 ChangedID;
// hardware mapping hint
E_HARDWARE_MAPPING MappingHint;
video::SMaterial Material; //! material of this meshBuffer video::SMaterial Material; //! material of this meshBuffer
core::array<video::S3DVertex> *Vertices;//! Shared Array of vertices core::array<video::S3DVertex> *Vertices;//! Shared Array of vertices
core::array<u16> Indices; //! Array of Indices core::array<u16> Indices; //! Array of Indices
......
...@@ -19,7 +19,7 @@ namespace scene ...@@ -19,7 +19,7 @@ namespace scene
//! S3DVertex2TCoords, S3DVertex and S3DVertexTangents at runtime //! S3DVertex2TCoords, S3DVertex and S3DVertexTangents at runtime
struct SSkinMeshBuffer : public IMeshBuffer struct SSkinMeshBuffer : public IMeshBuffer
{ {
SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) : VertexType(vt) SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) : ChangedID(1),MappingHint(EHM_NEVER),VertexType(vt)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("SSkinMeshBuffer"); setDebugName("SSkinMeshBuffer");
...@@ -210,10 +210,10 @@ struct SSkinMeshBuffer : public IMeshBuffer ...@@ -210,10 +210,10 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Pos; return Vertices_2TCoords[i].Pos;
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
return Vertices_Tangents[i].Pos; return Vertices_Tangents[i].Pos;
default: default:
return Vertices_Standard[i].Pos; return Vertices_Standard[i].Pos;
} }
} }
//! returns position of vertex i //! returns position of vertex i
virtual core::vector3df& getPosition(u32 i) virtual core::vector3df& getPosition(u32 i)
...@@ -224,10 +224,10 @@ struct SSkinMeshBuffer : public IMeshBuffer ...@@ -224,10 +224,10 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Pos; return Vertices_2TCoords[i].Pos;
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
return Vertices_Tangents[i].Pos; return Vertices_Tangents[i].Pos;
default: default:
return Vertices_Standard[i].Pos; return Vertices_Standard[i].Pos;
} }
} }
//! returns normal of vertex i //! returns normal of vertex i
virtual const core::vector3df& getNormal(u32 i) const virtual const core::vector3df& getNormal(u32 i) const
...@@ -238,10 +238,10 @@ struct SSkinMeshBuffer : public IMeshBuffer ...@@ -238,10 +238,10 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Normal; return Vertices_2TCoords[i].Normal;
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
return Vertices_Tangents[i].Normal; return Vertices_Tangents[i].Normal;
default: default:
return Vertices_Standard[i].Normal; return Vertices_Standard[i].Normal;
} }
} }
//! returns normal of vertex i //! returns normal of vertex i
virtual core::vector3df& getNormal(u32 i) virtual core::vector3df& getNormal(u32 i)
...@@ -252,17 +252,45 @@ struct SSkinMeshBuffer : public IMeshBuffer ...@@ -252,17 +252,45 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Normal; return Vertices_2TCoords[i].Normal;
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
return Vertices_Tangents[i].Normal; return Vertices_Tangents[i].Normal;
default: default:
return Vertices_Standard[i].Normal; return Vertices_Standard[i].Normal;
} }
} }
//! append the vertices and indices to the current buffer //! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {} virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
//! append the meshbuffer to the current buffer //! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) {} virtual void append(const IMeshBuffer* const other) {}
//! get the current hardware mapping hint
virtual const E_HARDWARE_MAPPING getHardwareMappingHint() const
{
return MappingHint;
}
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
{
MappingHint=NewMappingHint;
}
//! flags the mesh as changed, reloads hardware buffers
virtual void setDirty() {ChangedID++;}
virtual const u32 getChangedID() const {return ChangedID;}
u32 ChangedID;
// hardware mapping hint
E_HARDWARE_MAPPING MappingHint;
//ISkinnedMesh::SJoint *AttachedJoint; //ISkinnedMesh::SJoint *AttachedJoint;
core::matrix4 Transformation; core::matrix4 Transformation;
......
...@@ -214,6 +214,7 @@ bool CNullDriver::beginScene(bool backBuffer, bool zBuffer, SColor color) ...@@ -214,6 +214,7 @@ bool CNullDriver::beginScene(bool backBuffer, bool zBuffer, SColor color)
bool CNullDriver::endScene( s32 windowId, core::rect<s32>* sourceRect ) bool CNullDriver::endScene( s32 windowId, core::rect<s32>* sourceRect )
{ {
FPSCounter.registerFrame(os::Timer::getRealTime(), PrimitivesDrawn); FPSCounter.registerFrame(os::Timer::getRealTime(), PrimitivesDrawn);
updateAllHardwareBuffers();
return true; return true;
} }
...@@ -1246,10 +1247,84 @@ void CNullDriver::drawMeshBuffer(const scene::IMeshBuffer* mb) ...@@ -1246,10 +1247,84 @@ void CNullDriver::drawMeshBuffer(const scene::IMeshBuffer* mb)
if (!mb) if (!mb)
return; return;
drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), mb->getIndexCount()/3, mb->getVertexType(), scene::EPT_TRIANGLES); //IVertexBuffer and IIndexBuffer later
SHWBufferLink *HWBuffer=getBufferLink(mb);
if (HWBuffer)
drawHardwareBuffer(HWBuffer);
else
drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), mb->getIndexCount()/3, mb->getVertexType(), scene::EPT_TRIANGLES);
} }
CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer* mb)
{
if (!isHardwareBufferRecommend(mb))
return 0;
/*
u32 startIndex=0;
for (u32 n=0;n<HWBufferLinks.size();n+=30)
{
if (HWBufferLinks[n]->MeshBuffer < mb)
startIndex=n;
}
*/
//search for hardware links
for (u32 n=0;n<HWBufferLinks.size();++n)
{
SHWBufferLink *Link=HWBufferLinks[n];
if (Link->MeshBuffer==mb)
{
((scene::IMeshBuffer*)mb)->HardwareHint=n;
return Link;
}
}
return createHardwareBuffer(mb); //no hardware links, and mesh wants one, create it
}
//! Update all hardware buffers, remove unused ones
void CNullDriver::updateAllHardwareBuffers()
{
for (u32 n=0;n<HWBufferLinks.size();++n)
{
SHWBufferLink *Link=HWBufferLinks[n];
Link->LastUsed++;
if (Link->LastUsed>1000)
{
deleteHardwareBuffer(Link);
delete Link;
HWBufferLinks.erase(n);
}
}
}
//! Remove all hardware buffers
void CNullDriver::removeAllHardwareBuffers()
{
for (u32 n=0;n<HWBufferLinks.size();++n)
{
deleteHardwareBuffer(HWBufferLinks[n]);
delete HWBufferLinks[n];
}
HWBufferLinks.clear();
}
bool CNullDriver::isHardwareBufferRecommend(const scene::IMeshBuffer* mb)
{
if (mb->getHardwareMappingHint()==scene::EHM_NEVER)
return false;
if (mb->getVertexCount()<500) //todo: tweak and make user definable
return false;
return true;
}
//! Only used by the internal engine. Used to notify the driver that //! Only used by the internal engine. Used to notify the driver that
//! the window was resized. //! the window was resized.
......
This diff is collapsed.
This diff is collapsed.
...@@ -106,6 +106,30 @@ namespace video ...@@ -106,6 +106,30 @@ namespace video
//! sets transformation //! sets transformation
virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat); virtual void setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat);
struct SHWBufferLink_opengl : public SHWBufferLink
{
SHWBufferLink_opengl(const scene::IMeshBuffer *_MeshBuffer): SHWBufferLink(_MeshBuffer), vbo_verticesID(0),vbo_indicesID(0){}
GLuint vbo_verticesID; //tmp
GLuint vbo_indicesID; //tmp
};
bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);
//! updates hardware buffer if needed
virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer);
//! Create hardware buffer from mesh
virtual SHWBufferLink *createHardwareBuffer(const scene::IMeshBuffer* mb);
//! Delete hardware buffer (only some drivers can)
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
//! Draw hardware buffer
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer);
//! draws a vertex primitive list //! draws a vertex primitive list
virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const u16* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType); virtual void drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const u16* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType);
...@@ -324,6 +348,10 @@ namespace video ...@@ -324,6 +348,10 @@ namespace video
void createMaterialRenderers(); void createMaterialRenderers();
core::stringw Name; core::stringw Name;
core::matrix4 Matrices[ETS_COUNT]; core::matrix4 Matrices[ETS_COUNT];
core::array<u8> ColorBuffer; core::array<u8> ColorBuffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment