From: <axl...@us...> - 2010-11-21 14:22:40
|
Revision: 768 http://hgengine.svn.sourceforge.net/hgengine/?rev=768&view=rev Author: axlecrusher Date: 2010-11-21 14:22:34 +0000 (Sun, 21 Nov 2010) Log Message: ----------- Make an array of strings that can be used to set ShaderAttribute. This removes a lot of ssprintf statements, malloc, and free calls. Provides a noticeable boost in performance. Modified Paths: -------------- Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2010-11-21 04:52:54 UTC (rev 767) +++ Mercury2/src/Texture.cpp 2010-11-21 14:22:34 UTC (rev 768) @@ -19,6 +19,9 @@ { m_initTextureSuccess = true; m_numActiveTextures = 0; + m_shaderBindPoints = new MString[Texture::TextureStackDepth]; + for (unsigned short i = 0; i < Texture::TextureStackDepth; ++i) + m_shaderBindPoints[i] = ssprintf("HG_Texture%d", m_numActiveTextures); } SetIgnoreCull( true ); @@ -189,7 +192,7 @@ ShaderAttribute sa; sa.type = ShaderAttribute::TYPE_SAMPLER; sa.value.iSampler = m_numActiveTextures; - Shader::SetAttribute( ssprintf("HG_Texture%d", m_numActiveTextures), sa); + Shader::SetAttribute( m_shaderBindPoints[m_numActiveTextures], sa); m_activeTextures.Push(this); @@ -201,15 +204,25 @@ //Everything needs to be done in reverse of BindTexture() --m_numActiveTextures; - Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_numActiveTextures) ); + Shader::RemoveAttribute( m_shaderBindPoints[m_numActiveTextures] ); m_activeTextures.Pop(); // Deactivate(GL_TEXTURE0 + m_numActiveTextures); } +void Texture::ActiveTexture(uint32_t i) +{ + static uint32_t active = 0; + if (active!=i) + { + GLCALL( glActiveTexture( i ) ); + } + active = i; +} + void Texture::Activate(uint32_t textureResource) { - GLCALL( glActiveTexture( textureResource ) ); + ActiveTexture(textureResource); // GLCALL( glClientActiveTextureARB(textureResource) ); //XXX: Note to self, this seems to be causing a crash, look into it. GLCALL( glEnableClientState(GL_TEXTURE_COORD_ARRAY) ); GLCALL( glEnable( GL_TEXTURE_2D ) ); @@ -217,7 +230,7 @@ void Texture::Deactivate(uint32_t textureResource) { - GLCALL( glActiveTexture( textureResource ) ); + ActiveTexture(textureResource); // GLCALL( glClientActiveTextureARB(textureResource) ); GLCALL( glDisableClientState(GL_TEXTURE_COORD_ARRAY) ); GLCALL( glDisable( GL_TEXTURE_2D ) ); @@ -228,7 +241,7 @@ { for (uint8_t i = 0; i < m_numActiveTextures; ++i) { - GLCALL( glActiveTexture( GL_TEXTURE0+i ) ); + ActiveTexture(GL_TEXTURE0+i); // GLCALL( glClientActiveTextureARB(GL_TEXTURE0+i) ); //XXX: Note to self, this seems to be causing a crash, look into it. GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(uvByteOffset)) ); } @@ -355,6 +368,8 @@ Texture** Texture::m_lastBound = NULL; uint8_t Texture::m_maxActiveTextures = 0; +MString* Texture::m_shaderBindPoints = NULL; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2010-11-21 04:52:54 UTC (rev 767) +++ Mercury2/src/Texture.h 2010-11-21 14:22:34 UTC (rev 768) @@ -49,6 +49,7 @@ static void ApplyActiveTextures(uint16_t stride, uint8_t uvByteOffset); static void DisableUnusedTextures(); + static void ActiveTexture(uint32_t i); static MString GenKey(const MString& k, const XMLNode* n); @@ -77,6 +78,7 @@ static uint8_t m_numActiveTextures; static uint32_t m_textureBinds; static ArrayStack< Texture* > m_activeTextures; + static MString* m_shaderBindPoints; static uint8_t m_maxActiveTextures; static Texture** m_lastBound; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |