2006-07-17 06:47:33 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2013-02-15 08:47:44 -08:00
|
|
|
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2006-07-17 06:47:33 +00:00
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
|
|
|
|
2011-01-20 18:04:05 -08:00
|
|
|
#include "SDL_windowsvideo.h"
|
2006-07-17 06:47:33 +00:00
|
|
|
|
|
|
|
/* WGL implementation of SDL OpenGL support */
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
#if SDL_VIDEO_OPENGL_WGL
|
2006-07-17 06:47:33 +00:00
|
|
|
#include "SDL_opengl.h"
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
#define DEFAULT_OPENGL "OPENGL32.DLL"
|
2006-07-17 06:47:33 +00:00
|
|
|
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
#ifndef WGL_ARB_create_context
|
|
|
|
#define WGL_ARB_create_context
|
|
|
|
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
|
|
|
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
|
|
|
|
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
|
2012-07-22 21:47:56 +02:00
|
|
|
#define WGL_CONTEXT_FLAGS_ARB 0x2094
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
|
|
|
|
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
|
2012-02-20 23:37:57 -05:00
|
|
|
|
|
|
|
#ifndef WGL_ARB_create_context_profile
|
|
|
|
#define WGL_ARB_create_context_profile
|
|
|
|
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
|
|
|
|
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
|
|
|
|
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_ARB_create_context_robustness
|
|
|
|
#define WGL_ARB_create_context_robustness
|
|
|
|
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
|
|
|
|
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
|
|
|
|
#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
|
|
|
|
#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WGL_EXT_create_context_es2_profile
|
|
|
|
#define WGL_EXT_create_context_es2_profile
|
|
|
|
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-12 11:16:24 -07:00
|
|
|
#ifndef WGL_EXT_create_context_es_profile
|
|
|
|
#define WGL_EXT_create_context_es_profile
|
|
|
|
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
|
|
|
|
#endif
|
|
|
|
|
2009-05-23 22:41:08 +00:00
|
|
|
typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
|
|
|
|
HGLRC
|
|
|
|
hShareContext,
|
|
|
|
const int
|
|
|
|
*attribList);
|
2006-07-17 06:47:33 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
WIN_GL_LoadLibrary(_THIS, const char *path)
|
|
|
|
{
|
|
|
|
LPTSTR wpath;
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
if (path == NULL) {
|
2006-07-28 08:43:17 +00:00
|
|
|
path = SDL_getenv("SDL_OPENGL_LIBRARY");
|
|
|
|
}
|
|
|
|
if (path == NULL) {
|
|
|
|
path = DEFAULT_OPENGL;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
wpath = WIN_UTF8ToString(path);
|
2009-02-09 05:32:12 +00:00
|
|
|
_this->gl_config.dll_handle = LoadLibrary(wpath);
|
2006-07-17 06:47:33 +00:00
|
|
|
SDL_free(wpath);
|
2009-02-09 05:32:12 +00:00
|
|
|
if (!_this->gl_config.dll_handle) {
|
2006-07-17 06:47:33 +00:00
|
|
|
char message[1024];
|
|
|
|
SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
|
|
|
|
path);
|
2013-03-31 12:48:50 -04:00
|
|
|
return WIN_SetError(message);
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
2009-02-09 05:32:12 +00:00
|
|
|
SDL_strlcpy(_this->gl_config.driver_path, path,
|
|
|
|
SDL_arraysize(_this->gl_config.driver_path));
|
|
|
|
|
|
|
|
/* Allocate OpenGL memory */
|
|
|
|
_this->gl_data =
|
|
|
|
(struct SDL_GLDriverData *) SDL_calloc(1,
|
|
|
|
sizeof(struct
|
|
|
|
SDL_GLDriverData));
|
|
|
|
if (!_this->gl_data) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_OutOfMemory();
|
2009-02-09 05:32:12 +00:00
|
|
|
}
|
2006-07-17 06:47:33 +00:00
|
|
|
|
|
|
|
/* Load function pointers */
|
2009-02-09 05:32:12 +00:00
|
|
|
handle = _this->gl_config.dll_handle;
|
2006-07-17 06:47:33 +00:00
|
|
|
_this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
|
|
|
|
GetProcAddress(handle, "wglGetProcAddress");
|
|
|
|
_this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
|
|
|
|
GetProcAddress(handle, "wglCreateContext");
|
|
|
|
_this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
|
|
|
|
GetProcAddress(handle, "wglDeleteContext");
|
|
|
|
_this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
|
|
|
|
GetProcAddress(handle, "wglMakeCurrent");
|
2012-08-12 11:16:24 -07:00
|
|
|
_this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
|
|
|
|
GetProcAddress(handle, "wglShareLists");
|
2006-07-17 06:47:33 +00:00
|
|
|
|
|
|
|
if (!_this->gl_data->wglGetProcAddress ||
|
|
|
|
!_this->gl_data->wglCreateContext ||
|
|
|
|
!_this->gl_data->wglDeleteContext ||
|
|
|
|
!_this->gl_data->wglMakeCurrent) {
|
2011-01-24 21:20:30 -08:00
|
|
|
SDL_UnloadObject(handle);
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Could not retrieve OpenGL functions");
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
WIN_GL_GetProcAddress(_THIS, const char *proc)
|
|
|
|
{
|
|
|
|
void *func;
|
|
|
|
|
|
|
|
/* This is to pick up extensions */
|
|
|
|
func = _this->gl_data->wglGetProcAddress(proc);
|
|
|
|
if (!func) {
|
|
|
|
/* This is probably a normal GL function */
|
|
|
|
func = GetProcAddress(_this->gl_config.dll_handle, proc);
|
|
|
|
}
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2009-02-09 05:32:12 +00:00
|
|
|
void
|
2006-07-17 06:47:33 +00:00
|
|
|
WIN_GL_UnloadLibrary(_THIS)
|
|
|
|
{
|
2009-02-09 05:32:12 +00:00
|
|
|
FreeLibrary((HMODULE) _this->gl_config.dll_handle);
|
|
|
|
_this->gl_config.dll_handle = NULL;
|
|
|
|
|
|
|
|
/* Free OpenGL memory */
|
|
|
|
SDL_free(_this->gl_data);
|
|
|
|
_this->gl_data = NULL;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
|
|
|
|
{
|
|
|
|
SDL_zerop(pfd);
|
|
|
|
pfd->nSize = sizeof(*pfd);
|
|
|
|
pfd->nVersion = 1;
|
|
|
|
pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
|
|
|
|
if (_this->gl_config.double_buffer) {
|
|
|
|
pfd->dwFlags |= PFD_DOUBLEBUFFER;
|
|
|
|
}
|
|
|
|
if (_this->gl_config.stereo) {
|
|
|
|
pfd->dwFlags |= PFD_STEREO;
|
|
|
|
}
|
|
|
|
pfd->iLayerType = PFD_MAIN_PLANE;
|
|
|
|
pfd->iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd->cRedBits = _this->gl_config.red_size;
|
|
|
|
pfd->cGreenBits = _this->gl_config.green_size;
|
|
|
|
pfd->cBlueBits = _this->gl_config.blue_size;
|
|
|
|
pfd->cAlphaBits = _this->gl_config.alpha_size;
|
|
|
|
if (_this->gl_config.buffer_size) {
|
|
|
|
pfd->cColorBits =
|
|
|
|
_this->gl_config.buffer_size - _this->gl_config.alpha_size;
|
|
|
|
} else {
|
|
|
|
pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
|
|
|
|
}
|
|
|
|
pfd->cAccumRedBits = _this->gl_config.accum_red_size;
|
|
|
|
pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
|
|
|
|
pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
|
|
|
|
pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
|
|
|
|
pfd->cAccumBits =
|
|
|
|
(pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
|
|
|
|
pfd->cAccumAlphaBits);
|
|
|
|
pfd->cDepthBits = _this->gl_config.depth_size;
|
|
|
|
pfd->cStencilBits = _this->gl_config.stencil_size;
|
|
|
|
}
|
|
|
|
|
2007-07-05 06:14:26 +00:00
|
|
|
/* Choose the closest pixel format that meets or exceeds the target.
|
|
|
|
FIXME: Should we weight any particular attribute over any other?
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
int count, index, best = 0;
|
|
|
|
unsigned int dist, best_dist = ~0U;
|
|
|
|
|
|
|
|
count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
|
|
|
|
|
|
|
|
for (index = 1; index <= count; index++) {
|
|
|
|
|
|
|
|
if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pfd.iLayerType != target->iLayerType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pfd.iPixelType != target->iPixelType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dist = 0;
|
|
|
|
|
|
|
|
if (pfd.cColorBits < target->cColorBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cColorBits - target->cColorBits);
|
|
|
|
}
|
|
|
|
if (pfd.cRedBits < target->cRedBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cRedBits - target->cRedBits);
|
|
|
|
}
|
|
|
|
if (pfd.cGreenBits < target->cGreenBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cGreenBits - target->cGreenBits);
|
|
|
|
}
|
|
|
|
if (pfd.cBlueBits < target->cBlueBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cBlueBits - target->cBlueBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAlphaBits < target->cAlphaBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAlphaBits - target->cAlphaBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAccumBits < target->cAccumBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAccumBits - target->cAccumBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAccumRedBits < target->cAccumRedBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAccumRedBits - target->cAccumRedBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
|
|
|
|
}
|
|
|
|
if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
|
|
|
|
}
|
|
|
|
if (pfd.cDepthBits < target->cDepthBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cDepthBits - target->cDepthBits);
|
|
|
|
}
|
|
|
|
if (pfd.cStencilBits < target->cStencilBits) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dist += (pfd.cStencilBits - target->cStencilBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dist < best_dist) {
|
|
|
|
best = index;
|
|
|
|
best_dist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2006-07-17 06:47:33 +00:00
|
|
|
static SDL_bool
|
|
|
|
HasExtension(const char *extension, 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-07-12 06:31:36 +00:00
|
|
|
WIN_GL_InitExtensions(_THIS, HDC hdc)
|
2006-07-17 06:47:33 +00:00
|
|
|
{
|
|
|
|
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
|
|
|
const char *extensions;
|
|
|
|
|
|
|
|
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
|
|
|
|
_this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
|
|
|
|
if (wglGetExtensionsStringARB) {
|
|
|
|
extensions = wglGetExtensionsStringARB(hdc);
|
|
|
|
} else {
|
|
|
|
extensions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for WGL_ARB_pixel_format */
|
2012-08-01 20:29:36 -04:00
|
|
|
_this->gl_data->HAS_WGL_ARB_pixel_format = SDL_FALSE;
|
2006-07-17 06:47:33 +00:00
|
|
|
if (HasExtension("WGL_ARB_pixel_format", extensions)) {
|
|
|
|
_this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
|
|
|
|
(HDC, const int *,
|
|
|
|
const FLOAT *, UINT,
|
|
|
|
int *, UINT *))
|
|
|
|
WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
|
|
|
|
_this->gl_data->wglGetPixelFormatAttribivARB =
|
|
|
|
(BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
|
|
|
|
WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
|
|
|
|
|
|
|
|
if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
|
|
|
|
(_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
|
2012-08-01 20:29:36 -04:00
|
|
|
_this->gl_data->HAS_WGL_ARB_pixel_format = SDL_TRUE;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for WGL_EXT_swap_control */
|
2012-08-01 20:29:36 -04:00
|
|
|
_this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_FALSE;
|
2006-07-17 06:47:33 +00:00
|
|
|
if (HasExtension("WGL_EXT_swap_control", extensions)) {
|
|
|
|
_this->gl_data->wglSwapIntervalEXT =
|
|
|
|
WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
|
|
|
|
_this->gl_data->wglGetSwapIntervalEXT =
|
|
|
|
WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
|
2012-08-01 20:29:36 -04:00
|
|
|
if (HasExtension("WGL_EXT_swap_control_tear", extensions)) {
|
|
|
|
_this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_TRUE;
|
|
|
|
}
|
2007-07-12 06:31:36 +00:00
|
|
|
} else {
|
|
|
|
_this->gl_data->wglSwapIntervalEXT = NULL;
|
|
|
|
_this->gl_data->wglGetSwapIntervalEXT = NULL;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
2007-07-12 06:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc;
|
2007-07-12 06:59:43 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2007-07-12 06:31:36 +00:00
|
|
|
HGLRC hglrc;
|
|
|
|
int pixel_format = 0;
|
|
|
|
unsigned int matching;
|
|
|
|
|
|
|
|
hwnd =
|
|
|
|
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
|
|
|
|
10, 10, NULL, NULL, SDL_Instance, NULL);
|
|
|
|
WIN_PumpEvents(_this);
|
2006-07-17 06:47:33 +00:00
|
|
|
|
2007-07-12 06:31:36 +00:00
|
|
|
hdc = GetDC(hwnd);
|
2007-07-12 06:59:43 +00:00
|
|
|
|
|
|
|
WIN_GL_SetupPixelFormat(_this, &pfd);
|
|
|
|
|
|
|
|
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
|
2007-07-12 06:31:36 +00:00
|
|
|
|
|
|
|
hglrc = _this->gl_data->wglCreateContext(hdc);
|
2006-07-17 06:47:33 +00:00
|
|
|
if (hglrc) {
|
2007-07-12 06:31:36 +00:00
|
|
|
_this->gl_data->wglMakeCurrent(hdc, hglrc);
|
|
|
|
|
|
|
|
WIN_GL_InitExtensions(_this, hdc);
|
|
|
|
|
2012-08-01 20:29:36 -04:00
|
|
|
if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
|
2007-07-12 06:31:36 +00:00
|
|
|
_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
|
|
|
|
1, &pixel_format,
|
|
|
|
&matching);
|
|
|
|
}
|
|
|
|
|
2006-07-17 06:47:33 +00:00
|
|
|
_this->gl_data->wglMakeCurrent(NULL, NULL);
|
|
|
|
_this->gl_data->wglDeleteContext(hglrc);
|
|
|
|
}
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
WIN_PumpEvents(_this);
|
2007-07-12 06:31:36 +00:00
|
|
|
|
|
|
|
return pixel_format;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
WIN_GL_SetupWindow(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2012-02-20 23:37:57 -05:00
|
|
|
int pixel_format = 0;
|
2006-07-17 06:47:33 +00:00
|
|
|
int iAttribs[64];
|
|
|
|
int *iAttr;
|
|
|
|
float fAttribs[1] = { 0 };
|
|
|
|
|
|
|
|
WIN_GL_SetupPixelFormat(_this, &pfd);
|
|
|
|
|
|
|
|
/* setup WGL_ARB_pixel_format attribs */
|
|
|
|
iAttr = &iAttribs[0];
|
|
|
|
|
|
|
|
*iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
|
|
|
|
*iAttr++ = GL_TRUE;
|
|
|
|
*iAttr++ = WGL_RED_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.red_size;
|
|
|
|
*iAttr++ = WGL_GREEN_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.green_size;
|
|
|
|
*iAttr++ = WGL_BLUE_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.blue_size;
|
|
|
|
|
|
|
|
if (_this->gl_config.alpha_size) {
|
|
|
|
*iAttr++ = WGL_ALPHA_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.alpha_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
*iAttr++ = WGL_DOUBLE_BUFFER_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.double_buffer;
|
|
|
|
|
|
|
|
*iAttr++ = WGL_DEPTH_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.depth_size;
|
|
|
|
|
|
|
|
if (_this->gl_config.stencil_size) {
|
|
|
|
*iAttr++ = WGL_STENCIL_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.stencil_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.accum_red_size) {
|
|
|
|
*iAttr++ = WGL_ACCUM_RED_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.accum_red_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.accum_green_size) {
|
|
|
|
*iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.accum_green_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.accum_blue_size) {
|
|
|
|
*iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.accum_blue_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.accum_alpha_size) {
|
|
|
|
*iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.accum_alpha_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.stereo) {
|
|
|
|
*iAttr++ = WGL_STEREO_ARB;
|
|
|
|
*iAttr++ = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.multisamplebuffers) {
|
|
|
|
*iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.multisamplebuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_this->gl_config.multisamplesamples) {
|
|
|
|
*iAttr++ = WGL_SAMPLES_ARB;
|
|
|
|
*iAttr++ = _this->gl_config.multisamplesamples;
|
|
|
|
}
|
|
|
|
|
2012-02-20 23:37:57 -05:00
|
|
|
*iAttr++ = WGL_ACCELERATION_ARB;
|
|
|
|
*iAttr++ = WGL_FULL_ACCELERATION_ARB;
|
2006-07-17 06:47:33 +00:00
|
|
|
|
|
|
|
*iAttr = 0;
|
|
|
|
|
|
|
|
/* Choose and set the closest available pixel format */
|
2012-02-20 23:37:57 -05:00
|
|
|
if (_this->gl_config.accelerated != 0) {
|
|
|
|
pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
|
|
|
|
}
|
|
|
|
if (!pixel_format && _this->gl_config.accelerated != 1) {
|
|
|
|
iAttr[-1] = WGL_NO_ACCELERATION_ARB;
|
2013-05-18 14:17:52 -07:00
|
|
|
pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
|
2012-02-20 23:37:57 -05:00
|
|
|
}
|
2007-07-12 06:31:36 +00:00
|
|
|
if (!pixel_format) {
|
2007-07-05 06:14:26 +00:00
|
|
|
pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
if (!pixel_format) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("No matching GL pixel format available");
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return WIN_SetError("SetPixelFormat()");
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_GLContext
|
|
|
|
WIN_GL_CreateContext(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
2012-08-12 11:16:24 -07:00
|
|
|
HGLRC context, share_context;
|
|
|
|
|
|
|
|
if (_this->gl_config.share_with_current_context) {
|
|
|
|
share_context = (HGLRC)(_this->current_glctx);
|
|
|
|
} else {
|
|
|
|
share_context = 0;
|
|
|
|
}
|
2007-07-12 06:31:36 +00:00
|
|
|
|
2012-08-12 11:16:24 -07:00
|
|
|
if (_this->gl_config.major_version < 3 &&
|
2013-05-18 14:17:52 -07:00
|
|
|
_this->gl_config.profile_mask == 0 &&
|
|
|
|
_this->gl_config.flags == 0) {
|
2012-08-12 11:16:24 -07:00
|
|
|
/* Create legacy context */
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
context = _this->gl_data->wglCreateContext(hdc);
|
2013-05-18 14:17:52 -07:00
|
|
|
if( share_context != 0 ) {
|
2012-08-25 16:49:05 -04:00
|
|
|
_this->gl_data->wglShareLists(share_context, context);
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
} else {
|
|
|
|
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
|
|
|
|
HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
|
|
|
|
if (!temp_context) {
|
2009-05-23 22:41:08 +00:00
|
|
|
SDL_SetError("Could not create GL context");
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-23 22:41:08 +00:00
|
|
|
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
/* Make the context current */
|
|
|
|
if (WIN_GL_MakeCurrent(_this, window, temp_context) < 0) {
|
|
|
|
WIN_GL_DeleteContext(_this, temp_context);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-23 22:41:08 +00:00
|
|
|
|
|
|
|
wglCreateContextAttribsARB =
|
|
|
|
(PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
|
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
if (!wglCreateContextAttribsARB) {
|
|
|
|
SDL_SetError("GL 3.x is not supported");
|
|
|
|
context = temp_context;
|
|
|
|
} else {
|
2013-05-18 14:17:52 -07:00
|
|
|
/* max 8 attributes plus terminator */
|
2012-02-20 23:37:57 -05:00
|
|
|
int attribs[9] = {
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
|
|
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
|
2009-05-23 22:41:08 +00:00
|
|
|
0
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
};
|
2013-05-18 14:17:52 -07:00
|
|
|
int iattr = 4;
|
2012-02-20 23:37:57 -05:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* SDL profile bits match WGL profile bits */
|
|
|
|
if( _this->gl_config.profile_mask != 0 ) {
|
|
|
|
attribs[iattr++] = WGL_CONTEXT_PROFILE_MASK_ARB;
|
|
|
|
attribs[iattr++] = _this->gl_config.profile_mask;
|
|
|
|
}
|
2012-02-20 23:37:57 -05:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* SDL flags match WGL flags */
|
|
|
|
if( _this->gl_config.flags != 0 ) {
|
|
|
|
attribs[iattr++] = WGL_CONTEXT_FLAGS_ARB;
|
|
|
|
attribs[iattr++] = _this->gl_config.flags;
|
|
|
|
}
|
2012-02-20 23:37:57 -05:00
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
attribs[iattr++] = 0;
|
2012-02-20 23:37:57 -05:00
|
|
|
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
/* Create the GL 3.x context */
|
2012-08-12 11:16:24 -07:00
|
|
|
context = wglCreateContextAttribsARB(hdc, share_context, attribs);
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
/* Delete the GL 2.x context */
|
2009-04-03 17:19:05 +00:00
|
|
|
_this->gl_data->wglDeleteContext(temp_context);
|
Date: Sun, 22 Mar 2009 12:52:29 +0000
From: Luke Benstead
Subject: OpenGL 3.0 Context Creation
I've attached a patch which implements OpenGL 3.x context creation on
the latest SVN. I've added two options to SDL_GL_SetAttribute, these
are SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION.
These default to 2 and 1 respectively. If the major version is less
than 3 then the current context creation method is used, otherwise the
appropriate new context creation function is called (depending on the
platform).
Sample code:
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //Without these 2 lines, SDL will create a GL 2.x context
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL | SDL_FULLSCREEN );
I've implemented context creation on both Win32 and X and run basic
tests on both. This patch doesn't provide access to all the options
allowed by the new context creation (e.g. shared contexts, forward
compatible contexts) but they can be added pretty easily.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403567
2009-03-24 10:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 22:41:08 +00:00
|
|
|
|
2007-07-12 06:31:36 +00:00
|
|
|
if (!context) {
|
2009-12-15 08:11:06 +00:00
|
|
|
WIN_SetError("Could not create GL context");
|
2007-07-12 06:31:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
|
|
|
|
WIN_GL_DeleteContext(_this, context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WIN_GL_InitExtensions(_this, hdc);
|
2006-07-17 06:47:33 +00:00
|
|
|
|
2007-07-12 06:31:36 +00:00
|
|
|
return context;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
|
2012-09-30 01:08:48 -07:00
|
|
|
if (!_this->gl_data) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("OpenGL not initialized");
|
2012-09-30 01:08:48 -07:00
|
|
|
}
|
|
|
|
|
2006-07-17 06:47:33 +00:00
|
|
|
if (window) {
|
|
|
|
hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
|
|
|
} else {
|
|
|
|
hdc = NULL;
|
|
|
|
}
|
|
|
|
if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return WIN_SetError("wglMakeCurrent()");
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
2013-03-31 12:48:50 -04:00
|
|
|
return 0;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
WIN_GL_SetSwapInterval(_THIS, int interval)
|
|
|
|
{
|
2012-08-01 20:29:36 -04:00
|
|
|
if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("Negative swap interval unsupported in this GL");
|
2012-08-01 20:29:36 -04:00
|
|
|
} else if (_this->gl_data->wglSwapIntervalEXT) {
|
2013-03-31 12:48:50 -04:00
|
|
|
if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) {
|
|
|
|
return WIN_SetError("wglSwapIntervalEXT()");
|
2012-08-01 20:57:03 -04:00
|
|
|
}
|
2006-07-17 06:47:33 +00:00
|
|
|
} else {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_Unsupported();
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
2013-03-31 12:48:50 -04:00
|
|
|
return 0;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
WIN_GL_GetSwapInterval(_THIS)
|
|
|
|
{
|
2012-08-01 20:57:03 -04:00
|
|
|
int retval = 0;
|
2006-07-17 06:47:33 +00:00
|
|
|
if (_this->gl_data->wglGetSwapIntervalEXT) {
|
2012-08-01 20:57:03 -04:00
|
|
|
retval = _this->gl_data->wglGetSwapIntervalEXT();
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
2012-08-01 20:57:03 -04:00
|
|
|
return retval;
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WIN_GL_SwapWindow(_THIS, SDL_Window * window)
|
|
|
|
{
|
|
|
|
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
|
|
|
|
|
|
|
SwapBuffers(hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
|
|
|
|
{
|
2012-09-30 01:08:48 -07:00
|
|
|
if (!_this->gl_data) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-25 06:22:42 +00:00
|
|
|
_this->gl_data->wglDeleteContext((HGLRC) context);
|
2006-07-17 06:47:33 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
#endif /* SDL_VIDEO_OPENGL_WGL */
|
2006-07-17 06:47:33 +00:00
|
|
|
|
2011-10-31 05:56:58 -04:00
|
|
|
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
|
|
|
|
|
2006-07-17 06:47:33 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|