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);
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCopyContext );
|
|
|
|
ret = physdev->funcs->pwglCopyContext(hglrcSrc, hglrcDst, mask);
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
}
|
2007-11-11 21:32:12 +01:00
|
|
|
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);
|
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContext );
|
|
|
|
update_dc( dc );
|
|
|
|
ret = physdev->funcs->pwglCreateContext( physdev );
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
}
|
2006-10-03 19:52:17 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-16 23:24:24 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* wglCreateContextAttribsARB
|
|
|
|
*/
|
2009-11-24 11:02:14 +01:00
|
|
|
static HGLRC WINAPI wglCreateContextAttribsARB(HDC hdc, HGLRC hShareContext, const int *attributeList)
|
2009-11-16 23:24:24 +01:00
|
|
|
{
|
|
|
|
HGLRC ret = 0;
|
|
|
|
DC * dc = get_dc_ptr( hdc );
|
|
|
|
|
|
|
|
TRACE("(%p)\n",hdc);
|
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContextAttribsARB );
|
|
|
|
update_dc( dc );
|
|
|
|
ret = physdev->funcs->pwglCreateContextAttribsARB( physdev, hShareContext, attributeList );
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
}
|
2009-11-16 23:24:24 +01:00
|
|
|
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)
|
2010-11-07 07:14:44 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
2006-10-16 23:28:33 +02:00
|
|
|
return FALSE;
|
2010-11-07 07:14:44 +01:00
|
|
|
}
|
2006-10-16 23:28:33 +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);
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
2010-11-07 07:14:44 +01:00
|
|
|
{
|
2011-03-09 20:51:06 +01:00
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglDeleteContext );
|
|
|
|
ret = physdev->funcs->pwglDeleteContext( hglrc );
|
|
|
|
release_dc_ptr( dc );
|
2010-11-07 07:14:44 +01:00
|
|
|
}
|
2011-03-09 20:51:06 +01:00
|
|
|
else SetLastError(ERROR_INVALID_HANDLE);
|
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-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);
|
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglMakeCurrent );
|
|
|
|
update_dc( dc );
|
|
|
|
ret = physdev->funcs->pwglMakeCurrent( physdev, hglrc );
|
|
|
|
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;
|
2011-03-09 20:51:06 +01:00
|
|
|
PHYSDEV draw_physdev, read_physdev;
|
2006-10-31 18:29:14 +01:00
|
|
|
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 );
|
2011-03-09 20:51:06 +01:00
|
|
|
draw_physdev = GET_DC_PHYSDEV( DrawDC, pwglMakeContextCurrentARB );
|
|
|
|
read_physdev = GET_DC_PHYSDEV( ReadDC, pwglMakeContextCurrentARB );
|
|
|
|
if (draw_physdev->funcs == read_physdev->funcs)
|
|
|
|
ret = draw_physdev->funcs->pwglMakeContextCurrentARB(draw_physdev, read_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);
|
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglSetPixelFormatWINE );
|
|
|
|
update_dc( dc );
|
|
|
|
bRet = physdev->funcs->pwglSetPixelFormatWINE( physdev, iPixelFormat, ppfd );
|
|
|
|
release_dc_ptr( dc );
|
|
|
|
}
|
2008-04-23 00:15:15 +02:00
|
|
|
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);
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglShareLists );
|
|
|
|
ret = physdev->funcs->pwglShareLists( hglrc1, hglrc2 );
|
|
|
|
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
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglUseFontBitmapsA );
|
|
|
|
ret = physdev->funcs->pwglUseFontBitmapsA( physdev, first, count, listBase );
|
|
|
|
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
|
|
|
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglUseFontBitmapsW );
|
|
|
|
ret = physdev->funcs->pwglUseFontBitmapsW( physdev, first, count, listBase );
|
|
|
|
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();
|
2011-03-09 20:51:06 +01:00
|
|
|
if (dc)
|
|
|
|
{
|
|
|
|
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress );
|
|
|
|
ret = physdev->funcs->pwglGetProcAddress(func);
|
|
|
|
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;
|
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;
|
|
|
|
}
|