iPhone Scroll Performance - Polys vs Drawsprite vs Drawanim

Previous topic - Next topic

kaotiklabs

Is there any performance difference between using drawanim with just one fixed frame or a simple drawsprite?
Thanks in advance.
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Schranz0r

Hmm... i think DRAWSPRITE are a littlebit faster... but POLYVECTOR are much faster :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

kaotiklabs

I can image that drawanim is slower because has to handle the animation but I don´t get the difference between drawsprite and polyvector altought I´ve read several times that is faster.
Can you explain the differences a little deeper?

I ask you this because coding an iPhone app I tried to use polyvector instead of drawsprite on a simple scroll algorithm and got better results with drawsprite.



Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Kitty Hello

on the iPhone a POLYVECTOR is much faster _if_ you draw a lot of triangles in between STARTPOLY and ENDPOLY. That's because the calls to glDrawArrays should be limited on the iPhone chip.

FutureCow

What about not on an iPhone  - should I create a custom "drawanim" function that creates a polyvector instead and use it in place of any "drawanim" commands?

doimus

Quote from: Kitty Hello on 2009-Oct-28
on the iPhone a POLYVECTOR is much faster _if_ you draw a lot of triangles in between STARTPOLY and ENDPOLY. That's because the calls to glDrawArrays should be limited on the iPhone chip.

Now I think I get it:

We use POLYVECTOR to define sort of "planar 3D object" with certain texture, and then draw parts of that object with start/end poly.

So if I'm drawing a 2d platformer with lots of tiles (ground, sky, stairs, player, enemies, coins, whatever) and if I put all those tiles on a single texture, and then draw it all inside one POLYVECTOR command it would be treated as ONE draw-call?

So, my dream of having 16-bit style rpg/platformer with lots of tiles would indeed be possible on iPhone...
Oh man, I HAVE to buy myself a Mac finally... oh priorities in life, oh the fate... :'(

kaotiklabs


Sorry but I don´t get the point.

How could I draw the entire screen composed with several tiles using just one startpoly-endpoly call?
How should I asign the different textures?

I have tried to do it using one call for each tile but don´t know how to draw the full tile screen with just one call.

Maybe colud you post some example?
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Kitty Hello

The same as you would do with DRAWANIM. Just put several tiles on one image. Here's what I use for Wumbo:

Code (glbasic) Select


STARTPOLY sprite_id%, TRUE
FOR x=0 to 100
  FOR y=0 to 100 ...
    pQuad(hit[x][y], x*32, y*32)
  NEXT
NEXT

FUNCTION pQuad%: i%, x,y
IF g_polydraw%=FALSE; DRAWANIM 0, i, x,y; RETURN; ENDIF

LOCAL tx, ty
tx = MOD(i, 20)*32
ty = (i/20)*32
LOCAL txh=tx+32
LOCAL tyh=ty+32
LOCAL xw=x+32, yw=y+32
POLYVECTOR x,   y,  tx, ty, 0xffffff
POLYVECTOR x,   yw, tx, tyh,0xffffff
POLYVECTOR xw,  yw, txh,tyh,0xffffff

POLYVECTOR xw,  yw, txh,tyh,0xffffff
POLYVECTOR xw,  y,  txh,ty, 0xffffff
POLYVECTOR x,   y,  tx ,ty, 0xffffff
ENDFUNCTION

kaotiklabs

#8
Thanks for the code, Gernot.
Don´t know why but I didn´t understand the polyvector tx, ty textures coordinates.

I have modified my code using polyvectors and my frame speed is near the same as with drawsprite. Is not faster.  :'(
I´m drawing between 110 and 150 tiles per frame (using 2 startpolys calls, because I have 2 scroll layers), each tile is 32x32.

With such a quantity of triangles, shouldn´t I see some perfomance improvement with polyvector?
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Kitty Hello

I have no idea. My game came a bit faster this way.

Schranz0r

Quote from: kaotiklabs on 2009-Oct-28
I have modified my code using polyvectors and my frame speed is near the same as with drawsprite. Is not faster.  :'(
I´m drawing between 110 and 150 tiles per frame (using 2 startpolys calls, because I have 2 scroll layers), each tile is 32x32.


You have to draw only visible tiles on the screen!
Thats much faster, i made a map with 3 layers and > 1 mio. tiles on it ;)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Moru

My tile engine draws 2400 tiles on the screen in eight layers with 60 FPS on a GP2X :-) Sounds like the iPhone is more tricky to program for?

kaotiklabs

Quote from: Moru on 2009-Oct-29
My tile engine draws 2400 tiles on the screen in eight layers with 60 FPS on a GP2X :-) Sounds like the iPhone is more tricky to program for?

Yes ,you are right, is not as fast as I thought.

Quote from: Schranz0r on 2009-Oct-29
You have to draw only visible tiles on the screen!
Thats much faster, i made a map with 3 layers and > 1 mio. tiles on it ;)

Schranz0r I´m not sure if I understand you.
I´m not drawing total transparent tiles but I´m drawing tiles on the background that are overlaped but tiles on the foreground. If you are refering to the second option, I don´t imagine how to calculate and avoid this drawing. any idea?

I also have tried to use alphamode with a startpoly-endpoly but divides the performance per 2  :'( Using drawsprite was quite fast.
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Moru

I think he means that you don't need to draw tiles that are outside the screen at the moment but I'm sure you don't do that anyway.

kaotiklabs

Of course I´m not doing that way, I promise I read scroll lesson 1  =D

If it helps, I´m posting here one of the scroll loops.
With this code I´m only getting a very jumpy framerate of 32-46 fps, using two scroll layers.
Its a 32x32 tile based system, 16 files , 8 columns
As I´m using a background image, tile 0 is used for not drawing the tile in order to show the background image and save transparency calculations.

Code (glbasic) Select

//=============================================================================
SUB LayerDRAW:
//=============================================================================
LOCAL x%,y%,dx%,dy%,p%

p=INTEGER(scrollx / 32 /2)*8
dx=0-(bAND(scrollx,63) /2)

STARTPOLY imglevel00, TRUE
FOR x=0 TO 15
dy=0
FOR y=0 TO 7
IF Layer.Map[p] <> 0 then PolyQuad(Layer.Map[p], dx, dy)
INC dy,32
INC p,1
NEXT
INC dx,32
NEXT
ENDSUB


Quote from: Moru on 2009-Oct-29
My tile engine draws 2400 tiles on the screen in eight layers with 60 FPS on a GP2X :-)

Moru, maybe are you talking about your published tilemap engine?  If it is, I will take a look to the code...
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!