From: <axl...@us...> - 2008-12-06 19:53:50
|
Revision: 51 http://hgengine.svn.sourceforge.net/hgengine/?rev=51&view=rev Author: axlecrusher Date: 2008-12-06 19:53:45 +0000 (Sat, 06 Dec 2008) Log Message: ----------- support multi texture Modified Paths: -------------- Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-05 23:54:50 UTC (rev 50) +++ Mercury2/src/Texture.cpp 2008-12-06 19:53:45 UTC (rev 51) @@ -1,7 +1,11 @@ #include <Texture.h> -#include <GL/gl.h> #include <RenderableNode.h> +#define GL_GLEXT_PROTOTYPES + +#include <GL/gl.h> +#include <GL/glext.h> + using namespace std; REGISTER_ASSET_TYPE(Texture); @@ -168,7 +172,11 @@ Texture::Texture() :m_raw(NULL),m_textureID(0) { - glEnable( GL_TEXTURE_2D ); + if (!m_initTextureSuccess) + { + m_initTextureSuccess = true; + m_activeTextures = 0; + } } Texture::~Texture() @@ -208,7 +216,7 @@ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); +// glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -217,13 +225,12 @@ void Texture::Render(MercuryNode* node) { - glEnable( GL_TEXTURE_2D ); - glBindTexture(GL_TEXTURE_2D, m_textureID); + BindTexture(); } void Texture::PostRender(MercuryNode* node) { - glDisable( GL_TEXTURE_2D ); + UnbindTexture(); } void Texture::LoadFromXML(const XMLNode& node) @@ -235,6 +242,26 @@ } } +void Texture::BindTexture() +{ + m_textureResource = GL_TEXTURE0+m_activeTextures; + glActiveTexture( m_textureResource ); + glEnable( GL_TEXTURE_2D ); + glBindTexture(GL_TEXTURE_2D, m_textureID); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + ++m_activeTextures; +} + +void Texture::UnbindTexture() +{ + glActiveTexture( m_textureResource ); + glDisable( GL_TEXTURE_2D ); + --m_activeTextures; +} + +bool Texture::m_initTextureSuccess; +unsigned short Texture::m_activeTextures; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2008-12-05 23:54:50 UTC (rev 50) +++ Mercury2/src/Texture.h 2008-12-06 19:53:45 UTC (rev 51) @@ -26,9 +26,19 @@ virtual void LoadFromXML(const XMLNode& node); void LoadFromRaw(const RawImageData* raw); + + inline static unsigned short NumberActiveTextures() { return m_activeTextures; } + private: + void BindTexture(); + void UnbindTexture(); + const RawImageData* m_raw; unsigned int m_textureID; + unsigned int m_textureResource; + + static bool m_initTextureSuccess; + static unsigned short m_activeTextures; }; /*************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |