Removed DUSK_ prefix

This commit is contained in:
2025-08-23 10:13:49 -05:00
parent 1bf6fe6eaf
commit 1dfde00317
28 changed files with 148 additions and 101 deletions

View File

@@ -19,17 +19,18 @@ add_subdirectory(texture)
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE
DUSK_DISPLAY_SDL2=1
DISPLAY_SDL2=1
DISPLAY_WINDOW_WIDTH_DEFAULT=960
DISPLAY_WINDOW_HEIGHT_DEFAULT=720
)
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE
DUSK_DISPLAY_SDL2=1
DISPLAY_SDL2=1
DISPLAY_WINDOW_WIDTH_DEFAULT=480
DISPLAY_WINDOW_HEIGHT_DEFAULT=272
DISPLAY_WIDTH=480
DISPLAY_HEIGHT=272
DISPLAY_SIZE_DYNAMIC=0
)
endif()

View File

@@ -30,7 +30,6 @@ void cameraEntityAdded(const ecsid_t id) {
cam->perspective.fov = glm_rad(90.0f);
cam->nearClip = 0.1f;
cam->farClip = 1000.0f;
cam->clearColor = COLOR_CORNFLOWER_BLUE;
}
void cameraPush(const ecsid_t id) {
@@ -67,7 +66,7 @@ void cameraPush(const ecsid_t id) {
);
}
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
mat4 pv;
glm_mat4_mul(projection, view, pv);
@@ -76,21 +75,13 @@ void cameraPush(const ecsid_t id) {
glLoadIdentity();
glLoadMatrixf((const GLfloat*)pv);
glClearColor(
cam->clearColor.r / 255.0f,
cam->clearColor.g / 255.0f,
cam->clearColor.b / 255.0f,
cam->clearColor.a / 255.0f
);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#endif
}
void cameraPop(void) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
glPopMatrix();
#endif
}

View File

@@ -32,7 +32,6 @@ typedef struct {
float_t nearClip;
float_t farClip;
color_t clearColor;
} camera_t;
extern camera_t CAMERA_DATA[ECS_ENTITY_COUNT_MAX];

View File

@@ -16,7 +16,7 @@
display_t DISPLAY;
errorret_t displayInit(void) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) != 0) {
errorThrow("SDL Failed to Initialize: %s", SDL_GetError());
}
@@ -65,7 +65,7 @@ errorret_t displayInit(void) {
}
errorret_t displayUpdate(void) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
@@ -86,7 +86,7 @@ errorret_t displayUpdate(void) {
rendererRender(CAMERA_MAIN);
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
SDL_GL_SwapWindow(DISPLAY.window);
#endif
@@ -95,7 +95,7 @@ errorret_t displayUpdate(void) {
}
errorret_t displayDispose(void) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(DISPLAY.glContext) {
SDL_GL_DeleteContext(DISPLAY.glContext);
DISPLAY.glContext = NULL;

View File

@@ -8,11 +8,15 @@
#pragma once
#include "error/error.h"
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
#include <SDL2/SDL.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#ifndef DISPLAY_SIZE_DYNAMIC
#define DISPLAY_SIZE_DYNAMIC 1
#endif
#else
#error "Need to specify display backend."
#endif
@@ -31,8 +35,10 @@
#define DISPLAY_WINDOW_HEIGHT_DEFAULT DISPLAY_HEIGHT
#endif
typedef struct {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
SDL_Window *window;
SDL_GLContext glContext;
#endif

View File

@@ -20,11 +20,15 @@ void frameBufferInitBackbuffer() {
}
int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowWidth;
#if DISPLAY_SIZE_DYNAMIC == 0
return DISPLAY_WIDTH;
#else
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowWidth;
#endif
}
assertUnreachable("Framebuffer width not implemented");
@@ -33,11 +37,15 @@ int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
}
int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowHeight;
#if DISPLAY_SIZE_DYNAMIC == 0
return DISPLAY_HEIGHT;
#else
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowHeight;
#endif
}
assertUnreachable("Framebuffer height not implemented");
@@ -47,7 +55,7 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
void frameBufferBind(const framebuffer_t *framebuffer) {
if(framebuffer == NULL) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
#endif
@@ -56,14 +64,19 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
}
// Bind the framebuffer for rendering
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
#if PSP
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
#else
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
#endif
} else {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);
#if PSP
assertUnreachable("Framebuffers not supported on PSP");
#else
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);
#endif
}
glViewport(
0, 0,
@@ -74,6 +87,28 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
FRAMEBUFFER_BOUND = framebuffer;
}
void frameBufferClear(uint8_t flags, color_t color) {
#if DISPLAY_SDL2
GLbitfield glFlags = 0;
if(flags & FRAMEBUFFER_CLEAR_COLOR) {
glFlags |= GL_COLOR_BUFFER_BIT;
glClearColor(
color.r / 255.0f,
color.g / 255.0f,
color.b / 255.0f,
color.a / 255.0f
);
}
if(flags & FRAMEBUFFER_CLEAR_DEPTH) {
glFlags |= GL_DEPTH_BUFFER_BIT;
}
glClear(glFlags);
#endif
}
/**
* Disposes of the framebuffer using EXT methods.
*
@@ -82,7 +117,7 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
void frameBufferDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
assertUnreachable("Cannot dispose of backbuffer");
}

View File

@@ -9,8 +9,11 @@
#include "display/display.h"
#include "display/texture/texture.h"
#define FRAMEBUFFER_CLEAR_COLOR (1 << 0)
#define FRAMEBUFFER_CLEAR_DEPTH (1 << 1)
typedef struct {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
// OpenGL Framebuffer Object ID
GLuint id;
#endif
@@ -45,6 +48,14 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer);
*/
void frameBufferBind(const 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);
/**
* Disposes of the framebuffer using EXT methods.
*

View File

@@ -43,7 +43,7 @@ void meshDraw(
"Vertex offset + count must not exceed vertex count"
);
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
// PSP style pointer legacy OpenGL
const GLsizei stride = sizeof(meshvertex_t);

View File

@@ -7,7 +7,7 @@
#include "display/display.h"
typedef enum {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
MESH_PRIMITIVE_TRIANGLES = GL_TRIANGLES,
MESH_PRIMITIVE_LINES = GL_LINES,
MESH_PRIMITIVE_POINTS = GL_POINTS,
@@ -19,7 +19,7 @@ typedef enum {
#define MESH_VERTEX_POS_SIZE 3
typedef struct {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
GLubyte color[MESH_VERTEX_COLOR_SIZE];
GLfloat uv[MESH_VERTEX_UV_SIZE];
GLfloat pos[MESH_VERTEX_POS_SIZE];

View File

@@ -20,6 +20,10 @@ void rendererRender(const ecsid_t camera) {
meshCount = meshRendererGetAll(meshes);
frameBufferBind(NULL);
frameBufferClear(
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
COLOR_CORNFLOWER_BLUE
);
cameraPush(camera);
for(uint32_t i = 0; i < meshCount; i++) {
id = meshes[i];

View File

@@ -37,7 +37,7 @@ void textureInit(
);
#endif
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
glGenTextures(1, &texture->id);
glBindTexture(GL_TEXTURE_2D, texture->id);
glTexImage2D(
@@ -58,7 +58,7 @@ void textureBind(const texture_t *texture) {
if(TEXTURE_BOUND == texture) return;
if(texture == NULL) {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
glDisable(GL_TEXTURE_2D);
#endif
TEXTURE_BOUND = NULL;
@@ -74,7 +74,7 @@ void textureBind(const texture_t *texture) {
"Texture width and height must be greater than 0"
);
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->id);
#endif
@@ -85,7 +85,7 @@ void textureDispose(texture_t *texture) {
assertNotNull(texture, "Texture cannot be NULL");
assertTrue(texture->id != 0, "Texture ID must not be 0");
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
glDeleteTextures(1, &texture->id);
#endif
}

View File

@@ -10,14 +10,14 @@
#include "display/color.h"
typedef enum {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
TEXTURE_FORMAT_RGBA = GL_RGBA,
TEXTURE_FORMAT_ALPHA = GL_ALPHA,
#endif
} textureformat_t;
typedef struct {
#if DUSK_DISPLAY_SDL2
#if DISPLAY_SDL2
GLuint id;
#endif