From c7fe8ec3b4a3d333ec259e11ad309cb3999df99e Mon Sep 17 00:00:00 2001 From: Vicente Carrasco <122119831+striga314@users.noreply.github.com> Date: Sun, 8 Jan 2023 15:17:48 -0300 Subject: [PATCH] Restored PSP build, added fog to it (#451) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vicente Carrasco Álvarez --- src/gapi/gu.h | 43 ++++++++++++++++++++++++++++++++++++------- src/level.h | 7 +++++-- src/sound.h | 2 +- src/texture.h | 6 +++--- src/utils.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 13 deletions(-) diff --git a/src/gapi/gu.h b/src/gapi/gu.h index 1574ceb..713c307 100644 --- a/src/gapi/gu.h +++ b/src/gapi/gu.h @@ -33,11 +33,12 @@ namespace GAPI { // Texture struct Texture { uint8 *memory; - int width, height, origWidth, origHeight; + int width, height, depth, origWidth, origHeight, origDepth;//todo: depth TexFormat fmt; uint32 opt; - Texture(int width, int height, uint32 opt) : memory(0), width(width), height(height), origWidth(width), origHeight(height), fmt(FMT_RGBA), opt(opt) {} + /*depth*/ + Texture(int width, int height, int depth, uint32 opt) : memory(0), width(width), height(height), depth(depth), origWidth(width), origHeight(height), origDepth(depth), fmt(FMT_RGBA), opt(opt) {} void init(void *data) { ASSERT((opt & OPT_PROXY) == 0); @@ -238,19 +239,22 @@ namespace GAPI { support.maxVectors = 0; support.shaderBinary = false; support.VAO = false; + support.VBO = false; support.depthTexture = false; support.shadowSampler = false; support.discardFrame = false; support.texNPOT = false; + support.tex3D = false; support.texRG = false; support.texBorder = false; + support.texMaxLevel = false; support.colorFloat = false; support.colorHalf = false; support.texFloatLinear = false; support.texFloat = false; support.texHalfLinear = false; support.texHalf = false; - support.clipDist = false; + //support.clipDist = false; Core::width = 480; Core::height = 272; @@ -351,9 +355,33 @@ namespace GAPI { sceGuClearColor(*((uint32*)&c)); } - void setViewport(const Viewport &vp) { - sceGuOffset(2048 - vp.width / 2, 2048 - vp.height / 2); - sceGuViewport(2048 + vp.x, 2048 + vp.y, vp.width, vp.height); + // Previous: struct Viewport + void setViewport(const short4 &vp) { + sceGuOffset(2048 - vp.z / 2, 2048 - vp.w / 2); + sceGuViewport(2048 + vp.x, 2048 + vp.y, vp.z, vp.w); + } + + /*this was giving errors on menu rendering when method was empty, see RT_ flags too*/ + void setFog(const vec4 ¶ms) { + uint32 color; + if(params.w > 0.0f){ + sceGuEnable(GU_FOG); + // FFP TODO + color = 0xFF000000 + | (uint32(clamp(params.x * 255.0f, 0.0f, 255.0f)) << 0) + | (uint32(clamp(params.y * 255.0f, 0.0f, 255.0f)) << 8) + | (uint32(clamp(params.z * 255.0f, 0.0f, 255.0f)) << 16); + // from 3DS + sceGuFog(24.0f, 32.0f * 1024.0f, color); + } + else{ + sceGuDisable(GU_FOG); + } + } + + // from other gapi, could be improved?? + void setScissor(const short4 &s) { + sceGuScissor(s.x, Core::viewportDef.w - (s.y + s.w), s.x + s.z, Core::viewportDef.w - s.y); } void setDepthTest(bool enable) { @@ -458,8 +486,9 @@ namespace GAPI { } vec4 copyPixel(int x, int y) { + //pspgu.h, pspdisplay.h ?? return vec4(0.0f); // TODO: read from framebuffer } } -#endif \ No newline at end of file +#endif diff --git a/src/level.h b/src/level.h index 90acb6c..809333a 100644 --- a/src/level.h +++ b/src/level.h @@ -3489,8 +3489,11 @@ struct Level : IGame { short4 oldViewport = Core::viewportDef; setDefaultTarget(eye, view, false); - - Core::setTarget(NULL, NULL, RT_CLEAR_DEPTH | RT_STORE_COLOR); + #ifdef FFP //fixme: psp framebuffer error? + Core::setTarget(NULL, NULL, RT_CLEAR_DEPTH | RT_CLEAR_COLOR | RT_STORE_COLOR); + #else + Core::setTarget(NULL, NULL, RT_CLEAR_DEPTH | RT_STORE_COLOR); + #endif float aspect = setViewport(view, eye); diff --git a/src/sound.h b/src/sound.h index e8b5d28..c1a95f9 100644 --- a/src/sound.h +++ b/src/sound.h @@ -653,7 +653,7 @@ namespace Sound { } virtual int decode(Frame *frames, int count) { - #if _OS_PSV // TODO crash + #if defined(_OS_PSV) || defined(_OS_PSP) // TODO crash memset(frames, 0, count * sizeof(Frame)); return count; #endif diff --git a/src/texture.h b/src/texture.h index 89aaeb4..e102ceb 100644 --- a/src/texture.h +++ b/src/texture.h @@ -17,11 +17,11 @@ struct Texture : GAPI::Texture { #elif defined(_GAPI_GU) Tile4 *tiles; CLUT *cluts; - + // TODO: PSP depth ?? Texture(Tile4 *tiles, int tilesCount, CLUT *cluts, int clutsCount) : GAPI::Texture(256, 256, 1, OPT_PROXY) { #ifdef EDRAM_TEX - this->tiles = (TR::Tile4*)GAPI::allocEDRAM(tilesCount * sizeof(tiles[0])); - this->cluts = (TR::CLUT*)GAPI::allocEDRAM(clutsCount * sizeof(cluts[0])); + this->tiles = (Tile4*)GAPI::allocEDRAM(tilesCount * sizeof(tiles[0])); + this->cluts = (CLUT*)GAPI::allocEDRAM(clutsCount * sizeof(cluts[0])); memcpy(this->cluts, cluts, clutsCount * sizeof(cluts[0])); #ifdef TEX_SWIZZLE for (int i = 0; i < tilesCount; i++) diff --git a/src/utils.h b/src/utils.h index 79e5624..34472db 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2047,6 +2047,37 @@ public: strcpy(path, contentDir); readDirectory(path); } +#elif _OS_PSP //vita isnt called "psp2" by coincidence +//dunno if this is used (?) + static void readDirectory(char* path) { + SceUID dd = sceIoDopen(path); + + size_t len = strlen(path); + + SceIoDirent entry; + while (sceIoDread(dd, &entry) > 0) + { + strcat(path, entry.d_name); + + if (FIO_S_ISDIR(entry.d_stat.st_mode)) + { + strcat(path, "/"); + readDirectory(path); + } else { + fileList.push(StrUtils::copy(path + strlen(contentDir))); + } + + path[len] = 0; + } + + sceIoClose(dd); + } + + static void readFileList() { + char path[255]; + strcpy(path, contentDir); + readDirectory(path); + } #else static void readFileList() {}; #endif