Android: How long does OpenGL maintain texture?

How long does openGL keep texture?

Does texture memory remain after exiting it?

For example, if I have the following code:

mGL.glGenTextures(1, mTextures, 0); mGL.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[0]); // A bound texture is // an active texture //mGL.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, bitmap.getWidth(),bitmap.getHeight(), 0, GL10.GL_RGBA, GL10.GL_FLOAT, textures); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,GL10.GL_RGBA, bitmap, 0); // create nearest filtered texture mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); // This is where the scaling algorithms are mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); // This is where the scaling algorithms are mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); //bitmap.recycle(); Log.v("GLSurfaceView", "Loading Texture Finished"); return mTextures[0]; 

What changes will invalidate the return value?

I don’t want to reload all my textures when I return to activity (say, a person had a phone call) because it really slows down.

Update:

Found this information in the Renderer documentation, which confirms the answer below: @svdree:

EGL Context There are situations when the EGL rendering context is lost. This usually happens when the device wakes up after sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with this context will be automatically deleted. For the rendering to display correctly, the visualizer must recreate any lost resources that it still needs. The onSurfaceCreated method (GL10, EGLConfig) is a convenient place to do this.

This means that the textures are associated with the EGL context.

After posting this question, I tried to solve the problem by following my steps based on a basic action that has a link to a custom GLRenderer. Basically, I can pass OpenGLSurface View forward (i.e., make it an instance in one action and use it in the next), but as soon as it completes its shutdown procedure, it will not start again.

I also found that the transparency of your activity keeps the openGL context below the transparent activity (which makes sense, but only helps for menus, etc.). However, I believe that it would always be possible to perform every action after the openGL activity was a bit transparent, thereby keeping the textures in the background in all your actions (this is probably what I will do)

+6
source share
2 answers

When you leave the action, your OpenGL context will be lost, which means that all your textures, vertex buffer objects, etc. will need to be recreated. This is usually done in the onSurfaceCreated () method of GLSurfaceView.Renderer .

+1
source

onPause () throws most openGL pens, etc.! Good luck in the open land!

0
source

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


All Articles