diff --git a/Core/Config.cpp b/Core/Config.cpp index df77f7ba2f..5ec26364f4 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -432,7 +432,9 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, true), #endif ReportedConfigSetting("ForceMaxEmulatedFPS", &g_Config.iForceMaxEmulatedFPS, 60, true, true), -#ifdef USING_GLES2 + + // TODO: Hm, on fast mobile GPUs we should definitely default to at least 4... +#ifdef MOBILE_DEVICE ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 0, true, true), #else ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 8, true, true), diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 3bab172e2f..b518576262 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -16,8 +16,9 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #if !defined(USING_GLES2) -// SDL 1.2 on Apple does not have support for OpenGL 3 and hence needs -// special treatment in the shader generator. +// We do not yet enable OpenGL 3 on Apple, so we need +// special treatment in the shader generator. However, the GL version check +// should be enough? TODO #if defined(__APPLE__) #define FORCE_OPENGL_2_0 #endif @@ -373,8 +374,7 @@ enum LogicOpReplaceType { }; static inline LogicOpReplaceType ReplaceLogicOpType() { -#if defined(USING_GLES2) - if (gstate.isLogicOpEnabled()) { + if (!gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP) && gstate.isLogicOpEnabled()) { switch (gstate.getLogicOp()) { case GE_LOGIC_COPY_INVERTED: case GE_LOGIC_AND_INVERTED: @@ -391,7 +391,6 @@ static inline LogicOpReplaceType ReplaceLogicOpType() { return LOGICOPTYPE_NORMAL; } } -#endif return LOGICOPTYPE_NORMAL; } @@ -426,14 +425,14 @@ void ComputeFragmentShaderID(ShaderID *id) { id0 |= (doTextureAlpha & 1) << 5; // rgb or rgba id0 |= (gstate_c.flipTexture & 1) << 6; -if (gstate_c.needShaderTexClamp) { - bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; - // 3 bits total. - id0 |= 1 << 7; - id0 |= gstate.isTexCoordClampedS() << 8; - id0 |= gstate.isTexCoordClampedT() << 9; - id0 |= (textureAtOffset & 1) << 10; -} + if (gstate_c.needShaderTexClamp) { + bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; + // 3 bits total. + id0 |= 1 << 7; + id0 |= gstate.isTexCoordClampedS() << 8; + id0 |= gstate.isTexCoordClampedT() << 9; + id0 |= (textureAtOffset & 1) << 10; + } } id0 |= (lmode & 1) << 11; diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 3e23885127..0099087acd 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -543,6 +543,10 @@ void GLES_GPU::CheckGPUFeatures() { if (!gl_extensions.IsGLES) features |= GPU_SUPPORTS_LOGIC_OP; + if (gl_extensions.GLES3 || !gl_extensions.IsGLES) { + features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL; + } + #ifdef MOBILE_DEVICE // Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc. features |= GPU_IS_MOBILE; diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index ab562bb090..8bc849267e 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -22,11 +22,11 @@ #include "GPU/GLES/ShaderManager.h" #include "GPU/GLES/TextureCache.h" -static const char *stencil_fs = -#ifdef USING_GLES2 +static const char *gles_prefix = "#version 100\n" -"precision highp float;\n" -#endif +"precision highp float;\n"; + +static const char *stencil_fs = "varying vec2 v_texcoord0;\n" "uniform float u_stencilValue;\n" "uniform sampler2D tex;\n" @@ -39,10 +39,6 @@ static const char *stencil_fs = "}\n"; static const char *stencil_vs = -#ifdef USING_GLES2 -"#version 100\n" -"precision highp float;\n" -#endif "attribute vec4 a_position;\n" "attribute vec2 a_texcoord0;\n" "varying vec2 v_texcoord0;\n" @@ -51,6 +47,14 @@ static const char *stencil_vs = " gl_Position = a_position;\n" "}\n"; +std::string GLSLES100PrefixProgram(std::string code) { + if (gl_extensions.IsGLES) { + return std::string(gles_prefix) + code; + } else { + return code; + } +} + static u8 StencilBits5551(const u8 *ptr8, u32 numPixels) { const u32 *ptr = (const u32 *)ptr8; @@ -146,7 +150,7 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size, bool skipZero) if (!stencilUploadProgram_) { std::string errorString; - stencilUploadProgram_ = glsl_create_source(stencil_vs, stencil_fs, &errorString); + stencilUploadProgram_ = glsl_create_source(GLSLES100PrefixProgram(stencil_vs).c_str(), GLSLES100PrefixProgram(stencil_fs).c_str(), &errorString); if (!stencilUploadProgram_) { ERROR_LOG_REPORT(G3D, "Failed to compile stencilUploadProgram! This shouldn't happen.\n%s", errorString.c_str()); } else { diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index ff352ca552..aba39f7ad1 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -719,20 +719,23 @@ void TextureCache::UpdateSamplingParams(TexCacheEntry &entry, bool force) { if (entry.maxLevel != 0) { if (force || entry.lodBias != lodBias) { + if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { + GETexLevelMode mode = gstate.getTexLevelMode(); + switch (mode) { + case GE_TEXLEVEL_MODE_AUTO: + // TODO + break; + case GE_TEXLEVEL_MODE_CONST: + // Sigh, LOD_BIAS is not even in ES 3.0.. #ifndef USING_GLES2 - GETexLevelMode mode = gstate.getTexLevelMode(); - switch (mode) { - case GE_TEXLEVEL_MODE_AUTO: - // TODO - break; - case GE_TEXLEVEL_MODE_CONST: - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, lodBias); - break; - case GE_TEXLEVEL_MODE_SLOPE: - // TODO - break; - } + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, lodBias); #endif + break; + case GE_TEXLEVEL_MODE_SLOPE: + // TODO + break; + } + } entry.lodBias = lodBias; } } @@ -1419,8 +1422,7 @@ void TextureCache::SetTexture(bool force) { break; } -#ifndef USING_GLES2 - if (i > 0) { + if (i > 0 && gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { int tw = gstate.getTextureWidth(i); int th = gstate.getTextureHeight(i); if (tw != 1 && tw != (gstate.getTextureWidth(i - 1) >> 1)) @@ -1428,7 +1430,6 @@ void TextureCache::SetTexture(bool force) { else if (th != 1 && th != (gstate.getTextureHeight(i - 1) >> 1)) badMipSizes = true; } -#endif } // In addition, simply don't load more than level 0 if g_Config.bMipMap is false. @@ -1506,34 +1507,28 @@ void TextureCache::SetTexture(bool force) { // Mipmapping only enable when texture scaling disable if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) { -#ifndef USING_GLES2 - if (badMipSizes) { - // WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format); - glGenerateMipmap(GL_TEXTURE_2D); - } else { - for (int i = 1; i <= maxLevel; i++) { - LoadTextureLevel(*entry, i, replaceImages, scaleFactor, dstFmt); + if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { + if (badMipSizes) { + // WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format); + glGenerateMipmap(GL_TEXTURE_2D); + } else { + for (int i = 1; i <= maxLevel; i++) { + LoadTextureLevel(*entry, i, replaceImages, scaleFactor, dstFmt); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (float)maxLevel); } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (float)maxLevel); - } -#else - // Avoid PowerVR driver bug - if (w > 1 && h > 1 && !(gl_extensions.gpuVendor == GPU_VENDOR_POWERVR && h > w)) { // Really! only seems to fail if height > width - // NOTICE_LOG(G3D, "Generating mipmap for texture sized %dx%d%d", w, h, (int)format); - glGenerateMipmap(GL_TEXTURE_2D); } else { - entry->maxLevel = 0; + // Avoid PowerVR driver bug + if (w > 1 && h > 1 && !(h > w && (gl_extensions.bugs & BUG_PVR_GENMIPMAP_HEIGHT_GREATER))) { // Really! only seems to fail if height > width + // NOTICE_LOG(G3D, "Generating mipmap for texture sized %dx%d%d", w, h, (int)format); + glGenerateMipmap(GL_TEXTURE_2D); + } else { + entry->maxLevel = 0; + } } -#endif - } else { -#ifndef USING_GLES2 + } else if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); -#else - if (gl_extensions.GLES3) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - } -#endif } int aniso = 1 << g_Config.iAnisotropyLevel; diff --git a/GPU/GPUState.h b/GPU/GPUState.h index d319a8205c..9099d846b7 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -454,6 +454,7 @@ enum { GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4), GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5), GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), + GPU_SUPPORTS_TEXTURE_LOD_CONTROL = FLAG_BIT(24), GPU_SUPPORTS_FBO = FLAG_BIT(25), GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26), GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27), diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2bbc151f21..2aa4854582 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -924,20 +924,20 @@ void EmuScreen::render() { screenManager()->getUIContext()->End(); } -#ifdef USING_GLES2 // We have no use for backbuffer depth or stencil, so let tiled renderers discard them after tiling. if (gl_extensions.GLES3 && glInvalidateFramebuffer != nullptr) { GLenum attachments[2] = { GL_DEPTH, GL_STENCIL }; glInvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments); } else if (!gl_extensions.GLES3) { +#ifdef USING_GLES2 // Tiled renderers like PowerVR should benefit greatly from this. However - seems I can't call it? bool hasDiscard = gl_extensions.EXT_discard_framebuffer; // TODO if (hasDiscard) { //const GLenum targets[3] = { GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT }; //glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, targets); } - } #endif + } } void EmuScreen::deviceLost() { diff --git a/native b/native index 6934d31090..67e22c29c2 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 6934d31090a25d44b23a05b6eaa7576cc4a4f4b9 +Subproject commit 67e22c29c2823c4f182e99920adff32ba88c1069