From d96aba237b039948c4973f04e0f9ee8ba10c92e7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 7 Apr 2023 13:05:03 +1000 Subject: [PATCH] PSP: Less broken rendering --- src/Graphics_PSP.c | 28 +++++++++++++++++++--------- src/Platform_PSP.c | 41 ++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index f7c09a10e..945b5d015 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -60,6 +60,8 @@ static void guInit(void) { sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); sceGuDisable(GU_SCISSOR_TEST); + + //sceGuEnable(GU_CLIP_PLANES); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuFinish(); @@ -137,13 +139,18 @@ void Gfx_ClearCol(PackedCol color) { } void Gfx_SetColWriteMask(cc_bool r, cc_bool g, cc_bool b, cc_bool a) { - //glColorMask(r, g, b, a); - /* TODO implemenet */ + unsigned int mask = 0xffffffff; + if (r) mask &= 0xffffff00; + if (g) mask &= 0xffff00ff; + if (b) mask &= 0xff00ffff; + if (a) mask &= 0x00ffffff; + + //sceGuPixelMask(mask); TODO implement } void Gfx_SetDepthWrite(cc_bool enabled) { sceGuDepthMask(enabled); } void Gfx_SetDepthTest(cc_bool enabled) { GU_Toggle(GU_DEPTH_TEST); } - +//void Gfx_SetDepthTest(cc_bool enabled) { sceGuDisable(GU_DEPTH_TEST); } /*########################################################################################################################* *---------------------------------------------------------Matrices--------------------------------------------------------* @@ -305,11 +312,11 @@ void Gfx_DepthOnlyRendering(cc_bool depthOnly) { *---------------------------------------------------------Matrices--------------------------------------------------------* *#########################################################################################################################*/ static int matrix_modes[] = { GU_PROJECTION, GU_VIEW }; +static ScePspFMatrix4 tmp_matrix; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - ScePspFMatrix4 m; - gumLoadMatrix(&m, matrix); - sceGuSetMatrix(matrix_modes[type], &m); + gumLoadMatrix(&tmp_matrix, matrix); + sceGuSetMatrix(matrix_modes[type], &tmp_matrix); } void Gfx_LoadIdentityMatrix(MatrixType type) { @@ -349,14 +356,17 @@ void Gfx_DrawVb_Lines(int verticesCount) { } void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { - sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, verticesCount, gfx_indices, gfx_vertices + startVertex * gfx_stride); + sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, ICOUNT(verticesCount), + gfx_indices, gfx_vertices + startVertex * gfx_stride); } void Gfx_DrawVb_IndexedTris(int verticesCount) { - sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, verticesCount, gfx_indices, gfx_vertices); + sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, ICOUNT(verticesCount), + gfx_indices, gfx_vertices); } void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { - sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, verticesCount, gfx_indices, gfx_vertices + startVertex * SIZEOF_VERTEX_TEXTURED); + sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, ICOUNT(verticesCount), + gfx_indices, gfx_vertices + startVertex * SIZEOF_VERTEX_TEXTURED); } #endif \ No newline at end of file diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 610937708..5f2ce9535 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -9,7 +9,6 @@ #include "Utils.h" #include "Errors.h" #include -#include #include #include #include @@ -19,14 +18,13 @@ #include #include #include -#include #include #include #include #include +#include -#define NS_PER_SEC 1000000000ULL -const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ +const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = ENOENT; const cc_result ReturnCode_SocketInProgess = EINPROGRESS; const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK; @@ -64,13 +62,16 @@ void Mem_Free(void* mem) { /*########################################################################################################################* *------------------------------------------------------Logging/Time-------------------------------------------------------* *#########################################################################################################################*/ -/* TODO: check this is actually accurate */ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { if (end < beg) return 0; - return (end - beg) / 1000; + return end - beg; } void Platform_Log(const char* msg, int len) { + int fd = sceKernelStdout(); + sceIoWrite(fd, msg, len); + sceIoWrite(fd, "\n", 1); + //pspDebugSioPutData(msg, len); //pspDebugSioPutData("\n", 1); } @@ -83,25 +84,23 @@ TimeMS DateTime_CurrentUTC_MS(void) { } void DateTime_CurrentLocal(struct DateTime* t) { - struct timeval cur; - struct tm loc_time; - gettimeofday(&cur, NULL); - localtime_r(&cur.tv_sec, &loc_time); + pspTime curTime; + sceRtcGetCurrentClockLocalTime(&curTime); - t->year = loc_time.tm_year + 1900; - t->month = loc_time.tm_mon + 1; - t->day = loc_time.tm_mday; - t->hour = loc_time.tm_hour; - t->minute = loc_time.tm_min; - t->second = loc_time.tm_sec; + t->year = curTime.year; + t->month = curTime.month; + t->day = curTime.day; + t->hour = curTime.hour; + t->minute = curTime.minutes; + t->second = curTime.seconds; } +#define US_PER_SEC 1000000ULL cc_uint64 Stopwatch_Measure(void) { - struct timespec t; - // sceKernelGetSystemTimeWide - /* TODO: CLOCK_MONOTONIC_RAW ?? */ - clock_gettime(CLOCK_MONOTONIC, &t); - return (cc_uint64)t.tv_sec * NS_PER_SEC + t.tv_nsec; + // TODO: sceKernelGetSystemTimeWide + struct SceKernelTimeval cur; + sceKernelLibcGettimeofday(&cur, NULL); + return (cc_uint64)cur.tv_sec * US_PER_SEC + cur.tv_usec; }