idk
This commit is contained in:
@@ -7,9 +7,13 @@ add_subdirectory(dusk)
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
add_subdirectory(dusklinux)
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskopengl)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
add_subdirectory(duskpsp)
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskopengl)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||
add_subdirectory(duskdolphin)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "debug/debug.h"
|
||||
|
||||
/**
|
||||
* Platform-specific debug print function for Dolphin.
|
||||
*
|
||||
* @param message The message format string.
|
||||
* @param ... Additional arguments for the format string.
|
||||
*/
|
||||
void debugPrintDolphin(const char_t *message, ...);
|
||||
|
||||
/**
|
||||
* Flushes the Dolphin debug output buffer.
|
||||
*/
|
||||
void debugFlushDolphin();
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "debug/debug.h"
|
||||
|
||||
/**
|
||||
* Platform-specific debug print function for PSP.
|
||||
*
|
||||
* @param message The message format string.
|
||||
* @param ... Additional arguments for the format string.
|
||||
*/
|
||||
void debugPrintPSP(const char_t *message, ...);
|
||||
@@ -17,7 +17,6 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
add_subdirectory(camera)
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(texture)
|
||||
add_subdirectory(platform)
|
||||
|
||||
# Color definitions
|
||||
dusk_run_python(
|
||||
|
||||
@@ -10,19 +10,9 @@
|
||||
#include "error/error.h"
|
||||
#include "display/camera/camera.h"
|
||||
#include "display/framebuffer.h"
|
||||
#if DISPLAY_SDL2
|
||||
#include "display/platform/sdl2.h"
|
||||
#elif DOLPHIN
|
||||
#include "display/platform/dolphin.h"
|
||||
#endif
|
||||
#include "display/displayplatform.h"
|
||||
|
||||
typedef struct {
|
||||
#if DISPLAY_SDL2
|
||||
displaysdl2_t sdl2;
|
||||
#elif DOLPHIN
|
||||
displaydolphin_t dolphin;
|
||||
#endif
|
||||
} display_t;
|
||||
typedef displayplatform_t display_t;
|
||||
|
||||
extern display_t DISPLAY;
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dolphin.h"
|
||||
|
||||
void displayInitDolphin(void) {
|
||||
VIDEO_Init();
|
||||
DISPLAY.screenMode = VIDEO_GetPreferredMode(NULL);
|
||||
DISPLAY.frameBuffer[0] = MEM_K0_TO_K1(
|
||||
SYS_AllocateFramebuffer(DISPLAY.screenMode)
|
||||
);
|
||||
DISPLAY.frameBuffer[1] = MEM_K0_TO_K1(
|
||||
SYS_AllocateFramebuffer(DISPLAY.screenMode)
|
||||
);
|
||||
VIDEO_Configure(DISPLAY.screenMode);
|
||||
|
||||
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer]);
|
||||
// VIDEO_SetPostRetraceCallback(copy_buffers);
|
||||
VIDEO_SetBlack(FALSE);
|
||||
VIDEO_Flush();
|
||||
VIDEO_WaitVSync();
|
||||
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
||||
|
||||
DISPLAY.fifoBuffer = memalign(32, DISPLAY_FIFO_SIZE);
|
||||
memoryZero(DISPLAY.fifoBuffer, DISPLAY_FIFO_SIZE);
|
||||
|
||||
GX_Init(DISPLAY.fifoBuffer, DISPLAY_FIFO_SIZE);
|
||||
|
||||
// This seems to be mostly related to interlacing vs progressive
|
||||
GX_SetViewport(
|
||||
0, 0,
|
||||
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight,
|
||||
0, 1
|
||||
);
|
||||
float_t yscale = GX_GetYScaleFactor(
|
||||
DISPLAY.screenMode->efbHeight, DISPLAY.screenMode->xfbHeight
|
||||
);
|
||||
uint32_t xfbHeight = GX_SetDispCopyYScale(yscale);
|
||||
GX_SetScissor(
|
||||
0, 0,
|
||||
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight
|
||||
);
|
||||
GX_SetDispCopySrc(
|
||||
0, 0,
|
||||
DISPLAY.screenMode->fbWidth, DISPLAY.screenMode->efbHeight
|
||||
);
|
||||
GX_SetDispCopyDst(DISPLAY.screenMode->fbWidth, xfbHeight);
|
||||
GX_SetCopyFilter(
|
||||
DISPLAY.screenMode->aa,
|
||||
DISPLAY.screenMode->sample_pattern,
|
||||
GX_TRUE,
|
||||
DISPLAY.screenMode->vfilter
|
||||
);
|
||||
GX_SetFieldMode(
|
||||
DISPLAY.screenMode->field_rendering,
|
||||
(
|
||||
(DISPLAY.screenMode->viHeight == 2 * DISPLAY.screenMode->xfbHeight) ?
|
||||
GX_ENABLE :
|
||||
GX_DISABLE
|
||||
)
|
||||
);
|
||||
|
||||
// Setup cull modes
|
||||
GX_SetCullMode(GX_CULL_NONE);
|
||||
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE);
|
||||
GX_CopyDisp(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer], GX_TRUE);
|
||||
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||
|
||||
GX_ClearVtxDesc();
|
||||
GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
|
||||
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX16);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
|
||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_U8, 0);
|
||||
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||
}
|
||||
|
||||
void displayDolphinSwap(void) {
|
||||
GX_DrawDone();
|
||||
|
||||
DISPLAY.whichFrameBuffer ^= 1;
|
||||
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||
GX_SetColorUpdate(GX_TRUE);
|
||||
GX_CopyDisp(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer], GX_TRUE);
|
||||
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer[DISPLAY.whichFrameBuffer]);
|
||||
VIDEO_Flush();
|
||||
VIDEO_WaitVSync();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* 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/displaydefs.h"
|
||||
|
||||
typedef struct {
|
||||
void *frameBuffer[2];// Double-Bufferred
|
||||
int whichFrameBuffer;
|
||||
GXRModeObj *screenMode;
|
||||
void *fifoBuffer;
|
||||
} displaydolphin_t;
|
||||
|
||||
/**
|
||||
* Initializes the display for Dolphin.
|
||||
*/
|
||||
void displayDolphinInit(void);
|
||||
|
||||
/**
|
||||
* Swaps the back buffer to the front for Dolphin.
|
||||
*/
|
||||
void displayDolphinSwap(void);
|
||||
@@ -1,124 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "sdl2.h"
|
||||
|
||||
void displaySDL2Init(void) {
|
||||
uint32_t flags = SDL_INIT_VIDEO;
|
||||
#if INPUT_GAMEPAD == 1
|
||||
flags |= SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK;
|
||||
#endif
|
||||
if(SDL_Init(flags) != 0) {
|
||||
errorThrow("SDL Failed to Initialize: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
// Set OpenGL attributes (Needs to be done now or later?)
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
// Create window with OpenGL flag.
|
||||
DISPLAY.window = SDL_CreateWindow(
|
||||
"Dusk",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT,
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT,
|
||||
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI |
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
if(!DISPLAY.window) {
|
||||
errorThrow("SDL_CreateWindow failed: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
// Create OpenGL context
|
||||
DISPLAY.glContext = SDL_GL_CreateContext(DISPLAY.window);
|
||||
if(!DISPLAY.glContext) {
|
||||
errorThrow("SDL_GL_CreateContext failed: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);// PSP defaults this on?
|
||||
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glClearDepth(1.0f);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
glEnableClientState(GL_COLOR_ARRAY);// To confirm: every frame on PSP?
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
// Get and validate GL state.
|
||||
GLenum err = glGetError();
|
||||
if(err != GL_NO_ERROR) {
|
||||
assertUnreachable("GL Error before checking support");
|
||||
}
|
||||
|
||||
#if PSP
|
||||
displayInitPSP();
|
||||
#else
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void displaySDL2Update(void) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
switch(event.type) {
|
||||
case SDL_QUIT: {
|
||||
ENGINE.running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
switch(event.window.event) {
|
||||
case SDL_WINDOWEVENT_CLOSE: {
|
||||
ENGINE.running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext);
|
||||
}
|
||||
|
||||
void displaySDL2Swap(void) {
|
||||
SDL_GL_SwapWindow(DISPLAY.window);
|
||||
|
||||
GLenum err;
|
||||
while((err = glGetError()) != GL_NO_ERROR) {
|
||||
debugPrint("GL Error: %d\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
void displaySDL2Dispose(void) {
|
||||
if(DISPLAY.glContext) {
|
||||
SDL_GL_DeleteContext(DISPLAY.glContext);
|
||||
DISPLAY.glContext = NULL;
|
||||
}
|
||||
if(DISPLAY.window) {
|
||||
SDL_DestroyWindow(DISPLAY.window);
|
||||
DISPLAY.window = NULL;
|
||||
}
|
||||
SDL_Quit();
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glContext;
|
||||
bool_t usingShaderedPalettes;
|
||||
} displaysdl2_t;
|
||||
|
||||
/**
|
||||
* Initializes the display for SDL2.
|
||||
*/
|
||||
void displaySDL2Init(void);
|
||||
|
||||
/**
|
||||
* Updates the display for SDL2.
|
||||
*/
|
||||
void displaySDL2Update(void);
|
||||
|
||||
/**
|
||||
* Swaps the display buffers for SDL2.
|
||||
*/
|
||||
void displaySDL2Swap(void);
|
||||
|
||||
/**
|
||||
* Disposes of the display for SDL2.
|
||||
*/
|
||||
void displaySDL2Dispose(void);
|
||||
@@ -2,3 +2,12 @@
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(debug)
|
||||
@@ -7,6 +7,5 @@
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
psp.c
|
||||
dolphin.c
|
||||
debug.c
|
||||
)
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
static char_t DEBUG_ERROR_BUFFER[16*1024] = {0};
|
||||
|
||||
void debugPrintDolphin(const char_t *message, ...) {
|
||||
void debugPrint(const char_t *message, ...) {
|
||||
// append to error buffer
|
||||
size_t start = strlen(DEBUG_ERROR_BUFFER);
|
||||
va_list args;
|
||||
@@ -24,7 +24,7 @@ void debugPrintDolphin(const char_t *message, ...) {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void debugFlushDolphin() {
|
||||
void debugFlush() {
|
||||
// Either create graphics, or hijack the displays' graphics.
|
||||
void *xfb = NULL;
|
||||
GXRModeObj *rmode = NULL;
|
||||
@@ -6,8 +6,4 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Initializes the display for PSP.
|
||||
*/
|
||||
void displayInitPSP(void);
|
||||
#include "display/displaysdl2.h"
|
||||
@@ -3,5 +3,11 @@
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(debug)
|
||||
@@ -6,3 +6,4 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusksdl2.h"
|
||||
12
src/duskopengl/CMakeLists.txt
Normal file
12
src/duskopengl/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
@@ -5,8 +5,4 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "psp.h"
|
||||
|
||||
void displayInitPSP(void) {
|
||||
DISPLAY.usingShaderedPalettes = false;
|
||||
}
|
||||
#pragma once
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(debug)
|
||||
@@ -1,12 +1,11 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
sdl2.c
|
||||
psp.c
|
||||
dolphin.c
|
||||
debug.c
|
||||
)
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "psp.h"
|
||||
|
||||
void debugPrintPSP(const char_t *message, ...) {
|
||||
void debugPrint(const char_t *message, ...) {
|
||||
FILE *file = fopen("ms0:/PSP/GAME/Dusk/debug.log", "a");
|
||||
if(!file) return;
|
||||
|
||||
@@ -16,4 +16,8 @@ void debugPrintPSP(const char_t *message, ...) {
|
||||
vfprintf(file, message, args);
|
||||
va_end(args);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void debugFlush() {
|
||||
fflush(stdout);
|
||||
}
|
||||
12
src/dusksdl2/CMakeLists.txt
Normal file
12
src/dusksdl2/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
15
src/dusksdl2/display/displaysdl2.h
Normal file
15
src/dusksdl2/display/displaysdl2.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glContext;
|
||||
bool_t usingShaderedPalettes;
|
||||
} displayplatform_t;
|
||||
9
src/dusksdl2/dusksdl2.h
Normal file
9
src/dusksdl2/dusksdl2.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "duskopengl.h"
|
||||
Reference in New Issue
Block a user