This commit is contained in:
2026-06-18 20:25:54 -05:00
parent 730a5b2b10
commit 57b2cdb9d1
111 changed files with 865 additions and 3328 deletions
@@ -0,0 +1,10 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
framebuffer.c
)
@@ -0,0 +1,77 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "framebuffer.h"
#include "display/display.h"
#include "assert/assert.h"
#include "util/memory.h"
framebuffer_t FRAMEBUFFER_BACKBUFFER = {0};
const framebuffer_t *FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
errorret_t frameBufferInitBackBuffer() {
memoryZero(&FRAMEBUFFER_BACKBUFFER, sizeof(framebuffer_t));
errorChain(frameBufferPlatformInitBackBuffer());
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
errorOk();
}
errorret_t frameBufferBind(framebuffer_t *framebuffer) {
if(framebuffer == NULL) {
frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
errorOk();
}
errorChain(frameBufferPlatformBind(framebuffer));
FRAMEBUFFER_BOUND = framebuffer;
errorOk();
}
uint32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
return frameBufferPlatformGetWidth(framebuffer);
}
uint32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
return frameBufferPlatformGetHeight(framebuffer);
}
float_t frameBufferGetAspect(const framebuffer_t *framebuffer) {
#ifdef frameBufferPlatformGetAspect
return frameBufferPlatformGetAspect(framebuffer);
#endif
uint32_t width = frameBufferGetWidth(framebuffer);
uint32_t height = frameBufferGetHeight(framebuffer);
if(height == 0) return 1.0f; // Avoid divide by zero, just return 1:1 aspect.
return (float_t)width / (float_t)height;
}
void frameBufferClear(const uint8_t flags, const color_t color) {
frameBufferPlatformClear(flags, color);
}
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
errorret_t frameBufferInit(
framebuffer_t *fb,
const uint32_t width,
const uint32_t height
) {
assertNotNull(fb, "Framebuffer cannot be NULL");
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
memoryZero(fb, sizeof(framebuffer_t));
errorChain(frameBufferPlatformInit(fb, width, height));
errorOk();
}
errorret_t frameBufferDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
errorChain(frameBufferPlatformDispose(framebuffer));
errorOk();
}
#endif
@@ -0,0 +1,118 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
#include "display/framebuffer/framebufferplatform.h"
#include "display/texture/texture.h"
// Expected defs.
#ifndef frameBufferPlatformInitBackBuffer
#error "frameBufferPlatformInitBackBuffer not defined for this platform"
#endif
#ifndef frameBufferPlatformBind
#error "frameBufferPlatformBind not defined for this platform"
#endif
#ifndef frameBufferPlatformGetWidth
#error "frameBufferPlatformGetWidth not defined for this platform"
#endif
#ifndef frameBufferPlatformGetHeight
#error "frameBufferPlatformGetHeight not defined for this platform"
#endif
#ifndef frameBufferPlatformClear
#error "frameBufferPlatformClear not defined for this platform"
#endif
#define FRAMEBUFFER_CLEAR_COLOR (1 << 0)
#define FRAMEBUFFER_CLEAR_DEPTH (1 << 1)
typedef framebufferplatform_t framebuffer_t;
extern framebuffer_t FRAMEBUFFER_BACKBUFFER;
extern const framebuffer_t *FRAMEBUFFER_BOUND;
/**
* Initializes the backbuffer framebuffer.
*
* @return Error for initialization of the backbuffer.
*/
errorret_t frameBufferInitBackBuffer(void);
/**
* Gets the width of the framebuffer.
*
* @param framebuffer The framebuffer to get the width of.
* @return The width of the framebuffer, or 0 if the framebuffer is NULL.
*/
uint32_t frameBufferGetWidth(const framebuffer_t *framebuffer);
/**
* Gets the height of the framebuffer.
*
* @param framebuffer The framebuffer to get the height of.
* @return The height of the framebuffer, or 0 if the framebuffer is NULL.
*/
uint32_t frameBufferGetHeight(const framebuffer_t *framebuffer);
/**
* Returns the aspect ratio of the framebuffer. This is ALMOST always just
* the width / height, however some platforms may choose to override this if
* they have stretched styled back buffers, e.g. 640x480 stretched.
*
* @param framebuffer The framebuffer to get the aspect ratio of.
* @return The aspect ratio of the framebuffer.
*/
float_t frameBufferGetAspect(const framebuffer_t *framebuffer);
/**
* Binds the framebuffer for rendering, or the backbuffer if the framebuffer
* provided is NULL.
*
* @param framebuffer The framebuffer to bind, or NULL to bind the backbuffer.
* @return Error for binding the framebuffer.
*/
errorret_t frameBufferBind(framebuffer_t *framebuffer);
/**
* Clears the currently bound framebuffer.
*
* @param flags The clear flags.
* @param color The color to clear the color buffer to (if clearing color).
*/
void frameBufferClear(uint8_t flags, color_t color);
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
#ifndef frameBufferPlatformInit
#error "frameBufferPlatformInit not defined for this platform"
#endif
#ifndef frameBufferPlatformDispose
#error "frameBufferPlatformDispose not defined for this platform"
#endif
/**
* Initializes a framebuffer.
*
* @param framebuffer The framebuffer to initialize.
* @param width The width of the framebuffer.
* @param height The height of the framebuffer.
* @return Error for initialization of the framebuffer.
*/
errorret_t frameBufferInit(
framebuffer_t *framebuffer,
const uint32_t width,
const uint32_t height
);
/**
* Disposes of the framebuffer. Will also be used for request disposing of the
* backbuffer.
*
* @param framebuffer The framebuffer to dispose of.
*/
errorret_t frameBufferDispose(framebuffer_t *framebuffer);
#endif