From 029da617db46aa3be50ebc9da27a606e88dd0081 Mon Sep 17 00:00:00 2001 From: lukeph Date: Sun, 9 Dec 2007 13:19:31 +0000 Subject: [PATCH] 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 --- include/IVideoDriver.h | 8 +++++- source/Irrlicht/CNullDriver.cpp | 46 ++++++++++++++++++------------- source/Irrlicht/CNullDriver.h | 9 ++++-- source/Irrlicht/COpenGLDriver.cpp | 9 ++++-- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index 2e1546e3..f0e736fe 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -199,6 +199,12 @@ namespace video materials which are using textures to 0 first. */ 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. /** This makes the texture transparent at the regions where this color key can be found when using for example draw2DImage with useAlphachannel @@ -564,7 +570,7 @@ namespace video /** \return Size of screen or render window. */ virtual const core::dimension2d& 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 /** \return Size of render target or screen/window */ virtual const core::dimension2d& getCurrentRenderTargetSize() const = 0; diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 1814e681..53f6a0ff 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -1262,22 +1262,12 @@ CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer* if (!isHardwareBufferRecommend(mb)) return 0; - /* - u32 startIndex=0; - for (u32 n=0;nMeshBuffer < mb) - startIndex=n; - } - */ - //search for hardware links for (u32 n=0;nMeshBuffer==mb) { - //((scene::IMeshBuffer*)mb)->HardwareHint=n; return Link; } } @@ -1294,27 +1284,45 @@ void CNullDriver::updateAllHardwareBuffers() Link->LastUsed++; - if (Link->LastUsed>1000) + if (Link->LastUsed>20000) { 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;nMeshBuffer==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) { if (mb->getHardwareMappingHint()==scene::EHM_NEVER) diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index ebfc64a3..3b6a4902 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -324,12 +324,15 @@ namespace video //! Draw hardware buffer (only some drivers can) virtual void drawHardwareBuffer(SHWBufferLink *HWBuffer) {} - //! Delete hardware buffer (only some drivers can) - virtual void deleteHardwareBuffer(SHWBufferLink *HWBuffer) {} - //! Update all hardware buffers, remove unused ones 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 virtual void removeAllHardwareBuffers(); diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 22511bca..b2f9c657 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -570,6 +570,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) if (!HWBuffer->vbo_verticesID) { extGlGenBuffers(1, &HWBuffer->vbo_verticesID); + if (!HWBuffer->vbo_verticesID) return false; newBuffer=true; } @@ -621,6 +622,7 @@ bool COpenGLDriver::updateIndexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) if (!HWBuffer->vbo_indicesID) { extGlGenBuffers(1, &HWBuffer->vbo_indicesID); + if (!HWBuffer->vbo_indicesID) return false; newBuffer=true; } @@ -710,8 +712,6 @@ COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::I if (!updateHardwareBuffer(HWBuffer)) { deleteHardwareBuffer(HWBuffer); - HWBufferLinks.erase(n); - delete HWBuffer; return 0; } @@ -724,6 +724,8 @@ COpenGLDriver::SHWBufferLink *COpenGLDriver::createHardwareBuffer(const scene::I void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) { + if (!_HWBuffer) return; + #if defined(GL_ARB_vertex_buffer_object) SHWBufferLink_opengl *HWBuffer=(SHWBufferLink_opengl*)_HWBuffer; if (HWBuffer->vbo_verticesID) @@ -737,6 +739,9 @@ void COpenGLDriver::deleteHardwareBuffer(SHWBufferLink *_HWBuffer) HWBuffer->vbo_indicesID=0; } #endif + + CNullDriver::deleteHardwareBuffer(_HWBuffer); + }