Fix atomic ssbo xor test
[platform/upstream/VK-GL-CTS.git] / framework / opengl / gluRenderConfig.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief OpenGL rendering configuration.
22  *//*--------------------------------------------------------------------*/
23
24 #include "gluRenderConfig.hpp"
25 #include "tcuCommandLine.hpp"
26 #include "deString.h"
27
28 namespace glu
29 {
30
31 void parseConfigBitsFromName (RenderConfig* config, const char* renderCfgName)
32 {
33         const char*     cfgName = renderCfgName;
34
35         DE_ASSERT(config->redBits               == RenderConfig::DONT_CARE      &&
36                           config->greenBits             == RenderConfig::DONT_CARE      &&
37                           config->blueBits              == RenderConfig::DONT_CARE      &&
38                           config->alphaBits             == RenderConfig::DONT_CARE      &&
39                           config->depthBits             == RenderConfig::DONT_CARE      &&
40                           config->stencilBits   == RenderConfig::DONT_CARE      &&
41                           config->numSamples    == RenderConfig::DONT_CARE);
42
43         static const struct
44         {
45                 const char*     name;
46                 int                     redBits;
47                 int                     greenBits;
48                 int                     blueBits;
49                 int                     alphaBits;
50         } colorCfgs[] =
51         {
52                 { "rgb888",             8, 8, 8, 0 },
53                 { "rgba8888",   8, 8, 8, 8 },
54                 { "rgb565",             5, 6, 5, 0 },
55                 { "rgba4444",   4, 4, 4, 4 },
56                 { "rgba5551",   5, 5, 5, 1 }
57         };
58         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorCfgs); ndx++)
59         {
60                 if (deStringBeginsWith(cfgName, colorCfgs[ndx].name))
61                 {
62                         config->redBits         = colorCfgs[ndx].redBits;
63                         config->greenBits       = colorCfgs[ndx].greenBits;
64                         config->blueBits        = colorCfgs[ndx].blueBits;
65                         config->alphaBits       = colorCfgs[ndx].alphaBits;
66
67                         cfgName += strlen(colorCfgs[ndx].name);
68                         break;
69                 }
70         }
71
72         static const struct
73         {
74                 const char*     name;
75                 int                     depthSize;
76         } depthCfgs[] =
77         {
78                 { "d0",         0 },
79                 { "d16",        16 },
80                 { "d24",        24 },
81                 { "d32",        32 }
82         };
83         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthCfgs); ndx++)
84         {
85                 if (deStringBeginsWith(cfgName, depthCfgs[ndx].name))
86                 {
87                         config->depthBits = depthCfgs[ndx].depthSize;
88
89                         cfgName += strlen(depthCfgs[ndx].name);
90                         break;
91                 }
92         }
93
94         static const struct
95         {
96                 const char*     name;
97                 int                     stencilSize;
98         } stencilCfgs[] =
99         {
100                 { "s0",          0 },
101                 { "s8",          8 },
102                 { "s16",        16 },
103         };
104         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(stencilCfgs); ndx++)
105         {
106                 if (deStringBeginsWith(cfgName, stencilCfgs[ndx].name))
107                 {
108                         config->stencilBits = stencilCfgs[ndx].stencilSize;
109
110                         cfgName += strlen(stencilCfgs[ndx].name);
111                         break;
112                 }
113         }
114
115         static const struct
116         {
117                 const char*     name;
118                 int                     numSamples;
119         } multiSampleCfgs[] =
120         {
121                 { "ms0",         0 },
122                 { "ms16",       16 },
123                 { "ms1",         1 },
124                 { "ms2",         2 },
125                 { "ms4",         4 },
126                 { "ms8",         8 }
127         };
128         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(multiSampleCfgs); ndx++)
129         {
130                 if (deStringBeginsWith(cfgName, multiSampleCfgs[ndx].name))
131                 {
132                         config->numSamples = multiSampleCfgs[ndx].numSamples;
133
134                         cfgName += strlen(multiSampleCfgs[ndx].name);
135                         break;
136                 }
137         }
138
139         if (cfgName[0] != 0)
140                 throw tcu::InternalError(std::string("Invalid GL configuration: '") + renderCfgName + "'");
141 }
142
143 void parseRenderConfig (RenderConfig* config, const tcu::CommandLine& cmdLine)
144 {
145         switch (cmdLine.getSurfaceType())
146         {
147                 case tcu::SURFACETYPE_WINDOW:                           config->surfaceType             = RenderConfig::SURFACETYPE_WINDOW;                             break;
148                 case tcu::SURFACETYPE_OFFSCREEN_NATIVE:         config->surfaceType             = RenderConfig::SURFACETYPE_OFFSCREEN_NATIVE;   break;
149                 case tcu::SURFACETYPE_OFFSCREEN_GENERIC:        config->surfaceType             = RenderConfig::SURFACETYPE_OFFSCREEN_GENERIC;  break;
150                 case tcu::SURFACETYPE_FBO:                                      config->surfaceType             = RenderConfig::SURFACETYPE_DONT_CARE;                  break;
151                 case tcu::SURFACETYPE_LAST:                                     config->surfaceType             = RenderConfig::SURFACETYPE_DONT_CARE;                  break;
152                 default:
153                         throw tcu::InternalError("Unsupported surface type");
154         }
155
156         config->windowVisibility = parseWindowVisibility(cmdLine);
157
158         if (cmdLine.getSurfaceWidth() > 0)
159                 config->width = cmdLine.getSurfaceWidth();
160
161         if (cmdLine.getSurfaceHeight() > 0)
162                 config->height = cmdLine.getSurfaceHeight();
163
164         if (cmdLine.getGLConfigName() != DE_NULL)
165                 parseConfigBitsFromName(config, cmdLine.getGLConfigName());
166
167         if (cmdLine.getGLConfigId() >= 0)
168                 config->id = cmdLine.getGLConfigId();
169 }
170
171 RenderConfig::Visibility parseWindowVisibility (const tcu::CommandLine& cmdLine)
172 {
173         switch (cmdLine.getVisibility())
174         {
175                 case tcu::WINDOWVISIBILITY_HIDDEN:              return RenderConfig::VISIBILITY_HIDDEN;
176                 case tcu::WINDOWVISIBILITY_WINDOWED:    return RenderConfig::VISIBILITY_VISIBLE;
177                 case tcu::WINDOWVISIBILITY_FULLSCREEN:  return RenderConfig::VISIBILITY_FULLSCREEN;
178                 default:
179                         throw tcu::InternalError("Unsupported window visibility");
180         }
181 }
182
183 } // glu