Rendering on PSP again.
This commit is contained in:
@@ -10,8 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||||
|
|
||||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||||
set(DUSK_TARGET_SYSTEM "linux")
|
# set(DUSK_TARGET_SYSTEM "linux")
|
||||||
# set(DUSK_TARGET_SYSTEM "psp")
|
set(DUSK_TARGET_SYSTEM "psp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Prep cache
|
# Prep cache
|
||||||
@@ -69,8 +69,17 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
|||||||
|
|
||||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
target_link_libraries(${DUSK_TARGET_NAME} PRIVATE
|
find_package(OpenGL REQUIRED)
|
||||||
|
target_link_libraries(${DUSK_TARGET_NAME} PUBLIC
|
||||||
${SDL2_LIBRARIES}
|
${SDL2_LIBRARIES}
|
||||||
|
SDL2
|
||||||
|
OpenGL::GL
|
||||||
|
zip
|
||||||
|
bz2
|
||||||
|
z
|
||||||
|
mbedtls
|
||||||
|
mbedcrypto
|
||||||
|
lzma
|
||||||
)
|
)
|
||||||
target_include_directories(${DUSK_TARGET_NAME} PRIVATE
|
target_include_directories(${DUSK_TARGET_NAME} PRIVATE
|
||||||
${SDL2_INCLUDE_DIRS}
|
${SDL2_INCLUDE_DIRS}
|
||||||
|
@@ -33,7 +33,7 @@ if(NOT TARGET pspsdk)
|
|||||||
file(DOWNLOAD
|
file(DOWNLOAD
|
||||||
"https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz"
|
"https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz"
|
||||||
"${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
"${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
||||||
EXPECTED_HASH SHA256=afe338e92f6eeec21c56a64eeb65201e6b95ecbae938ae38688bbf0f17b69ead
|
EXPECTED_HASH SHA256=2befe2ad83afd88934c106dbe98a72a7ad5ede8d272b7f1e79fda256a22f1062
|
||||||
SHOW_PROGRESS
|
SHOW_PROGRESS
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -98,6 +98,9 @@ if(NOT TARGET pspsdk)
|
|||||||
pspaudio
|
pspaudio
|
||||||
pspaudiolib
|
pspaudiolib
|
||||||
psputility
|
psputility
|
||||||
|
pspvfpu
|
||||||
|
pspvram
|
||||||
|
psphprm
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
@@ -51,6 +51,7 @@ errorret_t displayInit(void) {
|
|||||||
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
|
glShadeModel(GL_SMOOTH); // Fixes color on PSP?
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
glEnableClientState(GL_COLOR_ARRAY);// To confirm: every frame on PSP?
|
glEnableClientState(GL_COLOR_ARRAY);// To confirm: every frame on PSP?
|
||||||
@@ -82,7 +83,12 @@ errorret_t displayUpdate(void) {
|
|||||||
|
|
||||||
// TODO: move to framebuffer component
|
// TODO: move to framebuffer component
|
||||||
int32_t windowWidth, windowHeight;
|
int32_t windowWidth, windowHeight;
|
||||||
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
|
#if PSP
|
||||||
|
windowWidth = DISPLAY_WINDOW_WIDTH_DEFAULT;
|
||||||
|
windowHeight = DISPLAY_WINDOW_HEIGHT_DEFAULT;
|
||||||
|
#else
|
||||||
|
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
|
||||||
|
#endif
|
||||||
glViewport(0, 0, windowWidth, windowHeight);
|
glViewport(0, 0, windowWidth, windowHeight);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
@@ -122,7 +122,11 @@ void frameBufferDispose(framebuffer_t *framebuffer) {
|
|||||||
assertUnreachable("Cannot dispose of backbuffer");
|
assertUnreachable("Cannot dispose of backbuffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteFramebuffersEXT(1, &framebuffer->id);
|
#if DISPLAY_SIZE_DYNAMIC == 0
|
||||||
|
assertUnreachable("Dynamic size framebuffers not supported");
|
||||||
|
#else
|
||||||
|
glDeleteFramebuffersEXT(1, &framebuffer->id);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ void sceneOverworldRender(void) {
|
|||||||
spriteBatchPush(
|
spriteBatchPush(
|
||||||
&testAsset->paletteImage.texture,
|
&testAsset->paletteImage.texture,
|
||||||
0.0f, 0.0f, 12.0f, 12.0f,
|
0.0f, 0.0f, 12.0f, 12.0f,
|
||||||
0xFF, 0x00, 0x00, 0xFF,
|
0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
0.0f, 0.0f, 1.0f, 1.0f
|
0.0f, 0.0f, 1.0f, 1.0f
|
||||||
);
|
);
|
||||||
spriteBatchFlush();
|
spriteBatchFlush();
|
||||||
|
@@ -66,6 +66,7 @@ void textureInit(
|
|||||||
"Palette index out of range"
|
"Palette index out of range"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get and validate the palette.
|
||||||
const palette_t *pal = PALETTE_LIST[data.palette.palette];
|
const palette_t *pal = PALETTE_LIST[data.palette.palette];
|
||||||
assertNotNull(pal, "Palette cannot be NULL");
|
assertNotNull(pal, "Palette cannot be NULL");
|
||||||
GLenum err = glGetError();
|
GLenum err = glGetError();
|
||||||
@@ -75,18 +76,23 @@ void textureInit(
|
|||||||
|
|
||||||
// Do we support paletted textures?
|
// Do we support paletted textures?
|
||||||
bool_t havePalTex = false;
|
bool_t havePalTex = false;
|
||||||
GLint mask = 0;
|
|
||||||
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
#if PSP
|
||||||
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
|
havePalTex = true;
|
||||||
GLint n=0; glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
#else
|
||||||
for (GLint i=0; i<n; ++i) {
|
GLint mask = 0;
|
||||||
const char* e = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
||||||
if (e && strcmp(e, "GL_EXT_paletted_texture")==0) { havePalTex = true; break; }
|
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
|
||||||
|
GLint n=0; glGetIntegerv(GL_NUM_EXTENSIONS, &n);
|
||||||
|
for (GLint i=0; i<n; ++i) {
|
||||||
|
const char* e = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||||
|
if (e && strcmp(e, "GL_EXT_paletted_texture")==0) { havePalTex = true; break; }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
|
havePalTex = ext && strstr(ext, "GL_EXT_paletted_texture");
|
||||||
}
|
}
|
||||||
} else {
|
#endif
|
||||||
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
|
|
||||||
havePalTex = ext && strstr(ext, "GL_EXT_paletted_texture");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!havePalTex) {
|
if(!havePalTex) {
|
||||||
// Not supported, convert to RGBA using lookup
|
// Not supported, convert to RGBA using lookup
|
||||||
@@ -105,10 +111,14 @@ void textureInit(
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Supported.
|
// Supported.
|
||||||
glColorTableEXT(
|
#if PSP
|
||||||
GL_TEXTURE_2D, GL_RGBA, pal->colorCount, GL_RGBA,
|
// PSP requires the color table itself to be a power of two
|
||||||
GL_UNSIGNED_BYTE, (const void*)pal->colors
|
assertTrue(
|
||||||
);
|
pal->colorCount == mathNextPowTwo(pal->colorCount),
|
||||||
|
"Palette color count must be a power of 2 for PSP"
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D,
|
GL_TEXTURE_2D,
|
||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
@@ -116,6 +126,11 @@ void textureInit(
|
|||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
GL_UNSIGNED_BYTE, (void*)data.palette.data
|
GL_UNSIGNED_BYTE, (void*)data.palette.data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
glColorTableEXT(
|
||||||
|
GL_TEXTURE_2D, GL_RGBA, pal->colorCount, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, (const void*)pal->colors
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -129,8 +144,6 @@ void textureInit(
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -19,6 +19,14 @@
|
|||||||
#include <cglm/cglm.h>
|
#include <cglm/cglm.h>
|
||||||
#include <cglm/types.h>
|
#include <cglm/types.h>
|
||||||
|
|
||||||
|
#if PSP
|
||||||
|
#include <pspkernel.h>
|
||||||
|
#include <pspdebug.h>
|
||||||
|
#include <pspdisplay.h>
|
||||||
|
#include <pspctrl.h>
|
||||||
|
#include <psphprm.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef bool bool_t;
|
typedef bool bool_t;
|
||||||
typedef int int_t;
|
typedef int int_t;
|
||||||
typedef float float_t;
|
typedef float float_t;
|
||||||
|
@@ -8,8 +8,7 @@
|
|||||||
#include "engine/engine.h"
|
#include "engine/engine.h"
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
|
|
||||||
// PSP_MODULE_INFO("Dusk", 0, 1, 0);
|
|
||||||
// PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | THREAD_ATTR_VFPU);
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
errorret_t ret;
|
errorret_t ret;
|
||||||
|
@@ -19,5 +19,6 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
|||||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
TIME_FIXED=1
|
TIME_FIXED=1
|
||||||
|
TIME_PLATFORM_STEP=0.016
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
@@ -30,15 +30,27 @@ def processPalette(asset):
|
|||||||
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]
|
fileNameWithoutExt = os.path.splitext(os.path.basename(asset['path']))[0]
|
||||||
fileNameWithoutPalette = os.path.splitext(fileNameWithoutExt)[0]
|
fileNameWithoutPalette = os.path.splitext(fileNameWithoutExt)[0]
|
||||||
|
|
||||||
|
# PSP requires that the palette size be a power of two, so we will pad the
|
||||||
|
# palette with transparent colors if needed.
|
||||||
|
# if args.platform == "psp":
|
||||||
|
def mathNextPowTwo(x):
|
||||||
|
return 1 << (x - 1).bit_length()
|
||||||
|
|
||||||
|
nextPowTwo = mathNextPowTwo(len(pixels))
|
||||||
|
while len(pixels) < nextPowTwo:
|
||||||
|
pixels.append((0, 0, 0, 0))
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
data = f"// Palette Generated for {asset['path']} at {now}\n"
|
data = f"// Palette Generated for {asset['path']} at {now}\n"
|
||||||
data += f"#include \"display/palette/palette.h\"\n\n"
|
data += f"#include \"display/palette/palette.h\"\n\n"
|
||||||
data += f"#define PALETTE_{paletteIndex}_COLOR_COUNT {len(pixels)}\n\n"
|
data += f"#define PALETTE_{paletteIndex}_COLOR_COUNT {len(pixels)}\n\n"
|
||||||
|
data += f"#pragma pack(push, 1)\n"
|
||||||
data += f"static const color_t PALETTE_{paletteIndex}_COLORS[PALETTE_{paletteIndex}_COLOR_COUNT] = {{\n"
|
data += f"static const color_t PALETTE_{paletteIndex}_COLORS[PALETTE_{paletteIndex}_COLOR_COUNT] = {{\n"
|
||||||
for pixel in pixels:
|
for pixel in pixels:
|
||||||
data += f" {{ 0x{pixel[0]:02X}, 0x{pixel[1]:02X}, 0x{pixel[2]:02X}, 0x{pixel[3]:02X} }},\n"
|
data += f" {{ 0x{pixel[0]:02X}, 0x{pixel[1]:02X}, 0x{pixel[2]:02X}, 0x{pixel[3]:02X} }},\n"
|
||||||
data += f"}};\n\n"
|
data += f"}};\n\n"
|
||||||
|
data += f"#pragma pack(pop)\n\n"
|
||||||
data += f"static const palette_t PALETTE_{paletteIndex} = {{\n"
|
data += f"static const palette_t PALETTE_{paletteIndex} = {{\n"
|
||||||
data += f" .colorCount = PALETTE_{paletteIndex}_COLOR_COUNT,\n"
|
data += f" .colorCount = PALETTE_{paletteIndex}_COLOR_COUNT,\n"
|
||||||
data += f" .colors = PALETTE_{paletteIndex}_COLORS,\n"
|
data += f" .colors = PALETTE_{paletteIndex}_COLORS,\n"
|
||||||
|
Reference in New Issue
Block a user