# How to specify maximum mipmap level in opengles?

**URL:** <https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625>\
**Category:** PowerVR Insider\
**Created:** [March 6, 2010, 2:13am UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625 "2010-03-06T02:13:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mashangming](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mashangming](https://forums.imgtec.com/u/mashangming)\
**Post date:** [March 6, 2010, 2:13am UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/1 "2010-03-06T02:13:12Z")

</div>

I specify the maximum mipmap level in opengl by the following code,but GL\_TEXTURE\_MAX\_LEVEL not define in opengles.  
glTexParameteri( GL\_TEXTURE\_2D, GL\_TEXTURE\_MAX\_LEVEL, maxLevel);  
  
I use mipmap function&nbsp; by the following method, but the texture does not show:  
  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR\_MIPMAP\_NEAREST);  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);  
  
glTexImage2D(GL\_TEXTURE\_2D, 0, internalFormat,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width0, height0, 0,   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; internalFormat, dataType, data0);  
glTexImage2D(GL\_TEXTURE\_2D, 1, internalFormat,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width1, height1, 0,   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; internalFormat, dataType, data1);  
glTexImage2D(GL\_TEXTURE\_2D, 2, internalFormat,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width2, height2, 0,   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; internalFormat, dataType, data2);

---

<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:** [March 8, 2010, 8:52am UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/2 "2010-03-08T08:52:36Z")

</div>

mashangming wrote:

I specify the maximum mipmap level in opengl by the following code,but GL\_TEXTURE\_MAX\_LEVEL not define in opengles.

  
Unfortunately this functionality does not exist in OpenGL ES. You have to provide a complete mipmap pyramid.

---

<div class="post-metadata">

**Author:** ![mashangming](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@mashangming](https://forums.imgtec.com/u/mashangming)\
**Post date:** [May 10, 2010, 11:47pm UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/3 "2010-05-10T23:47:11Z")

</div>

Thank you!  
I use compressed texture load each level of mipmap , when the width or high&nbsp; is less than 4 ,loading failed OpenGLES return GL\_INVALID\_VALUE.\<span id=“result\_” =“short\_text”\>Code is as follows:(level0 is 256\*256)  
  
&nbsp;&nbsp;&nbsp; glGenTextures(1, &textureID);  
  
&nbsp;&nbsp;&nbsp; if(textureID == GL\_INVALID\_VALUE)  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return NULL;  
&nbsp;&nbsp;&nbsp; }  
  
&nbsp;&nbsp;&nbsp; glBindTexture(GL\_TEXTURE\_2D , textureID );  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; if (levelCount\>1)  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR\_MIPMAP\_NEAREST);  
&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; else  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR );  
  
&nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);  
  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; GLenum dataType;  
&nbsp;&nbsp;&nbsp; GLenum internalFormat = GetGLInternalPixelFormat(format,dataType);  
  
&nbsp;&nbsp;&nbsp; width = 256;  
&nbsp;&nbsp;&nbsp; height = 256;  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; for(int mip=0; mip\<levelCount; mip++)  
&nbsp;&nbsp;&nbsp; {  
  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; glCompressedTexImage2D(GL\_TEXTURE\_2D, mip, internalFormat,  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width, height, 0,   
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pixelDataSize, pixelData);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width/=2;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width = width?1:width;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; height/=2;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; height = height?1:height;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pixelData +=pixelDataSize;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pixelDataSize/=4;  
&nbsp;&nbsp;&nbsp; }

---

<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:** [May 11, 2010, 8:06am UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/4 "2010-05-11T08:06:27Z")

</div>

With PVRTC a texture level is always at least two blocks (4x4 pixels for 4bpp, 8x4 pixels for 2bpp) wide and high. However this only affects the imageSize argument, not width and height which still go down to 1x1 for the last level.

Code:

&nbsp;&nbsp;&nbsp;&nbsp;  
if (internalFormat == GL\_COMPRESSED\_RGB\_PVRTC\_4BPPV1\_IMG ||  
&nbsp;&nbsp;&nbsp;&nbsp;internalFormat == GL\_COMPRESSED\_RGBA\_PVRTC\_4BPPV1\_IMG)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;for(int mip=0; mip\<levelCount; mip++)  
&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixelDataSize = MAX(width, 8) \* MAX(height, 8) / 2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; glCompressedTexImage2D(GL\_TEXTURE\_2D, mip, internalFormat,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width, height, 0,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixelDataSize, pixelData);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width/=2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = width?1:width;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height/=2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height = height?1:height;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixelData +=pixelDataSize;  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://forums.imgtec.com/u/kris)\
**Post date:** [November 4, 2010, 11:07pm UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/5 "2010-11-04T23:07:01Z")

</div>

Xmas wrote:

With PVRTC a texture level is always at least two blocks (4x4 pixels for 4bpp, 8x4 pixels for 2bpp) wide and high. However this only affects the imageSize argument, not width and height which still go down to 1x1 for the last level.   

  

  

  

  

  

&nbsp;
  

So for the PVRTC miplevels below the minimum block size (i.e. 2x2, 1x1), you're supposed to keep passing the minimum-size-block's data into glCompressedTexImage2D, even though it represents an image that is larger than the width&nbsp;&& height parameters passed to glCompressedTexImage2D indicate?
  

&nbsp;
Kris2010-11-05 00:07:42

---

<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:** [November 23, 2010, 10:15am UTC](https://forums.imgtec.com/t/how-to-specify-maximum-mipmap-level-in-opengles/625/6 "2010-11-23T10:15:40Z")

</div>

Kris wrote:

So for the PVRTC miplevels below the minimum block size (i.e. 2x2, 1x1), you're supposed to keep passing the minimum-size-block's data into glCompressedTexImage2D, even though it represents an image that is larger than the width&nbsp;&& height parameters passed to glCompressedTexImage2D indicate?

  
That's correct.
