@@ -90,6 +90,53 @@ int query_DXT_capability( void );
90
90
#define SOIL_RGBA_S3TC_DXT5 0x83F3
91
91
typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ) (GLenum target , GLint level , GLenum internalformat , GLsizei width , GLsizei height , GLint border , GLsizei imageSize , const GLvoid * data );
92
92
P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL ;
93
+ typedef const GLubyte * (APIENTRY * P_SOIL_GLGETSTRINGIPROC ) (GLenum name , GLuint index );
94
+
95
+ /**
96
+ https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=727175
97
+ "Most SOIL functions crash if OpenGL context is 3.2+ core profile. SOIL calls
98
+ glGetString with a value that is no longer valid, and then sends the returned
99
+ null pointer to strstr.
100
+ This patch checks the OpenGL version at runtime, and uses a glGetString function
101
+ that is appropriate and available. It doesn't crash if, for whatever reason,
102
+ glGetString returns a null pointer."
103
+ - Thanks to Brandon!
104
+ **/
105
+ static int SOIL_internal_has_OGL_capability (const char * cap )
106
+ {
107
+ int i ;
108
+ GLint num_ext ;
109
+ const GLubyte * ext_string ;
110
+ int major_version ;
111
+
112
+ const GLubyte * ver_string = glGetString (GL_VERSION );
113
+ if (ver_string )
114
+ major_version = atoi ((const char * ) ver_string );
115
+ else
116
+ major_version = 0 ;
117
+
118
+ P_SOIL_GLGETSTRINGIPROC soilGlGetStringi =
119
+ (P_SOIL_GLGETSTRINGIPROC ) glXGetProcAddressARB ((const GLubyte * ) "glGetStringi" );
120
+
121
+ if (major_version >= 3 && soilGlGetStringi ) {
122
+ // OpenGL 3.0+
123
+ glGetIntegerv (GL_NUM_EXTENSIONS , & num_ext );
124
+ for (i = 0 ; i < num_ext ; i ++ ) {
125
+ ext_string = soilGlGetStringi (GL_EXTENSIONS , i );
126
+ if (ext_string && !strcmp ((const char * ) ext_string , cap )) {
127
+ return GL_TRUE ;
128
+ }
129
+ }
130
+ }
131
+ else {
132
+ // OpenGL < 3.0
133
+ ext_string = glGetString (GL_EXTENSIONS );
134
+ if (ext_string && strstr ((const char * ) ext_string , cap )) {
135
+ return GL_TRUE ;
136
+ }
137
+ }
138
+ return GL_FALSE ;
139
+ }
93
140
unsigned int SOIL_direct_load_DDS (
94
141
const char * filename ,
95
142
unsigned int reuse_texture_ID ,
@@ -1725,7 +1772,7 @@ unsigned int SOIL_direct_load_DDS_from_memory(
1725
1772
/* do this for each face of the cubemap! */
1726
1773
for ( cf_target = ogl_target_start ; cf_target <= ogl_target_end ; ++ cf_target )
1727
1774
{
1728
- if ( buffer_index + DDS_full_size <= buffer_length )
1775
+ if ( buffer_index + DDS_full_size <= ( unsigned int ) buffer_length )
1729
1776
{
1730
1777
unsigned int byte_offset = DDS_main_size ;
1731
1778
memcpy ( (void * )DDS_data , (const void * )(& buffer [buffer_index ]), DDS_full_size );
@@ -1735,7 +1782,7 @@ unsigned int SOIL_direct_load_DDS_from_memory(
1735
1782
{
1736
1783
/* and remember, DXT uncompressed uses BGR(A),
1737
1784
so swap to RGB(A) for ALL MIPmap levels */
1738
- for ( i = 0 ; i < DDS_full_size ; i += block_size )
1785
+ for ( i = 0 ; i < ( int ) DDS_full_size ; i += block_size )
1739
1786
{
1740
1787
unsigned char temp = DDS_data [i ];
1741
1788
DDS_data [i ] = DDS_data [i + 2 ];
@@ -1872,29 +1919,25 @@ unsigned int SOIL_direct_load_DDS(
1872
1919
}
1873
1920
/* now try to do the loading */
1874
1921
tex_ID = SOIL_direct_load_DDS_from_memory (
1875
- (const unsigned char * const )buffer , buffer_length ,
1922
+ (const unsigned char * const )buffer , ( int ) buffer_length ,
1876
1923
reuse_texture_ID , flags , loading_as_cubemap );
1877
1924
SOIL_free_image_data ( buffer );
1878
1925
return tex_ID ;
1879
1926
}
1880
1927
1928
+ // GL_ARB_texture_non_power_of_two is a core feature in OpenGL 2.0
1881
1929
int query_NPOT_capability ( void )
1882
1930
{
1883
1931
/* check for the capability */
1884
1932
if ( has_NPOT_capability == SOIL_CAPABILITY_UNKNOWN )
1885
1933
{
1886
1934
/* we haven't yet checked for the capability, do so */
1887
- if (
1888
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1889
- "GL_ARB_texture_non_power_of_two" ) )
1890
- &&
1891
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1892
- "GL_OES_texture_npot" ) )
1893
- )
1935
+ if (!SOIL_internal_has_OGL_capability ("GL_ARB_texture_non_power_of_two" ))
1894
1936
{
1895
1937
/* not there, flag the failure */
1896
1938
has_NPOT_capability = SOIL_CAPABILITY_NONE ;
1897
- } else
1939
+ }
1940
+ else
1898
1941
{
1899
1942
/* it's there! */
1900
1943
has_NPOT_capability = SOIL_CAPABILITY_PRESENT ;
@@ -1904,26 +1947,21 @@ int query_NPOT_capability( void )
1904
1947
return has_NPOT_capability ;
1905
1948
}
1906
1949
1950
+ // GL_ARB_texture_rectangle is a core feature in OpenGL 3.1
1907
1951
int query_tex_rectangle_capability ( void )
1908
1952
{
1909
1953
/* check for the capability */
1910
1954
if ( has_tex_rectangle_capability == SOIL_CAPABILITY_UNKNOWN )
1911
1955
{
1912
1956
/* we haven't yet checked for the capability, do so */
1913
- if (
1914
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1915
- "GL_ARB_texture_rectangle" ) )
1916
- &&
1917
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1918
- "GL_EXT_texture_rectangle" ) )
1919
- &&
1920
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1921
- "GL_NV_texture_rectangle" ) )
1922
- )
1957
+ if (!SOIL_internal_has_OGL_capability ("GL_ARB_texture_rectangle" ) &&
1958
+ !SOIL_internal_has_OGL_capability ("GL_EXT_texture_rectangle" ) &&
1959
+ !SOIL_internal_has_OGL_capability ("GL_NV_texture_rectangle" ))
1923
1960
{
1924
1961
/* not there, flag the failure */
1925
1962
has_tex_rectangle_capability = SOIL_CAPABILITY_NONE ;
1926
- } else
1963
+ }
1964
+ else
1927
1965
{
1928
1966
/* it's there! */
1929
1967
has_tex_rectangle_capability = SOIL_CAPABILITY_PRESENT ;
@@ -1933,26 +1971,24 @@ int query_tex_rectangle_capability( void )
1933
1971
return has_tex_rectangle_capability ;
1934
1972
}
1935
1973
1974
+ // GL_ARB_texture_cube_map is a core feature in OpenGL 1.3
1936
1975
int query_cubemap_capability ( void )
1937
1976
{
1938
1977
/* check for the capability */
1939
1978
if ( has_cubemap_capability == SOIL_CAPABILITY_UNKNOWN )
1940
1979
{
1941
1980
/* we haven't yet checked for the capability, do so */
1942
- if (
1943
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1944
- "GL_ARB_texture_cube_map" ) )
1945
- &&
1946
- (NULL == strstr ( (char const * )glGetString ( GL_EXTENSIONS ),
1947
- "GL_EXT_texture_cube_map" ) )
1981
+ if (!SOIL_internal_has_OGL_capability ("GL_ARB_texture_cube_map" ) &&
1982
+ !SOIL_internal_has_OGL_capability ("GL_EXT_texture_cube_map" )
1948
1983
#ifdef GL_ES_VERSION_2_0
1949
1984
&& (0 ) /* GL ES 2.0 supports cubemaps, always enable */
1950
1985
#endif
1951
1986
)
1952
1987
{
1953
1988
/* not there, flag the failure */
1954
1989
has_cubemap_capability = SOIL_CAPABILITY_NONE ;
1955
- } else
1990
+ }
1991
+ else
1956
1992
{
1957
1993
/* it's there! */
1958
1994
has_cubemap_capability = SOIL_CAPABILITY_PRESENT ;
@@ -1962,19 +1998,20 @@ int query_cubemap_capability( void )
1962
1998
return has_cubemap_capability ;
1963
1999
}
1964
2000
2001
+ // GL_EXT_texture_compression_s3tc does not appear to be a core feature in any
2002
+ // version of OpenGL up to 4.4
1965
2003
int query_DXT_capability ( void )
1966
2004
{
1967
2005
/* check for the capability */
1968
2006
if ( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )
1969
2007
{
1970
2008
/* we haven't yet checked for the capability, do so */
1971
- if ( NULL == strstr (
1972
- (char const * )glGetString ( GL_EXTENSIONS ),
1973
- "GL_EXT_texture_compression_s3tc" ) )
2009
+ if (!SOIL_internal_has_OGL_capability ("GL_EXT_texture_compression_s3tc" ))
1974
2010
{
1975
2011
/* not there, flag the failure */
1976
2012
has_DXT_capability = SOIL_CAPABILITY_NONE ;
1977
- } else
2013
+ }
2014
+ else
1978
2015
{
1979
2016
/* and find the address of the extension function */
1980
2017
P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC ext_addr = NULL ;
0 commit comments