From 45577de60a172cd1c92a278320688736134a0ed1 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 10 May 2015 17:04:01 +0200 Subject: [PATCH] Added support for GL_EXT_texture_edge_clamp as well since some GL implementations don't expose GL_SGIS_texture_edge_clamp even when clamp-to-edge functionality is supported. Fixes #880 --- src/SFML/Graphics/GLExtensions.hpp | 4 ++++ src/SFML/Graphics/GLExtensions.txt | 1 + src/SFML/Graphics/GLLoader.cpp | 7 +++++-- src/SFML/Graphics/GLLoader.hpp | 3 +++ src/SFML/Graphics/Texture.cpp | 16 ++++++++++------ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/SFML/Graphics/GLExtensions.hpp b/src/SFML/Graphics/GLExtensions.hpp index 7cff5947..52195a19 100644 --- a/src/SFML/Graphics/GLExtensions.hpp +++ b/src/SFML/Graphics/GLExtensions.hpp @@ -45,6 +45,7 @@ // Core since 1.0 #define GLEXT_multitexture true #define GLEXT_texture_edge_clamp true + #define GLEXT_EXT_texture_edge_clamp true #define GLEXT_blend_minmax true #define GLEXT_glClientActiveTexture glClientActiveTexture #define GLEXT_glActiveTexture glActiveTexture @@ -130,6 +131,9 @@ #define GLEXT_texture_edge_clamp sfogl_ext_SGIS_texture_edge_clamp #define GLEXT_GL_CLAMP_TO_EDGE GL_CLAMP_TO_EDGE_SGIS + // Core since 1.2 - EXT_texture_edge_clamp + #define GLEXT_EXT_texture_edge_clamp sfogl_ext_EXT_texture_edge_clamp + // Core since 1.2 - EXT_blend_minmax #define GLEXT_blend_minmax sfogl_ext_EXT_blend_minmax #define GLEXT_glBlendEquation glBlendEquationEXT diff --git a/src/SFML/Graphics/GLExtensions.txt b/src/SFML/Graphics/GLExtensions.txt index 5f2b5b33..033404d2 100644 --- a/src/SFML/Graphics/GLExtensions.txt +++ b/src/SFML/Graphics/GLExtensions.txt @@ -4,6 +4,7 @@ // lua LoadGen.lua -style=pointer_c -spec=gl -version=1.1 -indent=space -prefix=sf -extfile=GLExtensions.txt GLLoader SGIS_texture_edge_clamp +//EXT_texture_edge_clamp EXT_blend_minmax EXT_blend_subtract ARB_multitexture diff --git a/src/SFML/Graphics/GLLoader.cpp b/src/SFML/Graphics/GLLoader.cpp index cceab2f4..e82cd7a2 100644 --- a/src/SFML/Graphics/GLLoader.cpp +++ b/src/SFML/Graphics/GLLoader.cpp @@ -50,6 +50,7 @@ static sf::GlFunctionPointer IntGetProcAddress(const char* name) } int sfogl_ext_SGIS_texture_edge_clamp = sfogl_LOAD_FAILED; +int sfogl_ext_EXT_texture_edge_clamp = sfogl_LOAD_FAILED; int sfogl_ext_EXT_blend_minmax = sfogl_LOAD_FAILED; int sfogl_ext_EXT_blend_subtract = sfogl_LOAD_FAILED; int sfogl_ext_ARB_multitexture = sfogl_LOAD_FAILED; @@ -317,8 +318,9 @@ typedef struct sfogl_StrToExtMap_s PFN_LOADFUNCPOINTERS LoadExtension; } sfogl_StrToExtMap; -static sfogl_StrToExtMap ExtensionMap[12] = { +static sfogl_StrToExtMap ExtensionMap[13] = { {"GL_SGIS_texture_edge_clamp", &sfogl_ext_SGIS_texture_edge_clamp, NULL}, + {"GL_EXT_texture_edge_clamp", &sfogl_ext_EXT_texture_edge_clamp, NULL}, {"GL_EXT_blend_minmax", &sfogl_ext_EXT_blend_minmax, Load_EXT_blend_minmax}, {"GL_EXT_blend_subtract", &sfogl_ext_EXT_blend_subtract, NULL}, {"GL_ARB_multitexture", &sfogl_ext_ARB_multitexture, Load_ARB_multitexture}, @@ -332,7 +334,7 @@ static sfogl_StrToExtMap ExtensionMap[12] = { {"GL_EXT_framebuffer_object", &sfogl_ext_EXT_framebuffer_object, Load_EXT_framebuffer_object} }; -static int g_extensionMapSize = 12; +static int g_extensionMapSize = 13; static sfogl_StrToExtMap *FindExtEntry(const char *extensionName) { @@ -350,6 +352,7 @@ static sfogl_StrToExtMap *FindExtEntry(const char *extensionName) static void ClearExtensionVars() { sfogl_ext_SGIS_texture_edge_clamp = sfogl_LOAD_FAILED; + sfogl_ext_EXT_texture_edge_clamp = sfogl_LOAD_FAILED; sfogl_ext_EXT_blend_minmax = sfogl_LOAD_FAILED; sfogl_ext_EXT_blend_subtract = sfogl_LOAD_FAILED; sfogl_ext_ARB_multitexture = sfogl_LOAD_FAILED; diff --git a/src/SFML/Graphics/GLLoader.hpp b/src/SFML/Graphics/GLLoader.hpp index 42e1e093..00064065 100644 --- a/src/SFML/Graphics/GLLoader.hpp +++ b/src/SFML/Graphics/GLLoader.hpp @@ -174,6 +174,7 @@ extern "C" { #endif /*__cplusplus*/ extern int sfogl_ext_SGIS_texture_edge_clamp; +extern int sfogl_ext_EXT_texture_edge_clamp; extern int sfogl_ext_EXT_blend_minmax; extern int sfogl_ext_EXT_blend_subtract; extern int sfogl_ext_ARB_multitexture; @@ -188,6 +189,8 @@ extern int sfogl_ext_EXT_framebuffer_object; #define GL_CLAMP_TO_EDGE_SGIS 0x812F +#define GL_CLAMP_TO_EDGE_EXT 0x812F + #define GL_BLEND_EQUATION_EXT 0x8009 #define GL_FUNC_ADD_EXT 0x8006 #define GL_MAX_EXT 0x8008 diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index a747a2db..610dfa2c 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -158,7 +158,9 @@ bool Texture::create(unsigned int width, unsigned int height) // Make sure that the current texture binding will be preserved priv::TextureSaver save; - if (!m_isRepeated && !GLEXT_texture_edge_clamp) + static bool textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; + + if (!m_isRepeated && !textureEdgeClamp) { static bool warned = false; @@ -175,8 +177,8 @@ bool Texture::create(unsigned int width, unsigned int height) // Initialize the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); - glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (GLEXT_texture_edge_clamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); - glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (GLEXT_texture_edge_clamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_cacheId = getUniqueId(); @@ -480,7 +482,9 @@ void Texture::setRepeated(bool repeated) // Make sure that the current texture binding will be preserved priv::TextureSaver save; - if (!m_isRepeated && !GLEXT_texture_edge_clamp) + static bool textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; + + if (!m_isRepeated && !textureEdgeClamp) { static bool warned = false; @@ -495,8 +499,8 @@ void Texture::setRepeated(bool repeated) } glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (GLEXT_texture_edge_clamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); - glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (GLEXT_texture_edge_clamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); + glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); } } }