Author Topic: Reloading textures to frame buffer  (Read 1781 times)

Offline ap

  • byte
  • *
  • Posts: 12
    • View Profile
Reloading textures to frame buffer
« on: January 19, 2015, 11:12:29 am »
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.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Reloading textures to frame buffer
« Reply #1 on: January 19, 2015, 08:05:31 pm »
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

Code: [Select]
<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.

Offline ap

  • byte
  • *
  • Posts: 12
    • View Profile
Re: Reloading textures to frame buffer
« Reply #2 on: January 20, 2015, 02:29:11 pm »
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..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Reloading textures to frame buffer
« Reply #3 on: January 20, 2015, 05:30:38 pm »
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.