PVRTShadowVol.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /******************************************************************************
  2. @File PVRTShadowVol.h
  3. @Title PVRTShadowVol
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Declarations of functions relating to shadow volume generation.
  8. ******************************************************************************/
  9. #ifndef _PVRTSHADOWVOL_H_
  10. #define _PVRTSHADOWVOL_H_
  11. #include "PVRTContext.h"
  12. #include "PVRTVector.h"
  13. /****************************************************************************
  14. ** Defines
  15. ****************************************************************************/
  16. #define PVRTSHADOWVOLUME_VISIBLE 0x00000001
  17. #define PVRTSHADOWVOLUME_NEED_CAP_FRONT 0x00000002
  18. #define PVRTSHADOWVOLUME_NEED_CAP_BACK 0x00000004
  19. #define PVRTSHADOWVOLUME_NEED_ZFAIL 0x00000008
  20. /****************************************************************************
  21. ** Structures
  22. ****************************************************************************/
  23. struct PVRTShadowVolMEdge {
  24. unsigned short wV0, wV1; /*!< Indices of the vertices of the edge */
  25. int nVis; /*!< Bit0 = Visible, Bit1 = Hidden, Bit2 = Reverse Winding */
  26. };
  27. struct PVRTShadowVolMTriangle {
  28. unsigned short w[3]; /*!< Source indices of the triangle */
  29. PVRTShadowVolMEdge *pE0, *pE1, *pE2; /*!< Edges of the triangle */
  30. PVRTVECTOR3 vNormal; /*!< Triangle normal */
  31. int nWinding; /*!< BitN = Correct winding for edge N */
  32. };
  33. struct PVRTShadowVolShadowMesh {
  34. PVRTVECTOR3 *pV; /*!< Unique vertices in object space */
  35. PVRTShadowVolMEdge *pE;
  36. PVRTShadowVolMTriangle *pT;
  37. unsigned int nV; /*!< Vertex count */
  38. unsigned int nE; /*!< Edge count */
  39. unsigned int nT; /*!< Triangle count */
  40. #ifdef BUILD_DX9
  41. IDirect3DVertexBuffer9 *pivb; /*!< Two copies of the vertices */
  42. #endif
  43. #ifdef BUILD_DX10
  44. ID3D10Buffer *pivb; /*!< Two copies of the vertices */
  45. #endif
  46. #if defined(BUILD_OGL) || defined(BUILD_OGLES) || defined(BUILD_OGLES2)
  47. void *pivb; /*!< Two copies of the vertices */
  48. #endif
  49. };
  50. /*
  51. Renderable shadow-volume information:
  52. */
  53. struct PVRTShadowVolShadowVol {
  54. #ifdef BUILD_DX9
  55. IDirect3DIndexBuffer9 *piib; /*!< Indices to render the volume */
  56. #endif
  57. #ifdef BUILD_DX10
  58. ID3D10Buffer *piib; /*!< Indices to render the volume */
  59. #endif
  60. #if defined(BUILD_OGL) || defined(BUILD_OGLES) || defined(BUILD_OGLES2)
  61. unsigned short *piib; /*!< Indices to render the volume */
  62. #endif
  63. unsigned int nIdxCnt; /*!< Number of indices in piib */
  64. #ifdef _DEBUG
  65. unsigned int nIdxCntMax; /*!< Number of indices which can fit in piib */
  66. #endif
  67. };
  68. /****************************************************************************
  69. ** Declarations
  70. ****************************************************************************/
  71. /*!***********************************************************************
  72. @Function PVRTShadowVolMeshCreateMesh
  73. @Modified psMesh The shadow volume mesh to populate
  74. @Input pVertex A list of vertices
  75. @Input nNumVertex The number of vertices
  76. @Input pFaces A list of faces
  77. @Input nNumFaces The number of faces
  78. @Description Creates a mesh format suitable for generating shadow volumes
  79. *************************************************************************/
  80. void PVRTShadowVolMeshCreateMesh(
  81. PVRTShadowVolShadowMesh * const psMesh,
  82. const float * const pVertex,
  83. const unsigned int nNumVertex,
  84. const unsigned short * const pFaces,
  85. const unsigned int nNumFaces);
  86. /*!***********************************************************************
  87. @Function PVRTShadowVolMeshInitMesh
  88. @Input psMesh The shadow volume mesh
  89. @Input pContext A struct for API specific data
  90. @Returns True on success
  91. @Description Init the mesh
  92. *************************************************************************/
  93. bool PVRTShadowVolMeshInitMesh(
  94. PVRTShadowVolShadowMesh * const psMesh,
  95. const SPVRTContext * const pContext);
  96. /*!***********************************************************************
  97. @Function PVRTShadowVolMeshInitVol
  98. @Modified psVol The shadow volume struct
  99. @Input psMesh The shadow volume mesh
  100. @Input pContext A struct for API specific data
  101. @Returns True on success
  102. @Description Init the renderable shadow volume information.
  103. *************************************************************************/
  104. bool PVRTShadowVolMeshInitVol(
  105. PVRTShadowVolShadowVol * const psVol,
  106. const PVRTShadowVolShadowMesh * const psMesh,
  107. const SPVRTContext * const pContext);
  108. /*!***********************************************************************
  109. @Function PVRTShadowVolMeshDestroyMesh
  110. @Input psMesh The shadow volume mesh to destroy
  111. @Description Destroys all shadow volume mesh data created by PVRTShadowVolMeshCreateMesh
  112. *************************************************************************/
  113. void PVRTShadowVolMeshDestroyMesh(
  114. PVRTShadowVolShadowMesh * const psMesh);
  115. /*!***********************************************************************
  116. @Function PVRTShadowVolMeshReleaseMesh
  117. @Input psMesh The shadow volume mesh to release
  118. @Description Releases all shadow volume mesh data created by PVRTShadowVolMeshInitMesh
  119. *************************************************************************/
  120. void PVRTShadowVolMeshReleaseMesh(
  121. PVRTShadowVolShadowMesh * const psMesh);
  122. /*!***********************************************************************
  123. @Function PVRTShadowVolMeshReleaseVol
  124. @Input psVol The shadow volume information to release
  125. @Description Releases all data create by PVRTShadowVolMeshInitVol
  126. *************************************************************************/
  127. void PVRTShadowVolMeshReleaseVol(
  128. PVRTShadowVolShadowVol * const psVol);
  129. /*!***********************************************************************
  130. @Function PVRTShadowVolSilhouetteProjectedBuild
  131. @Modified psVol The shadow volume information
  132. @Input dwVisFlags Shadow volume creation flags
  133. @Input psMesh The shadow volume mesh
  134. @Input pvLightModel The light position/direction
  135. @Input bPointLight Is the light a point light
  136. @Description Using the light set up the shadow volume so it can be extruded.
  137. *************************************************************************/
  138. void PVRTShadowVolSilhouetteProjectedBuild(
  139. PVRTShadowVolShadowVol * const psVol,
  140. const unsigned int dwVisFlags,
  141. const PVRTShadowVolShadowMesh * const psMesh,
  142. const PVRTVECTOR3 * const pvLightModel,
  143. const bool bPointLight);
  144. /*!***********************************************************************
  145. @Function PVRTShadowVolSilhouetteProjectedBuild
  146. @Modified psVol The shadow volume information
  147. @Input dwVisFlags Shadow volume creation flags
  148. @Input psMesh The shadow volume mesh
  149. @Input pvLightModel The light position/direction
  150. @Input bPointLight Is the light a point light
  151. @Description Using the light set up the shadow volume so it can be extruded.
  152. *************************************************************************/
  153. void PVRTShadowVolSilhouetteProjectedBuild(
  154. PVRTShadowVolShadowVol * const psVol,
  155. const unsigned int dwVisFlags,
  156. const PVRTShadowVolShadowMesh * const psMesh,
  157. const PVRTVec3 * const pvLightModel,
  158. const bool bPointLight);
  159. /*!***********************************************************************
  160. @Function PVRTShadowVolBoundingBoxExtrude
  161. @Modified pvExtrudedCube 8 Vertices to represent the extruded box
  162. @Input pBoundingBox The bounding box to extrude
  163. @Input pvLightMdl The light position/direction
  164. @Input bPointLight Is the light a point light
  165. @Input fVolLength The length the volume has been extruded by
  166. @Description Extrudes the bounding box of the volume
  167. *************************************************************************/
  168. void PVRTShadowVolBoundingBoxExtrude(
  169. PVRTVECTOR3 * const pvExtrudedCube,
  170. const PVRTBOUNDINGBOX * const pBoundingBox,
  171. const PVRTVECTOR3 * const pvLightMdl,
  172. const bool bPointLight,
  173. const float fVolLength);
  174. /*!***********************************************************************
  175. @Function PVRTShadowVolBoundingBoxIsVisible
  176. @Modified pdwVisFlags Visibility flags
  177. @Input bObVisible Is the object visible? Unused set to true
  178. @Input bNeedsZClipping Does the object require Z clipping? Unused set to true
  179. @Input pBoundingBox The volumes bounding box
  180. @Input pmTrans The projection matrix
  181. @Input pvLightMdl The light position/direction
  182. @Input bPointLight Is the light a point light
  183. @Input fCamZProj The camera's z projection value
  184. @Input fVolLength The length the volume is extruded by
  185. @Description Determines if the volume is visible and if it needs caps
  186. *************************************************************************/
  187. void PVRTShadowVolBoundingBoxIsVisible(
  188. unsigned int * const pdwVisFlags,
  189. const bool bObVisible,
  190. const bool bNeedsZClipping,
  191. const PVRTBOUNDINGBOX * const pBoundingBox,
  192. const PVRTMATRIX * const pmTrans,
  193. const PVRTVECTOR3 * const pvLightMdl,
  194. const bool bPointLight,
  195. const float fCamZProj,
  196. const float fVolLength);
  197. /*!***********************************************************************
  198. @Function PVRTShadowVolSilhouetteProjectedRender
  199. @Input psMesh Shadow volume mesh
  200. @Input psVol Renderable shadow volume information
  201. @Input pContext A struct for passing in API specific data
  202. @Description Draws the shadow volume
  203. *************************************************************************/
  204. int PVRTShadowVolSilhouetteProjectedRender(
  205. const PVRTShadowVolShadowMesh * const psMesh,
  206. const PVRTShadowVolShadowVol * const psVol,
  207. const SPVRTContext * const pContext);
  208. #endif /* _PVRTSHADOWVOL_H_ */
  209. /*****************************************************************************
  210. End of file (PVRTShadowVol.h)
  211. *****************************************************************************/