Sweden-Number/dlls/gdi32/opengl.c

192 lines
5.9 KiB
C
Raw Normal View History

/*
* 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"
#include "winternl.h"
#include "winnt.h"
#include "gdi_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
static const WCHAR opengl32W[] = {'o','p','e','n','g','l','3','2','.','d','l','l',0};
static HMODULE opengl32;
static INT (WINAPI *wglChoosePixelFormat)(HDC,const PIXELFORMATDESCRIPTOR *);
static INT (WINAPI *wglDescribePixelFormat)(HDC,INT,UINT,PIXELFORMATDESCRIPTOR*);
static BOOL (WINAPI *wglSetPixelFormat)(HDC,INT,const PIXELFORMATDESCRIPTOR*);
static BOOL (WINAPI *wglSwapBuffers)(HDC);
2006-10-07 20:08:26 +02:00
static HDC default_hdc = 0;
/* 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.
* 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.
*/
static DC* OPENGL_GetDefaultDC(void)
2006-10-07 20:08:26 +02:00
{
if(!default_hdc)
default_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
return get_dc_ptr(default_hdc);
2006-10-07 20:08:26 +02:00
}
/***********************************************************************
* wglCreateContext (OPENGL32.@)
*/
HGLRC WINAPI wglCreateContext(HDC hdc)
{
HGLRC ret = 0;
DC * dc = get_dc_ptr( hdc );
TRACE("(%p)\n",hdc);
if (dc)
{
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContext );
update_dc( dc );
ret = physdev->funcs->pwglCreateContext( physdev );
release_dc_ptr( dc );
}
return ret;
}
/***********************************************************************
* wglCreateContextAttribsARB
*/
static 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)
{
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglCreateContextAttribsARB );
update_dc( dc );
ret = physdev->funcs->pwglCreateContextAttribsARB( physdev, hShareContext, attributeList );
release_dc_ptr( dc );
}
return ret;
}
2006-10-16 23:28:33 +02:00
/***********************************************************************
* Internal wglGetProcAddress for retrieving WGL extensions
*/
PROC WINAPI wglGetProcAddress(LPCSTR func)
{
PROC ret = NULL;
DC *dc;
if(!func)
return NULL;
TRACE("func: '%s'\n", func);
/* Retrieve the global hDC to get access to the driver. */
dc = OPENGL_GetDefaultDC();
if (dc)
{
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress );
ret = physdev->funcs->pwglGetProcAddress(func);
release_dc_ptr( dc );
}
/* 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.
*/
if(ret && strcmp(func, "wglCreateContextAttribsARB") == 0)
return (PROC)wglCreateContextAttribsARB;
return ret;
}
/******************************************************************************
* ChoosePixelFormat (GDI32.@)
*/
INT WINAPI ChoosePixelFormat( HDC hdc, const PIXELFORMATDESCRIPTOR *pfd )
{
if (!wglChoosePixelFormat)
{
if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
if (!(wglChoosePixelFormat = (void *)GetProcAddress( opengl32, "wglChoosePixelFormat" )))
return 0;
}
return wglChoosePixelFormat( hdc, pfd );
}
/******************************************************************************
* DescribePixelFormat (GDI32.@)
*/
INT WINAPI DescribePixelFormat( HDC hdc, INT fmt, UINT size, PIXELFORMATDESCRIPTOR *pfd )
{
if (!wglDescribePixelFormat)
{
if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
if (!(wglDescribePixelFormat = (void *)GetProcAddress( opengl32, "wglDescribePixelFormat" )))
return 0;
}
return wglDescribePixelFormat( hdc, fmt, size, pfd );
}
/******************************************************************************
* SetPixelFormat (GDI32.@)
*/
BOOL WINAPI SetPixelFormat( HDC hdc, INT fmt, const PIXELFORMATDESCRIPTOR *pfd )
{
if (!wglSetPixelFormat)
{
if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
if (!(wglSetPixelFormat = (void *)GetProcAddress( opengl32, "wglSetPixelFormat" )))
return 0;
}
return wglSetPixelFormat( hdc, fmt, pfd );
}
/******************************************************************************
* SwapBuffers (GDI32.@)
*/
BOOL WINAPI SwapBuffers( HDC hdc )
{
if (!wglSwapBuffers)
{
if (!opengl32) opengl32 = LoadLibraryW( opengl32W );
if (!(wglSwapBuffers = (void *)GetProcAddress( opengl32, "wglSwapBuffers" )))
return 0;
}
return wglSwapBuffers( hdc );
}