mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Flip texcoord vertically when texturing from FBO to compensate for OpenGL coordinate systems
This commit is contained in:
parent
de626e329b
commit
2301a3b49e
7 changed files with 48 additions and 12 deletions
|
@ -542,6 +542,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GE_CMD_TEXTUREMAPENABLE:
|
case GE_CMD_TEXTUREMAPENABLE:
|
||||||
|
if (diff)
|
||||||
gstate_c.textureChanged = true;
|
gstate_c.textureChanged = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -549,14 +550,17 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GE_CMD_FOGCOLOR:
|
case GE_CMD_FOGCOLOR:
|
||||||
|
if (diff)
|
||||||
shaderManager_->DirtyUniform(DIRTY_FOGCOLOR);
|
shaderManager_->DirtyUniform(DIRTY_FOGCOLOR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GE_CMD_FOG1:
|
case GE_CMD_FOG1:
|
||||||
|
if (diff)
|
||||||
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GE_CMD_FOG2:
|
case GE_CMD_FOG2:
|
||||||
|
if (diff)
|
||||||
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -618,6 +622,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
||||||
case GE_CMD_TEXADDR6:
|
case GE_CMD_TEXADDR6:
|
||||||
case GE_CMD_TEXADDR7:
|
case GE_CMD_TEXADDR7:
|
||||||
gstate_c.textureChanged = true;
|
gstate_c.textureChanged = true;
|
||||||
|
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GE_CMD_TEXBUFWIDTH0:
|
case GE_CMD_TEXBUFWIDTH0:
|
||||||
|
|
|
@ -138,6 +138,7 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs)
|
||||||
glUniform1i(u_tex, 0);
|
glUniform1i(u_tex, 0);
|
||||||
// The rest, use the "dirty" mechanism.
|
// The rest, use the "dirty" mechanism.
|
||||||
dirtyUniforms = DIRTY_ALL;
|
dirtyUniforms = DIRTY_ALL;
|
||||||
|
use();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedShader::~LinkedShader() {
|
LinkedShader::~LinkedShader() {
|
||||||
|
@ -266,6 +267,8 @@ void LinkedShader::updateUniforms() {
|
||||||
if (u_uvscaleoffset != -1 && (dirtyUniforms & DIRTY_UVSCALEOFFSET)) {
|
if (u_uvscaleoffset != -1 && (dirtyUniforms & DIRTY_UVSCALEOFFSET)) {
|
||||||
float uvscaleoff[4] = {gstate_c.uScale, gstate_c.vScale, gstate_c.uOff, gstate_c.vOff};
|
float uvscaleoff[4] = {gstate_c.uScale, gstate_c.vScale, gstate_c.uOff, gstate_c.vOff};
|
||||||
if (gstate.isModeThrough()) {
|
if (gstate.isModeThrough()) {
|
||||||
|
// We never get here because we don't use HW transform with through mode.
|
||||||
|
// Although - why don't we?
|
||||||
uvscaleoff[0] /= gstate_c.curTextureWidth;
|
uvscaleoff[0] /= gstate_c.curTextureWidth;
|
||||||
uvscaleoff[1] /= gstate_c.curTextureHeight;
|
uvscaleoff[1] /= gstate_c.curTextureHeight;
|
||||||
uvscaleoff[2] /= gstate_c.curTextureWidth;
|
uvscaleoff[2] /= gstate_c.curTextureWidth;
|
||||||
|
|
|
@ -24,9 +24,20 @@
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "../Core/Config.h"
|
#include "../Core/Config.h"
|
||||||
|
|
||||||
// If a texture hasn't been seen for 200 frames, get rid of it.
|
// If a texture hasn't been seen for this many frames, get rid of it.
|
||||||
#define TEXTURE_KILL_AGE 200
|
#define TEXTURE_KILL_AGE 200
|
||||||
float maxAnisotropyLevel ;
|
|
||||||
|
u32 RoundUpToPowerOf2(u32 v)
|
||||||
|
{
|
||||||
|
v--;
|
||||||
|
v |= v >> 1;
|
||||||
|
v |= v >> 2;
|
||||||
|
v |= v >> 4;
|
||||||
|
v |= v >> 8;
|
||||||
|
v |= v >> 16;
|
||||||
|
v++;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
TextureCache::TextureCache() {
|
TextureCache::TextureCache() {
|
||||||
lastBoundTexture = -1;
|
lastBoundTexture = -1;
|
||||||
|
@ -681,22 +692,28 @@ void TextureCache::SetTexture() {
|
||||||
|
|
||||||
TexCache::iterator iter = cache.find(cachekey);
|
TexCache::iterator iter = cache.find(cachekey);
|
||||||
TexCacheEntry *entry = NULL;
|
TexCacheEntry *entry = NULL;
|
||||||
|
gstate_c.flipTexture = false;
|
||||||
|
|
||||||
if (iter != cache.end()) {
|
if (iter != cache.end()) {
|
||||||
entry = &iter->second;
|
entry = &iter->second;
|
||||||
// Check for FBO - slow!
|
// Check for FBO - slow!
|
||||||
if (entry->fbo) {
|
if (entry->fbo) {
|
||||||
|
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||||
|
int h = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||||
|
|
||||||
fbo_bind_color_as_texture(entry->fbo, 0);
|
fbo_bind_color_as_texture(entry->fbo, 0);
|
||||||
UpdateSamplingParams(*entry, false);
|
UpdateSamplingParams(*entry, false);
|
||||||
|
|
||||||
int fbow, fboh;
|
int fbow, fboh;
|
||||||
fbo_get_dimensions(entry->fbo, &fbow, &fboh);
|
fbo_get_dimensions(entry->fbo, &fbow, &fboh);
|
||||||
|
|
||||||
// Almost certain this isn't right.
|
// This isn't right.
|
||||||
gstate_c.curTextureWidth = fbow;
|
gstate_c.curTextureWidth = w; //w; //RoundUpToPowerOf2(fbow);
|
||||||
gstate_c.curTextureHeight = fboh;
|
gstate_c.curTextureHeight = h; // RoundUpToPowerOf2(fboh);
|
||||||
|
gstate_c.flipTexture = true;
|
||||||
|
entry->lastFrame = gpuStats.numFrames;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validate the texture here (width, height etc)
|
//Validate the texture here (width, height etc)
|
||||||
|
|
||||||
int dim = gstate.texsize[0] & 0xF0F;
|
int dim = gstate.texsize[0] & 0xF0F;
|
||||||
|
|
|
@ -101,5 +101,6 @@ private:
|
||||||
u16 *clutBuf16;
|
u16 *clutBuf16;
|
||||||
|
|
||||||
int lastBoundTexture;
|
int lastBoundTexture;
|
||||||
|
float maxAnisotropyLevel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -642,6 +642,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
||||||
memcpy(&transformed[index].x, v, 3 * sizeof(float));
|
memcpy(&transformed[index].x, v, 3 * sizeof(float));
|
||||||
transformed[index].fog = fogCoef;
|
transformed[index].fog = fogCoef;
|
||||||
memcpy(&transformed[index].u, uv, 2 * sizeof(float));
|
memcpy(&transformed[index].u, uv, 2 * sizeof(float));
|
||||||
|
if (gstate_c.flipTexture)
|
||||||
|
transformed[index].v = 1.0f - transformed[index].v * 2.0f;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
transformed[index].color0[i] = c0[i] * 255.0f;
|
transformed[index].color0[i] = c0[i] * 255.0f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,9 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim)
|
||||||
id->d[0] |= ((int)enableFog) << 2;
|
id->d[0] |= ((int)enableFog) << 2;
|
||||||
id->d[0] |= doTexture << 3;
|
id->d[0] |= doTexture << 3;
|
||||||
id->d[0] |= (hasColor & 1) << 4;
|
id->d[0] |= (hasColor & 1) << 4;
|
||||||
|
if (doTexture)
|
||||||
|
id->d[0] |= (gstate_c.flipTexture & 1) << 5;
|
||||||
|
|
||||||
if (CanUseHardwareTransform(prim)) {
|
if (CanUseHardwareTransform(prim)) {
|
||||||
id->d[0] |= 1 << 8;
|
id->d[0] |= 1 << 8;
|
||||||
id->d[0] |= (hasNormal & 1) << 9;
|
id->d[0] |= (hasNormal & 1) << 9;
|
||||||
|
@ -139,6 +142,7 @@ void GenerateVertexShader(int prim, char *buffer) {
|
||||||
bool hasColor = (gstate.vertType & GE_VTYPE_COL_MASK) != 0 || !hwXForm;
|
bool hasColor = (gstate.vertType & GE_VTYPE_COL_MASK) != 0 || !hwXForm;
|
||||||
bool hasNormal = (gstate.vertType & GE_VTYPE_NRM_MASK) != 0 && hwXForm;
|
bool hasNormal = (gstate.vertType & GE_VTYPE_NRM_MASK) != 0 && hwXForm;
|
||||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||||
|
bool flipV = gstate_c.flipTexture;
|
||||||
|
|
||||||
DoLightComputation doLight[4] = {LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF};
|
DoLightComputation doLight[4] = {LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF};
|
||||||
if (hwXForm) {
|
if (hwXForm) {
|
||||||
|
@ -396,6 +400,8 @@ void GenerateVertexShader(int prim, char *buffer) {
|
||||||
// ILLEGAL
|
// ILLEGAL
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (flipV)
|
||||||
|
WRITE(p, " v_texcoord.y = 1.0f - v_texcoord.y;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute fogdepth
|
// Compute fogdepth
|
||||||
|
|
|
@ -238,6 +238,8 @@ struct GPUStateCache
|
||||||
|
|
||||||
float uScale,vScale;
|
float uScale,vScale;
|
||||||
float uOff,vOff;
|
float uOff,vOff;
|
||||||
|
bool flipTexture;
|
||||||
|
|
||||||
float zMin, zMax;
|
float zMin, zMax;
|
||||||
float lightpos[4][3];
|
float lightpos[4][3];
|
||||||
float lightdir[4][3];
|
float lightdir[4][3];
|
||||||
|
|
Loading…
Add table
Reference in a new issue