1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #include "CoreProfileConfigs.h"
18 
19 #ifdef _MSC_VER
20 // For gl.h WINGDIAPI to be defined
21 #include <windows.h>
22 #endif
23 #include <GLES/glplatform.h>
24 #include <GL/gl.h>
25 #include <GL/wglext.h>
26 
27 // Based on https://git.reviewboard.kde.org/r/130118/diff/1#index_header
28 static const int kCoreProfileConfig_4_5[] = {
29     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
30     WGL_CONTEXT_MINOR_VERSION_ARB, 5,
31     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
32     0
33 };
34 
35 static const int kCoreProfileConfig_4_4[] = {
36     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
37     WGL_CONTEXT_MINOR_VERSION_ARB, 4,
38     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
39     0
40 };
41 
42 static const int kCoreProfileConfig_4_3[] = {
43     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
44     WGL_CONTEXT_MINOR_VERSION_ARB, 3,
45     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
46     0
47 };
48 
49 static const int kCoreProfileConfig_4_2[] = {
50     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
51     WGL_CONTEXT_MINOR_VERSION_ARB, 2,
52     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
53     0
54 };
55 
56 static const int kCoreProfileConfig_4_1[] = {
57     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
58     WGL_CONTEXT_MINOR_VERSION_ARB, 1,
59     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
60     0
61 };
62 
63 static const int kCoreProfileConfig_4_0[] = {
64     WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
65     WGL_CONTEXT_MINOR_VERSION_ARB, 0,
66     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
67     0
68 };
69 
70 static const int kCoreProfileConfig_3_3[] = {
71     WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
72     WGL_CONTEXT_MINOR_VERSION_ARB, 3,
73     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
74     0
75 };
76 
77 static const int kCoreProfileConfig_3_2[] = {
78     WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
79     WGL_CONTEXT_MINOR_VERSION_ARB, 2,
80     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
81     0
82 };
83 
84 static const int* kCoreProfileConfigs[] = {
85     kCoreProfileConfig_4_5,
86     kCoreProfileConfig_4_4,
87     kCoreProfileConfig_4_3,
88     kCoreProfileConfig_4_2,
89     kCoreProfileConfig_4_1,
90     kCoreProfileConfig_4_0,
91     kCoreProfileConfig_3_3,
92     kCoreProfileConfig_3_2,
93 };
94 
95 // Versions 3.1 and below ignored since they won't
96 // help us support ES 3.x
97 
getNumCoreProfileCtxAttribs()98 int getNumCoreProfileCtxAttribs() {
99     return sizeof(kCoreProfileConfigs) / sizeof(kCoreProfileConfigs[0]);
100 }
101 
getCoreProfileCtxAttribs(int index)102 const int* getCoreProfileCtxAttribs(int index) {
103     return kCoreProfileConfigs[index];
104 }
105 
getCoreProfileCtxAttribsVersion(const int * attribs,int * maj,int * min)106 void getCoreProfileCtxAttribsVersion(const int* attribs, int* maj, int* min) {
107     int i = 0;
108     if (!attribs) return;
109 
110     while (attribs[i] != 0) {
111         switch (attribs[i]) {
112             case WGL_CONTEXT_MAJOR_VERSION_ARB:
113                 if (maj) *maj = attribs[i + 1];
114                 break;
115             case WGL_CONTEXT_MINOR_VERSION_ARB:
116                 if (min) *min = attribs[i + 1];
117                 break;
118             default:
119                 break;
120         }
121         i += 2;
122     }
123 }
124