I create simple live wallpapers for Android. I load the required texture into OpenGL ES 2.0 using the code below. I uploaded all my images to a single file with a size of 2048x2048. This code below takes from 900 to 1200 ms to load the texture. Is this a normal time, or am I doing something wrong to make it slow?
I also try to clear the texture list in Opengl every time onSurfaceCreated is called in my renderer. Is it right to do this, or is there a simple way to check if the previously loaded texture is already in memory, and if this avoids cleaning and rebooting? Please let me know your comments on this. Thanks.
Also, when the screen orientation changes, OnSurfaceCreated is called. Thus, texture loading occurs again. This is not a good idea. What job?
public int addTexture(Bitmap texture) { int bitmapFormat = texture.getConfig() == Config.ARGB_8888 ? GLES20.GL_RGBA : GLES20.GL_RGB; int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); int textureId = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapFormat, texture, 0); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); return textureId; }
source share