|
From: <axl...@us...> - 2009-08-23 01:41:20
|
Revision: 514
http://hgengine.svn.sourceforge.net/hgengine/?rev=514&view=rev
Author: axlecrusher
Date: 2009-08-23 01:41:14 +0000 (Sun, 23 Aug 2009)
Log Message:
-----------
reduce the number of opengl API calls by not always disablsing and activating textures
Modified Paths:
--------------
Mercury2/src/MercuryVBO.cpp
Mercury2/src/RenderDifferedLights.cpp
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-08-22 21:25:09 UTC (rev 513)
+++ Mercury2/src/MercuryVBO.cpp 2009-08-23 01:41:14 UTC (rev 514)
@@ -25,7 +25,6 @@
void MercuryVBO::Render(const MercuryNode* node)
{
- uint8_t numTextures = Texture::NumberActiveTextures();
uint16_t stride = sizeof(float)*8;
if ( !m_initiated ) InitVBO();
@@ -45,13 +44,7 @@
++m_vboBinds;
}
- //apply all the active Textures
- for (uint8_t i = 0; i < numTextures; ++i)
- {
- GLCALL( glActiveTexture( GL_TEXTURE0+i ) );
- GLCALL( glClientActiveTextureARB(GL_TEXTURE0+i) );
- GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)) );
- }
+ Texture::ApplyActiveTextures(stride);
GLCALL( glEnableClientState( GL_NORMAL_ARRAY ) );
GLCALL( glNormalPointer(GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*2)) );
Modified: Mercury2/src/RenderDifferedLights.cpp
===================================================================
--- Mercury2/src/RenderDifferedLights.cpp 2009-08-22 21:25:09 UTC (rev 513)
+++ Mercury2/src/RenderDifferedLights.cpp 2009-08-23 01:41:14 UTC (rev 514)
@@ -5,7 +5,6 @@
#include <GLHeaders.h>
REGISTER_ASSET_TYPE(RenderDifferedLights);
-#define BUFFER_OFFSET(i) ((char*)NULL + (i))
RenderDifferedLights::RenderDifferedLights()
{
@@ -20,13 +19,7 @@
uint8_t numTextures = Texture::NumberActiveTextures();
uint16_t stride = sizeof(float)*8;
- //apply all the active Textures
- for (uint8_t i = 0; i < numTextures; ++i)
- {
- GLCALL( glActiveTexture( GL_TEXTURE0+i ) );
- GLCALL( glClientActiveTextureARB(GL_TEXTURE0+i) );
- GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)) );
- }
+ Texture::ApplyActiveTextures(stride);
GLCALL( glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT) );
GLCALL( glCullFace(GL_FRONT) );
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2009-08-22 21:25:09 UTC (rev 513)
+++ Mercury2/src/Texture.cpp 2009-08-23 01:41:14 UTC (rev 514)
@@ -10,6 +10,8 @@
REGISTER_ASSET_TYPE(Texture);
+#define BUFFER_OFFSET(i) ((char*)NULL + (i))
+
Texture::Texture()
:MercuryAsset(), m_raw(NULL),m_textureID(0)
{
@@ -34,6 +36,14 @@
void Texture::Clean()
{
if (m_textureID) { GLCALL( glDeleteTextures(1, &m_textureID) ); }
+ for (uint8_t i = 0; i < m_maxActiveTextures; ++i)
+ {
+ if (m_lastBound[i] == this)
+ {
+ Deactivate();
+ m_lastBound[i] = 0;
+ }
+ }
m_textureID = 0;
}
@@ -107,13 +117,15 @@
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 ) );
if (m_lastBound[m_numActiveTextures] != this)
{
+// We don't really even have to disable old spots
+// if ( m_lastBound[m_numActiveTextures] != NULL)
+// m_lastBound[m_numActiveTextures]->Deactivate();
+
+ Activate();
+
GLCALL( glBindTexture(GL_TEXTURE_2D, m_textureID) );
m_lastBound[m_numActiveTextures] = this;
++m_textureBinds;
@@ -134,11 +146,13 @@
void Texture::UnbindTexture()
{
+ /*
GLCALL( glActiveTexture( m_textureResource ) );
GLCALL( glClientActiveTextureARB(m_textureResource) );
GLCALL( glDisableClientState(GL_TEXTURE_COORD_ARRAY) );
GLCALL( glDisable( GL_TEXTURE_2D ) );
GLERRORCHECK;
+ */
Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_numActiveTextures) );
m_activeTextures.pop_back();
@@ -146,6 +160,47 @@
--m_numActiveTextures;
}
+void Texture::Activate()
+{
+ GLCALL( glActiveTexture( m_textureResource ) );
+ GLCALL( glClientActiveTextureARB(m_textureResource) );
+ GLCALL( glEnableClientState(GL_TEXTURE_COORD_ARRAY) );
+ GLCALL( glEnable( GL_TEXTURE_2D ) );
+}
+
+void Texture::Deactivate()
+{
+ GLCALL( glActiveTexture( m_textureResource ) );
+ GLCALL( glClientActiveTextureARB(m_textureResource) );
+ GLCALL( glDisableClientState(GL_TEXTURE_COORD_ARRAY) );
+ GLCALL( glDisable( GL_TEXTURE_2D ) );
+ GLERRORCHECK;
+}
+
+void Texture::ApplyActiveTextures(uint16_t stride)
+{
+ for (uint8_t i = 0; i < m_numActiveTextures; ++i)
+ {
+ GLCALL( glActiveTexture( GL_TEXTURE0+i ) );
+ GLCALL( glClientActiveTextureARB(GL_TEXTURE0+i) );
+ GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)) );
+ }
+
+ Texture::DisableUnusedTextures();
+}
+
+void Texture::DisableUnusedTextures()
+{
+ for (uint8_t i = m_numActiveTextures; i < m_maxActiveTextures; ++i)
+ {
+ if (m_lastBound[m_numActiveTextures] != NULL)
+ {
+ m_lastBound[m_numActiveTextures]->Deactivate();
+ m_lastBound[m_numActiveTextures] = NULL;
+ }
+ }
+}
+
void Texture::InitiateBindCache()
{
GLint x;
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2009-08-22 21:25:09 UTC (rev 513)
+++ Mercury2/src/Texture.h 2009-08-23 01:41:14 UTC (rev 514)
@@ -31,12 +31,18 @@
static const std::list< Texture* >& GetActiveTextures() { return m_activeTextures; }
void SetRawData(RawImageData* raw);
+
+ static void ApplyActiveTextures(uint16_t stride);
+ static void DisableUnusedTextures();
private:
void LoadImagePath(const MString& path);
void BindTexture();
void UnbindTexture();
+ void Activate();
+ void Deactivate();
+
void InitiateBindCache();
const RawImageData* m_raw;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|