DGL
https://delphigl.com/forum/

Loading many textures in a separate thread...
https://delphigl.com/forum/viewtopic.php?f=19&t=6849
Seite 1 von 1

Autor:  dpm_dpmartin [ Sa Aug 25, 2007 19:12 ]
Betreff des Beitrags:  Loading many textures in a separate thread...

I am stumped by my inability to code a simple threaded texture loader. I have coded a simple application to load 4 textures into an array of GLUInt and the OpenGL timer doing the drawing will either display a white box if there is no data there, or the four textures if they have been loaded.

With my application, I have two ways of loading the four textures - the first is a loop in the OnClick event of a TButton, the second is in the exact same code loop, but this time it is kicked off by a call to BeginThread. When I start the application, it will display four white boxes as no textures have been loaded. As soon as I press the "Load in OnClick" button the images are shown as the textures are loaded. If I press the "Load in BeginThread" button, either then or just after the application loads - then my textures disappear.

Does anyone know why the textures can't seem to be loaded inside a BeginThread? To explain myself better I have decided to attach a 55K .zip file with the program and textures I am trying to load in a thread - if anyone wanted to have a look at it, it should compile straight away.

Dateianhänge:
Dateikommentar: Source code and textures to test.
ThreadTextureLoader.zip [55.75 KiB]
343-mal heruntergeladen

Autor:  LarsMiddendorf [ Sa Aug 25, 2007 19:23 ]
Betreff des Beitrags: 

The OpenGL Context (RC) is only made current in the main thread. You should call wglMakeCurrent from the texture loader thread. As an alternative there is the extension ARB_pixel_buffer_object which allows asynchronous texture upload.

Autor:  dpm_dpmartin [ Sa Aug 25, 2007 20:33 ]
Betreff des Beitrags: 

Thank you for the response. I wonder if you could guide me a bit further by elaborating as I currently do not realise how that is achieved.

Isn't my single global DC used for rendering? I'm not rendering inside my thread, just loading data from file into an array of GLUInt. I tried adding a call to wglMakeCurrent (DC,RC); at the start of the thread code but it changes nothing - disappointed it wasn't so simple. I had assumed, wrongly obviously, that I didn't need to do much more than that as, as stated above, I have only have one DC established throughout the run of the program.

Do I need a shared context?

What do I need to do to my program to get the textures loaded in the thread that is started from the button press?

Autor:  Lossy eX [ So Aug 26, 2007 13:26 ]
Betreff des Beitrags: 

pixel_buffer_objects is an relative new extension but only newer cards and newer driver support it. That could be an problem in you media software,

Yes its could be possible if you create an second context. Bind this context to the loader thread and share this with the other context. But i think it would be easier to load only the images in the loader thread and create the textures in the renderthread. You only need to transfer some informations to the renderthread. Like pointer of the data, width, height and format. If you create the textures with glTexImage2D it only needs 1-2 ms to upload the data. That should be easy and fast enough.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/