3 * Copyright (C) 2003 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 typedef int (WINAPI
*CHOOSEPIXELFMT
) (HDC
, CONST PIXELFORMATDESCRIPTOR
*);
32 typedef BOOL (WINAPI
*SETPIXELFMT
) (HDC
, int, CONST PIXELFORMATDESCRIPTOR
*);
33 typedef BOOL (WINAPI
*SWAPBUFFERS
) (HDC hdc
);
34 typedef int (WINAPI
*DESCRIBEPIXELFMT
) (HDC
, int, UINT
, LPPIXELFORMATDESCRIPTOR
);
35 typedef int (WINAPI
*GETPIXELFMT
) (HDC
);
38 static CHOOSEPIXELFMT glChoosePixelFormat
= NULL
;
39 static SETPIXELFMT glSetPixelFormat
= NULL
;
40 static SWAPBUFFERS glSwapBuffers
= NULL
;
41 static DESCRIBEPIXELFMT glDescribePixelFormat
= NULL
;
42 static GETPIXELFMT glGetPixelFormat
= NULL
;
47 HINSTANCE hOpenGL
= NULL
;
49 static BOOL
OpenGLInitFunction(PCSTR name
,
54 func
= (PVOID
)GetProcAddress(hOpenGL
, name
);
57 (void)InterlockedCompareExchangePointer((PVOID
*)funcptr
,
66 static BOOL
OpenGLEnable(void)
71 hModOpengl32
= LoadLibraryW(L
"OPENGL32.DLL");
72 if (hModOpengl32
== NULL
)
75 if (InterlockedCompareExchangePointer((PVOID
*)&hOpenGL
,
79 FreeLibrary(hModOpengl32
);
81 /* NOTE: Even though another thread was faster loading the
82 library we can't just bail out here. We really need
83 to *try* to locate every function. This is slow but
88 if (!OpenGLInitFunction("wglChoosePixelFormat", &glChoosePixelFormat
))
91 if (!OpenGLInitFunction("wglSetPixelFormat", &glSetPixelFormat
))
94 if (!OpenGLInitFunction("wglSwapBuffers", &glSwapBuffers
))
97 if (!OpenGLInitFunction("wglDescribePixelFormat", &glDescribePixelFormat
))
100 if (!OpenGLInitFunction("wglGetPixelFormat", &glGetPixelFormat
))
113 ChoosePixelFormat(HDC hdc
,
114 CONST PIXELFORMATDESCRIPTOR
* ppfd
)
116 if (glChoosePixelFormat
== NULL
)
117 if (OpenGLEnable() == FALSE
)
120 return(glChoosePixelFormat(hdc
, ppfd
));
130 DescribePixelFormat(HDC hdc
,
133 LPPIXELFORMATDESCRIPTOR ppfd
)
135 if (glDescribePixelFormat
== NULL
)
136 if (OpenGLEnable() == FALSE
)
139 return(glDescribePixelFormat(hdc
, iPixelFormat
, nBytes
, ppfd
));
149 GetPixelFormat(HDC hdc
)
151 if (glGetPixelFormat
== NULL
)
152 if (OpenGLEnable() == FALSE
)
155 return(glGetPixelFormat(hdc
));
165 SetPixelFormat(HDC hdc
,
167 CONST PIXELFORMATDESCRIPTOR
* ppfd
)
169 /* Can only be set once */
170 INT current
= GetPixelFormat(hdc
);
171 if(current
) return current
== iPixelFormat
;
173 if (glSetPixelFormat
== NULL
)
174 if (OpenGLEnable() == FALSE
)
177 return(glSetPixelFormat(hdc
, iPixelFormat
, ppfd
));
189 if (glSwapBuffers
== NULL
)
190 if (OpenGLEnable() == FALSE
)
194 return(glSwapBuffers(hdc
));
199 Do this here for now.
207 GetEnhMetaFilePixelFormat(
210 PIXELFORMATDESCRIPTOR
*ppfd
215 if(GetEnhMetaFileHeader(hemf
, sizeof(ENHMETAHEADER
), &pemh
))
219 if(pemh
.cbPixelFormat
)
221 memcpy((void*)ppfd
, UlongToPtr(pemh
.offPixelFormat
), cbBuffer
);
222 return(pemh
.cbPixelFormat
);