From 903d128c695b94f8adccd6f81195b254901a78ed Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Thu, 22 Oct 2020 16:58:25 +0200 Subject: [PATCH] Fixed all remaining glitches. --- src/gl/gl3device.cpp | 41 ++++++++++++++++++++++++++++++----------- src/gl/gl3matfx.cpp | 19 ++++++++++--------- src/gl/gl3raster.cpp | 28 +++++++++++++++++++++------- src/gl/gl3render.cpp | 8 +++++--- src/gl/gl3skin.cpp | 8 ++++---- 5 files changed, 70 insertions(+), 34 deletions(-) diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index c3455ab..eef9d5c 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "../rwbase.h" #include "../rwerror.h" @@ -303,10 +304,10 @@ flushGlRenderState(void) void setAlphaBlend(bool32 enable) { - if(rwStateCache.blendEnable != enable){ + //if(rwStateCache.blendEnable != enable){ rwStateCache.blendEnable = enable; setGlRenderState(RWGL_BLEND, enable); - } + //} } bool32 @@ -417,16 +418,31 @@ bindFramebuffer(uint32 fbo) } // TODO: support mipmaps +#ifdef PSP2_MIPMAPS +static GLint filterConvMap_NoMIP[] = { + 0, GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR, + GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR, + GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR +}; +#else static GLint filterConvMap_NoMIP[] = { 0, GL_NEAREST, GL_LINEAR, GL_NEAREST, GL_LINEAR, GL_NEAREST, GL_LINEAR }; +#endif +#ifdef PSP2 +static GLint addressConvMap[] = { + 0, GL_REPEAT, GL_REPEAT, + GL_REPEAT, GL_REPEAT +}; +#else static GLint addressConvMap[] = { 0, GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; +#endif static void setFilterMode(uint32 stage, int32 filter) @@ -869,14 +885,15 @@ Shader *lastShaderUploaded; #define U(i) currentShader->uniformLocations[i] +rw::RGBAf matColorCache; +float surfPropsCache[4]; + void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops) { //bool force = lastShaderUploaded != currentShader; //if(force || !equal(shaderState.matColor, color)){ - rw::RGBAf col; - convColor(&col, &color); - glUniform4fv(U(u_matColor), 1, (GLfloat*)&col); + convColor(&matColorCache, &color); shaderState.matColor = color; //} @@ -884,12 +901,10 @@ setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops) // shaderState.surfProps.ambient != surfaceprops.ambient || // shaderState.surfProps.specular != surfaceprops.specular || // shaderState.surfProps.diffuse != surfaceprops.diffuse){ - float surfProps[4]; - surfProps[0] = surfaceprops.ambient; - surfProps[1] = surfaceprops.specular; - surfProps[2] = surfaceprops.diffuse; - surfProps[3] = 0.0f; - glUniform4fv(U(u_surfProps), 1, surfProps); + surfPropsCache[0] = surfaceprops.ambient; + surfPropsCache[1] = surfaceprops.specular; + surfPropsCache[2] = surfaceprops.diffuse; + surfPropsCache[3] = 0.0f; shaderState.surfProps = surfaceprops; //} } @@ -899,6 +914,9 @@ flushCache(void) { flushGlRenderState(); + glUniform4fv(U(u_matColor), 1, (GLfloat*)&matColorCache); + glUniform4fv(U(u_surfProps), 1, surfPropsCache); + // TODO: this is probably a stupid way to do it without UBOs /*if(lastShaderUploaded != currentShader){ lastShaderUploaded = currentShader; @@ -1340,6 +1358,7 @@ openGLFW(EngineOpenParams *openparams) } vglInitExtended(0x10000, 960, 544, 0x100000, SCE_GXM_MULTISAMPLE_4X); + vglSetupRuntimeShaderCompiler(SHARK_OPT_UNSAFE, SHARK_ENABLE, SHARK_ENABLE, SHARK_ENABLE); vglUseVram(GL_TRUE); vglStartRendering(); diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index cfc82fe..9d31f66 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -38,12 +38,12 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) defaultShader->use(); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - - flushCache(); - - setMaterial(m->color, m->surfaceProps); - + setTexture(0, m->texture); + + setMaterial(m->color, m->surfaceProps); + + flushCache(); drawInst(header, inst); } @@ -94,13 +94,14 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) rw::SetRenderState(VERTEXALPHA, 1); rw::SetRenderState(SRCBLEND, BLENDONE); - flushCache(); - setTexture(0, m->texture); setTexture(1, env->tex); - uploadEnvMatrix(env->frame); - + setMaterial(m->color, m->surfaceProps); + + flushCache(); + + uploadEnvMatrix(env->frame); float fxparams[2]; fxparams[0] = env->coefficient; diff --git a/src/gl/gl3raster.cpp b/src/gl/gl3raster.cpp index c6050db..8a73312 100644 --- a/src/gl/gl3raster.cpp +++ b/src/gl/gl3raster.cpp @@ -19,6 +19,8 @@ namespace gl3 { int32 nativeRasterOffset; +#define RW_GLES + #ifdef RW_OPENGL static Raster* rasterCreateTexture(Raster *raster) @@ -56,7 +58,7 @@ rasterCreateTexture(Raster *raster) #ifdef RW_GLES // glReadPixels only supports GL_RGBA - natras->internalFormat = GL_RGBA8; + natras->internalFormat = GL_RGBA; natras->format = GL_RGBA; natras->type = GL_UNSIGNED_BYTE; natras->bpp = 4; @@ -111,13 +113,13 @@ rasterCreateCameraTexture(Raster *raster) natras->bpp = 2; break; } - + #ifdef RW_GLES // glReadPixels only supports GL_RGBA -// natras->internalFormat = GL_RGBA8; -// natras->format = GL_RGBA; -// natras->type = GL_UNSIGNED_BYTE; -// natras->bpp = 4; + natras->internalFormat = GL_RGBA; + natras->format = GL_RGBA; + natras->type = GL_UNSIGNED_BYTE; + natras->bpp = 4; #endif raster->stride = raster->width*natras->bpp; @@ -251,6 +253,8 @@ rasterCreate(Raster *raster) } } +#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1)) + uint8* rasterLock(Raster *raster, int32 level, int32 lockMode) { @@ -271,7 +275,14 @@ memset(px, 0, raster->stride*raster->height); if(lockMode & Raster::LOCKREAD || !(lockMode & Raster::LOCKNOFETCH)){ uint32 prev = bindTexture(natras->texid); - memcpy_neon(px, vglGetTexDataPointer(GL_TEXTURE_2D), raster->stride*raster->height); + int y = 0; + uint8_t *p = (uint8_t*)vglGetTexDataPointer(GL_TEXTURE_2D); + uint32_t internal_stride = ALIGN(raster->width, 8) * natras->bpp; + while (y < raster->height) { + memcpy_neon(px, p, raster->stride); + px += internal_stride; + y++; + } bindTexture(prev); } @@ -302,6 +313,9 @@ rasterUnlock(Raster *raster, int32 level) glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat, raster->width, raster->height, 0, natras->format, natras->type, raster->pixels); +#ifdef PSP2_MIPMAPS + glGenerateMipmap(GL_TEXTURE_2D); +#endif bindTexture(prev); } diff --git a/src/gl/gl3render.cpp b/src/gl/gl3render.cpp index d3b60de..1132d62 100644 --- a/src/gl/gl3render.cpp +++ b/src/gl/gl3render.cpp @@ -64,9 +64,11 @@ drawInst_GSemu(InstanceDataHeader *header, InstanceData *inst) void drawInst(InstanceDataHeader *header, InstanceData *inst) { +#ifndef PSP2 if(rw::GetRenderState(rw::GSALPHATEST)) drawInst_GSemu(header, inst); else +#endif drawInst_simple(header, inst); } @@ -132,11 +134,11 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - flushCache(); + setTexture(0, m->texture); setMaterial(m->color, m->surfaceProps); - - setTexture(0, m->texture); + + flushCache(); drawInst(header, inst); inst++; diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index 3d749b4..242ec90 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -275,12 +275,12 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - flushCache(); - - setMaterial(m->color, m->surfaceProps); - setTexture(0, m->texture); + setMaterial(m->color, m->surfaceProps); + + flushCache(); + uploadSkinMatrices(atomic); drawInst(header, inst);