PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Surface Size

I was thinking of putting most of my images into one big surface.

It would be 240x4800 in size, and probably about 200KB.

Is this too large? Or will it be alright?
That's not a problem. I've used much larger image sizes and it works fine.
Is there any information on which is generally better: a number of smaller individual surfaces, or one giant one that you blit portions of?

I'm thinking in terms of performance and efficiency (memory-wise mainly) of one vs. the other. Any appreciable difference in load times? (I'd guess it takes just as long to decode a larger image as a number of small ones).

I've always been curious about this... I tend to favor the individual surfaces just because I percieve it being a little easier to swap in new graphics, but if there's some real technical merit to one big "graphics sheet", I'd love to know.
I believe memory wise, a single 'sheet' is more efficient due to the minor overhead of each CGapiSurface. Load time should be a minimally faster as well because you're only creating a single CGapiSurface and performing a single file load rather then numerous ones. However, you have no easy way to present a 'loading' progress meter using a single large surface.
mlepage wrote:I was thinking of putting most of my images into one big surface.

It would be 240x4800 in size, and probably about 200KB.

Is this too large? Or will it be alright?


Blitting small parts from this big surface to the backbuffer is very inefficient in terms of cache usage.
An advice to get both cache efficiency and fast loading time :

Load all your surfaces in memory and dump this big memory chunk to a binary file, then compress it (lz algo).

Your loading time will be greatly decreased...

Of course this have to be done only when the game is in it's "gold" stage...
Another nice thing would be to combine sprites and images with "almost" the same colors in one imagemap and then others into another and let them share the same palette. This will decrease the filesizes of your images. However, this doesn't matter much to PNGs, but I still save a few hundred KBs by doing this.
egarayblas wrote:Another nice thing would be to combine sprites and images with "almost" the same colors in one imagemap and then others into another and let them share the same palette. This will decrease the filesizes of your images. However, this doesn't matter much to PNGs, but I still save a few hundred KBs by doing this.


Putting several sprites in one file is a well known techniques for videogames...

My engine use a format that enable the loading of all the sprites in an image with only one call to the loading function.

Example :
Attachments:
hud.gif
StephC wrote:My engine use a format that enable the loading of all the sprites in an image with only one call to the loading function.


Same with our SpriteEngine. It's a common method of sprite loading and much more efficient than loading individual frames.
Thanks for the tips!

For me, this is less sprites than whole screens. My upcoming game uses non-rectangular sprites so it's a bit different in this respect. Hopefully I'll be announcing it later this week so you'll see what I mean.

So of my 240x4800 surface, I'll always be dealing with particular areas of 240x240 within it. The cache problems for me are, even within those areas I'll be only taking out arbitrary span lines (not full lines), and I'll be using 240x240 areas in no particular order.

I can probably rework my code to at least access the 240x240 areas in order and see if that helps any. But so far it's plenty fast enough I think so long as I can have this one big surface.
It seems to work. However, if you don't have enough free memory it will fail to load the surface. I might try splitting it into two relatively large surfaces to see if this alleviates the problems. (Plus, I only need one of those two surfaces for any particular game play mode, so I can free one if necessary.)