View Full Version : Best practice for resource loading?
05-02-2011, 03:19 AM
Is there any good way to load resources while the zgl app is running (outside of the SYS_LOAD function)? I would really like to have some basic sort of loading screen being drawn as resources load, but doing any loading in the SYS_DRAW function or a thread results in corrupted graphics.
I've tried creating the loading thread within the SYS_LOAD proc as well as the SYS_DRAW proc, but it it doesn't work in either.
05-02-2011, 09:00 AM
You can't just create your own thread and load there resources, because tex_*functions uses OpenGL commands and this commands can be executed only in the main thread where OpenGL context was created. You can load your resources in timer(don't forget to call timer_Reset when resources will be loaded), or in SYS_DRAW(but if you use batch2d_Begin/batch2d_End, you must call batch2d_Flush before loading textures). And if you want to draw something - scr_Flush will help little bit, but don't expect that you will get smooth animation and so on. So, code in your timer can be something like this:
if TimeToLoadResources Then
while Progress < 100 do
// Choose what to load for current Progress state and load it :) Increment Progress.
// Draw current percentage/etc.
Background resource loading in separate threads will be available later. Some work for this was done in ZenGL(as you can remember this topic (http://www.pascalgamedevelopment.com/showthread.php?6051-Multithreaded-resource-loading)), but only as an experiment. I have fixed all founded problems, but didn't include the code because of architecture questions and some other things.
05-02-2011, 03:19 PM
Ah thanks. No, I never expected smooth animation for loading resources within the sys_draw proc ;) but with multithreading it would be nice to have it available.
13-04-2011, 03:02 AM
During the loading procress, if I focus another window, I can't focus anymore the ZenGL Window until the loading finishes. ZenGL window stay in Background!
Is it possible to avoid this?
13-04-2011, 05:45 AM
I can't focus anymore the ZenGL Window until the loading finishes. ZenGL window stay in Background!
You can try to call app_ProcessOS(after scr_Flush) from unit zgl_application. This function is only for internal use, but I can export it if it will be useful :)
Powered by vBulletin® Version 4.1.10 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.