Added SDL_GL_ExtensionSupported()
Use GL_ARB_texture_rectangle in the OpenGL renderer, if supported. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401971
This commit is contained in:
parent
f4ac9ed70c
commit
c05ca3687f
4 changed files with 96 additions and 28 deletions
|
@ -1458,6 +1458,14 @@ extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
|
extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \fn SDL_bool SDL_GL_ExtensionSupported(const char *extension)
|
||||||
|
*
|
||||||
|
* \brief Return true if an OpenGL extension is supported for the current context.
|
||||||
|
*/
|
||||||
|
extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
|
||||||
|
*extension);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
* \fn int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
||||||
*
|
*
|
||||||
|
|
|
@ -97,6 +97,7 @@ SDL_RenderDriver GL_RenderDriver = {
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SDL_GLContext context;
|
SDL_GLContext context;
|
||||||
|
SDL_bool GL_ARB_texture_rectangle_supported;
|
||||||
} GL_RenderData;
|
} GL_RenderData;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -226,16 +227,19 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_width);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_width);
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_height);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_height);
|
||||||
|
|
||||||
/* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */
|
if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
|
||||||
|
|| SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
|
||||||
|
data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up parameters for rendering */
|
/* Set up parameters for rendering */
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
#ifdef USE_GL_TEXTURE_RECTANGLE
|
if (data->GL_ARB_texture_rectangle_supported) {
|
||||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||||
#else
|
} else {
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
#endif
|
}
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
@ -369,19 +373,19 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||||
|
|
||||||
glGetError();
|
glGetError();
|
||||||
glGenTextures(1, &data->texture);
|
glGenTextures(1, &data->texture);
|
||||||
#ifdef USE_GL_TEXTURE_RECTANGLE
|
if (renderdata->GL_ARB_texture_rectangle_supported) {
|
||||||
data->type = GL_TEXTURE_RECTANGLE_ARB;
|
data->type = GL_TEXTURE_RECTANGLE_ARB;
|
||||||
texture_w = texture->w;
|
texture_w = texture->w;
|
||||||
texture_h = texture->h;
|
texture_h = texture->h;
|
||||||
data->texw = (GLfloat) texture->w;
|
data->texw = (GLfloat) texture->w;
|
||||||
data->texh = (GLfloat) texture->h;
|
data->texh = (GLfloat) texture->h;
|
||||||
#else
|
} else {
|
||||||
data->type = GL_TEXTURE_2D;
|
data->type = GL_TEXTURE_2D;
|
||||||
texture_w = power_of_2(texture->w);
|
texture_w = power_of_2(texture->w);
|
||||||
texture_h = power_of_2(texture->h);
|
texture_h = power_of_2(texture->h);
|
||||||
data->texw = (GLfloat) texture->w / texture_w;
|
data->texw = (GLfloat) texture->w / texture_w;
|
||||||
data->texh = (GLfloat) texture->h / texture_h;
|
data->texh = (GLfloat) texture->h / texture_h;
|
||||||
#endif
|
}
|
||||||
data->format = format;
|
data->format = format;
|
||||||
data->formattype = type;
|
data->formattype = type;
|
||||||
glBindTexture(data->type, data->texture);
|
glBindTexture(data->type, data->texture);
|
||||||
|
|
|
@ -32,6 +32,15 @@
|
||||||
#include "../events/SDL_sysevents.h"
|
#include "../events/SDL_sysevents.h"
|
||||||
#include "../events/SDL_events_c.h"
|
#include "../events/SDL_events_c.h"
|
||||||
|
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
#include "SDL_opengl.h"
|
||||||
|
|
||||||
|
/* On Windows, windows.h defines CreateWindow */
|
||||||
|
#ifdef CreateWindow
|
||||||
|
#undef CreateWindow
|
||||||
|
#endif
|
||||||
|
#endif /* SDL_VIDEO_OPENGL */
|
||||||
|
|
||||||
/* Available video drivers */
|
/* Available video drivers */
|
||||||
static VideoBootStrap *bootstrap[] = {
|
static VideoBootStrap *bootstrap[] = {
|
||||||
#if SDL_VIDEO_DRIVER_QUARTZ
|
#if SDL_VIDEO_DRIVER_QUARTZ
|
||||||
|
@ -2064,6 +2073,62 @@ SDL_GL_GetProcAddress(const char *proc)
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_bool
|
||||||
|
SDL_GL_ExtensionSupported(const char *extension)
|
||||||
|
{
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
||||||
|
const char *extensions;
|
||||||
|
const char *start;
|
||||||
|
const char *where, *terminator;
|
||||||
|
|
||||||
|
/* Extension names should not have spaces. */
|
||||||
|
where = SDL_strchr(extension, ' ');
|
||||||
|
if (where || *extension == '\0') {
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See if there's an environment variable override */
|
||||||
|
start = SDL_getenv(extension);
|
||||||
|
if (start && *start == '0') {
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lookup the available extensions */
|
||||||
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
||||||
|
if (glGetStringFunc) {
|
||||||
|
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
||||||
|
} else {
|
||||||
|
extensions = NULL;
|
||||||
|
}
|
||||||
|
if (!extensions) {
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It takes a bit of care to be fool-proof about parsing the
|
||||||
|
* OpenGL extensions string. Don't be fooled by sub-strings,
|
||||||
|
* etc. */
|
||||||
|
|
||||||
|
start = extensions;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
where = SDL_strstr(start, extension);
|
||||||
|
if (!where)
|
||||||
|
break;
|
||||||
|
|
||||||
|
terminator = where + SDL_strlen(extension);
|
||||||
|
if (where == start || *(where - 1) == ' ')
|
||||||
|
if (*terminator == ' ' || *terminator == '\0')
|
||||||
|
return SDL_TRUE;
|
||||||
|
|
||||||
|
start = terminator;
|
||||||
|
}
|
||||||
|
return SDL_FALSE;
|
||||||
|
#else
|
||||||
|
return SDL_FALSE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -196,7 +196,6 @@ WIN_GL_InitExtensions(_THIS)
|
||||||
int pixel_format;
|
int pixel_format;
|
||||||
HGLRC hglrc;
|
HGLRC hglrc;
|
||||||
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
||||||
const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
|
|
||||||
const char *extensions;
|
const char *extensions;
|
||||||
|
|
||||||
hwnd =
|
hwnd =
|
||||||
|
@ -241,14 +240,6 @@ WIN_GL_InitExtensions(_THIS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetStringFunc = WIN_GL_GetProcAddress(_this, "glGetString");
|
|
||||||
if (glGetStringFunc) {
|
|
||||||
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
|
||||||
} else {
|
|
||||||
/* Uh oh, something is seriously wrong here... */
|
|
||||||
extensions = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for WGL_EXT_swap_control */
|
/* Check for WGL_EXT_swap_control */
|
||||||
if (HasExtension("WGL_EXT_swap_control", extensions)) {
|
if (HasExtension("WGL_EXT_swap_control", extensions)) {
|
||||||
_this->gl_data->wglSwapIntervalEXT =
|
_this->gl_data->wglSwapIntervalEXT =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue