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