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