I’m trying to dynamically load texture during my OpenGL application, but if I put the loading in the main render loop its slowing down my app.
I try to put the loading into a thread (pthread) but a soon as I access ANY gl instruction the program crash… I guess its because the GLX context is linked with the main thread? So…
How I can do the loading of my textures in a thread and then assigned them to my model when they are loaded?
I google quite a bit but didn’t find anything… Please help!!!
when the new texture-s is/are required, start the loading thread - to load the data RGBA bytes [for example from a PNG file] into the memory. DO NOT call any gl Commands from the loading thread
your other thread [the one with rendering loop],
will check in some intervals, or get notified if the texture data were loaded into the memory
once the data were loaded [and the loading thread successfuly finished] , use the data [from the main thread] to create the texture
The code snippet you posted does not seem to be right. The function Imlib_create_image_from_drawable
returns ImlibImage* , and you are passing ImlibImage* img to the function gluBuild2DMipmaps, however gluBuild2DMipmaps expects const void* img. You have to change your code from:
the example above is for imlib, with imlib2 the above is still true, just the type names and function names are different, you have to get the
RGB image data from the Imlib_Image calling the imlib_image_get_data_for_reading_only function:
Great! Works like a charm, however, I’m loading textures of 1024x1024, and it’s a bit slow, is there another way to speed things up? or using gluBuild2DMipmaps (cuz glTexture2d is even slower…) is my only option???
I even try to “cut” the picture (like 4x512x512) but it doesn’t take about the same loading time… What is the best way to load large texture REALLY fast?