Made first major changes; missing integration and optimization
This commit is contained in:
parent
ed98984164
commit
a4b246095a
|
@ -0,0 +1,12 @@
|
|||
|
||||
#ifndef NOX_GRAPHICS_COMMAND_QUEUE_H
|
||||
#define NOX_GRAPHICS_COMMAND_QUEUE_H
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
|
||||
// TODO
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#ifndef NOX_GRAPHICS_DEFAULT_IMPLEMENTATION_H
|
||||
#define NOX_GRAPHICS_DEFAULT_IMPLEMENTATION_H
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
|
||||
// TODO
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
#ifndef NOX_GRAPHICS_DRIVER_H
|
||||
#define NOX_GRAPHICS_DRIVER_H
|
||||
|
||||
#include <boot/boot_info.h>
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
|
||||
#include <drivers/gfx/pixelbuffer.h>
|
||||
|
||||
typedef struct framebuffer_t {
|
||||
|
||||
uint32_t pixel_width;
|
||||
uint32_t pixel_height;
|
||||
uint8_t pixel_stride;
|
||||
|
||||
void *memory_mapping;
|
||||
pixelbuffer_T *root_pixelbuffer;
|
||||
|
||||
} framebuffer_T;
|
||||
|
||||
typedef struct graphics_driver_t {
|
||||
|
||||
uint32_t num_framebuffers;
|
||||
framebuffer_T *framebuffers;
|
||||
|
||||
} graphics_driver_T;
|
||||
|
||||
graphics_driver_T * create_graphics_driver_from_boot_info(boot_info_T *boot_info);
|
||||
void delete_graphics_driver(graphics_driver_T *driver);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
#ifndef NOX_PIXELBUFFER_H
|
||||
#define NOX_PIXELBUFFER_H
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
#include <drivers/gfx/utility.h>
|
||||
|
||||
typedef struct pixelbuffer_t pixelbuffer_T;
|
||||
|
||||
struct pixelbuffer_t {
|
||||
|
||||
//
|
||||
// Other relevant state
|
||||
//
|
||||
|
||||
pixelbuffer_T *parent;
|
||||
// root_pixelbuffer: The first pixelbuffer for a screen, it represents the whole screen
|
||||
// from a drawing perspective. In the root pixelbuffers themselves, this is NULL.
|
||||
pixelbuffer_T *root_pixelbuffer;
|
||||
|
||||
//
|
||||
// Dimensions of the pixelbuffers' area
|
||||
//
|
||||
|
||||
uint32_t relative_start_x;
|
||||
uint32_t relative_start_y;
|
||||
uint32_t absolute_start_x;
|
||||
uint32_t absolute_start_y;
|
||||
uint32_t pixel_width;
|
||||
uint32_t pixel_height;
|
||||
|
||||
//
|
||||
// Information necessary for drawing
|
||||
//
|
||||
|
||||
// pixel_stride: The distance between pixels in 'mapped_region', in bytes.
|
||||
uint8_t pixel_stride;
|
||||
void *memory_mapping;
|
||||
|
||||
};
|
||||
|
||||
pixelbuffer_T * create_pixelbuffer (pixelbuffer_T *parent);
|
||||
void delete_pixelbuffer (pixelbuffer_T *pixelbuffer);
|
||||
|
||||
void graphics_set_pixel (pixelbuffer_T *pixelbuffer,
|
||||
uint32_t relative_x, uint32_t relative_y, pixel_T pixel);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#ifndef NOX_GRAPHICS_STRINGIFY_ENUMS_H
|
||||
#define NOX_GRAPHICS_STRINGIFY_ENUMS_H
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
|
||||
// TODO
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#ifndef NOX_GRAPHICS_UTILITY_H
|
||||
#define NOX_GRAPHICS_UTILITY_H
|
||||
|
||||
#include <utils/math.h>
|
||||
#include <utils/memory.h>
|
||||
#include <utils/stdtypes.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t red;
|
||||
uint16_t green;
|
||||
uint16_t blue;
|
||||
uint16_t alpha;
|
||||
|
||||
} pixel_T;
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// TODO
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// TODO
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#include <drivers/gfx/graphics_driver.h>
|
||||
|
||||
pixelbuffer_T * create_root_pixelbuffer(graphics_driver_T *driver, framebuffer_T *framebuffer) {
|
||||
|
||||
pixelbuffer_T *pixelbuffer = memory_allocate(sizeof(pixelbuffer_T));
|
||||
pixelbuffer->parent = NULL;
|
||||
pixelbuffer->root_pixelbuffer = NULL;
|
||||
pixelbuffer->relative_start_x = 0;
|
||||
pixelbuffer->relative_start_y = 0;
|
||||
pixelbuffer->absolute_start_x = 0;
|
||||
pixelbuffer->absolute_start_y = 0;
|
||||
pixelbuffer->pixel_width = framebuffer->pixel_width;
|
||||
pixelbuffer->pixel_height = framebuffer->pixel_height;
|
||||
pixelbuffer->pixel_stride = framebuffer->pixel_stride;
|
||||
pixelbuffer->memory_mapping = framebuffer->memory_mapping;
|
||||
|
||||
return pixelbuffer;
|
||||
}
|
||||
|
||||
framebuffer_T convert_limine_framebuffer_to_noxos_framebuffer(graphics_driver_T *driver, struct limine_framebuffer *limine_framebuffer) {
|
||||
|
||||
framebuffer_T noxos_framebuffer;
|
||||
noxos_framebuffer.pixel_width = limine_framebuffer->width;
|
||||
noxos_framebuffer.pixel_height = limine_framebuffer->height;
|
||||
noxos_framebuffer.pixel_stride = limine_framebuffer->bpp / 8; // TODO: Check: Is this right?
|
||||
noxos_framebuffer.memory_mapping = limine_framebuffer->address;
|
||||
noxos_framebuffer.root_pixelbuffer = create_root_pixelbuffer(driver, &noxos_framebuffer);
|
||||
|
||||
return noxos_framebuffer;
|
||||
}
|
||||
|
||||
graphics_driver_T * create_graphics_driver_from_boot_info(boot_info_T *boot_info) {
|
||||
|
||||
graphics_driver_T *driver = memory_allocate(sizeof(graphics_driver_T));
|
||||
driver->num_framebuffers = boot_info->framebuffer->framebuffer_count;
|
||||
driver->framebuffers = memory_allocate(sizeof(framebuffer_T) * driver->num_framebuffers);
|
||||
|
||||
uint32_t framebuffer_index = 0;
|
||||
while(framebuffer_index > boot_info->framebuffer->framebuffer_count)
|
||||
{
|
||||
driver->framebuffers[framebuffer_index] = convert_limine_framebuffer_to_noxos_framebuffer(
|
||||
driver, &boot_info->framebuffer->framebuffers[framebuffer_index]);
|
||||
++framebuffer_index;
|
||||
}
|
||||
return driver;
|
||||
}
|
||||
|
||||
void delete_graphics_driver(graphics_driver_T *driver) {
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#include <drivers/gfx/pixelbuffer.h>
|
||||
|
||||
pixelbuffer_T * find_root_pixelbuffer(pixelbuffer_T *current) {
|
||||
if(current->parent == NULL) return current;
|
||||
return find_root_pixelbuffer(current->parent);
|
||||
}
|
||||
|
||||
pixelbuffer_T * create_pixelbuffer(pixelbuffer_T *parent) {
|
||||
|
||||
pixelbuffer_T *pixelbuffer = memory_allocate(sizeof(pixelbuffer_T));
|
||||
pixelbuffer->parent = parent;
|
||||
pixelbuffer->root_pixelbuffer = find_root_pixelbuffer(parent);
|
||||
pixelbuffer->memory_mapping = parent->memory_mapping;
|
||||
pixelbuffer->absolute_start_x = parent->absolute_start_x;
|
||||
pixelbuffer->absolute_start_y = parent->absolute_start_y;
|
||||
pixelbuffer->relative_start_x = 0;
|
||||
pixelbuffer->relative_start_y = 0;
|
||||
pixelbuffer->pixel_width = 1;
|
||||
pixelbuffer->pixel_height = 1;
|
||||
pixelbuffer->pixel_stride = pixelbuffer->root_pixelbuffer->pixel_stride;
|
||||
|
||||
return pixelbuffer;
|
||||
}
|
||||
|
||||
void delete_pixelbuffer(pixelbuffer_T *pixelbuffer) {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void graphics_set_pixel(pixelbuffer_T *pixelbuffer,
|
||||
uint32_t relative_x, uint32_t relative_y, pixel_T pixel)
|
||||
{
|
||||
// TODO: Check if these values are inside the pixelbuffers' range!
|
||||
|
||||
uint8_t *output_address = pixelbuffer->memory_mapping
|
||||
+ ((relative_y * pixelbuffer->pixel_width + relative_x) + pixelbuffer->pixel_stride);
|
||||
output_address[0] = pixel.red;
|
||||
output_address[1] = pixel.green;
|
||||
output_address[2] = pixel.blue;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// TODO
|
||||
|
Loading…
Reference in New Issue