From: <cn...@us...> - 2009-11-07 08:37:24
|
Revision: 605 http://hgengine.svn.sourceforge.net/hgengine/?rev=605&view=rev Author: cnlohr Date: 2009-11-07 08:37:17 +0000 (Sat, 07 Nov 2009) Log Message: ----------- add extra utility to the screen to point stuff... Allow textures to be fed from code or to feed code... and add a new state changer (lighting disable/enabling) Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Mercury2/src/StateChanger.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/GLHelpers.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -57,7 +57,7 @@ return mm; } -MercuryVertex pointFromScreenLoc(int screen_x, int screen_y) +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth) { GLfloat winX, winY, winZ; GLdouble mouseX = 0, mouseY = 0, mouseZ = 0; @@ -71,15 +71,26 @@ winX = (float)screen_x; winY = (float)viewport[3] - (float)screen_y; - GLCALL( glReadPixels( screen_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ) ); gluUnProject( - winX, winY, winZ, + winX, winY, fForceDepth, modelview, projection, viewport, &mouseX, &mouseY, &mouseZ); return MercuryVertex( (float)mouseX, (float)mouseY, (float)mouseZ ); } +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y ) +{ + GLint viewport[4]; + GLCALL( glGetIntegerv(GL_VIEWPORT, viewport) ); + + float winY = (float)viewport[3] - (float)screen_y; + + float winZ; + GLCALL( glReadPixels( screen_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ) ); + return pointFromScreenLoc( screen_x, screen_y, winZ ); +} + unsigned int ToGLColorType(ColorByteType cbt) { switch (cbt) Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/GLHelpers.h 2009-11-07 08:37:17 UTC (rev 605) @@ -18,6 +18,7 @@ void glLoadMatrix(const MercuryMatrix& m); MercuryMatrix glGetMatrix(unsigned int m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth); unsigned int ToGLColorType(ColorByteType cbt); #ifdef GL_PROFILE Modified: Mercury2/src/StateChanger.cpp =================================================================== --- Mercury2/src/StateChanger.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/StateChanger.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -44,7 +44,41 @@ REGISTER_STATECHANGE( ColorChange ); +///State changer for enabling/disabling lighting +class LightingSwitch : public StateChange +{ +public: + LightingSwitch( const MVector< MString > & sParameters ) : StateChange( sParameters ) + { + if( sParameters.size() < 1 ) + { + LOG.Write( ssprintf( "Error: ColorChange state has invalid number of parameters(%d).", sParameters.size() ) ); + return; + } + bEnable = StrToBool( sParameters[0] ); + } + + void Stringify( MString & sOut ) + { + sOut = ssprintf( "%f", bEnable ); + } + + void Activate() + { + if( bEnable ) + glEnable( GL_LIGHTING ); + else + glDisable( GL_LIGHTING ); + } + + STATECHANGE_RTTI( LightingSwitch ); + bool bEnable; +}; + +REGISTER_STATECHANGE( LightingSwitch ); + + //////////////////////////////////////STATE CHANGE CHUNK////////////////////////////////////// StateChangeRegister * StateChangeRegister::m_Instance; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/Texture.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -13,7 +13,7 @@ #define BUFFER_OFFSET(i) ((char*)NULL + (i)) Texture::Texture( const MString & key, bool bInstanced ) - :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_dynamic(false) + :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false) { if (!m_initTextureSuccess) { @@ -76,7 +76,8 @@ GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) ); // GLCALL( gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ) ); - SAFE_DELETE(m_raw); + if( m_bDeleteRaw ) + SAFE_DELETE(m_raw); GLCALL( glPopAttrib() ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/Texture.h 2009-11-07 08:37:17 UTC (rev 605) @@ -20,7 +20,10 @@ virtual bool ChangeKey( const MString & sNewKey ); void LoadFromRaw(); - + + void SetDeleteRawData( bool bDelete = true ) { m_bDeleteRaw = bDelete; } + RawImageData * GetRawImageDataHandle() { return m_raw; } + inline static uint8_t NumberActiveTextures() { return m_numActiveTextures; } inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; } inline uint32_t TextureID() const { return m_textureID; } @@ -35,6 +38,7 @@ static void ApplyActiveTextures(uint16_t stride); static void DisableUnusedTextures(); + GENRTTI( Texture ); private: void LoadImagePath(const MString& path); @@ -47,7 +51,7 @@ void InitiateBindCache(); - const RawImageData* m_raw; + RawImageData* m_raw; uint32_t m_textureID; static bool m_initTextureSuccess; @@ -58,6 +62,7 @@ static uint8_t m_maxActiveTextures; static Texture** m_lastBound; + bool m_bDeleteRaw; bool m_dynamic; // MString m_filename; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |