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