Take the 2-minute tour ×

How long does openGL store a texture for?

Does the texture memory get recycled when you leave an activity?

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,
        mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
        mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,

        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 come back into an activity (say the person had a phone call) because it really slows things down.


Found this info in the Renderer documentation, which confirms the answer given below by @svdree:


That means that the textures are related to the EGL Context

Since posting this question I have attempted to solve the problem by having my activities inherit from a base activity that has a reference to a custom GLRenderer. Basically, I can pass the OpenGLSurface View forward (i.e. make it instantiate it in one activity and use it in the next), but once it goes through its shutdown procedure it doesn't start up again.

I have also found that making your activities transparent preserves the openGL context below the transparent activity (which makes sense, but helps only for menus and such). However I suppose it would be possible to always have every activity after the openGL activity be just a little bit transparent, thereby preserving the textures in the background across all your activities (this is probably what I will do)

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
can I pass the context to a new activity, or somehow save it. I'm worried about the case in which someone takes a call and then comes back to my application and all the textures have to load again. –  tjb Aug 16 '11 at 14:26
A lost context is lost, it can't be saved. "Losing" a context typically indicates that the system had something else to do, or an error occurred, and requires you recreate all video resources. –  ssube Aug 20 '11 at 17:43
This is a common design pattern in Android; whenever another activity comes to the front, you need to free up your resources so the other activity can use them (really helpful on systems with limited resources). This is built-in functionality in the GLSurfaceView. I suspect you can work around this by writing your own version of the GLSurfaceView, but I would not recommend that. Besides, if you give priority to the stuff that is actually visible when loading your resources again, this does not have to be that slow. –  svdree Aug 20 '11 at 18:19
add comment

onPause() tosses most openGL handles etc! Good luck in openGL land!

share|improve this answer
add comment

Your Answer


