[MSACM32]
[reactos.git] / reactos / dll / opengl / mesa / src / gallium / state_trackers / wgl / stw_ext_context.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.11
4 *
5 * Copyright (C) 2011 Morgan Armand <morgan.devel@gmail.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 //#include <windows.h>
26
27 #define WGL_WGLEXT_PROTOTYPES
28
29 #include <GL/gl.h>
30 #include <GL/wglext.h>
31
32 #include "stw_icd.h"
33 #include "stw_context.h"
34
35 HGLRC WINAPI
36 wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
37 {
38 int majorVersion = 1, minorVersion = 0, layerPlane = 0;
39 int contextFlags = 0x0;
40 int profileMask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
41 int i;
42 BOOL done = FALSE;
43
44 /* parse attrib_list */
45 if (attribList) {
46 for (i = 0; !done && attribList[i]; i++) {
47 switch (attribList[i]) {
48 case WGL_CONTEXT_MAJOR_VERSION_ARB:
49 majorVersion = attribList[++i];
50 break;
51 case WGL_CONTEXT_MINOR_VERSION_ARB:
52 minorVersion = attribList[++i];
53 break;
54 case WGL_CONTEXT_LAYER_PLANE_ARB:
55 layerPlane = attribList[++i];
56 break;
57 case WGL_CONTEXT_FLAGS_ARB:
58 contextFlags = attribList[++i];
59 break;
60 case WGL_CONTEXT_PROFILE_MASK_ARB:
61 profileMask = attribList[++i];
62 break;
63 case 0:
64 /* end of list */
65 done = TRUE;
66 break;
67 default:
68 /* bad attribute */
69 SetLastError(ERROR_INVALID_PARAMETER);
70 return NULL;
71 }
72 }
73 }
74
75 /* check version (generate ERROR_INVALID_VERSION_ARB if bad) */
76 switch (majorVersion) {
77 case 1:
78 if (minorVersion < 0 || minorVersion > 5) {
79 SetLastError(ERROR_INVALID_VERSION_ARB);
80 return NULL;
81 }
82 break;
83 case 2:
84 if (minorVersion < 0 || minorVersion > 1) {
85 SetLastError(ERROR_INVALID_VERSION_ARB);
86 return NULL;
87 }
88 break;
89 case 3:
90 if (minorVersion < 0 || minorVersion > 3) {
91 SetLastError(ERROR_INVALID_VERSION_ARB);
92 return NULL;
93 }
94 break;
95 case 4:
96 if (minorVersion < 0 || minorVersion > 2) {
97 SetLastError(ERROR_INVALID_VERSION_ARB);
98 return NULL;
99 }
100 break;
101 default:
102 return NULL;
103 }
104
105 if ((contextFlags & WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) && majorVersion < 3) {
106 SetLastError(ERROR_INVALID_VERSION_ARB);
107 return NULL;
108 }
109
110 /* check profileMask */
111 if (profileMask != WGL_CONTEXT_CORE_PROFILE_BIT_ARB &&
112 profileMask != WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) {
113 SetLastError(ERROR_INVALID_PROFILE_ARB);
114 return NULL;
115 }
116
117 return (HGLRC) stw_create_context_attribs( hDC, layerPlane, (DHGLRC)(UINT_PTR)hShareContext,
118 majorVersion, minorVersion, contextFlags, profileMask );
119 }