From 0fd53e2e3d3242f88fdb4f7c7074340dc596902d Mon Sep 17 00:00:00 2001 From: Jordan Christiansen Date: Wed, 9 Dec 2020 19:54:36 -0600 Subject: [PATCH 01/16] Disable GL_EXT_texture_array on OpenGL ES 2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Nvidia Tegra 3 driver for Android (used by Ouya) erroneously claims to support the desktop-oriented GL_EXT_texture_array extension. On desktop GPUs using (non ES) OpenGL, the glTexImage3D and similar functions are always present, and the GL_EXT_texture_array extension simply adds support for texture arrays to those functions. On OpenGL ES 2.0, those functions do not exist, and GL_OES_texture_3D is required to define them. Calling glTexImage3D on the Tegra 3 causes a segfault. This change works around the issue by manually setting GLAD_EXT_texture_array to 0 on OpenGL ES 2.0 systems, which causes LÖVE to avoid codepaths that assume that the 3D texture functions are available. It doesn't make sense for any OpenGL ES 2.0 GPU to claim support for GL_EXT_texture_array. Fixes #1647 --- src/modules/graphics/opengl/OpenGL.cpp | 24 +++++++++++++------- src/modules/graphics/wrap_GraphicsShader.lua | 9 ++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index f2fcbb01a..cae7e74ec 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -391,15 +391,23 @@ void OpenGL::initOpenGLFunctions() } } - if (GLAD_ES_VERSION_2_0 && GLAD_OES_texture_3D && !GLAD_ES_VERSION_3_0) + if (GLAD_ES_VERSION_2_0 && !GLAD_ES_VERSION_3_0) { - // Function signatures don't match, we'll have to conditionally call it - //fp_glTexImage3D = fp_glTexImage3DOES; - fp_glTexSubImage3D = fp_glTexSubImage3DOES; - fp_glCopyTexSubImage3D = fp_glCopyTexSubImage3DOES; - fp_glCompressedTexImage3D = fp_glCompressedTexImage3DOES; - fp_glCompressedTexSubImage3D = fp_glCompressedTexSubImage3DOES; - fp_glFramebufferTexture3D = fp_glFramebufferTexture3DOES; + // The Nvidia Tegra 3 driver (used by Ouya) claims to support GL_EXT_texture_array but + // segfaults if you actually try to use it. OpenGL ES 2.0 devices should use OES_texture_3D. + // GL_EXT_texture_array is for desktops. + GLAD_EXT_texture_array = false; + + if (GLAD_OES_texture_3D) + { + // Function signatures don't match, we'll have to conditionally call it + //fp_glTexImage3D = fp_glTexImage3DOES; + fp_glTexSubImage3D = fp_glTexSubImage3DOES; + fp_glCopyTexSubImage3D = fp_glCopyTexSubImage3DOES; + fp_glCompressedTexImage3D = fp_glCompressedTexImage3DOES; + fp_glCompressedTexSubImage3D = fp_glCompressedTexSubImage3DOES; + fp_glFramebufferTexture3D = fp_glFramebufferTexture3DOES; + } } if (!GLAD_VERSION_3_2 && !GLAD_ES_VERSION_3_2 && !GLAD_ARB_draw_elements_base_vertex) diff --git a/src/modules/graphics/wrap_GraphicsShader.lua b/src/modules/graphics/wrap_GraphicsShader.lua index 095f21a19..2b4335240 100644 --- a/src/modules/graphics/wrap_GraphicsShader.lua +++ b/src/modules/graphics/wrap_GraphicsShader.lua @@ -54,7 +54,8 @@ GLSL.SYNTAX = [[ #define DepthCubeImage samplerCubeShadow #endif #define extern uniform -#ifdef GL_EXT_texture_array +#if defined(GL_EXT_texture_array) && (!defined(GL_ES) || __VERSION__ > 100) +#define texture_arrays_enabled #extension GL_EXT_texture_array : enable #endif #ifdef GL_OES_texture_3D @@ -85,7 +86,7 @@ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_ScreenSize; GLSL.FUNCTIONS = [[ #ifdef GL_ES - #if __VERSION__ >= 300 || defined(GL_EXT_texture_array) + #if __VERSION__ >= 300 || defined(texture_arrays_enabled) precision lowp sampler2DArray; #endif #if __VERSION__ >= 300 || defined(GL_OES_texture_3D) @@ -121,7 +122,7 @@ GLSL.FUNCTIONS = [[ #if __VERSION__ > 100 || defined(GL_OES_texture_3D) vec4 Texel(sampler3D s, vec3 c) { return love_texture3D(s, c); } #endif - #if __VERSION__ >= 130 || defined(GL_EXT_texture_array) + #if __VERSION__ >= 130 || defined(texture_arrays_enabled) vec4 Texel(sampler2DArray s, vec3 c) { return love_texture2DArray(s, c); } #endif #ifdef PIXEL @@ -130,7 +131,7 @@ GLSL.FUNCTIONS = [[ #if __VERSION__ > 100 || defined(GL_OES_texture_3D) vec4 Texel(sampler3D s, vec3 c, float b) { return love_texture3D(s, c, b); } #endif - #if __VERSION__ >= 130 || defined(GL_EXT_texture_array) + #if __VERSION__ >= 130 || defined(texture_arrays_enabled) vec4 Texel(sampler2DArray s, vec3 c, float b) { return love_texture2DArray(s, c, b); } #endif #endif From f3afdee70a3666fb774be99389c92da994f48666 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 23 Dec 2020 12:58:26 -0400 Subject: [PATCH 02/16] Keep math.mod and string.gfind when LuaJIT 2.1 is used Code written assuming LuaJIT 2.0 is being used might rely on them, even though they're deprecated (and removed in LuaJIT 2.1). --- src/modules/love/love.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 1dce17077..693952a68 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -362,6 +362,23 @@ static int w_deprecation__gc(lua_State *) return 0; } +static void luax_addcompatibilityalias(lua_State *L, const char *module, const char *name, const char *alias) +{ + lua_getglobal(L, module); + if (lua_istable(L, -1)) + { + lua_getfield(L, -1, alias); + bool hasalias = !lua_isnoneornil(L, -1); + lua_pop(L, 1); + if (!hasalias) + { + lua_getfield(L, -1, name); + lua_setfield(L, -2, alias); + } + } + lua_pop(L, 1); +} + int luaopen_love(lua_State *L) { love::luax_insistpinnedthread(L); @@ -469,6 +486,13 @@ int luaopen_love(lua_State *L) love::luax_require(L, "love.data"); lua_pop(L, 1); +#if LUA_VERSION_NUM <= 501 + // These are deprecated in Lua 5.1. LuaJIT 2.1 removes them, but code + // written assuming LuaJIT 2.0 or Lua 5.1 is used might still rely on them. + luax_addcompatibilityalias(L, "math", "fmod", "mod"); + luax_addcompatibilityalias(L, "string", "gmatch", "gfind"); +#endif + #ifdef LOVE_ENABLE_LUASOCKET love::luasocket::__open(L); #endif From ae4fe5bff9d024af98d2cf33a5cf553d7a3b3bf5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 23 Dec 2020 13:00:24 -0400 Subject: [PATCH 03/16] Update Xcode project files --- platform/xcode/liblove.xcodeproj/project.pbxproj | 2 +- platform/xcode/love.xcodeproj/project.pbxproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index 04886b3a2..1abcea551 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -4149,7 +4149,7 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1000; + LastUpgradeCheck = 1230; TargetAttributes = { FA0B78DC1A958B90000E1D17 = { CreatedOnToolsVersion = 6.1.1; diff --git a/platform/xcode/love.xcodeproj/project.pbxproj b/platform/xcode/love.xcodeproj/project.pbxproj index 38e3e5605..20e6eb592 100644 --- a/platform/xcode/love.xcodeproj/project.pbxproj +++ b/platform/xcode/love.xcodeproj/project.pbxproj @@ -328,7 +328,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1000; + LastUpgradeCheck = 1230; TargetAttributes = { FA0B7F051A95AAF3000E1D17 = { CreatedOnToolsVersion = 6.1.1; From 48a13d443b739d98f6ba95b6db73f102b5b787ec Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 23 Dec 2020 20:42:12 -0400 Subject: [PATCH 04/16] Fix validating glsl1 shaders using array textures on GLES3 --- src/modules/graphics/wrap_GraphicsShader.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/wrap_GraphicsShader.lua b/src/modules/graphics/wrap_GraphicsShader.lua index 3fbe9e10b..81f793482 100644 --- a/src/modules/graphics/wrap_GraphicsShader.lua +++ b/src/modules/graphics/wrap_GraphicsShader.lua @@ -54,8 +54,11 @@ GLSL.SYNTAX = [[ #define DepthCubeImage samplerCubeShadow #endif #define extern uniform -#if defined(GL_EXT_texture_array) && (!defined(GL_ES) || __VERSION__ > 100) -#define texture_arrays_enabled +#if defined(GL_EXT_texture_array) && (!defined(GL_ES) || __VERSION__ > 100 || defined(GL_OES_gpu_shader5)) +// Only used when !GLSLES1 to work around Ouya driver bug. But we still want it +// enabled for glslang validation when glsl 1-on-3 is used, so also enable it if +// OES_gpu_shader5 exists. +#define LOVE_EXT_TEXTURE_ARRAY_ENABLED #extension GL_EXT_texture_array : enable #endif #ifdef GL_OES_texture_3D @@ -86,7 +89,7 @@ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_ScreenSize; GLSL.FUNCTIONS = [[ #ifdef GL_ES - #if __VERSION__ >= 300 || defined(texture_arrays_enabled) + #if __VERSION__ >= 300 || defined(LOVE_EXT_TEXTURE_ARRAY_ENABLED) precision lowp sampler2DArray; #endif #if __VERSION__ >= 300 || defined(GL_OES_texture_3D) @@ -122,7 +125,7 @@ GLSL.FUNCTIONS = [[ #if __VERSION__ > 100 || defined(GL_OES_texture_3D) vec4 Texel(sampler3D s, vec3 c) { return love_texture3D(s, c); } #endif - #if __VERSION__ >= 130 || defined(texture_arrays_enabled) + #if __VERSION__ >= 130 || defined(LOVE_EXT_TEXTURE_ARRAY_ENABLED) vec4 Texel(sampler2DArray s, vec3 c) { return love_texture2DArray(s, c); } #endif #ifdef PIXEL @@ -131,7 +134,7 @@ GLSL.FUNCTIONS = [[ #if __VERSION__ > 100 || defined(GL_OES_texture_3D) vec4 Texel(sampler3D s, vec3 c, float b) { return love_texture3D(s, c, b); } #endif - #if __VERSION__ >= 130 || defined(texture_arrays_enabled) + #if __VERSION__ >= 130 || defined(LOVE_EXT_TEXTURE_ARRAY_ENABLED) vec4 Texel(sampler2DArray s, vec3 c, float b) { return love_texture2DArray(s, c, b); } #endif #endif From 57a2a88a09f43d989592119531c2b006b6cea466 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Thu, 24 Dec 2020 22:15:15 +0800 Subject: [PATCH 05/16] Android: Rename "openURL" Java method to "openURLFromLOVE" SDL 2.0.14 adds openURL method which conflicts with LOVE one. --- src/common/android.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/android.cpp b/src/common/android.cpp index 0b7724ef0..22a6ccefa 100644 --- a/src/common/android.cpp +++ b/src/common/android.cpp @@ -148,7 +148,14 @@ bool openURL(const std::string &url) JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv(); jclass activity = env->FindClass("org/love2d/android/GameActivity"); - jmethodID openURL = env->GetStaticMethodID(activity, "openURL", "(Ljava/lang/String;)Z"); + jmethodID openURL = env->GetStaticMethodID(activity, "openURLFromLOVE", "(Ljava/lang/String;)Z"); + + if (openURL == nullptr) + { + env->ExceptionClear(); + openURL = env->GetStaticMethodID(activity, "openURL", "(Ljava/lang/String;)Z"); + } + jstring url_jstring = (jstring) env->NewStringUTF(url.c_str()); jboolean result = env->CallStaticBooleanMethod(activity, openURL, url_jstring); From 9e460ba53e5d4c56d7a45c7580580f3a22ff12d0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 24 Dec 2020 12:29:00 -0400 Subject: [PATCH 06/16] Fix explicit window position not being restored in some cases when exiting fullscreen Fixes #1426 --- src/modules/window/sdl/Window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 81fccc233..2b1d635b5 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -481,7 +481,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) int x = f.x; int y = f.y; - if (f.useposition && !f.fullscreen) + if (f.useposition) { // The position needs to be in the global coordinate space. SDL_Rect displaybounds = {}; @@ -511,7 +511,7 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) // Enforce minimum window dimensions. SDL_SetWindowMinimumSize(window, f.minwidth, f.minheight); - if ((f.useposition || f.centered) && !f.fullscreen) + if (f.useposition || f.centered) SDL_SetWindowPosition(window, x, y); SDL_RaiseWindow(window); From 90bd8f18112d5ceb44a8303a6cba239c08865d55 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 24 Dec 2020 12:45:08 -0400 Subject: [PATCH 07/16] Update version --- extra/appveyor/appveyor.yml | 2 +- extra/windows/love.rc | Bin 3632 -> 3632 bytes platform/unix/love.6 | 2 +- platform/xcode/ios/love-ios.plist | 2 +- .../xcode/liblove.xcodeproj/project.pbxproj | 3 +++ platform/xcode/love.xcodeproj/project.pbxproj | 6 ++++++ platform/xcode/macosx/liblove-macosx.plist | 2 +- platform/xcode/macosx/love-macosx.plist | 2 +- src/common/version.h | 6 +++--- 9 files changed, 17 insertions(+), 8 deletions(-) diff --git a/extra/appveyor/appveyor.yml b/extra/appveyor/appveyor.yml index b081aa9a3..639d824db 100644 --- a/extra/appveyor/appveyor.yml +++ b/extra/appveyor/appveyor.yml @@ -1,4 +1,4 @@ -version: 11.3.{build} +version: 11.4.{build} image: Visual Studio 2013 diff --git a/extra/windows/love.rc b/extra/windows/love.rc index dd0b6b9976921f3430d23acd9a283a5aa19cb8c1..fc8777529416fbc735952c8ca6de3f7d5a493e82 100644 GIT binary patch delta 26 icmdlWvq5Hq3JbFdgVN+i7Wv6;ELMyrn;Tiya{>Tls0Td& delta 26 icmdlWvq5Hq3JbF_gVN+i7Wv6;ELM!hn;Tiya{>TlkOw;e diff --git a/platform/unix/love.6 b/platform/unix/love.6 index b621dd229..a2eb4c3d6 100644 --- a/platform/unix/love.6 +++ b/platform/unix/love.6 @@ -12,7 +12,7 @@ .\" 3. This notice may not be removed or altered from any source distribution. .Dd March 31, 2018 .Dt LOVE 6 -.Os LÖVE 11.3 +.Os LÖVE 11.4 .Sh NAME .Nm love .Nd 2D game development framework diff --git a/platform/xcode/ios/love-ios.plist b/platform/xcode/ios/love-ios.plist index 6abf7e335..21b2c64e5 100644 --- a/platform/xcode/ios/love-ios.plist +++ b/platform/xcode/ios/love-ios.plist @@ -36,7 +36,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 11.3 + $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index 1abcea551..0b3dbf5be 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -5330,6 +5330,7 @@ "$(inherited)", "$(PROJECT_DIR)/ios/libraries/freetype", ); + MARKETING_VERSION = 11.4; OTHER_LDFLAGS = ( "-undefined", dynamic_lookup, @@ -5373,6 +5374,7 @@ "$(inherited)", "$(PROJECT_DIR)/ios/libraries/freetype", ); + MARKETING_VERSION = 11.4; OTHER_LDFLAGS = ( "-undefined", dynamic_lookup, @@ -5417,6 +5419,7 @@ "$(inherited)", "$(PROJECT_DIR)/ios/libraries/freetype", ); + MARKETING_VERSION = 11.4; OTHER_LDFLAGS = ( "-undefined", dynamic_lookup, diff --git a/platform/xcode/love.xcodeproj/project.pbxproj b/platform/xcode/love.xcodeproj/project.pbxproj index 20e6eb592..67ea81532 100644 --- a/platform/xcode/love.xcodeproj/project.pbxproj +++ b/platform/xcode/love.xcodeproj/project.pbxproj @@ -462,6 +462,7 @@ INFOPLIST_FILE = "macosx/love-macosx.plist"; INSTALL_PATH = /Applications; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MARKETING_VERSION = 11.4; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; }; @@ -495,6 +496,7 @@ INFOPLIST_FILE = "macosx/love-macosx.plist"; INSTALL_PATH = /Applications; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MARKETING_VERSION = 11.4; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; }; @@ -704,6 +706,7 @@ ); INFOPLIST_FILE = "$(SRCROOT)/ios/love-ios.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MARKETING_VERSION = 11.4; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; @@ -750,6 +753,7 @@ ); INFOPLIST_FILE = "$(SRCROOT)/ios/love-ios.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MARKETING_VERSION = 11.4; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; @@ -797,6 +801,7 @@ ); INFOPLIST_FILE = "$(SRCROOT)/ios/love-ios.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MARKETING_VERSION = 11.4; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; @@ -918,6 +923,7 @@ INFOPLIST_FILE = "macosx/love-macosx.plist"; INSTALL_PATH = /Applications; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MARKETING_VERSION = 11.4; PRODUCT_BUNDLE_IDENTIFIER = org.love2d.love; PRODUCT_NAME = love; }; diff --git a/platform/xcode/macosx/liblove-macosx.plist b/platform/xcode/macosx/liblove-macosx.plist index b76e815fe..606144ce4 100644 --- a/platform/xcode/macosx/liblove-macosx.plist +++ b/platform/xcode/macosx/liblove-macosx.plist @@ -17,7 +17,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 11.3 + $(MARKETING_VERSION) CFBundleSignature LoVe NSPrincipalClass diff --git a/platform/xcode/macosx/love-macosx.plist b/platform/xcode/macosx/love-macosx.plist index 479346944..a59b85fe2 100644 --- a/platform/xcode/macosx/love-macosx.plist +++ b/platform/xcode/macosx/love-macosx.plist @@ -62,7 +62,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 11.3 + $(MARKETING_VERSION) CFBundleSignature LoVe LSApplicationCategoryType diff --git a/src/common/version.h b/src/common/version.h index f72740fcd..b41a3d083 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -25,12 +25,12 @@ namespace love { // Version stuff. -#define LOVE_VERSION_STRING "11.3" +#define LOVE_VERSION_STRING "11.4" static const int VERSION_MAJOR = 11; -static const int VERSION_MINOR = 3; +static const int VERSION_MINOR = 4; static const int VERSION_REV = 0; static const char *VERSION = LOVE_VERSION_STRING; -static const char *VERSION_COMPATIBILITY[] = { VERSION, "11.0", "11.1", "11.2", 0 }; +static const char *VERSION_COMPATIBILITY[] = { VERSION, "11.0", "11.1", "11.2", "11.3", 0 }; static const char *VERSION_CODENAME = "Mysterious Mysteries"; } // love From fe23c1619897eb357e2f064a1cafe4f5f8926ef9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 24 Dec 2020 20:31:33 -0400 Subject: [PATCH 08/16] Disable gamma correction on Windows + Intel HD 2/3000 / Intel HD Graphics It's completely broken there. Closes #1592 --- src/modules/graphics/opengl/Canvas.cpp | 9 --------- src/modules/graphics/opengl/Graphics.cpp | 4 ++-- src/modules/graphics/opengl/OpenGL.cpp | 16 ++++++++++++++-- src/modules/graphics/opengl/OpenGL.h | 7 +++++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 9bd14ab51..9a38c0305 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -39,11 +39,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo glGenFramebuffers(1, &framebuffer); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer); - // Might work around an Intel driver bug: https://github.com/love2d/love/issues/1592 - bool current_srgb = gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB); - if (current_srgb && isPixelFormatDepthStencil(format)) - gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, false); - if (texture != 0) { if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) @@ -110,10 +105,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo); - // Restore sRGB state if we turned it off above. - if (current_srgb && isPixelFormatDepthStencil(format)) - gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, current_srgb); - return status; } diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 6b5e229be..d826479ee 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -198,8 +198,8 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Set whether drawing converts input from linear -> sRGB colorspace. - if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB || GLAD_EXT_framebuffer_sRGB - || GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB) + if (!gl.bugs.brokenSRGB && (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB + || GLAD_EXT_framebuffer_sRGB || GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB)) { if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control) gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, isGammaCorrect()); diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 44d7f8767..a5757798f 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -155,6 +155,16 @@ bool OpenGL::initContext() if (strstr(device, "HD Graphics 4000") || strstr(device, "HD Graphics 2500")) bugs.clientWaitSyncStalls = true; } + + if (getVendor() == VENDOR_INTEL) + { + const char *device = (const char *) glGetString(GL_RENDERER); + if (strstr(device, "HD Graphics 3000") || strstr(device, "HD Graphics 2000") + || !strcmp(device, "Intel(R) HD Graphics") || !strcmp(device, "Intel(R) HD Graphics Family")) + { + bugs.brokenSRGB = true; + } + } #endif #ifdef LOVE_WINDOWS @@ -215,8 +225,8 @@ void OpenGL::setupContext() setEnableState(ENABLE_SCISSOR_TEST, state.enableState[ENABLE_SCISSOR_TEST]); setEnableState(ENABLE_FACE_CULL, state.enableState[ENABLE_FACE_CULL]); - if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB || GLAD_EXT_framebuffer_sRGB - || GLAD_EXT_sRGB_write_control) + if (!bugs.brokenSRGB && (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB + || GLAD_EXT_framebuffer_sRGB || GLAD_EXT_sRGB_write_control)) { setEnableState(ENABLE_FRAMEBUFFER_SRGB, state.enableState[ENABLE_FRAMEBUFFER_SRGB]); } @@ -1717,6 +1727,8 @@ bool OpenGL::isPixelFormatSupported(PixelFormat pixelformat, bool rendertarget, else return true; case PIXELFORMAT_sRGBA8: + if (gl.bugs.brokenSRGB) + return false; if (rendertarget) { if (GLAD_VERSION_1_0) diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index a1a6cb61a..a2467ad25 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -177,6 +177,13 @@ public: **/ bool brokenR8PixelFormat; + /** + * Intel HD Graphics drivers on Windows prior to the HD 2500/4000 have + * completely broken sRGB support. + * https://github.com/love2d/love/issues/1592 + **/ + bool brokenSRGB; + /** * Other bugs which have workarounds that don't use conditional code at * the moment: From 9c4db00e9490742317d4a493f5c11d7f7e200124 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Fri, 25 Dec 2020 21:45:32 +0800 Subject: [PATCH 09/16] Android: Fix changing orientation with t.window.fullscreen = true Fixes love2d/love-android#196 --- src/modules/window/sdl/Window.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 2b1d635b5..159c83550 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -440,8 +440,16 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) Uint32 sdlflags = SDL_WINDOW_OPENGL; - // On Android we always must have fullscreen type FULLSCREEN_TYPE_DESKTOP + // On Android, disable fullscreen first on window creation so it's + // possible to change the orientation by specifying portait width and + // height, otherwise SDL will pick the current orientation dimensions when + // fullscreen flag is set. Don't worry, we'll set it back later when user + // also requested fullscreen after the window is created. + // See https://github.com/love2d/love-android/issues/196 #ifdef LOVE_ANDROID + bool fullscreen = f.fullscreen; + + f.fullscreen = false; f.fstype = FULLSCREEN_DESKTOP; #endif @@ -527,8 +535,11 @@ bool Window::setWindow(int width, int height, WindowSettings *settings) graphics->setMode((int) scaledw, (int) scaledh, pixelWidth, pixelHeight, f.stencil); } + // Set fullscreen when user requested it before. + // See above for explanation. #ifdef LOVE_ANDROID - love::android::setImmersive(f.fullscreen); + setFullscreen(fullscreen); + love::android::setImmersive(fullscreen); #endif return true; From 4f730e930be0f7e814cadb4ac103e2457533ce2b Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 25 Dec 2020 16:13:29 -0400 Subject: [PATCH 10/16] Potential workaround for driver bug related to canvas mipmaps --- src/modules/graphics/opengl/Canvas.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 9a38c0305..947c51d20 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -60,12 +60,26 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo // Make sure all faces and layers of the texture are initialized to // transparent black. This is unfortunately probably pretty slow for // 2D-array and 3D textures with a lot of layers... + // Iterate backwards to make sure mip/layer/face 0 is bound at the end. for (int mip = nb_mips - 1; mip >= 0; mip--) { int nlayers = layers; if (texType == TEXTURE_VOLUME) nlayers = std::max(layers >> mip, 1); + GLuint tempframebuffer = 0; + if (mip > 0) + { + // Some Intel drivers on Windows don't like reusing the same + // FBO for different sized attachments, so use a temporary one + // to clear smaller mips. + // https://github.com/love2d/love/issues/1585 + glGenFramebuffers(1, &tempframebuffer); + gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, tempframebuffer); + } + else + gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer); + for (int layer = nlayers - 1; layer >= 0; layer--) { for (int face = faces - 1; face >= 0; face--) @@ -98,6 +112,9 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo } } } + + if (tempframebuffer != 0) + gl.deleteFramebuffer(tempframebuffer); } } From 95ab4054ff355b669f400f077feb31f09d3cdc59 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 26 Dec 2020 16:37:37 -0400 Subject: [PATCH 11/16] Fix a freeze on Intel drivers when using mipmapped Canvases Fixes #1585 Also disallow generateMipmaps on depth/stencil canvases because it's not really supported. --- src/modules/graphics/Canvas.cpp | 3 +++ src/modules/graphics/opengl/Canvas.cpp | 34 ++++++++++++------------ src/modules/graphics/opengl/Graphics.cpp | 4 --- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/modules/graphics/Canvas.cpp b/src/modules/graphics/Canvas.cpp index e8179271b..682967c27 100644 --- a/src/modules/graphics/Canvas.cpp +++ b/src/modules/graphics/Canvas.cpp @@ -69,6 +69,9 @@ Canvas::Canvas(const Settings &settings) filter.mipmap = defaultMipmapFilter; } + if (settings.mipmaps == MIPMAPS_AUTO && isPixelFormatDepthStencil(format)) + throw love::Exception("Automatic mipmap generation cannot be used for depth/stencil Canvases."); + auto gfx = Module::getInstance(Module::M_GRAPHICS); const Graphics::Capabilities &caps = gfx->getCapabilities(); diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 947c51d20..6d1a99745 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -67,19 +67,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo if (texType == TEXTURE_VOLUME) nlayers = std::max(layers >> mip, 1); - GLuint tempframebuffer = 0; - if (mip > 0) - { - // Some Intel drivers on Windows don't like reusing the same - // FBO for different sized attachments, so use a temporary one - // to clear smaller mips. - // https://github.com/love2d/love/issues/1585 - glGenFramebuffers(1, &tempframebuffer); - gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, tempframebuffer); - } - else - gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer); - for (int layer = nlayers - 1; layer >= 0; layer--) { for (int face = faces - 1; face >= 0; face--) @@ -112,9 +99,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo } } } - - if (tempframebuffer != 0) - gl.deleteFramebuffer(tempframebuffer); } } @@ -278,8 +262,18 @@ bool Canvas::loadVolatile() return false; } + // All mipmap levels need to be initialized - for color formats we can + // clear the base mip and use glGenerateMipmap after that's done. Depth + // and stencil formats don't always support glGenerateMipmap so we need + // to individually clear each mip level in that case. We avoid doing that + // for color formats because of an Intel driver bug: + // https://github.com/love2d/love/issues/1585 + int clearmips = 1; + if (isPixelFormatDepthStencil(format)) + clearmips = mipmapCount; + // Create a canvas-local FBO used for glReadPixels as well as MSAA blitting. - status = createFBO(fbo, texType, format, texture, texType == TEXTURE_VOLUME ? depth : layers, mipmapCount); + status = createFBO(fbo, texType, format, texture, texType == TEXTURE_VOLUME ? depth : layers, clearmips); if (status != GL_FRAMEBUFFER_COMPLETE) { @@ -290,6 +284,9 @@ bool Canvas::loadVolatile() } return false; } + + if (clearmips < mipmapCount && getMipmapMode() != MIPMAPS_NONE) + generateMipmaps(); } if (!isReadable() || actualSamples > 0) @@ -488,6 +485,9 @@ void Canvas::generateMipmaps() if (getMipmapCount() == 1 || getMipmapMode() == MIPMAPS_NONE) throw love::Exception("generateMipmaps can only be called on a Canvas which was created with mipmaps enabled."); + if (isPixelFormatDepthStencil(format)) + throw love::Exception("generateMipmaps cannot be called on a depth/stencil Canvas."); + gl.bindTextureToUnit(this, 0, false); GLenum gltextype = OpenGL::getGLTextureType(texType); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index d826479ee..5f11db41c 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -587,10 +587,6 @@ void Graphics::endPass() if (rt.canvas->getMipmapMode() == Canvas::MIPMAPS_AUTO && rt.mipmap == 0) rt.canvas->generateMipmaps(); } - - int dsmipmap = rts.depthStencil.mipmap; - if (depthstencil != nullptr && depthstencil->getMipmapMode() == Canvas::MIPMAPS_AUTO && dsmipmap == 0) - depthstencil->generateMipmaps(); } void Graphics::clear(OptionalColorf c, OptionalInt stencil, OptionalDouble depth) From 2682b75ebcef25f9a35a66dbedf692677e8ae846 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 26 Dec 2020 22:55:06 -0400 Subject: [PATCH 12/16] Change macOS/iOS deployment targets to Xcode 12's minimums --- platform/xcode/liblove.xcodeproj/project.pbxproj | 12 ++++++------ platform/xcode/love.xcodeproj/project.pbxproj | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index b503078da..d9218572f 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -5103,10 +5103,10 @@ "\"$(SRCROOT)/../../src/modules\"", "\"$(SRCROOT)/../../src/libraries/enet/libenet/include\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@rpath"; LIBRARY_SEARCH_PATHS = ""; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = NO; SDKROOT = macosx; USE_HEADERMAP = NO; @@ -5169,10 +5169,10 @@ "\"$(SRCROOT)/../../src/modules\"", "\"$(SRCROOT)/../../src/libraries/enet/libenet/include\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@rpath"; LIBRARY_SEARCH_PATHS = ""; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; USE_HEADERMAP = NO; @@ -5352,11 +5352,11 @@ "\"$(SRCROOT)/../../src/modules\"", "\"$(SRCROOT)/../../src/libraries/enet/libenet/include\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@rpath"; LIBRARY_SEARCH_PATHS = ""; LLVM_LTO = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = NO; SDKROOT = macosx; USE_HEADERMAP = NO; diff --git a/platform/xcode/love.xcodeproj/project.pbxproj b/platform/xcode/love.xcodeproj/project.pbxproj index 7b78fdd03..e54d93fc6 100644 --- a/platform/xcode/love.xcodeproj/project.pbxproj +++ b/platform/xcode/love.xcodeproj/project.pbxproj @@ -557,9 +557,9 @@ "\"$(SRCROOT)/../../src/modules\"", ); INFOPLIST_FILE = "love-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ""; "OTHER_LDFLAGS[arch=x86_64]" = ( @@ -638,10 +638,10 @@ "\"$(SRCROOT)/../../src/modules\"", ); INFOPLIST_FILE = "love-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; LLVM_LTO = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ""; "OTHER_LDFLAGS[arch=x86_64]" = ( @@ -869,10 +869,10 @@ "\"$(SRCROOT)/../../src/modules\"", ); INFOPLIST_FILE = "love-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; LLVM_LTO = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ""; "OTHER_LDFLAGS[arch=x86_64]" = ( From 769fcf5fc6b2588ea1f527a37cfc20ca799cc207 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 27 Dec 2020 15:01:09 -0400 Subject: [PATCH 13/16] macOS/iOS: allow c++17 language features --- platform/xcode/liblove.xcodeproj/project.pbxproj | 6 +++--- platform/xcode/love.xcodeproj/project.pbxproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index d9218572f..a17af7108 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -5055,7 +5055,7 @@ 10D5479E63C26BB35EB5482E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -5117,7 +5117,7 @@ 64274E785071353E1A1D0D4B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -5304,7 +5304,7 @@ FA5326C4189719C700F7BBF4 /* Distribution */ = { isa = XCBuildConfiguration; buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; diff --git a/platform/xcode/love.xcodeproj/project.pbxproj b/platform/xcode/love.xcodeproj/project.pbxproj index e54d93fc6..326654779 100644 --- a/platform/xcode/love.xcodeproj/project.pbxproj +++ b/platform/xcode/love.xcodeproj/project.pbxproj @@ -503,7 +503,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -582,7 +582,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -813,7 +813,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; From 2a5a90ccef1286a8018f082831cfcdcdd8cf0504 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 27 Dec 2020 19:17:47 -0400 Subject: [PATCH 14/16] Add 'vertexmain' and 'pixelmain' shader entry points. These are low level 'raw' entry points which don't declare any inputs or outputs themselves. They require GLSL 3 to use. --- src/modules/graphics/Graphics.cpp | 4 +- src/modules/graphics/Shader.cpp | 120 ++++++++++++++++++++++-------- src/modules/graphics/Shader.h | 11 ++- 3 files changed, 98 insertions(+), 37 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index fe2ae7339..f0c2cdfd7 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -268,7 +268,7 @@ Shader *Graphics::newShader(const std::vector &stagessource) if (!validstages[i]) continue; - if (info.isStage[i]) + if (info.stages[i] != Shader::ENTRYPOINT_NONE) { isanystage = true; stages[i].set(newShaderStage((ShaderStage::StageType) i, source, info), Acquire::NORETAIN); @@ -347,7 +347,7 @@ bool Graphics::validateShader(bool gles, const std::vector &stagess if (!validstages[i]) continue; - if (info.isStage[i]) + if (info.stages[i] != Shader::ENTRYPOINT_NONE) { isanystage = true; std::string glsl = Shader::createShaderStageCode(this, stype, source, info); diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index c45689e9c..c64770640 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -38,6 +38,7 @@ namespace graphics namespace glsl { + static const char global_syntax[] = R"( #if !defined(GL_ES) && __VERSION__ < 140 #define lowp @@ -275,6 +276,16 @@ void main() { } )"; +static const char vertex_main_raw[] = R"( +void vertexmain(); + +void main() { + love_initializeBuiltinUniforms(); + setPointSize(); + vertexmain(); +} +)"; + static const char pixel_header[] = R"( #ifdef GL_ES precision mediump float; @@ -284,29 +295,10 @@ static const char pixel_header[] = R"( #if __VERSION__ >= 130 #define varying in - // Some drivers seem to make the pixel shader do more work when multiple - // pixel shader outputs are defined, even when only one is actually used. - // TODO: We should use reflection or something instead of this, to determine - // how many outputs are actually used in the shader code. - #ifdef LOVE_MULTI_RENDER_TARGETS - layout(location = 0) out vec4 love_RenderTargets[love_MaxRenderTargets]; - #define love_PixelColor love_RenderTargets[0] - #else - layout(location = 0) out vec4 love_PixelColor; - #endif -#else - #ifdef LOVE_MULTI_RENDER_TARGETS - #define love_RenderTargets gl_FragData - #endif - #define love_PixelColor gl_FragColor #endif // Legacy #define love_MaxCanvases love_MaxRenderTargets -#define love_Canvases love_RenderTargets -#ifdef LOVE_MULTI_RENDER_TARGETS -#define LOVE_MULTI_CANVASES 1 -#endif // See Shader::updateScreenParams in Shader.cpp. #define love_PixelCoord (vec2(gl_FragCoord.x, (gl_FragCoord.y * love_ScreenSize.z) + love_ScreenSize.w)) @@ -335,6 +327,12 @@ vec4 VideoTexel(vec2 texcoords) { )"; static const char pixel_main[] = R"( +#if __VERSION__ >= 130 + layout(location = 0) out vec4 love_PixelColor; +#else + #define love_PixelColor gl_FragColor +#endif + uniform sampler2D MainTex; varying LOVE_HIGHP_OR_MEDIUMP vec4 VaryingTexCoord; varying mediump vec4 VaryingColor; @@ -348,6 +346,30 @@ void main() { )"; static const char pixel_main_custom[] = R"( +#if __VERSION__ >= 130 + // Some drivers seem to make the pixel shader do more work when multiple + // pixel shader outputs are defined, even when only one is actually used. + // TODO: We should use reflection or something instead of this, to determine + // how many outputs are actually used in the shader code. + #ifdef LOVE_MULTI_RENDER_TARGETS + layout(location = 0) out vec4 love_RenderTargets[love_MaxRenderTargets]; + #define love_PixelColor love_RenderTargets[0] + #else + layout(location = 0) out vec4 love_PixelColor; + #endif +#else + #ifdef LOVE_MULTI_RENDER_TARGETS + #define love_RenderTargets gl_FragData + #endif + #define love_PixelColor gl_FragColor +#endif + +// Legacy +#define love_Canvases love_RenderTargets +#ifdef LOVE_MULTI_RENDER_TARGETS +#define LOVE_MULTI_CANVASES 1 +#endif + varying LOVE_HIGHP_OR_MEDIUMP vec4 VaryingTexCoord; varying mediump vec4 VaryingColor; @@ -359,6 +381,15 @@ void main() { } )"; +static const char pixel_main_raw[] = R"( +void pixelmain(); + +void main() { + love_initializeBuiltinUniforms(); + pixelmain(); +} +)"; + struct StageInfo { const char *name; @@ -366,12 +397,13 @@ struct StageInfo const char *functions; const char *main; const char *main_custom; + const char *main_raw; }; static const StageInfo stageInfo[] = { - { "VERTEX", vertex_header, vertex_functions, vertex_main, vertex_main }, - { "PIXEL", pixel_header, pixel_functions, pixel_main, pixel_main_custom }, + { "VERTEX", vertex_header, vertex_functions, vertex_main, vertex_main, vertex_main_raw }, + { "PIXEL", pixel_header, pixel_functions, pixel_main, pixel_main_custom, pixel_main_raw }, }; static_assert((sizeof(stageInfo) / sizeof(StageInfo)) == ShaderStage::STAGE_MAX_ENUM, "Stages array size must match ShaderStage enum."); @@ -400,30 +432,38 @@ static Shader::Language getTargetLanguage(const std::string &src) return lang; } -static bool isVertexCode(const std::string &src) +static Shader::EntryPoint getVertexEntryPoint(const std::string &src) { - std::regex r("vec4\\s+position\\s*\\("); std::smatch m; - return std::regex_search(src, m, r); + + if (std::regex_search(src, m, std::regex("void\\s+vertexmain\\s*\\("))) + return Shader::ENTRYPOINT_RAW; + + if (std::regex_search(src, m, std::regex("vec4\\s+position\\s*\\("))) + return Shader::ENTRYPOINT_HIGHLEVEL; + + return Shader::ENTRYPOINT_NONE; } -static bool isPixelCode(const std::string &src, bool &custompixel, bool &mrt) +static Shader::EntryPoint getPixelEntryPoint(const std::string &src, bool &mrt) { - custompixel = false; mrt = false; std::smatch m; + + if (std::regex_search(src, m, std::regex("void\\s+pixelmain\\s*\\("))) + return Shader::ENTRYPOINT_RAW; + if (std::regex_search(src, m, std::regex("vec4\\s+effect\\s*\\("))) - return true; + return Shader::ENTRYPOINT_HIGHLEVEL; if (std::regex_search(src, m, std::regex("void\\s+effect\\s*\\("))) { - custompixel = true; if (src.find("love_RenderTargets") != std::string::npos || src.find("love_Canvases") != std::string::npos) mrt = true; - return true; + return Shader::ENTRYPOINT_CUSTOM; } - return false; + return Shader::ENTRYPOINT_NONE; } } // glsl @@ -439,8 +479,8 @@ Shader::SourceInfo Shader::getSourceInfo(const std::string &src) { SourceInfo info = {}; info.language = glsl::getTargetLanguage(src); - info.isStage[ShaderStage::STAGE_VERTEX] = glsl::isVertexCode(src); - info.isStage[ShaderStage::STAGE_PIXEL] = glsl::isPixelCode(src, info.customPixelFunction, info.usesMRT); + info.stages[ShaderStage::STAGE_VERTEX] = glsl::getVertexEntryPoint(src); + info.stages[ShaderStage::STAGE_PIXEL] = glsl::getPixelEntryPoint(src, info.usesMRT); return info; } @@ -449,6 +489,12 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStage::StageType if (info.language == Shader::LANGUAGE_MAX_ENUM) throw love::Exception("Invalid shader language"); + if (info.stages[stage] == ENTRYPOINT_NONE) + throw love::Exception("Cannot find entry point for shader stage."); + + if (info.stages[stage] == ENTRYPOINT_RAW && info.language == LANGUAGE_GLSL1) + throw love::Exception("Shaders using a raw entry point must use GLSL 3 or greater."); + const auto &features = gfx->getCapabilities().features; if (info.language == LANGUAGE_GLSL3 && !features[Graphics::FEATURE_GLSL3]) @@ -481,7 +527,15 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStage::StageType ss << glsl::global_uniforms; ss << glsl::global_functions; ss << stageinfo.functions; - ss << (info.customPixelFunction ? stageinfo.main_custom : stageinfo.main); + + if (info.stages[stage] == ENTRYPOINT_HIGHLEVEL) + ss << stageinfo.main; + else if (info.stages[stage] == ENTRYPOINT_CUSTOM) + ss << stageinfo.main_custom; + else if (info.stages[stage] == ENTRYPOINT_RAW) + ss << stageinfo.main_raw; + else + throw love::Exception("Unknown shader entry point %d", info.stages[stage]); ss << ((!gles && (lang == Shader::LANGUAGE_GLSL1 || glsl1on3)) ? "#line 0\n" : "#line 1\n"); ss << code; diff --git a/src/modules/graphics/Shader.h b/src/modules/graphics/Shader.h index 2c4717626..d75a6100c 100644 --- a/src/modules/graphics/Shader.h +++ b/src/modules/graphics/Shader.h @@ -90,11 +90,18 @@ public: STANDARD_MAX_ENUM }; + enum EntryPoint + { + ENTRYPOINT_NONE, + ENTRYPOINT_HIGHLEVEL, + ENTRYPOINT_CUSTOM, + ENTRYPOINT_RAW, + }; + struct SourceInfo { Language language; - bool isStage[ShaderStage::STAGE_MAX_ENUM]; - bool customPixelFunction; + EntryPoint stages[ShaderStage::STAGE_MAX_ENUM]; bool usesMRT; }; From 2fb88cb4a5f08f34675f6020c618b210dd66a862 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 27 Dec 2020 19:52:27 -0400 Subject: [PATCH 15/16] Remove some obsolete code --- src/modules/graphics/opengl/Texture.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/modules/graphics/opengl/Texture.cpp b/src/modules/graphics/opengl/Texture.cpp index dd027702d..2d7c8a62f 100644 --- a/src/modules/graphics/opengl/Texture.cpp +++ b/src/modules/graphics/opengl/Texture.cpp @@ -42,11 +42,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo glGenFramebuffers(1, &framebuffer); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer); - // Intel driver bug: https://github.com/love2d/love/issues/1592 - bool current_srgb = gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB); - if (current_srgb && isPixelFormatDepthStencil(format)) - gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, false); - if (texture != 0) { if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) @@ -112,10 +107,6 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo); - // Restore sRGB state if we turned it off above. - if (current_srgb && isPixelFormatDepthStencil(format)) - gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, current_srgb); - return status; } From 0ec7ea73de77660608fba8e054e671310f2199ae Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 30 Dec 2020 11:46:00 -0400 Subject: [PATCH 16/16] Improve error message slightly --- src/modules/graphics/Shader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/graphics/Shader.cpp b/src/modules/graphics/Shader.cpp index c64770640..df1990fc3 100644 --- a/src/modules/graphics/Shader.cpp +++ b/src/modules/graphics/Shader.cpp @@ -493,7 +493,7 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStage::StageType throw love::Exception("Cannot find entry point for shader stage."); if (info.stages[stage] == ENTRYPOINT_RAW && info.language == LANGUAGE_GLSL1) - throw love::Exception("Shaders using a raw entry point must use GLSL 3 or greater."); + throw love::Exception("Shaders using a raw entry point (vertexmain or pixelmain) must use GLSL 3 or greater."); const auto &features = gfx->getCapabilities().features;