This repository has been archived on 2023-09-28. You can view files and clone it, but cannot push or open issues or pull requests.
homepage/content/projects/noxos/docs/codebase/drivers/graphics/renderer.h.md

90 lines
8.8 KiB
Markdown
Raw Normal View History

---
title: "renderer.h"
summary: "the renderer is maybe a bit over-engineered and slow"
---
The renderer has a stack of buffers, which act like canvases.
You can create, move, hide and show buffers.
#### `graphics_buffer_layer_E` - enum
- **Standard** - The layer, where almost everything should be on
- **Overlay** - This layer should be used for stuff like a mouse cursor, that should always be visible
#### `graphics_buffer_T` - struct
| Name | Type | Description |
|---------|------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| buffer | [color_argb_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/color.h/#color_argb_t---struct)* | The buffer, where all the pixels are stored |
| width | uint32_t | The width of the buffer |
| height | uint32_t | The height of the buffer |
| pos_x | uint32_t | The buffers x offset (from the top-left corner) in the renderers main buffer |
| pos_y | uint32_t | The buffers y offset (from the top-left corner) in the renderers main buffer |
| blocked | bool | Thread safety block variable |
| render | bool | Controls, if the buffer will be rendered or not |
| layer | [graphics_buffer_layer_E](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_buffer_layer_e---enum) | The layer, on which the buffer will be rendered |
| prev | [graphics_buffer_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_buffer_t---struct)* | The previous buffer in the rendering queue |
| next | [graphics_buffer_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_buffer_t---struct)* | The next buffer in the rendering queue |
#### `graphics_renderer_T` - struct
| Name | Type | Description |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| framebuffer | [framebuffer_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/framebuffer.h/#framebuffer_t---struct) | The systems framebuffer (requested from bootloader) |
| back_buffer | uint32_t* | The buffer, where the final image is calculated, before sending it to the framebuffer |
| buffer_size | uint64_t | The size of `back_buffer` (in bytes) |
| graphics_buffer_layers | [graphics_buffer_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_buffer_t---struct)** | List of pointers to the first [graphics_buffer_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_buffer_t---struct) of every layer |
| font | [font_T](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/font.h/#font_t---struct) | The font, all graphics buffers use to draw chars (could be moved to `graphics_buffer_T`) |
| initialized | bool | Indicates whether the renderer is initialized or not |
| blocked | bool | Blocking variable that is used for thread safety in [graphics_renderer_update](https://nerdcult.net/projects/noxos/docs/codebase/drivers/graphics/renderer.h/#graphics_renderer_update---function-void) |
#### `graphics_buffer_request(pos_x, pos_y, width, height, layer)` - function (graphics_buffer_T*)
Allocates a graphics buffer and pushes it on top of the rendering queue of **_layer_**.
#### `graphics_buffer_show(graphics_buffer)` - function (void)
Enables rendering for this buffer.
Every created buffer will be rendered by default.
#### `graphics_buffer_hide(graphics_buffer)` - function (void)
Disables rendering for this buffer.
#### `graphics_buffer_destruct(graphics_buffer)` - function (void)
Removes **_graphics_buffer_** from the rendering queue and frees its memory allocations.
#### `graphics_buffer_shift_up(graphics_buffer, shift)` - function (void)
Shifts **_graphics_buffer_**'s content **_shift_** rows up.
#### `graphics_buffer_set_pixel(graphics_buffer, x, y, color)` - function (void)
Sets a pixel with the given **_color_** at position(**_x_** | **_y_**) in **_graphics_buffer_**.
**_x_** and **_y_** are graphics buffer relative.
#### `graphics_buffer_get_pixel(graphics_buffer, x, y)` - function (color_argb_T)
Returns the color of the pixel at position(**_x_** | **_y_**) in **_graphics_buffer_**.
#### `graphics_buffer_draw_char(graphics_buffer, x, y, color, chr)` - function (void)
Draws a character (**_chr_**) at position(**_x_** | **_y_**) in **_graphics_buffer_**.
The position is the top-left corner of the char.
#### `graphics_buffer_draw_string(graphics_buffer, x, y, color, string)` - function (position_T)
Draws **_string_** at position(**_x_** | **_y_**) in **_graphics_buffer_**.
The position is the top-left corner of the string.
Returns the position after the last char of the string.
#### `graphics_renderer_init(boot_info)` - function (void)
Initializes the global graphics renderer.
Needs a pointer to `boot_info` to extract information about the framebuffer.
#### `graphics_renderer_update()` - function (void)
Updates the renderers back_buffer and swaps it into the framebuffer.
To update the back_buffer, it iterates over the rendering queue and copies every buffer to the back_buffer.
If there are overlapping graphics_buffers, it alpha-blends them.
#### `graphics_renderer_get_top_buffer(layer)` - function (graphics_buffer_T*)
Returns a pointer to the graphics_buffer, that is on top of the rendering queue of **_layer_**.
#### `graphics_renderer_get_width()` - function (uint32_t)
Returns the width of the framebuffer.
#### `graphics_renderer_get_height()` - function (uint32_t)
Returns the height of the framebuffer.