Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 7:50 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Apr 30, 2012 10:24 am 
Offline

Joined: Sun Apr 08, 2012 2:13 pm
Posts: 18
Hello again, as I am moving forward, I wonder, what's the big difference of rendering a tile map with each tile separately and using the sheet with startUse, renderInUse, endUse? I haven't spotted any, but ofcourse can't tell anything about the performance drops, since my laptop cpu adapts it's frequency to the load, and FPS remains similar under any circumstances, unless I am making it work full speed+turbo boost(while gaming). :?


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 10:50 am 
Offline
Regular
User avatar

Joined: Thu May 05, 2011 8:35 pm
Posts: 231
Location: Somewhere between the bits and bytes
I wrote this a while ago but i think it answers your question, I know my example isn't about tilemap, but should be exactly the same thing happening.
The best way to tell the performance difference is by uncapping the fps, if you haven't already tried that.

_________________
For every new problem, a new source of solutions has come to exist.


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 12:07 pm 
Offline

Joined: Sun Apr 08, 2012 2:13 pm
Posts: 18
Thanks, it explained a lot. :> Why I asked this is that I'd like to modify the spritesheet subimages before drawing them, like scaling or filters. Seems like I could just control the drawing myself by starting the use of spritesheet and then drawing embedded the parts of it, following by end use of the spritesheet at the end? Will this keep the same performance? :?

And yes, I have my fps uncapped. No matter how much usage I feed the cpu, it tries to stay at 800FPS. It's the normal intel mobile i7 behaviour, everything's so "optimus" to save battery life, including the video card. :D


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 4:46 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Quote:
Why I asked this is that I'd like to modify the spritesheet subimages before drawing them, like scaling or filters.

Depending on what you need, this might be an expensive operation. What kind of filters are you applying?

  • Don't use getImage for each sub-image. getImage needs to allocate a new OpenGL texture, which will require a new texture bind (and will give you errors with startUse/endUse). The performance will drop significantly if you need to bind many new textures. Ideally, you should be binding as few textures per frame as you possibly can, for maximum performance.
  • Something like scaling or rotation requires no modification of the sub-image's texture; instead, just pass different values to drawEmbedded (look at the latest dev branch for rotation).
  • Always think about how you can reduce draw calls and texture binds!
  • Try micro-benchmarking with milliseconds per frame, or try your game on different machines. If you still need better performance, Shaders would definitely be an option.


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 9:35 pm 
Offline

Joined: Sun Apr 08, 2012 2:13 pm
Posts: 18
Performance is not what is hitting on me, I am just keeping it in my concern. On my laptop (i7 quad, GT555m) it goes 840+- fps no matter what load I give it, unless it's an overhaul. My old machine with pentium 4 gets 2300FPS and gradually going down with stress tests. The main idea of my question was, how can I, for example, scale or colour a single tile, but leave others intact and still use renderInUse method properly?


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 10:02 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Code:
...init...
subImage1 = spriteSheet.getSubImage(...);
subImage2 = spriteSheet.getSubImage(...);

...render...

//startUse binds the color white
spriteSheet.startUse();

//draw our sprite with default size
subImage1.drawEmbedded(x, y, subImage1.getWidth(), subImage1.getHeight());

//draw our sprite with a new size
subImage1.drawEmbedded(x2, y2, 50, 50);

//we can bind a different colour if we want
Color.blue.bind(); //or Graphics.setColor(Color.blue);
subImage1.drawEmbedded(x3, y3, 50, 50);
subImage2.drawEmbedded(x4, y4, 50, 50);

//bind white again to reset the color filter
Color.white.bind();
subImage2.drawEmbedded(x5, y5, 25, 25);

//finish rendering the sheet
spriteSheet.endUse();


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 11:08 pm 
Offline

Joined: Sun Apr 08, 2012 2:13 pm
Posts: 18
I see, thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group