mirror of
https://github.com/yawut/SDL.git
synced 2026-09-07 08:36:19 -05:00
Added SDL_GL_ExtensionSupported()
Use GL_ARB_texture_rectangle in the OpenGL renderer, if supported.
This commit is contained in:
@@ -1458,6 +1458,14 @@ extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
|
||||
*/
|
||||
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)
|
||||
*
|
||||
|
||||
@@ -97,6 +97,7 @@ SDL_RenderDriver GL_RenderDriver = {
|
||||
typedef struct
|
||||
{
|
||||
SDL_GLContext context;
|
||||
SDL_bool GL_ARB_texture_rectangle_supported;
|
||||
} GL_RenderData;
|
||||
|
||||
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_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 */
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
#ifdef USE_GL_TEXTURE_RECTANGLE
|
||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||
#else
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
if (data->GL_ARB_texture_rectangle_supported) {
|
||||
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
||||
} else {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -369,19 +373,19 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
|
||||
glGetError();
|
||||
glGenTextures(1, &data->texture);
|
||||
#ifdef USE_GL_TEXTURE_RECTANGLE
|
||||
data->type = GL_TEXTURE_RECTANGLE_ARB;
|
||||
texture_w = texture->w;
|
||||
texture_h = texture->h;
|
||||
data->texw = (GLfloat) texture->w;
|
||||
data->texh = (GLfloat) texture->h;
|
||||
#else
|
||||
data->type = GL_TEXTURE_2D;
|
||||
texture_w = power_of_2(texture->w);
|
||||
texture_h = power_of_2(texture->h);
|
||||
data->texw = (GLfloat) texture->w / texture_w;
|
||||
data->texh = (GLfloat) texture->h / texture_h;
|
||||
#endif
|
||||
if (renderdata->GL_ARB_texture_rectangle_supported) {
|
||||
data->type = GL_TEXTURE_RECTANGLE_ARB;
|
||||
texture_w = texture->w;
|
||||
texture_h = texture->h;
|
||||
data->texw = (GLfloat) texture->w;
|
||||
data->texh = (GLfloat) texture->h;
|
||||
} else {
|
||||
data->type = GL_TEXTURE_2D;
|
||||
texture_w = power_of_2(texture->w);
|
||||
texture_h = power_of_2(texture->h);
|
||||
data->texw = (GLfloat) texture->w / texture_w;
|
||||
data->texh = (GLfloat) texture->h / texture_h;
|
||||
}
|
||||
data->format = format;
|
||||
data->formattype = type;
|
||||
glBindTexture(data->type, data->texture);
|
||||
|
||||
@@ -32,6 +32,15 @@
|
||||
#include "../events/SDL_sysevents.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 */
|
||||
static VideoBootStrap *bootstrap[] = {
|
||||
#if SDL_VIDEO_DRIVER_QUARTZ
|
||||
@@ -2064,6 +2073,62 @@ SDL_GL_GetProcAddress(const char *proc)
|
||||
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
|
||||
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
|
||||
{
|
||||
|
||||
@@ -196,7 +196,6 @@ WIN_GL_InitExtensions(_THIS)
|
||||
int pixel_format;
|
||||
HGLRC hglrc;
|
||||
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
||||
const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
|
||||
const char *extensions;
|
||||
|
||||
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 */
|
||||
if (HasExtension("WGL_EXT_swap_control", extensions)) {
|
||||
_this->gl_data->wglSwapIntervalEXT =
|
||||
|
||||
Reference in New Issue
Block a user