1/*
2* Copyright 2011 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 "MacPixelFormatsAttribs.h"
18
19static const NSOpenGLPixelFormatAttribute attrs32_1[] =
20{
21    NSOpenGLPFAColorSize   ,32,
22    NSOpenGLPFADepthSize   ,24,
23    NSOpenGLPFAStencilSize ,8,
24    0
25};
26
27static const NSOpenGLPixelFormatAttribute attrs32_2[] =
28{
29    NSOpenGLPFAColorSize   ,32,
30    NSOpenGLPFAAlphaSize   ,8,
31    NSOpenGLPFADepthSize   ,24,
32    NSOpenGLPFAStencilSize ,8,
33    0
34};
35
36static const NSOpenGLPixelFormatAttribute attrs32_3[] =
37{
38    NSOpenGLPFAColorSize   ,32,
39    NSOpenGLPFAAlphaSize   ,8,
40    0
41};
42
43static const NSOpenGLPixelFormatAttribute attrs32_4[] =
44{
45    NSOpenGLPFAColorSize   ,32,
46    0
47};
48
49static const NSOpenGLPixelFormatAttribute attrs32_5[] =
50{
51    NSOpenGLPFAColorSize   ,32,
52    NSOpenGLPFADepthSize   ,24,
53    NSOpenGLPFASamples     ,2,
54    0
55};
56
57static const NSOpenGLPixelFormatAttribute attrs32_6[] =
58{
59    NSOpenGLPFAColorSize   ,32,
60    NSOpenGLPFADepthSize   ,24,
61    NSOpenGLPFASamples     ,4,
62    0
63};
64
65static const NSOpenGLPixelFormatAttribute attrs32_7[] =
66{
67    NSOpenGLPFAColorSize   ,32,
68    NSOpenGLPFAAlphaSize   ,8,
69    NSOpenGLPFADepthSize   ,24,
70    NSOpenGLPFAStencilSize ,8,
71    NSOpenGLPFASamples     ,4,
72    0
73};
74
75static const NSOpenGLPixelFormatAttribute attrs16_1[] =
76{
77    NSOpenGLPFAColorSize   ,16,
78    NSOpenGLPFADepthSize   ,24,
79    0
80};
81
82static NSOpenGLPixelFormatAttribute attrs16_2[] =
83{
84    NSOpenGLPFAColorSize   ,16,
85    NSOpenGLPFADepthSize   ,24,
86    NSOpenGLPFAStencilSize ,8,
87    0
88};
89
90const NSOpenGLPixelFormatAttribute* const* getPixelFormatsAttributes(int* size){
91    static const NSOpenGLPixelFormatAttribute* const arr[] = {
92        attrs32_1,
93        attrs32_2,
94        attrs32_3,
95        attrs32_4,
96        attrs32_5,
97        attrs32_6,
98        attrs32_7,
99    };
100    *size = sizeof(arr)/sizeof(arr[0]);
101    return arr;
102}
103
104// Variants
105static const NSOpenGLPixelFormatAttribute Legacy[] = {
106    NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
107    NSOpenGLPFADoubleBuffer,
108    NSOpenGLPFAWindow,
109    NSOpenGLPFAPixelBuffer,
110    0
111};
112
113static const NSOpenGLPixelFormatAttribute Core3_2[] = {
114    NSOpenGLPFAAccelerated,
115    NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
116    NSOpenGLPFADoubleBuffer,
117    0
118};
119
120static const NSOpenGLPixelFormatAttribute Core4_1[] = {
121    NSOpenGLPFAAccelerated,
122    NSOpenGLPFANoRecovery,
123    NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core,
124    NSOpenGLPFADoubleBuffer,
125    0
126};
127
128static NSOpenGLPixelFormatAttribute sWantedCoreProfileLevel = 0;
129
130void setCoreProfileLevel(NSOpenGLPixelFormatAttribute level) {
131    sWantedCoreProfileLevel = level;
132}
133
134const NSOpenGLPixelFormatAttribute* const  getLegacyProfileAttributes() {
135    return Legacy;
136}
137
138const NSOpenGLPixelFormatAttribute* const getCoreProfileAttributes() {
139    if (sWantedCoreProfileLevel == NSOpenGLProfileVersion4_1Core) {
140        return Core4_1;
141    } else if (sWantedCoreProfileLevel == NSOpenGLProfileVersion3_2Core) {
142        return Core3_2;
143    } else {
144        return Legacy;
145    }
146}
147