From 1a9262dda9f16cb4dbf0ea9b6d756dc4ef2c264d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 9 Mar 2017 20:46:26 -0400 Subject: [PATCH] Fix compilation on iOS. Fix shader compilation on OpenGL ES. Fix (harmless) GL errors on OpenGL ES 2. Resolves issue #1266. --HG-- branch : minor --- src/modules/audio/openal/Effect.h | 2 ++ src/modules/graphics/opengl/OpenGL.cpp | 34 +++++++++++++++++--------- src/modules/graphics/opengl/OpenGL.h | 1 + src/modules/graphics/wrap_Graphics.lua | 9 +++++++ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/modules/audio/openal/Effect.h b/src/modules/audio/openal/Effect.h index 0512acc7a..547db2e6e 100644 --- a/src/modules/audio/openal/Effect.h +++ b/src/modules/audio/openal/Effect.h @@ -21,6 +21,8 @@ #ifndef LOVE_AUDIO_OPENAL_EFFECTS_H #define LOVE_AUDIO_OPENAL_EFFECTS_H +#include "common/config.h" + // OpenAL #ifdef LOVE_APPLE_USE_FRAMEWORKS // Frameworks have different include paths. #ifdef LOVE_IOS diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index afdf3b1bc..481c134c9 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -217,7 +217,12 @@ void OpenGL::setupContext() glActiveTexture(GL_TEXTURE0 + i); for (int j = 0; j < TEXTURE_MAX_ENUM; j++) - glBindTexture(getGLTextureType((TextureType) j), 0); + { + TextureType textype = (TextureType) j; + + if (isTextureTypeSupported(textype)) + glBindTexture(getGLTextureType(textype), 0); + } } glActiveTexture(GL_TEXTURE0); @@ -1004,16 +1009,7 @@ bool OpenGL::rawTexStorage(TextureType target, int levels, PixelFormat pixelform glTexParameteri(gltarget, GL_TEXTURE_SWIZZLE_A, fmt.swizzle[3]); } - bool supportsTexStorage = GLAD_VERSION_4_2 || GLAD_ARB_texture_storage; - - // Apparently there are bugs with glTexStorage on some Android drivers. I'd - // rather not find out the hard way, so we'll avoid it for now... -#ifndef LOVE_ANDROID - if (GLAD_ES_VERSION_3_0) - supportsTexStorage = true; -#endif - - if (supportsTexStorage) + if (isTexStorageSupported()) { if (target == TEXTURE_2D || target == TEXTURE_CUBE) glTexStorage2D(gltarget, levels, fmt.internalformat, width, height); @@ -1065,6 +1061,20 @@ bool OpenGL::rawTexStorage(TextureType target, int levels, PixelFormat pixelform return gltarget != GL_ZERO; } +bool OpenGL::isTexStorageSupported() +{ + bool supportsTexStorage = GLAD_VERSION_4_2 || GLAD_ARB_texture_storage; + + // Apparently there are bugs with glTexStorage on some Android drivers. I'd + // rather not find out the hard way, so we'll avoid it for now... +#ifndef LOVE_ANDROID + if (GLAD_ES_VERSION_3_0) + supportsTexStorage = true; +#endif + + return supportsTexStorage; +} + bool OpenGL::isTextureTypeSupported(TextureType type) const { switch (type) @@ -1432,7 +1442,7 @@ OpenGL::TextureFormat OpenGL::convertPixelFormat(PixelFormat pixelformat, bool r if (!isPixelFormatCompressed(pixelformat)) { if (GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 && pixelformat == PIXELFORMAT_LA8) - && !renderbuffer) + && !renderbuffer && !isTexStorageSupported()) { f.internalformat = f.externalformat; } diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index c3c8f7c58..8adf35648 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -378,6 +378,7 @@ public: static GLint getGLWrapMode(Texture::WrapMode wmode); static TextureFormat convertPixelFormat(PixelFormat pixelformat, bool renderbuffer, bool &isSRGB); + static bool isTexStorageSupported(); static bool isPixelFormatSupported(PixelFormat pixelformat, bool rendertarget, bool isSRGB); static bool hasTextureFilteringSupport(PixelFormat pixelformat); diff --git a/src/modules/graphics/wrap_Graphics.lua b/src/modules/graphics/wrap_Graphics.lua index 75828c65b..cae05a576 100644 --- a/src/modules/graphics/wrap_Graphics.lua +++ b/src/modules/graphics/wrap_Graphics.lua @@ -71,6 +71,15 @@ uniform LOVE_HIGHP_OR_MEDIUMP mat3 NormalMatrix; uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_ScreenSize;]] GLSL.FUNCTIONS = [[ +#ifdef GL_ES + #if __VERSION__ >= 300 || defined(GL_EXT_texture_array) + precision lowp sampler2DArray; + #endif + #if __VERSION__ >= 300 || defined(GL_OES_texture_3D) + precision lowp sampler3D; + #endif +#endif + #if __VERSION__ >= 130 && !defined(LOVE_GLSL1_ON_GLSL3) #define Texel texture #else