PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/GT-I5700/gles20/src/glTex.cpp

https://github.com/DE-NISkA/cm_android_vendor_spica
C++ | 5533 lines | 3760 code | 1017 blank | 756 comment | 1205 complexity | 18e6b01492ad12521b320a8745f6d4c6 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. *******************************************************************************
  3. *
  4. * SAMSUNG INDIA SOFTWARE OPERATIONS
  5. * Copyright(C) 2006
  6. * ALL RIGHTS RESERVED
  7. *
  8. * This program is proprietary to Samsung India Software Operations Pvt. Ltd.,
  9. * and is protected under International Copyright Act as an unpublished work.Its
  10. * use and disclosure is limited by the terms and conditions of a license agree-
  11. * -ment. It may not be copied or otherwise reproduced or disclosed to persons
  12. * outside the licensee's organization except in accordance with the terms and
  13. * conditions of such an agreement. All copies and reproductions shall be the
  14. * property of Samsung India Software Operations Pvt. Ltd. and must bear this
  15. * notice in its entirety.
  16. *
  17. *******************************************************************************
  18. */
  19. /*
  20. ***************************************************************************//*!
  21. *
  22. * \file glTex.cpp
  23. * \author Prashant Singh (prashant@samsung.com),
  24. * Anurag Ved (anuragv@samsung.com)
  25. * \brief Texture handling
  26. *
  27. *//*---------------------------------------------------------------------------
  28. * NOTES:
  29. *
  30. *//*---------------------------------------------------------------------------
  31. * HISTORY:
  32. *
  33. * 31.07.2006 Anurag Ved Initial draft implementation
  34. *
  35. * 3.08.2006 Prashant Singh Functions with new state and texture object
  36. *
  37. * 22.08.2006 Prashant Singh Compilable version with isComplete, Compile,
  38. * etc. Complete image specification, tex copy
  39. * and compressed image api is missing
  40. *
  41. * 24.08.2006 Prashant Singh Priliminary testing on host completed
  42. *
  43. *******************************************************************************
  44. */
  45. /*
  46. *******************************************************************************
  47. * Includes
  48. *******************************************************************************
  49. */
  50. #include "gl.h"
  51. #include "platform.h"
  52. #include "glState.h"
  53. #include "glTex.h"
  54. #include "buffers.h"
  55. #include "texfglstate.h"
  56. #include "glFimg.h"
  57. //#include "pixel.h"
  58. #include "ustl.h"
  59. /*
  60. *******************************************************************************
  61. * Macro definitions and enumerations
  62. *******************************************************************************
  63. */
  64. #define TEX_2D_DEFAULT (MAX_TEXTURE_OBJECTS)
  65. #define TEX_3D_DEFAULT (TEX_2D_DEFAULT + 1)
  66. #define TEX_CUBE_MAP_DEFAULT (TEX_3D_DEFAULT + 1)
  67. #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
  68. #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
  69. /*
  70. *******************************************************************************
  71. * Type, Structure & Class Definitions
  72. *******************************************************************************
  73. */
  74. /*
  75. *******************************************************************************
  76. * Global Variables
  77. *******************************************************************************
  78. */
  79. /*
  80. *******************************************************************************
  81. * Local Function Declarations
  82. *******************************************************************************
  83. */
  84. //static GLint GetTextureObject (OGLState* pState, GLenum target);
  85. static GLenum checkTextureFormat (OGLState* pState, GLenum internalFormat, GLenum format);
  86. static inline GLboolean IsPowerOf2 (GLuint n);
  87. static bool s3tcCompressedTex(GLenum& texformat,GLenum internalformat,GLsizei width,GLsizei height,GLsizei imageSize);
  88. static GLboolean CheckFormatConversion(GLenum dstFormat, GLenum srcFormat, GLenum* dstType);
  89. /*
  90. *******************************************************************************
  91. * Function Definitions
  92. *******************************************************************************
  93. */
  94. static void decodePalette4(const void *data, int level, int width, int height,
  95. void *surface, int stride, int format)
  96. {
  97. int indexBits = 8;
  98. int entrySize = 0;
  99. switch (format) {
  100. case GL_PALETTE4_RGB8_OES:
  101. indexBits = 4;
  102. /* FALLTHROUGH */
  103. case GL_PALETTE8_RGB8_OES:
  104. entrySize = 3;
  105. break;
  106. case GL_PALETTE4_RGBA8_OES:
  107. indexBits = 4;
  108. /* FALLTHROUGH */
  109. case GL_PALETTE8_RGBA8_OES:
  110. entrySize = 4;
  111. break;
  112. case GL_PALETTE4_R5_G6_B5_OES:
  113. case GL_PALETTE4_RGBA4_OES:
  114. case GL_PALETTE4_RGB5_A1_OES:
  115. indexBits = 4;
  116. /* FALLTHROUGH */
  117. case GL_PALETTE8_R5_G6_B5_OES:
  118. case GL_PALETTE8_RGBA4_OES:
  119. case GL_PALETTE8_RGB5_A1_OES:
  120. entrySize = 2;
  121. break;
  122. }
  123. const int paletteSize = (1 << indexBits) * entrySize;
  124. unsigned char const* pixels = (unsigned char *)data + paletteSize;
  125. for (int i=0 ; i<level ; i++) {
  126. int w = (width >> i) ? : 1;
  127. int h = (height >> i) ? : 1;
  128. pixels += h * ((w * indexBits) / 8);
  129. }
  130. width = (width >> level) ? : 1;
  131. height = (height >> level) ? : 1;
  132. if (entrySize == 2) {
  133. unsigned char const* const palette = (unsigned char*)data;
  134. for (int y=0 ; y<height ; y++) {
  135. unsigned char* p = (unsigned char*)surface + y*stride*2;
  136. if (indexBits == 8) {
  137. for (int x=0 ; x<width ; x++) {
  138. int index = 2 * (*pixels++);
  139. *p++ = palette[index + 0];
  140. *p++ = palette[index + 1];
  141. }
  142. } else {
  143. for (int x=0 ; x<width ; x+=2) {
  144. int v = *pixels++;
  145. int index = 2 * (v >> 4);
  146. *p++ = palette[index + 0];
  147. *p++ = palette[index + 1];
  148. if (x+1 < width) {
  149. index = 2 * (v & 0xF);
  150. *p++ = palette[index + 0];
  151. *p++ = palette[index + 1];
  152. }
  153. }
  154. }
  155. }
  156. } else if (entrySize == 3) {
  157. unsigned char const* const palette = (unsigned char*)data;
  158. for (int y=0 ; y<height ; y++) {
  159. unsigned char* p = (unsigned char*)surface + y*stride*3;
  160. if (indexBits == 8) {
  161. for (int x=0 ; x<width ; x++) {
  162. int index = 3 * (*pixels++);
  163. *p++ = palette[index + 0];
  164. *p++ = palette[index + 1];
  165. *p++ = palette[index + 2];
  166. }
  167. } else {
  168. for (int x=0 ; x<width ; x+=2) {
  169. int v = *pixels++;
  170. int index = 3 * (v >> 4);
  171. *p++ = palette[index + 0];
  172. *p++ = palette[index + 1];
  173. *p++ = palette[index + 2];
  174. if (x+1 < width) {
  175. index = 3 * (v & 0xF);
  176. *p++ = palette[index + 0];
  177. *p++ = palette[index + 1];
  178. *p++ = palette[index + 2];
  179. }
  180. }
  181. }
  182. }
  183. } else if (entrySize == 4) {
  184. unsigned char const* const palette = (unsigned char*)data;
  185. for (int y=0 ; y<height ; y++) {
  186. unsigned char* p = (unsigned char*)surface + y*stride*4;
  187. if (indexBits == 8) {
  188. for (int x=0 ; x<width ; x++) {
  189. int index = 4 * (*pixels++);
  190. *p++ = palette[index + 0];
  191. *p++ = palette[index + 1];
  192. *p++ = palette[index + 2];
  193. *p++ = palette[index + 3];
  194. }
  195. } else {
  196. for (int x=0 ; x<width ; x+=2) {
  197. int v = *pixels++;
  198. int index = 4 * (v >> 4);
  199. *p++ = palette[index + 0];
  200. *p++ = palette[index + 1];
  201. *p++ = palette[index + 2];
  202. *p++ = palette[index + 3];
  203. if (x+1 < width) {
  204. index = 4 * (v & 0xF);
  205. *p++ = palette[index + 0];
  206. *p++ = palette[index + 1];
  207. *p++ = palette[index + 2];
  208. *p++ = palette[index + 3];
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. #if 1
  216. GLboolean getTextureNames( SharedTextureState* pSharedTexState ,GLsizei n, GLuint *textures)
  217. {
  218. GLuint lastValue = 1;
  219. GLsizei toAssign = n;
  220. int (* unusedValueRange)[2]=NULL; // The first element will store the starting unused name (not present in the set) and the second element will store the range
  221. unusedValueRange = (int(*)[2])Plat::malloc ( 2*sizeof(int));
  222. int index = 0 ;
  223. //right from the beginning to the end of the set there might be unused value , to assign these value first
  224. TexNameSet::iterator it = pSharedTexState->usedTexNames.begin();
  225. while(it != pSharedTexState->usedTexNames.end()){
  226. //if the values are not equal it means atleast 1 value is missing
  227. if(*it == lastValue){
  228. it++;
  229. lastValue++;
  230. }
  231. else{ //storing the unused name and the range
  232. GLsizei noOfConsecUnusedValue = *it - lastValue; //the no of unused name(not present in the set)
  233. unusedValueRange[index][0] = lastValue;
  234. unusedValueRange[index][1] = noOfConsecUnusedValue;
  235. index++;
  236. unusedValueRange = (int(*)[2])Plat::realloc(unusedValueRange, 2*(index+1)*sizeof(int));
  237. lastValue = lastValue + noOfConsecUnusedValue;
  238. }
  239. }
  240. //inserting the unused name in the set
  241. for(GLsizei var = 0; var < index; var++)
  242. {
  243. for (GLsizei count = 0; count < unusedValueRange[var][1] ; count++)
  244. {
  245. *textures++ = unusedValueRange[var][0];
  246. toAssign--;
  247. pSharedTexState->usedTexNames.insert(unusedValueRange[var][0]);
  248. unusedValueRange[var][0]++;
  249. if (toAssign == 0)
  250. {
  251. free(unusedValueRange);
  252. return GL_TRUE;
  253. }
  254. }
  255. }
  256. //some texture might be left to be assigned
  257. for( ; toAssign > 0 ; toAssign--){
  258. *textures++ = lastValue;
  259. pSharedTexState->usedTexNames.insert(lastValue);
  260. lastValue++;
  261. }
  262. Plat::safe_free(unusedValueRange);
  263. return GL_TRUE;
  264. }
  265. #else
  266. GLboolean getTextureNames( SharedTextureState* pSharedTexState ,GLsizei n, GLuint *textures)
  267. {
  268. GLuint lastValue = 1;
  269. GLsizei toAssign = n;
  270. TexNameSet::iterator it = pSharedTexState->usedTexNames.begin();
  271. //right from the beginning to the end of the set there might be unused value , to assign these value first
  272. while(it != pSharedTexState->usedTexNames.end()){
  273. //if the values are not equal it means atleast 1 value is missing
  274. if(*it == lastValue){
  275. lastValue ++ ;
  276. it++;
  277. }else{
  278. GLsizei noOfValue = *it - lastValue; //the no of unused name(not present in the set)
  279. for( GLsizei count = 0; count < noOfValue ; count++){
  280. *textures++ = lastValue;
  281. toAssign --;
  282. pSharedTexState->usedTexNames.insert(lastValue);
  283. lastValue++;
  284. if(toAssign == 0) return GL_TRUE;
  285. }
  286. }
  287. }
  288. //some texture might be left to be assigned
  289. for( ; toAssign > 0 ; toAssign--){
  290. *textures++ = lastValue;
  291. pSharedTexState->usedTexNames.insert(lastValue);
  292. lastValue++;
  293. }
  294. return GL_TRUE;
  295. }
  296. #endif
  297. static
  298. void deleteTexImage(TextureObject* pTexObj )
  299. {
  300. Image *pImgObj = NULL;
  301. switch(pTexObj->texType)
  302. {
  303. case GL_TEXTURE_2D:
  304. for(int i = 0; i < MAX_MIPMAP_LEVELS; i++)
  305. {
  306. pImgObj = &(pTexObj->images.tex2D[i]);
  307. if(pImgObj->hImgChunk != NULL){
  308. pCA->Free(pImgObj->hImgChunk);
  309. pImgObj->hImgChunk = NULL;
  310. pImgObj->imagedataLocation = NONE;
  311. }
  312. //Resetting the values of the image structure.
  313. pImgObj->imgSize = 0;
  314. pImgObj->isUsed = GL_FALSE;
  315. pImgObj->width = 0;
  316. pImgObj->height = 0;
  317. pImgObj->depth = 0;
  318. //not needed added just to be sure
  319. pImgObj->internalFormat = GLenum(-1);
  320. pImgObj->PixType = GLenum(-1);
  321. pImgObj->nativeFormat = E_INVALID_PIXEL_FORMAT;
  322. pImgObj->isCompressed = GL_FALSE;
  323. }
  324. break;
  325. case GL_TEXTURE_CUBE_MAP:
  326. for(int j = 0 ; j < 6; j++)
  327. for(int i = 0; i < MAX_MIPMAP_LEVELS; i++)
  328. {
  329. pImgObj = &(pTexObj->images.cubeMap[j][i]);
  330. if(pImgObj->hImgChunk != NULL){
  331. pCA->Free(pImgObj->hImgChunk);
  332. pImgObj->hImgChunk = NULL;
  333. pImgObj->imagedataLocation = NONE;
  334. }
  335. //Resetting the values of the image structure.
  336. pImgObj->imgSize = 0;
  337. pImgObj->isUsed = GL_FALSE;
  338. pImgObj->width = 0;
  339. pImgObj->height = 0;
  340. pImgObj->depth = 0;
  341. //not needed added just to be sure
  342. pImgObj->internalFormat = GLenum(-1);
  343. pImgObj->PixType = GLenum(-1);
  344. pImgObj->nativeFormat = E_INVALID_PIXEL_FORMAT;
  345. pImgObj->isCompressed = GL_FALSE;
  346. }
  347. break;
  348. case GL_TEXTURE_3D:
  349. for(int i = 0; i < MAX_MIPMAP_LEVELS; i++)
  350. {
  351. pImgObj = &(pTexObj->images.tex3D[i]);
  352. if(pImgObj->hImgChunk != NULL){
  353. pCA->Free(pImgObj->hImgChunk);
  354. pImgObj->hImgChunk = NULL;
  355. pImgObj->imagedataLocation = NONE;
  356. }
  357. //Resetting the values of the image structure.
  358. pImgObj->imgSize = 0;
  359. pImgObj->isUsed = GL_FALSE;
  360. pImgObj->width = 0;
  361. pImgObj->height = 0;
  362. pImgObj->depth = 0;
  363. //not needed added just to be sure
  364. pImgObj->internalFormat = GLenum(-1);
  365. pImgObj->PixType = GLenum(-1);
  366. pImgObj->nativeFormat = E_INVALID_PIXEL_FORMAT;
  367. pImgObj->isCompressed = GL_FALSE;
  368. }
  369. break;
  370. }
  371. }
  372. inline
  373. void transferImageFromTexChunckToImageChunck(TextureObject* pTexObj)
  374. {
  375. Image *pImgObj = NULL;
  376. GLubyte* pImgBuf = NULL;
  377. if(pTexObj->texType == GL_TEXTURE_2D){
  378. int bpp =0;
  379. if(pTexObj->images.tex2D[0].isCompressed == false) bpp = pixelSize(pTexObj->nativeFormat); //TO DO ONCE SURE HOW THE MIPMAPPED COMPRESSED IMAGE ARE DEALT
  380. GLubyte* texObjImagedata = (GLubyte*) pTexObj->hChunk->GetVirtAddr();
  381. for(int level = 0; level < pTexObj->levels; level++) {
  382. pImgObj = &(pTexObj->images.tex2D[level]);
  383. pImgObj->hImgChunk = pCA->New(pImgObj->imgSize);
  384. if(pImgObj->hImgChunk == NULL || (pImgBuf = (GLubyte*) pImgObj->hImgChunk->GetVirtAddr()) == NULL)
  385. {
  386. //LOGMSG("OUT OF MEMORY \n");
  387. return ;
  388. }
  389. Plat::memcpy( pImgBuf, texObjImagedata+ pTexObj->Offsets[level] * bpp, pImgObj->imgSize );
  390. pImgObj->imagedataLocation = IMAGECHUNK;
  391. pTexObj->Offsets[level] = 0;
  392. }
  393. pCA->Free(pTexObj->hChunk);
  394. pTexObj->hChunk = NULL;
  395. pTexObj->levels = 0;
  396. texObjImagedata = NULL;
  397. }else if(pTexObj->texType == GL_TEXTURE_3D){
  398. int bpp = pixelSize(pTexObj->nativeFormat);
  399. GLubyte* texObjImagedata = (GLubyte*) pTexObj->hChunk->GetVirtAddr();
  400. for(int level = 0; level < pTexObj->levels; level++) {
  401. Image* pImageObj= &(pTexObj->images.tex3D[level]);
  402. pImageObj->hImgChunk = pCA->New( pImageObj->imgSize);
  403. if(pImageObj->hImgChunk == NULL || (pImgBuf = (GLubyte*) pImageObj->hImgChunk->GetVirtAddr()) == NULL)
  404. {
  405. //LOGMSG("OUT OF MEMORY \n");
  406. return ;
  407. }
  408. Plat::memcpy( pImgBuf, texObjImagedata+ pTexObj->Offsets[level] * bpp, pImgObj->imgSize );
  409. pTexObj->Offsets[level] = 0;
  410. pImgObj->imagedataLocation = IMAGECHUNK;
  411. pImageObj = NULL;
  412. }
  413. pCA->Free(pTexObj->hChunk);
  414. pTexObj->hChunk = NULL;
  415. pTexObj->levels = 0;
  416. texObjImagedata = NULL;
  417. }else if(pTexObj->texType == GL_TEXTURE_CUBE_MAP){
  418. int faceOffset = pTexObj->Offsets[pTexObj->levels - 1] + 1 * 1 ;
  419. int bpp = pixelSize(pTexObj->nativeFormat);
  420. GLubyte* texObjImagedata = (GLubyte*) pTexObj->hChunk->GetVirtAddr();
  421. for(int faceNo = 0; faceNo < 6; faceNo++){
  422. for(int level = 0; level < pTexObj->levels; level++){
  423. Image* pImageObj= &(pTexObj->images.cubeMap[faceNo][level]);
  424. pImageObj->hImgChunk = pCA->New(pImageObj->imgSize);
  425. if(pImageObj->hImgChunk == NULL || (pImgBuf = (GLubyte*) pImageObj->hImgChunk->GetVirtAddr()) == NULL)
  426. {
  427. //LOGMSG("OUT OF MEMORY \n");
  428. return ;
  429. }
  430. Plat::memcpy( pImgBuf, texObjImagedata + (faceOffset * faceNo + pTexObj->Offsets[level]) * bpp, pImageObj->imgSize );
  431. pTexObj->Offsets[level] = 0;
  432. pImgObj->imagedataLocation = IMAGECHUNK;
  433. pImageObj = NULL;
  434. }
  435. }
  436. pCA->Free(pTexObj->hChunk);
  437. pTexObj->hChunk = NULL;
  438. pTexObj->levels = 0;
  439. texObjImagedata = NULL;
  440. }
  441. }
  442. //called by glCopyTex* and glTex* function. If needed memory can be allocated
  443. GLubyte* getImageDataLocation(TextureObject* pTexObj,GLint level , GLint faceNo, GLint width , GLint height ,int depth ,GLenum format, GLenum type, GLint imgSize , GLint isExt)
  444. {
  445. Image *pImgObj = NULL;
  446. GLubyte* pImgBuf = NULL;
  447. int newDepth =1;
  448. if(depth != 0) newDepth =depth; //for 3D
  449. //get the pointer to the image structure
  450. if(pTexObj->texType == GL_TEXTURE_2D){
  451. pImgObj = &(pTexObj->images.tex2D[level]);
  452. }else if(pTexObj->texType == GL_TEXTURE_3D){
  453. pImgObj = &(pTexObj->images.tex3D[level]);
  454. }else if(pTexObj->texType == GL_TEXTURE_CUBE_MAP){
  455. pImgObj = &(pTexObj->images.cubeMap[faceNo][level]);
  456. }else{
  457. gAssert(false && "undetermined texture format in function getImageDataLocation");
  458. return NULL;
  459. }
  460. //if previous was externally managed texture
  461. if(pTexObj->isExtTex == GL_TRUE){
  462. pTexObj->releaseMem();
  463. pTexObj->images.tex2D[0].imagedataLocation = NONE;
  464. }
  465. //if external managed tex image: then delete all the previous mipmap level
  466. if(isExt == GL_TRUE){
  467. pTexObj->releaseMem();
  468. deleteTexImage(pTexObj);
  469. return NULL;
  470. }
  471. //if the image data is NULL(i.e. not present in imagechunk or tex object chunck)
  472. if(pImgObj->imagedataLocation == NONE){
  473. pImgObj->hImgChunk = pCA->New(imgSize);
  474. if(pImgObj->hImgChunk == NULL || (pImgBuf = (GLubyte*) pImgObj->hImgChunk->GetVirtAddr()) == NULL)
  475. {
  476. // SET_ERR(pState, GL_OUT_OF_MEMORY, "glTexImage2D");
  477. return NULL;
  478. }else{
  479. pImgObj->imagedataLocation = IMAGECHUNK;
  480. pTexObj->reCompile = GL_TRUE;
  481. return pImgBuf;
  482. }
  483. }
  484. //if the image is present in the texture chunk .
  485. if(pImgObj->imagedataLocation == TEXOBJCHUNK){
  486. //if texture format, width , heigth , depth are same then we can use the texture chunk memory itself
  487. if((pImgObj->internalFormat == format) && (pImgObj->PixType == type) &&
  488. (pImgObj->width == width) && (pImgObj->height == height) && (pImgObj->depth == depth)){
  489. if(pImgObj->isCompressed == false){
  490. int bpp = GetPixelSize(format, type); //of the format specified for the current gldrawCall
  491. unsigned int faceOffset = (pTexObj->Offsets[pTexObj->levels - 1]) + 1 * 1;
  492. return(((GLubyte*)( pTexObj->hChunk->GetVirtAddr())) +(faceNo* faceOffset * bpp) + (pTexObj->Offsets[level] * bpp));
  493. }else{
  494. //TO DO ONCE SURE HOW THE MIPMAPPED COMPRESSED IMAGE ARE DEALT
  495. return(GLubyte*)( pTexObj->hChunk->GetVirtAddr()) ;
  496. }
  497. }else{
  498. //spill back the texture image from texture chunk to the image chunk
  499. transferImageFromTexChunckToImageChunck(pTexObj);
  500. }
  501. }
  502. //if the image is present in the image chunk .This can even happen when the image has been transfered from texture chunk to image chunck ( above)
  503. if(pImgObj->imagedataLocation == IMAGECHUNK){
  504. //if image size are same we can use the same image chunk memory location //TO DO WRONG
  505. if( pImgObj->imgSize == imgSize){
  506. pTexObj->reCompile = GL_TRUE;
  507. return ((GLubyte* )pImgObj->hImgChunk->GetVirtAddr());
  508. }else{
  509. //free the previous image data and then allocate the new one
  510. pCA->Free(pImgObj->hImgChunk);
  511. pImgObj->hImgChunk = NULL;
  512. pImgObj->hImgChunk = pCA->New(imgSize);
  513. if(pImgObj->hImgChunk == NULL || (pImgBuf = (GLubyte*) pImgObj->hImgChunk->GetVirtAddr()) == NULL) {
  514. //LOGMSG("OUT OF MEMORY \n");
  515. return NULL;
  516. }else{
  517. pTexObj->reCompile = GL_TRUE;
  518. return pImgBuf;
  519. }
  520. }
  521. }
  522. //LOGMSG(" should not have reached the end of the function :getImageDataLocation \n") ;
  523. return NULL;
  524. }
  525. //called by glTexSub* glCopyTexSub* function.As the memry has to be already allocated need to return the pointer
  526. GLubyte* getImageDataLocation(TextureObject* pTexObj, Image *pImgObj , GLint level , GLint faceNo)
  527. {
  528. if(pImgObj->imagedataLocation == NONE){
  529. gAssert(false && "subimage called but memory not allocated : an errror \n");
  530. }else if(pImgObj->imagedataLocation == TEXOBJCHUNK){
  531. if(pImgObj->isCompressed == false){
  532. int bpp = pixelSize(pTexObj->nativeFormat );
  533. unsigned int faceOffset = (pTexObj->Offsets[pTexObj->levels - 1]) + 1 * 1;
  534. return(((GLubyte*)( pTexObj->hChunk->GetVirtAddr())) +(faceNo* faceOffset * bpp) + (pTexObj->Offsets[level] * bpp));
  535. }else{
  536. //TO DO ONCE SURE HOW THE MIPMAPPED COMPRESSED IMAGE ARE DEALT
  537. return(GLubyte*)( pTexObj->hChunk->GetVirtAddr()) ;
  538. }
  539. }else if(pImgObj->imagedataLocation == IMAGECHUNK){
  540. return ((GLubyte* )pImgObj->hImgChunk->GetVirtAddr());
  541. }
  542. return NULL;
  543. }
  544. GLboolean isMipmapFilter(GLenum minFilter)
  545. {
  546. if((minFilter == GL_LINEAR) || (minFilter == GL_NEAREST)){
  547. return GL_FALSE;
  548. }else if((minFilter == GL_NEAREST_MIPMAP_NEAREST) ||(minFilter == GL_LINEAR_MIPMAP_NEAREST)
  549. || (minFilter == GL_NEAREST_MIPMAP_LINEAR ) || (minFilter == GL_LINEAR_MIPMAP_LINEAR)){
  550. return GL_TRUE;
  551. }else{
  552. gAssert(false && "undetermined mimfilter in function isMipmapFilter \n");
  553. return GL_TRUE;
  554. }
  555. }
  556. /*
  557. *******************************************************************************
  558. * OpenGL API functions
  559. *******************************************************************************
  560. */
  561. /*-----------------------------------------------------------------------*//*!
  562. * OpenGL active texture function.
  563. *
  564. * This function sets the active texture unit in texture state. The steps
  565. * performed are:
  566. * - Sanity checks and Set error.
  567. * - Store the index to active texture unit.
  568. *
  569. *//*------------------------------------------------------------------------*/
  570. GL_API void GL_APIENTRY
  571. glActiveTexture (GLenum texture)
  572. {
  573. OGLState* pState = GET_OGL_STATE();
  574. TextureState* pTexState = &(pState->texState);
  575. // Sanity checks and error reporting
  576. if(texture < GL_TEXTURE0 || texture >= (GL_TEXTURE0 + MAX_TEXTURE_UNITS)){
  577. SET_ERR(pState, GL_INVALID_OPERATION, "glActiveTexture");
  578. return;
  579. }
  580. // Store the index to texture unit
  581. pTexState->activeTexUnit = texture - GL_TEXTURE0;
  582. }
  583. /*-----------------------------------------------------------------------*//*!
  584. * OpenGL generate textures function.
  585. *
  586. * This function finds the free texture names and sets it in the pointer passed.
  587. * The steps performed are:
  588. * - Search the object array for free texture names and store as required.
  589. * - Record error if we don't find enough free texture names.
  590. *
  591. *//*------------------------------------------------------------------------*/
  592. GL_API void GL_APIENTRY
  593. glGenTextures (GLsizei n, GLuint *textures)
  594. {
  595. OGLState* pState = GET_OGL_STATE();
  596. SharedTextureState* psharedTexState = &(pState->sharedState->sharedTexState);
  597. GLuint *texID = textures;
  598. // Validate parameters
  599. if(n < 0 || textures == NULL){
  600. SET_ERR(pState, GL_INVALID_VALUE, "glGenTextures");
  601. return;
  602. }
  603. // Search in the object array for free textures
  604. // Texture 0 is default texture. Skip it.
  605. #if 1
  606. lockGLSharedTextureState(pState);
  607. if(getTextureNames(psharedTexState,n,textures) != GL_TRUE)
  608. {
  609. //this case is not expected to be reached
  610. SET_ERR(pState, GL_OUT_OF_MEMORY, "glGenTextures");
  611. }
  612. unlockGLSharedTextureState( pState);
  613. #else
  614. for(i = 1; i < MAX_TEXTURE_OBJECTS; i++) {
  615. if((pTexState->texObjects[i]).isUsed == GL_FALSE) {
  616. *(textures + j) = i;
  617. j++;
  618. if(j >= n) return; // We got all we wanted
  619. }
  620. }
  621. // We couldn't find the required no of free textures
  622. SET_ERR(pState, GL_OUT_OF_MEMORY, "glGenTextures");
  623. #endif
  624. while(n--)
  625. {
  626. while(psharedTexState->texObjects.count(*texID) > 0)
  627. psharedTexState->texObjects.erase(*texID);
  628. texID++;
  629. }
  630. return;
  631. }
  632. /*-----------------------------------------------------------------------*//*!
  633. * OpenGL bind texture function.
  634. *
  635. * This function creates or re-use texture objects and binds them to current
  636. * texture. The steps followed are:
  637. * - Validate input parameters.
  638. * - Check if texture object referenced is already in use. Create new object
  639. * if required.
  640. * - Check type if object already exists and raise error on mismatch. If the
  641. * texture referenced is default texture then type change will re-initialize
  642. * the default texture.
  643. *
  644. *//*------------------------------------------------------------------------*/
  645. GL_API void GL_APIENTRY
  646. glBindTexture (GLenum target, GLuint texture)
  647. {
  648. OGLState* pState = GET_OGL_STATE();
  649. TextureState* pTexState = &(pState->texState);
  650. SharedTextureState* pSharedTexState = &(pState->sharedState->sharedTexState);
  651. GLint texRef;
  652. GLuint currentUnit = pTexState->activeTexUnit;//sanvd added this
  653. TextureObject* lastTexObj = NULL;
  654. TextureObject *pTexObj;
  655. CurrentTexture *currTex = &pTexState->texUnitBinding[currentUnit];
  656. // -----------------------------------------------------------------------
  657. // Validate input parameters
  658. // -----------------------------------------------------------------------
  659. if(!(target == GL_TEXTURE_2D || target == GL_TEXTURE_3D || target == GL_TEXTURE_CUBE_MAP)){
  660. SET_ERR(pState, GL_INVALID_ENUM, "glBindTexture");
  661. return;
  662. }
  663. // -----------------------------------------------------------------------
  664. // Handle texture 0 special case
  665. // -----------------------------------------------------------------------
  666. lockGLSharedTextureState(pState);
  667. if(texture == 0) {
  668. // Texture zero has 3 different objects associated with it. One each
  669. // for different targets.
  670. switch(target) {
  671. case GL_TEXTURE_2D:
  672. //texRef = TEX_2D_DEFAULT;
  673. if(currTex->texture2D != 0){
  674. lastTexObj = GetTextureObject( target, false , 0);
  675. lastTexObj->release(pState);
  676. lastTexObj = NULL;
  677. }
  678. currTex->texture2D = texture;
  679. #if STORE_TEX_OBJ_POINTER == ENABLE
  680. pTexState->ptexUnitBinding[currentUnit].texture2D = &(pTexState->defaultTexObjects[TEX_2D_DEFAULT -TEX_2D_DEFAULT]);
  681. #endif
  682. break;
  683. case GL_TEXTURE_3D:
  684. //texRef = TEX_3D_DEFAULT;
  685. if(currTex->texture3D != 0){
  686. lastTexObj = GetTextureObject( target, false , 0);
  687. lastTexObj->release(pState);
  688. lastTexObj = NULL;
  689. }
  690. currTex->texture3D = texture;
  691. #if STORE_TEX_OBJ_POINTER == ENABLE
  692. pTexState->ptexUnitBinding[currentUnit].texture3D = &(pTexState->defaultTexObjects[TEX_3D_DEFAULT -TEX_2D_DEFAULT]);
  693. #endif
  694. break;
  695. case GL_TEXTURE_CUBE_MAP:
  696. //texRef = TEX_CUBE_MAP_DEFAULT;
  697. if(currTex->cubeMap != 0){
  698. lastTexObj = GetTextureObject( target, false , 0);
  699. lastTexObj->release(pState);
  700. lastTexObj = NULL;
  701. }
  702. currTex->cubeMap = texture;
  703. #if STORE_TEX_OBJ_POINTER == ENABLE
  704. pTexState->ptexUnitBinding[currentUnit].cubeMap = &(pTexState->defaultTexObjects[TEX_CUBE_MAP_DEFAULT -TEX_2D_DEFAULT]);
  705. #endif
  706. break;
  707. }
  708. //default textures are not shared
  709. // -----------------------------------------------------------------------
  710. // Handle other textures
  711. // -----------------------------------------------------------------------
  712. }
  713. else
  714. {
  715. texRef = GetTexNameArrayIndex(texture,false);
  716. if(texRef ==-1){
  717. SET_ERR(pState, GL_INVALID_VALUE, "glBindTexture");
  718. unlockGLSharedTextureState(pState);
  719. return;
  720. }
  721. // New texture object
  722. pTexObj = pSharedTexState->texObjects[texRef];
  723. if(pTexObj != NULL)
  724. {
  725. if(pTexObj->isUsed != GL_TRUE) {
  726. // Initialize, mark used
  727. pTexObj->Init(texture, target);
  728. //reaching inside the loop means that this is the first time the texture has been called by glBindTexture
  729. // so it might have been called using the glGenTexture or without it
  730. //this if condition can be removed as set contain only 1 copy of the value
  731. if(pSharedTexState->usedTexNames.count(texture) == 0){
  732. pSharedTexState->usedTexNames.insert(texture);
  733. }
  734. // Texture object reuse
  735. } else if(pTexObj->texType != target){
  736. // Raise error if type mismatches
  737. SET_ERR(pState, GL_INVALID_OPERATION, "glBindTexture");
  738. unlockGLSharedTextureState(pState);
  739. return;
  740. }
  741. // for reference count of the texture objects
  742. // & Store current texture value
  743. switch(target) {
  744. case GL_TEXTURE_2D:
  745. if(currTex->texture2D != texture)
  746. {
  747. if(currTex->texture2D != 0){
  748. lastTexObj = GetTextureObject( target, false , 0);
  749. lastTexObj->release(pState);
  750. lastTexObj = NULL;
  751. }
  752. pTexObj->acquire(pState);
  753. currTex->texture2D = texture;
  754. #if STORE_TEX_OBJ_POINTER == ENABLE
  755. pTexState->ptexUnitBinding[currentUnit].texture2D = (pSharedTexState->texObjects[texRef]);
  756. #endif
  757. }
  758. break;
  759. case GL_TEXTURE_3D:
  760. if(currTex->texture3D != texture){
  761. if(currTex->texture3D != 0){
  762. lastTexObj = GetTextureObject( target, false , 0);
  763. lastTexObj->release(pState);
  764. lastTexObj = NULL;
  765. }
  766. pTexObj->acquire(pState);
  767. currTex->texture3D = texture;
  768. #if STORE_TEX_OBJ_POINTER == ENABLE
  769. pTexState->ptexUnitBinding[currentUnit].texture3D = (pSharedTexState->texObjects[texRef]);
  770. #endif
  771. }
  772. break;
  773. case GL_TEXTURE_CUBE_MAP:
  774. if(currTex->cubeMap != texture){
  775. if(currTex->cubeMap != 0){
  776. lastTexObj = GetTextureObject( target, false , 0);
  777. lastTexObj->release(pState);
  778. lastTexObj = NULL;
  779. }
  780. pTexObj->acquire(pState);
  781. currTex->cubeMap = texture;
  782. #if STORE_TEX_OBJ_POINTER == ENABLE
  783. pTexState->ptexUnitBinding[currentUnit].cubeMap = (pSharedTexState->texObjects[texRef]);
  784. #endif
  785. }
  786. break;
  787. };
  788. }
  789. }
  790. unlockGLSharedTextureState(pState);
  791. #if 0
  792. // -----------------------------------------------------------------------
  793. // Store current texture value
  794. // -----------------------------------------------------------------------
  795. switch(target) {
  796. case GL_TEXTURE_2D:
  797. pTexState->texUnitBinding[currentUnit].texture2D = texture;
  798. break;
  799. case GL_TEXTURE_3D:
  800. pTexState->texUnitBinding[currentUnit].texture3D = texture;
  801. break;
  802. case GL_TEXTURE_CUBE_MAP:
  803. pTexState->texUnitBinding[currentUnit].cubeMap = texture;
  804. break;
  805. };
  806. #endif
  807. }
  808. /*-----------------------------------------------------------------------*//*!
  809. * OpenGL delete texture function.
  810. *//*------------------------------------------------------------------------*/
  811. GL_API void GL_APIENTRY
  812. glDeleteTextures (GLsizei n, const GLuint *textures)
  813. {
  814. OGLState* pState = GET_OGL_STATE();
  815. TextureState* pTexState = &(pState->texState);
  816. GLuint currentUnit = pTexState->activeTexUnit;
  817. int i = 0 ; //for count of the no of texture unit
  818. // Validate parameters
  819. if(n < 0 || textures == NULL){
  820. SET_ERR(pState, GL_INVALID_VALUE, "glDeleteTextures");
  821. return;
  822. }
  823. lockGLSharedTextureState(pState);
  824. while(n--){
  825. if(*textures == 0){
  826. continue; //silently ignore 0
  827. }
  828. GLint texRef = GetTexNameArrayIndex(*textures,false);//only delete userdefined tex objects..operation is heavy.....O( n )
  829. SharedTextureState *pSTState = &(pState->sharedState->sharedTexState);
  830. TextureObject* pTexObj = pSTState->texObjects[texRef];
  831. if((texRef == -1) || (pTexObj->isUsed == GL_FALSE))//it means that texture is not found in the list and that textureObject array is fulluy populated...
  832. //if((texRef == -1) || (pState->sharedState->sharedTexState.texObjects[texRef]->isUsed == GL_FALSE))//it means that texture is not found in the list and that textureObject array is fulluy populated...
  833. {
  834. //Sandeep K. spec says silently ignore 0 and invalid texture names
  835. //SET_ERR(pState, GL_INVALID_VALUE, "glDeleteTexture");
  836. // unlockGLSharedTextureState(pState);
  837. //return;
  838. continue; //it should try tio delete the other texture object
  839. }
  840. //check the reference count before deleting
  841. //the reference count need to be decreased for all the texture unit that is using the f=given texture object
  842. pTexObj->deleteTexObj = GL_TRUE;
  843. switch(pTexObj->texType){
  844. case GL_TEXTURE_2D:
  845. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  846. if ((pTexObj->id == pTexState->texUnitBinding[i].texture2D)
  847. && (pTexObj->id !=0)){
  848. pTexState->texUnitBinding[i].texture2D = 0;
  849. #if STORE_TEX_OBJ_POINTER == ENABLE
  850. pTexState->ptexUnitBinding[currentUnit].texture2D =
  851. &(pTexState->defaultTexObjects[TEX_2D_DEFAULT
  852. -TEX_2D_DEFAULT]);
  853. #endif
  854. int id = pTexObj->id;
  855. pSTState->ReleaseTexObj(pState, pTexObj->id) ;
  856. }
  857. }
  858. //if the object is not bounded to any texture object
  859. if( pTexObj->id != 0 && pSTState->texObjects.count(texRef)){
  860. int id = pTexObj->id;
  861. pSTState->ReleaseTexObj(pState, pTexObj->id);
  862. }
  863. pTexObj = NULL;
  864. //pSTState->texObjects[texRef] = NULL;
  865. break;
  866. case GL_TEXTURE_3D:
  867. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  868. if ((pTexObj->id == pTexState->texUnitBinding[i].texture3D)
  869. && (pTexObj->id !=0)){
  870. pTexState->texUnitBinding[i].texture3D = 0;
  871. #if STORE_TEX_OBJ_POINTER == ENABLE
  872. pTexState->ptexUnitBinding[currentUnit].texture3D =
  873. &(pTexState->defaultTexObjects[TEX_3D_DEFAULT
  874. -TEX_2D_DEFAULT]);
  875. #endif
  876. pSTState->ReleaseTexObj(pState, pTexObj->id);
  877. }
  878. }
  879. if( pTexObj->id != 0 && pSTState->texObjects.count(texRef)){
  880. pSTState->ReleaseTexObj(pState, pTexObj->id);
  881. }
  882. pTexObj = NULL;
  883. //pSTState->texObjects[texRef] = NULL;
  884. break;
  885. case GL_TEXTURE_CUBE_MAP:
  886. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  887. if( (pTexObj->id == pTexState->texUnitBinding[i].cubeMap)
  888. && (pTexObj->id !=0)){
  889. pTexState->texUnitBinding[i].cubeMap= 0;
  890. #if STORE_TEX_OBJ_POINTER == ENABLE
  891. pTexState->ptexUnitBinding[currentUnit].cubeMap =
  892. &(pTexState->defaultTexObjects[TEX_CUBE_MAP_DEFAULT
  893. -TEX_2D_DEFAULT]);
  894. #endif
  895. pSTState->ReleaseTexObj(pState, pTexObj->id);
  896. }
  897. }
  898. if( pTexObj->id != 0 && pSTState->texObjects.count(texRef)){
  899. pSTState->ReleaseTexObj(pState, pTexObj->id);
  900. }
  901. pTexObj = NULL;
  902. //pSTState->texObjects[texRef] = NULL;
  903. break;
  904. }
  905. #if 0
  906. //need to unbound from all texture unit
  907. switch(pTexState->psharedTexObjects->ptexObjects[texRef].texType ){
  908. case GL_TEXTURE_2D:
  909. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  910. if (*textures == pTexState->texUnitBinding[i].texture2D){
  911. pTexState->texUnitBinding[i].texture2D = 0;
  912. }
  913. }
  914. break;
  915. case GL_TEXTURE_3D:
  916. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  917. if (*textures == pTexState->texUnitBinding[i].texture3D){
  918. pTexState->texUnitBinding[i].texture3D = 0;
  919. }
  920. }
  921. break;
  922. case GL_TEXTURE_CUBE_MAP:
  923. for( i =0 ; i < MAX_TEXTURE_UNITS ; i++){
  924. if (*textures == pTexState->texUnitBinding[i].cubeMap){
  925. pTexState->texUnitBinding[i].cubeMap= 0;
  926. }
  927. }
  928. break;
  929. }
  930. if(*textures == pTexState->texUnitBinding[currentUnit].texture2D)
  931. pTexState->texUnitBinding[currentUnit].texture2D = 0;
  932. if(*textures == pTexState->texUnitBinding[currentUnit].texture3D)
  933. pTexState->texUnitBinding[currentUnit].texture3D = 0;
  934. if(*textures == pTexState->texUnitBinding[currentUnit].cubeMap)
  935. pTexState->texUnitBinding[currentUnit].cubeMap= 0;
  936. // Delete texture object
  937. if(*textures != 0 && pTexState->psharedTexObjects->ptexObjects[texRef].isUsed == GL_TRUE){
  938. pTexState->psharedTexObjects->ptexObjects[texRef].Delete();
  939. }
  940. //to remove form the used texture name set
  941. if(pTexState->psharedTexObjects->usedTexNames.count(*textures) != 0){
  942. pTexState->psharedTexObjects->usedTexNames.erase(*textures);
  943. }
  944. #endif
  945. //Sandeep K.
  946. //FBO spec says that is a texture is bound to the currently bound fbo it must be detached from all attachment points
  947. // it is attached to.
  948. pState->framebuffState.detachTexture(*textures);
  949. textures++; // Next object
  950. }
  951. unlockGLSharedTextureState(pState);
  952. }
  953. /*-----------------------------------------------------------------------*//*!
  954. * OpenGL IsTexture function.
  955. *//*------------------------------------------------------------------------*/
  956. GL_API GLboolean GL_APIENTRY
  957. glIsTexture (GLuint texture)
  958. {
  959. OGLState* pState = GET_OGL_STATE();
  960. // Validate parameters
  961. if(texture >= MAX_TEXTURE_OBJECTS){
  962. SET_ERR(pState, GL_INVALID_VALUE, "glIsTexture");
  963. return GL_FALSE;
  964. }
  965. GLint texRef = GetTexNameArrayIndex(texture,false);//only checks the non-default tex objs//operation is heavy.....O( n )
  966. if(texRef == -1) //it means that texture is not found in the list and that textureObject array is fulluy populated...
  967. return GL_FALSE;
  968. if(pState->sharedState->sharedTexState.texObjects[texRef]->isUsed == GL_TRUE)
  969. return GL_TRUE;
  970. else
  971. return GL_FALSE;
  972. }
  973. /*-----------------------------------------------------------------------*//*!
  974. * OpenGL texture parameter function (int).
  975. *//*------------------------------------------------------------------------*/
  976. GL_API void GL_APIENTRY
  977. glTexParameteri (GLenum target, GLenum pname, GLint param)
  978. {
  979. OGLState* pState = GET_OGL_STATE();
  980. TextureObject* pTexObj = NULL;
  981. //GLuint texRef;
  982. //Sandeep
  983. GLenum eParam = (GLenum)(param);
  984. // Select object reference according to target
  985. // Return error on invalid enum
  986. if(target == GL_TEXTURE_2D || target == GL_TEXTURE_3D || target == GL_TEXTURE_CUBE_MAP){
  987. pTexObj = GetTextureObject(target,false,0);
  988. } else {
  989. SET_ERR(pState, GL_INVALID_ENUM, "glTexParameter*");
  990. return;
  991. }
  992. GLboolean isMipmapFilterPrevious = isMipmapFilter(pTexObj->minFilter);
  993. // Store the parameter passed in texture state
  994. // Return error on invalid enum or value
  995. switch(pname) {
  996. case GL_TEXTURE_MIN_FILTER:
  997. if((eParam == GL_LINEAR) || (eParam == GL_NEAREST) || (eParam == GL_LINEAR_MIPMAP_LINEAR)
  998. || (eParam == GL_LINEAR_MIPMAP_NEAREST) || (eParam == GL_NEAREST_MIPMAP_LINEAR) ||
  999. (eParam == GL_NEAREST_MIPMAP_NEAREST)) {
  1000. pTexObj->minFilter = eParam;
  1001. break;
  1002. } else {
  1003. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1004. return;
  1005. }
  1006. case GL_TEXTURE_MAG_FILTER:
  1007. if((eParam == GL_LINEAR) || (eParam == GL_NEAREST)){
  1008. pTexObj->magFilter = eParam;
  1009. break;
  1010. } else {
  1011. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1012. return;
  1013. }
  1014. case GL_TEXTURE_WRAP_S:
  1015. if((eParam == GL_REPEAT) || (eParam == GL_CLAMP_TO_EDGE) || (eParam == GL_MIRRORED_REPEAT)) {
  1016. pTexObj->wrapS = eParam;
  1017. break;
  1018. } else {
  1019. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1020. return;
  1021. }
  1022. case GL_TEXTURE_WRAP_T:
  1023. if((eParam == GL_REPEAT) || (eParam == GL_CLAMP_TO_EDGE) || (eParam == GL_MIRRORED_REPEAT)) {
  1024. pTexObj->wrapT = eParam;
  1025. break;
  1026. } else {
  1027. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1028. return;
  1029. }
  1030. case GL_TEXTURE_WRAP_R:
  1031. if(target != GL_TEXTURE_3D) {
  1032. SET_ERR(pState, GL_INVALID_ENUM, "glTexParameter*");
  1033. return;
  1034. }
  1035. if((eParam == GL_REPEAT) || (eParam == GL_CLAMP_TO_EDGE) || (eParam == GL_MIRRORED_REPEAT)) {
  1036. pTexObj->wrapR = eParam;
  1037. break;
  1038. } else {
  1039. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1040. return;
  1041. }
  1042. default:
  1043. SET_ERR(pState, GL_INVALID_ENUM, "glTexParameter*");
  1044. return;
  1045. };
  1046. GLboolean isMipmapFilterPresent = isMipmapFilter(pTexObj->minFilter);
  1047. if(isMipmapFilterPresent != isMipmapFilterPrevious){
  1048. pTexObj->reCompile = GL_TRUE;
  1049. }
  1050. pTexObj->isDirtyState = GL_TRUE;
  1051. }
  1052. /*-----------------------------------------------------------------------*//*!
  1053. * OpenGL texture parameter function (intv).
  1054. *
  1055. * See glTexParameteri() for details regarding glTexParameter* functions.
  1056. *
  1057. *//*------------------------------------------------------------------------*/
  1058. GL_API void GL_APIENTRY
  1059. glTexParameteriv (GLenum target, GLenum pname, const GLint *params)
  1060. {
  1061. OGLState* pState = GET_OGL_STATE();
  1062. if(params == NULL) {
  1063. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1064. } else {
  1065. //Texture OES API - 2009.05.20
  1066. //#ifndef GL_OES_draw_texture
  1067. // glTexParameteri(EXPCTX_LOCAL target, pname, *params);
  1068. //#else
  1069. if ((target == GL_TEXTURE_2D) && (pname == GL_TEXTURE_CROP_RECT_OES)){
  1070. TextureObject* pTexObj = NULL;
  1071. pTexObj = GetTextureObject(target,false,0);
  1072. // Plat::printf ("\nGL_TEXTURE_CROP_RECT_OES is called.\n");
  1073. pTexObj->crop_rect[0] = params[0];
  1074. pTexObj->crop_rect[1] = params[1];
  1075. pTexObj->crop_rect[2] = params[2];
  1076. pTexObj->crop_rect[3] = params[3];
  1077. }else{
  1078. glTexParameteri( target, pname, *params);
  1079. }
  1080. //#endif //GL_OES_draw_texture
  1081. }
  1082. }
  1083. /*-----------------------------------------------------------------------*//*!
  1084. * OpenGL texture parameter function (float).
  1085. *
  1086. * See glTexParameteri() for details regarding glTexParameter* functions.
  1087. *
  1088. *//*------------------------------------------------------------------------*/
  1089. GL_API void GL_APIENTRY
  1090. glTexParameterf (GLenum target, GLenum pname, GLfloat param)
  1091. {
  1092. glTexParameteri(target, pname, (GLint)param);
  1093. }
  1094. /*-----------------------------------------------------------------------*//*!
  1095. * OpenGL texture parameter function (floatv).
  1096. *
  1097. * See glTexParameteri() for details regarding glTexParameter* functions.
  1098. *
  1099. *//*------------------------------------------------------------------------*/
  1100. GL_API void GL_APIENTRY
  1101. glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params)
  1102. {
  1103. OGLState* pState = GET_OGL_STATE();
  1104. if(params == NULL) {
  1105. SET_ERR(pState, GL_INVALID_VALUE, "glTexParameter*");
  1106. } else {
  1107. //Tex…

Large files files are truncated, but you can click here to view the full file