|
From: <axl...@us...> - 2009-08-22 19:46:42
|
Revision: 511
http://hgengine.svn.sourceforge.net/hgengine/?rev=511&view=rev
Author: axlecrusher
Date: 2009-08-22 19:46:34 +0000 (Sat, 22 Aug 2009)
Log Message:
-----------
remember the last thing that was cached
Modified Paths:
--------------
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2009-08-22 17:51:38 UTC (rev 510)
+++ Mercury2/src/Texture.cpp 2009-08-22 19:46:34 UTC (rev 511)
@@ -102,12 +102,22 @@
void Texture::BindTexture()
{
+ if ( !m_lastBound ) InitiateBindCache();
+
+ if (m_numActiveTextures >= m_maxActiveTextures) return;
+
m_textureResource = GL_TEXTURE0+m_numActiveTextures;
GLCALL( glActiveTexture( m_textureResource ) );
GLCALL( glClientActiveTextureARB(m_textureResource) );
GLCALL( glEnableClientState(GL_TEXTURE_COORD_ARRAY) );
GLCALL( glEnable( GL_TEXTURE_2D ) );
- GLCALL( glBindTexture(GL_TEXTURE_2D, m_textureID) );
+
+ if (m_lastBound[m_numActiveTextures] != this)
+ {
+ GLCALL( glBindTexture(GL_TEXTURE_2D, m_textureID) );
+ m_lastBound[m_numActiveTextures] = this;
+ ++m_textureBinds;
+ }
GLCALL( glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) );
GLERRORCHECK;
@@ -120,7 +130,6 @@
m_activeTextures.push_back(this);
++m_numActiveTextures;
- ++m_textureBinds;
}
void Texture::UnbindTexture()
@@ -137,6 +146,17 @@
--m_numActiveTextures;
}
+void Texture::InitiateBindCache()
+{
+ GLint x;
+ GLCALL( glGetIntegerv( GL_MAX_TEXTURE_UNITS, &x ) );
+ m_lastBound = new Texture*[x];
+ m_maxActiveTextures = x;
+
+ for ( x = 0; x < m_maxActiveTextures; ++x)
+ m_lastBound[x] = NULL;
+}
+
void Texture::LoadImagePath(const MString& path)
{
if (m_isInstanced) return;
@@ -207,6 +227,8 @@
uint8_t Texture::m_numActiveTextures = 0;
uint32_t Texture::m_textureBinds = 0;
std::list< Texture* > Texture::m_activeTextures;
+Texture** Texture::m_lastBound = NULL;
+uint8_t Texture::m_maxActiveTextures = 0;
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2009-08-22 17:51:38 UTC (rev 510)
+++ Mercury2/src/Texture.h 2009-08-22 19:46:34 UTC (rev 511)
@@ -37,6 +37,8 @@
void BindTexture();
void UnbindTexture();
+ void InitiateBindCache();
+
const RawImageData* m_raw;
uint32_t m_textureID;
uint32_t m_textureResource;
@@ -46,7 +48,8 @@
static uint32_t m_textureBinds;
static std::list< Texture* > m_activeTextures;
-
+ static uint8_t m_maxActiveTextures;
+ static Texture** m_lastBound;
// MString m_filename;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|