Monday, October 25, 2010

Proposal for GPU accelerated drawTriangles/masks on iPhone

I have a game whose foreground layer is composed of a horizontally and vertically repeating texture. The level data is loaded from an Inkscape generated svg file, and the level is way too large to bitmap cache. It would take .5 gb to cache my 20,000 x 5,000 pixel levels. The terrain texture is masked a Shape that is generated from the svg level data. This means that currently, the terrain cannot be hardware accelerated.

I also draw a horizontally repeating floor and ceiling texture on the top and bottom edges of the terrain, similar to how the terrain is drawn in the Worms games. Those textures are drawn using Graphics.beginBitmapFill and Graphics.drawTriangles. These items are also difficult to hardware accelerate.

My thought is this, create an air build of my application that writes a giant png snapshot of the entire level. A native OSX/Win32 utility processes the png, producing a sequence of large atlas pngs with all the unique tiles from the level snapshot and an xml file with indices that point to the unique tiles in the atlases. Then, the game render loop can render the foreground layer using full hardware acceleration, converting the altases into small GPU accelerated bitmaps that are tiled to draw the foreground.

One advantage of this scheme is that small tiles can compress the level to a smaller amount of bitmap data in the atlases, and the bitmaps that are scrolled across the screen to represent the foreground layer can still be a multiple of the tile size. This allows a very smooth and flexible assembly of the bitmap resources that are required for hardware acceleration, without requiring a great amount of runtime memory usage, or requiring the slowdown of rendering a very large object to many smaller bitmaps. The CPU cost to assemble these new bitmaps before they scroll onto the screen can be spread out evenly over a few frames.

Already done: AS3 class that can draw a screen's worth of tiles to a backbuffer bitmapdata. Native app that can create tilemap and atlas from large png.

To do: Create AS3 png dumper that can write a large movieclip to a large png (when built as AIR). Modify class that draws tiles to use Bitmap objects that don't disable GPU acceleration.

1 comments:

  1. Instead of rendering your collision shape can you hold that in memory as triangles and do collision against polygons? I am not familiar with inkscape / svg so don't understand what that format looks like. You could then render just the triangles that are becoming visible as the level scrolls withe the foreground texture...

    ReplyDelete