PVRTPFXParser.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /******************************************************************************
  2. @File PVRTPFXParser.h
  3. @Title PVRTPFXParser
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform Windows + Linux
  7. @Description Declaration of PFX file parser
  8. ******************************************************************************/
  9. #ifndef _PVRTPFXPARSER_H_
  10. #define _PVRTPFXPARSER_H_
  11. /*****************************************************************************
  12. ** Includes
  13. ******************************************************************************/
  14. #include "PVRTString.h"
  15. #include "PVRTError.h"
  16. #include "PVRTTexture.h"
  17. #include "PVRTVector.h"
  18. /****************************************************************************
  19. ** Structures
  20. ****************************************************************************/
  21. /*!**************************************************************************
  22. @Struct SPVRTPFXParserHeader
  23. @Brief Struct for storing PFX file header data
  24. ****************************************************************************/
  25. struct SPVRTPFXParserHeader
  26. {
  27. char *pszVersion;
  28. char *pszDescription;
  29. char *pszCopyright;
  30. };
  31. /*!**************************************************************************
  32. @Struct SPVRTPFXParserTexture
  33. @Brief Struct for storing PFX data from the texture block
  34. ****************************************************************************/
  35. struct SPVRTPFXParserTexture
  36. {
  37. char *pszName;
  38. char *pszFile;
  39. bool bRenderToTexture;
  40. unsigned int nMin, nMag, nMIP;
  41. unsigned int nWrapS, nWrapT, nWrapR; // either GL_CLAMP or GL_REPEAT
  42. unsigned int uiWidth, uiHeight;
  43. unsigned int uiFlags;
  44. SPVRTPFXParserTexture()
  45. :
  46. pszName(NULL),
  47. pszFile(NULL)
  48. {
  49. }
  50. };
  51. /*!**************************************************************************
  52. @Struct SPVRTPFXParserShader
  53. @Brief Struct for storing PFX data from the shader block
  54. ****************************************************************************/
  55. struct SPVRTPFXParserShader
  56. {
  57. char *pszName;
  58. bool bUseFileName;
  59. char *pszGLSLfile;
  60. char *pszGLSLBinaryFile;
  61. char *pszGLSLcode;
  62. char *pbGLSLBinary;
  63. unsigned int nGLSLBinarySize;
  64. unsigned int nFirstLineNumber; // Line number in the text file where this code began; use to correct line-numbers in compiler errors
  65. };
  66. /*!**************************************************************************
  67. @Enum ESemanticDefaultDataType
  68. @Brief Enum values for the various variable types supported
  69. ****************************************************************************/
  70. enum ESemanticDefaultDataType
  71. {
  72. eDataTypeMat2,
  73. eDataTypeMat3,
  74. eDataTypeMat4,
  75. eDataTypeVec2,
  76. eDataTypeVec3,
  77. eDataTypeVec4,
  78. eDataTypeIvec2,
  79. eDataTypeIvec3,
  80. eDataTypeIvec4,
  81. eDataTypeBvec2,
  82. eDataTypeBvec3,
  83. eDataTypeBvec4,
  84. eDataTypeFloat,
  85. eDataTypeInt,
  86. eDataTypeBool,
  87. eNumDefaultDataTypes,
  88. eDataTypeNone
  89. };
  90. /*!**************************************************************************
  91. @Enum EDefaultDataInternalType
  92. @Brief Enum values for defining whether a variable is float, interger or bool
  93. ****************************************************************************/
  94. enum EDefaultDataInternalType
  95. {
  96. eFloating,
  97. eInteger,
  98. eBoolean
  99. };
  100. struct SSemanticDefaultDataTypeInfo
  101. {
  102. ESemanticDefaultDataType eType;
  103. const char *pszName;
  104. unsigned int nNumberDataItems;
  105. EDefaultDataInternalType eInternalType;
  106. };
  107. const static SSemanticDefaultDataTypeInfo c_psSemanticDefaultDataTypeInfo[] =
  108. {
  109. { eDataTypeMat2, "mat2", 4, eFloating },
  110. { eDataTypeMat3, "mat3", 9, eFloating },
  111. { eDataTypeMat4, "mat4", 16, eFloating },
  112. { eDataTypeVec2, "vec2", 2, eFloating },
  113. { eDataTypeVec3, "vec3", 3, eFloating },
  114. { eDataTypeVec4, "vec4", 4, eFloating },
  115. { eDataTypeIvec2, "ivec2", 2, eInteger },
  116. { eDataTypeIvec3, "ivec3", 3, eInteger },
  117. { eDataTypeIvec4, "ivec4", 4, eInteger },
  118. { eDataTypeBvec2, "bvec2", 2, eBoolean },
  119. { eDataTypeBvec3, "bvec3", 3, eBoolean },
  120. { eDataTypeBvec4, "bvec4", 4, eBoolean },
  121. { eDataTypeFloat, "float", 1, eFloating },
  122. { eDataTypeInt, "int", 1, eInteger },
  123. { eDataTypeBool, "bool", 1, eBoolean }
  124. };
  125. /*!**************************************************************************
  126. @Struct SPVRTSemanticDefaultData
  127. @Brief Stores a default value
  128. ****************************************************************************/
  129. struct SPVRTSemanticDefaultData
  130. {
  131. float pfData[16];
  132. int pnData[4];
  133. bool pbData[4];
  134. ESemanticDefaultDataType eType;
  135. };
  136. /*!**************************************************************************
  137. @Struct SPVRTPFXParserSemantic
  138. @Brief Stores semantic information
  139. ****************************************************************************/
  140. struct SPVRTPFXParserSemantic
  141. {
  142. char *pszName; /*!< The variable name as used in the shader-language code */
  143. char *pszValue; /*!< For example: LIGHTPOSITION */
  144. unsigned int nIdx; /*!< Index; for example two semantics might be LIGHTPOSITION0 and LIGHTPOSITION1 */
  145. SPVRTSemanticDefaultData sDefaultValue; /*!< Default value */
  146. };
  147. /*!**************************************************************************
  148. @Struct SPVRTPFXParserEffectTexture
  149. @Brief Stores effect texture information
  150. ****************************************************************************/
  151. struct SPVRTPFXParserEffectTexture
  152. {
  153. unsigned int nNumber; /*!< Texture number to set */
  154. char *pszName; /*!< Name of the texture to set there */
  155. unsigned int u32Type; /*!< Identifying cube maps etc. */
  156. };
  157. /*!**************************************************************************
  158. @enum ERenderPassType
  159. @Brief Decribes the type of render required
  160. ****************************************************************************/
  161. enum ERenderPassType
  162. {
  163. eCubeMapRender,
  164. eSphMapRender,
  165. eCameraRender,
  166. ePostProcessRender
  167. };
  168. enum ERenderPassCamera
  169. {
  170. eFromNode,
  171. eFromExplicitPositon,
  172. eFromCenterOfCurrent
  173. };
  174. enum PixelType;
  175. /*!**************************************************************************
  176. @Struct SPVRTPFXRenderPass
  177. @Brief Stores render pass information
  178. ****************************************************************************/
  179. struct SPVRTPFXRenderPass
  180. {
  181. int i32TextureNumber; // Element no within parser texture array
  182. ERenderPassType eRenderPassType;
  183. ERenderPassCamera eCameraPosition;
  184. char* pszSemanticName;
  185. PixelType eFormat;
  186. PVRTVec3 vecPos;
  187. char *pszNodeName;
  188. SPVRTPFXRenderPass()
  189. :
  190. i32TextureNumber(0),
  191. pszSemanticName(NULL),
  192. vecPos(0,0,0),
  193. pszNodeName(NULL)
  194. {
  195. }
  196. ~SPVRTPFXRenderPass()
  197. {
  198. if(pszSemanticName) delete[] pszSemanticName;
  199. if(pszNodeName) delete[] pszNodeName;
  200. }
  201. };
  202. /*!**************************************************************************
  203. @Struct SPVRTPFXParserEffect
  204. @Brief Stores effect information
  205. ****************************************************************************/
  206. struct SPVRTPFXParserEffect
  207. {
  208. char *pszName;
  209. char *pszAnnotation;
  210. char *pszVertexShaderName;
  211. char *pszFragmentShaderName;
  212. SPVRTPFXParserSemantic *psUniform;
  213. unsigned int nNumUniforms, nMaxUniforms;
  214. SPVRTPFXParserSemantic *psAttribute;
  215. unsigned int nNumAttributes, nMaxAttributes;
  216. SPVRTPFXParserEffectTexture *psTextures;
  217. unsigned int nNumTextures, nMaxTextures;
  218. };
  219. class CPVRTPFXParserReadContext;
  220. /*!**************************************************************************
  221. @Class CPVRTPFXParser
  222. @Brief PFX parser
  223. ****************************************************************************/
  224. class CPVRTPFXParser
  225. {
  226. public:
  227. /*!***************************************************************************
  228. @Function CPVRTPFXParser
  229. @Description Sets initial values.
  230. *****************************************************************************/
  231. CPVRTPFXParser();
  232. /*!***************************************************************************
  233. @Function ~CPVRTPFXParser
  234. @Description Frees memory used.
  235. *****************************************************************************/
  236. ~CPVRTPFXParser();
  237. /*!***************************************************************************
  238. @Function ParseFromMemory
  239. @Input pszScript PFX script
  240. @Output pReturnError error string
  241. @Return EPVRTError PVR_SUCCESS for success parsing file
  242. PVR_FAIL if file doesn't exist or is invalid
  243. @Description Parses a PFX script from memory.
  244. *****************************************************************************/
  245. EPVRTError ParseFromMemory(const char * const pszScript, CPVRTString * const pReturnError);
  246. /*!***************************************************************************
  247. @Function ParseFromFile
  248. @Input pszFileName PFX file name
  249. @Output pReturnError error string
  250. @Return EPVRTError PVR_SUCCESS for success parsing file
  251. PVR_FAIL if file doesn't exist or is invalid
  252. @Description Reads the PFX file and calls the parser.
  253. *****************************************************************************/
  254. EPVRTError ParseFromFile(const char * const pszFileName, CPVRTString * const pReturnError);
  255. /*!***************************************************************************
  256. @Function SetViewportSize
  257. @Input uiWidth New viewport width
  258. @Input uiHeight New viewport height
  259. @Return bool True on success
  260. @Description Allows the current viewport size to be set. This value
  261. is used for calculating relative texture resolutions
  262. *****************************************************************************/
  263. bool SetViewportSize(unsigned int uiWidth, unsigned int uiHeight);
  264. /*!***************************************************************************
  265. @Function DebugDump
  266. @Return string A string containing debug information for the user
  267. to handle
  268. @Description Debug output.
  269. *****************************************************************************/
  270. CPVRTString DebugDump() const;
  271. SPVRTPFXParserHeader m_sHeader;
  272. SPVRTPFXParserTexture *m_psTexture;
  273. unsigned int m_nNumTextures, m_nMaxTextures;
  274. SPVRTPFXParserShader *m_psFragmentShader;
  275. unsigned int m_nNumFragShaders, m_nMaxFragShaders;
  276. SPVRTPFXParserShader *m_psVertexShader;
  277. unsigned int m_nNumVertShaders, m_nMaxVertShaders;
  278. SPVRTPFXParserEffect *m_psEffect;
  279. unsigned int m_nNumEffects, m_nMaxEffects;
  280. SPVRTPFXRenderPass *m_psRenderPasses;
  281. unsigned int m_nNumRenderPasses, m_nMaxRenders;
  282. unsigned int m_uiViewportWidth, m_uiViewportHeight;
  283. private:
  284. CPVRTPFXParserReadContext *m_psContext;
  285. /*!***************************************************************************
  286. @Function Parse
  287. @Output pReturnError error string
  288. @Return bool true for success parsing file
  289. @Description Parses a loaded PFX file.
  290. *****************************************************************************/
  291. bool Parse( CPVRTString * const pReturnError);
  292. /*!***************************************************************************
  293. @Function ReduceWhitespace
  294. @Output line output text
  295. @Input line input text
  296. @Description Reduces all white space characters in the string to one
  297. blank space.
  298. *****************************************************************************/
  299. void ReduceWhitespace(char *line);
  300. /*!***************************************************************************
  301. @Function GetEndTag
  302. @Input pszTagName tag name
  303. @Input nStartLine start line
  304. @Output pnEndLine line end tag found
  305. @Return true if tag found
  306. @Description Searches for end tag pszTagName from line nStartLine.
  307. Returns true and outputs the line number of the end tag if
  308. found, otherwise returning false.
  309. *****************************************************************************/
  310. bool GetEndTag(const char *pszTagName, int nStartLine, int *pnEndLine);
  311. /*!***************************************************************************
  312. @Function ReturnParameter
  313. @Output
  314. @Input
  315. @Description Finds the parameter after the specified delimiting character and
  316. returns the parameter as a string. An empty string is returned
  317. if a parameter cannot be found
  318. *****************************************************************************/
  319. CPVRTString FindParameter(char *aszSourceString, const CPVRTString &parameterTag, const CPVRTString &delimiter);
  320. /*!***************************************************************************
  321. @Function ProcessKeywordParam
  322. @Input parameterString Parameter string to process
  323. @Return Returns true on success
  324. @Description Processes the node name or vector position parameters that
  325. can be assigned to render pass keywords (e.g. ENVMAPCUBE=(11.0, 22.0, 0.0))
  326. *****************************************************************************/
  327. bool ProcessKeywordParam(const CPVRTString &parameterString);
  328. /*!***************************************************************************
  329. @Function ParseHeader
  330. @Input nStartLine start line number
  331. @Input nEndLine end line number
  332. @Output pReturnError error string
  333. @Return bool true if parse is successful
  334. @Description Parses the HEADER section of the PFX file.
  335. *****************************************************************************/
  336. bool ParseHeader(int nStartLine, int nEndLine, CPVRTString * const pReturnError);
  337. /*!***************************************************************************
  338. @Function ParseTextures
  339. @Input nStartLine start line number
  340. @Input nEndLine end line number
  341. @Output pReturnError error string
  342. @Return bool true if parse is successful
  343. @Description Parses the TEXTURE section of the PFX file.
  344. *****************************************************************************/
  345. bool ParseTextures(int nStartLine, int nEndLine, CPVRTString * const pReturnError);
  346. /*!***************************************************************************
  347. @Function ParseShader
  348. @Input nStartLine start line number
  349. @Input nEndLine end line number
  350. @Output pReturnError error string
  351. @Output shader shader data object
  352. @Input pszBlockName name of block in PFX file
  353. @Return bool true if parse is successful
  354. @Description Parses the VERTEXSHADER or FRAGMENTSHADER section of the
  355. PFX file.
  356. *****************************************************************************/
  357. bool ParseShader(int nStartLine, int nEndLine, CPVRTString *pReturnError, SPVRTPFXParserShader &shader, const char * const pszBlockName);
  358. /*!***************************************************************************
  359. @Function ParseSemantic
  360. @Output semantic semantic data object
  361. @Input nStartLine start line number
  362. @Output pReturnError error string
  363. @Return bool true if parse is successful
  364. @Description Parses a semantic.
  365. *****************************************************************************/
  366. bool ParseSemantic(SPVRTPFXParserSemantic &semantic, const int nStartLine, CPVRTString * const pReturnError);
  367. /*!***************************************************************************
  368. @Function ParseEffect
  369. @Output effect effect data object
  370. @Input nStartLine start line number
  371. @Input nEndLine end line number
  372. @Output pReturnError error string
  373. @Return bool true if parse is successful
  374. @Description Parses the EFFECT section of the PFX file.
  375. *****************************************************************************/
  376. bool ParseEffect(SPVRTPFXParserEffect &effect, const int nStartLine, const int nEndLine, CPVRTString * const pReturnError);
  377. };
  378. #endif /* _PVRTPFXPARSER_H_ */
  379. /*****************************************************************************
  380. End of file (PVRTPFXParser.h)
  381. *****************************************************************************/