2003-09-06 16:50:11 +00:00
|
|
|
/*
|
|
|
|
* ReactOS Gdi32
|
|
|
|
* Copyright (C) 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-08-15 18:40:07 +00:00
|
|
|
#include "precomp.h"
|
2004-09-06 21:15:46 +00:00
|
|
|
|
2003-09-06 16:50:11 +00:00
|
|
|
#define NDEBUG
|
2005-07-27 20:09:46 +00:00
|
|
|
#include <debug.h>
|
2003-09-06 16:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-09-26 06:26:17 +00:00
|
|
|
typedef int STDCALL (*CHOOSEPIXELFMT) (HDC, CONST PIXELFORMATDESCRIPTOR *);
|
|
|
|
typedef BOOL STDCALL (*SETPIXELFMT) (HDC, int, CONST PIXELFORMATDESCRIPTOR *);
|
|
|
|
typedef BOOL STDCALL (*SWAPBUFFERS) (HDC hdc);
|
|
|
|
typedef int STDCALL (*DESCRIBEPIXELFMT) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
|
|
|
|
typedef int STDCALL (*GETPIXELFMT) (HDC);
|
2003-09-06 16:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
static CHOOSEPIXELFMT glChoosePixelFormat = NULL;
|
|
|
|
static SETPIXELFMT glSetPixelFormat = NULL;
|
|
|
|
static SWAPBUFFERS glSwapBuffers = NULL;
|
|
|
|
static DESCRIBEPIXELFMT glDescribePixelFormat = NULL;
|
|
|
|
static GETPIXELFMT glGetPixelFormat = NULL;
|
2003-09-06 19:44:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
OpenGL Handle.
|
|
|
|
*/
|
|
|
|
HINSTANCE hOpenGL = NULL;
|
2003-09-06 16:50:11 +00:00
|
|
|
|
|
|
|
static BOOL OpenGLEnable(void)
|
|
|
|
{
|
|
|
|
if(hOpenGL == NULL)
|
|
|
|
{
|
|
|
|
hOpenGL = LoadLibraryA("OPENGL32.DLL");
|
|
|
|
if(hOpenGL == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glChoosePixelFormat == NULL) {
|
|
|
|
glChoosePixelFormat = (CHOOSEPIXELFMT)GetProcAddress(hOpenGL, "wglChoosePixelFormat");
|
|
|
|
if(glChoosePixelFormat == NULL)
|
2007-06-19 20:38:49 +00:00
|
|
|
return(FALSE);
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(glSetPixelFormat == NULL) {
|
|
|
|
glSetPixelFormat = (SETPIXELFMT)GetProcAddress(hOpenGL, "wglSetPixelFormat");
|
|
|
|
if(glSetPixelFormat == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glSwapBuffers == NULL) {
|
|
|
|
glSwapBuffers = (SWAPBUFFERS)GetProcAddress(hOpenGL, "wglSwapBuffers");
|
|
|
|
if(glSwapBuffers == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glDescribePixelFormat == NULL) {
|
|
|
|
glDescribePixelFormat = (DESCRIBEPIXELFMT)GetProcAddress(hOpenGL, "wglDescribePixelFormat");
|
|
|
|
if(glDescribePixelFormat == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(glGetPixelFormat == NULL) {
|
|
|
|
glGetPixelFormat = (GETPIXELFMT)GetProcAddress(hOpenGL, "wglGetPixelFormat");
|
|
|
|
if(glGetPixelFormat == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE); /* OpenGL is initialized and enabled*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
INT
|
|
|
|
STDCALL
|
2004-04-25 14:46:54 +00:00
|
|
|
ChoosePixelFormat(HDC hdc,
|
|
|
|
CONST PIXELFORMATDESCRIPTOR * ppfd)
|
2003-09-06 16:50:11 +00:00
|
|
|
{
|
|
|
|
if (glChoosePixelFormat == NULL)
|
|
|
|
if (OpenGLEnable() == FALSE)
|
|
|
|
return(0);
|
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
return(glChoosePixelFormat(hdc, ppfd));
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
INT
|
|
|
|
STDCALL
|
2004-04-25 14:46:54 +00:00
|
|
|
DescribePixelFormat(HDC hdc,
|
|
|
|
INT iPixelFormat,
|
|
|
|
UINT nBytes,
|
|
|
|
LPPIXELFORMATDESCRIPTOR ppfd)
|
2003-09-06 16:50:11 +00:00
|
|
|
{
|
|
|
|
if (glDescribePixelFormat == NULL)
|
|
|
|
if (OpenGLEnable() == FALSE)
|
|
|
|
return(0);
|
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
return(glDescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd));
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
INT
|
|
|
|
STDCALL
|
2004-04-25 14:46:54 +00:00
|
|
|
GetPixelFormat(HDC hdc)
|
2003-09-06 16:50:11 +00:00
|
|
|
{
|
|
|
|
if (glGetPixelFormat == NULL)
|
|
|
|
if (OpenGLEnable() == FALSE)
|
|
|
|
return(0);
|
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
return(glGetPixelFormat(hdc));
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
STDCALL
|
2004-04-25 14:46:54 +00:00
|
|
|
SetPixelFormat(HDC hdc,
|
|
|
|
INT iPixelFormat,
|
|
|
|
CONST PIXELFORMATDESCRIPTOR * ppfd)
|
2003-09-06 16:50:11 +00:00
|
|
|
{
|
|
|
|
if (glSetPixelFormat == NULL)
|
|
|
|
if (OpenGLEnable() == FALSE)
|
|
|
|
return(0);
|
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
return(glSetPixelFormat(hdc, iPixelFormat, ppfd));
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
STDCALL
|
2004-04-25 14:46:54 +00:00
|
|
|
SwapBuffers(HDC hdc)
|
2003-09-06 16:50:11 +00:00
|
|
|
{
|
|
|
|
if (glSwapBuffers == NULL)
|
|
|
|
if (OpenGLEnable() == FALSE)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
return(glSwapBuffers(hdc));
|
2003-09-06 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
2003-09-06 19:44:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Do this here for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
STDCALL
|
|
|
|
GetEnhMetaFilePixelFormat(
|
2004-04-25 14:46:54 +00:00
|
|
|
HENHMETAFILE hemf,
|
2005-12-28 20:31:44 +00:00
|
|
|
UINT cbBuffer,
|
|
|
|
PIXELFORMATDESCRIPTOR *ppfd
|
2003-09-06 19:44:00 +00:00
|
|
|
)
|
|
|
|
{
|
2004-04-09 20:03:21 +00:00
|
|
|
ENHMETAHEADER pemh;
|
2003-09-06 19:44:00 +00:00
|
|
|
|
2004-04-25 14:46:54 +00:00
|
|
|
if(GetEnhMetaFileHeader(hemf, sizeof(ENHMETAHEADER), &pemh))
|
2003-09-06 19:44:00 +00:00
|
|
|
{
|
|
|
|
if(pemh.bOpenGL)
|
|
|
|
{
|
|
|
|
if(pemh.cbPixelFormat)
|
|
|
|
{
|
2005-12-28 20:31:44 +00:00
|
|
|
memcpy((void*)ppfd, UlongToPtr(pemh.offPixelFormat), cbBuffer );
|
2003-09-06 19:44:00 +00:00
|
|
|
return(pemh.cbPixelFormat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2003-09-06 16:50:11 +00:00
|
|
|
/* EOF */
|