gluStrUtil.cpp revision 1f99d6991ce9a27d32ec0543d95646fe4e7bf001
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 value to string utilities.
22 *//*--------------------------------------------------------------------*/
23
24#include "gluStrUtil.hpp"
25#include "glwEnums.hpp"
26
27namespace glu
28{
29
30namespace detail
31{
32
33std::ostream& operator<< (std::ostream& str, const BooleanPointerFmt& fmt)
34{
35	if (fmt.value)
36	{
37		str << "{ ";
38		for (deUint32 ndx = 0; ndx < fmt.size; ndx++)
39		{
40			if (ndx != 0)
41				str << ", ";
42			str << getBooleanStr(fmt.value[ndx]);
43		}
44		str << " }";
45		return str;
46	}
47	else
48		return str << "(null)";
49}
50
51
52std::ostream& operator<< (std::ostream& str, const EnumPointerFmt& fmt)
53{
54	if (fmt.value)
55	{
56		str << "{ ";
57		for (deUint32 ndx = 0; ndx < fmt.size; ndx++)
58		{
59			if (ndx != 0)
60				str << ", ";
61			// use storage size (4) as print width for clarity
62			str << tcu::Format::Enum<int, 4>(fmt.getName, fmt.value[ndx]);
63		}
64		str << " }";
65		return str;
66	}
67	else
68		return str << "(null)";
69}
70
71std::ostream& operator<< (std::ostream& str, const TextureUnitStr& unitStr)
72{
73	int unitNdx = unitStr.texUnit - GL_TEXTURE0;
74	if (unitNdx >= 0)
75		return str << "GL_TEXTURE" << unitNdx;
76	else
77		return str << tcu::toHex(unitStr.texUnit);
78}
79
80std::ostream& operator<< (std::ostream& str, const TextureParameterValueStr& valueStr)
81{
82	switch (valueStr.param)
83	{
84		case GL_TEXTURE_WRAP_S:
85		case GL_TEXTURE_WRAP_T:
86		case GL_TEXTURE_WRAP_R:
87			return str << getTextureWrapModeStr(valueStr.value);
88
89		case GL_TEXTURE_BASE_LEVEL:
90		case GL_TEXTURE_MAX_LEVEL:
91		case GL_TEXTURE_MAX_LOD:
92		case GL_TEXTURE_MIN_LOD:
93			return str << valueStr.value;
94
95		case GL_TEXTURE_COMPARE_MODE:
96			return str << getTextureCompareModeStr(valueStr.value);
97
98		case GL_TEXTURE_COMPARE_FUNC:
99			return str << getCompareFuncStr(valueStr.value);
100
101		case GL_TEXTURE_SWIZZLE_R:
102		case GL_TEXTURE_SWIZZLE_G:
103		case GL_TEXTURE_SWIZZLE_B:
104		case GL_TEXTURE_SWIZZLE_A:
105			return str << getTextureSwizzleStr(valueStr.value);
106
107		case GL_TEXTURE_MIN_FILTER:
108		case GL_TEXTURE_MAG_FILTER:
109			return str << getTextureFilterStr(valueStr.value);
110
111		default:
112			return str << tcu::toHex(valueStr.value);
113	}
114}
115
116} // detail
117
118detail::EnumPointerFmt getInvalidateAttachmentStr (const deUint32* attachments, int numAttachments)
119{
120	return detail::EnumPointerFmt(attachments, (deUint32)numAttachments, getInvalidateAttachmentName);
121}
122
123std::ostream& operator<< (std::ostream& str, ApiType apiType)
124{
125	str << "OpenGL ";
126
127	if (apiType.getProfile() == PROFILE_ES)
128		str << "ES ";
129
130	str << apiType.getMajorVersion() << "." << apiType.getMinorVersion();
131
132	if (apiType.getProfile() == PROFILE_CORE)
133		str << " core profile";
134	else if (apiType.getProfile() == PROFILE_COMPATIBILITY)
135		str << " compatibility profile";
136	else if (apiType.getProfile() != PROFILE_ES)
137		str << " (unknown profile)";
138
139	return str;
140}
141
142std::ostream& operator<< (std::ostream& str, ContextType contextType)
143{
144	str << contextType.getAPI();
145
146	if (contextType.getFlags() != ContextFlags(0))
147	{
148		static const struct
149		{
150			ContextFlags	flag;
151			const char*		desc;
152		} s_descs[] =
153		{
154			{ CONTEXT_DEBUG,				"debug"					},
155			{ CONTEXT_FORWARD_COMPATIBLE,	"forward-compatible"	},
156			{ CONTEXT_ROBUST,				"robust"				}
157		};
158		ContextFlags	flags	= contextType.getFlags();
159
160		str << " (";
161
162		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_descs) && flags != 0; ndx++)
163		{
164			if ((flags & s_descs[ndx].flag) != 0)
165			{
166				if (flags != contextType.getFlags())
167					str << ", ";
168
169				str << s_descs[ndx].desc;
170				flags = flags & ~s_descs[ndx].flag;
171			}
172		}
173
174		if (flags != 0)
175		{
176			// Unresolved
177			if (flags != contextType.getFlags())
178				str << ", ";
179			str << tcu::toHex(flags);
180		}
181
182		str << ")";
183	}
184
185	return str;
186}
187
188#include "gluStrUtil.inl"
189
190} // glu
191