Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef SPRITE_H
  10. #define SPRITE_H
  11. #pragma once
  12. #include "mathlib/mathlib.h"
  13. #include "materialsystem/imaterialsystem.h"
  14. class CTexture;
  15. class CMaterial;
  16. class IMaterialVar;
  17. class CRender;
  18. class CRender3D;
  19. // must match definition in modelgen.h
  20. enum synctype_t
  21. {
  22. ST_SYNC=0,
  23. ST_RAND
  24. };
  25. #define SPR_VP_PARALLEL_UPRIGHT 0
  26. #define SPR_FACING_UPRIGHT 1
  27. #define SPR_VP_PARALLEL 2
  28. #define SPR_ORIENTED 3
  29. #define SPR_VP_PARALLEL_ORIENTED 4
  30. #define SPR_NORMAL 0
  31. #define SPR_ADDITIVE 1
  32. #define SPR_INDEXALPHA 2
  33. #define SPR_ALPHATEST 3
  34. //-----------------------------------------------------------------------------
  35. // From engine\GL_MODEL.H:
  36. //-----------------------------------------------------------------------------
  37. class CSpriteModel
  38. {
  39. public:
  40. CSpriteModel(void);
  41. ~CSpriteModel(void);
  42. bool LoadSprite(const char *pszSpritePath);
  43. int GetFrameCount(void);
  44. int GetWidth() const;
  45. int GetHeight() const;
  46. int GetType() const;
  47. void Bind( CRender* pRender, int frame );
  48. void GetRect( float& left, float& up, float& right, float& down ) const;
  49. void SetRenderMode( const int mode );
  50. void SetMaterialPrimitiveType( const MaterialPrimitiveType_t type );
  51. void SetOrigin( const Vector &v );
  52. void GetOrigin( Vector &v );
  53. void SetAngles( const QAngle& pfAngles );
  54. void SetScale( const float fScale );
  55. void SetInvert( const bool b );
  56. inline void SetTextureExtent( Vector2D TexUL, Vector2D TexLR ) { m_TexUL = TexUL; m_TexLR = TexLR; }
  57. inline void SetExtent( Vector2D UL, Vector2D LR ) { m_UL = UL; m_LR = LR; }
  58. void DrawSprite3D( CRender3D *pRender, unsigned char color[3] );
  59. protected:
  60. void GetSpriteAxes(QAngle& Angles, int type, Vector& forward, Vector& right, Vector& up, Vector& ViewUp, Vector& ViewRight, Vector& ViewForward);
  61. Vector m_Origin;
  62. Vector m_Normal; // for lpreview, etc
  63. QAngle m_Angles;
  64. float m_fScale;
  65. MaterialPrimitiveType_t m_MaterialPrimitiveType;
  66. CMaterial* m_pMaterial;
  67. IMaterialVar* m_pFrameVar;
  68. IMaterialVar* m_pRenderModeVar;
  69. int m_NumFrames;
  70. int m_Type;
  71. int m_Width;
  72. int m_Height;
  73. bool m_bInvert;
  74. Vector2D m_TexUL, m_TexLR;
  75. Vector2D m_UL, m_LR;
  76. };
  77. //-----------------------------------------------------------------------------
  78. // inline methods
  79. //-----------------------------------------------------------------------------
  80. inline int CSpriteModel::GetWidth() const
  81. {
  82. return m_Width;
  83. }
  84. inline int CSpriteModel::GetHeight() const
  85. {
  86. return m_Height;
  87. }
  88. inline int CSpriteModel::GetType() const
  89. {
  90. return m_Type;
  91. }
  92. inline void CSpriteModel::GetRect( float& left, float& up, float& right, float& down ) const
  93. {
  94. left = m_UL.x;
  95. right = m_LR.x;
  96. up = m_UL.y;
  97. down = m_LR.y;
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Sprite cache
  101. //-----------------------------------------------------------------------------
  102. struct SpriteCache_t
  103. {
  104. CSpriteModel *pSprite;
  105. char *pszPath;
  106. int nRefCount;
  107. };
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. #define SPRITE_CACHE_SIZE 1024
  112. class CSpriteCache
  113. {
  114. public:
  115. static CSpriteModel *CreateSprite(const char *pszSpritePath);
  116. static void AddRef(CSpriteModel *pSprite);
  117. static void Release(CSpriteModel *pSprite);
  118. protected:
  119. static bool AddSprite(CSpriteModel *pSprite, const char *pszSpritePath);
  120. static void RemoveSprite(CSpriteModel *pSprite);
  121. static SpriteCache_t m_Cache[SPRITE_CACHE_SIZE];
  122. static int m_nItems;
  123. };
  124. #endif // SPRITE_H