Skip to content

Commit

Permalink
Added support for GL_EXT_texture_edge_clamp as well since some GL imp…
Browse files Browse the repository at this point in the history
…lementations don't expose GL_SGIS_texture_edge_clamp even when clamp-to-edge functionality is supported. Fixes #880
  • Loading branch information
binary1248 committed May 10, 2015
1 parent 80214d1 commit d6fdb7f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/SFML/Graphics/GLExtensions.hpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/SFML/Graphics/GLExtensions.txt
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/SFML/Graphics/GLLoader.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/SFML/Graphics/GLLoader.hpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/SFML/Graphics/Texture.cpp
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -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)));
}
}
}
Expand Down

0 comments on commit d6fdb7f

Please sign in to comment.