From f3a6c8df7144f9f6645fe98039b4682d53337648 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 6 Oct 2025 16:23:36 -0500 Subject: [PATCH] More screen modes. --- src/display/screen.c | 76 +++++++++++++++++++++++++++++++++++++++++++- src/display/screen.h | 11 +++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/display/screen.c b/src/display/screen.c index 073c3a5..620fc3f 100644 --- a/src/display/screen.c +++ b/src/display/screen.c @@ -58,6 +58,33 @@ void screenBind() { } #if DISPLAY_SIZE_DYNAMIC == 1 + case SCREEN_MODE_FIXED_SIZE: { + SCREEN.width = SCREEN.fixedSize.width; + SCREEN.height = SCREEN.fixedSize.height; + + if(SCREEN.framebufferReady) { + // Is current framebuffer the correct size? + int32_t curFbWidth, curFbHeight; + curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer); + curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer); + if(curFbWidth == SCREEN.width && curFbHeight == SCREEN.height) { + // Correct size, nothing to do. + frameBufferBind(&SCREEN.framebuffer); + return; + } + + // Need a new framebuffer. + frameBufferDispose(&SCREEN.framebuffer); + SCREEN.framebufferReady = false; + } + + // Create new framebuffer + frameBufferInit(&SCREEN.framebuffer, SCREEN.width, SCREEN.height); + SCREEN.framebufferReady = true; + frameBufferBind(&SCREEN.framebuffer); + break; + } + case SCREEN_MODE_ASPECT_RATIO: { // Aspect ratio mode, requires a framebuffer. int32_t fbWidth, fbHeight; @@ -159,6 +186,49 @@ void screenBind() { frameBufferBind(&SCREEN.framebuffer); break; } + + case SCREEN_MODE_FIXED_WIDTH: { + float_t fbWidth = (float_t)frameBufferGetWidth(FRAMEBUFFER_BOUND); + float_t fbHeight = (float_t)frameBufferGetHeight(FRAMEBUFFER_BOUND); + float_t fbAspect = fbWidth / fbHeight; + + int32_t newFbWidth, newFbHeight; + newFbWidth = SCREEN.fixedWidth.width; + newFbHeight = (int32_t)floorf(newFbWidth / fbAspect); + + SCREEN.width = newFbWidth; + SCREEN.height = newFbHeight; + + if(fbWidth == newFbWidth && fbHeight == newFbHeight) { + // No need to use framebuffer. + if(SCREEN.framebufferReady) { + frameBufferDispose(&SCREEN.framebuffer); + SCREEN.framebufferReady = false; + } + return; + } + + if(SCREEN.framebufferReady) { + // Is current framebuffer the correct size? + int32_t curFbWidth, curFbHeight; + curFbWidth = frameBufferGetWidth(&SCREEN.framebuffer); + curFbHeight = frameBufferGetHeight(&SCREEN.framebuffer); + if(curFbWidth == newFbWidth && curFbHeight == newFbHeight) { + frameBufferBind(&SCREEN.framebuffer); + return; + } + + // Need a new framebuffer. + frameBufferDispose(&SCREEN.framebuffer); + SCREEN.framebufferReady = false; + } + + // Create a new framebuffer. + frameBufferInit(&SCREEN.framebuffer, newFbWidth, newFbHeight); + SCREEN.framebufferReady = true; + frameBufferBind(&SCREEN.framebuffer); + break; + } #endif default: { @@ -178,6 +248,8 @@ void screenUnbind() { #if DISPLAY_SIZE_DYNAMIC == 1 case SCREEN_MODE_ASPECT_RATIO: case SCREEN_MODE_FIXED_HEIGHT: + case SCREEN_MODE_FIXED_SIZE: + case SCREEN_MODE_FIXED_WIDTH: if(SCREEN.framebufferReady) frameBufferBind(NULL); break; #endif @@ -197,7 +269,9 @@ void screenRender() { #if DISPLAY_SIZE_DYNAMIC == 1 if( SCREEN.mode == SCREEN_MODE_ASPECT_RATIO || - SCREEN.mode == SCREEN_MODE_FIXED_HEIGHT + SCREEN.mode == SCREEN_MODE_FIXED_HEIGHT || + SCREEN.mode == SCREEN_MODE_FIXED_SIZE || + SCREEN.mode == SCREEN_MODE_FIXED_WIDTH ) { if(!SCREEN.framebufferReady) { // Nothing to do here. diff --git a/src/display/screen.h b/src/display/screen.h index 47b9e10..a376e67 100644 --- a/src/display/screen.h +++ b/src/display/screen.h @@ -15,8 +15,10 @@ typedef enum { SCREEN_MODE_BACKBUFFER, #if DISPLAY_SIZE_DYNAMIC == 1 + SCREEN_MODE_FIXED_SIZE, SCREEN_MODE_ASPECT_RATIO,// Maintains aspect at all cost SCREEN_MODE_FIXED_HEIGHT, // Fixed height, width expands/contracts as needed + SCREEN_MODE_FIXED_WIDTH, // Fixed width, height expands/contracts as needed #endif } screenmode_t; @@ -43,6 +45,11 @@ typedef struct { #endif union { + struct { + int32_t width; + int32_t height; + } fixedSize; + struct { float_t ratio; } aspectRatio; @@ -50,6 +57,10 @@ typedef struct { struct { int32_t height; } fixedHeight; + + struct { + int32_t width; + } fixedWidth; }; } screen_t;