Why Did They Tile Their Images?
Sometimes images in your game are tiled. This is done to help the graphics processor render the graphics faster.
The graphics processor is divided into subunits and each of these is able to draw graphics. To obtain the best performance, it's necessary to keep all of these units busy. In a tiled image, the image is divided into tiles and each is assigned to a subunit, so the image can be drawn quickly.
Note: For standard images this happens too. However, it's more work for the graphics processor's main unit, because for standard images, the image has to first be cleaved into tiles and then assigned to each subunit.
What is a Tiled Image?
Here is what our example image looks like in standard format. I've rendered the images in text format so you can more easily see them. Our image is a 4 x 4 pixel image. This is what it looks like as a standard image:
0123 4567 89AB CDEF
As a simple string of pixels, our image looks like: 0123456789ABCDEF
When game developers made tools to make their game, they decided on a tile size that's based on the properties of the graphics processor of the hardware their game was supposed to run on. The tile size will be different depending on the graphics processing hardware. A general rule of thumb is tile sizes tended to get larger as time moved forward.
We're going to divide our image into four tiles: 0145, 2367, 89CD and ABEF. As a string of pixels, our tiled image looks like 0145236789CDABEF. Now the GPU needs to hand them out to subunits, enough for one tile at a time. It does not need to apply an offset to get the next row of pixel data- the data is said to be tiled- ordered ahead of time for efficient rendering.
If we try to render tiled pixels in standard order, we get garbage- the pixels are out of order for standard rendering, such as in an image viewer program. So we need to conduct the untiling process.
- First we make an empty buffer of 16 pixels. Then we go by tiled pixels.
- When starting each tile we move the buffer position counter to the top-left of the tile.
- We copy tile_width worth of pixels, then move the buffer position counter down one row. We do this once for each pixel in the tile height.
Untiling Sample Code