prog
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user