# glCompressedTexImage2D problems

**URL:** <https://forums.imgtec.com/t/glcompressedteximage2d-problems/156>\
**Category:** PowerVR Insider\
**Created:** [September 29, 2008, 10:36am UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156 "2008-09-29T10:36:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jirzynek](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jirzynek](https://forums.imgtec.com/u/jirzynek)\
**Post date:** [September 29, 2008, 10:36am UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/1 "2008-09-29T10:36:37Z")

</div>

Hi!   
I've some problems with glCompressedTexImage2D function:  
  
when creating 16x16 texture with 8Bit palette  
  
**glCompressedTexImage2D(GL\_TEXTURE\_2D,0,GL\_PALETTE8\_R5\_G6\_B5\_OES,16,16,0,256 \* 2 + 16 \* 16,m);**  
  
everything is ok, but when I use 16x 16 image with 4bit palette   
  
**glCompressedTexImage2D(GL\_TEXTURE\_2D,0,GL\_PALETTE4\_R5\_G6\_B5\_OES,16,16,0,16 \* 2 + 16 \* 16, m);**  
  
where:  
**u8\* m = (u8 \*)malloc(64 \* 64 \* 4);**  
  
**data\_size = 2^PaletteBits \* sizeof(u16) + width \* height;**  
  
  
  
I've got GL error&nbsp; GL\_INVALID\_VALUE (0x0501).   
  
Second:  
  
Why this code produces error when glTexSubImage2D() is invoked  
  
&nbsp; u8\* m = (u8 \*)allocCustomHeap(128 \* 128 \* 4);  
&nbsp; GLuint tex1, tex2, tex3;  
&nbsp;GLint glerr;  
&nbsp;  
&nbsp; glGenTextures(1, &tex1);  
&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex1);  
&nbsp; glTexImage2D(GL\_TEXTURE\_2D, 0,&nbsp; GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
&nbsp; glerr = glGetError();   
  
&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex1);  
&nbsp; glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
&nbsp; glerr = glGetError();   
  
**&nbsp; glGenTextures(1, &tex2);  
&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex2);  
&nbsp; glTexImage2D(GL\_TEXTURE\_2D, 0,&nbsp; GL\_RGB, 32, 32, 0, GL\_RGB,&nbsp; GL\_UNSIGNED\_SHORT\_5\_6\_5, m);  
&nbsp; glerr = glGetError();**   
  
**&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex1);  
&nbsp; glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
&nbsp; glerr = glGetError();**   
  
&nbsp; glGenTextures(1, &tex3);  
&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex3);  
&nbsp; glTexImage2D(GL\_TEXTURE\_2D, 0,&nbsp; GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
&nbsp; glerr = glGetError();   
  
&nbsp; glBindTexture(GL\_TEXTURE\_2D, tex1);  
&nbsp; glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
&nbsp; glerr = glGetError();   
  
but when all textures has same type (GL\_RGB and GL\_UNSINGED\_BYTE) everything is ok  
SDK bug??  
  
  
please help, what Am I doing wrong?  
  
  
regards  
jirzynek  
jirzynek2008-09-29 14:04:15

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [September 30, 2008, 8:16am UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/2 "2008-09-30T08:16:52Z")

</div>

jirzynek wrote:

Code:

glCompressedTexImage2D(GL\_TEXTURE\_2D,0,GL\_PALETTE4\_R5\_G6\_B5\_OES,16,16,0,16 \* 2 + 16 \* 16, m);

  
The size should be (16 \* 2) + (16 \* 16 **/ 2** ) since you only use 4 bits per pixel not 8.  
  
  
  
What error do you get in the second case?  
  
  
  
Regards,  
  
Georg

---

<div class="post-metadata">

**Author:** ![jirzynek](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jirzynek](https://forums.imgtec.com/u/jirzynek)\
**Post date:** [September 30, 2008, 4:13pm UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/3 "2008-09-30T16:13:56Z")

</div>

I've got INVALID\_ENUM.  
  
  
check this code:  
  
**first case: no error**  
 u8\* m = (u8 \*)allocCustomHeap(128 \* 128 \* 4);  
 GLuint tex1, tex2, tex3;  
 GLint glerr;  
  
 glGenTextures(1, &tex1);  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
 // NO ERROR!!!  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
 glGenTextures(1, &tex2);  
 glBindTexture(GL\_TEXTURE\_2D, tex2);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_SHORT\_5\_6\_5, m);  
 glerr = glGetError();   
  
 glGenTextures(1, &tex3);  
 glBindTexture(GL\_TEXTURE\_2D, tex3);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
  
**second case: error, I've only moved first glTexSubImage2D after glTexImage2D for second texture.**  
  
 u8\* m = (u8 \*)allocCustomHeap(128 \* 128 \* 4);  
 GLuint tex1, tex2, tex3;  
 GLint glerr;  
   
 glGenTextures(1, &tex1);  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
  
 glGenTextures(1, &tex2);  
 glBindTexture(GL\_TEXTURE\_2D, tex2);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_SHORT\_5\_6\_5, m);  
 glerr = glGetError();   
  
// ERROR!!!  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
 glGenTextures(1, &tex3);  
 glBindTexture(GL\_TEXTURE\_2D, tex3);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
  
**3rd case (NO ERROR): All textures has same type (GL\_UNSINGED\_BYTE****):**  
 u8\* m = (u8 \*)allocCustomHeap(128 \* 128 \* 4);  
 GLuint tex1, tex2, tex3;  
 GLint glerr;  
   
 glGenTextures(1, &tex1);  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
  
 glGenTextures(1, &tex2);  
 glBindTexture(GL\_TEXTURE\_2D, tex2);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
// NO ERROR!!!  
 glBindTexture(GL\_TEXTURE\_2D, tex1);  
 glTexSubImage2D(GL\_TEXTURE\_2D, 0, 0, 0, 10, 14, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
 glGenTextures(1, &tex3);  
 glBindTexture(GL\_TEXTURE\_2D, tex3);  
 glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 32, 32, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, m);  
 glerr = glGetError();   
  
  
I think that glTexSubImage2D is using texture parameters not from currently bound   
texture but from previously created texture.  
  
Right now I'm using PC Emulation.  
  
cheers  
j.  
  
jirzynek2008-09-30 18:16:17

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [October 1, 2008, 1:49pm UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/4 "2008-10-01T13:49:28Z")

</div>

We’ll have a closer look at this. By the way, have you tried it with our latest SDK (2.3)?  
  
  
  
  
  
Regards,  
  
  
Georg

---

<div class="post-metadata">

**Author:** ![jirzynek](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jirzynek](https://forums.imgtec.com/u/jirzynek)\
**Post date:** [October 1, 2008, 2:09pm UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/5 "2008-10-01T14:09:55Z")

</div>

Xmas wrote:

We'll have a closer look at this. By the way, have you tried it with our latest SDK (2.3)?

  
  
Yes, problem still exists...  
  
cheers  
j.

---

<div class="post-metadata">

**Author:** ![GordonMaclachlan](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@GordonMaclachlan](https://forums.imgtec.com/u/GordonMaclachlan)\
**Post date:** [April 2, 2009, 8:32am UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/6 "2009-04-02T08:32:25Z")

</div>

This issue should get looked at soon - apologies for the long delay.Gordon2009-04-02 10:37:12

---

<div class="post-metadata">

**Author:** ![GordonMaclachlan](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@GordonMaclachlan](https://forums.imgtec.com/u/GordonMaclachlan)\
**Post date:** [May 8, 2009, 1:45pm UTC](https://forums.imgtec.com/t/glcompressedteximage2d-problems/156/7 "2009-05-08T13:45:01Z")

</div>

This issue has been fixed for our next release, due this summer.
