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 #include <GL/glx.h>
20 
21 // Based on https://git.reviewboard.kde.org/r/130118/diff/1#index_header
22 static const int kCoreProfileConfig_4_5[] = {
23     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
24     GLX_CONTEXT_MINOR_VERSION_ARB, 5,
25     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
26     None
27 };
28 
29 static const int kCoreProfileConfig_4_4[] = {
30     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
31     GLX_CONTEXT_MINOR_VERSION_ARB, 4,
32     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
33     None
34 };
35 
36 static const int kCoreProfileConfig_4_3[] = {
37     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
38     GLX_CONTEXT_MINOR_VERSION_ARB, 3,
39     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
40     None
41 };
42 
43 static const int kCoreProfileConfig_4_2[] = {
44     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
45     GLX_CONTEXT_MINOR_VERSION_ARB, 2,
46     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
47     None
48 };
49 
50 static const int kCoreProfileConfig_4_1[] = {
51     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
52     GLX_CONTEXT_MINOR_VERSION_ARB, 1,
53     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
54     None
55 };
56 
57 static const int kCoreProfileConfig_4_0[] = {
58     GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
59     GLX_CONTEXT_MINOR_VERSION_ARB, 0,
60     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
61     None
62 };
63 
64 static const int kCoreProfileConfig_3_3[] = {
65     GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
66     GLX_CONTEXT_MINOR_VERSION_ARB, 3,
67     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
68     None
69 };
70 
71 static const int kCoreProfileConfig_3_2[] = {
72     GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
73     GLX_CONTEXT_MINOR_VERSION_ARB, 2,
74     GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
75     None
76 };
77 
78 static const int* kCoreProfileConfigs[] = {
79     kCoreProfileConfig_4_5,
80     kCoreProfileConfig_4_4,
81     kCoreProfileConfig_4_3,
82     kCoreProfileConfig_4_2,
83     kCoreProfileConfig_4_1,
84     kCoreProfileConfig_4_0,
85     kCoreProfileConfig_3_3,
86     kCoreProfileConfig_3_2,
87 };
88 
89 // Versions 3.1 and below ignored since they won't
90 // help us support ES 3.x
91 
getNumCoreProfileCtxAttribs()92 int getNumCoreProfileCtxAttribs() {
93     return sizeof(kCoreProfileConfigs) / sizeof(kCoreProfileConfigs[0]);
94 }
95 
getCoreProfileCtxAttribs(int index)96 const int* getCoreProfileCtxAttribs(int index) {
97     return kCoreProfileConfigs[index];
98 }
99 
getCoreProfileCtxAttribsVersion(const int * attribs,int * maj,int * min)100 void getCoreProfileCtxAttribsVersion(const int* attribs, int* maj, int* min) {
101     int i = 0;
102     if (!attribs) return;
103 
104     while (attribs[i] != None) {
105         switch (attribs[i]) {
106             case GLX_CONTEXT_MAJOR_VERSION_ARB:
107                 if (maj) *maj = attribs[i + 1];
108                 break;
109             case GLX_CONTEXT_MINOR_VERSION_ARB:
110                 if (min) *min = attribs[i + 1];
111                 break;
112             default:
113                 break;
114         }
115         i += 2;
116     }
117 }
118