PDA

View Full Version : Multithreaded resource loading



Andru
03-10-2010, 07:00 PM
Some time ago I was interested in multithreaded resource loading in OpenGL and started working on it. After implementation it for GNU/Linux and MacOS X long time I couldn't understand what I must do for Windows. Now I implemented this and want to do some tests on different PC's.

Can you please test this demo(1.5Mb) (http://andru-kun.inf.ua/tmp/demo08win.7z) and write what CPU and GPU in your PC? Here (http://andru-kun.inf.ua/tmp/demo08mac.zip) the MacOS X version.

http://s56.radikal.ru/i151/1010/db/33ef28169df2.png

Demo is based on one open source library and changes will be available after successfully tests :)

AthenaOfDelphi
03-10-2010, 07:11 PM
Hi Andru,

I've tested the demo, and all appears to work correctly with one notable exception... the 'Play Sound'/'Mute Sounds' graphic is corrupted.

Andru
03-10-2010, 07:17 PM
the 'Play Sound'/'Mute Sounds' graphic is corrupted.
Can you make a screenshot? And what videocard is used?

AthenaOfDelphi
03-10-2010, 07:25 PM
Yes, you did ask for that info... sorry hon... Here's my machine specs:- http://www.pgdannual.com/index.php?m=displaymachine&id=15&key=YVKLCZSRESEOMPPE

Now... a screenshot... I'd love to oblige, but when I fired it up to grab the screenie, it works, the images are great. The picture displayed when sound is off was very garbled, the picture for when sound on was just like a grey block that was all out of shape.

Andru
03-10-2010, 07:36 PM
Now... a screenshot... I'd love to oblige, but when I fired it up to grab the screenie, it works, the images are great.
Hmm... demo starts and waiting 1 sec. before starting load resources. Every texture that doesn't loaded - drawing like a white shape. Maybe demo lost a focus or something else happened? :)


Here's my machine specs:

- Drivers Version: Forceware 6.14.11.7813 (9-17-2008 )
Pretty old drivers, but problem not in it I think.

AthenaOfDelphi
03-10-2010, 07:57 PM
Hmm... demo starts and waiting 1 sec. before starting load resources. Every texture that doesn't loaded - drawing like a white shape. Maybe demo lost a focus or something else happened? :)

Pretty old drivers, but problem not in it I think.

I've stopped and started it, switched focus and basically tried to break it during the load but I can't. I think it must have been something really quirky, but I just can't repeat it.

As for my old drivers... I've been burned by keeping my drivers up to date in the past so generally I find a set that works with all the stuff I use and then leave them well alone :)

Andru
03-10-2010, 08:50 PM
I think it must have been something really quirky, but I just can't repeat it.
Threads... never guess when error can happens :) Maybe there is some error in my code, so I will investigate it.

User137
03-10-2010, 09:50 PM
I was trying to make my OpenGL imageviewer threaded but no luck so far. The program keeps 3 images loaded same time and they are scrolled up and down continuously. You can imagine there is a small pause when scroll reach the ends and needs to load next file.

I was hoping command glFinish would do the trick for me but it seemed to be more complicated problem...

Edit: And i tested your program, it run good and all images loaded normally. Only windows taskbar button was showing a generic application icon instead of the icon that was in .exe and application titlebar.

cpu: E8400 3Ghz dualcore
gpu: Radeon HD 5700

Andru
03-10-2010, 10:21 PM
I was hoping command glFinish would do the trick for me but it seemed to be more complicated problem...
Yeah, there is some tricky way for using multithreaded texture loading under Windows :)

1. Create context in main thread
2. Call wglMakeCurrent( 0, 0 ) in main thread and create second thread
3. Create new context using main device context(HDC) in second thread and make it current
4. Call wglShareLists( context_from_main_thread, new_context ) in second thread
5. Call wglMakeCurrent for main context in main thread

So, after this you can load resources in second thread and use them in main thread. But you must be careful with other operations, like binding texture before it was loaded in second thread(seems this is my error in demo, but this happens not on all PC's)


Only windows taskbar button was showing a generic application icon instead of the icon that was in .exe and application titlebar.
Hmm, there is no icon in exe. I compiled it wthout resource file.

WILL
03-10-2010, 11:35 PM
Hey is this a Windows demo? If you provide me with a Snow Leopard compatible demo I'd gladly run it on my, almost newest, iMac (has an Intel Core i7 with a ATI Radeon HD 4850) for you. :)

Andru
04-10-2010, 06:29 AM
Hey is this a Windows demo? If you provide me with a Snow Leopard compatible demo I'd gladly run it on my, almost newest, iMac (has an Intel Core i7 with a ATI Radeon HD 4850) for you.
Oh, it will be interesting to test it on real Mac :) Tonight I will build a Mac demo.

User137
04-10-2010, 08:16 AM
Are you doing this with Lazarus? It has lazOpenGLContext package which works same time on most operating systems.

Andru
04-10-2010, 08:30 AM
Are you doing this with Lazarus? It has lazOpenGLContext package which works same time on most operating systems.
Nope, I use my own code(that can be compiled by FreePascal and Delphi(7-2010, Win32 only)). Maybe some time later I will present my library with examples here :)

Luuk van Venrooij
04-10-2010, 02:29 PM
Cool stuff! programs seems to work ok here. I experimented with this a while back:) see we use the same approach. You can not only load textures this way but also geometry into VBO/DPL, load and compile shader programs or any other OpenGL resource for that matter.

To bad that this approach requires a context switch:( I made a small grid bassed world system that would automaticly stream in new models/textures when needed but the switching of contexts gave me pretty large framedrops. Hope that OGL 4.X wil have a solution for this like DX10 and DX11.

Andru
04-10-2010, 02:51 PM
To bad that this approach requires a context switch
I switch context only one time - for creating second context. After that all threads working without switching and waiting :)

Andru
04-10-2010, 04:03 PM
WILL
Here (http://andru-kun.inf.ua/tmp/demo08mac.zip) the MacOS X version of demo compiled under MacOS X 10.6.3

WILL
04-10-2010, 06:29 PM
Downloaded! I'll get back to you once I have time to run it after work. I'm running 10.6.4 (Snow Leopard) so it should be compatible I'm sure.

de_jean_7777
04-10-2010, 07:01 PM
I tried your demo and it works. I assume that the music stopping when switching to different windows is intentional?

My PC is:
OS: Windows 7 Ultimate
CPU: Athlon II X2 240
GPU: Sapphire Radeon HD4850 512MB

Andru
04-10-2010, 07:09 PM
I assume that the music stopping when switching to different windows is intentional?
Yes, and it must continue playing after returning the focus to demo.

de_jean_7777
04-10-2010, 08:12 PM
Yes, and it must continue playing after returning the focus to demo.

It continues playing.

I also tried it on another PC, at my work.
OS: Windows XP Professional SP3
CPU: Intel Pentium Dual E2200
GPU: Intel 82945G (i945G) integrated

It worked on that PC too. If it works on the Intel card with shoddy OpenGL drivers, it should work anywhere.

WILL
04-10-2010, 10:04 PM
Well I gat back from work and gave it a run. For the most part it runs just fine, graphics display and the sound clip plays too without any popup errors. However the one bug I found was that most of the faces were showing a block of glitchy and random static instead of their respective sprite. Here is a couple of screenies to show basically what it was doing.


5960


Go ahead and send me an update or tweaked version if you like. I can be your 'real test run' on the current iMacs if you like.

My system specs are:

CPU: Intel Core i7 (Quad Core)
GPU: ATI Radeon HD 4850
Screen Res: 2560 x 1440 (27" screen)
RAM: 4GB DDR3
OS: Mac OS X 10.6.4

Stoney
04-10-2010, 11:19 PM
I've got the same problem WILL does when running the application on my MacBook Pro (Core 2 Duo 2.53 GHz, NVidia GeForce 9400 graphics card and 4 GB DDR3 RAM).
Some sprites seem that they are not loaded correctly which seems to be always different sprites when re-running the application.

WILL
04-10-2010, 11:24 PM
Just a heads up, I ran it again (twice; ran it, Command-Q, ran it) just now out of curiosity and now ALL the images (including the glowy ZenGL image) except for the speaker and the x button and the label for the text shows some form of glitchy garble.

Andru
04-10-2010, 11:30 PM
Tanks for tests. Seems I found the bug :) When the second thread loading texture to videocard(glTexImage2D) in first I'm tried to do glBindTexture. Now I changed something in my library, and it should work correctly(anyway now it work's correctly in my VirtualBox :)). I will update demo soon.

Andru
04-10-2010, 11:49 PM
Try this one (http://andru-kun.inf.ua/tmp/demo08mac.zip).

WILL
05-10-2010, 04:11 AM
Well that one worked a whole lot better. :) The x button doesn't play the song clip anymore but I do hear a 'click' sound when I do click on the window.

All the images are fine now, but it does seem like you have any vsync turned on, which for OpenGL I don't think you can set in program anyhow. Am I right?

Nice job!

Andru
05-10-2010, 04:22 AM
The x button doesn't play the song clip anymore but I do hear a 'click' sound when I do click on the window.
Oh, I forgot to build my app statically with ogg libraries.


which for OpenGL I don't think you can set in program anyhow
I can, but in this demo I didn't turn on it :)

WILL
05-10-2010, 04:30 AM
So I guess this means you'll be making some Mac games pretty soon huh? :)

Andru
05-10-2010, 05:26 AM
So I guess this means you'll be making some Mac games pretty soon huh?
Maybe, but for now I continue develop only the library(year ago one commercial game based on this library has been published for Macs, and new one waiting for release :))

Luuk van Venrooij
05-10-2010, 02:58 PM
I switch context only one time - for creating second context. After that all threads working without switching and waiting :)

You need to switch the context. Otherwise your rendering commands will be send to the wrong threads if you want to handle drawing onscreen.

Andru
05-10-2010, 04:48 PM
You need to switch the context. Otherwise your rendering commands will be send to the wrong threads if you want to handle drawing onscreen.
Why you so sure? :) OpenGL has a rule - "one thread - one context", so situation "will be send to the wrong threads" never will happen, and my demo works as you can see(only Windows version has a problem and it will be fixed the same way as MacOS X demo)

Andru
05-10-2010, 10:16 PM
AthenaOfDelphi
Can you test this new demo (http://andru-kun.inf.ua/tmp/demo08win.7z) for Windows, please?

de_jean_7777
05-10-2010, 11:30 PM
I've tested it on the following machine. It works if I just run it, albeit a bit slow.

OS: Windows XP Pro SP3
CPU: Pentium 4 1.9 (Northwood)
GPU: Intel i845G (integrated)

However, when I minimize the demo during loading, and then try to restore it later by clicking on the demo button in taskbar, I eventually hear a few of those asterisk sounds windows makes, and the program no longer responds. While it's minimized it does not use CPU and has about ~3 MB memory use. When I restore it, it takes up ~100% of CPU and suddenly increases it's memory use up to ~20 MB, like it's stuck in some kind of a loop and continues to use more and more memory (slowly increasing). Sometimes it'll crash when I restore it, sometimes I get an access violation error message. Once the program has loaded completely, it can be minimized and restored without problems.

Andru
06-10-2010, 07:19 AM
Once the program has loaded completely, it can be minimized and restored without problems.
Strange. Seems this old videocard with old drivers wants active DC with own window. Can you put here content of log.txt?

AthenaOfDelphi
06-10-2010, 07:40 AM
AthenaOfDelphi
Can you test this new demo (http://andru-kun.inf.ua/tmp/demo08win.7z) for Windows, please?

I'll give it a whirl later when I'm back home (probably be something like 7-8pm UK time).

AthenaOfDelphi
06-10-2010, 07:47 PM
Hi Andru,

I'm afraid, the first time it ran, this was all that was displayed where the speaker should be:-

65

I've run it again, and it works perfectly. Here's the log from the first run.


=====================
=== ZenGL 0.2 RC4 ===
=====================
[00000000ms] Begin
[00000001ms] Current mode: 1680 x 1050
[00000628ms] wglChoosePixelFormatARB: zDepth = 24; stencil = 0; fsaa = 0
[00000678ms] Create OpenGL Context
[00000699ms] Making current OpenGL context
[00000699ms] GL_VERSION: 2.1.2
[00000699ms] GL_RENDERER: GeForce 7600 GT/PCI/SSE2/3DNOW!
[00000699ms] GL_MAX_TEXTURE_SIZE: 4096
[00000699ms] GL_ARB_TEXTURE_COMPRESSION: TRUE
[00000699ms] GL_EXT_TEXTURE_COMPRESSION_S3TC: TRUE
[00000699ms] GL_MAX_TEXTURE_UNITS_ARB: 4
[00000700ms] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 16
[00000700ms] GL_EXT_BLEND_FUNC_SEPARATE: TRUE
[00000700ms] GL_ARB_VERTEX_BUFFER_OBJECT: TRUE
[00000700ms] GL_EXT_FRAMEBUFFER_OBJECT: TRUE
[00000700ms] WGL_PBUFFER: TRUE
[00000700ms] Support WaitVSync: TRUE
[00000702ms] DirectSound: loading DSound.dll
[00001107ms] DirectSound: sound system initialized
[00001505ms] Texture loaded: "data/font-page0.png"
[00001602ms] Texture loaded: "data/halloween/Alien.png"
[00001679ms] Texture loaded: "data/halloween/Bat.png"
[00001752ms] Texture loaded: "data/halloween/Casper.png"
[00001820ms] Texture loaded: "data/halloween/Chucky.png"
[00001894ms] Texture loaded: "data/halloween/Devil.png"
[00001959ms] Texture loaded: "data/halloween/Dracula.png"
[00002022ms] Texture loaded: "data/halloween/Frankenstein.png"
[00002090ms] Texture loaded: "data/halloween/Freddie.png"
[00002145ms] Texture loaded: "data/halloween/Ghost.png"
[00002204ms] Texture loaded: "data/halloween/Gomez.png"
[00002254ms] Texture loaded: "data/halloween/Jack Skellington.png"
[00002305ms] Texture loaded: "data/halloween/Jason.png"
[00002367ms] Texture loaded: "data/halloween/Kokey.png"
[00002426ms] Texture loaded: "data/halloween/Mike.png"
[00002490ms] Texture loaded: "data/halloween/Mummy.png"
[00002542ms] Texture loaded: "data/halloween/Pumpkin.png"
[00002601ms] Texture loaded: "data/halloween/Scream.png"
[00002657ms] Texture loaded: "data/halloween/Skull.png"
[00002715ms] Texture loaded: "data/halloween/Slimer.png"
[00002767ms] Texture loaded: "data/halloween/Squash.png"
[00002773ms] Sound loaded: "data/click.wav"
[00002786ms] Texture loaded: "data/audio-stop.png"
[00002800ms] Texture loaded: "data/audio-play.png"
[00002925ms] Texture loaded: "data/zengl.png"
[00057600ms] Ogg: Initialized
[00084432ms] Average FPS: 747
[00084460ms] Timers to free: 2
[00084461ms] Render Targets to free: 0
[00084460ms] Atlases to free: 0
[00084460ms] Textures to free: 26
[00084460ms] Fonts to free: 1
[00084461ms] Sounds to free: 1
[00084624ms] DirectSound: sound system finalized
[00084707ms] EndReally, this is exactly the same as the first time I tried it. The first run, it failed with a corrupted image... after that, all seemed OK.

Nitrogen
06-10-2010, 07:56 PM
Here's my run:



=====================
=== ZenGL 0.2 RC4 ===
=====================
[00000000ms] Begin
[00000000ms] Current mode: 1680 x 1050
[00000180ms] wglChoosePixelFormatARB: zDepth = 24; stencil = 0; fsaa = 0
[00000197ms] Create OpenGL Context
[00000199ms] Making current OpenGL context
[00000200ms] GL_VERSION: 3.3.0
[00000200ms] GL_RENDERER: GeForce 8800 GT/PCI/SSE2
[00000200ms] GL_MAX_TEXTURE_SIZE: 8192
[00000200ms] GL_ARB_TEXTURE_COMPRESSION: TRUE
[00000200ms] GL_EXT_TEXTURE_COMPRESSION_S3TC: TRUE
[00000200ms] GL_MAX_TEXTURE_UNITS_ARB: 4
[00000200ms] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 16
[00000200ms] GL_EXT_BLEND_FUNC_SEPARATE: TRUE
[00000200ms] GL_ARB_VERTEX_BUFFER_OBJECT: TRUE
[00000200ms] GL_EXT_FRAMEBUFFER_OBJECT: TRUE
[00000200ms] WGL_PBUFFER: TRUE
[00000201ms] Support WaitVSync: TRUE
[00000201ms] DirectSound: loading DSound.dll
[00000223ms] DirectSound: sound system initialized
[00000465ms] Texture loaded: "data/font-page0.png"
[00001069ms] Texture loaded: "data/halloween/Alien.png"
[00001123ms] Texture loaded: "data/halloween/Bat.png"
[00001174ms] Texture loaded: "data/halloween/Casper.png"
[00001224ms] Texture loaded: "data/halloween/Chucky.png"
[00001278ms] Texture loaded: "data/halloween/Devil.png"
[00001327ms] Texture loaded: "data/halloween/Dracula.png"
[00001377ms] Texture loaded: "data/halloween/Frankenstein.png"
[00001432ms] Texture loaded: "data/halloween/Freddie.png"
[00001484ms] Texture loaded: "data/halloween/Ghost.png"
[00001534ms] Texture loaded: "data/halloween/Gomez.png"
[00001582ms] Texture loaded: "data/halloween/Jack Skellington.png"
[00001632ms] Texture loaded: "data/halloween/Jason.png"
[00001684ms] Texture loaded: "data/halloween/Kokey.png"
[00001737ms] Texture loaded: "data/halloween/Mike.png"
[00001792ms] Texture loaded: "data/halloween/Mummy.png"
[00001841ms] Texture loaded: "data/halloween/Pumpkin.png"
[00001888ms] Texture loaded: "data/halloween/Scream.png"
[00001941ms] Texture loaded: "data/halloween/Skull.png"
[00001995ms] Texture loaded: "data/halloween/Slimer.png"
[00002046ms] Texture loaded: "data/halloween/Squash.png"
[00002049ms] Sound loaded: "data/click.wav"
[00002061ms] Texture loaded: "data/audio-stop.png"
[00002070ms] Texture loaded: "data/audio-play.png"
[00002144ms] Texture loaded: "data/zengl.png"
[00005586ms] Average FPS: 1901
[00005608ms] Timers to free: 2
[00005608ms] Render Targets to free: 0
[00005608ms] Atlases to free: 0
[00005608ms] Textures to free: 26
[00005608ms] Fonts to free: 1
[00005608ms] Sounds to free: 1
[00005709ms] DirectSound: sound system finalized
[00005728ms] End


My pc is a
Intel Core 2 Duo E6850 - 2gb ram
8800gt - Nvidia driver 258.96


The first time it ran, it didnt show the speaker graphic at all, just a black space.
The next time it did show the speaker, then after that it didnt come back.

It seemed to run okay (apart from the missing speaker) when I minimised it or dragged the window around while it was loading.

de_jean_7777
06-10-2010, 08:49 PM
Here is the log file.



=====================
=== ZenGL 0.2 RC4 ===
=====================
[00000000ms] Begin
[00000001ms] Current mode: 1152 x 864
[00000067ms] wglChoosePixelFormatARB: zDepth = 24; stencil = 0; fsaa = 0
[00000129ms] Create OpenGL Context
[00000130ms] Making current OpenGL context
[00000130ms] GL_VERSION: 1.3.0 - Build 4.14.10.4342
[00000130ms] GL_RENDERER: Intel 845G
[00000130ms] GL_MAX_TEXTURE_SIZE: 2048
[00000130ms] GL_ARB_TEXTURE_COMPRESSION: TRUE
[00000130ms] GL_EXT_TEXTURE_COMPRESSION_S3TC: TRUE
[00000130ms] GL_MAX_TEXTURE_UNITS_ARB: 4
[00000130ms] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 2
[00000130ms] GL_EXT_BLEND_FUNC_SEPARATE: FALSE
[00000130ms] GL_ARB_VERTEX_BUFFER_OBJECT: TRUE
[00000130ms] GL_EXT_FRAMEBUFFER_OBJECT: FALSE
[00000130ms] WGL_PBUFFER: TRUE
[00000130ms] Support WaitVSync: TRUE
[00000132ms] DirectSound: loading DSound.dll
[00000261ms] DirectSound: sound system initialized
[00000883ms] Texture loaded: "data/font-page0.png"
[00001153ms] Texture loaded: "data/halloween/Alien.png"
[00001284ms] Texture loaded: "data/halloween/Bat.png"
[00001400ms] Texture loaded: "data/halloween/Casper.png"
[00001525ms] Texture loaded: "data/halloween/Chucky.png"
[00001661ms] Texture loaded: "data/halloween/Devil.png"
[00001796ms] Texture loaded: "data/halloween/Dracula.png"
[00001927ms] Texture loaded: "data/halloween/Frankenstein.png"
[00002062ms] Texture loaded: "data/halloween/Freddie.png"
[00002256ms] Texture loaded: "data/halloween/Ghost.png"
[00002421ms] Texture loaded: "data/halloween/Gomez.png"
[00002540ms] Texture loaded: "data/halloween/Jack Skellington.png"
[00002660ms] Texture loaded: "data/halloween/Jason.png"
[00002784ms] Texture loaded: "data/halloween/Kokey.png"
[00002914ms] Texture loaded: "data/halloween/Mike.png"
[00003046ms] Texture loaded: "data/halloween/Mummy.png"
[00003160ms] Texture loaded: "data/halloween/Pumpkin.png"
[00003271ms] Texture loaded: "data/halloween/Scream.png"
[00003390ms] Texture loaded: "data/halloween/Skull.png"
[00003524ms] Texture loaded: "data/halloween/Slimer.png"
[00003650ms] Texture loaded: "data/halloween/Squash.png"
[00003653ms] Sound loaded: "data/click.wav"
[00003676ms] Texture loaded: "data/audio-stop.png"
[00003699ms] Texture loaded: "data/audio-play.png"
[00003893ms] Texture loaded: "data/zengl.png"

Andru
06-10-2010, 08:55 PM
Thanks for tests and logs. This weekend I will try to make a demo with second thread that will have own window and DC(maybe problem in one Device Context for two threads under Windows). Till that I will be waiting an answer from service centre, because today power supply from my PC died... :(

azrael11
07-10-2010, 04:31 AM
my pc is P4 3 GHz
Nvidia 8400 512Ram

Runs great ;)


=====================
=== ZenGL 0.2 RC4 ===
=====================
[00000001ms] Begin
[00000001ms] Current mode: 1024 x 768
[00001111ms] wglChoosePixelFormatARB: zDepth = 24; stencil = 0; fsaa = 0
[00001195ms] Create OpenGL Context
[00001211ms] Making current OpenGL context
[00001212ms] GL_VERSION: 3.3.0
[00001212ms] GL_RENDERER: GeForce 8400 GS/PCI/SSE2
[00001212ms] GL_MAX_TEXTURE_SIZE: 8192
[00001212ms] GL_ARB_TEXTURE_COMPRESSION: TRUE
[00001212ms] GL_EXT_TEXTURE_COMPRESSION_S3TC: TRUE
[00001213ms] GL_MAX_TEXTURE_UNITS_ARB: 4
[00001220ms] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 16
[00001220ms] GL_EXT_BLEND_FUNC_SEPARATE: TRUE
[00001220ms] GL_ARB_VERTEX_BUFFER_OBJECT: TRUE
[00001220ms] GL_EXT_FRAMEBUFFER_OBJECT: TRUE
[00001220ms] WGL_PBUFFER: TRUE
[00001220ms] Support WaitVSync: TRUE
[00001276ms] DirectSound: loading DSound.dll
[00001386ms] DirectSound: sound system initialized
[00001756ms] Texture loaded: "data/font-page0.png"
[00001891ms] Texture loaded: "data/halloween/Alien.png"
[00001997ms] Texture loaded: "data/halloween/Bat.png"
[00002098ms] Texture loaded: "data/halloween/Casper.png"
[00002197ms] Texture loaded: "data/halloween/Chucky.png"
[00002304ms] Texture loaded: "data/halloween/Devil.png"
[00002403ms] Texture loaded: "data/halloween/Dracula.png"
[00002500ms] Texture loaded: "data/halloween/Frankenstein.png"
[00002607ms] Texture loaded: "data/halloween/Freddie.png"
[00002711ms] Texture loaded: "data/halloween/Ghost.png"
[00002810ms] Texture loaded: "data/halloween/Gomez.png"
[00002903ms] Texture loaded: "data/halloween/Jack Skellington.png"
[00003000ms] Texture loaded: "data/halloween/Jason.png"
[00003102ms] Texture loaded: "data/halloween/Kokey.png"
[00003205ms] Texture loaded: "data/halloween/Mike.png"
[00003313ms] Texture loaded: "data/halloween/Mummy.png"
[00003408ms] Texture loaded: "data/halloween/Pumpkin.png"
[00003500ms] Texture loaded: "data/halloween/Scream.png"
[00003597ms] Texture loaded: "data/halloween/Skull.png"
[00003705ms] Texture loaded: "data/halloween/Slimer.png"
[00003803ms] Texture loaded: "data/halloween/Squash.png"
[00003824ms] Sound loaded: "data/click.wav"
[00003844ms] Texture loaded: "data/audio-stop.png"
[00003862ms] Texture loaded: "data/audio-play.png"
[00004009ms] Texture loaded: "data/zengl.png"
[00017844ms] Ogg: Initialized
[00040080ms] Average FPS: 197
[00040091ms] Timers to free: 2
[00040091ms] Render Targets to free: 0
[00040091ms] Atlases to free: 0
[00040091ms] Textures to free: 26
[00040126ms] Fonts to free: 1
[00040126ms] Sounds to free: 1
[00040132ms] DirectSound: sound system finalized
[00040197ms] End

code_glitch
07-10-2010, 06:45 AM
works 100% on both graphics cards (I have stretchable) with this spec:
windows 7 Hp 64 bit
4gb ddr3 ram
ATI 4330HD and GMA 4500MHD
SU4100 @ 1.3ghz

loaded great, and wuite fast. Cpu tops out at around 7-8% with a few megs of ram.

User137
07-10-2010, 09:50 PM
I was able to make my ImageViewer work with separate thread properly.

Execute doesn't free on exit but it sets Finished variable true. Main application loop checks in its start if Finished is set and then do the Finish; to bind texture and fill the data in with glTexImage2D().

TLoadThread = class(TThread)
private
fn: string;
texIndex: integer;
finished: boolean;
public
constructor Create(_texIndex: integer; _fn: string);
procedure Execute; override;
procedure Finish;
end;

constructor TLoadThread.Create(_texIndex: integer; _fn: string);
begin
inherited Create(False);
texIndex:=_texIndex; fn:=_fn;
finished:=false;
FreeOnTerminate:=True;
end;

procedure TLoadThread.Execute;
begin
tex.LoadTextureData(@tex.texture[texIndex],fn);
if terminated then exit;
finished:=true;
end;

procedure TLoadThread.Finish;
begin
tex.Restore(texIndex);
form1.loader:=nil;
form1.MakeDispList;
Terminate;
end;

ps. missing pascal tags...

Andru
07-10-2010, 10:41 PM
Execute doesn't free on exit but it sets Finished variable true. Main application loop checks in its start if Finished is set and then do the Finish; to bind texture and fill the data in with glTexImage2D().
Yeah, this is one of solution, but this is not so interesting as two independent threads :) And if I get a fail, I will use this method to load the resources(decoding in separate thread and uploading to videocard in main thread).

phibermon
09-10-2010, 12:14 PM
Hey guys, sorry been very busy lately. I'm going to be releasing JUI within the next month or so. It has a fully working multi-threaded resource loader, which does have an option for loading data (images, vertex etc) directly into an OpenGL context. But while you can do this, you really shouldn't, it's basically a waste of time. Since the render thread can't switch to back the context until the data has been uploaded, it's a lot simpler and more elegant to load data into system memory first, then copy the data across to the card in the render thread when it's ready. My resource loader is tied in with a generic scene-graph allowing you to do things like a streaming world AKA the Grand Theft Auto Series. A much better area of focus for your multi-threaded musings would be path finding and steering algorithms. Since both of these require simultaneous access to data along with the render thread, it's a lot more challenging and fun to solve :)

Andru
09-10-2010, 01:17 PM
phibermon

t's a lot simpler and more elegant to load data into system memory first, then copy the data across to the card in the render thread when it's ready
There is no fun if it simple, so... I will waste my time with fun first :)

phibermon
09-10-2010, 01:41 PM
It's not just simpler, it's the only rational solution. You can't load data to the card and render at the same time with OpenGL, at least not with version < 3.2. On higher versions you can use fence sync objects (http://www.opengl.org/registry/doc/glspec41.core.20100725.pdf - section 5.3). With your current method, you may be loading the data in seperate thread, but your main thread will be locking on GL calls until this load is complete and the context is switched back.

Your method will crash a PS3 and most older ATI cards too. Sorry :( I'm really not trying to be a killjoy but you're quite clearly a good developer and I feel your time would be better spent on learning about fence syncing, it was designed exactly for what you're trying to do.

EDIT : But I do agree, sometimes the best solution isn't the most fun :)