/** * 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