Optimize PSP slightly
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
||||
set(CMAKE_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" CACHE FILEPATH "" FORCE)
|
||||
set(CMAKE_C_COMPILER_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE)
|
||||
@@ -58,12 +62,6 @@ target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_DISPLAY_OVERSCAN=6
|
||||
)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_ASSERTIONS_FAKED
|
||||
)
|
||||
endif()
|
||||
|
||||
# Postbuild, create .pbp file for PSP.
|
||||
create_pbp_file(
|
||||
TARGET "${DUSK_BINARY_TARGET_NAME}"
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
// Release-style CMake configs (Release, RelWithDebInfo, MinSizeRel) define
|
||||
// NDEBUG automatically; fake assertions there rather than requiring every
|
||||
// platform's CMakeLists to set DUSK_ASSERTIONS_FAKED itself.
|
||||
#if defined(NDEBUG) && !defined(DUSK_ASSERTIONS_FAKED)
|
||||
#define DUSK_ASSERTIONS_FAKED
|
||||
#endif
|
||||
|
||||
#ifdef DUSK_TEST_ASSERT
|
||||
#include <cmocka.h>
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/math.h"
|
||||
|
||||
size_t memoryGetAllocatedCount(void) {
|
||||
return MEMORY_POINTERS_IN_USE;
|
||||
@@ -106,9 +105,8 @@ int_t memoryCompare(
|
||||
void memoryReallocate(void **ptr, const size_t size) {
|
||||
assertNotNull(ptr, "Cannot reallocate NULL pointer.");
|
||||
assertTrue(size > 0, "Cannot reallocate to 0 bytes of memory.");
|
||||
void *newPointer = memoryAllocate(size);
|
||||
void *newPointer = realloc(*ptr, size);
|
||||
assertNotNull(newPointer, "Memory reallocation failed.");
|
||||
memoryFree(*ptr);
|
||||
*ptr = newPointer;
|
||||
}
|
||||
|
||||
@@ -141,9 +139,7 @@ void memoryResize(void **ptr, const size_t oldSize, const size_t newSize) {
|
||||
assertTrue(oldSize > 0, "Old size cannot be 0 bytes.");
|
||||
if(newSize == oldSize) return;
|
||||
|
||||
void *newPointer = memoryAllocate(newSize);
|
||||
void *newPointer = realloc(*ptr, newSize);
|
||||
assertNotNull(newPointer, "Memory resizing failed.");
|
||||
memoryCopy(newPointer, *ptr, mathMin(oldSize, newSize));
|
||||
memoryFree(*ptr);
|
||||
*ptr = newPointer;
|
||||
}
|
||||
@@ -10,7 +10,12 @@
|
||||
#include "display/displaygl.h"
|
||||
#include "error/errorgl.h"
|
||||
|
||||
static bool_t DISPLAY_SDL2_STATE_VALID = false;
|
||||
static uint8_t DISPLAY_SDL2_STATE_FLAGS = 0;
|
||||
|
||||
errorret_t displaySDL2Init(void) {
|
||||
DISPLAY_SDL2_STATE_VALID = false;
|
||||
|
||||
uint32_t flags = SDL_INIT_VIDEO;
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
flags |= SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK;
|
||||
@@ -103,38 +108,53 @@ errorret_t displaySDL2Swap(void) {
|
||||
}
|
||||
|
||||
errorret_t displaySDL2SetState(displaystate_t state) {
|
||||
if(state.flags & DISPLAY_STATE_FLAG_CULL) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
errorChain(errorGLCheck());
|
||||
glCullFace(GL_BACK);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
errorChain(errorGLCheck());
|
||||
// Only touch GL state that actually differs from what's already bound --
|
||||
// avoids a redundant glEnable/glDisable/glBlendFunc/glDepthFunc round
|
||||
// trip per draw when consecutive entities share the same display state.
|
||||
const uint8_t changed = DISPLAY_SDL2_STATE_VALID ?
|
||||
(state.flags ^ DISPLAY_SDL2_STATE_FLAGS) : 0xFF;
|
||||
|
||||
if(changed & DISPLAY_STATE_FLAG_CULL) {
|
||||
if(state.flags & DISPLAY_STATE_FLAG_CULL) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
errorChain(errorGLCheck());
|
||||
glCullFace(GL_BACK);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
errorChain(errorGLCheck());
|
||||
}
|
||||
}
|
||||
|
||||
if(state.flags & DISPLAY_STATE_FLAG_DEPTH_TEST) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
errorChain(errorGLCheck());
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
errorChain(errorGLCheck());
|
||||
glClearDepth(1.0f);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
errorChain(errorGLCheck());
|
||||
if(changed & DISPLAY_STATE_FLAG_DEPTH_TEST) {
|
||||
if(state.flags & DISPLAY_STATE_FLAG_DEPTH_TEST) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
errorChain(errorGLCheck());
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
errorChain(errorGLCheck());
|
||||
glClearDepth(1.0f);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
errorChain(errorGLCheck());
|
||||
}
|
||||
}
|
||||
|
||||
if(state.flags & DISPLAY_STATE_FLAG_BLEND) {
|
||||
glEnable(GL_BLEND);
|
||||
errorChain(errorGLCheck());
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_BLEND);
|
||||
errorChain(errorGLCheck());
|
||||
if(changed & DISPLAY_STATE_FLAG_BLEND) {
|
||||
if(state.flags & DISPLAY_STATE_FLAG_BLEND) {
|
||||
glEnable(GL_BLEND);
|
||||
errorChain(errorGLCheck());
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
errorChain(errorGLCheck());
|
||||
} else {
|
||||
glDisable(GL_BLEND);
|
||||
errorChain(errorGLCheck());
|
||||
}
|
||||
}
|
||||
|
||||
DISPLAY_SDL2_STATE_FLAGS = state.flags;
|
||||
DISPLAY_SDL2_STATE_VALID = true;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user