More screen modes.

This commit is contained in:
2025-10-06 16:23:36 -05:00
parent 6e5c5f61db
commit f3a6c8df71
2 changed files with 86 additions and 1 deletions

View File

@@ -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.

View File

@@ -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;