Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created September 20, 2013 20:43
Embed
What would you like to do?
Why I'm touchy about over-zealous API deprecation.
static S32 hasext( char const * which )
{
#ifdef TARGET_GL_CORE
// GL Core deprecates glGetString(GL_EXTENSIONS)
GLint i, num_exts;
glGetIntegerv( GL_NUM_EXTENSIONS, &num_exts );
for ( i = 0 ; i < num_exts ; i++ )
if ( strcmp( which, (char const *) glGetStringi( GL_EXTENSIONS, i ) ) == 0 )
return 1;
return 0;
#else
char const * exts = (char const *) glGetString( GL_EXTENSIONS );
char const * where = strstr( exts, which );
size_t len = strlen( which );
if ( !where )
return 0;
return ( where == exts || *( where - 1 ) == ' ' ) && // starts with terminator
( where[ len ] == ' ' || where[ len ] == 0 ); // ends with terminator
#endif
}
static S32 Platform_Init()
{
#ifdef TARGET_GL_ES
s_HasUnpackRowLength = hasext( "GL_EXT_unpack_subimage" );
#endif
return 1;
}
static void update_texture_subrect( GLuint x0, GLuint y0, GLuint x1, GLuint y1, void const * buffer, GLsizei stride )
{
#ifdef GL_UNPACK_ROW_LENGTH
if ( s_HasUnpackRowLength )
{
glPixelStorei( GL_UNPACK_ROW_LENGTH, stride );
glTexSubImage2D( GL_TEXTURE_2D, 0, x0, y0, x1 - x0, y1 - y0, TEXFORMAT, GL_UNSIGNED_BYTE, (char *)buffer + y0*stride + x0 );
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
}
else
#endif
{
// without unpack row length, have to upload strided textures line by line
GLuint y;
for ( y = y0 ; y < y1 ; y++ )
glTexSubImage2D( GL_TEXTURE_2D, 0, x0, y, x1 - x0, 1, TEXFORMAT, GL_UNSIGNED_BYTE, (char *)Buffer + y*stride + x0 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment