Skip to content
Will Thomas edited this page Mar 31, 2014 · 2 revisions

The gfxBuffer library provides special render targets. Like canvas objects, they will have the full set of gpu library methods and be fully functioning render targets, usable interchangeably with gpu objects. Unlike canvases, they do not keep a full copy of everything drawn to them. Instead, they simply act as a buffer, processing and holding on to the results of each draw command until buffer.flush() is called. Calling flush will cause it to present list of changes to its parent, after which it will empty their buffer and wait for more draw commands. Any redundancy and overwrites between flushes are removed, as well as any writes which would not change anything, and small, separate writes will, where possible, be combined into a minimum number of calls.

Create a buffer by calling gfxbuffer.create

local buffer=gfxbuffer.create(parent)

parent is optional, and will default to the primary gpu component. You could pass another buffer or a canvas as your target, but there is no good reason at present to do so.

Once you have your buffer, draw to it as you would a gpu, using buffer.set, buffer.setForeground, and buffer.setBackground. When you're done, just call buffer.flush() and the changes will be written through to the parent.

Note that in the current implementation, buffer.fill, buffer.copy, and buffer.get will all cause an immediate flush of the buffer. There are plans to address at least the first two in future versions, though buffer.get will likely always flush, due to the high cost of extracting from the array of spans and the low cost of just calling gpu.get.

Clone this wiki locally