2006-10-03 19:52:17 +02:00
|
|
|
/*
|
|
|
|
* OpenGL function forwarding to the display driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999 Lionel Ulmer
|
|
|
|
* Copyright (c) 2005 Raphael Junqueira
|
|
|
|
* Copyright (c) 2006 Roderick Colenbrander
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winerror.h"
|
2006-10-14 12:56:07 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "winnt.h"
|
2006-10-03 19:52:17 +02:00
|
|
|
#include "gdi_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
|
|
|
|
|
2006-10-07 20:08:26 +02:00
|
|
|
static HDC default_hdc = 0;
|
|
|
|
|
2006-10-14 22:11:33 +02:00
|
|
|
typedef struct opengl_context
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
} *OPENGL_Context;
|
|
|
|
|
2006-10-07 20:08:26 +02:00
|
|
|
/* We route all wgl functions from opengl32.dll through gdi32.dll to
|
|
|
|
* the display driver. Various wgl calls have a hDC as one of their parameters.
|
2007-09-24 18:17:21 +02:00
|
|
|
* Using get_dc_ptr we get access to the functions exported by the driver.
|
2006-10-07 20:08:26 +02:00
|
|
|
* Some functions don't receive a hDC. This function creates a global hdc and
|
|
|
|
* if there's already a global hdc, it returns it.
|
|
|
|
*/
|
2007-03-10 22:00:47 +01:00
|
|
|
static DC* OPENGL_GetDefaultDC(void)
|
2006-10-07 20:08:26 +02:00
|
|
|
{
|
|
|
|
if(!default_hdc)
|
|
|
|
default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
|
2007-09-17 16:49:37 +02:00
|
|
|
|
|
|
|
return get_dc_ptr(default_hdc);
|
2006-10-07 20:08:26 +02:00
|
|
|
}
|
|
|
|
|
2007-11-11 21:32:12 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* wglCopyContext (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
|
|
|
|
{
|
|
|
|
DC *dc;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
OPENGL_Context ctx = (OPENGL_Context)hglrcSrc;
|
|
|
|
|
|
|
|
TRACE("hglrcSrc: (%p), hglrcDst: (%p), mask: %#x\n", hglrcSrc, hglrcDst, mask);
|
|
|
|
/* If no context is set, this call doesn't have a purpose */
|
|
|
|
if(!hglrcSrc || !hglrcDst)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Retrieve the HDC associated with the context to access the display driver */
|
|
|
|
dc = get_dc_ptr(ctx->hdc);
|
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
|
|
|
if (!dc->funcs->pwglCopyContext) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglCopyContext(hglrcSrc, hglrcDst, mask);
|
|
|
|
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-03 19:52:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglCreateContext (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
HGLRC WINAPI wglCreateContext(HDC hdc)
|
|
|
|
{
|
|
|
|
HGLRC ret = 0;
|
2007-09-17 16:56:56 +02:00
|
|
|
DC * dc = get_dc_ptr( hdc );
|
2006-10-03 19:52:17 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",hdc);
|
|
|
|
|
|
|
|
if (!dc) return 0;
|
|
|
|
|
2007-09-17 16:56:56 +02:00
|
|
|
update_dc( dc );
|
2006-10-03 19:52:17 +02:00
|
|
|
if (!dc->funcs->pwglCreateContext) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglCreateContext(dc->physDev);
|
|
|
|
|
2007-09-17 16:56:56 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-03 19:52:17 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-16 23:24:24 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* wglCreateContextAttribsARB
|
|
|
|
*/
|
|
|
|
HGLRC WINAPI wglCreateContextAttribsARB(HDC hdc, HGLRC hShareContext, const int *attributeList)
|
|
|
|
{
|
|
|
|
HGLRC ret = 0;
|
|
|
|
DC * dc = get_dc_ptr( hdc );
|
|
|
|
|
|
|
|
TRACE("(%p)\n",hdc);
|
|
|
|
|
|
|
|
if (!dc) return 0;
|
|
|
|
|
|
|
|
update_dc( dc );
|
|
|
|
if (!dc->funcs->pwglCreateContextAttribsARB) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglCreateContextAttribsARB(dc->physDev, hShareContext, attributeList);
|
|
|
|
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
return ret;
|
|
|
|
}
|
2006-10-16 23:28:33 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wglDeleteContext (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglDeleteContext(HGLRC hglrc)
|
|
|
|
{
|
|
|
|
DC *dc;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
OPENGL_Context ctx = (OPENGL_Context)hglrc;
|
|
|
|
|
|
|
|
TRACE("hglrc: (%p)\n", hglrc);
|
|
|
|
if(ctx == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Retrieve the HDC associated with the context to access the display driver */
|
2007-09-24 18:17:21 +02:00
|
|
|
dc = get_dc_ptr(ctx->hdc);
|
2006-10-16 23:28:33 +02:00
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
|
|
|
if (!dc->funcs->pwglDeleteContext) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglDeleteContext(hglrc);
|
|
|
|
|
2007-09-24 18:17:21 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-16 23:28:33 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-14 12:56:07 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglGetCurrentContext (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
HGLRC WINAPI wglGetCurrentContext(void)
|
|
|
|
{
|
|
|
|
HGLRC ret = NtCurrentTeb()->glContext;
|
|
|
|
TRACE(" returning %p\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-14 22:11:33 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglGetCurrentDC (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
HDC WINAPI wglGetCurrentDC(void)
|
|
|
|
{
|
|
|
|
OPENGL_Context ctx = (OPENGL_Context)wglGetCurrentContext();
|
|
|
|
|
|
|
|
TRACE(" found context: %p\n", ctx);
|
|
|
|
if(ctx == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Retrieve the current DC from the active context */
|
|
|
|
TRACE(" returning hdc: %p\n", ctx->hdc);
|
|
|
|
return ctx->hdc;
|
|
|
|
}
|
|
|
|
|
2006-11-04 22:23:15 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* wglGetPbufferDCARB
|
|
|
|
*/
|
|
|
|
static HDC WINAPI wglGetPbufferDCARB(void *pbuffer)
|
|
|
|
{
|
|
|
|
HDC ret = 0;
|
|
|
|
|
|
|
|
/* Create a device context to associate with the pbuffer */
|
|
|
|
HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
|
2007-09-24 18:17:21 +02:00
|
|
|
DC *dc = get_dc_ptr(hdc);
|
2006-11-04 22:23:15 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pbuffer);
|
|
|
|
|
2009-08-06 10:17:58 +02:00
|
|
|
if (!dc) return 0;
|
2006-11-04 22:23:15 +01:00
|
|
|
|
|
|
|
/* The display driver has to do the rest of the work because
|
|
|
|
* we need access to lowlevel datatypes which we can't access here
|
|
|
|
*/
|
|
|
|
if (!dc->funcs->pwglGetPbufferDCARB) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglGetPbufferDCARB(dc->physDev, pbuffer);
|
|
|
|
|
|
|
|
TRACE("(%p), hdc=%p\n", pbuffer, ret);
|
2007-09-24 18:17:21 +02:00
|
|
|
|
|
|
|
release_dc_ptr( dc );
|
2006-11-04 22:23:15 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-03 19:52:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglMakeCurrent (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2006-10-07 20:08:26 +02:00
|
|
|
DC * dc = NULL;
|
|
|
|
|
|
|
|
/* When the context hglrc is NULL, the HDC is ignored and can be NULL.
|
|
|
|
* In that case use the global hDC to get access to the driver. */
|
|
|
|
if(hglrc == NULL)
|
2009-09-19 15:52:36 +02:00
|
|
|
{
|
|
|
|
if( hdc == NULL && !wglGetCurrentContext() )
|
|
|
|
{
|
|
|
|
WARN( "Current context is NULL\n");
|
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-10-07 20:08:26 +02:00
|
|
|
dc = OPENGL_GetDefaultDC();
|
2009-09-19 15:52:36 +02:00
|
|
|
}
|
2006-10-07 20:08:26 +02:00
|
|
|
else
|
2007-09-17 16:49:37 +02:00
|
|
|
dc = get_dc_ptr( hdc );
|
2006-10-03 19:52:17 +02:00
|
|
|
|
|
|
|
TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc);
|
|
|
|
|
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
2007-09-17 16:49:37 +02:00
|
|
|
update_dc( dc );
|
2006-10-03 19:52:17 +02:00
|
|
|
if (!dc->funcs->pwglMakeCurrent) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglMakeCurrent(dc->physDev,hglrc);
|
|
|
|
|
2007-09-17 16:49:37 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-03 19:52:17 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2006-10-03 21:22:22 +02:00
|
|
|
|
2006-10-31 18:29:14 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* wglMakeContextCurrentARB
|
|
|
|
*/
|
|
|
|
static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
DC *DrawDC;
|
|
|
|
DC *ReadDC;
|
|
|
|
|
|
|
|
TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc);
|
|
|
|
|
|
|
|
/* Both hDrawDC and hReadDC need to be valid */
|
2007-09-17 16:56:56 +02:00
|
|
|
DrawDC = get_dc_ptr( hDrawDC );
|
2006-10-31 18:29:14 +01:00
|
|
|
if (!DrawDC) return FALSE;
|
|
|
|
|
2007-09-17 16:56:56 +02:00
|
|
|
ReadDC = get_dc_ptr( hReadDC );
|
2006-10-31 18:29:14 +01:00
|
|
|
if (!ReadDC) {
|
2007-09-17 16:56:56 +02:00
|
|
|
release_dc_ptr( DrawDC );
|
2006-10-31 18:29:14 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-17 16:56:56 +02:00
|
|
|
update_dc( DrawDC );
|
|
|
|
update_dc( ReadDC );
|
2006-10-31 18:29:14 +01:00
|
|
|
if (!DrawDC->funcs->pwglMakeContextCurrentARB) FIXME(" :stub\n");
|
|
|
|
else ret = DrawDC->funcs->pwglMakeContextCurrentARB(DrawDC->physDev, ReadDC->physDev, hglrc);
|
|
|
|
|
2007-09-17 16:56:56 +02:00
|
|
|
release_dc_ptr( DrawDC );
|
|
|
|
release_dc_ptr( ReadDC );
|
2006-10-31 18:29:14 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-23 00:15:15 +02:00
|
|
|
/**************************************************************************************
|
|
|
|
* WINE-specific wglSetPixelFormat which can set the iPixelFormat multiple times
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL WINAPI wglSetPixelFormatWINE(HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
|
|
|
|
{
|
|
|
|
INT bRet = FALSE;
|
|
|
|
DC * dc = get_dc_ptr( hdc );
|
|
|
|
|
|
|
|
TRACE("(%p,%d,%p)\n", hdc, iPixelFormat, ppfd);
|
|
|
|
|
|
|
|
if (!dc) return 0;
|
|
|
|
|
2008-05-12 19:58:23 +02:00
|
|
|
update_dc( dc );
|
2008-04-23 00:15:15 +02:00
|
|
|
if (!dc->funcs->pwglSetPixelFormatWINE) FIXME(" :stub\n");
|
|
|
|
else bRet = dc->funcs->pwglSetPixelFormatWINE(dc->physDev, iPixelFormat, ppfd);
|
|
|
|
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2006-10-14 22:49:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglShareLists (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglShareLists(HGLRC hglrc1, HGLRC hglrc2)
|
|
|
|
{
|
|
|
|
DC *dc;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
OPENGL_Context ctx = (OPENGL_Context)hglrc1;
|
|
|
|
|
|
|
|
TRACE("hglrc1: (%p); hglrc: (%p)\n", hglrc1, hglrc2);
|
2009-11-15 12:09:08 +01:00
|
|
|
if(ctx == NULL || hglrc2 == NULL)
|
2006-10-14 22:49:09 +02:00
|
|
|
return FALSE;
|
2007-09-24 18:17:21 +02:00
|
|
|
|
2006-10-14 22:49:09 +02:00
|
|
|
/* Retrieve the HDC associated with the context to access the display driver */
|
2007-09-24 18:17:21 +02:00
|
|
|
dc = get_dc_ptr(ctx->hdc);
|
2006-10-14 22:49:09 +02:00
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
|
|
|
if (!dc->funcs->pwglShareLists) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglShareLists(hglrc1, hglrc2);
|
|
|
|
|
2007-09-24 18:17:21 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-14 22:49:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-03 21:22:22 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wglUseFontBitmapsA (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglUseFontBitmapsA(HDC hdc, DWORD first, DWORD count, DWORD listBase)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2007-09-24 18:17:21 +02:00
|
|
|
DC * dc = get_dc_ptr( hdc );
|
2006-10-03 21:22:22 +02:00
|
|
|
|
2006-10-12 22:56:56 +02:00
|
|
|
TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
|
2006-10-03 21:22:22 +02:00
|
|
|
|
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
|
|
|
if (!dc->funcs->pwglUseFontBitmapsA) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglUseFontBitmapsA(dc->physDev, first, count, listBase);
|
|
|
|
|
2007-09-24 18:17:21 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-03 21:22:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wglUseFontBitmapsW (OPENGL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI wglUseFontBitmapsW(HDC hdc, DWORD first, DWORD count, DWORD listBase)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2007-09-24 18:17:21 +02:00
|
|
|
DC * dc = get_dc_ptr( hdc );
|
2006-10-03 21:22:22 +02:00
|
|
|
|
2006-10-12 22:56:56 +02:00
|
|
|
TRACE("(%p, %d, %d, %d)\n", hdc, first, count, listBase);
|
2006-10-03 21:22:22 +02:00
|
|
|
|
|
|
|
if (!dc) return FALSE;
|
|
|
|
|
|
|
|
if (!dc->funcs->pwglUseFontBitmapsW) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglUseFontBitmapsW(dc->physDev, first, count, listBase);
|
|
|
|
|
2007-09-24 18:17:21 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-03 21:22:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2006-10-26 23:11:07 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Internal wglGetProcAddress for retrieving WGL extensions
|
|
|
|
*/
|
|
|
|
PROC WINAPI wglGetProcAddress(LPCSTR func)
|
|
|
|
{
|
|
|
|
PROC ret = NULL;
|
2006-10-31 18:29:14 +01:00
|
|
|
DC *dc;
|
2006-10-26 23:11:07 +02:00
|
|
|
|
|
|
|
if(!func)
|
|
|
|
return NULL;
|
|
|
|
|
2007-08-29 00:40:46 +02:00
|
|
|
TRACE("func: '%s'\n", func);
|
2006-10-26 23:11:07 +02:00
|
|
|
|
|
|
|
/* Retrieve the global hDC to get access to the driver. */
|
|
|
|
dc = OPENGL_GetDefaultDC();
|
2009-08-06 10:17:58 +02:00
|
|
|
if (!dc) return NULL;
|
2006-10-26 23:11:07 +02:00
|
|
|
|
|
|
|
if (!dc->funcs->pwglGetProcAddress) FIXME(" :stub\n");
|
|
|
|
else ret = dc->funcs->pwglGetProcAddress(func);
|
|
|
|
|
2007-09-17 16:49:37 +02:00
|
|
|
release_dc_ptr( dc );
|
2006-10-26 23:11:07 +02:00
|
|
|
|
2006-10-31 18:29:14 +01:00
|
|
|
/* At the moment we implement one WGL extension which requires a HDC. When we
|
|
|
|
* are looking up this call and when the Extension is available (that is the case
|
|
|
|
* when a non-NULL value is returned by wglGetProcAddress), we return the address
|
|
|
|
* of a wrapper function which will handle the HDC->PhysDev conversion.
|
|
|
|
*/
|
2009-11-16 23:24:24 +01:00
|
|
|
if(ret && strcmp(func, "wglCreateContextAttribsARB") == 0)
|
|
|
|
return (PROC)wglCreateContextAttribsARB;
|
|
|
|
else if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0)
|
2007-05-24 16:41:17 +02:00
|
|
|
return (PROC)wglMakeContextCurrentARB;
|
2006-11-04 22:23:15 +01:00
|
|
|
else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0)
|
|
|
|
return (PROC)wglGetPbufferDCARB;
|
2008-04-23 00:15:15 +02:00
|
|
|
else if(ret && strcmp(func, "wglSetPixelFormatWINE") == 0)
|
|
|
|
return (PROC)wglSetPixelFormatWINE;
|
2006-10-31 18:29:14 +01:00
|
|
|
|
2006-10-26 23:11:07 +02:00
|
|
|
return ret;
|
|
|
|
}
|