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.

116 lines
3.3 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMEAMALGAMATEDTEXTURE_H
  7. #define DMEAMALGAMATEDTEXTURE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "materialobjects/amalgtexturevars.h"
  12. #include "bitmap/floatbitmap.h"
  13. #include "tier2/tier2.h"
  14. #include "datamodel/dmelement.h"
  15. #include "datamodel/dmehandle.h"
  16. #include "datamodel/dmattributevar.h"
  17. #include "resourcefile/resourcedictionary.h"
  18. #include "materialobjects/dmeimage.h"
  19. //-----------------------------------------------------------------------------
  20. // Forward declarations
  21. //-----------------------------------------------------------------------------
  22. class CDmeSheetImage; // known in mksheet as a SequenceFrame
  23. class CDmeSheetSequenceFrame; // known in mksheet as a SequenceEntry
  24. class CDmeSheetSequence;
  25. class CResourceStream;
  26. class CDmeImage;
  27. //-----------------------------------------------------------------------------
  28. // The Amalgamated texture itself.
  29. //-----------------------------------------------------------------------------
  30. class CDmeAmalgamatedTexture : public CDmElement
  31. {
  32. DEFINE_ELEMENT( CDmeAmalgamatedTexture, CDmElement );
  33. public:
  34. // Called when attributes change
  35. virtual void OnAttributeChanged( CDmAttribute *pAttribute ) {}
  36. virtual void OnAttributeArrayElementAdded( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
  37. virtual void OnAttributeArrayElementRemoved( CDmAttribute *pAttribute, int nFirstElem, int nLastElem ) {}
  38. void Init( const char *pShtFileName = NULL, bool bUseCurrentDir = false );
  39. void *WriteFile( CResourceStream *pStream, ResourceId_t nTextureResourceId );
  40. // old-style
  41. void WriteFile( const char *pFileName, bool bVerbose = false );
  42. bool DetermineBestPacking();
  43. bool PackImages( bool bGenerateImage, int nWidth );
  44. int GetWidth() { return m_nWidth; }
  45. int GetHeight() { return m_nHeight; }
  46. void GetSize( int &width, int &height )
  47. {
  48. width = m_nWidth;
  49. height = m_nHeight;
  50. }
  51. void SetCurrentSequenceClamp( bool bState );
  52. void SetPackingMode( int mode );
  53. void CreateNewSequence( int mode = PCKM_FLAT );
  54. void SetSequenceType( int eMode );
  55. bool CurrentSequenceExists();
  56. void CreateFrame( CUtlVector<char *> &frameNames, float ftime = 1.0f );
  57. void AddImage( CDmeSheetSequenceFrame *pNewSequenceFrame, char *pImageName );
  58. int GetSequenceCount(){ return m_SequenceCount; }
  59. CDmeImage *GetPackedImage();
  60. bool WriteTGA( const char *pFileName );
  61. private:
  62. CDmeSheetImage *FindImage( const char *pImageName );
  63. int GetPackingMode();
  64. int GetSequenceType();
  65. void ValidateImagePacking( CDmeSheetImage *pBitmap, char *pImageName );
  66. bool PackImagesFlat( bool bGenerateImage, int nWidth );
  67. bool PackImagesRGBA( bool bGenerateImage, int nWidth );
  68. float UCoord( int u )
  69. {
  70. float uc = u + 0.5;
  71. return uc / (float) m_nWidth;
  72. }
  73. float VCoord( int v )
  74. {
  75. float vc = v + 0.5;
  76. return vc / (float) m_nHeight;
  77. }
  78. CDmaElementArray< CDmeSheetImage > m_ImageList;
  79. CDmaVar< int > m_ePackingMode;
  80. CDmaElementArray< CDmeSheetSequence > m_Sequences;
  81. CDmeSheetSequence *m_pCurSequence;
  82. CDmaVar< int > m_nWidth;
  83. CDmaVar< int > m_nHeight;
  84. CDmaElement< CDmeImage > m_pPackedImage;
  85. int m_SequenceCount;
  86. };
  87. inline CDmeImage *CDmeAmalgamatedTexture::GetPackedImage()
  88. {
  89. return m_pPackedImage;
  90. }
  91. #endif // DMEAMALGAMATEDTEXTURE_H