Fixed all remaining glitches.

This commit is contained in:
Rinnegatamante
2020-10-22 16:58:25 +02:00
parent 57b3457f61
commit 903d128c69
5 changed files with 70 additions and 34 deletions
+30 -11
View File
@@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <vitashark.h>
#include "../rwbase.h" #include "../rwbase.h"
#include "../rwerror.h" #include "../rwerror.h"
@@ -303,10 +304,10 @@ flushGlRenderState(void)
void void
setAlphaBlend(bool32 enable) setAlphaBlend(bool32 enable)
{ {
if(rwStateCache.blendEnable != enable){ //if(rwStateCache.blendEnable != enable){
rwStateCache.blendEnable = enable; rwStateCache.blendEnable = enable;
setGlRenderState(RWGL_BLEND, enable); setGlRenderState(RWGL_BLEND, enable);
} //}
} }
bool32 bool32
@@ -417,16 +418,31 @@ bindFramebuffer(uint32 fbo)
} }
// TODO: support mipmaps // 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[] = { static GLint filterConvMap_NoMIP[] = {
0, GL_NEAREST, GL_LINEAR, 0, GL_NEAREST, GL_LINEAR,
GL_NEAREST, GL_LINEAR, 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[] = { static GLint addressConvMap[] = {
0, GL_REPEAT, GL_MIRRORED_REPEAT, 0, GL_REPEAT, GL_MIRRORED_REPEAT,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE
}; };
#endif
static void static void
setFilterMode(uint32 stage, int32 filter) setFilterMode(uint32 stage, int32 filter)
@@ -869,14 +885,15 @@ Shader *lastShaderUploaded;
#define U(i) currentShader->uniformLocations[i] #define U(i) currentShader->uniformLocations[i]
rw::RGBAf matColorCache;
float surfPropsCache[4];
void void
setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops) setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops)
{ {
//bool force = lastShaderUploaded != currentShader; //bool force = lastShaderUploaded != currentShader;
//if(force || !equal(shaderState.matColor, color)){ //if(force || !equal(shaderState.matColor, color)){
rw::RGBAf col; convColor(&matColorCache, &color);
convColor(&col, &color);
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
shaderState.matColor = color; shaderState.matColor = color;
//} //}
@@ -884,12 +901,10 @@ setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops)
// shaderState.surfProps.ambient != surfaceprops.ambient || // shaderState.surfProps.ambient != surfaceprops.ambient ||
// shaderState.surfProps.specular != surfaceprops.specular || // shaderState.surfProps.specular != surfaceprops.specular ||
// shaderState.surfProps.diffuse != surfaceprops.diffuse){ // shaderState.surfProps.diffuse != surfaceprops.diffuse){
float surfProps[4]; surfPropsCache[0] = surfaceprops.ambient;
surfProps[0] = surfaceprops.ambient; surfPropsCache[1] = surfaceprops.specular;
surfProps[1] = surfaceprops.specular; surfPropsCache[2] = surfaceprops.diffuse;
surfProps[2] = surfaceprops.diffuse; surfPropsCache[3] = 0.0f;
surfProps[3] = 0.0f;
glUniform4fv(U(u_surfProps), 1, surfProps);
shaderState.surfProps = surfaceprops; shaderState.surfProps = surfaceprops;
//} //}
} }
@@ -899,6 +914,9 @@ flushCache(void)
{ {
flushGlRenderState(); 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 // TODO: this is probably a stupid way to do it without UBOs
/*if(lastShaderUploaded != currentShader){ /*if(lastShaderUploaded != currentShader){
lastShaderUploaded = currentShader; lastShaderUploaded = currentShader;
@@ -1340,6 +1358,7 @@ openGLFW(EngineOpenParams *openparams)
} }
vglInitExtended(0x10000, 960, 544, 0x100000, SCE_GXM_MULTISAMPLE_4X); vglInitExtended(0x10000, 960, 544, 0x100000, SCE_GXM_MULTISAMPLE_4X);
vglSetupRuntimeShaderCompiler(SHARK_OPT_UNSAFE, SHARK_ENABLE, SHARK_ENABLE, SHARK_ENABLE);
vglUseVram(GL_TRUE); vglUseVram(GL_TRUE);
vglStartRendering(); vglStartRendering();
+6 -5
View File
@@ -39,11 +39,11 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
flushCache(); setTexture(0, m->texture);
setMaterial(m->color, m->surfaceProps); setMaterial(m->color, m->surfaceProps);
setTexture(0, m->texture); flushCache();
drawInst(header, inst); drawInst(header, inst);
} }
@@ -94,14 +94,15 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env)
rw::SetRenderState(VERTEXALPHA, 1); rw::SetRenderState(VERTEXALPHA, 1);
rw::SetRenderState(SRCBLEND, BLENDONE); rw::SetRenderState(SRCBLEND, BLENDONE);
flushCache();
setTexture(0, m->texture); setTexture(0, m->texture);
setTexture(1, env->tex); setTexture(1, env->tex);
uploadEnvMatrix(env->frame);
setMaterial(m->color, m->surfaceProps); setMaterial(m->color, m->surfaceProps);
flushCache();
uploadEnvMatrix(env->frame);
float fxparams[2]; float fxparams[2];
fxparams[0] = env->coefficient; fxparams[0] = env->coefficient;
fxparams[1] = env->fbAlpha ? 0.0f : 1.0f; fxparams[1] = env->fbAlpha ? 0.0f : 1.0f;
+20 -6
View File
@@ -19,6 +19,8 @@ namespace gl3 {
int32 nativeRasterOffset; int32 nativeRasterOffset;
#define RW_GLES
#ifdef RW_OPENGL #ifdef RW_OPENGL
static Raster* static Raster*
rasterCreateTexture(Raster *raster) rasterCreateTexture(Raster *raster)
@@ -56,7 +58,7 @@ rasterCreateTexture(Raster *raster)
#ifdef RW_GLES #ifdef RW_GLES
// glReadPixels only supports GL_RGBA // glReadPixels only supports GL_RGBA
natras->internalFormat = GL_RGBA8; natras->internalFormat = GL_RGBA;
natras->format = GL_RGBA; natras->format = GL_RGBA;
natras->type = GL_UNSIGNED_BYTE; natras->type = GL_UNSIGNED_BYTE;
natras->bpp = 4; natras->bpp = 4;
@@ -114,10 +116,10 @@ rasterCreateCameraTexture(Raster *raster)
#ifdef RW_GLES #ifdef RW_GLES
// glReadPixels only supports GL_RGBA // glReadPixels only supports GL_RGBA
// natras->internalFormat = GL_RGBA8; natras->internalFormat = GL_RGBA;
// natras->format = GL_RGBA; natras->format = GL_RGBA;
// natras->type = GL_UNSIGNED_BYTE; natras->type = GL_UNSIGNED_BYTE;
// natras->bpp = 4; natras->bpp = 4;
#endif #endif
raster->stride = raster->width*natras->bpp; raster->stride = raster->width*natras->bpp;
@@ -251,6 +253,8 @@ rasterCreate(Raster *raster)
} }
} }
#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1))
uint8* uint8*
rasterLock(Raster *raster, int32 level, int32 lockMode) 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)){ if(lockMode & Raster::LOCKREAD || !(lockMode & Raster::LOCKNOFETCH)){
uint32 prev = bindTexture(natras->texid); 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); bindTexture(prev);
} }
@@ -302,6 +313,9 @@ rasterUnlock(Raster *raster, int32 level)
glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat, glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
raster->width, raster->height, raster->width, raster->height,
0, natras->format, natras->type, raster->pixels); 0, natras->format, natras->type, raster->pixels);
#ifdef PSP2_MIPMAPS
glGenerateMipmap(GL_TEXTURE_2D);
#endif
bindTexture(prev); bindTexture(prev);
} }
+4 -2
View File
@@ -64,9 +64,11 @@ drawInst_GSemu(InstanceDataHeader *header, InstanceData *inst)
void void
drawInst(InstanceDataHeader *header, InstanceData *inst) drawInst(InstanceDataHeader *header, InstanceData *inst)
{ {
#ifndef PSP2
if(rw::GetRenderState(rw::GSALPHATEST)) if(rw::GetRenderState(rw::GSALPHATEST))
drawInst_GSemu(header, inst); drawInst_GSemu(header, inst);
else else
#endif
drawInst_simple(header, inst); drawInst_simple(header, inst);
} }
@@ -132,11 +134,11 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
flushCache(); setTexture(0, m->texture);
setMaterial(m->color, m->surfaceProps); setMaterial(m->color, m->surfaceProps);
setTexture(0, m->texture); flushCache();
drawInst(header, inst); drawInst(header, inst);
inst++; inst++;
+2 -2
View File
@@ -275,11 +275,11 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
flushCache(); setTexture(0, m->texture);
setMaterial(m->color, m->surfaceProps); setMaterial(m->color, m->surfaceProps);
setTexture(0, m->texture); flushCache();
uploadSkinMatrices(atomic); uploadSkinMatrices(atomic);