W3DShroud.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #pragma once
  24. #ifndef __W3DSHROUD_H_
  25. #define __W3DSHROUD_H_
  26. #include "WW3D2/matpass.h"
  27. #include "WW3D2/dx8wrapper.h"
  28. class AABoxClass;
  29. class WorldHeightMap;
  30. typedef UnsignedByte W3DShroudLevel;
  31. // In Global Data now
  32. //const W3DShroudLevel FULL_SHROUD_LEVEL=0;
  33. //const W3DShroudLevel FOG_SHROUD_LEVEL=127;
  34. //const W3DShroudLevel NO_SHROUD_LEVEL=255;
  35. /** Custom W3D material pass which has been modified to apply
  36. a shroud texture projection.
  37. */
  38. class W3DShroudMaterialPassClass : public MaterialPassClass
  39. {
  40. public:
  41. W3DShroudMaterialPassClass(void) : m_isTransparentObjectPass(FALSE) {}
  42. virtual void Install_Materials(void) const;
  43. virtual void UnInstall_Materials(void) const;
  44. void enableTransparentObjectPass(Bool enable) {m_isTransparentObjectPass = enable;}
  45. protected:
  46. //customized version to deal with transparent (alpha-tested) polys.
  47. Bool m_isTransparentObjectPass;
  48. };
  49. /** Custom W3D material pass which has been modified to apply
  50. a texture projection. Similar to the above code except
  51. that it's more generic so could be used for non-shroud
  52. projection of various masks.
  53. */
  54. class W3DMaskMaterialPassClass : public MaterialPassClass
  55. {
  56. public:
  57. W3DMaskMaterialPassClass(void) : m_texture(NULL), m_allowUninstall(TRUE) {}
  58. virtual void Install_Materials(void) const;
  59. virtual void UnInstall_Materials(void) const;
  60. void setTexture(TextureClass *texture) {m_texture=texture;}
  61. void setAllowUninstall(Bool state) { m_allowUninstall = state;}
  62. protected:
  63. TextureClass *m_texture; ///<texture to be projected.
  64. Bool m_allowUninstall; ///<flag which allows uninstalling this material.
  65. };
  66. /** Terrain shroud rendering class */
  67. class W3DShroud
  68. {
  69. public:
  70. W3DShroud(void);
  71. ~W3DShroud(void);
  72. void render(CameraClass *cam); ///< render the current shroud state as seen from camera
  73. void init(WorldHeightMap *pMap, Real worldCellSizeX, Real worldCellSizeY);
  74. void reset(void);
  75. TextureClass *getShroudTexture(void) { return m_pDstTexture;} //<return shroud projection texture.
  76. void ReleaseResources(void); ///<release resources that can't survive D3D device reset.
  77. Bool ReAcquireResources(void); ///<allocate resources that can't survive D3D device reset.
  78. void fillShroudData(W3DShroudLevel level); ///<sets the state of the current shroud to some constant value
  79. Int getNumShroudCellsY(void) {return m_numCellsY;}
  80. Int getNumShroudCellsX(void) {return m_numCellsX;}
  81. Real getCellWidth(void) {return m_cellWidth;} ///<world-space width (x) of each shroud cell.
  82. Real getCellHeight(void) {return m_cellHeight;} ///<world-space height (y)of each shroud cell.
  83. Int getTextureWidth(void) {return m_dstTextureWidth;} ///<internal use by the shader system.
  84. Int getTextureHeight(void) {return m_dstTextureHeight;}
  85. W3DShroudLevel getShroudLevel(Int x, Int y);
  86. void setShroudLevel(Int x, Int y, W3DShroudLevel,Bool textureOnly=FALSE);
  87. void setShroudFilter(Bool enable); ///<turns on bilinear filtering of shroud cells.
  88. void setBorderShroudLevel(W3DShroudLevel level); ///<color that will appear in unused border terrain.
  89. Real getDrawOriginX(void) {return m_drawOriginX;} ///<returns ws origin of first pixel in shroud texture.
  90. Real getDrawOriginY(void) {return m_drawOriginY;} ///<returns ws origin of first pixel in shroud texture.
  91. protected:
  92. Int m_numCellsX; ///<number of cells covering entire map
  93. Int m_numCellsY; ///<number of cells covering entire map
  94. Int m_numMaxVisibleCellsX; ///<maximum number of shroud cells that can be visible
  95. Int m_numMaxVisibleCellsY; ///<maximum number of shroud cells that can be visible
  96. Real m_cellWidth; ///<spacing between adjacent cells
  97. Real m_cellHeight; ///<spacing between adjacent cells
  98. Byte *m_shroudData; ///<holds amount of shroud per cell.
  99. IDirect3DSurface8 *m_pSrcTexture; ///<stores sysmem copy of visible shroud.
  100. void *m_srcTextureData; ///<pointer to shroud data
  101. UnsignedInt m_srcTexturePitch; ///<width (in bytes) of shroud data buffer.
  102. TextureClass *m_pDstTexture; ///<stores vidmem copy of visible shroud.
  103. Int m_dstTextureWidth; ///<dimensions of m_pDstTexture
  104. Int m_dstTextureHeight; ///<dimensions of m_pDstTexture
  105. TextureFilterClass::FilterType m_shroudFilter;
  106. Real m_drawOriginX;
  107. Real m_drawOriginY;
  108. Bool m_drawFogOfWar; ///<switch to draw alternate fog style instead of solid black
  109. Bool m_clearDstTexture; ///<flag indicating we must clear video memory destination texture
  110. W3DShroudLevel m_boderShroudLevel; ///<color used to clear the shroud border
  111. W3DShroudLevel *m_finalFogData; ///<copy of logical shroud in an easier to access array.
  112. W3DShroudLevel *m_currentFogData; ///<copy of intermediate logical shroud while it's interpolated.
  113. void interpolateFogLevels(RECT *rect); ///<fade current fog levels to actual logic side levels.
  114. void fillBorderShroudData(W3DShroudLevel level, SurfaceClass* pDestSurface); ///<fill the destination texture with a known value
  115. };
  116. #endif //__W3DSHROUD_H_