Page 1 of 1
Sprites 3D question...
Posted: Thu Oct 16, 2003 1:21 pm
by lethalpolux
Another little thing:
why is it better to display all sprites 3D at the same time ( after Start3D(), display all sprites, Stop3D())..?
Is it more faster?
Because it's not evident to do that.
I want to know if it is valable to modify my code ( at the moment, i display my sprites 3D when i need them and i put start3D() and Stop3D() every time ).
Thanx
Posted: Thu Oct 16, 2003 5:35 pm
by Codemonger
It is faster to put the code between Start3D and Stop3D, because Directx would not have to make as many state changes and it can flush the sprites to the gpu all at once. But seeing as they are just 3d sprites and if you are running a fast Cpu you probably wouldn't notice a speed difference at all, unless you start to max out the number of sprites you are using, then you will notice a speed decrease. Anyway just my thoughts, all in all I wouldn't worry too much about it.
As far as organising your code it probably would be better and more efficient to have your sprites lumped together.

Posted: Thu Oct 16, 2003 6:56 pm
by coma
I have made some tests :
Code: Select all
InitSprite() : InitKeyboard() : InitSprite3D()
OpenScreen(800,600,16,"")
CreateSprite (0,64,64,#PB_Sprite_Texture)
CreateSprite3D(0,0)
CreateSprite (1,64,64,0)
;draw a circle on each sprite
StartDrawing (SpriteOutput(0))
FrontColor (128,0,0) : Circle (32,32,32)
StopDrawing()
StartDrawing (SpriteOutput(1))
FrontColor (0,0,128) : Circle (32,32,32)
StopDrawing()
Repeat
ExamineKeyboard ()
ClearScreen (0,0,0)
;FIRST LOOP
timer = TimeGetTime_()
Start3D()
For i=0 To 5000
DisplaySprite3D(0,320,240,255)
Next
Stop3D()
For i=0 To 5000
DisplayTransparentSprite (1,400,240)
Next
timer1 = TimeGetTime_() - timer
;SECOND LOOP
timer = TimeGetTime_()
For i=0 To 5000
Start3D()
DisplaySprite3D(0,320,240, 255)
Stop3D()
DisplayTransparentSprite (1,400,240)
Next
timer2 = TimeGetTime_() - timer
StartDrawing(ScreenOutput())
FrontColor (255,255,255) : DrawingMode (1)
Locate (200,50) : DrawText ("loop 1 : "+Str(timer1)+" ms")
Locate (200,65) : DrawText ("loop 2 : "+Str(timer2)+" ms")
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
In the first loop, I draw 5000 3d sprites (start/stop3d outside the loop), then 5000 classic sprites.
In the second loop, the I draw alternately a 3d sprite and a classic sprite (start/stop3d inside the loop).
Something strange is that in 32 bit screen mode, the difference between the two loops decrease a lot (almost same time for both).
Posted: Fri Oct 17, 2003 12:40 am
by vanleth
I get a "Error in line 24: Start3D() must be called before DisplaySprite3D()" in your test code
Think you need to have only one Start3D() and Stop3d() in you main flipbuffer() loop.
I do not know for sure, but my guess is that routines like Start3D() is optimized to work within a single flipbuffer() cycle. So using more Start3D() within a flipbuffer() cycle could give various results on different systems.
As for the speed difference in 16 bit mode vs. 32 bit I wouldn't be surprised performance would be better in 32 bit, since newer 3D cards often perfroms better in that mode.
Just my thoughts
Van
Posted: Fri Oct 17, 2003 12:48 am
by coma
the code works perfectly here.....
You can use a lot of start3d/stop3d in your main loop, no problem.
And in a game, it's very usefull to put some 3d sprites behind the classic sprites (shadows...) and others 3d sprites in front (smoke, light...).
Posted: Fri Oct 17, 2003 12:58 am
by vanleth
With debugger on, i only get around 4 cycles before the above Start3D() error halts the code.
Nvidia Geforece4 Mx440 (45.33 Driver), DirectX 9
Posted: Fri Oct 17, 2003 1:04 am
by coma
strange... Probably a bug.
Are you using pb v3.80 ?
And if you remove the second loop ?
Posted: Fri Oct 17, 2003 1:05 am
by vanleth
Yep using 3.8
Posted: Fri Oct 17, 2003 1:12 am
by vanleth
Tested it abit more, and it seems that Escaping the test code with 'ESC' works very slow on my system. So in my restless mude, I've Alt-Tabbed out of the program to quickly and then i get the Start3D() error. Without beeing restless it works, but it takes 10 secs to quit the app and it dosn't display the "loop1" and "loop2" text.
It works better ,not perfect, with one loop only. Still i don't get any text info
Posted: Fri Oct 17, 2003 1:21 am
by coma
ok :)
so, try to reduce the number of displayed sprites. 500 instead of 5000 in the loops for exemple.
Posted: Fri Oct 17, 2003 1:25 am
by vanleth
if i remove all Start3d() stuff and what's inside it, the StartDrawing() info Text shows, else it won't.
And reducing the sprite numbers helps on Escaping out
Posted: Fri Oct 17, 2003 8:18 am
by lethalpolux
Thanx codemonger,coma!
But it seems that sprites 3D works better when you use only one Start3D/Stop3D in code ( with GF4 MX it's sure! ).. I've made the tests with my Geforce 4TI4200 128Mo, no problem, but the same program with a GF4 MX 64Mo slow down about 10/20 fps...
Put only one start3D/Stop3D have reduced this difference(5/10)... and i put always sprite3D on sprite2D ( with a little modified code )

To solve the problem of the fps' decrease, i've deleted 5/6 sprites 3D... and the performance returns...
Posted: Fri Oct 17, 2003 10:10 am
by Fred
Yes, if possible use only one Start3D()/Stop3D per loop as it initialize the little 3D engine every time.
Posted: Fri Oct 17, 2003 10:18 am
by lethalpolux
Thanx fred!

But, what is the limit of sprites 3D.. video card memory,chipset?
What make my code run faster on my GF4TI 128Mo than the same on a GF4MX 64Mo ( with same PIV and memory )..?
how to optimized ( if it's possible )?
I'm happy to see you again fred.
( LJ2 : 45% coded - if you want to test the beta... soon )