116 lines
2.4 KiB
C
116 lines
2.4 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "dusk.h"
|
|
#include "display/framebuffer/framebuffer.h"
|
|
#include "display/mesh/quad.h"
|
|
#include "display/color.h"
|
|
|
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
|
#ifndef DUSK_DISPLAY_SCREEN_HEIGHT
|
|
#error "DUSK_DISPLAY_SCREEN_HEIGHT must be defined"
|
|
#endif
|
|
#endif
|
|
|
|
typedef enum {
|
|
SCREEN_MODE_BACKBUFFER,
|
|
|
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
|
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
|
|
// Fixed viewport height. Fixed height but higher resolution.
|
|
SCREEN_MODE_FIXED_VIEWPORT_HEIGHT,
|
|
#endif
|
|
} screenmode_t;
|
|
|
|
// typedef enum {
|
|
// SCREEN_SCALE_MODE_FILL,
|
|
// SCREEN_SCALE_MODE_INTEGER,
|
|
// SCREEN_SCALE_MODE_INEGER_OVERFLOW
|
|
// } screenscalemode_t;
|
|
|
|
typedef struct {
|
|
screenmode_t mode;
|
|
// screenscalemode_t scaleMode;
|
|
|
|
// Calculated dimensions of the viewport, to be used by the camera
|
|
int32_t width;
|
|
int32_t height;
|
|
float_t aspect;
|
|
color_t background;
|
|
|
|
#ifdef DUSK_DISPLAY_SIZE_DYNAMIC
|
|
framebuffer_t framebuffer;
|
|
bool_t framebufferReady;
|
|
// camera_t framebufferCamera;
|
|
mesh_t frameBufferMesh;
|
|
meshvertex_t frameBufferMeshVertices[QUAD_VERTEX_COUNT];
|
|
#endif
|
|
|
|
union {
|
|
struct {
|
|
int32_t width;
|
|
int32_t height;
|
|
} fixedSize;
|
|
|
|
struct {
|
|
float_t ratio;
|
|
} aspectRatio;
|
|
|
|
struct {
|
|
int32_t height;
|
|
} fixedHeight;
|
|
|
|
struct {
|
|
int32_t width;
|
|
} fixedWidth;
|
|
|
|
struct {
|
|
int32_t height;
|
|
} fixedViewportHeight;
|
|
};
|
|
} screen_t;
|
|
|
|
extern screen_t SCREEN;
|
|
|
|
/**
|
|
* Initializes the screen system.
|
|
*
|
|
* @return Error code and state, if error occurs.
|
|
*/
|
|
errorret_t screenInit();
|
|
|
|
/**
|
|
* Binds the screen, this is done before rendering game content.
|
|
*
|
|
* @return Error code and state, if error occurs.
|
|
*/
|
|
errorret_t screenBind();
|
|
|
|
/**
|
|
* Unbinds the screen, does nothing for now.
|
|
*
|
|
* @return Error code and state, if error occurs.
|
|
*/
|
|
errorret_t screenUnbind();
|
|
|
|
/**
|
|
* Renders the screen to the current framebuffer.
|
|
*
|
|
* @return Error code and state, if error occurs.
|
|
*/
|
|
errorret_t screenRender();
|
|
|
|
/**
|
|
* Disposes the screen system.
|
|
*
|
|
* @return Error code and state, if error occurs.
|
|
*/
|
|
errorret_t screenDispose(); |