-1

Im working on isometric 2D tile engin for RTS game. I have two ways how can I draw floor. One option is one big image (for example 8000px x 8000px have about 10MB) and second option is draw images tile by tile only in visibly area.

My questin is what is better (for performance)?

Earlgray
  • 647
  • 1
  • 8
  • 31
  • 2
    What have you tried? Answers about performance will vary greatly based on implementation. And [premature optimization is the root of all evil](http://c2.com/cgi/wiki?PrematureOptimization) – crthompson Jan 05 '14 at 01:20
  • As pagogomez hinted, first make it work, then make it work better. If you will encapsulate background drawing code in neat class, then you will be able to replace it later on for better version without messing up rest of code. Well planed classes are more important than a bit of speed in creating new project, so just draw solid bitmap for now and focus on important parts instead. – PTwr Jan 05 '14 at 01:41

1 Answers1

1

Performance-wise and memory-wise, a tiled approach is better.

Memory-wise: If you can use a single spritesheet to hold the textures of every tile you need to render, then the amount of memory used would decrease tremendously - as opposed to redefining textures for tiles you want to render more than once. Also, on every texture there is an attribute called "pitch". This attribute tells us how much more memory is being used than the image actually needs. What? Why would my program be doing this? Back in the good old days, when Ben Kenobi was still called Obi Wan Kenobi, textures took up the memory they were supposed to. But now, with hardware acceleration, the GPU adds some padding to your texture to make it align with boundaries that it can process faster. This is memory you can reduce with the use of a spritesheet.

From a performance standpoint: Whenever you draw a regular sprite to the screen, the graphics hardware requires three main pieces of information: 1) The texture you want to render from. 2) What part of that texture you want to render from. 3) Where on the screen you want to render to. Repeat for every object you want to render. With a spritesheet, it only passes data once - a big performance increase because passing data from the CPU to the GPU (and vice-versa) is really slow.

And I disagree with the two comments, actually. Making a change of this caliber would be difficult when your program is mature.

Proxy
  • 1,824
  • 1
  • 16
  • 27