July 16, 2019, 06:10:58 AM

Author Topic: draw an image ?  (Read 939 times)

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 1951
Re: draw an image ?
« Reply #30 on: May 17, 2019, 02:18:58 AM »
Does anyone know if drawing several instance of a sprite with DrawSprite count for one draw call overall, or a draw call for each sprite ?
Drawing the same sprite multiple times doesn't really count as a draw call. Drawing different sprites from different textures does. This is the reason that using a sprite atlas for your sprites helps a whole heap as then you can draw hundreds of sprites from the same image rather than the GPU having to swap textures increasing draw calls. In a very basic nutshell drawing a sprite from a different texture is classed as a draw call.
Until the next time...

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: draw an image ?
« Reply #31 on: May 17, 2019, 05:53:24 AM »
I would have assumed that a draw stays to be a draw call (a polygon/quad with a texture[part] on it). Changing textures is a texture switch.

Both are "expensive" and the texture switch can get minimized by batching.


Bye
Ron

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1828
Re: draw an image ?
« Reply #32 on: May 17, 2019, 10:00:59 AM »
Quote
I would have assumed

You know what they say about assume, you make an ASS-out-of-U-and-ME.   Well make an ass out of Pingus in this case because he's the one asking and Derron is assuming ;D
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: draw an image ?
« Reply #33 on: May 17, 2019, 10:08:31 AM »
I needed to assume as I did not like to guarantee - Let's hope it is not an "End of the road" (prefer the "Gimme Gimmes" variant) ;-)

A draw call means (in my limited POV) to setup states, shaders, ... for an material thing. Dunno if AGK somehow merges together multiple images of one texture by arranging UVs on a bigger object (polygon instead of quad) or so.
I assume GaborD or other gfx gurus might be able to tell us more about it.


bye
Ron

Online blinkok

  • Full Member
  • ***
  • Posts: 103
Re: draw an image ?
« Reply #34 on: May 17, 2019, 10:35:49 AM »

Offline GaborD

  • Sr. Member
  • ****
  • Posts: 286
Re: draw an image ?
« Reply #35 on: May 17, 2019, 10:40:39 AM »
You have it right, Derron. New texture means new batch.
AGK doesn't combine sprite textures or such as far as I know. It does try to batch sprites if they have the same texture, so that's good.
Batch counts should be fairly low unless using tons of individual textures. Even lower if (as you guys already suggested) an atlas is used.

Generally, for a sprite based 2D game I wouldn't see batch count to be an issue, would be hard to not comfortably stay under the max amount the system can handle (usually in the thousands).
In almost every case the game will be fillrate limited, as usual. The stock sprite shader is extremely simple and fast though (one tex lookup and one multiplication in the ps).

The issues start when having thousands of batches, in this case severe CPU bottlenecking can happen, especially when each batch is tiny and can be executed superfast by the GPU.
The CPU will not be able to pack and send all the tiny geometry packets quickly enough to keep the GPU happy and the GPU will start idling inbetween, waiting for data. Thus you lose performance and your app becomes CPU bound instead of using the full power of the GPU.
But this should never be the case in a simple 2D game. That said, if someone exports to a 17 year old toaster, anything can happen :)

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 1951
Re: draw an image ?
« Reply #36 on: May 18, 2019, 03:26:14 AM »
Quote
You have it right, Derron. New texture means new batch.
Yes a texture switch is a new draw call. At least that's the version I'm more familiar with. No doubt these days with whizzy whizzy techniques it's not as straight forward as that anymore.

Quote
AGK doesn't combine sprite textures or such as far as I know. It does try to batch sprites if they have the same texture, so that's good.
AGK does try and batch sprites and does a great job when all your game sprites are part of the same texture. It has great throughput grunt on it's 2D engine.

Quote
The issues start when having thousands of batches, in this case severe CPU bottlenecking can happen
You are bang on with that. When dealing with 10'000's of sprites the only realistic option is for the GPU to handle that directly. Sending all that info into the GPU per frame is a real frame rate killer. From my own tests Tier 1 of AGK on a fairly decent setup can comfortably handle around 5000 sprites per frame + a good chunk of game logic.

Quote
You know what they say about assume
To quote Under Siege 2 - "Assumption is the mother of all fuck ups" ;D

Quote
Dunno if AGK somehow merges together multiple images of one texture by arranging UVs on a bigger object (polygon instead of quad) or so.
As mentioned above AGK does attempt to batch sprites together based on their texture. As AGK has atlas support built in it's a no brainier not to use it. It's much faster to use a texture atlas over individually loaded sprites.
Until the next time...

Online blinkok

  • Full Member
  • ***
  • Posts: 103
Re: draw an image ?
« Reply #37 on: May 18, 2019, 05:06:57 AM »
When you assume you make an ASS out of U and ME

Offline GaborD

  • Sr. Member
  • ****
  • Posts: 286
Re: draw an image ?
« Reply #38 on: May 18, 2019, 09:27:57 AM »
Quote
You have it right, Derron. New texture means new batch.
Yes a texture switch is a new draw call. At least that's the version I'm more familiar with. No doubt these days with whizzy whizzy techniques it's not as straight forward as that anymore.
Yep, "draw call" fits too, for a discussion about drawing sprites in AGK we can indeed ignore the whizzy whizzy and just see drawcalls and batches as referring to the function call or the data being sent.

From my own tests Tier 1 of AGK on a fairly decent setup can comfortably handle around 5000 sprites per frame + a good chunk of game logic.
That's the craziness of modern hardware.  :)
The GPU can comfortably handle a million moving sprites/particles (well, if they are big then you'll get tons of overdraw and fillrate will kill you ofcourse), but there is no way to control them on the CPU and push all the data over. Some trickery is needed.

It has great throughput grunt on it's 2D engine.
Agreed. AGK is so underrated.
People vastly underestimate how much power is available under the hood. Both in 2D and 3D. Learned that the hard way with the "fake!" complainers lol.

Agree on atlas usage for sprites. Always a good idea.

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
Re: draw an image ?
« Reply #39 on: May 19, 2019, 01:03:15 PM »
Hello
I come back...
I want to give a chance to AGK :)

If I unterstand, if i create 100 tiles, all the tiles will be on screen on the same time !!!!!

Does it mean that on each loop i should start by hide all the tiles (sprites) ?

for i=1 to 100
setspritevisible(i,0)
next

(instead of CLS or Clearscreen in other classic basic languages)

and then I decide which tiles I active + its position with :

setspritevisible(7,1)
setspriteposition(7,123,234)
sync()

is that correct ????

Offline Derron

  • Hero Member
  • *****
  • Posts: 2199
Re: draw an image ?
« Reply #40 on: May 19, 2019, 01:46:45 PM »
Qube wrote that it depends on the way you set the sprite up - relative positions or absolute positions.
Absolute positions: you need to draw them manually
Relative positions (percentage): automatic rendering except they are hidden


bye
Ron

Offline drfloyd

  • Jr. Member
  • **
  • Posts: 35
Re: draw an image ?
« Reply #41 on: May 19, 2019, 02:23:01 PM »
Yes, i used Pqube method but it doesnt work. Each sprite iI load is visible
Exemple with a empty loop :

Code: [Select]
SetVirtualResolution( 320, 240 )

temp=loadimage("cache.png")
cache=createsprite(temp)

// want to draw Nothing but it draw :/
do
//setspriteposition(cache,50,50)
       //drawsprite (cache)
 
    Sync()
loop


even without drawing the sprite, it display it at 0,0... It is for that reason i ask if I should do a setspritevisible(cache,0) at each loop ?

so i try another solution :

Code: [Select]
SetVirtualResolution( 320, 240 ) // doesn't have to match the window
cache=loadimage("cache.png")

do

setspriteposition(cache,50,50)
drawsprite (cache)

    Sync()
loop


the sprite does not appear, but when i activate drawsprite, it say that the sprite does not exist...


Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 1951
Re: draw an image ?
« Reply #42 on: May 19, 2019, 03:47:56 PM »
Quote
Yes, i used Pqube method but it doesnt work. Each sprite iI load is visible
All you keep saying is "Doesn't work"  ::) - READ THE MANUAL :P

If you read the manual you'll see that your code should be :

Code: [Select]
SetVirtualResolution( 320, 240 )

temp=loadimage("cache.png")
cache=createsprite(temp)

// want to draw Nothing but it draw :/
do
       setspriteposition(cache,50,50)
       drawsprite (cache)
 
    Swap() // THIS IS WHAT YOU USE IF YOU ONLY WANT SPRITES TO SHOW WHEN DRAWN WITH THE DRAWSPRITE COMMAND
loop

Sync() will draw all sprites unless hidden.
Swap() with ONLY draw sprites that you've drawn with the DrawSprite command and does not require you to hide sprites.
Until the next time...

Offline GaborD

  • Sr. Member
  • ****
  • Posts: 286
Re: draw an image ?
« Reply #43 on: May 19, 2019, 03:59:52 PM »
@drfloyd
Keep in mind Swap() will not auto draw anything, no 3D, no sprites, no print commands (text is also in Render2DFront(), just like sprites.)
Just adding this so you don't eventually wonder why your print commands suddenly don't work. :)

Just to clarify:
Sync() is a shortcut for
Update(), Render(), Swap()

Render() is a shortcut for
Render2DBack(), ClearDepthBuffer(), Render3D(), ClearDepthBuffer(), Render2DFront()


Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 1951
Re: draw an image ?
« Reply #44 on: May 19, 2019, 04:07:39 PM »
@drfloyd
Keep in mind Swap() will not auto draw anything, no 3D, no sprites, no print commands (text is also in Render2DFront(), just like sprites.)
Just adding this so you don't eventually wonder why your print commands suddenly don't work. :)

Just to clarify:
Sync() is a shortcut for
Update(), Render(), Swap()

Render() is a shortcut for
Render2DBack(), ClearDepthBuffer(), Render3D(), ClearDepthBuffer(), Render2DFront()
One step at a time, he's not got the hang of drawing sprites yet :P
Until the next time...