PVRTPFXParserAPI.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /******************************************************************************
  2. @File PVRTPFXParserAPI.cpp
  3. @Title PVRTPFXParserAPI
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description PFX file parser.
  8. ******************************************************************************/
  9. /*****************************************************************************
  10. ** Includes
  11. *****************************************************************************/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "PVRTContext.h"
  16. #include "PVRTMatrix.h"
  17. #include "PVRTFixedPoint.h"
  18. #include "PVRTString.h"
  19. #include "PVRTShader.h"
  20. #include "PVRTPFXParser.h"
  21. #include "PVRTPFXParserAPI.h"
  22. #include "PVRTTexture.h"
  23. #include "PVRTgles2Ext.h"
  24. /*!***************************************************************************
  25. @Function CPVRTPFXEffect Constructor
  26. @Description Sets the context and initialises the member variables to zero.
  27. *****************************************************************************/
  28. CPVRTPFXEffect::CPVRTPFXEffect()
  29. {
  30. m_psContext = NULL;
  31. m_uiProgram = 0;
  32. m_pnTextureIdx = 0;
  33. }
  34. /*!***************************************************************************
  35. @Function CPVRTPFXEffect Constructor
  36. @Description Sets the context and initialises the member variables to zero.
  37. *****************************************************************************/
  38. CPVRTPFXEffect::CPVRTPFXEffect(SPVRTContext &sContext)
  39. {
  40. m_psContext = &sContext;
  41. m_uiProgram = 0;
  42. m_pnTextureIdx = 0;
  43. }
  44. /*!***************************************************************************
  45. @Function CPVRTPFXEffect Destructor
  46. @Description Calls Destroy().
  47. *****************************************************************************/
  48. CPVRTPFXEffect::~CPVRTPFXEffect()
  49. {
  50. Destroy();
  51. }
  52. /*!***************************************************************************
  53. @Function Load
  54. @Input src PFX Parser Object
  55. @Input pszEffect Effect name
  56. @Input pszFileName Effect file name
  57. @Output pReturnError Error string
  58. @Returns EPVRTError PVR_SUCCESS if load succeeded
  59. @Description Loads the specified effect from the CPVRTPFXParser object.
  60. Compiles and links the shaders. Initialises texture data.
  61. *****************************************************************************/
  62. EPVRTError CPVRTPFXEffect::Load(CPVRTPFXParser &src, const char * const pszEffect, const char * const pszFileName, CPVRTString *pReturnError)
  63. {
  64. GLuint uiVertexShader = 0, uiFragShader = 0;
  65. unsigned int i, j;
  66. if(!src.m_nNumEffects)
  67. return PVR_FAIL;
  68. /*
  69. First find the named effect from the effect file
  70. */
  71. if(pszEffect)
  72. {
  73. for(i = 0; i < src.m_nNumEffects; ++i)
  74. {
  75. if(strcmp(src.m_psEffect[i].pszName, pszEffect) == 0)
  76. {
  77. m_nEffect = i;
  78. break;
  79. }
  80. }
  81. if(i == src.m_nNumEffects)
  82. {
  83. return PVR_FAIL;
  84. }
  85. }
  86. else
  87. {
  88. m_nEffect = 0;
  89. }
  90. /*
  91. Now load the effect
  92. */
  93. m_pParser = &src;
  94. SPVRTPFXParserEffect *psParserEffect = &src.m_psEffect[m_nEffect];
  95. // Create room for per-texture data
  96. m_psTextures = new SPVRTPFXTexture[src.m_nNumTextures];
  97. // Initialise each Texture
  98. for(i = 0; i < src.m_nNumTextures; ++i)
  99. {
  100. m_psTextures[i].p = src.m_psTexture[i].pszFile;
  101. m_psTextures[i].ui = 0xFFFFFFFF;
  102. }
  103. // Initialise the effect
  104. {
  105. // initialise attributes to default values
  106. char *pszVertexShader = NULL;
  107. char *pszFragmentShader = NULL;
  108. bool bFreeVertexShader = false;
  109. bool bFreeFragmentShader = false;
  110. // find shaders requested
  111. for(i=0; i < src.m_nNumVertShaders; ++i)
  112. {
  113. if(strcmp(psParserEffect->pszVertexShaderName, src.m_psVertexShader[i].pszName) == 0)
  114. {
  115. if(src.m_psVertexShader[i].bUseFileName)
  116. {
  117. pszVertexShader = src.m_psVertexShader[i].pszGLSLcode;
  118. }
  119. else
  120. {
  121. // offset glsl code by nFirstLineNumber
  122. pszVertexShader = (char *)malloc((strlen(src.m_psVertexShader[i].pszGLSLcode) + (src.m_psVertexShader[i].nFirstLineNumber) + 1) * sizeof(char));
  123. pszVertexShader[0] = '\0';
  124. for(unsigned int n = 0; n < src.m_psVertexShader[i].nFirstLineNumber; n++)
  125. strcat(pszVertexShader, "\n");
  126. strcat(pszVertexShader, src.m_psVertexShader[i].pszGLSLcode);
  127. bFreeVertexShader = true;
  128. }
  129. break;
  130. }
  131. }
  132. for(i=0; i<src.m_nNumFragShaders; ++i)
  133. {
  134. if(strcmp(psParserEffect->pszFragmentShaderName, src.m_psFragmentShader[i].pszName) == 0)
  135. {
  136. if(src.m_psFragmentShader[i].bUseFileName)
  137. {
  138. pszFragmentShader = src.m_psFragmentShader[i].pszGLSLcode;
  139. }
  140. else
  141. {
  142. // offset glsl code by nFirstLineNumber
  143. pszFragmentShader = (char *)malloc((strlen(src.m_psFragmentShader[i].pszGLSLcode) + (src.m_psFragmentShader[i].nFirstLineNumber) + 1) * sizeof(char));
  144. pszFragmentShader[0] = '\0';
  145. for(unsigned int n = 0; n < src.m_psFragmentShader[i].nFirstLineNumber; n++)
  146. strcat(pszFragmentShader, "\n");
  147. strcat(pszFragmentShader, src.m_psFragmentShader[i].pszGLSLcode);
  148. bFreeFragmentShader = true;
  149. }
  150. break;
  151. }
  152. }
  153. CPVRTString error;
  154. bool bLoadSource = 1;
  155. // Try first to load from the binary block
  156. if (src.m_psVertexShader[i].pbGLSLBinary!=NULL)
  157. {
  158. if (PVRTShaderLoadBinaryFromMemory(src.m_psVertexShader[i].pbGLSLBinary, src.m_psVertexShader[i].nGLSLBinarySize,
  159. GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &uiVertexShader, &error) == PVR_SUCCESS)
  160. {
  161. // success loading the binary block so we do not need to load the source
  162. bLoadSource = 0;
  163. }
  164. else
  165. {
  166. bLoadSource = 1;
  167. }
  168. }
  169. // If it fails, load from source
  170. if (bLoadSource)
  171. {
  172. if(pszVertexShader)
  173. {
  174. if (PVRTShaderLoadSourceFromMemory(pszVertexShader, GL_VERTEX_SHADER, &uiVertexShader, &error) != PVR_SUCCESS)
  175. {
  176. *pReturnError = CPVRTString("Vertex Shader compile error in file '") + pszFileName + "':\n" + error;
  177. if(bFreeVertexShader) FREE(pszVertexShader);
  178. if(bFreeFragmentShader) FREE(pszFragmentShader);
  179. return PVR_FAIL;
  180. }
  181. }
  182. else // Shader not found or failed binary block
  183. {
  184. if (src.m_psVertexShader[i].pbGLSLBinary==NULL)
  185. {
  186. *pReturnError = CPVRTString("Vertex shader ") + psParserEffect->pszVertexShaderName + " not found in " + pszFileName + ".\n";
  187. }
  188. else
  189. {
  190. *pReturnError = CPVRTString("Binary vertex shader ") + psParserEffect->pszVertexShaderName + " not supported.\n";
  191. }
  192. if(bFreeVertexShader) FREE(pszVertexShader);
  193. if(bFreeFragmentShader) FREE(pszFragmentShader);
  194. return PVR_FAIL;
  195. }
  196. }
  197. // Try first to load from the binary block
  198. if (src.m_psFragmentShader[i].pbGLSLBinary!=NULL)
  199. {
  200. if (PVRTShaderLoadBinaryFromMemory(src.m_psFragmentShader[i].pbGLSLBinary, src.m_psVertexShader[i].nGLSLBinarySize,
  201. GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &uiFragShader, &error) == PVR_SUCCESS)
  202. {
  203. // success loading the binary block so we do not need to load the source
  204. bLoadSource = 0;
  205. }
  206. else
  207. {
  208. bLoadSource = 1;
  209. }
  210. }
  211. // If it fails, load from source
  212. if (bLoadSource)
  213. {
  214. if(pszFragmentShader)
  215. {
  216. if (PVRTShaderLoadSourceFromMemory(pszFragmentShader, GL_FRAGMENT_SHADER, &uiFragShader, &error) != PVR_SUCCESS)
  217. {
  218. *pReturnError = CPVRTString("Fragment Shader compile error in file '") + pszFileName + "':\n" + error;
  219. if(bFreeVertexShader) FREE(pszVertexShader);
  220. if(bFreeFragmentShader) FREE(pszFragmentShader);
  221. return PVR_FAIL;
  222. }
  223. }
  224. else // Shader not found or failed binary block
  225. {
  226. if (src.m_psFragmentShader[i].pbGLSLBinary==NULL)
  227. {
  228. *pReturnError = CPVRTString("Fragment shader ") + psParserEffect->pszFragmentShaderName + " not found in " + pszFileName + ".\n";
  229. }
  230. else
  231. {
  232. *pReturnError = CPVRTString("Binary Fragment shader ") + psParserEffect->pszFragmentShaderName + " not supported.\n";
  233. }
  234. if(bFreeVertexShader)
  235. FREE(pszVertexShader);
  236. if(bFreeFragmentShader)
  237. FREE(pszFragmentShader);
  238. return PVR_FAIL;
  239. }
  240. }
  241. if(bFreeVertexShader)
  242. FREE(pszVertexShader);
  243. if(bFreeFragmentShader)
  244. FREE(pszFragmentShader);
  245. // Create the shader program
  246. m_uiProgram = glCreateProgram();
  247. // Attach the fragment and vertex shaders to it
  248. glAttachShader(m_uiProgram, uiFragShader);
  249. glAttachShader(m_uiProgram, uiVertexShader);
  250. glDeleteShader(uiVertexShader);
  251. glDeleteShader(uiFragShader);
  252. // Bind vertex attributes
  253. for(i = 0; i < psParserEffect->nNumAttributes; ++i)
  254. {
  255. glBindAttribLocation(m_uiProgram, i, psParserEffect->psAttribute[i].pszName);
  256. }
  257. // Link the program.
  258. glLinkProgram(m_uiProgram);
  259. GLint Linked;
  260. glGetProgramiv(m_uiProgram, GL_LINK_STATUS, &Linked);
  261. if (!Linked)
  262. {
  263. int i32InfoLogLength, i32CharsWritten;
  264. glGetProgramiv(m_uiProgram, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
  265. char* pszInfoLog = new char[i32InfoLogLength];
  266. glGetProgramInfoLog(m_uiProgram, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
  267. *pReturnError = CPVRTString("Error Linking shaders in file '") + pszFileName + "':\n\n"
  268. + CPVRTString("Failed to link: ") + pszInfoLog + "\n";
  269. delete [] pszInfoLog;
  270. return PVR_FAIL;
  271. }
  272. /*
  273. Textures
  274. */
  275. m_pnTextureIdx = new unsigned int[psParserEffect->nNumTextures];
  276. for(i = 0; i < psParserEffect->nNumTextures; ++i)
  277. {
  278. for(j = 0; j < src.m_nNumTextures; ++j)
  279. {
  280. if(strcmp(psParserEffect->psTextures[i].pszName, src.m_psTexture[j].pszName) == 0)
  281. {
  282. m_pnTextureIdx[i] = j;
  283. break;
  284. }
  285. }
  286. if(j == src.m_nNumTextures)
  287. {
  288. *pReturnError = CPVRTString("Effect \"") + psParserEffect->pszName + "\", requested non-existent texture: \""
  289. + psParserEffect->psTextures[i].pszName + "\"\n";
  290. m_pnTextureIdx[i] = 0;
  291. }
  292. }
  293. }
  294. return PVR_SUCCESS;
  295. }
  296. /*!***************************************************************************
  297. @Function Destroy
  298. @Description Deletes the gl program object and texture data.
  299. *****************************************************************************/
  300. void CPVRTPFXEffect::Destroy()
  301. {
  302. {
  303. if(m_uiProgram != 0)
  304. {
  305. glDeleteProgram(m_uiProgram);
  306. m_uiProgram = 0;
  307. }
  308. delete [] m_pnTextureIdx;
  309. m_pnTextureIdx = 0;
  310. }
  311. delete [] m_psTextures;
  312. m_psTextures = 0;
  313. }
  314. /*!***************************************************************************
  315. @Function Activate
  316. @Returns PVR_SUCCESS if activate succeeded
  317. @Description Selects the gl program object and binds the textures.
  318. *****************************************************************************/
  319. EPVRTError CPVRTPFXEffect::Activate()
  320. {
  321. unsigned int i;
  322. SPVRTPFXParserEffect *psParserEffect = &m_pParser->m_psEffect[m_nEffect];
  323. // Set the program
  324. glUseProgram(m_uiProgram);
  325. // Set the textures
  326. for(i = 0; i < psParserEffect->nNumTextures; ++i)
  327. {
  328. glActiveTexture(GL_TEXTURE0 + psParserEffect->psTextures[i].nNumber);
  329. if((psParserEffect->psTextures[m_pnTextureIdx[i]].u32Type&PVRTEX_CUBEMAP)!=0)
  330. glBindTexture(GL_TEXTURE_CUBE_MAP, m_psTextures[m_pnTextureIdx[i]].ui);
  331. else
  332. glBindTexture(GL_TEXTURE_2D, m_psTextures[m_pnTextureIdx[i]].ui);
  333. }
  334. return PVR_SUCCESS;
  335. }
  336. /*!***************************************************************************
  337. @Function GetSemantics
  338. @Output psUniforms pointer to application uniform data array
  339. @Output pnUnknownUniformCount unknown uniform count
  340. @Input psParams pointer to semantic data array
  341. @Input nParamCount number of samantic items
  342. @Input psUniformSemantics pointer to uniform semantics array
  343. @Input nUniformSemantics number of uniform semantic items
  344. @Input pglesExt opengl extensions object
  345. @Input uiProgram program object index
  346. @Input bIsAttribue true if getting attribute semantics
  347. @Output errorMsg error string
  348. @Returns unsigned int number of successful semantics
  349. @Description Get the data array for the semantics.
  350. *****************************************************************************/
  351. static unsigned int GetSemantics(
  352. SPVRTPFXUniform * const psUniforms,
  353. unsigned int * const pnUnknownUniformCount,
  354. const SPVRTPFXParserSemantic * const psParams,
  355. const unsigned int nParamCount,
  356. const SPVRTPFXUniformSemantic * const psUniformSemantics,
  357. const unsigned int nUniformSemantics,
  358. const GLuint uiProgram,
  359. bool bIsAttribue,
  360. CPVRTString * const errorMsg)
  361. {
  362. unsigned int i, j, nCount, nCountUnused;
  363. int nLocation;
  364. /*
  365. Loop over the parameters searching for their semantics. If
  366. found/recognised, it should be placed in the output array.
  367. */
  368. nCount = 0;
  369. nCountUnused = 0;
  370. for(j = 0; j < nParamCount; ++j)
  371. {
  372. for(i = 0; i < nUniformSemantics; ++i)
  373. {
  374. if(strcmp(psParams[j].pszValue, psUniformSemantics[i].p) != 0)
  375. {
  376. continue;
  377. }
  378. // Semantic found for this parameter
  379. if(bIsAttribue)
  380. {
  381. nLocation = glGetAttribLocation(uiProgram, psParams[j].pszName);
  382. }
  383. else
  384. {
  385. nLocation = glGetUniformLocation(uiProgram, psParams[j].pszName);
  386. }
  387. if(nLocation != -1)
  388. {
  389. if(psUniforms)
  390. {
  391. psUniforms[nCount].nSemantic = psUniformSemantics[i].n;
  392. psUniforms[nCount].nLocation = nLocation;
  393. psUniforms[nCount].nIdx = psParams[j].nIdx;
  394. }
  395. ++nCount;
  396. }
  397. else
  398. {
  399. *errorMsg += "WARNING: Variable not used by GLSL code: ";
  400. *errorMsg += CPVRTString(psParams[j].pszName) + " ";
  401. *errorMsg += CPVRTString(psParams[j].pszValue) + "\n";
  402. ++nCountUnused;
  403. }
  404. // Skip to the next parameter
  405. break;
  406. }
  407. if(i == nUniformSemantics)
  408. {
  409. *errorMsg += "WARNING: Semantic unknown to application: ";
  410. *errorMsg += CPVRTString(psParams[j].pszName) + " ";
  411. *errorMsg += CPVRTString(psParams[j].pszValue) + "\n";
  412. }
  413. }
  414. *pnUnknownUniformCount = nParamCount - nCount - nCountUnused;
  415. return nCount;
  416. }
  417. /*!***************************************************************************
  418. @Function BuildUniformTable
  419. @Output ppsUniforms pointer to uniform data array
  420. @Output pnUniformCount pointer to number of uniforms
  421. @Output pnUnknownUniformCount pointer to number of unknown uniforms
  422. @Input psUniformSemantics pointer to uniform semantic data array
  423. @Input nSemantics number of uniform semantics
  424. @Output pReturnError error string
  425. @Returns EPVRTError PVR_SUCCESS if succeeded
  426. @Description Builds the uniform table from the semantics.
  427. *****************************************************************************/
  428. EPVRTError CPVRTPFXEffect::BuildUniformTable(
  429. SPVRTPFXUniform ** const ppsUniforms,
  430. unsigned int * const pnUniformCount,
  431. unsigned int * const pnUnknownUniformCount,
  432. const SPVRTPFXUniformSemantic * const psUniformSemantics,
  433. const unsigned int nSemantics,
  434. CPVRTString *pReturnError)
  435. {
  436. unsigned int nCount, nUnknownCount;
  437. SPVRTPFXUniform *psUniforms;
  438. SPVRTPFXParserEffect *psParserEffect = &m_pParser->m_psEffect[m_nEffect];
  439. nCount = 0;
  440. nCount += GetSemantics(NULL, &nUnknownCount, psParserEffect->psUniform, psParserEffect->nNumUniforms, psUniformSemantics, nSemantics, m_uiProgram, false, pReturnError);
  441. nCount += GetSemantics(NULL, &nUnknownCount, psParserEffect->psAttribute, psParserEffect->nNumAttributes, psUniformSemantics, nSemantics, m_uiProgram, true, pReturnError);
  442. psUniforms = (SPVRTPFXUniform*)malloc(nCount * sizeof(*psUniforms));
  443. if(!psUniforms)
  444. return PVR_FAIL;
  445. *pReturnError = "";
  446. nCount = 0;
  447. nCount += GetSemantics(&psUniforms[nCount], &nUnknownCount, psParserEffect->psUniform, psParserEffect->nNumUniforms, psUniformSemantics, nSemantics, m_uiProgram, false, pReturnError);
  448. *pnUnknownUniformCount = nUnknownCount;
  449. nCount += GetSemantics(&psUniforms[nCount], &nUnknownCount, psParserEffect->psAttribute, psParserEffect->nNumAttributes, psUniformSemantics, nSemantics, m_uiProgram, true, pReturnError);
  450. *pnUnknownUniformCount += nUnknownCount;
  451. *ppsUniforms = psUniforms;
  452. *pnUniformCount = nCount;
  453. return PVR_SUCCESS;
  454. }
  455. /*!***************************************************************************
  456. @Function GetTextureArray
  457. @Output nCount number of textures
  458. @Returns SPVRTPFXTexture* pointer to the texture data array
  459. @Description Gets the texture data array.
  460. *****************************************************************************/
  461. const SPVRTPFXTexture *CPVRTPFXEffect::GetTextureArray(unsigned int &nCount) const
  462. {
  463. nCount = m_pParser->m_nNumTextures;
  464. return m_psTextures;
  465. }
  466. /*!***************************************************************************
  467. @Function SetTexture
  468. @Input nIdx texture number
  469. @Input ui opengl texture handle
  470. @Input u32flags texture flags
  471. @Description Sets the textrue and applys the filtering.
  472. *****************************************************************************/
  473. void CPVRTPFXEffect::SetTexture(const unsigned int nIdx, const GLuint ui, const unsigned int u32flags)
  474. {
  475. if(nIdx < m_pParser->m_nNumTextures)
  476. {
  477. GLenum u32Target = GL_TEXTURE_2D;
  478. // Check if texture is a cubemap
  479. if((u32flags & PVRTEX_CUBEMAP) != 0)
  480. u32Target = GL_TEXTURE_CUBE_MAP;
  481. // Set default filter from PFX file
  482. switch(m_pParser->m_psTexture[nIdx].nMIP)
  483. {
  484. case 0:
  485. switch(m_pParser->m_psTexture[nIdx].nMin)
  486. {
  487. case 0:
  488. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  489. break;
  490. case 1:
  491. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  492. break;
  493. }
  494. break;
  495. case 1:
  496. switch(m_pParser->m_psTexture[nIdx].nMin)
  497. {
  498. case 0:
  499. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
  500. break;
  501. case 1:
  502. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  503. break;
  504. }
  505. break;
  506. case 2:
  507. switch(m_pParser->m_psTexture[nIdx].nMin)
  508. {
  509. case 0:
  510. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
  511. break;
  512. case 1:
  513. glTexParameteri(u32Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  514. break;
  515. }
  516. break;
  517. }
  518. switch(m_pParser->m_psTexture[nIdx].nMag)
  519. {
  520. case 0:
  521. glTexParameteri(u32Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  522. break;
  523. case 1:
  524. glTexParameteri(u32Target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  525. break;
  526. }
  527. switch(m_pParser->m_psTexture[nIdx].nWrapS)
  528. {
  529. case 0:
  530. glTexParameteri(u32Target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  531. break;
  532. case 1:
  533. glTexParameteri(u32Target, GL_TEXTURE_WRAP_S, GL_REPEAT);
  534. break;
  535. }
  536. switch(m_pParser->m_psTexture[nIdx].nWrapT)
  537. {
  538. case 0:
  539. glTexParameteri(u32Target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  540. break;
  541. case 1:
  542. glTexParameteri(u32Target, GL_TEXTURE_WRAP_T, GL_REPEAT);
  543. break;
  544. }
  545. #ifdef GL_TEXTURE_WRAP_R
  546. switch(m_pParser->m_psTexture[nIdx].nWrapR)
  547. {
  548. case 0:
  549. glTexParameteri(u32Target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  550. break;
  551. case 1:
  552. glTexParameteri(u32Target, GL_TEXTURE_WRAP_R, GL_REPEAT);
  553. break;
  554. }
  555. #endif
  556. m_psTextures[nIdx].ui = ui;
  557. // store flags
  558. m_pParser->m_psEffect[m_nEffect].psTextures[nIdx].u32Type = u32flags;
  559. }
  560. }
  561. /*!***************************************************************************
  562. @Function SetDefaultSemanticValue
  563. @Input pszName name of uniform
  564. @Input psDefaultValue pointer to default value
  565. @Description Sets the default value for the uniform semantic.
  566. *****************************************************************************/
  567. void CPVRTPFXEffect::SetDefaultUniformValue(const char *const pszName, const SPVRTSemanticDefaultData *psDefaultValue)
  568. {
  569. GLint nLocation = glGetUniformLocation(m_uiProgram, pszName);
  570. switch(psDefaultValue->eType)
  571. {
  572. case eDataTypeMat2:
  573. glUniformMatrix2fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
  574. break;
  575. case eDataTypeMat3:
  576. glUniformMatrix3fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
  577. break;
  578. case eDataTypeMat4:
  579. glUniformMatrix4fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
  580. break;
  581. case eDataTypeVec2:
  582. glUniform2fv(nLocation, 1, psDefaultValue->pfData);
  583. break;
  584. case eDataTypeVec3:
  585. glUniform3fv(nLocation, 1, psDefaultValue->pfData);
  586. break;
  587. case eDataTypeVec4:
  588. glUniform4fv(nLocation, 1, psDefaultValue->pfData);
  589. break;
  590. case eDataTypeIvec2:
  591. glUniform2iv(nLocation, 1, psDefaultValue->pnData);
  592. break;
  593. case eDataTypeIvec3:
  594. glUniform3iv(nLocation, 1, psDefaultValue->pnData);
  595. break;
  596. case eDataTypeIvec4:
  597. glUniform4iv(nLocation, 1, psDefaultValue->pnData);
  598. break;
  599. case eDataTypeBvec2:
  600. glUniform2i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0);
  601. break;
  602. case eDataTypeBvec3:
  603. glUniform3i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0);
  604. break;
  605. case eDataTypeBvec4:
  606. glUniform4i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0, psDefaultValue->pbData[3] ? 1 : 0);
  607. break;
  608. case eDataTypeFloat:
  609. glUniform1f(nLocation, psDefaultValue->pfData[0]);
  610. break;
  611. case eDataTypeInt:
  612. glUniform1i(nLocation, psDefaultValue->pnData[0]);
  613. break;
  614. case eDataTypeBool:
  615. glUniform1i(nLocation, psDefaultValue->pbData[0] ? 1 : 0);
  616. break;
  617. case eNumDefaultDataTypes:
  618. case eDataTypeNone:
  619. default:
  620. break;
  621. }
  622. }
  623. /*****************************************************************************
  624. End of file (PVRTPFXParserAPI.cpp)
  625. *****************************************************************************/