Skip to content

GPUImpl

tom5454 edited this page Nov 5, 2023 · 4 revisions

GPU

This is the default GPU context available through the GPU Peripheral, Image.gpuDraw or createWindow function.

Color

Color values can be entered in multiple ways:

  • single ARGB number: 0xAARRGGBB
  • three channels as three separate arguments: R, G, B
  • four channels as four separate arguments: R, G, B, A

VRAM

The GPU Peripheral has an internal buffer for processing called VRAM.
Every operation that works with large amount of data uses this buffer.
The maximum size of this buffer is configurable in the mod's config file with the maxVRAMSize setting.
It has nothing to do with the actual VRAM of the computer

Window

Windows are a separate GPU context that can be moved, hidden or resized.
Each window has it's own internal buffer, so it uses VRAM based on it's size.
The buffer can be drawn using the sync function.
Multiple windows can be layered on top of each other by changing the order of the sync calls.

createWindow(x, y, w, h)

Create a window with a normal GPU context

createWindow3D(x, y, width, height)

Create a window with a 3D GPU context
See GPU3D

sync()

Draw the window buffer into the parent context or update the monitors on the GPU Peripheral.

Utility functions

decodeImage(input...)

The function accepts unpacked numbers or buffer references. Returns the decoded image or throws an error if the image is corrupted or too big

getUsedMemory()

Returns the currently used VRAM by the GPU

newImage(width, height)

Creates a new image with the defined size

newBuffer([initial size])

Creates a new byte buffer with the given initial size or 32 bytes as the default.

imageFromBuffer(width, pixels...)

Creates an image with an unpacked ARGB pixels buffer

getMaxMemory()

Returns the maximum available VRAM

getBounds()

Returns the Window bounds object if the context was created using createWindow

getSize()

Returns the context size in pixels

Graphics functions

filledRectangle(x, y, width, height, color)

rectangle(x, y, width, height, color)

lineS(x1, y1, x2, y2, color)

setFont(name)

getFont()

drawText(x, y, text, [text color], [bg color], [size], [padding])

drawTextSmart(x, y, text, [text color], [bg color], [force unicode], [size], [padding])

freeChars()

drawChar(x, y, char, [text color], [bg color], [size])

clearChars()

delChar(char)

drawBuffer(x, y, image width, scale, argb pixels...)

drawImage(x, y, image ref)

addNewChar(char, width, char data...x16)

getTextLength(text, [size], [padding])

getFontDefaultCharID()

setFontDefaultCharID(id)

fill(color)

line(x1, y1, x2, y2, color)

Tom's Peripherals Wiki

Clone this wiki locally