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.

143 lines
3.9 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //==========================================================================//
  6. #ifndef PAINT_H
  7. #define PAINT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "materialsystem/MaterialSystemUtil.h"
  12. #include "materialsystem/ipaintmapdatamanager.h"
  13. #include "bitvec.h"
  14. #include "surfacehandle.h"
  15. //forward declaration
  16. struct model_t;
  17. struct PaintRect_t
  18. {
  19. Rect_t rect;
  20. Vector2D uvCenter;
  21. float flCenterAlpha;
  22. float flCircleRadius;
  23. float flPaintCoatPercent;
  24. BYTE colorIndex;
  25. SurfaceHandle_t surfID;
  26. };
  27. enum PaintDirtyFlags_t
  28. {
  29. PAINTMAP_CLEAN = 0,
  30. PAINTMAP_DIRTY_SUBRECT,
  31. PAINTMAP_DIRTY_FULLRECT
  32. };
  33. class CPaintTextureData
  34. {
  35. public:
  36. CPaintTextureData();
  37. // Initializes, shuts down the material
  38. bool Init( int width, int height, int lightmapPageID );
  39. void Destroy();
  40. // Returns the texcoord range
  41. void GetTexCoordRange( float *pMaxU, float *pMaxV );
  42. // Returns the size of the paint texture (stored in a subrect of the material itself)
  43. void GetPaintSize( int *pWidth, int *pHeight );
  44. void ClearTexture();
  45. void GetPixels( const Rect_t& splatRect, CUtlVector<BYTE>& surfColors );
  46. BYTE GetPixel( int x, int y ) const;
  47. void SetPixel( int x, int y, BYTE color );
  48. // Returns true if any data changed
  49. bool Paint( const PaintRect_t& paintRect2 );
  50. void PaintAllSurfaces( BYTE color );
  51. void GetSurfacePaintData( SurfaceHandle_t surfID, CUtlVector< BYTE > &data ) const;
  52. void SetSurfacePaintData( SurfaceHandle_t surfID, const CUtlVector< BYTE > &data );
  53. BYTE* GetPaintmapData() { return m_backbuffer; }
  54. PaintDirtyFlags_t GetDirtyFlag() const;
  55. void MarkAsDirty( PaintDirtyFlags_t nDirtyFlag = PAINTMAP_DIRTY_FULLRECT );
  56. void RemoveDirty();
  57. void AddDirtyRect( const Rect_t& rect );
  58. CUtlVectorFixedGrowable<Rect_t, 1024>* GetDirtyRectList();
  59. private:
  60. enum PaintChangeFlags_t
  61. {
  62. TEXEL_CHANGED = 0x1,
  63. PAINT_POWER_CHANGED = 0x2,
  64. };
  65. void ClearBuffer( BYTE *pByte = NULL );
  66. uint32 BlendLuxel( const PaintRect_t& paintRect, int x, int y, float flNewAlpha, float flMaxAlpha = 1.f );
  67. uint32 AddSurroundingAlpha( const PaintRect_t& paintRect, int x, int y );
  68. uint32 DrawLine( const PaintRect_t& paintRect, int x1, int x2, int y );
  69. uint32 Draw2Lines( const PaintRect_t& paintRect, float x, float y );
  70. uint32 Draw4Lines( const PaintRect_t& paintRect, float x, float y );
  71. uint32 DrawCircle( const PaintRect_t& paintRect );
  72. int m_nPaintWidth;
  73. int m_nPaintHeight;
  74. int m_lightmapPageID;
  75. BYTE *m_backbuffer;
  76. PaintDirtyFlags_t m_nDirtyFlag;
  77. CUtlVectorFixedGrowable<Rect_t, 1024> m_dirtyRects; // preallocate 1024, seems to be a conservative count
  78. };
  79. class CPaintmapDataManager : public IPaintmapDataManager
  80. {
  81. public:
  82. CPaintmapDataManager( void );
  83. ~CPaintmapDataManager( void );
  84. void RemoveAllPaint( void );
  85. void RemovePaint( const model_t *pModel );
  86. void PaintAllSurfaces( BYTE color );
  87. virtual void BeginPaintmapsDataAllocation( int iPaintmapCount );
  88. virtual void AllocatePaintmapData( int iPaintmapID, int iCorrespondingLightMapWidth, int iCorrespondingLightMapHeight );
  89. virtual void DestroyPaintmapsData( void );
  90. virtual BYTE* GetPaintmapData( int paintmap );
  91. virtual void GetPaintmapSize( int paintmap, int& width, int& height );
  92. virtual void OnRestorePaintmaps();
  93. void UpdatePaintmapTextures();
  94. void GetPaintmapDataRLE( CUtlVector< uint32 > &data ) const;
  95. void LoadPaintmapDataRLE( const CUtlVector< uint32 > &data );
  96. CPaintTextureData *m_pPaintTextureDataArray;
  97. int m_iPaintmaps;
  98. bool m_bShouldRegister;
  99. };
  100. //global paint atlas
  101. extern CPaintmapDataManager g_PaintManager;
  102. // Returns true if any paint changed
  103. bool ShootPaintSphere( const model_t *pModel, const Vector& vPosition, BYTE colorIndex, float flSphereRadius, float flPaintCoatPercent );
  104. void TracePaintSphere( const model_t *pModel, const Vector& vPosition, const Vector& vContactNormal, float flSphereRadius, CUtlVector<BYTE>& surfColors );
  105. void R_RedownloadAllPaintmaps();
  106. #endif // PAINT_H