From: <axl...@us...> - 2010-11-21 04:53:01
|
Revision: 767 http://hgengine.svn.sourceforge.net/hgengine/?rev=767&view=rev Author: axlecrusher Date: 2010-11-21 04:52:54 +0000 (Sun, 21 Nov 2010) Log Message: ----------- Change active texture stack to an array based stack. This is much faster and avoids a lot of things that std::list does, like issuing many new statements. Modified Paths: -------------- Mercury2/src/RenderGraph.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Added Paths: ----------- Mercury2/src/ArrayStack.h Added: Mercury2/src/ArrayStack.h =================================================================== --- Mercury2/src/ArrayStack.h (rev 0) +++ Mercury2/src/ArrayStack.h 2010-11-21 04:52:54 UTC (rev 767) @@ -0,0 +1,66 @@ +#ifndef ARRAYSTACK_H +#define ARRAYSTACK_H + +template <typename T> +class ArrayStack +{ + public: + ArrayStack(unsigned long size) + :m_stack(NULL), m_nextSpot(0),m_size(size) + { + m_stack = new T[m_size]; + }; + + ~ArrayStack() + { + delete[] m_stack; + } + + void Push(T x) { m_stack[m_nextSpot++] = x; } + + void Pop() { --m_nextSpot; } + + T Top() { return m_stack[m_nextSpot-1]; } + + unsigned long Depth() const { return m_nextSpot; } + + T operator[](unsigned long i) const { return m_stack[i]; } + + private: + T* m_stack; + unsigned long m_nextSpot; + unsigned long m_size; +}; + +#endif +/**************************************************************************** + * Copyright (C) 2010 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * Redistributions in binary form must reproduce the above * + * copyright notice, this list of conditions and the following * + * disclaimer in the documentation and/or other materials provided * + * with the distribution. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + ***************************************************************************/ Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2010-11-21 04:01:56 UTC (rev 766) +++ Mercury2/src/RenderGraph.cpp 2010-11-21 04:52:54 UTC (rev 767) @@ -154,10 +154,9 @@ void StoreRenderState::Save() { //get assets for current textures - const std::list< Texture* >& textures = Texture::GetActiveTextures(); - std::list< Texture* >::const_iterator i = textures.begin(); - for (;i != textures.end(); ++i) - Assets.push_back( *i ); + const ArrayStack< Texture* >& textures = Texture::GetActiveTextures(); + for (unsigned short i = 0; i<textures.Depth(); ++i) + Assets.push_back( textures[i] ); //save the active shader Shader* s = Shader::GetCurrentShader(); Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2010-11-21 04:01:56 UTC (rev 766) +++ Mercury2/src/Texture.cpp 2010-11-21 04:52:54 UTC (rev 767) @@ -191,8 +191,8 @@ sa.value.iSampler = m_numActiveTextures; Shader::SetAttribute( ssprintf("HG_Texture%d", m_numActiveTextures), sa); - m_activeTextures.push_back(this); - + m_activeTextures.Push(this); + ++m_numActiveTextures; } @@ -202,7 +202,7 @@ --m_numActiveTextures; Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_numActiveTextures) ); - m_activeTextures.pop_back(); + m_activeTextures.Pop(); // Deactivate(GL_TEXTURE0 + m_numActiveTextures); } @@ -351,7 +351,7 @@ bool Texture::m_initTextureSuccess = false; uint8_t Texture::m_numActiveTextures = 0; uint32_t Texture::m_textureBinds = 0; -std::list< Texture* > Texture::m_activeTextures; +ArrayStack< Texture* > Texture::m_activeTextures(Texture::TextureStackDepth); Texture** Texture::m_lastBound = NULL; uint8_t Texture::m_maxActiveTextures = 0; Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2010-11-21 04:01:56 UTC (rev 766) +++ Mercury2/src/Texture.h 2010-11-21 04:52:54 UTC (rev 767) @@ -4,6 +4,8 @@ #include <MercuryAsset.h> #include <RawImageData.h> +#include <ArrayStack.h> + enum TextureFilterMode { TF_NONE, @@ -13,6 +15,8 @@ class Texture : public MercuryAsset { + private: + static const unsigned int TextureStackDepth = 16; public: Texture( const MString & key, bool bInstanced ); virtual ~Texture(); @@ -39,7 +43,7 @@ static MAutoPtr< Texture > LoadFromFile(const MString& path); static MAutoPtr< Texture > LoadDynamicTexture(const MString& name); - static const std::list< Texture* >& GetActiveTextures() { return m_activeTextures; } + static const ArrayStack< Texture* >& GetActiveTextures() { return m_activeTextures; } void SetRawData(RawImageData* raw); @@ -72,7 +76,7 @@ static bool m_initTextureSuccess; static uint8_t m_numActiveTextures; static uint32_t m_textureBinds; - static std::list< Texture* > m_activeTextures; + static ArrayStack< Texture* > m_activeTextures; 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. |