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;
|
||||
|
||||
case GE_CMD_TEXTUREMAPENABLE:
|
||||
if (diff)
|
||||
gstate_c.textureChanged = true;
|
||||
break;
|
||||
|
||||
|
@ -549,14 +550,17 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
|||
break;
|
||||
|
||||
case GE_CMD_FOGCOLOR:
|
||||
if (diff)
|
||||
shaderManager_->DirtyUniform(DIRTY_FOGCOLOR);
|
||||
break;
|
||||
|
||||
case GE_CMD_FOG1:
|
||||
if (diff)
|
||||
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
||||
break;
|
||||
|
||||
case GE_CMD_FOG2:
|
||||
if (diff)
|
||||
shaderManager_->DirtyUniform(DIRTY_FOGCOEF);
|
||||
break;
|
||||
|
||||
|
@ -618,6 +622,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
|||
case GE_CMD_TEXADDR6:
|
||||
case GE_CMD_TEXADDR7:
|
||||
gstate_c.textureChanged = true;
|
||||
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
||||
break;
|
||||
|
||||
case GE_CMD_TEXBUFWIDTH0:
|
||||
|
@ -667,7 +672,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
|||
|
||||
case GE_CMD_TEXSIZE0:
|
||||
gstate_c.curTextureWidth = 1 << (gstate.texsize[0] & 0xf);
|
||||
gstate_c.curTextureHeight = 1 << ((gstate.texsize[0]>>8) & 0xf);
|
||||
gstate_c.curTextureHeight = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
||||
//fall thru - ignoring the mipmap sizes for now
|
||||
case GE_CMD_TEXSIZE1:
|
||||
|
|
|
@ -138,6 +138,7 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs)
|
|||
glUniform1i(u_tex, 0);
|
||||
// The rest, use the "dirty" mechanism.
|
||||
dirtyUniforms = DIRTY_ALL;
|
||||
use();
|
||||
}
|
||||
|
||||
LinkedShader::~LinkedShader() {
|
||||
|
@ -264,8 +265,10 @@ void LinkedShader::updateUniforms() {
|
|||
|
||||
// Texturing
|
||||
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()) {
|
||||
// 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[1] /= gstate_c.curTextureHeight;
|
||||
uvscaleoff[2] /= gstate_c.curTextureWidth;
|
||||
|
|
|
@ -24,9 +24,20 @@
|
|||
#include "TextureCache.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
|
||||
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() {
|
||||
lastBoundTexture = -1;
|
||||
|
@ -681,22 +692,28 @@ void TextureCache::SetTexture() {
|
|||
|
||||
TexCache::iterator iter = cache.find(cachekey);
|
||||
TexCacheEntry *entry = NULL;
|
||||
gstate_c.flipTexture = false;
|
||||
|
||||
if (iter != cache.end()) {
|
||||
entry = &iter->second;
|
||||
// Check for FBO - slow!
|
||||
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);
|
||||
UpdateSamplingParams(*entry, false);
|
||||
|
||||
int fbow, fboh;
|
||||
fbo_get_dimensions(entry->fbo, &fbow, &fboh);
|
||||
|
||||
// Almost certain this isn't right.
|
||||
gstate_c.curTextureWidth = fbow;
|
||||
gstate_c.curTextureHeight = fboh;
|
||||
// This isn't right.
|
||||
gstate_c.curTextureWidth = w; //w; //RoundUpToPowerOf2(fbow);
|
||||
gstate_c.curTextureHeight = h; // RoundUpToPowerOf2(fboh);
|
||||
gstate_c.flipTexture = true;
|
||||
entry->lastFrame = gpuStats.numFrames;
|
||||
return;
|
||||
}
|
||||
|
||||
//Validate the texture here (width, height etc)
|
||||
|
||||
int dim = gstate.texsize[0] & 0xF0F;
|
||||
|
|
|
@ -101,5 +101,6 @@ private:
|
|||
u16 *clutBuf16;
|
||||
|
||||
int lastBoundTexture;
|
||||
float maxAnisotropyLevel;
|
||||
};
|
||||
|
||||
|
|
|
@ -642,6 +642,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
|||
memcpy(&transformed[index].x, v, 3 * sizeof(float));
|
||||
transformed[index].fog = fogCoef;
|
||||
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++) {
|
||||
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] |= doTexture << 3;
|
||||
id->d[0] |= (hasColor & 1) << 4;
|
||||
if (doTexture)
|
||||
id->d[0] |= (gstate_c.flipTexture & 1) << 5;
|
||||
|
||||
if (CanUseHardwareTransform(prim)) {
|
||||
id->d[0] |= 1 << 8;
|
||||
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 hasNormal = (gstate.vertType & GE_VTYPE_NRM_MASK) != 0 && hwXForm;
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool flipV = gstate_c.flipTexture;
|
||||
|
||||
DoLightComputation doLight[4] = {LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF};
|
||||
if (hwXForm) {
|
||||
|
@ -396,6 +400,8 @@ void GenerateVertexShader(int prim, char *buffer) {
|
|||
// ILLEGAL
|
||||
break;
|
||||
}
|
||||
if (flipV)
|
||||
WRITE(p, " v_texcoord.y = 1.0f - v_texcoord.y;\n");
|
||||
}
|
||||
|
||||
// Compute fogdepth
|
||||
|
|
|
@ -238,6 +238,8 @@ struct GPUStateCache
|
|||
|
||||
float uScale,vScale;
|
||||
float uOff,vOff;
|
||||
bool flipTexture;
|
||||
|
||||
float zMin, zMax;
|
||||
float lightpos[4][3];
|
||||
float lightdir[4][3];
|
||||
|
|
Loading…
Add table
Reference in a new issue