Whatewver
This commit is contained in:
136
CMakeLists.txt
136
CMakeLists.txt
@@ -43,16 +43,6 @@ if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||
set(DUSK_TARGET_SYSTEM "linux")
|
||||
endif()
|
||||
|
||||
# Toolchains
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(pspsdk REQUIRED)
|
||||
endif()
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||
# Override to make library and binary be the same.
|
||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_LIBRARY_TARGET_NAME}.elf" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
endif()
|
||||
|
||||
# Init Project.
|
||||
project(${DUSK_LIBRARY_TARGET_NAME}
|
||||
VERSION 1.0.0
|
||||
@@ -78,132 +68,12 @@ else()
|
||||
add_executable(${DUSK_BINARY_TARGET_NAME} ${DUSK_SOURCES_DIR}/null.c)
|
||||
endif()
|
||||
|
||||
# Toolchains
|
||||
include(cmake/configure/${DUSK_TARGET_SYSTEM}.cmake)
|
||||
|
||||
# Add tools
|
||||
add_subdirectory(tools)
|
||||
|
||||
# Per Target Libraries and definitions
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
SDL2
|
||||
pthread
|
||||
OpenGL::GL
|
||||
GL
|
||||
m
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_SDL2=1
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=1080
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=810
|
||||
DISPLAY_SCREEN_HEIGHT_DEFAULT=270
|
||||
INPUT_SDL2=1
|
||||
INPUT_KEYBOARD=1
|
||||
INPUT_POINTER=1
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_SDL2=1
|
||||
TIME_FIXED=0
|
||||
)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
${SDL2_LIBRARIES}
|
||||
SDL2
|
||||
pthread
|
||||
OpenGL::GL
|
||||
zip
|
||||
bz2
|
||||
z
|
||||
mbedtls
|
||||
mbedcrypto
|
||||
lzma
|
||||
m
|
||||
)
|
||||
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_SDL2=1
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=480
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=272
|
||||
DISPLAY_WIDTH=480
|
||||
DISPLAY_HEIGHT=272
|
||||
DISPLAY_SIZE_DYNAMIC=0
|
||||
INPUT_SDL2=1
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_FIXED=1
|
||||
)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
||||
# configure_file(opengl.pc.in opengl.pc @ONLY)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(zip IMPORTED_TARGET libzip)
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DOLPHIN
|
||||
)
|
||||
|
||||
# Disable all warnings
|
||||
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE -w)
|
||||
|
||||
# Custom flags for cglm
|
||||
set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
||||
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
||||
find_package(cglm REQUIRED)
|
||||
|
||||
# Compile lua
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
liblua
|
||||
URL https://www.lua.org/ftp/lua-5.5.0.tar.gz
|
||||
)
|
||||
FetchContent_MakeAvailable(liblua)
|
||||
set(LUA_SRC_DIR "${liblua_SOURCE_DIR}/src")
|
||||
set(LUA_C_FILES
|
||||
lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c
|
||||
ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c
|
||||
loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c
|
||||
lstrlib.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c lzio.c
|
||||
)
|
||||
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||
add_library(liblua STATIC ${LUA_C_FILES})
|
||||
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||
add_library(lua::lua ALIAS liblua)
|
||||
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
cglm
|
||||
liblua
|
||||
m
|
||||
fat
|
||||
PkgConfig::zip
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=640
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=480
|
||||
DISPLAY_WIDTH=640
|
||||
DISPLAY_HEIGHT=480
|
||||
DISPLAY_SIZE_DYNAMIC=0
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_FIXED=1
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add code
|
||||
add_subdirectory(${DUSK_SOURCES_DIR})
|
||||
|
||||
|
||||
63
cmake/configure/dolphin.cmake
Normal file
63
cmake/configure/dolphin.cmake
Normal file
@@ -0,0 +1,63 @@
|
||||
message(FATAL_ERROR "Configure Dolphin")
|
||||
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii")
|
||||
# Override to make library and binary be the same.
|
||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_LIBRARY_TARGET_NAME}.elf" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
|
||||
# configure_file(opengl.pc.in opengl.pc @ONLY)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(zip IMPORTED_TARGET libzip)
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DOLPHIN
|
||||
)
|
||||
|
||||
# Disable all warnings
|
||||
target_compile_options(${DUSK_LIBRARY_TARGET_NAME} PRIVATE -w)
|
||||
|
||||
# Custom flags for cglm
|
||||
set(CGLM_SHARED OFF CACHE BOOL "Build cglm shared" FORCE)
|
||||
set(CGLM_STATIC ON CACHE BOOL "Build cglm static" FORCE)
|
||||
find_package(cglm REQUIRED)
|
||||
|
||||
# Compile lua
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
liblua
|
||||
URL https://www.lua.org/ftp/lua-5.5.0.tar.gz
|
||||
)
|
||||
FetchContent_MakeAvailable(liblua)
|
||||
set(LUA_SRC_DIR "${liblua_SOURCE_DIR}/src")
|
||||
set(LUA_C_FILES
|
||||
lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c ldblib.c ldebug.c
|
||||
ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c
|
||||
loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c
|
||||
lstrlib.c ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c lzio.c
|
||||
)
|
||||
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||
add_library(liblua STATIC ${LUA_C_FILES})
|
||||
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||
add_library(lua::lua ALIAS liblua)
|
||||
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
cglm
|
||||
liblua
|
||||
m
|
||||
fat
|
||||
PkgConfig::zip
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=640
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=480
|
||||
DISPLAY_WIDTH=640
|
||||
DISPLAY_HEIGHT=480
|
||||
DISPLAY_SIZE_DYNAMIC=0
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_FIXED=1
|
||||
)
|
||||
1
cmake/configure/gamecube.cmake
Normal file
1
cmake/configure/gamecube.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(cmake/configure/gamecube.cmake)
|
||||
26
cmake/configure/linux.cmake
Normal file
26
cmake/configure/linux.cmake
Normal file
@@ -0,0 +1,26 @@
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
SDL2
|
||||
pthread
|
||||
OpenGL::GL
|
||||
GL
|
||||
m
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_SDL2=1
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=1080
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=810
|
||||
DISPLAY_SCREEN_HEIGHT_DEFAULT=270
|
||||
DISPLAY_SHADER=1
|
||||
INPUT_SDL2=1
|
||||
INPUT_KEYBOARD=1
|
||||
INPUT_POINTER=1
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_SDL2=1
|
||||
TIME_FIXED=0
|
||||
)
|
||||
36
cmake/configure/psp.cmake
Normal file
36
cmake/configure/psp.cmake
Normal file
@@ -0,0 +1,36 @@
|
||||
find_package(pspsdk REQUIRED)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
${SDL2_LIBRARIES}
|
||||
SDL2
|
||||
pthread
|
||||
OpenGL::GL
|
||||
zip
|
||||
bz2
|
||||
z
|
||||
mbedtls
|
||||
mbedcrypto
|
||||
lzma
|
||||
m
|
||||
)
|
||||
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
${SDL2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
DISPLAY_SDL2=1
|
||||
DISPLAY_WINDOW_WIDTH_DEFAULT=480
|
||||
DISPLAY_WINDOW_HEIGHT_DEFAULT=272
|
||||
DISPLAY_WIDTH=480
|
||||
DISPLAY_HEIGHT=272
|
||||
DISPLAY_SIZE_DYNAMIC=0
|
||||
DISPLAY_COLOR_TABLE=1
|
||||
INPUT_SDL2=1
|
||||
INPUT_GAMEPAD=1
|
||||
THREAD_PTHREAD=1
|
||||
TIME_FIXED=1
|
||||
)
|
||||
1
cmake/configure/wii.cmake
Normal file
1
cmake/configure/wii.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(cmake/configure/dolphin.cmake)
|
||||
@@ -8,6 +8,18 @@
|
||||
#pragma once
|
||||
#include "display/color.h"
|
||||
|
||||
#if DISPLAY_SDL2
|
||||
#if DISPLAY_SHADER == 1
|
||||
|
||||
#elif DISPLAY_COLOR_TABLE == 1
|
||||
|
||||
#else
|
||||
#error "Unsupported palette mode"
|
||||
#endif
|
||||
#else
|
||||
#error "Unsupported palette mode"
|
||||
#endif
|
||||
|
||||
#define PALETTE_COUNT_MAX 4
|
||||
#define PALETTE_COLOR_COUNT_MAX 0xFF
|
||||
|
||||
|
||||
51
src/display/texture/palettetexture.c
Normal file
51
src/display/texture/palettetexture.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "palettetexture.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void paletteTextureInit(
|
||||
palettetexture_t *texture,
|
||||
const int32_t width,
|
||||
const int32_t height,
|
||||
const uint8_t *data
|
||||
) {
|
||||
assertNotNull(texture, "Palette texture cannot be NULL");
|
||||
assertTrue(width > 0 && height > 0, "width/height must be greater than 0");
|
||||
assertNotNull(data, "Palette texture data cannot be NULL");
|
||||
|
||||
#if DISPLAY_SDL2
|
||||
#if DISPLAY_SHADER == 1
|
||||
// Palette textures not supported, convert to GL_RED style texture
|
||||
// so shader can perform the lookup.
|
||||
uint8_t formatted[width * height];
|
||||
for(int32_t i = 0; i < width * height; i++) {
|
||||
uint8_t index = data.paletteData[i];
|
||||
formatted[i] = index * 128;
|
||||
}
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_R8, width, height, 0,
|
||||
GL_RED, GL_UNSIGNED_BYTE, (void*)formatted
|
||||
);
|
||||
|
||||
#else
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0, GL_COLOR_INDEX8_EXT,
|
||||
width, height,
|
||||
0, GL_COLOR_INDEX8_EXT,
|
||||
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
||||
);
|
||||
// glColorTableEXT(
|
||||
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
||||
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
||||
// );
|
||||
#endif
|
||||
#else
|
||||
#error "Palette textures not supported on this platform"
|
||||
#endif
|
||||
}
|
||||
28
src/display/texture/palettetexture.h
Normal file
28
src/display/texture/palettetexture.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
} palettetexture_t;
|
||||
|
||||
/**
|
||||
* Initializes a palette texture.
|
||||
*
|
||||
* @param texture The palette texture to initialize.
|
||||
* @param width The width of the texture. Must be a power of 2.
|
||||
* @param height The height of the texture. Must be a power of 2.
|
||||
* @param data The palette index data for the texture.
|
||||
*/
|
||||
void paletteTextureInit(
|
||||
palettetexture_t *texture,
|
||||
const int32_t width,
|
||||
const int32_t height,
|
||||
const uint8_t *data
|
||||
);
|
||||
Reference in New Issue
Block a user