"L. Spiro Engine"
|
00001 00017 #ifndef __LSG_SPRITE_H__ 00018 #define __LSG_SPRITE_H__ 00019 00020 #include "../LSGGraphicsLib.h" 00021 #include "../ShaderLanguage/LSGShader.h" 00022 #include "../Texture/LSGStandardTexture.h" 00023 #include "../Texture/LSGTextureManager.h" 00024 #include "../VertexBuffer/LSGVertexBuffer.h" 00025 #include "Matrix/LSMMatrix4x4.h" 00026 #include "Vector/LSMVector2.h" 00027 00028 namespace lsg { 00029 00037 class CSprite { 00038 public : 00039 // == Various constructors. 00040 LSE_CALLCTOR CSprite(); 00041 00042 00043 // == Types. 00047 typedef struct LSG_CELL { 00051 LSREAL fStartX; 00052 00056 LSREAL fStartY; 00057 00061 LSREAL fWidth; 00062 00066 LSREAL fHeight; 00067 00071 LSREAL fCenterX; 00072 00076 LSREAL fCenterY; 00077 } * LPLSG_CELL, * const LPCLSG_CELL; 00078 00082 typedef LSVOID (LSE_CALL * PfCellResizeCallback)( LSVOID * _pvParm ); 00083 00084 00085 // == Functions. 00091 LSE_INLINE const CStandardTexture * LSE_CALL GetTexture() const; 00092 00098 LSE_INLINE LSVOID LSE_CALL SetTexture( CSharedStdTexPtr _sstpTexture ); 00099 00106 LSE_INLINE LSBOOL LSE_CALL SetTexture( const LSCHAR * _pcPath ); 00107 00115 LSE_INLINE LSBOOL LSE_CALL SetTexture( const LSCHAR * _pcPath, const LSG_TEX_PARMS &_tpParms ); 00116 00122 LSE_INLINE LSVOID LSE_CALL SetShader( const CSharedShaderPtr * _psspShader ); 00123 00134 LSBOOL LSE_CALL DrawAtImm( const CVector2 &_vPos, LSREAL _fRot = LSM_ZERO, 00135 const CVector2 &_vScale = CVector2( LSM_ONE, LSM_ONE ), LSREAL _fAlpha = LSM_ONE ) const; 00136 00147 LSBOOL LSE_CALL DrawAtImm( const CVector2 &_vPos, const CMatrix2x2 &_mRotScale, LSREAL _fAlpha = LSM_ONE ) const; 00148 00155 LSVOID LSE_CALL SetCellCenter( LSREAL _fX, LSREAL _fY ); 00156 00163 LSVOID LSE_CALL SetCellCenterNorm( LSREAL _fX, LSREAL _fY ); 00164 00172 LSVOID LSE_CALL SetCell( const CVector2 &_vUpperLeft, const CVector2 &_vSize, 00173 const CVector2 &_vCenter ); 00174 00180 LSE_INLINE LSVOID LSE_CALL SetCell( const LSG_CELL &_cCell ); 00181 00187 LSE_INLINE const CVector2 & LSE_CALL CellSize() const; 00188 00194 LSE_INLINE const CVector2 & LSE_CALL CellScale() const; 00195 00201 LSE_INLINE CVector2 LSE_CALL CellCenterNegated() const; 00202 00209 LSVOID LSE_CALL SetCallbackFunction( PfCellResizeCallback _pcrcCallback, LSVOID * _pvParm ); 00210 00214 static LSVOID LSE_CALL ShutDownSprites(); 00215 00216 00217 // == Members. 00221 static CTextureManager m_tmTexMan; 00222 00223 protected : 00224 // == Members. 00228 mutable CSharedStdTexPtr m_sstpTexture; 00229 00233 mutable CSharedShaderPtr m_sspShader; 00234 00238 PfCellResizeCallback m_pcrcCellResizeCallback; 00239 00243 LSVOID * m_pvCallbackParm; 00244 00248 CVector3 m_vPos; 00249 00253 CVector2 m_vScale; 00254 00258 LSREAL m_fRot; 00259 00263 LSREAL m_fAlpha; 00264 00268 CVector2 m_vCellSize; 00269 00273 CVector2 m_vInvTexSize; 00274 00278 CVector2 m_vUvStart; 00279 00283 CVector2 m_vUvEnd; 00284 00288 CMatrix4x4 m_mLocalTrans; 00289 00293 static CVertexBuffer * m_pvbImmVertBuf; 00294 00298 static CSharedShaderPtr m_sspDefaultShader; 00299 00303 static CShader::LSG_HANDLE m_hDefaultAlpha; 00304 00305 00306 // == Functions. 00315 static LSVOID LSE_CALL UpdateTrans( const CVector3 &_vPos, LSREAL _fRot, const CVector2 &_vScale, 00316 CMatrix4x4 &_mRet ); 00317 00323 static CShader * LSE_CALL GetDefShader(); 00324 00330 static CVertexBuffer * LSE_CALL GetImmVertBuffer(); 00331 }; 00332 00333 00334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00335 // DEFINITIONS 00336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00337 // == Types. 00341 typedef CSharedPtr<CSprite> CSharedSpritePtr; 00342 00343 // == Functions. 00349 LSE_INLINE const CStandardTexture * LSE_CALL CSprite::GetTexture() const { 00350 return m_sstpTexture.Get(); 00351 } 00352 00358 LSE_INLINE LSVOID LSE_CALL CSprite::SetTexture( CSharedStdTexPtr _sstpTexture ) { 00359 m_sstpTexture = _sstpTexture; 00360 if ( m_sstpTexture.Valid() ) { 00361 m_vCellSize.x = static_cast<LSREAL>(m_sstpTexture->GetWidth()); 00362 m_vCellSize.y = static_cast<LSREAL>(m_sstpTexture->GetHeight()); 00363 00364 m_vInvTexSize = CVector2( LSM_ONE / m_vCellSize.x, LSM_ONE / m_vCellSize.y ); 00365 } 00366 else { 00367 m_vCellSize.x = m_vCellSize.y = m_vInvTexSize.x = m_vInvTexSize.y = LSM_ZERO; 00368 } 00369 m_vUvStart = CVector2( LSM_ZERO, LSM_ZERO ); 00370 m_vUvEnd = CVector2( LSM_ONE, LSM_ONE ); 00371 if ( m_pcrcCellResizeCallback ) { 00372 m_pcrcCellResizeCallback( m_pvCallbackParm ); 00373 } 00374 } 00375 00382 LSE_INLINE LSBOOL LSE_CALL CSprite::SetTexture( const LSCHAR * _pcPath ) { 00383 return SetTexture( _pcPath, CTextureBase::m_tpSpritePreset ); 00384 } 00385 00393 LSE_INLINE LSBOOL LSE_CALL CSprite::SetTexture( const LSCHAR * _pcPath, const LSG_TEX_PARMS &_tpParms ) { 00394 CSharedStdTexPtr sstpThis = m_tmTexMan.CreateSharedTexFromFile( _pcPath, _tpParms ); 00395 if ( !sstpThis.Valid() ) { return false; } 00396 if ( !sstpThis->Finalized() ) { sstpThis->Finalize(); } 00397 SetTexture( sstpThis ); 00398 return true; 00399 } 00400 00406 LSE_INLINE LSVOID LSE_CALL CSprite::SetShader( const CSharedShaderPtr * _psspShader ) { 00407 if ( _psspShader ) { 00408 m_sspShader = (*_psspShader); 00409 } 00410 else { 00411 m_sspShader.Reset(); 00412 } 00413 } 00414 00420 LSE_INLINE LSVOID LSE_CALL CSprite::SetCell( const LSG_CELL &_cCell ) { 00421 SetCell( CVector2( _cCell.fStartX, _cCell.fStartY ), CVector2( _cCell.fWidth, _cCell.fHeight ), 00422 CVector2( _cCell.fCenterX, _cCell.fCenterY ) ); 00423 } 00424 00430 LSE_INLINE const CVector2 & LSE_CALL CSprite::CellSize() const { 00431 return m_vCellSize; 00432 } 00433 00439 LSE_INLINE const CVector2 & LSE_CALL CSprite::CellScale() const { 00440 return m_vScale; 00441 } 00442 00448 LSE_INLINE CVector2 LSE_CALL CSprite::CellCenterNegated() const { 00449 return CVector2( m_vPos.x, m_vPos.y ); 00450 } 00451 00452 } // namespace lsg 00453 00454 #endif // __LSG_SPRITE_H__