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.

72 lines
1.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TEXTUREPACKER_H
  8. #define TEXTUREPACKER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlntree.h"
  13. #define DEFAULT_TEXTURE_PAGE_WIDTH 1024
  14. #define DEFAULT_TEXTURE_PAGE_WIDTH 1024
  15. //-----------------------------------------------------------------------------
  16. // Purpose: manages texture packing of textures as they are added.
  17. //-----------------------------------------------------------------------------
  18. class CTexturePacker
  19. {
  20. public:
  21. struct TreeEntry_t
  22. {
  23. Rect_t rc;
  24. bool bInUse;
  25. };
  26. CTexturePacker( int texWidth = DEFAULT_TEXTURE_PAGE_WIDTH, int texHeight = DEFAULT_TEXTURE_PAGE_WIDTH, int pixelGap = 0 );
  27. ~CTexturePacker();
  28. // Use -1 if you want to insert at the root.
  29. int InsertRect( const Rect_t& texRect, int nodeIndex = -1 );
  30. bool RemoveRect( int nodeIndex );
  31. const TreeEntry_t &GetEntry( int i )
  32. {
  33. return m_Tree[i];
  34. }
  35. int GetPageWidth()
  36. {
  37. return m_PageWidth;
  38. }
  39. int GetPageHeight()
  40. {
  41. return m_PageHeight;
  42. }
  43. // clears the tree
  44. void Clear();
  45. private:
  46. bool IsLeaf( int nodeIndex );
  47. bool IsLeftChild( int nodeIndexParent, int nodeIndexChild );
  48. bool IsRightChild( int nodeIndexParent, int nodeIndexChild );
  49. // Pixel gap between textures.
  50. int m_PixelGap;
  51. int m_PageWidth;
  52. int m_PageHeight;
  53. CUtlNTree< TreeEntry_t > m_Tree;
  54. };
  55. #endif // TEXTUREPACKER_H