mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
disable-npots: Don't allow the GL version to be 2.0
Cogl now assumes non-power-of-two textures are supported if the GL version is >= 2.0 so the disable-npots utility should also change the GL version.
This commit is contained in:
parent
e80030755e
commit
8f1edcb6ed
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* If RTLD_NEXT isn't available then try just using NULL */
|
||||
#ifdef RTLD_NEXT
|
||||
@ -28,12 +29,48 @@ static const char * const bad_strings[]
|
||||
"GL_EXT_texture_rectangle",
|
||||
NULL };
|
||||
|
||||
static gboolean
|
||||
get_gl_version (const gchar *version_string,
|
||||
int *major_out, int *minor_out)
|
||||
{
|
||||
const char *major_end, *minor_end;
|
||||
int major = 0, minor = 0;
|
||||
|
||||
if (version_string == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Extract the major number */
|
||||
for (major_end = version_string; *major_end >= '0'
|
||||
&& *major_end <= '9'; major_end++)
|
||||
major = (major * 10) + *major_end - '0';
|
||||
/* If there were no digits or the major number isn't followed by a
|
||||
dot then it is invalid */
|
||||
if (major_end == version_string || *major_end != '.')
|
||||
return FALSE;
|
||||
|
||||
/* Extract the minor number */
|
||||
for (minor_end = major_end + 1; *minor_end >= '0'
|
||||
&& *minor_end <= '9'; minor_end++)
|
||||
minor = (minor * 10) + *minor_end - '0';
|
||||
/* If there were no digits or there is an unexpected character then
|
||||
it is invalid */
|
||||
if (minor_end == major_end + 1
|
||||
|| (*minor_end && *minor_end != ' ' && *minor_end != '.'))
|
||||
return FALSE;
|
||||
|
||||
*major_out = major;
|
||||
*minor_out = minor;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const GLubyte *
|
||||
glGetString (GLenum name)
|
||||
{
|
||||
const GLubyte *ret = NULL;
|
||||
const gchar *ret = NULL;
|
||||
static GetStringFunc func = NULL;
|
||||
static GLubyte *extensions = NULL;
|
||||
static gchar *extensions = NULL;
|
||||
static gchar *version = NULL;
|
||||
|
||||
if (func == NULL
|
||||
&& (func = (GetStringFunc) dlsym (LIB_HANDLE, "glGetString")) == NULL)
|
||||
@ -42,22 +79,22 @@ glGetString (GLenum name)
|
||||
fprintf (stderr, "dlsym returned the wrapper of glGetString\n");
|
||||
else
|
||||
{
|
||||
ret = (* func) (name);
|
||||
ret = (const gchar *) (* func) (name);
|
||||
|
||||
if (name == GL_EXTENSIONS)
|
||||
{
|
||||
if (extensions == NULL)
|
||||
{
|
||||
if ((extensions = (GLubyte *) strdup ((char *) ret)) == NULL)
|
||||
if ((extensions = strdup ((char *) ret)) == NULL)
|
||||
fprintf (stderr, "strdup: %s\n", strerror (errno));
|
||||
else
|
||||
{
|
||||
GLubyte *dst = extensions, *src = extensions;
|
||||
gchar *dst = extensions, *src = extensions;
|
||||
|
||||
while (1)
|
||||
{
|
||||
const char * const *str = bad_strings;
|
||||
GLubyte *end;
|
||||
gchar *end;
|
||||
|
||||
while (isspace (*src))
|
||||
*(dst++) = *(src++);
|
||||
@ -85,7 +122,35 @@ glGetString (GLenum name)
|
||||
|
||||
ret = extensions;
|
||||
}
|
||||
else if (name == GL_VERSION)
|
||||
{
|
||||
int gl_major, gl_minor;
|
||||
|
||||
/* If the GL version is >= 2.0 then Cogl will assume it
|
||||
supports NPOT textures anyway so we need to tweak it */
|
||||
if (get_gl_version ((const gchar *) ret,
|
||||
&gl_major, &gl_minor) && gl_major >= 2)
|
||||
{
|
||||
if (version == NULL)
|
||||
{
|
||||
const gchar *tail = strchr (ret, ' ');
|
||||
if (tail)
|
||||
{
|
||||
version = malloc (3 + strlen (tail) + 1);
|
||||
if (version)
|
||||
{
|
||||
strcpy (version + 3, tail);
|
||||
memcpy (version, "1.9", 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
version = strdup ("1.9");
|
||||
}
|
||||
|
||||
ret = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (const GLubyte *) ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user