Reloading textures to frame buffer

Started by ap, January 19, 2015, 11:12:29 AM

Previous topic - Next topic

ap

Hello

According to the examples, the textures are typically loaded within the surfaceChanged method of the "GLSurfaceView.Renderer" implementation.

My concern is when loading the textures takes a lot of time, and I want to do it only once when the application starts.

If I am trying to load the textures elsewhere, what happens is when pausing/resuming the app, the surfaceChanged is called, the frame buffer is disposed, and a new frame buffer is generated.
The textures are removed from the GPU once the frame buffer is disposed, although they remain within the TextureManager.

It is possible to "re-add" the textures by doing something like:

TextureManager tm = TextureManager.getInstance();
for (String s : myTextures)
{
   tm.replaceTexture(s, tm.getTexture(s));
}

Iterating through the textures I've previously added and replacing them with themselves, which causes reloading them to the GPU (I store the textures names in a list. Actually, the list of all textures can also be extracted from the TextureManager itself..).

This is a bit weird. Is this the best way to so? I guess not..

I am actually trying to "re-load" the textures which where already added to the TextureManager to the GPU again for proper rendering of my objects ....
What is the best approach to do so?

Thanks
A.P.


EgonOlsen

There's no need to do that. The texture remain in the TextureManager to de reused on a context change. There's no need to load and assign more than once.
If you are creating a new FrameBuffer, Textures and Object3D can remain as they are. The engine will take care of the context change and upload new data to the gpu as needed.

BTW: You can try to make Android reuse the context by setting

<GLSurfaceView>.setPreserveEGLContextOnPause(true);

and creating a new FrameBuffer only if the gl context given to onSurfaceChanged differs from the last one. That will also work in OpenGL ES 2.0 even if that context isn't really used there.

ap

Thanks, I'l give that a try....
But, I am not sure there is no need to do that. After my app is paused and resumed, a new frame buffer is created and the textures are "gone". The TextureManager still holds the textures, but it seems like they are not automatically uploaded to the GPU..

EgonOlsen

They are! That's the whole purpose of that thing. In case of a resume, all you might have to do is to create a new FrameBuffer instance. Unless you are fiddling around with GL calls directly or are calling keepPixelData(false) or removePixels() on the textures, all should be fine.