From 1c3fbf02565909fb5fa1b82194e63b610e020aae Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 29 Jul 2013 03:41:10 +0200 Subject: [PATCH] Improve performance of UsedTexture debugging info in OpenGL driver --HG-- branch : kaetemi-optimize --- code/nel/src/3d/driver/opengl/driver_opengl.cpp | 8 ++++++-- code/nel/src/3d/driver/opengl/driver_opengl.h | 4 +++- .../src/3d/driver/opengl/driver_opengl_texture.cpp | 13 +++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 29e14a1a0..08b883e12 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1488,7 +1488,10 @@ void CDriverGL::enableUsedTextureMemorySum (bool enable) H_AUTO_OGL(CDriverGL_enableUsedTextureMemorySum ) if (enable) + { nlinfo ("3D: PERFORMANCE INFO: enableUsedTextureMemorySum has been set to true in CDriverGL"); + _TextureUsed.reserve(512); + } _SumTextureMemoryUsed=enable; } @@ -1502,7 +1505,7 @@ uint32 CDriverGL::getUsedTextureMemory() const uint32 memory=0; // For each texture used - set::const_iterator ite=_TextureUsed.begin(); + std::vector::const_iterator ite = _TextureUsed.begin(); while (ite!=_TextureUsed.end()) { // Get the gl texture @@ -1510,7 +1513,8 @@ uint32 CDriverGL::getUsedTextureMemory() const gltext= (*ite); // Sum the memory used by this texture - memory+=gltext->TextureMemory; + if (gltext) + memory+=gltext->TextureMemory; // Next texture ite++; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index bfe73492d..ee6431dc4 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -196,6 +196,8 @@ public: bool initFrameBufferObject(ITexture * tex); bool activeFrameBufferObject(ITexture * tex); + + std::vector::size_type TextureUsedIdx; }; @@ -1273,7 +1275,7 @@ private: uint32 _NbSetupMaterialCall; uint32 _NbSetupModelMatrixCall; bool _SumTextureMemoryUsed; - std::set _TextureUsed; + std::vector _TextureUsed; uint computeMipMapMemoryUsage(uint w, uint h, GLint glfmt) const; // VBHard Lock Profiling diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp index 77954a8e3..055f8d99d 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp @@ -79,6 +79,8 @@ CTextureDrvInfosGL::CTextureDrvInfosGL(IDriver *drv, ItTexDrvInfoPtrMap it, CDri InitFBO = false; AttachDepthStencil = true; UsePackedDepthStencil = drvGl->supportPackedDepthStencil(); + + TextureUsedIdx = 0; } // *************************************************************************** CTextureDrvInfosGL::~CTextureDrvInfosGL() @@ -91,7 +93,10 @@ CTextureDrvInfosGL::~CTextureDrvInfosGL() _Driver->_AllocatedTextureMemory-= TextureMemory; // release in TextureUsed. - _Driver->_TextureUsed.erase (this); + if (TextureUsedIdx < _Driver->_TextureUsed.size() && _Driver->_TextureUsed[TextureUsedIdx] == this) + { + _Driver->_TextureUsed[TextureUsedIdx] = NULL; + } if(InitFBO) { @@ -1492,7 +1497,11 @@ bool CDriverGL::activateTexture(uint stage, ITexture *tex) if (_SumTextureMemoryUsed) { // Insert the pointer of this texture - _TextureUsed.insert (gltext); + if (gltext->TextureUsedIdx >= _TextureUsed.size() || _TextureUsed[gltext->TextureUsedIdx] != gltext) + { + gltext->TextureUsedIdx = _TextureUsed.size(); + _TextureUsed.push_back(gltext); + } } if(tex->isTextureCube())