small vbo changes, added removeHardwareBuffer(const scene::IMeshBuffer* mb)

git-svn-id: http://svn.code.sf.net/p/irrlicht/code/trunk@1109 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
lukeph 2007-12-09 13:19:31 +00:00
parent e07e88b87e
commit 029da617db
4 changed files with 47 additions and 25 deletions

View File

@ -199,6 +199,12 @@ namespace video
materials which are using textures to 0 first. */ materials which are using textures to 0 first. */
virtual void removeAllTextures() = 0; virtual void removeAllTextures() = 0;
//! Remove hardware buffer
virtual void removeHardwareBuffer(const scene::IMeshBuffer* mb) = 0;
//! Remove all hardware buffers
virtual void removeAllHardwareBuffers() = 0;
//! Creates a 1bit alpha channel of the texture based of an color key. //! Creates a 1bit alpha channel of the texture based of an color key.
/** This makes the texture transparent at the regions where this color /** This makes the texture transparent at the regions where this color
key can be found when using for example draw2DImage with useAlphachannel key can be found when using for example draw2DImage with useAlphachannel
@ -564,7 +570,7 @@ namespace video
/** \return Size of screen or render window. */ /** \return Size of screen or render window. */
virtual const core::dimension2d<s32>& getScreenSize() const = 0; virtual const core::dimension2d<s32>& getScreenSize() const = 0;
//! Returns the size of the current render target, or the screen size if the driver //! Returns the size of the current render target, or the screen size if the driver
//! doesnt support render to texture //! doesnt support render to texture
/** \return Size of render target or screen/window */ /** \return Size of render target or screen/window */
virtual const core::dimension2d<s32>& getCurrentRenderTargetSize() const = 0; virtual const core::dimension2d<s32>& getCurrentRenderTargetSize() const = 0;

View File

@ -1262,22 +1262,12 @@ CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer*
if (!isHardwareBufferRecommend(mb)) if (!isHardwareBufferRecommend(mb))
return 0; 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 //search for hardware links
for (u32 n=0;n<HWBufferLinks.size();++n) for (u32 n=0;n<HWBufferLinks.size();++n)
{ {
SHWBufferLink *Link=HWBufferLinks[n]; SHWBufferLink *Link=HWBufferLinks[n];
if (Link->MeshBuffer==mb) if (Link->MeshBuffer==mb)
{ {
//((scene::IMeshBuffer*)mb)->HardwareHint=n;
return Link; return Link;
} }
} }
@ -1294,27 +1284,45 @@ void CNullDriver::updateAllHardwareBuffers()
Link->LastUsed++; Link->LastUsed++;
if (Link->LastUsed>1000) if (Link->LastUsed>20000)
{ {
deleteHardwareBuffer(Link); deleteHardwareBuffer(Link);
delete Link;
HWBufferLinks.erase(n);
} }
} }
} }
//! Remove all hardware buffers
void CNullDriver::removeAllHardwareBuffers() void CNullDriver::deleteHardwareBuffer(SHWBufferLink *HWBuffer)
{
s32 n=HWBufferLinks.binary_search(HWBuffer);
if (n!=-1) HWBufferLinks.erase(n);
delete HWBuffer;
}
//! Remove hardware buffer
void CNullDriver::removeHardwareBuffer(const scene::IMeshBuffer* mb)
{ {
for (u32 n=0;n<HWBufferLinks.size();++n) for (u32 n=0;n<HWBufferLinks.size();++n)
{ {
deleteHardwareBuffer(HWBufferLinks[n]); SHWBufferLink *Link=HWBufferLinks[n];
delete HWBufferLinks[n]; if (Link->MeshBuffer==mb)
{
deleteHardwareBuffer(Link);
}
} }
HWBufferLinks.clear();
} }
//! Remove all hardware buffers
void CNullDriver::removeAllHardwareBuffers()
{
while (HWBufferLinks.size())
deleteHardwareBuffer(HWBufferLinks[0]);
}
bool CNullDriver::isHardwareBufferRecommend(const scene::IMeshBuffer* mb) bool CNullDriver::isHardwareBufferRecommend(const scene::IMeshBuffer* mb)
{ {
if (mb->getHardwareMappingHint()==scene::EHM_NEVER) if (mb->getHardwareMappingHint()==scene::EHM_NEVER)

View File

@ -324,12 +324,15 @@ namespace video
//! Draw hardware buffer (only some drivers can) //! Draw hardware buffer (only some drivers can)
virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {} virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {}
//! Delete hardware buffer (only some drivers can)
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer) {}
//! Update all hardware buffers, remove unused ones //! Update all hardware buffers, remove unused ones
virtual void updateAllHardwareBuffers(); virtual void updateAllHardwareBuffers();
//! Delete hardware buffer
virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer);
//! Remove hardware buffer
virtual void removeHardwareBuffer(const scene::IMeshBuffer* mb);
//! Remove all hardware buffers //! Remove all hardware buffers
virtual void removeAllHardwareBuffers(); virtual void removeAllHardwareBuffers();

View File

@ -570,6 +570,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
if (!HWBuffer->vbo_verticesID) if (!HWBuffer->vbo_verticesID)
{ {
extGlGenBuffers(1, &HWBuffer->vbo_verticesID); extGlGenBuffers(1, &HWBuffer->vbo_verticesID);
if (!HWBuffer->vbo_verticesID) return false;
newBuffer=true; newBuffer=true;
} }
@ -621,6 +622,7 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
if (!HWBuffer->vbo_indicesID) if (!HWBuffer->vbo_indicesID)
{ {
extGlGenBuffers(1, &HWBuffer->vbo_indicesID); extGlGenBuffers(1, &HWBuffer->vbo_indicesID);
if (!HWBuffer->vbo_indicesID) return false;
newBuffer=true; newBuffer=true;
} }
@ -710,8 +712,6 @@ COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::I
if (!updateHardwareBuffer(HWBuffer)) if (!updateHardwareBuffer(HWBuffer))
{ {
deleteHardwareBuffer(HWBuffer); deleteHardwareBuffer(HWBuffer);
HWBufferLinks.erase(n);
delete HWBuffer;
return 0; return 0;
} }
@ -724,6 +724,8 @@ COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::I
void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer)
{ {
if (!_HWBuffer) return;
#if defined(GL_ARB_vertex_buffer_object) #if defined(GL_ARB_vertex_buffer_object)
SHWBufferLink_opengl *HWBuffer=(SHWBufferLink_opengl*)_HWBuffer; SHWBufferLink_opengl *HWBuffer=(SHWBufferLink_opengl*)_HWBuffer;
if (HWBuffer->vbo_verticesID) if (HWBuffer->vbo_verticesID)
@ -737,6 +739,9 @@ void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer)
HWBuffer->vbo_indicesID=0; HWBuffer->vbo_indicesID=0;
} }
#endif #endif
CNullDriver::deleteHardwareBuffer(_HWBuffer);
} }