gluTextureUtil.cpp revision 238d2aee289b3bc19b059ddbfc9e83892be1d8a6
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 31namespace glu 32{ 33 34using 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 *//*--------------------------------------------------------------------*/ 45TransferFormat 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 *//*--------------------------------------------------------------------*/ 132deUint32 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 *//*--------------------------------------------------------------------*/ 227deUint32 getGLFormat (tcu::CompressedTexFormat format) 228{ 229 switch (format) 230 { 231 case tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8: return GL_ETC1_RGB8_OES; 232 case tcu::COMPRESSEDTEXFORMAT_EAC_R11: return GL_COMPRESSED_R11_EAC; 233 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11: return GL_COMPRESSED_SIGNED_R11_EAC; 234 case tcu::COMPRESSEDTEXFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC; 235 case tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11: return GL_COMPRESSED_SIGNED_RG11_EAC; 236 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8: return GL_COMPRESSED_RGB8_ETC2; 237 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8: return GL_COMPRESSED_SRGB8_ETC2; 238 case tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; 239 case tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; 240 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC; 241 case tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; 242 243 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; 244 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; 245 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; 246 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; 247 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; 248 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; 249 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; 250 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; 251 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; 252 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; 253 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; 254 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; 255 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; 256 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; 257 case tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; 258 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; 259 case tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; 260 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; 261 case tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; 262 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; 263 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; 264 case tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; 265 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; 266 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; 267 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; 268 case tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; 269 case tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; 270 case tcu::COMPRESSEDTEXFORMAT_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/*--------------------------------------------------------------------*//*! 278 * \brief Map compressed GL format to generic compressed format. 279 * 280 * Maps compressed GL format to generic compressed format. 281 * If no mapping is found, throws tcu::InternalError. 282 * 283 * \param GL compressed texture format. 284 * \return format Generic compressed format. 285 *//*--------------------------------------------------------------------*/ 286tcu::CompressedTexFormat mapGLCompressedTexFormat (deUint32 format) 287{ 288 switch (format) 289 { 290 case GL_ETC1_RGB8_OES: return tcu::COMPRESSEDTEXFORMAT_ETC1_RGB8; 291 case GL_COMPRESSED_R11_EAC: return tcu::COMPRESSEDTEXFORMAT_EAC_R11; 292 case GL_COMPRESSED_SIGNED_R11_EAC: return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_R11; 293 case GL_COMPRESSED_RG11_EAC: return tcu::COMPRESSEDTEXFORMAT_EAC_RG11; 294 case GL_COMPRESSED_SIGNED_RG11_EAC: return tcu::COMPRESSEDTEXFORMAT_EAC_SIGNED_RG11; 295 case GL_COMPRESSED_RGB8_ETC2: return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8; 296 case GL_COMPRESSED_SRGB8_ETC2: return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8; 297 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: return tcu::COMPRESSEDTEXFORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; 298 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: return tcu::COMPRESSEDTEXFORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1; 299 case GL_COMPRESSED_RGBA8_ETC2_EAC: return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_RGBA8; 300 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: return tcu::COMPRESSEDTEXFORMAT_ETC2_EAC_SRGB8_ALPHA8; 301 302 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_RGBA; 303 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_RGBA; 304 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_RGBA; 305 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_RGBA; 306 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_RGBA; 307 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_RGBA; 308 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_RGBA; 309 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_RGBA; 310 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_RGBA; 311 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_RGBA; 312 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_RGBA; 313 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_RGBA; 314 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_RGBA; 315 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_RGBA; 316 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_4x4_SRGB8_ALPHA8; 317 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x4_SRGB8_ALPHA8; 318 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_5x5_SRGB8_ALPHA8; 319 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x5_SRGB8_ALPHA8; 320 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_6x6_SRGB8_ALPHA8; 321 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x5_SRGB8_ALPHA8; 322 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x6_SRGB8_ALPHA8; 323 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_8x8_SRGB8_ALPHA8; 324 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x5_SRGB8_ALPHA8; 325 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x6_SRGB8_ALPHA8; 326 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x8_SRGB8_ALPHA8; 327 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_10x10_SRGB8_ALPHA8; 328 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x10_SRGB8_ALPHA8; 329 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: return tcu::COMPRESSEDTEXFORMAT_ASTC_12x12_SRGB8_ALPHA8; 330 331 default: 332 throw tcu::InternalError("Can't map compressed GL format to compressed format"); 333 } 334} 335 336bool isCompressedFormat (deUint32 internalFormat) 337{ 338 switch (internalFormat) 339 { 340 case GL_ETC1_RGB8_OES: 341 case GL_COMPRESSED_R11_EAC: 342 case GL_COMPRESSED_SIGNED_R11_EAC: 343 case GL_COMPRESSED_RG11_EAC: 344 case GL_COMPRESSED_SIGNED_RG11_EAC: 345 case GL_COMPRESSED_RGB8_ETC2: 346 case GL_COMPRESSED_SRGB8_ETC2: 347 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 348 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 349 case GL_COMPRESSED_RGBA8_ETC2_EAC: 350 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 351 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR: 352 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR: 353 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR: 354 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR: 355 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR: 356 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR: 357 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR: 358 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR: 359 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR: 360 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR: 361 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR: 362 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR: 363 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR: 364 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR: 365 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: 366 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: 367 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: 368 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: 369 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: 370 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: 371 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: 372 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: 373 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: 374 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: 375 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: 376 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: 377 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: 378 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: 379 return true; 380 381 default: 382 return false; 383 } 384} 385 386static tcu::TextureFormat::ChannelType mapGLChannelType (deUint32 dataType, bool normalized) 387{ 388 // \note Normalized bit is ignored where it doesn't apply. 389 using tcu::TextureFormat; 390 391 switch (dataType) 392 { 393 case GL_UNSIGNED_BYTE: return normalized ? TextureFormat::UNORM_INT8 : TextureFormat::UNSIGNED_INT8; 394 case GL_BYTE: return normalized ? TextureFormat::SNORM_INT8 : TextureFormat::SIGNED_INT8; 395 case GL_UNSIGNED_SHORT: return normalized ? TextureFormat::UNORM_INT16 : TextureFormat::UNSIGNED_INT16; 396 case GL_SHORT: return normalized ? TextureFormat::SNORM_INT16 : TextureFormat::SIGNED_INT16; 397 case GL_UNSIGNED_INT: return normalized ? TextureFormat::UNORM_INT32 : TextureFormat::UNSIGNED_INT32; 398 case GL_INT: return normalized ? TextureFormat::SNORM_INT32 : TextureFormat::SIGNED_INT32; 399 case GL_FLOAT: return TextureFormat::FLOAT; 400 case GL_UNSIGNED_SHORT_4_4_4_4: return TextureFormat::UNORM_SHORT_4444; 401 case GL_UNSIGNED_SHORT_5_5_5_1: return TextureFormat::UNORM_SHORT_5551; 402 case GL_UNSIGNED_SHORT_5_6_5: return TextureFormat::UNORM_SHORT_565; 403 case GL_HALF_FLOAT: return TextureFormat::HALF_FLOAT; 404 case GL_UNSIGNED_INT_2_10_10_10_REV: return normalized ? TextureFormat::UNORM_INT_1010102_REV : TextureFormat::UNSIGNED_INT_1010102_REV; 405 case GL_UNSIGNED_INT_10F_11F_11F_REV: return TextureFormat::UNSIGNED_INT_11F_11F_10F_REV; 406 case GL_UNSIGNED_INT_24_8: return TextureFormat::UNSIGNED_INT_24_8; 407 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: return TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV; 408 case GL_UNSIGNED_INT_5_9_9_9_REV: return TextureFormat::UNSIGNED_INT_999_E5_REV; 409 410 default: 411 DE_ASSERT(false); 412 return TextureFormat::CHANNELTYPE_LAST; 413 } 414} 415 416/*--------------------------------------------------------------------*//*! 417 * \brief Map GL pixel transfer format to tcu::TextureFormat. 418 * 419 * If no mapping is found, throws tcu::InternalError. 420 * 421 * \param format GL pixel format. 422 * \param dataType GL data type. 423 * \return Generic texture format. 424 *//*--------------------------------------------------------------------*/ 425tcu::TextureFormat mapGLTransferFormat (deUint32 format, deUint32 dataType) 426{ 427 using tcu::TextureFormat; 428 switch (format) 429 { 430 case GL_ALPHA: return TextureFormat(TextureFormat::A, mapGLChannelType(dataType, true)); 431 case GL_LUMINANCE: return TextureFormat(TextureFormat::L, mapGLChannelType(dataType, true)); 432 case GL_LUMINANCE_ALPHA: return TextureFormat(TextureFormat::LA, mapGLChannelType(dataType, true)); 433 case GL_RGB: return TextureFormat(TextureFormat::RGB, mapGLChannelType(dataType, true)); 434 case GL_RGBA: return TextureFormat(TextureFormat::RGBA, mapGLChannelType(dataType, true)); 435 case GL_BGRA: return TextureFormat(TextureFormat::BGRA, mapGLChannelType(dataType, true)); 436 case GL_RG: return TextureFormat(TextureFormat::RG, mapGLChannelType(dataType, true)); 437 case GL_RED: return TextureFormat(TextureFormat::R, mapGLChannelType(dataType, true)); 438 case GL_RGBA_INTEGER: return TextureFormat(TextureFormat::RGBA, mapGLChannelType(dataType, false)); 439 case GL_RGB_INTEGER: return TextureFormat(TextureFormat::RGB, mapGLChannelType(dataType, false)); 440 case GL_RG_INTEGER: return TextureFormat(TextureFormat::RG, mapGLChannelType(dataType, false)); 441 case GL_RED_INTEGER: return TextureFormat(TextureFormat::R, mapGLChannelType(dataType, false)); 442 443 case GL_DEPTH_COMPONENT: return TextureFormat(TextureFormat::D, mapGLChannelType(dataType, true)); 444 case GL_DEPTH_STENCIL: return TextureFormat(TextureFormat::DS, mapGLChannelType(dataType, true)); 445 446 default: 447 throw tcu::InternalError(string("Can't map GL pixel format (") + tcu::toHex(format).toString() + ", " + tcu::toHex(dataType).toString() + ") to texture format"); 448 } 449} 450 451/*--------------------------------------------------------------------*//*! 452 * \brief Map GL internal texture format to tcu::TextureFormat. 453 * 454 * If no mapping is found, throws tcu::InternalError. 455 * 456 * \param internalFormat Sized internal format. 457 * \return Generic texture format. 458 *//*--------------------------------------------------------------------*/ 459tcu::TextureFormat mapGLInternalFormat (deUint32 internalFormat) 460{ 461 using tcu::TextureFormat; 462 switch (internalFormat) 463 { 464 case GL_RGB5_A1: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_5551); 465 case GL_RGBA4: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_4444); 466 case GL_RGB565: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_SHORT_565); 467 case GL_DEPTH_COMPONENT16: return TextureFormat(TextureFormat::D, TextureFormat::UNORM_INT16); 468 case GL_STENCIL_INDEX8: return TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8); 469 470 case GL_RGBA32F: return TextureFormat(TextureFormat::RGBA, TextureFormat::FLOAT); 471 case GL_RGBA32I: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT32); 472 case GL_RGBA32UI: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT32); 473 case GL_RGBA16: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT16); 474 case GL_RGBA16_SNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT16); 475 case GL_RGBA16F: return TextureFormat(TextureFormat::RGBA, TextureFormat::HALF_FLOAT); 476 case GL_RGBA16I: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT16); 477 case GL_RGBA16UI: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT16); 478 case GL_RGBA8: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT8); 479 case GL_RGBA8I: return TextureFormat(TextureFormat::RGBA, TextureFormat::SIGNED_INT8); 480 case GL_RGBA8UI: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT8); 481 case GL_SRGB8_ALPHA8: return TextureFormat(TextureFormat::sRGBA, TextureFormat::UNORM_INT8); 482 case GL_RGB10_A2: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_INT_1010102_REV); 483 case GL_RGB10_A2UI: return TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV); 484 case GL_RGBA8_SNORM: return TextureFormat(TextureFormat::RGBA, TextureFormat::SNORM_INT8); 485 486 case GL_RGB8: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT8); 487 case GL_R11F_G11F_B10F: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_11F_11F_10F_REV); 488 case GL_RGB32F: return TextureFormat(TextureFormat::RGB, TextureFormat::FLOAT); 489 case GL_RGB32I: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT32); 490 case GL_RGB32UI: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT32); 491 case GL_RGB16: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT16); 492 case GL_RGB16_SNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT16); 493 case GL_RGB16F: return TextureFormat(TextureFormat::RGB, TextureFormat::HALF_FLOAT); 494 case GL_RGB16I: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT16); 495 case GL_RGB16UI: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT16); 496 case GL_RGB8_SNORM: return TextureFormat(TextureFormat::RGB, TextureFormat::SNORM_INT8); 497 case GL_RGB8I: return TextureFormat(TextureFormat::RGB, TextureFormat::SIGNED_INT8); 498 case GL_RGB8UI: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT8); 499 case GL_SRGB8: return TextureFormat(TextureFormat::sRGB, TextureFormat::UNORM_INT8); 500 case GL_RGB9_E5: return TextureFormat(TextureFormat::RGB, TextureFormat::UNSIGNED_INT_999_E5_REV); 501 case GL_RGB10: return TextureFormat(TextureFormat::RGB, TextureFormat::UNORM_INT_1010102_REV); 502 503 case GL_RG32F: return TextureFormat(TextureFormat::RG, TextureFormat::FLOAT); 504 case GL_RG32I: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT32); 505 case GL_RG32UI: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT32); 506 case GL_RG16: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT16); 507 case GL_RG16_SNORM: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT16); 508 case GL_RG16F: return TextureFormat(TextureFormat::RG, TextureFormat::HALF_FLOAT); 509 case GL_RG16I: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT16); 510 case GL_RG16UI: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT16); 511 case GL_RG8: return TextureFormat(TextureFormat::RG, TextureFormat::UNORM_INT8); 512 case GL_RG8I: return TextureFormat(TextureFormat::RG, TextureFormat::SIGNED_INT8); 513 case GL_RG8UI: return TextureFormat(TextureFormat::RG, TextureFormat::UNSIGNED_INT8); 514 case GL_RG8_SNORM: return TextureFormat(TextureFormat::RG, TextureFormat::SNORM_INT8); 515 516 case GL_R32F: return TextureFormat(TextureFormat::R, TextureFormat::FLOAT); 517 case GL_R32I: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT32); 518 case GL_R32UI: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT32); 519 case GL_R16: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT16); 520 case GL_R16_SNORM: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT16); 521 case GL_R16F: return TextureFormat(TextureFormat::R, TextureFormat::HALF_FLOAT); 522 case GL_R16I: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT16); 523 case GL_R16UI: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT16); 524 case GL_R8: return TextureFormat(TextureFormat::R, TextureFormat::UNORM_INT8); 525 case GL_R8I: return TextureFormat(TextureFormat::R, TextureFormat::SIGNED_INT8); 526 case GL_R8UI: return TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8); 527 case GL_R8_SNORM: return TextureFormat(TextureFormat::R, TextureFormat::SNORM_INT8); 528 529 case GL_DEPTH_COMPONENT32F: return TextureFormat(TextureFormat::D, TextureFormat::FLOAT); 530 case GL_DEPTH_COMPONENT24: return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT_24_8); 531 case GL_DEPTH_COMPONENT32: return TextureFormat(TextureFormat::D, TextureFormat::UNSIGNED_INT32); 532 case GL_DEPTH32F_STENCIL8: return TextureFormat(TextureFormat::DS, TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV); 533 case GL_DEPTH24_STENCIL8: return TextureFormat(TextureFormat::DS, TextureFormat::UNSIGNED_INT_24_8); 534 535 default: 536 throw tcu::InternalError(string("Can't map GL sized internal format (") + tcu::toHex(internalFormat).toString() + ") to texture format"); 537 } 538} 539 540bool isGLInternalColorFormatFilterable (deUint32 format) 541{ 542 switch (format) 543 { 544 case GL_R8: 545 case GL_R8_SNORM: 546 case GL_RG8: 547 case GL_RG8_SNORM: 548 case GL_RGB8: 549 case GL_RGB8_SNORM: 550 case GL_RGB565: 551 case GL_RGBA4: 552 case GL_RGB5_A1: 553 case GL_RGBA8: 554 case GL_RGBA8_SNORM: 555 case GL_RGB10_A2: 556 case GL_SRGB8: 557 case GL_SRGB8_ALPHA8: 558 case GL_R16F: 559 case GL_RG16F: 560 case GL_RGB16F: 561 case GL_RGBA16F: 562 case GL_R11F_G11F_B10F: 563 case GL_RGB9_E5: 564 return true; 565 566 case GL_RGB10_A2UI: 567 case GL_R32F: 568 case GL_RG32F: 569 case GL_RGB32F: 570 case GL_RGBA32F: 571 case GL_R8I: 572 case GL_R8UI: 573 case GL_R16I: 574 case GL_R16UI: 575 case GL_R32I: 576 case GL_R32UI: 577 case GL_RG8I: 578 case GL_RG8UI: 579 case GL_RG16I: 580 case GL_RG16UI: 581 case GL_RG32I: 582 case GL_RG32UI: 583 case GL_RGB8I: 584 case GL_RGB8UI: 585 case GL_RGB16I: 586 case GL_RGB16UI: 587 case GL_RGB32I: 588 case GL_RGB32UI: 589 case GL_RGBA8I: 590 case GL_RGBA8UI: 591 case GL_RGBA16I: 592 case GL_RGBA16UI: 593 case GL_RGBA32I: 594 case GL_RGBA32UI: 595 return false; 596 597 default: 598 DE_ASSERT(false); 599 return false; 600 } 601} 602 603static inline tcu::Sampler::WrapMode mapGLWrapMode (deUint32 wrapMode) 604{ 605 switch (wrapMode) 606 { 607 case GL_CLAMP_TO_EDGE: return tcu::Sampler::CLAMP_TO_EDGE; 608 case GL_CLAMP_TO_BORDER: return tcu::Sampler::CLAMP_TO_BORDER; 609 case GL_REPEAT: return tcu::Sampler::REPEAT_GL; 610 case GL_MIRRORED_REPEAT: return tcu::Sampler::MIRRORED_REPEAT_GL; 611 default: 612 throw tcu::InternalError("Can't map GL wrap mode " + tcu::toHex(wrapMode).toString()); 613 } 614} 615 616static inline tcu::Sampler::FilterMode mapGLFilterMode (deUint32 filterMode) 617{ 618 switch (filterMode) 619 { 620 case GL_NEAREST: return tcu::Sampler::NEAREST; 621 case GL_LINEAR: return tcu::Sampler::LINEAR; 622 case GL_NEAREST_MIPMAP_NEAREST: return tcu::Sampler::NEAREST_MIPMAP_NEAREST; 623 case GL_NEAREST_MIPMAP_LINEAR: return tcu::Sampler::NEAREST_MIPMAP_LINEAR; 624 case GL_LINEAR_MIPMAP_NEAREST: return tcu::Sampler::LINEAR_MIPMAP_NEAREST; 625 case GL_LINEAR_MIPMAP_LINEAR: return tcu::Sampler::LINEAR_MIPMAP_LINEAR; 626 default: 627 throw tcu::InternalError("Can't map GL filter mode" + tcu::toHex(filterMode).toString()); 628 } 629} 630 631/*--------------------------------------------------------------------*//*! 632 * \brief Map GL sampler parameters to tcu::Sampler. 633 * 634 * If no mapping is found, throws tcu::InternalError. 635 * 636 * \param wrapS S-component wrap mode 637 * \param minFilter Minification filter mode 638 * \param magFilter Magnification filter mode 639 * \return Sampler description. 640 *//*--------------------------------------------------------------------*/ 641tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 minFilter, deUint32 magFilter) 642{ 643 return mapGLSampler(wrapS, wrapS, wrapS, minFilter, magFilter); 644} 645 646 647/*--------------------------------------------------------------------*//*! 648 * \brief Map GL sampler parameters to tcu::Sampler. 649 * 650 * If no mapping is found, throws tcu::InternalError. 651 * 652 * \param wrapS S-component wrap mode 653 * \param wrapT T-component wrap mode 654 * \param minFilter Minification filter mode 655 * \param magFilter Magnification filter mode 656 * \return Sampler description. 657 *//*--------------------------------------------------------------------*/ 658tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 minFilter, deUint32 magFilter) 659{ 660 return mapGLSampler(wrapS, wrapT, wrapS, minFilter, magFilter); 661} 662 663/*--------------------------------------------------------------------*//*! 664 * \brief Map GL sampler parameters to tcu::Sampler. 665 * 666 * If no mapping is found, throws tcu::InternalError. 667 * 668 * \param wrapS S-component wrap mode 669 * \param wrapT T-component wrap mode 670 * \param wrapR R-component wrap mode 671 * \param minFilter Minification filter mode 672 * \param magFilter Magnification filter mode 673 * \return Sampler description. 674 *//*--------------------------------------------------------------------*/ 675tcu::Sampler mapGLSampler (deUint32 wrapS, deUint32 wrapT, deUint32 wrapR, deUint32 minFilter, deUint32 magFilter) 676{ 677 return tcu::Sampler(mapGLWrapMode(wrapS), mapGLWrapMode(wrapT), mapGLWrapMode(wrapR), 678 mapGLFilterMode(minFilter), mapGLFilterMode(magFilter), 679 0.0f /* lod threshold */, 680 true /* normalized coords */, 681 tcu::Sampler::COMPAREMODE_NONE /* no compare */, 682 0 /* compare channel */, 683 tcu::Vec4(0.0f) /* border color, not used */); 684} 685 686/*--------------------------------------------------------------------*//*! 687 * \brief Map GL compare function to tcu::Sampler::CompareMode. 688 * 689 * If no mapping is found, throws tcu::InternalError. 690 * 691 * \param mode GL compare mode 692 * \return Compare mode 693 *//*--------------------------------------------------------------------*/ 694tcu::Sampler::CompareMode mapGLCompareFunc (deUint32 mode) 695{ 696 switch (mode) 697 { 698 case GL_LESS: return tcu::Sampler::COMPAREMODE_LESS; 699 case GL_LEQUAL: return tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL; 700 case GL_GREATER: return tcu::Sampler::COMPAREMODE_GREATER; 701 case GL_GEQUAL: return tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL; 702 case GL_EQUAL: return tcu::Sampler::COMPAREMODE_EQUAL; 703 case GL_NOTEQUAL: return tcu::Sampler::COMPAREMODE_NOT_EQUAL; 704 case GL_ALWAYS: return tcu::Sampler::COMPAREMODE_ALWAYS; 705 case GL_NEVER: return tcu::Sampler::COMPAREMODE_NEVER; 706 default: 707 throw tcu::InternalError("Can't map GL compare mode " + tcu::toHex(mode).toString()); 708 } 709} 710 711/*--------------------------------------------------------------------*//*! 712 * \brief Get GL wrap mode. 713 * 714 * If no mapping is found, throws tcu::InternalError. 715 * 716 * \param wrapMode Wrap mode 717 * \return GL wrap mode 718 *//*--------------------------------------------------------------------*/ 719deUint32 getGLWrapMode (tcu::Sampler::WrapMode wrapMode) 720{ 721 DE_ASSERT(wrapMode != tcu::Sampler::WRAPMODE_LAST); 722 switch (wrapMode) 723 { 724 case tcu::Sampler::CLAMP_TO_EDGE: return GL_CLAMP_TO_EDGE; 725 case tcu::Sampler::CLAMP_TO_BORDER: return GL_CLAMP_TO_BORDER; 726 case tcu::Sampler::REPEAT_GL: return GL_REPEAT; 727 case tcu::Sampler::MIRRORED_REPEAT_GL: return GL_MIRRORED_REPEAT; 728 default: 729 throw tcu::InternalError("Can't map wrap mode"); 730 } 731} 732 733/*--------------------------------------------------------------------*//*! 734 * \brief Get GL filter mode. 735 * 736 * If no mapping is found, throws tcu::InternalError. 737 * 738 * \param filterMode Filter mode 739 * \return GL filter mode 740 *//*--------------------------------------------------------------------*/ 741deUint32 getGLFilterMode (tcu::Sampler::FilterMode filterMode) 742{ 743 DE_ASSERT(filterMode != tcu::Sampler::FILTERMODE_LAST); 744 switch (filterMode) 745 { 746 case tcu::Sampler::NEAREST: return GL_NEAREST; 747 case tcu::Sampler::LINEAR: return GL_LINEAR; 748 case tcu::Sampler::NEAREST_MIPMAP_NEAREST: return GL_NEAREST_MIPMAP_NEAREST; 749 case tcu::Sampler::NEAREST_MIPMAP_LINEAR: return GL_NEAREST_MIPMAP_LINEAR; 750 case tcu::Sampler::LINEAR_MIPMAP_NEAREST: return GL_LINEAR_MIPMAP_NEAREST; 751 case tcu::Sampler::LINEAR_MIPMAP_LINEAR: return GL_LINEAR_MIPMAP_LINEAR; 752 default: 753 throw tcu::InternalError("Can't map filter mode"); 754 } 755} 756 757/*--------------------------------------------------------------------*//*! 758 * \brief Get GL compare mode. 759 * 760 * If no mapping is found, throws tcu::InternalError. 761 * 762 * \param compareMode Compare mode 763 * \return GL compare mode 764 *//*--------------------------------------------------------------------*/ 765deUint32 getGLCompareFunc (tcu::Sampler::CompareMode compareMode) 766{ 767 DE_ASSERT(compareMode != tcu::Sampler::COMPAREMODE_NONE); 768 switch (compareMode) 769 { 770 case tcu::Sampler::COMPAREMODE_NONE: return GL_NONE; 771 case tcu::Sampler::COMPAREMODE_LESS: return GL_LESS; 772 case tcu::Sampler::COMPAREMODE_LESS_OR_EQUAL: return GL_LEQUAL; 773 case tcu::Sampler::COMPAREMODE_GREATER: return GL_GREATER; 774 case tcu::Sampler::COMPAREMODE_GREATER_OR_EQUAL: return GL_GEQUAL; 775 case tcu::Sampler::COMPAREMODE_EQUAL: return GL_EQUAL; 776 case tcu::Sampler::COMPAREMODE_NOT_EQUAL: return GL_NOTEQUAL; 777 case tcu::Sampler::COMPAREMODE_ALWAYS: return GL_ALWAYS; 778 case tcu::Sampler::COMPAREMODE_NEVER: return GL_NEVER; 779 default: 780 throw tcu::InternalError("Can't map compare mode"); 781 } 782} 783 784/*--------------------------------------------------------------------*//*! 785 * \brief Get GL cube face. 786 * 787 * If no mapping is found, throws tcu::InternalError. 788 * 789 * \param face Cube face 790 * \return GL cube face 791 *//*--------------------------------------------------------------------*/ 792deUint32 getGLCubeFace (tcu::CubeFace face) 793{ 794 DE_ASSERT(face != tcu::CUBEFACE_LAST); 795 switch (face) 796 { 797 case tcu::CUBEFACE_NEGATIVE_X: return GL_TEXTURE_CUBE_MAP_NEGATIVE_X; 798 case tcu::CUBEFACE_POSITIVE_X: return GL_TEXTURE_CUBE_MAP_POSITIVE_X; 799 case tcu::CUBEFACE_NEGATIVE_Y: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; 800 case tcu::CUBEFACE_POSITIVE_Y: return GL_TEXTURE_CUBE_MAP_POSITIVE_Y; 801 case tcu::CUBEFACE_NEGATIVE_Z: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; 802 case tcu::CUBEFACE_POSITIVE_Z: return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; 803 default: 804 throw tcu::InternalError("Can't map cube face"); 805 } 806} 807 808tcu::CubeFace getCubeFaceFromGL (deUint32 face) 809{ 810 switch (face) 811 { 812 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: return tcu::CUBEFACE_NEGATIVE_X; 813 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: return tcu::CUBEFACE_POSITIVE_X; 814 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: return tcu::CUBEFACE_NEGATIVE_Y; 815 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: return tcu::CUBEFACE_POSITIVE_Y; 816 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: return tcu::CUBEFACE_NEGATIVE_Z; 817 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: return tcu::CUBEFACE_POSITIVE_Z; 818 default: 819 throw tcu::InternalError("Can't map cube face"); 820 } 821} 822 823/*--------------------------------------------------------------------*//*! 824 * \brief Get GLSL sampler type for texture format. 825 * 826 * If no mapping is found, glu::TYPE_LAST is returned. 827 * 828 * \param format Texture format 829 * \return GLSL 1D sampler type for format 830 *//*--------------------------------------------------------------------*/ 831DataType getSampler1DType (tcu::TextureFormat format) 832{ 833 using tcu::TextureFormat; 834 835 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 836 return TYPE_SAMPLER_1D; 837 838 if (format.order == TextureFormat::S) 839 return TYPE_LAST; 840 841 switch (tcu::getTextureChannelClass(format.type)) 842 { 843 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 844 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 845 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 846 return glu::TYPE_SAMPLER_1D; 847 848 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 849 return glu::TYPE_INT_SAMPLER_1D; 850 851 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 852 return glu::TYPE_UINT_SAMPLER_1D; 853 854 default: 855 return glu::TYPE_LAST; 856 } 857} 858 859/*--------------------------------------------------------------------*//*! 860 * \brief Get GLSL sampler type for texture format. 861 * 862 * If no mapping is found, glu::TYPE_LAST is returned. 863 * 864 * \param format Texture format 865 * \return GLSL 2D sampler type for format 866 *//*--------------------------------------------------------------------*/ 867DataType getSampler2DType (tcu::TextureFormat format) 868{ 869 using tcu::TextureFormat; 870 871 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 872 return TYPE_SAMPLER_2D; 873 874 if (format.order == TextureFormat::S) 875 return TYPE_LAST; 876 877 switch (tcu::getTextureChannelClass(format.type)) 878 { 879 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 880 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 881 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 882 return glu::TYPE_SAMPLER_2D; 883 884 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 885 return glu::TYPE_INT_SAMPLER_2D; 886 887 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 888 return glu::TYPE_UINT_SAMPLER_2D; 889 890 default: 891 return glu::TYPE_LAST; 892 } 893} 894 895/*--------------------------------------------------------------------*//*! 896 * \brief Get GLSL sampler type for texture format. 897 * 898 * If no mapping is found, glu::TYPE_LAST is returned. 899 * 900 * \param format Texture format 901 * \return GLSL cube map sampler type for format 902 *//*--------------------------------------------------------------------*/ 903DataType getSamplerCubeType (tcu::TextureFormat format) 904{ 905 using tcu::TextureFormat; 906 907 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 908 return TYPE_SAMPLER_CUBE; 909 910 if (format.order == TextureFormat::S) 911 return TYPE_LAST; 912 913 switch (tcu::getTextureChannelClass(format.type)) 914 { 915 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 916 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 917 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 918 return glu::TYPE_SAMPLER_CUBE; 919 920 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 921 return glu::TYPE_INT_SAMPLER_CUBE; 922 923 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 924 return glu::TYPE_UINT_SAMPLER_CUBE; 925 926 default: 927 return glu::TYPE_LAST; 928 } 929} 930 931/*--------------------------------------------------------------------*//*! 932 * \brief Get GLSL sampler type for texture format. 933 * 934 * If no mapping is found, glu::TYPE_LAST is returned. 935 * 936 * \param format Texture format 937 * \return GLSL 2D array sampler type for format 938 *//*--------------------------------------------------------------------*/ 939DataType getSampler2DArrayType (tcu::TextureFormat format) 940{ 941 using tcu::TextureFormat; 942 943 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 944 return TYPE_SAMPLER_2D_ARRAY; 945 946 if (format.order == TextureFormat::S) 947 return TYPE_LAST; 948 949 switch (tcu::getTextureChannelClass(format.type)) 950 { 951 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 952 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 953 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 954 return glu::TYPE_SAMPLER_2D_ARRAY; 955 956 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 957 return glu::TYPE_INT_SAMPLER_2D_ARRAY; 958 959 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 960 return glu::TYPE_UINT_SAMPLER_2D_ARRAY; 961 962 default: 963 return glu::TYPE_LAST; 964 } 965} 966 967/*--------------------------------------------------------------------*//*! 968 * \brief Get GLSL sampler type for texture format. 969 * 970 * If no mapping is found, glu::TYPE_LAST is returned. 971 * 972 * \param format Texture format 973 * \return GLSL 3D sampler type for format 974 *//*--------------------------------------------------------------------*/ 975DataType getSampler3DType (tcu::TextureFormat format) 976{ 977 using tcu::TextureFormat; 978 979 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 980 return TYPE_SAMPLER_3D; 981 982 if (format.order == TextureFormat::S) 983 return TYPE_LAST; 984 985 switch (tcu::getTextureChannelClass(format.type)) 986 { 987 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 988 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 989 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 990 return glu::TYPE_SAMPLER_3D; 991 992 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 993 return glu::TYPE_INT_SAMPLER_3D; 994 995 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 996 return glu::TYPE_UINT_SAMPLER_3D; 997 998 default: 999 return glu::TYPE_LAST; 1000 } 1001} 1002 1003/*--------------------------------------------------------------------*//*! 1004 * \brief Get GLSL sampler type for texture format. 1005 * 1006 * If no mapping is found, glu::TYPE_LAST is returned. 1007 * 1008 * \param format Texture format 1009 * \return GLSL cube map array sampler type for format 1010 *//*--------------------------------------------------------------------*/ 1011DataType getSamplerCubeArrayType (tcu::TextureFormat format) 1012{ 1013 using tcu::TextureFormat; 1014 1015 if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 1016 return TYPE_SAMPLER_CUBE_ARRAY; 1017 1018 if (format.order == TextureFormat::S) 1019 return TYPE_LAST; 1020 1021 switch (tcu::getTextureChannelClass(format.type)) 1022 { 1023 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: 1024 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: 1025 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: 1026 return glu::TYPE_SAMPLER_CUBE_ARRAY; 1027 1028 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: 1029 return glu::TYPE_INT_SAMPLER_CUBE_ARRAY; 1030 1031 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: 1032 return glu::TYPE_UINT_SAMPLER_CUBE_ARRAY; 1033 1034 default: 1035 return glu::TYPE_LAST; 1036 } 1037} 1038 1039enum RenderableType 1040{ 1041 RENDERABLE_COLOR = (1<<0), 1042 RENDERABLE_DEPTH = (1<<1), 1043 RENDERABLE_STENCIL = (1<<2) 1044}; 1045 1046static deUint32 getRenderableBitsES3 (const ContextInfo& contextInfo, deUint32 internalFormat) 1047{ 1048 switch (internalFormat) 1049 { 1050 // Color-renderable formats 1051 case GL_RGBA32I: 1052 case GL_RGBA32UI: 1053 case GL_RGBA16I: 1054 case GL_RGBA16UI: 1055 case GL_RGBA8: 1056 case GL_RGBA8I: 1057 case GL_RGBA8UI: 1058 case GL_SRGB8_ALPHA8: 1059 case GL_RGB10_A2: 1060 case GL_RGB10_A2UI: 1061 case GL_RGBA4: 1062 case GL_RGB5_A1: 1063 case GL_RGB8: 1064 case GL_RGB565: 1065 case GL_RG32I: 1066 case GL_RG32UI: 1067 case GL_RG16I: 1068 case GL_RG16UI: 1069 case GL_RG8: 1070 case GL_RG8I: 1071 case GL_RG8UI: 1072 case GL_R32I: 1073 case GL_R32UI: 1074 case GL_R16I: 1075 case GL_R16UI: 1076 case GL_R8: 1077 case GL_R8I: 1078 case GL_R8UI: 1079 return RENDERABLE_COLOR; 1080 1081 // GL_EXT_color_buffer_float 1082 case GL_RGBA32F: 1083 case GL_R11F_G11F_B10F: 1084 case GL_RG32F: 1085 case GL_R32F: 1086 if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float")) 1087 return RENDERABLE_COLOR; 1088 else 1089 return 0; 1090 1091 // GL_EXT_color_buffer_float / GL_EXT_color_buffer_half_float 1092 case GL_RGBA16F: 1093 case GL_RG16F: 1094 case GL_R16F: 1095 if (contextInfo.isExtensionSupported("GL_EXT_color_buffer_float") || 1096 contextInfo.isExtensionSupported("GL_EXT_color_buffer_half_float")) 1097 return RENDERABLE_COLOR; 1098 else 1099 return 0; 1100 1101 // Depth formats 1102 case GL_DEPTH_COMPONENT32F: 1103 case GL_DEPTH_COMPONENT24: 1104 case GL_DEPTH_COMPONENT16: 1105 return RENDERABLE_DEPTH; 1106 1107 // Depth+stencil formats 1108 case GL_DEPTH32F_STENCIL8: 1109 case GL_DEPTH24_STENCIL8: 1110 return RENDERABLE_DEPTH|RENDERABLE_STENCIL; 1111 1112 // Stencil formats 1113 case GL_STENCIL_INDEX8: 1114 return RENDERABLE_STENCIL; 1115 1116 default: 1117 return 0; 1118 } 1119} 1120 1121/*--------------------------------------------------------------------*//*! 1122 * \brief Check if sized internal format is color-renderable. 1123 * \note Works currently only on ES3 context. 1124 *//*--------------------------------------------------------------------*/ 1125bool isSizedFormatColorRenderable (const RenderContext& renderCtx, const ContextInfo& contextInfo, deUint32 sizedFormat) 1126{ 1127 deUint32 renderable = 0; 1128 1129 if (renderCtx.getType().getAPI() == ApiType::es(3,0)) 1130 renderable = getRenderableBitsES3(contextInfo, sizedFormat); 1131 else 1132 throw tcu::InternalError("Context type not supported in query"); 1133 1134 return (renderable & RENDERABLE_COLOR) != 0; 1135} 1136 1137} // glu 1138