Jump to content
  • Advertisement
Sign in to follow this  
staticVoid2

Android and mipmaps

This topic is 2643 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi I'm having a problem with mipmapping on android. I create the mipmaps manually using the Bitmap.createScaledBitmap() method, the code is as follows:


public int createTextureFromBmp(Bitmap bmp, GL10 gl) {
int[] texture = new int[1];
gl.glGenTextures(1, texture, 0);
if(gl.glGetError() != GL10.GL_NO_ERROR) {
return 0;
}

gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);

int width = bmp.getWidth();
int height = bmp.getHeight();
int mipLevel = 0;

while(true) {
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, mipLevel, bmp, 0);

if(gl.glGetError() != GL10.GL_NO_ERROR) {
return 0;
}

Log.d("MipMaps", "mipLevel: " + mipLevel + ", width: " + width + ", height: " + height);


mipLevel++;
width = width / 2;
height = height / 2;
if(width == 0 && height == 0) {
break;
}

Bitmap next = Bitmap.createScaledBitmap(bmp, Math.max(1, width), Math.max(1, height), true);
bmp.recycle();
bmp = next;
}

gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
return texture[0];


the input bitmaps are all powers of two. I have checked each level of the mipmaps created manually and they are all correct.

It only works with certain bitmaps on the device and on the emulator it seems to be working fine. I even duplicated one of the textures that was working and copied and pasted the one that wasn;t working into it and re-saved this, refreshed the project and it still never worked. It is just showing up all black when I use GL_LINEAR_MIPMAP_LINEAR and works fine when using just GL_LINEAR.

Share this post


Link to post
Share on other sites
Advertisement
I added this to the code:


public int createTextureFromBmp(Bitmap bmp2, GL10 gl) {
...
Bitmap bmp = bmp2.copy(Bitmap.Config.ARGB_8888, true);
if(bmp == null) {
return 0;
}
...
}


at the start of the function and it seems to be working fine now.

I don't really understand how this solves the problem, but my best guess is that GLUtils.texImage2d() creates a texture format based on the best suitable match for the input png file (i.e. different from ARGB_8888) and there is a bug in the GL backend for the device that doesn't know how to handle sampling from a set of mipmaps with that specific format. would this be a correct assumption?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!