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 Texture format utilities.
     22  *//*--------------------------------------------------------------------*/
     23 
     24 #include "gluTextureUtil.hpp"
     25 #include "gluRenderContext.hpp"
     26 #include "gluContextInfo.hpp"
     27 #include "tcuTextureUtil.hpp"
     28 #include "tcuFormatUtil.hpp"
     29 #include "glwEnums.hpp"
     30 
     31 namespace glu
     32 {
     33 
     34 using std::string;
     35 
     36 /*--------------------------------------------------------------------*//*!
     37  * \brief Map tcu::TextureFormat to GL pixel transfer format.
     38  *
     39  * Maps generic texture format description to GL pixel transfer format.
     40  * If no mapping is found, throws tcu::InternalError.
     41  *
     42  * \param texFormat Generic texture format.
     43  * \return GL pixel transfer format.
     44  *//*--------------------------------------------------------------------*/
     45 TransferFormat getTransferFormat (tcu::TextureFormat texFormat)
     46 {
     47 	using tcu::TextureFormat;
     48 
     49 	deUint32	format	= GL_NONE;
     50 	deUint32	type	= GL_NONE;
     51 	bool		isInt	= false;
     52 
     53 	switch (texFormat.type)
     54 	{
     55 		case TextureFormat::SIGNED_INT8:
     56 		case TextureFormat::SIGNED_INT16:
     57 		case TextureFormat::SIGNED_INT32:
     58 		case TextureFormat::UNSIGNED_INT8:
     59 		case TextureFormat::UNSIGNED_INT16:
     60 		case TextureFormat::UNSIGNED_INT32:
     61 		case TextureFormat::UNSIGNED_INT_1010102_REV:
     62 			isInt = true;
     63 			break;
     64 
     65 		default:
     66 			isInt = false;
     67 			break;
     68 	}
     69 
     70 	switch (texFormat.order)
     71 	{
     72 		case TextureFormat::A:		format = GL_ALPHA;								break;
     73 		case TextureFormat::L:		format = GL_LUMINANCE;							break;
     74 		case TextureFormat::LA:		format = GL_LUMINANCE_ALPHA;					break;
     75 		case TextureFormat::R:		format = isInt ? GL_RED_INTEGER		: GL_RED;	break;
     76 		case TextureFormat::RG:		format = isInt ? GL_RG_INTEGER		: GL_RG;	break;
     77 		case TextureFormat::RGB:	format = isInt ? GL_RGB_INTEGER		: GL_RGB;	break;
     78 		case TextureFormat::RGBA:	format = isInt ? GL_RGBA_INTEGER	: GL_RGBA;	break;
     79 		case TextureFormat::sRGB:	format = GL_RGB;								break;
     80 		case TextureFormat::sRGBA:	format = GL_RGBA;								break;
     81 		case TextureFormat::D:		format = GL_DEPTH_COMPONENT;					break;
     82 		case TextureFormat::DS:		format = GL_DEPTH_STENCIL;						break;
     83 		case TextureFormat::S:		format = GL_STENCIL_INDEX;						break;
     84 
     85 		default:
     86 			DE_ASSERT(false);
     87 	}
     88 
     89 	switch (texFormat.type)
     90 	{
     91 		case TextureFormat::SNORM_INT8:						type = GL_BYTE;								break;
     92 		case TextureFormat::SNORM_INT16:					type = GL_SHORT;							break;
     93 		case TextureFormat::UNORM_INT8:						type = GL_UNSIGNED_BYTE;					break;
     94 		case TextureFormat::UNORM_INT16:					type = GL_UNSIGNED_SHORT;					break;
     95 		case TextureFormat::UNORM_SHORT_565:				type = GL_UNSIGNED_SHORT_5_6_5;				break;
     96 		case TextureFormat::UNORM_SHORT_4444:				type = GL_UNSIGNED_SHORT_4_4_4_4;			break;
     97 		case TextureFormat::UNORM_SHORT_5551:				type = GL_UNSIGNED_SHORT_5_5_5_1;			break;
     98 		case TextureFormat::SIGNED_INT8:					type = GL_BYTE;								break;
     99 		case TextureFormat::SIGNED_INT16:					type = GL_SHORT;							break;
    100 		case TextureFormat::SIGNED_INT32:					type = GL_INT;								break;
    101 		case TextureFormat::UNSIGNED_INT8:					type = GL_UNSIGNED_BYTE;					break;
    102 		case TextureFormat::UNSIGNED_INT16:					type = GL_UNSIGNED_SHORT;					break;
    103 		case TextureFormat::UNSIGNED_INT32:					type = GL_UNSIGNED_INT;						break;
    104 		case TextureFormat::FLOAT:							type = GL_FLOAT;							break;
    105 		case TextureFormat::UNORM_INT_101010:				type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
    106 		case TextureFormat::UNORM_INT_1010102_REV:			type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
    107 		case TextureFormat::UNSIGNED_INT_1010102_REV:		type = GL_UNSIGNED_INT_2_10_10_10_REV;		break;
    108 		case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:	type = GL_UNSIGNED_INT_10F_11F_11F_REV;		break;
    109 		case TextureFormat::UNSIGNED_INT_999_E5_REV:		type = GL_UNSIGNED_INT_5_9_9_9_REV;			break;
    110 		case TextureFormat::HALF_FLOAT:						type = GL_HALF_FLOAT;						break;
    111 		case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:	type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;	break;
    112 		case TextureFormat::UNSIGNED_INT_24_8:				type = texFormat.order == TextureFormat::D
    113 																 ? GL_UNSIGNED_INT
    114 																 : GL_UNSIGNED_INT_24_8;				break;
    115 
    116 		default:
    117 			throw tcu::InternalError("Can't map texture format to GL transfer format");
    118 	}
    119 
    120 	return TransferFormat(format, type);
    121 }
    122 
    123 /*--------------------------------------------------------------------*//*!
    124  * \brief Map tcu::TextureFormat to GL internal sized format.
    125  *
    126  * Maps generic texture format description to GL internal format.
    127  * If no mapping is found, throws tcu::InternalError.
    128  *
    129  * \param texFormat Generic texture format.
    130  * \return GL sized internal format.
    131  *//*--------------------------------------------------------------------*/
    132 deUint32 getInternalFormat (tcu::TextureFormat texFormat)
    133 {
    134 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
    135 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
    136 
    137 #define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
    138 #define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
    139 
    140 	switch (PACK_FMT(texFormat.order, texFormat.type))
    141 	{
    142 		case FMT_CASE(RGBA,		UNORM_SHORT_5551):				return GL_RGB5_A1;
    143 		case FMT_CASE(RGBA,		UNORM_SHORT_4444):				return GL_RGBA4;
    144 		case FMT_CASE(RGB,		UNORM_SHORT_565):				return GL_RGB565;
    145 		case FMT_CASE(D,		UNORM_INT16):					return GL_DEPTH_COMPONENT16;
    146 		case FMT_CASE(S,		UNSIGNED_INT8):					return GL_STENCIL_INDEX8;
    147 
    148 		case FMT_CASE(RGBA,		FLOAT):							return GL_RGBA32F;
    149 		case FMT_CASE(RGBA,		SIGNED_INT32):					return GL_RGBA32I;
    150 		case FMT_CASE(RGBA,		UNSIGNED_INT32):				return GL_RGBA32UI;
    151 		case FMT_CASE(RGBA,		UNORM_INT16):					return GL_RGBA16;
    152 		case FMT_CASE(RGBA,		SNORM_INT16):					return GL_RGBA16_SNORM;
    153 		case FMT_CASE(RGBA,		HALF_FLOAT):					return GL_RGBA16F;
    154 		case FMT_CASE(RGBA,		SIGNED_INT16):					return GL_RGBA16I;
    155 		case FMT_CASE(RGBA,		UNSIGNED_INT16):				return GL_RGBA16UI;
    156 		case FMT_CASE(RGBA,		UNORM_INT8):					return GL_RGBA8;
    157 		case FMT_CASE(RGBA,		SIGNED_INT8):					return GL_RGBA8I;
    158 		case FMT_CASE(RGBA,		UNSIGNED_INT8):					return GL_RGBA8UI;
    159 		case FMT_CASE(sRGBA,	UNORM_INT8):					return GL_SRGB8_ALPHA8;
    160 		case FMT_CASE(RGBA,		UNORM_INT_1010102_REV):			return GL_RGB10_A2;
    161 		case FMT_CASE(RGBA,		UNSIGNED_INT_1010102_REV):		return GL_RGB10_A2UI;
    162 		case FMT_CASE(RGBA,		SNORM_INT8):					return GL_RGBA8_SNORM;
    163 
    164 		case FMT_CASE(RGB,		UNORM_INT8):					return GL_RGB8;
    165 		case FMT_CASE(RGB,		UNSIGNED_INT_11F_11F_10F_REV):	return GL_R11F_G11F_B10F;
    166 		case FMT_CASE(RGB,		FLOAT):							return GL_RGB32F;
    167 		case FMT_CASE(RGB,		SIGNED_INT32):					return GL_RGB32I;
    168 		case FMT_CASE(RGB,		UNSIGNED_INT32):				return GL_RGB32UI;
    169 		case FMT_CASE(RGB,		UNORM_INT16):					return GL_RGB16;
    170 		case FMT_CASE(RGB,		SNORM_INT16):					return GL_RGB16_SNORM;
    171 		case FMT_CASE(RGB,		HALF_FLOAT):					return GL_RGB16F;
    172 		case FMT_CASE(RGB,		SIGNED_INT16):					return GL_RGB16I;
    173 		case FMT_CASE(RGB,		UNSIGNED_INT16):				return GL_RGB16UI;
    174 		case FMT_CASE(RGB,		SNORM_INT8):					return GL_RGB8_SNORM;
    175 		case FMT_CASE(RGB,		SIGNED_INT8):					return GL_RGB8I;
    176 		case FMT_CASE(RGB,		UNSIGNED_INT8):					return GL_RGB8UI;
    177 		case FMT_CASE(sRGB,		UNORM_INT8):					return GL_SRGB8;
    178 		case FMT_CASE(RGB,		UNSIGNED_INT_999_E5_REV):		return GL_RGB9_E5;
    179 		case FMT_CASE(RGB,		UNORM_INT_1010102_REV):			return GL_RGB10;
    180 
    181 		case FMT_CASE(RG,		FLOAT):							return GL_RG32F;
    182 		case FMT_CASE(RG,		SIGNED_INT32):					return GL_RG32I;
    183 		case FMT_CASE(RG,		UNSIGNED_INT32):				return GL_RG32UI;
    184 		case FMT_CASE(RG,		UNORM_INT16):					return GL_RG16;
    185 		case FMT_CASE(RG,		SNORM_INT16):					return GL_RG16_SNORM;
    186 		case FMT_CASE(RG,		HALF_FLOAT):					return GL_RG16F;
    187 		case FMT_CASE(RG,		SIGNED_INT16):					return GL_RG16I;
    188 		case FMT_CASE(RG,		UNSIGNED_INT16):				return GL_RG16UI;
    189 		case FMT_CASE(RG,		UNORM_INT8):					return GL_RG8;
    190 		case FMT_CASE(RG,		SIGNED_INT8):					return GL_RG8I;
    191 		case FMT_CASE(RG,		UNSIGNED_INT8):					return GL_RG8UI;
    192 		case FMT_CASE(RG,		SNORM_INT8):					return GL_RG8_SNORM;
    193 
    194 		case FMT_CASE(R,		FLOAT):							return GL_R32F;
    195 		case FMT_CASE(R,		SIGNED_INT32):					return GL_R32I;
    196 		case FMT_CASE(R,		UNSIGNED_INT32):				return GL_R32UI;
    197 		case FMT_CASE(R,		UNORM_INT16):					return GL_R16;
    198 		case FMT_CASE(R,		SNORM_INT16):					return GL_R16_SNORM;
    199 		case FMT_CASE(R,		HALF_FLOAT):					return GL_R16F;
    200 		case FMT_CASE(R,		SIGNED_INT16):					return GL_R16I;
    201 		case FMT_CASE(R,		UNSIGNED_INT16):				return GL_R16UI;
    202 		case FMT_CASE(R,		UNORM_INT8):					return GL_R8;
    203 		case FMT_CASE(R,		SIGNED_INT8):					return GL_R8I;
    204 		case FMT_CASE(R,		UNSIGNED_INT8):					return GL_R8UI;
    205 		case FMT_CASE(R,		SNORM_INT8):					return GL_R8_SNORM;
    206 
    207 		case FMT_CASE(D,		FLOAT):							return GL_DEPTH_COMPONENT32F;
    208 		case FMT_CASE(D,		UNSIGNED_INT_24_8):				return GL_DEPTH_COMPONENT24;
    209 		case FMT_CASE(D,		UNSIGNED_INT32):				return GL_DEPTH_COMPONENT32;
    210 		case FMT_CASE(DS,		FLOAT_UNSIGNED_INT_24_8_REV):	return GL_DEPTH32F_STENCIL8;
    211 		case FMT_CASE(DS,		UNSIGNED_INT_24_8):				return GL_DEPTH24_STENCIL8;
    212 
    213 		default:
    214 			throw tcu::InternalError("Can't map texture format to GL internal format");
    215 	}
    216 }
    217 
    218 /*--------------------------------------------------------------------*//*!
    219  * \brief Map generic compressed format to GL compressed format enum.
    220  *
    221  * Maps generic compressed format to GL compressed format enum value.
    222  * If no mapping is found, throws tcu::InternalError.
    223  *
    224  * \param format Generic compressed format.
    225  * \return GL compressed texture format.
    226  *//*--------------------------------------------------------------------*/
    227 deUint32 getGLFormat (tcu::CompressedTexture::Format format)
    228 {
    229 	switch (format)
    230 	{
    231 		case tcu::CompressedTexture::ETC1_RGB8:							return GL_ETC1_RGB8_OES;
    232 		case tcu::CompressedTexture::EAC_R11:							return GL_COMPRESSED_R11_EAC;
    233 		case tcu::CompressedTexture::EAC_SIGNED_R11:					return GL_COMPRESSED_SIGNED_R11_EAC;
    234 		case tcu::CompressedTexture::EAC_RG11:							return GL_COMPRESSED_RG11_EAC;
    235 		case tcu::CompressedTexture::EAC_SIGNED_RG11:					return GL_COMPRESSED_SIGNED_RG11_EAC;
    236 		case tcu::CompressedTexture::ETC2_RGB8:							return GL_COMPRESSED_RGB8_ETC2;
    237 		case tcu::CompressedTexture::ETC2_SRGB8:						return GL_COMPRESSED_SRGB8_ETC2;
    238 		case tcu::CompressedTexture::ETC2_RGB8_PUNCHTHROUGH_ALPHA1:		return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
    239 		case tcu::CompressedTexture::ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:	return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
    240 		case tcu::CompressedTexture::ETC2_EAC_RGBA8:					return GL_COMPRESSED_RGBA8_ETC2_EAC;
    241 		case tcu::CompressedTexture::ETC2_EAC_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
    242 
    243 		case tcu::CompressedTexture::ASTC_4x4_RGBA:						return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
    244 		case tcu::CompressedTexture::ASTC_5x4_RGBA:						return GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
    245 		case tcu::CompressedTexture::ASTC_5x5_RGBA:						return GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
    246 		case tcu::CompressedTexture::ASTC_6x5_RGBA:						return GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
    247 		case tcu::CompressedTexture::ASTC_6x6_RGBA:						return GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
    248 		case tcu::CompressedTexture::ASTC_8x5_RGBA:						return GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
    249 		case tcu::CompressedTexture::ASTC_8x6_RGBA:						return GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
    250 		case tcu::CompressedTexture::ASTC_8x8_RGBA:						return GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
    251 		case tcu::CompressedTexture::ASTC_10x5_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
    252 		case tcu::CompressedTexture::ASTC_10x6_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
    253 		case tcu::CompressedTexture::ASTC_10x8_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
    254 		case tcu::CompressedTexture::ASTC_10x10_RGBA:					return GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
    255 		case tcu::CompressedTexture::ASTC_12x10_RGBA:					return GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
    256 		case tcu::CompressedTexture::ASTC_12x12_RGBA:					return GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
    257 		case tcu::CompressedTexture::ASTC_4x4_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
    258 		case tcu::CompressedTexture::ASTC_5x4_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
    259 		case tcu::CompressedTexture::ASTC_5x5_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
    260 		case tcu::CompressedTexture::ASTC_6x5_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
    261 		case tcu::CompressedTexture::ASTC_6x6_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
    262 		case tcu::CompressedTexture::ASTC_8x5_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
    263 		case tcu::CompressedTexture::ASTC_8x6_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
    264 		case tcu::CompressedTexture::ASTC_8x8_SRGB8_ALPHA8:				return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
    265 		case tcu::CompressedTexture::ASTC_10x5_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
    266 		case tcu::CompressedTexture::ASTC_10x6_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
    267 		case tcu::CompressedTexture::ASTC_10x8_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
    268 		case tcu::CompressedTexture::ASTC_10x10_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
    269 		case tcu::CompressedTexture::ASTC_12x10_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
    270 		case tcu::CompressedTexture::ASTC_12x12_SRGB8_ALPHA8:			return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
    271 
    272 		default:
    273 			throw tcu::InternalError("Can't map compressed format to GL format");
    274 	}
    275 }
    276 
    277 static tcu::TextureFormat::ChannelType mapGLChannelType (deUint32 dataType, bool normalized)
    278 {
    279 	// \note Normalized bit is ignored where it doesn't apply.
    280 	using tcu::TextureFormat;
    281 
    282 	switch (dataType)
    283 	{
    284 		case GL_UNSIGNED_BYTE:					return normalized ? TextureFormat::UNORM_INT8	: TextureFormat::UNSIGNED_INT8;
    285 		case GL_BYTE:							return normalized ? TextureFormat::SNORM_INT8	: TextureFormat::SIGNED_INT8;
    286 		case GL_UNSIGNED_SHORT:					return normalized ? TextureFormat::UNORM_INT16	: TextureFormat::UNSIGNED_INT16;
    287 		case GL_SHORT:							return normalized ? TextureFormat::SNORM_INT16	: TextureFormat::SIGNED_INT16;
    288 		case GL_UNSIGNED_INT:					return normalized ? TextureFormat::UNORM_INT32	: TextureFormat::UNSIGNED_INT32;
    289 		case GL_INT:							return normalized ? TextureFormat::SNORM_INT32	: TextureFormat::SIGNED_INT32;
    290 		case GL_FLOAT:							return TextureFormat::FLOAT;
    291 		case GL_UNSIGNED_SHORT_4_4_4_4:			return TextureFormat::UNORM_SHORT_4444;
    292 		case GL_UNSIGNED_SHORT_5_5_5_1:			return TextureFormat::UNORM_SHORT_5551;
    293 		case GL_UNSIGNED_SHORT_5_6_5:			return TextureFormat::UNORM_SHORT_565;
    294 		case GL_HALF_FLOAT:						return TextureFormat::HALF_FLOAT;
    295 		case GL_UNSIGNED_INT_2_10_10_10_REV:	return normalized ? TextureFormat::UNORM_INT_1010102_REV : TextureFormat::UNSIGNED_INT_1010102_REV;
    296 		case GL_UNSIGNED_INT_10F_11F_11F_REV:	return TextureFormat::UNSIGNED_INT_11F_11F_10F_REV;
    297 		case GL_UNSIGNED_INT_24_8:				return TextureFormat::UNSIGNED_INT_24_8;
    298 		case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:	return TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV;
    299 		case GL_UNSIGNED_INT_5_9_9_9_REV:		return TextureFormat::UNSIGNED_INT_999_E5_REV;
    300 
    301 		default:
    302 			DE_ASSERT(false);
    303 			return TextureFormat::CHANNELTYPE_LAST;
    304 	}
    305 }
    306 
    307 /*--------------------------------------------------------------------*//*!
    308  * \brief Map GL pixel transfer format to tcu::TextureFormat.
    309  *
    310  * If no mapping is found, throws tcu::InternalError.
    311  *
    312  * \param format	GL pixel format.
    313  * \param dataType	GL data type.
    314  * \return Generic texture format.
    315  *//*--------------------------------------------------------------------*/
    316 tcu::TextureFormat mapGLTransferFormat (deUint32 format, deUint32 dataType)
    317 {
    318 	using tcu::TextureFormat;
    319 	switch (format)
    320 	{
    321 		case GL_ALPHA:				return TextureFormat(TextureFormat::A,		mapGLChannelType(dataType, true));
    322 		case GL_LUMINANCE:			return TextureFormat(TextureFormat::L,		mapGLChannelType(dataType, true));
    323 		case GL_LUMINANCE_ALPHA:	return TextureFormat(TextureFormat::LA,		mapGLChannelType(dataType, true));
    324 		case GL_RGB:				return TextureFormat(TextureFormat::RGB,	mapGLChannelType(dataType, true));
    325 		case GL_RGBA:				return TextureFormat(TextureFormat::RGBA,	mapGLChannelType(dataType, true));
    326 		case GL_BGRA:				return TextureFormat(TextureFormat::BGRA,	mapGLChannelType(dataType, true));
    327 		case GL_RG:					return TextureFormat(TextureFormat::RG,		mapGLChannelType(dataType, true));
    328 		case GL_RED:				return TextureFormat(TextureFormat::R,		mapGLChannelType(dataType, true));
    329 		case GL_RGBA_INTEGER:		return TextureFormat(TextureFormat::RGBA,	mapGLChannelType(dataType, false));
    330 		case GL_RGB_INTEGER:		return TextureFormat(TextureFormat::RGB,	mapGLChannelType(dataType, false));
    331 		case GL_RG_INTEGER:			return TextureFormat(TextureFormat::RG,		mapGLChannelType(dataType, false));
    332 		case GL_RED_INTEGER:		return TextureFormat(TextureFormat::R,		mapGLChannelType(dataType, false));
    333 
    334 		case GL_DEPTH_COMPONENT:	return TextureFormat(TextureFormat::D,		mapGLChannelType(dataType, true));
    335 		case GL_DEPTH_STENCIL:		return TextureFormat(TextureFormat::DS,		mapGLChannelType(dataType, true));
    336 
    337 		default:
    338 			throw tcu::InternalError(string("Can't map GL pixel format (") + tcu::toHex(format).toString() + ", " + tcu::toHex(dataType).toString() + ") to texture format");
    339 	}
    340 }
    341 
    342 /*--------------------------------------------------------------------*//*!
    343  * \brief Map GL internal texture format to tcu::TextureFormat.
    344  *
    345  * If no mapping is found, throws tcu::InternalError.
    346  *
    347  * \param internalFormat Sized internal format.
    348  * \return Generic texture format.
    349  *//*--------------------------------------------------------------------*/
    350 tcu::TextureFormat mapGLInternalFormat (deUint32 internalFormat)
    351 {
    352 	using tcu::TextureFormat;
    353 	switch (internalFormat)
    354 	{
    355 		case GL_RGB5_A1:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_5551);
    356 		case GL_RGBA4:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_SHORT_4444);
    357 		case GL_RGB565:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_SHORT_565);
    358 		case GL_DEPTH_COMPONENT16:	return TextureFormat(TextureFormat::D,		TextureFormat::UNORM_INT16);
    359 		case GL_STENCIL_INDEX8:		return TextureFormat(TextureFormat::S,		TextureFormat::UNSIGNED_INT8);
    360 
    361 		case GL_RGBA32F:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::FLOAT);
    362 		case GL_RGBA32I:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT32);
    363 		case GL_RGBA32UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT32);
    364 		case GL_RGBA16:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT16);
    365 		case GL_RGBA16_SNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT16);
    366 		case GL_RGBA16F:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::HALF_FLOAT);
    367 		case GL_RGBA16I:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT16);
    368 		case GL_RGBA16UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT16);
    369 		case GL_RGBA8:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT8);
    370 		case GL_RGBA8I:				return TextureFormat(TextureFormat::RGBA,	TextureFormat::SIGNED_INT8);
    371 		case GL_RGBA8UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT8);
    372 		case GL_SRGB8_ALPHA8:		return TextureFormat(TextureFormat::sRGBA,	TextureFormat::UNORM_INT8);
    373 		case GL_RGB10_A2:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNORM_INT_1010102_REV);
    374 		case GL_RGB10_A2UI:			return TextureFormat(TextureFormat::RGBA,	TextureFormat::UNSIGNED_INT_1010102_REV);
    375 		case GL_RGBA8_SNORM:		return TextureFormat(TextureFormat::RGBA,	TextureFormat::SNORM_INT8);
    376 
    377 		case GL_RGB8:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT8);
    378 		case GL_R11F_G11F_B10F:		return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
    379 		case GL_RGB32F:				return TextureFormat(TextureFormat::RGB,	TextureFormat::FLOAT);
    380 		case GL_RGB32I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT32);
    381 		case GL_RGB32UI:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT32);
    382 		case GL_RGB16:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT16);
    383 		case GL_RGB16_SNORM:		return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT16);
    384 		case GL_RGB16F:				return TextureFormat(TextureFormat::RGB,	TextureFormat::HALF_FLOAT);
    385 		case GL_RGB16I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT16);
    386 		case GL_RGB16UI:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT16);
    387 		case GL_RGB8_SNORM:			return TextureFormat(TextureFormat::RGB,	TextureFormat::SNORM_INT8);
    388 		case GL_RGB8I:				return TextureFormat(TextureFormat::RGB,	TextureFormat::SIGNED_INT8);
    389 		case GL_RGB8UI:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT8);
    390 		case GL_SRGB8:				return TextureFormat(TextureFormat::sRGB,	TextureFormat::UNORM_INT8);
    391 		case GL_RGB9_E5:			return TextureFormat(TextureFormat::RGB,	TextureFormat::UNSIGNED_INT_999_E5_REV);
    392 		case GL_RGB10:				return TextureFormat(TextureFormat::RGB,	TextureFormat::UNORM_INT_1010102_REV);
    393 
    394 		case GL_RG32F:				return TextureFormat(TextureFormat::RG,		TextureFormat::FLOAT);
    395 		case GL_RG32I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT32);
    396 		case GL_RG32UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT32);
    397 		case GL_RG16:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT16);
    398 		case GL_RG16_SNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT16);
    399 		case GL_RG16F:				return TextureFormat(TextureFormat::RG,		TextureFormat::HALF_FLOAT);
    400 		case GL_RG16I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT16);
    401 		case GL_RG16UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT16);
    402 		case GL_RG8:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNORM_INT8);
    403 		case GL_RG8I:				return TextureFormat(TextureFormat::RG,		TextureFormat::SIGNED_INT8);
    404 		case GL_RG8UI:				return TextureFormat(TextureFormat::RG,		TextureFormat::UNSIGNED_INT8);
    405 		case GL_RG8_SNORM:			return TextureFormat(TextureFormat::RG,		TextureFormat::SNORM_INT8);
    406 
    407 		case GL_R32F:				return TextureFormat(TextureFormat::R,		TextureFormat::FLOAT);
    408 		case GL_R32I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT32);
    409 		case GL_R32UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT32);
    410 		case GL_R16:				return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT16);
    411 		case GL_R16_SNORM:			return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT16);
    412 		case GL_R16F:				return TextureFormat(TextureFormat::R,		TextureFormat::HALF_FLOAT);
    413 		case GL_R16I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT16);
    414 		case GL_R16UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT16);
    415 		case GL_R8:					return TextureFormat(TextureFormat::R,		TextureFormat::UNORM_INT8);
    416 		case GL_R8I:				return TextureFormat(TextureFormat::R,		TextureFormat::SIGNED_INT8);
    417 		case GL_R8UI:				return TextureFormat(TextureFormat::R,		TextureFormat::UNSIGNED_INT8);
    418 		case GL_R8_SNORM:			return TextureFormat(TextureFormat::R,		TextureFormat::SNORM_INT8);
    419 
    420 		case GL_DEPTH_COMPONENT32F:	return TextureFormat(TextureFormat::D,		TextureFormat::FLOAT);
    421 		case GL_DEPTH_COMPONENT24:	return TextureFormat(TextureFormat::D,		TextureFormat::UNSIGNED_INT_24_8);
    422 		case GL_DEPTH_COMPONENT32:	return TextureFormat(TextureFormat::D,		TextureFormat::UNSIGNED_INT32);
    423 		case GL_DEPTH32F_STENCIL8:	return TextureFormat(TextureFormat::DS,		TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
    424 		case GL_DEPTH24_STENCIL8:	return TextureFormat(TextureFormat::DS,		TextureFormat::UNSIGNED_INT_24_8);
    425 
    426 		default:
    427 			throw tcu::InternalError(string("Can't map GL sized internal format (") + tcu::toHex(internalFormat).toString() + ") to texture format");
    428 	}
    429 }
    430 
    431 bool isGLInternalColorFormatFilterable (deUint32 format)
    432 {
    433 	switch (format)
    434 	{
    435 		case GL_R8:
    436 		case GL_R8_SNORM:
    437 		case GL_RG8:
    438 		case GL_RG8_SNORM:
    439 		case GL_RGB8:
    440 		case GL_RGB8_SNORM:
    441 		case GL_RGB565:
    442 		case GL_RGBA4:
    443 		case GL_RGB5_A1:
    444 		case GL_RGBA8:
    445 		case GL_RGBA8_SNORM:
    446 		case GL_RGB10_A2:
    447 		case GL_SRGB8:
    448 		case GL_SRGB8_ALPHA8:
    449 		case GL_R16F:
    450 		case GL_RG16F:
    451 		case GL_RGB16F:
    452 		case GL_RGBA16F:
    453 		case GL_R11F_G11F_B10F:
    454 		case GL_RGB9_E5:
    455 			return true;
    456 
    457 		case GL_RGB10_A2UI:
    458 		case GL_R32F:
    459 		case GL_RG32F:
    460 		case GL_RGB32F:
    461 		case GL_RGBA32F:
    462 		case GL_R8I:
    463 		case GL_R8UI:
    464 		case GL_R16I:
    465 		case GL_R16UI:
    466 		case GL_R32I:
    467 		case GL_R32UI:
    468 		case GL_RG8I:
    469 		case GL_RG8UI:
    470 		case GL_RG16I:
    471 		case GL_RG16UI:
    472 		case GL_RG32I:
    473 		case GL_RG32UI:
    474 		case GL_RGB8I:
    475 		case GL_RGB8UI:
    476 		case GL_RGB16I:
    477 		case GL_RGB16UI:
    478 		case GL_RGB32I:
    479 		case GL_RGB32UI:
    480 		case GL_RGBA8I:
    481 		case GL_RGBA8UI:
    482 		case GL_RGBA16I:
    483 		case GL_RGBA16UI:
    484 		case GL_RGBA32I:
    485 		case GL_RGBA32UI:
    486 			return false;
    487 
    488 		default:
    489 			DE_ASSERT(false);
    490 			return false;
    491 	}
    492 }
    493 
    494 static inline tcu::Sampler::WrapMode mapGLWrapMode (deUint32 wrapMode)
    495 {
    496 	switch (wrapMode)
    497 	{
    498 		case GL_CLAMP_TO_EDGE:		return tcu::Sampler::CLAMP_TO_EDGE;
    499 		case GL_CLAMP_TO_BORDER:	return tcu::Sampler::CLAMP_TO_BORDER;
    500 		case GL_REPEAT:				return tcu::Sampler::REPEAT_GL;
    501 		case GL_MIRRORED_REPEAT:	return tcu::Sampler::MIRRORED_REPEAT_GL;
    502 		default:
    503 			throw tcu::InternalError("Can't map GL wrap mode " + tcu::toHex(wrapMode).toString());
    504 	}
    505 }
    506 
    507 static inline tcu::Sampler::FilterMode mapGLFilterMode (deUint32 filterMode)
    508 {
    509 	switch (filterMode)
    510 	{
    511 		case GL_NEAREST:				return tcu::Sampler::NEAREST;
    512 		case GL_LINEAR:					return tcu::Sampler::LINEAR;
    513 		case GL_NEAREST_MIPMAP_NEAREST:	return tcu::Sampler::NEAREST_MIPMAP_NEAREST;
    514 		case GL_NEAREST_MIPMAP_LINEAR:	return tcu::Sampler::NEAREST_MIPMAP_LINEAR;
    515 		case GL_LINEAR_MIPMAP_NEAREST:	return tcu::Sampler::LINEAR_MIPMAP_NEAREST;
    516 		case GL_LINEAR_MIPMAP_LINEAR:	return tcu::Sampler::LINEAR_MIPMAP_LINEAR;
    517 		default:
    518 			throw tcu::InternalError("Can't map GL filter mode" + tcu::toHex(filterMode).toString());
    519 	}
    520 }
    521 
    522 /*--------------------------------------------------------------------*//*!
    523  * \brief Map GL sampler parameters to tcu::Sampler.
    524  *
    525  * If no mapping is found, throws tcu::InternalError.
    526  *
    527  * \param wrapS		S-component wrap mode
    528  * \param minFilter	Minification filter mode
    529  * \param magFilter	Magnification filter mode
    530  * \return Sampler description.
    531  *//*--------------------------------------------------------------------*/
    532 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 minFilter, deUint32 magFilter)
    533 {
    534 	return mapGLSampler(wrapS, wrapS, wrapS, minFilter, magFilter);
    535 }
    536 
    537 
    538 /*--------------------------------------------------------------------*//*!
    539  * \brief Map GL sampler parameters to tcu::Sampler.
    540  *
    541  * If no mapping is found, throws tcu::InternalError.
    542  *
    543  * \param wrapS		S-component wrap mode
    544  * \param wrapT		T-component wrap mode
    545  * \param minFilter	Minification filter mode
    546  * \param magFilter	Magnification filter mode
    547  * \return Sampler description.
    548  *//*--------------------------------------------------------------------*/
    549 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter)
    550 {
    551 	return mapGLSampler(wrapS, wrapT, wrapS, minFilter, magFilter);
    552 }
    553 
    554 /*--------------------------------------------------------------------*//*!
    555  * \brief Map GL sampler parameters to tcu::Sampler.
    556  *
    557  * If no mapping is found, throws tcu::InternalError.
    558  *
    559  * \param wrapS		S-component wrap mode
    560  * \param wrapT		T-component wrap mode
    561  * \param wrapR		R-component wrap mode
    562  * \param minFilter	Minification filter mode
    563  * \param magFilter	Magnification filter mode
    564  * \return Sampler description.
    565  *//*--------------------------------------------------------------------*/
    566 tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 wrapR, deUint32 minFilter, deUint32 magFilter)
    567 {
    568 	return tcu::Sampler(mapGLWrapMode(wrapS), mapGLWrapMode(wrapT), mapGLWrapMode(wrapR),
    569 						mapGLFilterMode(minFilter), mapGLFilterMode(magFilter),
    570 						0.0f /* lod threshold */,
    571 						true /* normalized coords */,
    572 						tcu::Sampler::COMPAREMODE_NONE /* no compare */,
    573 						0 /* compare channel */,
    574 						tcu::Vec4(0.0f) /* border color, not used */);
    575 }
    576 
    577 /*--------------------------------------------------------------------*//*!
    578  * \brief Map GL compare function to tcu::Sampler::CompareMode.
    579  *
    580  * If no mapping is found, throws tcu::InternalError.
    581  *
    582  * \param mode GL compare mode
    583  * \return Compare mode
    584  *//*--------------------------------------------------------------------*/
    585 tcu::Sampler::CompareMode mapGLCompareFunc (deUint32 mode)
    586 {
    587 	switch (mode)
    588 	{
    589 		case GL_LESS:		return tcu::Sampler::COMPAREMODE_LESS;
    590 		case GL_LEQUAL:		return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL;
    591 		case GL_GREATER:	return tcu::Sampler::COMPAREMODE_GREATER;
    592 		case GL_GEQUAL:		return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL;
    593 		case GL_EQUAL:		return tcu::Sampler::COMPAREMODE_EQUAL;
    594 		case GL_NOTEQUAL:	return tcu::Sampler::COMPAREMODE_NOT_EQUAL;
    595 		case GL_ALWAYS:		return tcu::Sampler::COMPAREMODE_ALWAYS;
    596 		case GL_NEVER:		return tcu::Sampler::COMPAREMODE_NEVER;
    597 		default:
    598 			throw tcu::InternalError("Can't map GL compare mode " + tcu::toHex(mode).toString());
    599 	}
    600 }
    601 
    602 /*--------------------------------------------------------------------*//*!
    603  * \brief Get GL wrap mode.
    604  *
    605  * If no mapping is found, throws tcu::InternalError.
    606  *
    607  * \param wrapMode Wrap mode
    608  * \return GL wrap mode
    609  *//*--------------------------------------------------------------------*/
    610 deUint32 getGLWrapMode (tcu::Sampler::WrapMode wrapMode)
    611 {
    612 	DE_ASSERT(wrapMode != tcu::Sampler::WRAPMODE_LAST);
    613 	switch (wrapMode)
    614 	{
    615 		case tcu::Sampler::CLAMP_TO_EDGE:		return GL_CLAMP_TO_EDGE;
    616 		case tcu::Sampler::CLAMP_TO_BORDER:		return GL_CLAMP_TO_BORDER;
    617 		case tcu::Sampler::REPEAT_GL:			return GL_REPEAT;
    618 		case tcu::Sampler::MIRRORED_REPEAT_GL:	return GL_MIRRORED_REPEAT;
    619 		default:
    620 			throw tcu::InternalError("Can't map wrap mode");
    621 	}
    622 }
    623 
    624 /*--------------------------------------------------------------------*//*!
    625  * \brief Get GL filter mode.
    626  *
    627  * If no mapping is found, throws tcu::InternalError.
    628  *
    629  * \param filterMode Filter mode
    630  * \return GL filter mode
    631  *//*--------------------------------------------------------------------*/
    632 deUint32 getGLFilterMode (tcu::Sampler::FilterMode filterMode)
    633 {
    634 	DE_ASSERT(filterMode != tcu::Sampler::FILTERMODE_LAST);
    635 	switch (filterMode)
    636 	{
    637 		case tcu::Sampler::NEAREST:					return GL_NEAREST;
    638 		case tcu::Sampler::LINEAR:					return GL_LINEAR;
    639 		case tcu::Sampler::NEAREST_MIPMAP_NEAREST:	return GL_NEAREST_MIPMAP_NEAREST;
    640 		case tcu::Sampler::NEAREST_MIPMAP_LINEAR:	return GL_NEAREST_MIPMAP_LINEAR;
    641 		case tcu::Sampler::LINEAR_MIPMAP_NEAREST:	return GL_LINEAR_MIPMAP_NEAREST;
    642 		case tcu::Sampler::LINEAR_MIPMAP_LINEAR:	return GL_LINEAR_MIPMAP_LINEAR;
    643 		default:
    644 			throw tcu::InternalError("Can't map filter mode");
    645 	}
    646 }
    647 
    648 /*--------------------------------------------------------------------*//*!
    649  * \brief Get GL compare mode.
    650  *
    651  * If no mapping is found, throws tcu::InternalError.
    652  *
    653  * \param compareMode Compare mode
    654  * \return GL compare mode
    655  *//*--------------------------------------------------------------------*/
    656 deUint32 getGLCompareFunc (tcu::Sampler::CompareMode compareMode)
    657 {
    658 	DE_ASSERT(compareMode != tcu::Sampler::COMPAREMODE_NONE);
    659 	switch (compareMode)
    660 	{
    661 		case tcu::Sampler::COMPAREMODE_NONE:				return GL_NONE;
    662 		case tcu::Sampler::COMPAREMODE_LESS:				return GL_LESS;
    663 		case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL:		return GL_LEQUAL;
    664 		case tcu::Sampler::COMPAREMODE_GREATER:				return GL_GREATER;
    665 		case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL:	return GL_GEQUAL;
    666 		case tcu::Sampler::COMPAREMODE_EQUAL:				return GL_EQUAL;
    667 		case tcu::Sampler::COMPAREMODE_NOT_EQUAL:			return GL_NOTEQUAL;
    668 		case tcu::Sampler::COMPAREMODE_ALWAYS:				return GL_ALWAYS;
    669 		case tcu::Sampler::COMPAREMODE_NEVER:				return GL_NEVER;
    670 		default:
    671 			throw tcu::InternalError("Can't map compare mode");
    672 	}
    673 }
    674 
    675 /*--------------------------------------------------------------------*//*!
    676  * \brief Get GL cube face.
    677  *
    678  * If no mapping is found, throws tcu::InternalError.
    679  *
    680  * \param face Cube face
    681  * \return GL cube face
    682  *//*--------------------------------------------------------------------*/
    683 deUint32 getGLCubeFace (tcu::CubeFace face)
    684 {
    685 	DE_ASSERT(face != tcu::CUBEFACE_LAST);
    686 	switch (face)
    687 	{
    688 		case tcu::CUBEFACE_NEGATIVE_X:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
    689 		case tcu::CUBEFACE_POSITIVE_X:	return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
    690 		case tcu::CUBEFACE_NEGATIVE_Y:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
    691 		case tcu::CUBEFACE_POSITIVE_Y:	return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
    692 		case tcu::CUBEFACE_NEGATIVE_Z:	return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
    693 		case tcu::CUBEFACE_POSITIVE_Z:	return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
    694 		default:
    695 			throw tcu::InternalError("Can't map cube face");
    696 	}
    697 }
    698 
    699 /*--------------------------------------------------------------------*//*!
    700  * \brief Get GLSL sampler type for texture format.
    701  *
    702  * If no mapping is found, glu::TYPE_LAST is returned.
    703  *
    704  * \param format Texture format
    705  * \return GLSL 1D sampler type for format
    706  *//*--------------------------------------------------------------------*/
    707 DataType getSampler1DType (tcu::TextureFormat format)
    708 {
    709 	using tcu::TextureFormat;
    710 
    711 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    712 		return TYPE_SAMPLER_1D;
    713 
    714 	if (format.order == TextureFormat::S)
    715 		return TYPE_LAST;
    716 
    717 	switch (tcu::getTextureChannelClass(format.type))
    718 	{
    719 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    720 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    721 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    722 			return glu::TYPE_SAMPLER_1D;
    723 
    724 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    725 			return glu::TYPE_INT_SAMPLER_1D;
    726 
    727 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    728 			return glu::TYPE_UINT_SAMPLER_1D;
    729 
    730 		default:
    731 			return glu::TYPE_LAST;
    732 	}
    733 }
    734 
    735 /*--------------------------------------------------------------------*//*!
    736  * \brief Get GLSL sampler type for texture format.
    737  *
    738  * If no mapping is found, glu::TYPE_LAST is returned.
    739  *
    740  * \param format Texture format
    741  * \return GLSL 2D sampler type for format
    742  *//*--------------------------------------------------------------------*/
    743 DataType getSampler2DType (tcu::TextureFormat format)
    744 {
    745 	using tcu::TextureFormat;
    746 
    747 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    748 		return TYPE_SAMPLER_2D;
    749 
    750 	if (format.order == TextureFormat::S)
    751 		return TYPE_LAST;
    752 
    753 	switch (tcu::getTextureChannelClass(format.type))
    754 	{
    755 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    756 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    757 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    758 			return glu::TYPE_SAMPLER_2D;
    759 
    760 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    761 			return glu::TYPE_INT_SAMPLER_2D;
    762 
    763 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    764 			return glu::TYPE_UINT_SAMPLER_2D;
    765 
    766 		default:
    767 			return glu::TYPE_LAST;
    768 	}
    769 }
    770 
    771 /*--------------------------------------------------------------------*//*!
    772  * \brief Get GLSL sampler type for texture format.
    773  *
    774  * If no mapping is found, glu::TYPE_LAST is returned.
    775  *
    776  * \param format Texture format
    777  * \return GLSL cube map sampler type for format
    778  *//*--------------------------------------------------------------------*/
    779 DataType getSamplerCubeType (tcu::TextureFormat format)
    780 {
    781 	using tcu::TextureFormat;
    782 
    783 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    784 		return TYPE_SAMPLER_CUBE;
    785 
    786 	if (format.order == TextureFormat::S)
    787 		return TYPE_LAST;
    788 
    789 	switch (tcu::getTextureChannelClass(format.type))
    790 	{
    791 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    792 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    793 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    794 			return glu::TYPE_SAMPLER_CUBE;
    795 
    796 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    797 			return glu::TYPE_INT_SAMPLER_CUBE;
    798 
    799 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    800 			return glu::TYPE_UINT_SAMPLER_CUBE;
    801 
    802 		default:
    803 			return glu::TYPE_LAST;
    804 	}
    805 }
    806 
    807 /*--------------------------------------------------------------------*//*!
    808  * \brief Get GLSL sampler type for texture format.
    809  *
    810  * If no mapping is found, glu::TYPE_LAST is returned.
    811  *
    812  * \param format Texture format
    813  * \return GLSL 2D array sampler type for format
    814  *//*--------------------------------------------------------------------*/
    815 DataType getSampler2DArrayType (tcu::TextureFormat format)
    816 {
    817 	using tcu::TextureFormat;
    818 
    819 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    820 		return TYPE_SAMPLER_2D_ARRAY;
    821 
    822 	if (format.order == TextureFormat::S)
    823 		return TYPE_LAST;
    824 
    825 	switch (tcu::getTextureChannelClass(format.type))
    826 	{
    827 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    828 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    829 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    830 			return glu::TYPE_SAMPLER_2D_ARRAY;
    831 
    832 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    833 			return glu::TYPE_INT_SAMPLER_2D_ARRAY;
    834 
    835 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    836 			return glu::TYPE_UINT_SAMPLER_2D_ARRAY;
    837 
    838 		default:
    839 			return glu::TYPE_LAST;
    840 	}
    841 }
    842 
    843 /*--------------------------------------------------------------------*//*!
    844  * \brief Get GLSL sampler type for texture format.
    845  *
    846  * If no mapping is found, glu::TYPE_LAST is returned.
    847  *
    848  * \param format Texture format
    849  * \return GLSL 3D sampler type for format
    850  *//*--------------------------------------------------------------------*/
    851 DataType getSampler3DType (tcu::TextureFormat format)
    852 {
    853 	using tcu::TextureFormat;
    854 
    855 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    856 		return TYPE_SAMPLER_3D;
    857 
    858 	if (format.order == TextureFormat::S)
    859 		return TYPE_LAST;
    860 
    861 	switch (tcu::getTextureChannelClass(format.type))
    862 	{
    863 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    864 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    865 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    866 			return glu::TYPE_SAMPLER_3D;
    867 
    868 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    869 			return glu::TYPE_INT_SAMPLER_3D;
    870 
    871 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    872 			return glu::TYPE_UINT_SAMPLER_3D;
    873 
    874 		default:
    875 			return glu::TYPE_LAST;
    876 	}
    877 }
    878 
    879 /*--------------------------------------------------------------------*//*!
    880  * \brief Get GLSL sampler type for texture format.
    881  *
    882  * If no mapping is found, glu::TYPE_LAST is returned.
    883  *
    884  * \param format Texture format
    885  * \return GLSL cube map array sampler type for format
    886  *//*--------------------------------------------------------------------*/
    887 DataType getSamplerCubeArrayType (tcu::TextureFormat format)
    888 {
    889 	using tcu::TextureFormat;
    890 
    891 	if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
    892 		return TYPE_SAMPLER_CUBE_ARRAY;
    893 
    894 	if (format.order == TextureFormat::S)
    895 		return TYPE_LAST;
    896 
    897 	switch (tcu::getTextureChannelClass(format.type))
    898 	{
    899 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
    900 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
    901 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
    902 			return glu::TYPE_SAMPLER_CUBE_ARRAY;
    903 
    904 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
    905 			return glu::TYPE_INT_SAMPLER_CUBE_ARRAY;
    906 
    907 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
    908 			return glu::TYPE_UINT_SAMPLER_CUBE_ARRAY;
    909 
    910 		default:
    911 			return glu::TYPE_LAST;
    912 	}
    913 }
    914 
    915 enum RenderableType
    916 {
    917 	RENDERABLE_COLOR	= (1<<0),
    918 	RENDERABLE_DEPTH	= (1<<1),
    919 	RENDERABLE_STENCIL	= (1<<2)
    920 };
    921 
    922 static deUint32 getRenderableBitsES3 (const ContextInfo& contextInfo, deUint32 internalFormat)
    923 {
    924 	switch (internalFormat)
    925 	{
    926 		// Color-renderable formats
    927 		case GL_RGBA32I:
    928 		case GL_RGBA32UI:
    929 		case GL_RGBA16I:
    930 		case GL_RGBA16UI:
    931 		case GL_RGBA8:
    932 		case GL_RGBA8I:
    933 		case GL_RGBA8UI:
    934 		case GL_SRGB8_ALPHA8:
    935 		case GL_RGB10_A2:
    936 		case GL_RGB10_A2UI:
    937 		case GL_RGBA4:
    938 		case GL_RGB5_A1:
    939 		case GL_RGB8:
    940 		case GL_RGB565:
    941 		case GL_RG32I:
    942 		case GL_RG32UI:
    943 		case GL_RG16I:
    944 		case GL_RG16UI:
    945 		case GL_RG8:
    946 		case GL_RG8I:
    947 		case GL_RG8UI:
    948 		case GL_R32I:
    949 		case GL_R32UI:
    950 		case GL_R16I:
    951 		case GL_R16UI:
    952 		case GL_R8:
    953 		case GL_R8I:
    954 		case GL_R8UI:
    955 			return RENDERABLE_COLOR;
    956 
    957 		// GL_EXT_color_buffer_float
    958 		case GL_RGBA32F:
    959 		case GL_R11F_G11F_B10F:
    960 		case GL_RG32F:
    961 		case GL_R32F:
    962 			if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float"))
    963 				return RENDERABLE_COLOR;
    964 			else
    965 				return 0;
    966 
    967 		// GL_EXT_color_buffer_float / GL_EXT_color_buffer_half_float
    968 		case GL_RGBA16F:
    969 		case GL_RG16F:
    970 		case GL_R16F:
    971 			if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float") ||
    972 				contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float"))
    973 				return RENDERABLE_COLOR;
    974 			else
    975 				return 0;
    976 
    977 		// Depth formats
    978 		case GL_DEPTH_COMPONENT32F:
    979 		case GL_DEPTH_COMPONENT24:
    980 		case GL_DEPTH_COMPONENT16:
    981 			return RENDERABLE_DEPTH;
    982 
    983 		// Depth+stencil formats
    984 		case GL_DEPTH32F_STENCIL8:
    985 		case GL_DEPTH24_STENCIL8:
    986 			return RENDERABLE_DEPTH|RENDERABLE_STENCIL;
    987 
    988 		// Stencil formats
    989 		case GL_STENCIL_INDEX8:
    990 			return RENDERABLE_STENCIL;
    991 
    992 		default:
    993 			return 0;
    994 	}
    995 }
    996 
    997 /*--------------------------------------------------------------------*//*!
    998  * \brief Check if sized internal format is color-renderable.
    999  * \note Works currently only on ES3 context.
   1000  *//*--------------------------------------------------------------------*/
   1001 bool isSizedFormatColorRenderable (const RenderContext& renderCtx, const ContextInfo& contextInfo, deUint32 sizedFormat)
   1002 {
   1003 	deUint32 renderable = 0;
   1004 
   1005 	if (renderCtx.getType().getAPI() == ApiType::es(3,0))
   1006 		renderable = getRenderableBitsES3(contextInfo, sizedFormat);
   1007 	else
   1008 		throw tcu::InternalError("Context type not supported in query");
   1009 
   1010 	return (renderable & RENDERABLE_COLOR) != 0;
   1011 }
   1012 
   1013 } // glu
   1014