Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
component:gpu [2020/05/18 03:49]
payonel vram docs
component:gpu [2023/12/25 14:49] (current)
bioscreeper
Line 1: Line 1:
 Component: GPU Component: GPU
 ============== ==============
-This is the component provided by [[item:​graphics_card|graphics cards]]. For simple programs the [[api:​term|term API]] will usually all you need. For more complex operations, or to get a bit more performance,​ you may wish to interact with the GPU directly, though.+This is the component provided by [[item:​graphics_card|graphics cards]]. For simple programs the [[api:​term|term API]] is usually all you need. For more complex operations, or to get a bit more performance,​ you may wish to interact with the GPU directly, though.
  
 As of OC 1.3 screens of tier 2 and 3 have a 16 color palette. The palette is used to determine the exact colors used when displaying an RGB color. As of OC 1.3 screens of tier 2 and 3 have a 16 color palette. The palette is used to determine the exact colors used when displaying an RGB color.
Line 13: Line 13:
 - [[component:​gpu#​video_ram_buffers|Video Ram Buffers]] - [[component:​gpu#​video_ram_buffers|Video Ram Buffers]]
   This list of component api is getting long, so the new video ram api is listed below on this page in its own section   This list of component api is getting long, so the new video ram api is listed below on this page in its own section
-  - New in OC 1.7.5 Developer builds and expected in the next release (1.8)+  - New in OC 1.7.5 Developer builds and expected in the next release (OC 1.8)
 - `bind(address:​ string[, reset: boolean=true]):​ boolean[, string]`  ​ - `bind(address:​ string[, reset: boolean=true]):​ boolean[, string]`  ​
   Tries to bind the GPU to a screen with the specified address. Returns `true` on success, `false` and an error message on failure. Resets the screen'​s settings if reset is '​true'​.   Tries to bind the GPU to a screen with the specified address. Returns `true` on success, `false` and an error message on failure. Resets the screen'​s settings if reset is '​true'​.
Line 37: Line 37:
 - `getDepth():​ number`  ​ - `getDepth():​ number`  ​
   The currently set color depth of the GPU/screen, in bits. Can be 1, 4 or 8.   The currently set color depth of the GPU/screen, in bits. Can be 1, 4 or 8.
-- `setDepth(bit:​ number): ​boolean`   +- `setDepth(bit:​ number): ​string`   
-  Sets the color depth to use. Can be up to the maximum supported color depth. If a larger or invalid value is provided it will throw an error. Returns ​`true` if the depth was set, `falseotherwise.+  Sets the color depth to use. Can be up to the maximum supported color depth. If a larger or invalid value is provided it will throw an error. Returns the old depth as one of the strings `OneBit`, `FourBit`, or `EightBit`.
 - `maxResolution():​ number, number`  ​ - `maxResolution():​ number, number`  ​
   Gets the maximum resolution supported by the GPU and the screen it is bound to (minimum of the two).   Gets the maximum resolution supported by the GPU and the screen it is bound to (minimum of the two).
Line 106: Line 106:
 A GPU card has internal memory that you can allocate into pages. You can specify a custom page size (width and height each must be greater than zero). The total memory of a GPU is reduced by the width*height of an allocation. Each tier of gpu has more total memory than the last. Each page buffer acts like an offscreen [[component:​screen|Screen]] with its own width, height, and color. The max color depth of a gpu buffer is based on the gpu tier. Rebooting a machine releases all bufffers. A GPU card has internal memory that you can allocate into pages. You can specify a custom page size (width and height each must be greater than zero). The total memory of a GPU is reduced by the width*height of an allocation. Each tier of gpu has more total memory than the last. Each page buffer acts like an offscreen [[component:​screen|Screen]] with its own width, height, and color. The max color depth of a gpu buffer is based on the gpu tier. Rebooting a machine releases all bufffers.
  
-Each page buffer has its own index; the gpu finds the next available index. Index zero (0) has a special meaning, it is reserved for the scren. Whether a gpu is bound to a screen or not, you can allocate pages, set them active, and read/write to them. Attaching and detaching a screen, even binding to a new screen, does not release the gpu pages. When a computer shuts off or reboots, the pages are released. Each GPU has its own video memory and pages.+Each page buffer has its own index; the gpu finds the next available index. Index zero (0) has a special meaning, it is reserved for the screen. Whether a gpu is bound to a screen or not, you can allocate pages, set them active, and read/write to them. Attaching and detaching a screen, even binding to a new screen, does not release the gpu pages. When a computer shuts off or reboots, the pages are released. Each GPU has its own video memory and pages.
  
-- `getBuffer(): number`  ​+Budget and Energy Costs 
 +----------- 
 + 
 +Updates to vram (set, copy, fill, etc) are nearly free. They have no energy cost and no additional budget cost. Every direct component invoke (and these gpu methods are direct) has a tiny system minimum budget cost, but the gpu itself in these vram updates adds no additional cost. When bitblt'​ing the vram to the screen there is some cost, similar to how updates to the screen normally incur a cost. A dirty (modified) vram back buffer has a one time budget cost that increases with the size of the source buffer. Subsequent bitblts from a clean back buffer to the screen have extremely low costs. 
 + 
 +- `getActiveBuffer(): number`  ​
   Returns the index of the currently selected buffer. 0 is reserved for the screen, and may return 0 even when there is no screen   Returns the index of the currently selected buffer. 0 is reserved for the screen, and may return 0 even when there is no screen
-- `setBuffer(index: number): number`  ​+- `setActiveBuffer(index: number): number`  ​
   Sets the active buffer to `index`. 0 is reserved for the screen and can be set even when there is no screen. Returns nil for an invalid index (0 is valid even with no screen)   Sets the active buffer to `index`. 0 is reserved for the screen and can be set even when there is no screen. Returns nil for an invalid index (0 is valid even with no screen)
 - `buffers(): table`  ​ - `buffers(): table`  ​