Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 6:09 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Oct 20, 2011 6:26 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
Say I have a lot of images. What is the best way to render these performance wise?

* Just draw them all

* "combined" them to a large image (offline) and render just one big image

* Use some type of frame buffer?

* other?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 6:44 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Depends on the situation. A static background/map might be better off combined. HUD elements can be simply rendered. If you need further optimizations you can look into CachedRender, renderInUse, etc.

Check out the test I posted here which demonstrates a few different rendering techniques:
http://slick.javaunlimited.net/viewtopi ... 3217#23217


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 7:15 am 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
1) best draw images in batches, where in a batch are "same" images.. with same texture.
For example if you have to render 1000 objects of 10 types (10 different images), first render all images of one type, then second and so on. That's all I can think of now that I know will directly be faster. If you are wandering why, it's because when you render a texture you must tell opengl what texture it will be so it can prepare. Every time you render another image (texture) it must be told to prepare, but there wont be that overhead if you keep rendering same texture over and over.

2) also don't use blending if you don't have translucent images, the ones with alpha channel.

3) using FBO or any offscreen rendering will just be slower as you must render that final image to screen. No benefit AFAIK.

4) everybody should be aware of this already... but just in case: don't render the image if it's not actually on the screen.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 7:26 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Kova wrote:
3) using FBO or any offscreen rendering will just be slower as you must render that final image to screen. No benefit AFAIK.

In the case of, say, a grid or tiled map, where the many images together do not need to change over time, and thus can be combined into a single image, there is a huge improvement since you are only rendering once per frame instead of X images per frame.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 12:36 pm 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
davedes wrote:
Kova wrote:
3) using FBO or any offscreen rendering will just be slower as you must render that final image to screen. No benefit AFAIK.

In the case of, say, a grid or tiled map, where the many images together do not need to change over time, and thus can be combined into a single image, there is a huge improvement since you are only rendering once per frame instead of X images per frame.


As I see it, FBO is just another "screen" for OpenGL, or should I say when rendering to screen that is actually default FBO. If you render to screen or your own FBO either way it calculates same thing, it only goes to different places. I agree that with lots of static images that rendering to FBO in batches and then using that in next frames (like next 10 frames or player doesn't move the camera maybe much more) will be performance boost as you said.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 4:47 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
wow! Thanks guys! Lots to think about!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2011 5:19 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
davedes wrote:
Kova wrote:
3) using FBO or any offscreen rendering will just be slower as you must render that final image to screen. No benefit AFAIK.

In the case of, say, a grid or tiled map, where the many images together do not need to change over time, and thus can be combined into a single image, there is a huge improvement since you are only rendering once per frame instead of X images per frame.


This gives a noticeable FPS boast here (~101 average to ~123 average). On my 260GTX it goes from 32 fps to 968 fps! Insane.

This is rendering 32*32*9 tiles. I'm not even drawing images yet, but I do have some draw shapes (per title, just a rect that outlines it). I'll have to retest once I have images.

I take all tiles, draw them to a FBO. Once I have that, I just render the entire thing (instead of each tile).

Once on startup:
Code:
target = new Image(GameConfig.DEFAULT_MAP_SIZE_X_IN_PIXELS, GameConfig.DEFAULT_MAP_SIZE_Y_IN_PIXELS);
gTarget = target.getGraphics();

{draw to gTarget}
gTarget.flush()


Then every render:
Code:
target.draw();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2011 11:04 am 
Offline
Regular
User avatar

Joined: Thu Mar 12, 2009 9:52 am
Posts: 142
Location: Portugal, Lisbon
You can also use the imagebuffer and build a big image from several small images.

I use them for maps, windows, backgrounds made of several images.

On Image creation I group up all images and then just obtain a handle to a unique image.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2011 3:55 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
Spiegel wrote:
You can also use the imagebuffer and build a big image from several small images.

I use them for maps, windows, backgrounds made of several images.

On Image creation I group up all images and then just obtain a handle to a unique image.


This class?
http://slick.cokeandcode.com/javadoc/or ... uffer.html

How do you add images to it, I only see a setRBGA and doing it pixel by pixel seems like it would take forever. Have any examples?


Top
 Profile  
 
PostPosted: Fri Jan 27, 2012 6:11 am 
Offline

Joined: Mon Jan 23, 2012 9:40 pm
Posts: 12
I also have a question with the ImageBuffers, I am managing a background of several images and am trying to write an image on top of the background image. The problem arises when i do a setRBA on the background image trying to reset the pixels to those of the new image im trying to draw ontop of it. Basically, i edit a square of the image and then the image randomly contains a ton of separate vertical lines and i have no clue how they ended up that way... Any ideas guys? i have no clue what is causing this error, nor do i know how to fix it... =/


Top
 Profile  
 
PostPosted: Fri Jan 27, 2012 8:16 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
If you can provide a test case, we can start tracking down where the problem/bug is coming from.

Also be sure to look into "image graphics" (FBO) through image.getGraphics as it is much more efficient than setting each individual pixel.


Top
 Profile  
 
PostPosted: Fri Jan 27, 2012 8:50 pm 
Offline

Joined: Mon Jan 23, 2012 9:40 pm
Posts: 12
Ok, well i have a screen shot for the problem and the code that is causing the problem in this thread:
viewtopic.php?f=3&t=4465&p=25613#p25613

if you need any more information than that just let me know...


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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