win32-make ogl display method not leak gdi handles like theyre going out of style, and run more peacefully with new opengl code (i.e. not at 2fps)

This commit is contained in:
zeromus 2013-02-05 00:02:59 +00:00
parent 5b215efacc
commit 5538270c1a
3 changed files with 38 additions and 30 deletions

View File

@ -1404,6 +1404,7 @@ static void DD_FillRect(LPDIRECTDRAWSURFACE7 surf, int left, int top, int right,
struct GLDISPLAY
{
HGLRC privateContext;
HDC privateDC;
bool init;
GLDISPLAY()
@ -1415,7 +1416,7 @@ struct GLDISPLAY
{
//do we need to use another HDC?
if(init) return true;
init = initContext(MainWindow->getHWnd(),&privateContext);
init = initContext(MainWindow->getHWnd(),&privateContext, &privateDC);
return init;
}
@ -1423,6 +1424,9 @@ struct GLDISPLAY
{
if(!init) return;
wglDeleteContext(privateContext);
DeleteObject(privateDC);
privateDC = NULL;
privateContext = NULL;
init = false;
}
@ -1435,9 +1439,7 @@ struct GLDISPLAY
{
if(!initialize()) return false;
}
HWND hwnd = MainWindow->getHWnd();
HDC dc = GetDC(hwnd);
wglMakeCurrent(dc,privateContext);
wglMakeCurrent(privateDC,privateContext);
return true;
}
@ -1447,9 +1449,7 @@ struct GLDISPLAY
void showPage()
{
HWND hwnd = MainWindow->getHWnd();
HDC dc = GetDC(hwnd);
SwapBuffers(dc);
SwapBuffers(privateDC);
}
} gldisplay;

View File

@ -47,38 +47,46 @@ int CheckHardwareSupport(HDC hdc)
return -1; // check error
}
bool initContext(HWND hwnd, HGLRC *hRC)
bool initContext(HWND hwnd, HGLRC *hRC, HDC *hdc)
{
int pixelFormat;
*hRC = NULL;
*hdc = NULL;
HDC oglDC = GetDC (hwnd);
static PIXELFORMATDESCRIPTOR pfd =
{ 0, 0, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0 };
pixelFormat = ChoosePixelFormat(oglDC, &pfd);
if (pixelFormat == 0)
return false;
if(!SetPixelFormat(oglDC, pixelFormat, &pfd))
return false;
GLuint PixelFormat;
static PIXELFORMATDESCRIPTOR pfd;
memset(&pfd,0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 24;
pfd.cAlphaBits = 8;
pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE ;
PixelFormat = ChoosePixelFormat(oglDC, &pfd);
SetPixelFormat(oglDC, PixelFormat, &pfd);
*hRC = wglCreateContext(oglDC);
if (!hRC)
{
DeleteObject(oglDC);
return false;
}
*hdc = oglDC;
return true;
}
static HGLRC main_hRC;
static HDC main_hDC;
static bool _begin()
{
HDC oglDC = GetDC (NULL);
if(!wglMakeCurrent(oglDC, main_hRC))
if(!wglMakeCurrent(main_hDC, main_hRC))
return false;
return true;
@ -95,20 +103,20 @@ bool windows_opengl_init()
memset(&pfd,0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwFlags = PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 24;
pfd.cAlphaBits = 8;
pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE ;
HDC hDC = GetDC(NULL);
PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, PixelFormat, &pfd);
main_hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, main_hRC);
main_hDC = GetDC(NULL);
PixelFormat = ChoosePixelFormat(main_hDC, &pfd);
SetPixelFormat(main_hDC, PixelFormat, &pfd);
main_hRC = wglCreateContext(main_hDC);
wglMakeCurrent(main_hDC, main_hRC);
int res = CheckHardwareSupport(hDC);
int res = CheckHardwareSupport(main_hDC);
if (res>=0&&res<=2)
INFO("OpenGL mode: %s\n",opengl_modes[res]);
else

View File

@ -18,4 +18,4 @@
#pragma once
bool windows_opengl_init();
bool initContext(HWND hwnd, HGLRC *hRC);
bool initContext(HWND hwnd, HGLRC *hRC, HDC *hdc);