Home | History | Annotate | Download | only in opengl
      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 
     33 std::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 
     52 std::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 
     71 std::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 
     80 std::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 		case GL_DEPTH_STENCIL_TEXTURE_MODE:
    112 			return str << getTextureDepthStencilModeStr(valueStr.value);
    113 
    114 		default:
    115 			return str << tcu::toHex(valueStr.value);
    116 	}
    117 }
    118 
    119 } // detail
    120 
    121 detail::EnumPointerFmt getInvalidateAttachmentStr (const deUint32* attachments, int numAttachments)
    122 {
    123 	return detail::EnumPointerFmt(attachments, (deUint32)numAttachments, getInvalidateAttachmentName);
    124 }
    125 
    126 std::ostream& operator<< (std::ostream& str, ApiType apiType)
    127 {
    128 	str << "OpenGL ";
    129 
    130 	if (apiType.getProfile() == PROFILE_ES)
    131 		str << "ES ";
    132 
    133 	str << apiType.getMajorVersion() << "." << apiType.getMinorVersion();
    134 
    135 	if (apiType.getProfile() == PROFILE_CORE)
    136 		str << " core profile";
    137 	else if (apiType.getProfile() == PROFILE_COMPATIBILITY)
    138 		str << " compatibility profile";
    139 	else if (apiType.getProfile() != PROFILE_ES)
    140 		str << " (unknown profile)";
    141 
    142 	return str;
    143 }
    144 
    145 std::ostream& operator<< (std::ostream& str, ContextType contextType)
    146 {
    147 	str << contextType.getAPI();
    148 
    149 	if (contextType.getFlags() != ContextFlags(0))
    150 	{
    151 		static const struct
    152 		{
    153 			ContextFlags	flag;
    154 			const char*		desc;
    155 		} s_descs[] =
    156 		{
    157 			{ CONTEXT_DEBUG,				"debug"					},
    158 			{ CONTEXT_FORWARD_COMPATIBLE,	"forward-compatible"	},
    159 			{ CONTEXT_ROBUST,				"robust"				}
    160 		};
    161 		ContextFlags	flags	= contextType.getFlags();
    162 
    163 		str << " (";
    164 
    165 		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_descs) && flags != 0; ndx++)
    166 		{
    167 			if ((flags & s_descs[ndx].flag) != 0)
    168 			{
    169 				if (flags != contextType.getFlags())
    170 					str << ", ";
    171 
    172 				str << s_descs[ndx].desc;
    173 				flags = flags & ~s_descs[ndx].flag;
    174 			}
    175 		}
    176 
    177 		if (flags != 0)
    178 		{
    179 			// Unresolved
    180 			if (flags != contextType.getFlags())
    181 				str << ", ";
    182 			str << tcu::toHex(flags);
    183 		}
    184 
    185 		str << ")";
    186 	}
    187 
    188 	return str;
    189 }
    190 
    191 #include "gluStrUtil.inl"
    192 
    193 } // glu
    194