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 #include "eglwEnums.hpp"
28
29 namespace glu
30 {
31
parseConfigBitsFromName(RenderConfig * config,const char * renderCfgName)32 void parseConfigBitsFromName(RenderConfig *config, const char *renderCfgName)
33 {
34 const char *cfgName = renderCfgName;
35
36 DE_ASSERT(config->redBits == RenderConfig::DONT_CARE && config->greenBits == RenderConfig::DONT_CARE &&
37 config->blueBits == RenderConfig::DONT_CARE && config->alphaBits == RenderConfig::DONT_CARE &&
38 config->depthBits == RenderConfig::DONT_CARE && config->stencilBits == RenderConfig::DONT_CARE &&
39 config->numSamples == RenderConfig::DONT_CARE);
40
41 static const struct
42 {
43 const char *name;
44 int redBits;
45 int greenBits;
46 int blueBits;
47 int alphaBits;
48 } colorCfgs[] = {{"rgb888", 8, 8, 8, 0},
49 {"rgba8888", 8, 8, 8, 8},
50 {"rgb565", 5, 6, 5, 0},
51 {"rgba4444", 4, 4, 4, 4},
52 {"rgba5551", 5, 5, 5, 1}};
53 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorCfgs); ndx++)
54 {
55 if (deStringBeginsWith(cfgName, colorCfgs[ndx].name))
56 {
57 config->redBits = colorCfgs[ndx].redBits;
58 config->greenBits = colorCfgs[ndx].greenBits;
59 config->blueBits = colorCfgs[ndx].blueBits;
60 config->alphaBits = colorCfgs[ndx].alphaBits;
61
62 cfgName += strlen(colorCfgs[ndx].name);
63 break;
64 }
65 }
66
67 static const struct
68 {
69 const char *name;
70 int depthSize;
71 } depthCfgs[] = {{"d0", 0}, {"d16", 16}, {"d24", 24}, {"d32", 32}};
72 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthCfgs); ndx++)
73 {
74 if (deStringBeginsWith(cfgName, depthCfgs[ndx].name))
75 {
76 config->depthBits = depthCfgs[ndx].depthSize;
77
78 cfgName += strlen(depthCfgs[ndx].name);
79 break;
80 }
81 }
82
83 static const struct
84 {
85 const char *name;
86 int stencilSize;
87 } stencilCfgs[] = {
88 {"s0", 0},
89 {"s8", 8},
90 {"s16", 16},
91 };
92 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(stencilCfgs); ndx++)
93 {
94 if (deStringBeginsWith(cfgName, stencilCfgs[ndx].name))
95 {
96 config->stencilBits = stencilCfgs[ndx].stencilSize;
97
98 cfgName += strlen(stencilCfgs[ndx].name);
99 break;
100 }
101 }
102
103 static const struct
104 {
105 const char *name;
106 int numSamples;
107 } multiSampleCfgs[] = {{"ms0", 0}, {"ms16", 16}, {"ms1", 1}, {"ms2", 2}, {"ms4", 4}, {"ms8", 8}};
108 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(multiSampleCfgs); ndx++)
109 {
110 if (deStringBeginsWith(cfgName, multiSampleCfgs[ndx].name))
111 {
112 config->numSamples = multiSampleCfgs[ndx].numSamples;
113
114 cfgName += strlen(multiSampleCfgs[ndx].name);
115 break;
116 }
117 }
118
119 if (cfgName[0] != 0)
120 throw tcu::InternalError(std::string("Invalid GL configuration: '") + renderCfgName + "'");
121 }
122
parseRenderConfig(RenderConfig * config,const tcu::CommandLine & cmdLine)123 void parseRenderConfig(RenderConfig *config, const tcu::CommandLine &cmdLine)
124 {
125 switch (cmdLine.getSurfaceType())
126 {
127 case tcu::SURFACETYPE_WINDOW:
128 config->surfaceType = RenderConfig::SURFACETYPE_WINDOW;
129 break;
130 case tcu::SURFACETYPE_OFFSCREEN_NATIVE:
131 config->surfaceType = RenderConfig::SURFACETYPE_OFFSCREEN_NATIVE;
132 break;
133 case tcu::SURFACETYPE_OFFSCREEN_GENERIC:
134 config->surfaceType = RenderConfig::SURFACETYPE_OFFSCREEN_GENERIC;
135 break;
136 case tcu::SURFACETYPE_FBO:
137 config->surfaceType = RenderConfig::SURFACETYPE_DONT_CARE;
138 break;
139 case tcu::SURFACETYPE_LAST:
140 config->surfaceType = RenderConfig::SURFACETYPE_DONT_CARE;
141 break;
142 default:
143 throw tcu::InternalError("Unsupported surface type");
144 }
145
146 config->windowVisibility = parseWindowVisibility(cmdLine);
147
148 if (cmdLine.getSurfaceWidth() > 0)
149 config->width = cmdLine.getSurfaceWidth();
150
151 if (cmdLine.getSurfaceHeight() > 0)
152 config->height = cmdLine.getSurfaceHeight();
153
154 if (cmdLine.getGLConfigName() != DE_NULL)
155 parseConfigBitsFromName(config, cmdLine.getGLConfigName());
156
157 if (cmdLine.getGLConfigId() >= 0)
158 config->id = cmdLine.getGLConfigId();
159 }
160
parseWindowVisibility(const tcu::CommandLine & cmdLine)161 RenderConfig::Visibility parseWindowVisibility(const tcu::CommandLine &cmdLine)
162 {
163 switch (cmdLine.getVisibility())
164 {
165 case tcu::WINDOWVISIBILITY_HIDDEN:
166 return RenderConfig::VISIBILITY_HIDDEN;
167 case tcu::WINDOWVISIBILITY_WINDOWED:
168 return RenderConfig::VISIBILITY_VISIBLE;
169 case tcu::WINDOWVISIBILITY_FULLSCREEN:
170 return RenderConfig::VISIBILITY_FULLSCREEN;
171 default:
172 throw tcu::InternalError("Unsupported window visibility");
173 }
174 }
175
fromEGLComponentType(int eglComponentType)176 RenderConfig::ComponentType fromEGLComponentType(int eglComponentType)
177 {
178 switch (eglComponentType)
179 {
180 case EGL_NONE:
181 return glu::RenderConfig::COMPONENT_TYPE_DONT_CARE;
182 case EGL_DONT_CARE:
183 return glu::RenderConfig::COMPONENT_TYPE_DONT_CARE;
184 case EGL_COLOR_COMPONENT_TYPE_FIXED_EXT:
185 return glu::RenderConfig::COMPONENT_TYPE_FIXED;
186 case EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT:
187 return glu::RenderConfig::COMPONENT_TYPE_FLOAT;
188 default:
189 throw tcu::InternalError("Unsupported color component type");
190 }
191 }
192
toEGLComponentType(RenderConfig::ComponentType gluComponentType)193 int toEGLComponentType(RenderConfig::ComponentType gluComponentType)
194 {
195 switch (gluComponentType)
196 {
197 case glu::RenderConfig::COMPONENT_TYPE_DONT_CARE:
198 return EGL_DONT_CARE;
199 case glu::RenderConfig::COMPONENT_TYPE_FIXED:
200 return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
201 case glu::RenderConfig::COMPONENT_TYPE_FLOAT:
202 return EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
203 default:
204 throw tcu::InternalError("Unsupported color component type");
205 }
206 }
207
208 } // namespace glu
209