How to load textures efficiently in OpenGL ES

I have very simple knowledge about using OpenGL, especially on Android. I am developing an application using OpenGL to quickly switch between full-screen images (since it is too slow using the regular Android platform).

What I found is that to load the textures I need to do something like:

ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = byteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
textureBuffer = byteBuffer.asFloatBuffer();
textureBuffer.put(texture);
textureBuffer.position(0);
_gl = gl;
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), _imageResourceId);
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();

Now, since the images are intended for full-screen viewing (and they are quite large - 1024x1024), this takes some time, especially since I need to download 5 of them at the same time.

Therefore, I need to ask some questions regarding tips for improving the code, especially about efficient loading (but use less memory if necessary):

  • , , RGB_565, OpenGL ( )?

  • , 2, OpenGL , , ? , , texImage2D ?

  • , (, 10000x10000, 1024x1024 OpenGL)?

  • , ? , OpenGL , , . onDrawFrame GlRenderer, , , ?

  • , ( , ), . , . OpenGL ES Android?

  • Bitmap (, NDK)? , PNG 1024x1024 400 -700 , OpenGL 50 -70 .

  • Procrank, , OpenGL . ? , ?

  • Android , , , ?


@Majid Max:

  • OpenGL, - openGL?

  • ?

  • , , , ?

  • , , , ? ? ? , , - OpenGL. .

  • , , . , , , - , . . .

  • . , glDeleteTextures, , , ?

  • ? ?

  • , ? , (, ), ? Google IO, , , . . , , .


@Majid Max:

1 + 2 + 3.

  • . , , , OpenGL, ? , asyncTask publishprogress.

  • . - , ? , , , ?

  • .

  • , ETC1. , , , .

  • , ? , , Android 200 , OpenGL?

+5
3
  • , (), , , (RGB565), , , , opengl.

  • , 2 /, opengl 2 ( 513/513 1024/1024), , vram. opengl, , "teximage2d" / , ( ).

  • .

  • , , opengl. ( ) ( , C/++, java). , , .

  • ,

  • , (C/++)

  • ( vram ) , , ETC1, PVRTC, ATC , vram .

  • ( ), , .

EDIT:

4.. () , , .

5.. " ", .

6.. opengl ( ), . , opengl, ( ).

7.. - , , , "glCompressedTexImage2D" "texImage2D".       PVRTC GPU PowerVR;       ATC AMD GPU;       ASTC ;       ETC1 ( android 2.2 +).

8.. opengl, . ().

EDIT2:

5.. http://http.download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf

7.. , ETC (: , - ), "glCompressedTexImage2D" opengl (, textureId1, textureId2), :

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId1);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureId2);

:

uniform sampler2D     sTexture1;
uniform sampler2D     sTexture2;
varying mediump vec2  vTexCoord;

void main()
{
    gl_FragColor.rgb = texture2D(sTexture1, vTexCoord).rgb;
    gl_FragColor.a   = texture2D(sTexture2, vTexCoord).r;
}

, ( ETC):

GLint texture1Sampler = glGetUniformLocation(programObject, "sTexture1");
GLint texture2Sampler = glGetUniformLocation(programObject, "sTexture2");

glUniform1i(texture1Sampler, GL_TEXTURE0);
glUniform1i(texture2Sampler, GL_TEXTURE1);

8.. -, ( ) , GL_OUT_OF_MEMORY, (, ,...).

+5
-1

If you are still looking for an example for rendering bitmaps on InputSurface using OpenGL.

I was able to get this to work.
Check out my answers here.

fooobar.com/questions/1125885 / ...

fooobar.com/questions/1125886 / ...

https://stackoverflow.com/a/49331295/7602598

-1
source

All Articles