13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief OpenGL rendering configuration.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderConfig.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid parseConfigBitsFromName (RenderConfig* config, const char* renderCfgName)
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*	cfgName	= renderCfgName;
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(config->redBits		== RenderConfig::DONT_CARE	&&
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->greenBits		== RenderConfig::DONT_CARE	&&
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->blueBits		== RenderConfig::DONT_CARE	&&
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->alphaBits		== RenderConfig::DONT_CARE	&&
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->depthBits		== RenderConfig::DONT_CARE	&&
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->stencilBits	== RenderConfig::DONT_CARE	&&
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			  config->numSamples	== RenderConfig::DONT_CARE);
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			redBits;
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			greenBits;
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			blueBits;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			alphaBits;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} colorCfgs[] =
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgb888",		8, 8, 8, 0 },
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba8888",	8, 8, 8, 8 },
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgb565",		5, 6, 5, 0 },
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba4444",	4, 4, 4, 4 },
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "rgba5551",	5, 5, 5, 1 }
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(colorCfgs); ndx++)
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (deStringBeginsWith(cfgName, colorCfgs[ndx].name))
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->redBits		= colorCfgs[ndx].redBits;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->greenBits	= colorCfgs[ndx].greenBits;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->blueBits	= colorCfgs[ndx].blueBits;
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->alphaBits	= colorCfgs[ndx].alphaBits;
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cfgName	+= strlen(colorCfgs[ndx].name);
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			depthSize;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} depthCfgs[] =
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "d0",		0 },
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "d16",	16 },
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "d24",	24 },
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "d32",	32 }
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(depthCfgs); ndx++)
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (deStringBeginsWith(cfgName, depthCfgs[ndx].name))
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->depthBits = depthCfgs[ndx].depthSize;
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cfgName += strlen(depthCfgs[ndx].name);
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			stencilSize;
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} stencilCfgs[] =
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "s0",		 0 },
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "s8",		 8 },
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "s16",	16 },
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(stencilCfgs); ndx++)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (deStringBeginsWith(cfgName, stencilCfgs[ndx].name))
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->stencilBits = stencilCfgs[ndx].stencilSize;
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cfgName += strlen(stencilCfgs[ndx].name);
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*	name;
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		int			numSamples;
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} multiSampleCfgs[] =
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms0",	 0 },
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms16",	16 },
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms1",	 1 },
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms2",	 2 },
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms4",	 4 },
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "ms8",	 8 }
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(multiSampleCfgs); ndx++)
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (deStringBeginsWith(cfgName, multiSampleCfgs[ndx].name))
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			config->numSamples = multiSampleCfgs[ndx].numSamples;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			cfgName += strlen(multiSampleCfgs[ndx].name);
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			break;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cfgName[0] != 0)
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::InternalError(std::string("Invalid GL configuration: '") + renderCfgName + "'");
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid parseRenderConfig (RenderConfig* config, const tcu::CommandLine& cmdLine)
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (cmdLine.getSurfaceType())
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::SURFACETYPE_WINDOW:				config->surfaceType		= RenderConfig::SURFACETYPE_WINDOW;				break;
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::SURFACETYPE_OFFSCREEN_NATIVE:		config->surfaceType		= RenderConfig::SURFACETYPE_OFFSCREEN_NATIVE;	break;
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::SURFACETYPE_OFFSCREEN_GENERIC:	config->surfaceType		= RenderConfig::SURFACETYPE_OFFSCREEN_GENERIC;	break;
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::SURFACETYPE_FBO:					config->surfaceType		= RenderConfig::SURFACETYPE_DONT_CARE;			break;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::SURFACETYPE_LAST:					config->surfaceType		= RenderConfig::SURFACETYPE_DONT_CARE;			break;
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::InternalError("Unsupported surface type");
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	config->windowVisibility = parseWindowVisibility(cmdLine);
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cmdLine.getSurfaceWidth() > 0)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config->width = cmdLine.getSurfaceWidth();
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cmdLine.getSurfaceHeight() > 0)
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config->height = cmdLine.getSurfaceHeight();
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cmdLine.getGLConfigName() != DE_NULL)
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		parseConfigBitsFromName(config, cmdLine.getGLConfigName());
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (cmdLine.getGLConfigId() >= 0)
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		config->id = cmdLine.getGLConfigId();
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderConfig::Visibility parseWindowVisibility (const tcu::CommandLine& cmdLine)
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (cmdLine.getVisibility())
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_HIDDEN:		return RenderConfig::VISIBILITY_HIDDEN;
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_WINDOWED:	return RenderConfig::VISIBILITY_VISIBLE;
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_FULLSCREEN:	return RenderConfig::VISIBILITY_FULLSCREEN;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			throw tcu::InternalError("Unsupported window visibility");
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu
184