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]
342-mal heruntergeladen
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.
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?
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
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.
Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.