Skip to content

Commit

Permalink
Avoid forcing nearest/disabling linear if possible.
Browse files Browse the repository at this point in the history
If we know that the test is trivially true, we don't need to worry about
the test.  May help hrydgard#4405.
  • Loading branch information
unknownbrackets committed May 16, 2014
1 parent 6fcf25b commit 99458d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions GPU/GLES/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const bool safeDestFactors[16] = {
true, //GE_DSTBLEND_FIXB,
};

static bool IsAlphaTestTriviallyTrue() {
bool IsAlphaTestTriviallyTrue() {
switch (gstate.getAlphaTestFunction()) {
case GE_COMP_NEVER:
return false;
Expand Down Expand Up @@ -215,7 +215,7 @@ StencilValueType ReplaceAlphaWithStencilType() {
return STENCIL_VALUE_UNKNOWN;
}

static bool IsColorTestTriviallyTrue() {
bool IsColorTestTriviallyTrue() {
switch (gstate.getColorTestFunction()) {
case GE_COMP_NEVER:
return false;
Expand Down
2 changes: 2 additions & 0 deletions GPU/GLES/FragmentShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ enum ReplaceAlphaType {
REPLACE_ALPHA_DUALSOURCE = 2,
};

bool IsAlphaTestTriviallyTrue();
bool IsColorTestTriviallyTrue();
StencilValueType ReplaceAlphaWithStencilType();
ReplaceAlphaType ReplaceAlphaWithStencil();

19 changes: 13 additions & 6 deletions GPU/GLES/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "GPU/GPUState.h"
#include "GPU/GLES/TextureCache.h"
#include "GPU/GLES/Framebuffer.h"
#include "GPU/GLES/FragmentShaderGenerator.h"
#include "GPU/Common/TextureDecoder.h"
#include "Core/Config.h"
#include "Core/Host.h"
Expand Down Expand Up @@ -521,12 +522,18 @@ void TextureCache::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
}
}

if ((g_Config.iTexFiltering == LINEAR && !gstate.isColorTestEnabled() && !gstate.isAlphaTestEnabled()) || (g_Config.iTexFiltering == LINEARFMV && g_iNumVideos)) {
if (g_Config.iTexFiltering == LINEARFMV && g_iNumVideos > 0 && (entry.dim & 0xF) >= 9) {
magFilt |= 1;
minFilt |= 1;
}
if (g_Config.iTexFiltering == LINEAR && (!gstate.isColorTestEnabled() || IsColorTestTriviallyTrue())) {
if (!gstate.isAlphaTestEnabled() || IsAlphaTestTriviallyTrue()) {
magFilt |= 1;
minFilt |= 1;
}
}
// Force Nearest when color test enabled and rendering resolution greater than 480x272
if (g_Config.iTexFiltering == NEAREST || (gstate.isColorTestEnabled() && g_Config.iInternalResolution != 1 && gstate.isModeThrough())) {
if (g_Config.iTexFiltering == NEAREST || ((gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue()) && g_Config.iInternalResolution != 1 && gstate.isModeThrough())) {
magFilt &= ~1;
minFilt &= ~1;
}
Expand Down Expand Up @@ -878,12 +885,12 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry) {
entry->framebuffer->last_frame_used = gpuStats.numFlips;

// We need to force it, since we may have set it on a texture before attaching.
UpdateSamplingParams(*entry, true);
gstate_c.curTextureWidth = entry->framebuffer->width;
gstate_c.curTextureHeight = entry->framebuffer->height;
gstate_c.flipTexture = true;
gstate_c.textureFullAlpha = entry->framebuffer->format == GE_FORMAT_565;
gstate_c.textureSimpleAlpha = false;
UpdateSamplingParams(*entry, true);
} else {
if (entry->framebuffer->fbo)
entry->framebuffer->fbo = 0;
Expand Down Expand Up @@ -1296,15 +1303,15 @@ void TextureCache::SetTexture(bool force) {
float anisotropyLevel = (float) aniso > maxAnisotropyLevel ? maxAnisotropyLevel : (float) aniso;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropyLevel);

gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN;

UpdateSamplingParams(*entry, true);

//glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL;
gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN;
}

GLenum TextureCache::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {
Expand Down

0 comments on commit 99458d7

Please sign in to comment.