Texture loading fast in OpenGL 2.0

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; } 
+4
source share
1 answer

Several ways to increase productivity.

  • Do not load the texture every time onSurfaceChanged is onSurfaceChanged . Initialize your textureId to -1 (in the / surfaceCreated constructor of your renderer) and check onSurfaceChanged at the beginning if you have a different identifier. When you call glGenTextures , you will get a positive number.
  • Do you need Mipmaps? This may be the key point of your method here. Try without the line GLES20.glGenerateMipMap(GLES20.GL_TEXTURE_2D);
  • 2048x2048 is huge. Especially for textures. Do you really need a lot of details? Perhaps 1024x1024 is enough.
  • Avoid RGB_888, use RGB_565 instead: you'll get almost the same visual quality at half the size.
+3
source

Source: https://habr.com/ru/post/1386027/


All Articles