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