how to assign one texture to another efficiently in OpenGL ES for Android

user6943953

I want to copy texture1 to texture2. The background is that I generate 15 empty texture id and bind them to GLES11Ext.GL_TEXTURE_EXTERNAL_OES, the following is my code:

int[] textures = new int[15];
GLES20.glGenTextures(15, textures, 0);
GlUtil.checkGlError("glGenTextures");

for(int i=0;i<15;i++)
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[i]);

then I always transfer camera preview to textures[0], I want copy the texture from textures[0] to textures[1] in order to keep the frame content of timestamp 1, and copy the texture from textures[0] to textures[2] in order to keep the frame content of timestamp 2... it looks like buffer some texture data in GPU and render some of that in the future. So I want to know is there anyway to do this? And can I just use textures[2]=textures[0] to copy texture data?

Reto Koradi

There isn't a very direct way to copy texture data in ES 2.0. The easiest way is probably using glCopyTexImage2D(). To use this, you have to create an FBO, and attach the source texture to it. Say if srcTexId is the id of the source texture, and dstTexId the id of the destination texture:

GLuint fboId = 0;
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, srcTexId, 0);

glBindTexture(GL_TEXTURE_2D, dstTexId);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, width, height, 0);

That being said, from your description, I don't believe that this is really what you should be doing, for the following reasons:

  • I don't think copying texture data as shown above will work for the external textures you are using.
  • Copying texture data will always be expensive, and sounds completely unnecessary to solve your problem.

It sounds like you want to keep the 15 most recent camera images. To do this, you can simply track which of your 15 textures contains the most recent image, and treat the list of the 15 texture ids as a circular buffer.

Say initially you create your texture ids:

int[] textures = new int[15];
GLES20.glGenTextures(15, textures, 0);
int newestIdx = 0;

Then every time you receive a new frame, you write it to the next entry in your list of texture ids, wrapping around at 15:

newestIdx = (newestIdx + 1) % 15;
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[newestIdx]);
// Capture new frame into currently bound texture.

Then, every time you want to use the ith frame, with 0 referring to the most recent, 1 to the frame before that, etc, you bind it with:

GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[(newestIdx + i) % 15]);

So the textures never get copied. You just keep track of which texture contains which frame, and access them accordingly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

OpenGL ES 2.0 - How to efficiently copy a Texture into Frame Buffer

From Dev

How to render to a depth texture in OpenGL ES on Android

From Dev

how to load android camera frame into opengl es texture via ndk?

From Dev

how to load android camera frame into opengl es texture via ndk?

From Dev

How to check an uploaded texture in OpenGL ES 2.0 in Android?

From Dev

Copying data from one texture to another - opengl

From Dev

Copying data from one texture to another - opengl

From Dev

Android OpenGL ES 2 Texture Quadrants Rotated

From Dev

Android OpenGL.ES Texture/Image Drawing

From Dev

How to copy a texture in a OpenGL context to another context

From Dev

How to copy a texture in a OpenGL context to another context

From Dev

How to add some pixels on the texture in OpenGL ES

From Dev

How to add some pixels on the texture in OpenGL ES

From Dev

Android OpenGL: How to change bitmap attached to texture?

From Dev

Android - How to renderer video texture on 3D cube with opengl-es?

From Dev

OpenGL ES: Texture a plane

From Dev

OpenGL ES 2.0 drawing more than one texture

From Dev

android opengl texture overlapping

From Dev

Android Opengl Circle Texture

From Dev

Android drawing texture with OpenGL ES 2.0 slow on some devices

From Dev

Texture compression strategy for Android OpenGL ES that caters for alphas

From Dev

Android OpenGL ES 2.0 Texture setting does not seem to work

From Dev

Android drawing texture with OpenGL ES 2.0 slow on some devices

From Dev

Texture compression strategy for Android OpenGL ES that caters for alphas

From Dev

How to texture of a glutSolidTorus in OpenGL?

From Dev

OpenGL ES 2.0, how to animate texture's opacity

From Dev

OpenGL ES texture degrades in quality

From Dev

OpenGL ES texture atlas distortion

From Dev

OpenGL ES draws a black texture

Related Related

  1. 1

    OpenGL ES 2.0 - How to efficiently copy a Texture into Frame Buffer

  2. 2

    How to render to a depth texture in OpenGL ES on Android

  3. 3

    how to load android camera frame into opengl es texture via ndk?

  4. 4

    how to load android camera frame into opengl es texture via ndk?

  5. 5

    How to check an uploaded texture in OpenGL ES 2.0 in Android?

  6. 6

    Copying data from one texture to another - opengl

  7. 7

    Copying data from one texture to another - opengl

  8. 8

    Android OpenGL ES 2 Texture Quadrants Rotated

  9. 9

    Android OpenGL.ES Texture/Image Drawing

  10. 10

    How to copy a texture in a OpenGL context to another context

  11. 11

    How to copy a texture in a OpenGL context to another context

  12. 12

    How to add some pixels on the texture in OpenGL ES

  13. 13

    How to add some pixels on the texture in OpenGL ES

  14. 14

    Android OpenGL: How to change bitmap attached to texture?

  15. 15

    Android - How to renderer video texture on 3D cube with opengl-es?

  16. 16

    OpenGL ES: Texture a plane

  17. 17

    OpenGL ES 2.0 drawing more than one texture

  18. 18

    android opengl texture overlapping

  19. 19

    Android Opengl Circle Texture

  20. 20

    Android drawing texture with OpenGL ES 2.0 slow on some devices

  21. 21

    Texture compression strategy for Android OpenGL ES that caters for alphas

  22. 22

    Android OpenGL ES 2.0 Texture setting does not seem to work

  23. 23

    Android drawing texture with OpenGL ES 2.0 slow on some devices

  24. 24

    Texture compression strategy for Android OpenGL ES that caters for alphas

  25. 25

    How to texture of a glutSolidTorus in OpenGL?

  26. 26

    OpenGL ES 2.0, how to animate texture's opacity

  27. 27

    OpenGL ES texture degrades in quality

  28. 28

    OpenGL ES texture atlas distortion

  29. 29

    OpenGL ES draws a black texture

HotTag

Archive