• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

pbDex3D (the fundamentals of any 3D graphic engine)

Started by Patrice Terrier, August 02, 2007, 07:25:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

pbDex3D

This was a huge work to tanslate this piece of code to PB.

It shows you the common basis to all 3D engines (how things are done under the hood).

It uses my own animation technic to save CPU resources, to be cooperative with other running application, usualy it takes only 1 to 2% of the CPU cycles, instead of the 50% CPU found in most application that are based on the MSDN animation message pump example.

Here is the message pump animation being used:

          CALL SetTimer(hMain, 1, 0, %NULL)
          WHILE GetMessage(Msg, %NULL, 0, 0)
                CALL TranslateMessage(Msg)
                CALL DispatchMessage(Msg)
          WEND
          CALL KillTimer(hMain, 1)


simple isn't it?

Patrice Terrier
www.zapsolution.com
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

José Roca

#1
 
Hi Patrice,

Great tip!

I have modified the message pump in the dx9_primitive_types example from:


   WHILE msg.message <> %WM_QUIT
      IF PeekMessage(msg, %NULL, 0, 0, %PM_REMOVE) THEN
         TranslateMessage msg
         DispatchMessage msg
      ELSE
         RenderD3DScene
      END IF
   WEND


to:


   SetTimer(g_hwnd, 1, 0, %NULL)
   WHILE GetMessage(msg, %NULL, 0, 0)
      TranslateMessage msg
      DispatchMessage msg
   WEND
   KillTimer(g_hwnd, 1)


and added this to the WndProc callback function:


   CASE %WM_TIMER
      RenderD3DScene
      EXIT FUNCTION


and CPU usage is now 2% instead of 100%. Also it repaints in real time when resizing the window, solving the two problems, CPU usage and repainting, at the same time!

Petr Schreiber

#2
This is very good technique,

Patrice advised it for my thinEdge 3D editor and according to my tests so far it really dropped to about 2% for classic models and about 12% for complex models. It is amazing trick. Now I have to tune other features of the program :)


Thanks,
Petr

P.S. And PBDex is very cool too!
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Patrice Terrier

#3
Yes, it is kind of magic, this is the technic being used in GDImage either with OpenGL or pure GDImage,
and it works with everything including L5G applications like WinDev.

It is even more cooperative than WPF, and takes less resources than it, and no need to limit the frame rate to 30 fps as Microsoft does with WPF.


Indeed this message pump animation is a very good example of superiority of SDK over everything else,
because you control the low level message pump directly yourself.

Also very easy to create your own modal message pump if you need one.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Kent Sarikaya

Ok, now I am lost... I see no directX or openGL.

Does this mean all the graphics are being done by the CPU?

If so, this would be like selecting a software renderer correct and bypassing the GPU?

Thanks for the post, it looks like a very complete set of functions that should be available in all engines.
Lots to study in this one, thank you very much Patrice!

Paul Squires

Quote from: Patrice Terrier on August 02, 2007, 09:17:19 PM
...I have learned this and many other things from my Master Ethan Winer.
You and me both! At the time, Ethan's book really opened my eyes to the various methods to make more efficient code. I read and re-read that book literally hundreds of times. I emailed Ethan several years later to thank him for his work and I got a very nice response from him. Great guy, great coder.

Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

Kent Sarikaya

#6
Thanks Patrice, I don't have .net installed at all at the moment, so I will try the pbversion now.
Thanks.

Just ran it, wow really cool stuff and fast !! thanks.

Patrice Terrier

The first post of this thread has been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com