Skip to content

Commit

Permalink
Applied OpenGL 3.2+ fix patch
Browse files Browse the repository at this point in the history
  • Loading branch information
RaZeR-RBI committed Jan 3, 2019
1 parent 45368fc commit 40baa58
Showing 1 changed file with 59 additions and 17 deletions.
76 changes: 59 additions & 17 deletions src/soil.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,58 @@ int query_DXT_capability( void );
#define SOIL_RGBA_S3TC_DXT5 0x83F3
typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data);
P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL;
typedef const GLubyte* (APIENTRY * P_SOIL_GLGETSTRINGIPROC) (GLenum name, GLuint index);

/**
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=727175
"Most SOIL functions crash if OpenGL context is 3.2+ core profile. SOIL calls
glGetString with a value that is no longer valid, and then sends the returned
null pointer to strstr.
This patch checks the OpenGL version at runtime, and uses a glGetString function
that is appropriate and available. It doesn't crash if, for whatever reason,
glGetString returns a null pointer."
- Thanks to Brandon!
**/
static int SOIL_internal_has_OGL_capability(const char * cap)
{
int i;
GLint num_ext;
const GLubyte * ext_string;
int major_version;

const GLubyte * ver_string = glGetString(GL_VERSION);
if (ver_string)
major_version = atoi((const char *) ver_string);
else
major_version = 0;

P_SOIL_GLGETSTRINGIPROC soilGlGetStringi =
(P_SOIL_GLGETSTRINGIPROC) glXGetProcAddressARB((const GLubyte *) "glGetStringi");

if (major_version >= 3 && soilGlGetStringi) {
/* OpenGL 3.0+ */
glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext);
for (i = 0; i < num_ext; i++) {
ext_string = soilGlGetStringi(GL_EXTENSIONS, i);
if (ext_string && !strcmp((const char *) ext_string, cap)) {
return GL_TRUE;
}
}
}
else {
/* OpenGL < 3.0 */
ext_string = glGetString(GL_EXTENSIONS);
if (ext_string && strstr((const char *) ext_string, cap)) {
return GL_TRUE;
}
}
return GL_FALSE;
}

unsigned int SOIL_direct_load_DDS(
const char *filename,
unsigned int reuse_texture_ID,
Expand Down Expand Up @@ -1876,10 +1928,7 @@ int query_NPOT_capability( void )
if( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
{
/* we haven't yet checked for the capability, do so */
if(
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_ARB_texture_non_power_of_two" ) )
)
if(!SOIL_internal_has_OGL_capability("GL_ARB_texture_non_power_of_two"))
{
/* not there, flag the failure */
has_NPOT_capability = SOIL_CAPABILITY_NONE;
Expand All @@ -1900,14 +1949,11 @@ int query_tex_rectangle_capability( void )
{
/* we haven't yet checked for the capability, do so */
if(
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_ARB_texture_rectangle" ) )
(!SOIL_internal_has_OGL_capability("GL_ARB_texture_rectangle" ))
&&
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_EXT_texture_rectangle" ) )
(!SOIL_internal_has_OGL_capability("GL_EXT_texture_rectangle"))
&&
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_NV_texture_rectangle" ) )
(!SOIL_internal_has_OGL_capability("GL_NV_texture_rectangle" ))
)
{
/* not there, flag the failure */
Expand All @@ -1929,11 +1975,9 @@ int query_cubemap_capability( void )
{
/* we haven't yet checked for the capability, do so */
if(
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_ARB_texture_cube_map" ) )
(!SOIL_internal_has_OGL_capability("GL_ARB_texture_cube_map"))
&&
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_EXT_texture_cube_map" ) )
(!SOIL_internal_has_OGL_capability("GL_EXT_texture_cube_map"))
)
{
/* not there, flag the failure */
Expand All @@ -1954,9 +1998,7 @@ int query_DXT_capability( void )
if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )
{
/* we haven't yet checked for the capability, do so */
if( NULL == strstr(
(char const*)glGetString( GL_EXTENSIONS ),
"GL_EXT_texture_compression_s3tc" ) )
if(!SOIL_internal_has_OGL_capability("GL_EXT_texture_compression_s3tc"))
{
/* not there, flag the failure */
has_DXT_capability = SOIL_CAPABILITY_NONE;
Expand Down

0 comments on commit 40baa58

Please sign in to comment.