Commit e0a8c14a authored by Sam Lantinga's avatar Sam Lantinga

Implemented Windows OpenGL support

Fixed slowdown enumerating display modes, which was hosing OpenGL as well...
Removed SDL_ from the render driver prefixes

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401958
parent 2eed452d
......@@ -337,7 +337,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
SDL_VideoSurface = NULL;
}
if (SDL_VideoContext) {
SDL_GL_MakeCurrent(0, SDL_VideoContext);
SDL_GL_MakeCurrent(0, NULL);
SDL_GL_DeleteContext(SDL_VideoContext);
SDL_VideoContext = NULL;
}
......
......@@ -172,6 +172,11 @@ struct SDL_VideoDevice
*/
int (*VideoInit) (_THIS);
/* Reverse the effects VideoInit() -- called if VideoInit() fails
or if the application is shutting down the video subsystem.
*/
void (*VideoQuit) (_THIS);
/* * * */
/* Display functions
*/
......@@ -221,17 +226,13 @@ struct SDL_VideoDevice
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
struct SDL_SysWMinfo * info);
/* Reverse the effects VideoInit() -- called if VideoInit() fails
or if the application is shutting down the video subsystem.
*/
void (*VideoQuit) (_THIS);
/* * * */
/* OpenGL support
*/
int (*GL_LoadLibrary) (_THIS, const char *path);
void *(*GL_GetProcAddress) (_THIS, const char *proc);
int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
int (*GL_GetWindowAttribute) (_THIS, SDL_Window * window,
SDL_GLattr attrib, int *value);
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
int (*GL_SetSwapInterval) (_THIS, int interval);
......@@ -279,7 +280,7 @@ struct SDL_VideoDevice
/* * * */
/* Data private to this driver */
void *driverdata;
struct SDL_PrivateGLData *gl_data;
struct SDL_GLDriverData *gl_data;
/* * * */
/* The function used to dispose of this structure */
......
......@@ -2117,11 +2117,11 @@ SDL_GL_GetWindowAttribute(SDL_WindowID windowID, SDL_GLattr attr, int *value)
return -1;
}
if (_this->GL_GetAttribute) {
retval = _this->GL_GetAttribute(_this, attr, value);
if (_this->GL_GetWindowAttribute) {
retval = _this->GL_GetWindowAttribute(_this, window, attr, value);
} else {
*value = 0;
SDL_SetError("GL_GetAttribute not supported");
SDL_SetError("GL_GetWindowAttribute not supported");
retval = -1;
}
return retval;
......@@ -2147,10 +2147,7 @@ SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
{
SDL_Window *window = SDL_GetWindowFromID(windowID);
if (!window || !context) {
return -1;
}
if (!(window->flags & SDL_WINDOW_OPENGL)) {
if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("The specified window isn't an OpenGL window");
return -1;
}
......
......@@ -89,8 +89,8 @@ DUMMY_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = DUMMY_VideoInit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->VideoQuit = DUMMY_VideoQuit;
device->SetDisplayMode = DUMMY_SetDisplayMode;
device->PumpEvents = DUMMY_PumpEvents;
device->free = DUMMY_DeleteDevice;
......
This diff is collapsed.
This diff is collapsed.
......@@ -29,6 +29,7 @@
/*#define WMMSG_DEBUG*/
#ifdef WMMSG_DEBUG
#include <stdio.h>
#include "wmmsg.h"
#endif
......@@ -398,13 +399,17 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
}
#ifdef WMMSG_DEBUG
fprintf(stderr, "Received windows message: ");
if (msg > MAX_WMMSG) {
fprintf(stderr, "%d", msg);
} else {
fprintf(stderr, "%s", wmtab[msg]);
{
FILE *log = fopen("wmmsg.txt", "a");
fprintf(log, "Received windows message: %p ", hwnd);
if (msg > MAX_WMMSG) {
fprintf(log, "%d", msg);
} else {
fprintf(log, "%s", wmtab[msg]);
}
fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
fclose(log);
}
fprintf(stderr, " -- 0x%X, 0x%X\n", wParam, lParam);
#endif
/* Send a SDL_SYSWMEVENT if the application wants them */
......
......@@ -24,10 +24,6 @@
#include "SDL_win32video.h"
/* FIXME: Each call to EnumDisplaySettings() takes about 6 ms on my laptop.
With 500 or so modes, this takes almost 3 seconds to run!
*/
static SDL_bool
WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
{
......@@ -58,8 +54,8 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
mode->refresh_rate = devmode.dmDisplayFrequency;
mode->driverdata = data;
hdc = CreateDC(deviceName, NULL, NULL, &devmode);
if (hdc) {
if (index == ENUM_CURRENT_SETTINGS
&& (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
LPBITMAPINFO bmi;
HBITMAP hbm;
......@@ -92,6 +88,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
mode->format = SDL_PixelFormat_Index8;
}
} else {
/* FIXME: Can we tell what this will be? */
switch (devmode.dmBitsPerPel) {
case 32:
mode->format = SDL_PixelFormat_RGB888;
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_win32opengl_h
#define _SDL_win32opengl_h
#if SDL_VIDEO_OPENGL
struct SDL_GLDriverData
{
int initialized;
int WGL_ARB_pixel_format;
void *(WINAPI * wglGetProcAddress) (const char *proc);
HGLRC(WINAPI * wglCreateContext) (HDC hdc);
BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc,
const int *piAttribIList,
const FLOAT * pfAttribFList,
UINT nMaxFormats,
int *piFormats,
UINT * nNumFormats);
BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
int *piValues);
void (WINAPI * wglSwapIntervalEXT) (int interval);
int (WINAPI * wglGetSwapIntervalEXT) (void);
};
/* OpenGL functions */
extern int WIN_GL_LoadLibrary(_THIS, const char *path);
extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
extern void WIN_GL_CleanupWindow(_THIS, SDL_Window * window);
extern int WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window,
SDL_GLattr attrib, int *value);
extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
extern int WIN_GL_SetSwapInterval(_THIS, int interval);
extern int WIN_GL_GetSwapInterval(_THIS);
extern void WIN_GL_SwapWindow(_THIS, SDL_Window * window);
extern void WIN_GL_DeleteContext(_THIS, SDL_GLContext context);
#ifndef WGL_ARB_pixel_format
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#endif
#ifndef WGL_ARB_multisample
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#endif
#endif /* SDL_VIDEO_OPENGL */
#endif /* _SDL_win32opengl_h */
/* vi: set ts=4 sw=4 expandtab: */
......@@ -101,11 +101,11 @@ WIN_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = WIN_VideoInit;
device->VideoQuit = WIN_VideoQuit;
device->GetDisplayModes = WIN_GetDisplayModes;
device->SetDisplayMode = WIN_SetDisplayMode;
device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
device->VideoQuit = WIN_VideoQuit;
device->PumpEvents = WIN_PumpEvents;
#undef CreateWindow
......@@ -123,6 +123,17 @@ WIN_CreateDevice(int devindex)
device->SetWindowGrab = WIN_SetWindowGrab;
device->DestroyWindow = WIN_DestroyWindow;
device->GetWindowWMInfo = WIN_GetWindowWMInfo;
#ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = WIN_GL_LoadLibrary;
device->GL_GetProcAddress = WIN_GL_GetProcAddress;
device->GL_GetWindowAttribute = WIN_GL_GetWindowAttribute;
device->GL_CreateContext = WIN_GL_CreateContext;
device->GL_MakeCurrent = WIN_GL_MakeCurrent;
device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
device->GL_SwapWindow = WIN_GL_SwapWindow;
device->GL_DeleteContext = WIN_GL_DeleteContext;
#endif
device->free = WIN_DeleteDevice;
......
......@@ -42,6 +42,7 @@
#include "SDL_win32keyboard.h"
#include "SDL_win32modes.h"
#include "SDL_win32mouse.h"
#include "SDL_win32opengl.h"
#include "SDL_win32window.h"
#ifdef UNICODE
......
......@@ -43,12 +43,14 @@ SetupWindowData(SDL_Window * window, HWND hwnd, BOOL created)
}
data->windowID = window->id;
data->hwnd = hwnd;
data->hdc = GetDC(hwnd);
data->created = created;
data->mouse_pressed = SDL_FALSE;
data->videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata;
/* Associate the data with the window */
if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
ReleaseDC(hwnd, data->hdc);
SDL_free(data);
WIN_SetError("SetProp() failed");
return -1;
......@@ -133,7 +135,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
LPTSTR title = NULL;
HWND top;
RECT rect;
DWORD style = 0;
DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
int x, y;
int w, h;
......@@ -210,6 +212,14 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
DestroyWindow(hwnd);
return -1;
}
#ifdef SDL_VIDEO_OPENGL
if (window->flags & SDL_WINDOW_OPENGL) {
if (WIN_GL_SetupWindow(_this, window) < 0) {
WIN_DestroyWindow(_this, window);
return -1;
}
}
#endif
return 0;
}
......@@ -408,6 +418,12 @@ WIN_DestroyWindow(_THIS, SDL_Window * window)
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (data) {
#ifdef SDL_VIDEO_OPENGL
if (window->flags & SDL_WINDOW_OPENGL) {
WIN_GL_CleanupWindow(_this, window);
}
#endif
ReleaseDC(data->hwnd, data->hdc);
if (data->created) {
DestroyWindow(data->hwnd);
}
......
......@@ -31,6 +31,7 @@ typedef struct
{
SDL_WindowID windowID;
HWND hwnd;
HDC hdc;
WNDPROC wndproc;
BOOL created;
int mouse_pressed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment