1

I'm developing an OpenGL application using OpenGL2.1 and want to upload textures via threads.

What I have done so far:

  1. Create a second context and share between the two
  2. Upload texture data in a thread

Everything is working fine, except that I notice a small "lag" when the texture upload happens! I know this is because the driver have to synchronize the two contexts. The problem is that I want it to stream the texture. I don't want to update the texture later. I just want to load textures in the background while displaying an "almost smooth" loading animation without stalling the whole application.

That's the point I searched and found that PBOs can be used for DMA data transfer of pixel data. Is it possible to use a PBO for texture upload? If so, how?

genpfault
  • 51,148
  • 11
  • 85
  • 139
char8_t
  • 320
  • 2
  • 8

1 Answers1

3

You don't need a second context to upload the texture data async. Just make sure you don't use the buffer right after triggering the upload, or it will stall waiting for the copy to finish.

Here's an example of this process: http://www.songho.ca/opengl/gl_pbo.html#unpack

And here's a bit more info about what PBOs are and how they should be used: http://www.opengl.org/wiki/Pixel_Buffer_Object

Flawe
  • 49
  • 2
  • Thanks for your answer! I already read many articles about PBOs but I can't get it to work, I mean what are the steps I need to do to archive my goal? – char8_t Aug 06 '14 at 19:21
  • 1
    Check out the first link I posted, it has source code you can look at. – Flawe Aug 06 '14 at 19:26
  • Yes I have checked your first link, so when I have it understanded correctly I have to do the following: - Create texture (handle) and bind it - Create pbo (handle) and bind it - Initialize the pbo with the image size but without any data - Map the pbo and upload texture data - Do a "dummy" call to glTexImage2D to let the pbo transfer its data to the texture object Is this right or do I missed something/do something wrong? – char8_t Aug 06 '14 at 19:37
  • Ok I will check out my aproach tomorrow eitherand will post here if it works – char8_t Aug 06 '14 at 20:41
  • Ok everything is fixed now! -closed- – char8_t Aug 08 '14 at 10:54