2015-07-11 02:34:45 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLFormats.h"
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#include "gfxPrefs.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "GLDefs.h"
|
2015-07-11 02:34:45 +03:00
|
|
|
#include "mozilla/StaticMutex.h"
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#ifdef FOO
|
|
|
|
#error FOO is already defined! We use FOO() macros to keep things succinct in this file.
|
|
|
|
#endif
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace webgl {
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
template<typename K, typename V, typename K2, typename V2>
|
|
|
|
static inline void
|
|
|
|
AlwaysInsert(std::map<K,V>& dest, const K2& key, const V2& val)
|
|
|
|
{
|
|
|
|
auto res = dest.insert({ key, val });
|
|
|
|
bool didInsert = res.second;
|
|
|
|
MOZ_ALWAYS_TRUE(didInsert);
|
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
template<typename K, typename V, typename K2>
|
|
|
|
static inline V*
|
|
|
|
FindOrNull(const std::map<K,V*>& dest, const K2& key)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
auto itr = dest.find(key);
|
|
|
|
if (itr == dest.end())
|
2015-11-24 08:55:59 +03:00
|
|
|
return nullptr;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return itr->second;
|
2015-11-24 06:27:13 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// Returns a pointer to the in-place value for `key`.
|
|
|
|
template<typename K, typename V, typename K2>
|
|
|
|
static inline V*
|
2016-06-06 23:41:12 +03:00
|
|
|
FindPtrOrNull(std::map<K,V>& dest, const K2& key)
|
2015-11-24 06:27:13 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
auto itr = dest.find(key);
|
|
|
|
if (itr == dest.end())
|
2015-11-24 08:55:59 +03:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &(itr->second);
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
std::map<EffectiveFormat, const CompressedFormatInfo> gCompressedFormatInfoMap;
|
2016-06-06 23:41:12 +03:00
|
|
|
std::map<EffectiveFormat, FormatInfo> gFormatInfoMap;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
static inline const CompressedFormatInfo*
|
|
|
|
GetCompressedFormatInfo(EffectiveFormat format)
|
2015-11-24 08:55:59 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
MOZ_ASSERT(!gCompressedFormatInfoMap.empty());
|
|
|
|
return FindPtrOrNull(gCompressedFormatInfoMap, format);
|
|
|
|
}
|
|
|
|
|
2016-06-06 23:41:12 +03:00
|
|
|
static inline FormatInfo*
|
2015-11-25 07:15:29 +03:00
|
|
|
GetFormatInfo_NoLock(EffectiveFormat format)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!gFormatInfoMap.empty());
|
|
|
|
return FindPtrOrNull(gFormatInfoMap, format);
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat format, uint16_t bitsPerBlock, uint8_t blockWidth,
|
2015-11-25 07:15:29 +03:00
|
|
|
uint8_t blockHeight, CompressionFamily family)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(bitsPerBlock % 8 == 0);
|
|
|
|
uint16_t bytesPerBlock = bitsPerBlock / 8; // The specs always state these in bits,
|
|
|
|
// but it's only ever useful to us as
|
|
|
|
// bytes.
|
|
|
|
MOZ_ASSERT(bytesPerBlock <= 255);
|
|
|
|
|
|
|
|
const CompressedFormatInfo info = { format, uint8_t(bytesPerBlock), blockWidth,
|
2015-11-25 07:15:29 +03:00
|
|
|
blockHeight, family };
|
2015-07-11 02:34:45 +03:00
|
|
|
AlwaysInsert(gCompressedFormatInfoMap, format, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitCompressedFormatInfo()
|
|
|
|
{
|
|
|
|
// GLES 3.0.4, p147, table 3.19
|
|
|
|
// GLES 3.0.4, p286+, $C.1 "ETC Compressed Texture Image Formats"
|
2015-11-25 07:15:29 +03:00
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGB8_ETC2 , 64, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_SRGB8_ETC2 , 64, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA8_ETC2_EAC , 128, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC , 128, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_R11_EAC , 64, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RG11_EAC , 128, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_SIGNED_R11_EAC , 64, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_SIGNED_RG11_EAC , 128, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 , 64, 4, 4, CompressionFamily::ES3);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 64, 4, 4, CompressionFamily::ES3);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// AMD_compressed_ATC_texture
|
2015-11-25 07:15:29 +03:00
|
|
|
AddCompressedFormatInfo(EffectiveFormat::ATC_RGB_AMD , 64, 4, 4, CompressionFamily::ATC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::ATC_RGBA_EXPLICIT_ALPHA_AMD , 128, 4, 4, CompressionFamily::ATC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::ATC_RGBA_INTERPOLATED_ALPHA_AMD, 128, 4, 4, CompressionFamily::ATC);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// EXT_texture_compression_s3tc
|
2015-11-25 07:15:29 +03:00
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGB_S3TC_DXT1_EXT , 64, 4, 4, CompressionFamily::S3TC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT1_EXT, 64, 4, 4, CompressionFamily::S3TC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT3_EXT, 128, 4, 4, CompressionFamily::S3TC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT5_EXT, 128, 4, 4, CompressionFamily::S3TC);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// IMG_texture_compression_pvrtc
|
2015-11-25 07:15:29 +03:00
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGB_PVRTC_4BPPV1 , 256, 8, 8, CompressionFamily::PVRTC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA_PVRTC_4BPPV1, 256, 8, 8, CompressionFamily::PVRTC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGB_PVRTC_2BPPV1 , 256, 16, 8, CompressionFamily::PVRTC);
|
|
|
|
AddCompressedFormatInfo(EffectiveFormat::COMPRESSED_RGBA_PVRTC_2BPPV1, 256, 16, 8, CompressionFamily::PVRTC);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// OES_compressed_ETC1_RGB8_texture
|
2015-11-25 07:15:29 +03:00
|
|
|
AddCompressedFormatInfo(EffectiveFormat::ETC1_RGB8_OES, 64, 4, 4, CompressionFamily::ETC1);
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static void
|
2015-11-25 07:15:29 +03:00
|
|
|
AddFormatInfo(EffectiveFormat format, const char* name, GLenum sizedFormat,
|
2016-06-06 23:40:35 +03:00
|
|
|
uint8_t bytesPerPixel, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
|
|
|
|
uint8_t d, uint8_t s, UnsizedFormat unsizedFormat, bool isSRGB,
|
2015-11-25 07:15:29 +03:00
|
|
|
ComponentType componentType)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
2016-07-06 02:27:58 +03:00
|
|
|
#ifdef DEBUG
|
2016-06-06 23:40:35 +03:00
|
|
|
uint8_t totalBits = r + g + b + a + d + s;
|
|
|
|
if (format == EffectiveFormat::RGB9_E5) {
|
|
|
|
totalBits = 9 + 9 + 9 + 5;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(totalBits == bytesPerPixel*8);
|
2016-07-06 02:27:58 +03:00
|
|
|
#endif
|
2016-06-06 23:40:35 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool isColorFormat = false;
|
2015-07-11 02:34:45 +03:00
|
|
|
bool hasAlpha = false;
|
|
|
|
bool hasDepth = false;
|
|
|
|
bool hasStencil = false;
|
|
|
|
|
|
|
|
switch (unsizedFormat) {
|
|
|
|
case UnsizedFormat::L:
|
|
|
|
case UnsizedFormat::R:
|
|
|
|
case UnsizedFormat::RG:
|
|
|
|
case UnsizedFormat::RGB:
|
2015-11-25 07:15:29 +03:00
|
|
|
isColorFormat = true;
|
2015-07-11 02:34:45 +03:00
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case UnsizedFormat::A: // Alpha is a 'color format' since it's 'color-attachable'.
|
2015-07-11 02:34:45 +03:00
|
|
|
case UnsizedFormat::LA:
|
|
|
|
case UnsizedFormat::RGBA:
|
2015-11-25 07:15:29 +03:00
|
|
|
isColorFormat = true;
|
2015-07-11 02:34:45 +03:00
|
|
|
hasAlpha = true;
|
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
case UnsizedFormat::D:
|
|
|
|
hasDepth = true;
|
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
case UnsizedFormat::S:
|
|
|
|
hasStencil = true;
|
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
case UnsizedFormat::DS:
|
|
|
|
hasDepth = true;
|
|
|
|
hasStencil = true;
|
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Missing UnsizedFormat case.");
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CompressedFormatInfo* compressedFormatInfo = GetCompressedFormatInfo(format);
|
|
|
|
MOZ_ASSERT(!bytesPerPixel == bool(compressedFormatInfo));
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const FormatInfo info = { format, name, sizedFormat, unsizedFormat, componentType,
|
2016-06-06 23:40:35 +03:00
|
|
|
bytesPerPixel, r,g,b,a, isColorFormat, isSRGB, hasAlpha,
|
|
|
|
hasDepth, hasStencil, compressedFormatInfo };
|
2015-07-11 02:34:45 +03:00
|
|
|
AlwaysInsert(gFormatInfoMap, format, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-25 07:15:29 +03:00
|
|
|
InitFormatInfo()
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
#define FOO(x) EffectiveFormat::x, #x, LOCAL_GL_ ## x
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// GLES 3.0.4, p130-132, table 3.13
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(R8 ), 1, 8, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(R8_SNORM ), 1, 8, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(RG8 ), 2, 8, 8, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RG8_SNORM ), 2, 8, 8, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(RGB8 ), 3, 8, 8, 8, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGB8_SNORM ), 3, 8, 8, 8, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(RGB565 ), 2, 5, 6, 5, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGBA4 ), 2, 4, 4, 4, 4, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGB5_A1 ), 2, 5, 5, 5, 1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGBA8 ), 4, 8, 8, 8, 8, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGBA8_SNORM ), 4, 8, 8, 8, 8, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(RGB10_A2 ), 4, 10,10,10, 2, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(RGB10_A2UI ), 4, 10,10,10, 2, 0,0, UnsizedFormat::RGBA, false, ComponentType::UInt );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(SRGB8 ), 3, 8, 8, 8, 0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(SRGB8_ALPHA8 ), 4, 8, 8, 8, 8, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(R16F ), 2, 16, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RG16F ), 4, 16,16, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RGB16F ), 6, 16,16,16, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RGBA16F ), 8, 16,16,16,16, 0,0, UnsizedFormat::RGBA, false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(R32F ), 4, 32, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RG32F ), 8, 32,32, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RGB32F ), 12, 32,32,32, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RGBA32F ), 16, 32,32,32,32, 0,0, UnsizedFormat::RGBA, false, ComponentType::Float );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(R11F_G11F_B10F), 4, 11,11,10, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Float );
|
|
|
|
AddFormatInfo(FOO(RGB9_E5 ), 4, 14,14,14, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Float );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(R8I ), 1, 8, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(R8UI ), 1, 8, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(R16I ), 2, 16, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(R16UI ), 2, 16, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(R32I ), 4, 32, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(R32UI ), 4, 32, 0, 0, 0, 0,0, UnsizedFormat::R , false, ComponentType::UInt );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(RG8I ), 2, 8, 8, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RG8UI ), 2, 8, 8, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RG16I ), 4, 16,16, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RG16UI ), 4, 16,16, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RG32I ), 8, 32,32, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RG32UI ), 8, 32,32, 0, 0, 0,0, UnsizedFormat::RG , false, ComponentType::UInt );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(RGB8I ), 3, 8, 8, 8, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGB8UI ), 3, 8, 8, 8, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RGB16I ), 6, 16,16,16, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGB16UI ), 6, 16,16,16, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RGB32I ), 12, 32,32,32, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGB32UI ), 12, 32,32,32, 0, 0,0, UnsizedFormat::RGB , false, ComponentType::UInt );
|
|
|
|
|
|
|
|
AddFormatInfo(FOO(RGBA8I ), 4, 8, 8, 8, 8, 0,0, UnsizedFormat::RGBA, false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGBA8UI ), 4, 8, 8, 8, 8, 0,0, UnsizedFormat::RGBA, false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RGBA16I ), 8, 16,16,16,16, 0,0, UnsizedFormat::RGBA, false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGBA16UI ), 8, 16,16,16,16, 0,0, UnsizedFormat::RGBA, false, ComponentType::UInt );
|
|
|
|
AddFormatInfo(FOO(RGBA32I ), 16, 32,32,32,32, 0,0, UnsizedFormat::RGBA, false, ComponentType::Int );
|
|
|
|
AddFormatInfo(FOO(RGBA32UI ), 16, 32,32,32,32, 0,0, UnsizedFormat::RGBA, false, ComponentType::UInt );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// GLES 3.0.4, p133, table 3.14
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(DEPTH_COMPONENT16 ), 2, 0,0,0,0, 16,0, UnsizedFormat::D , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(DEPTH_COMPONENT24 ), 3, 0,0,0,0, 24,0, UnsizedFormat::D , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(DEPTH_COMPONENT32F), 4, 0,0,0,0, 32,0, UnsizedFormat::D , false, ComponentType::Float);
|
|
|
|
AddFormatInfo(FOO(DEPTH24_STENCIL8 ), 4, 0,0,0,0, 24,8, UnsizedFormat::DS, false, ComponentType::Special);
|
|
|
|
AddFormatInfo(FOO(DEPTH32F_STENCIL8 ), 5, 0,0,0,0, 32,8, UnsizedFormat::DS, false, ComponentType::Special);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// GLES 3.0.4, p205-206, "Required Renderbuffer Formats"
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(STENCIL_INDEX8), 1, 0,0,0,0, 0,8, UnsizedFormat::S, false, ComponentType::UInt);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// GLES 3.0.4, p147, table 3.19
|
|
|
|
// GLES 3.0.4 p286+ $C.1 "ETC Compressed Texture Image Formats"
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGB8_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_SRGB8_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA8_ETC2_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_R11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RG11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_SIGNED_R11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_SIGNED_RG11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormInt );
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// AMD_compressed_ATC_texture
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(ATC_RGB_AMD ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(ATC_RGBA_EXPLICIT_ALPHA_AMD ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(ATC_RGBA_INTERPOLATED_ALPHA_AMD), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// EXT_texture_compression_s3tc
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// IMG_texture_compression_pvrtc
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_4BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_2BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// OES_compressed_ETC1_RGB8_texture
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(ETC1_RGB8_OES), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB, false, ComponentType::NormUInt);
|
2015-07-17 06:53:03 +03:00
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
#undef FOO
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// 'Virtual' effective formats have no sizedFormat.
|
|
|
|
#define FOO(x) EffectiveFormat::x, #x, 0
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4, p128, table 3.12.
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(Luminance8Alpha8), 2, 8,0,0,8, 0,0, UnsizedFormat::LA, false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(Luminance8 ), 1, 8,0,0,0, 0,0, UnsizedFormat::L , false, ComponentType::NormUInt);
|
|
|
|
AddFormatInfo(FOO(Alpha8 ), 1, 0,0,0,8, 0,0, UnsizedFormat::A , false, ComponentType::NormUInt);
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// OES_texture_float
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(Luminance32FAlpha32F), 8, 32,0,0,32, 0,0, UnsizedFormat::LA, false, ComponentType::Float);
|
|
|
|
AddFormatInfo(FOO(Luminance32F ), 4, 32,0,0, 0, 0,0, UnsizedFormat::L , false, ComponentType::Float);
|
|
|
|
AddFormatInfo(FOO(Alpha32F ), 4, 0,0,0,32, 0,0, UnsizedFormat::A , false, ComponentType::Float);
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// OES_texture_half_float
|
2016-06-06 23:40:35 +03:00
|
|
|
AddFormatInfo(FOO(Luminance16FAlpha16F), 4, 16,0,0,16, 0,0, UnsizedFormat::LA, false, ComponentType::Float);
|
|
|
|
AddFormatInfo(FOO(Luminance16F ), 2, 16,0,0, 0, 0,0, UnsizedFormat::L , false, ComponentType::Float);
|
|
|
|
AddFormatInfo(FOO(Alpha16F ), 2, 0,0,0,16, 0,0, UnsizedFormat::A , false, ComponentType::Float);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
#undef FOO
|
2016-06-06 23:41:12 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const auto fnSetCopyDecay = [](EffectiveFormat src, EffectiveFormat asR,
|
|
|
|
EffectiveFormat asRG, EffectiveFormat asRGB,
|
|
|
|
EffectiveFormat asRGBA, EffectiveFormat asL,
|
|
|
|
EffectiveFormat asA, EffectiveFormat asLA)
|
|
|
|
{
|
|
|
|
auto& map = GetFormatInfo_NoLock(src)->copyDecayFormats;
|
|
|
|
|
|
|
|
const auto fnSet = [&map](UnsizedFormat uf, EffectiveFormat ef) {
|
|
|
|
if (ef == EffectiveFormat::MAX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto* format = GetFormatInfo_NoLock(ef);
|
|
|
|
MOZ_ASSERT(format->unsizedFormat == uf);
|
|
|
|
AlwaysInsert(map, uf, format);
|
|
|
|
};
|
|
|
|
|
|
|
|
fnSet(UnsizedFormat::R , asR);
|
|
|
|
fnSet(UnsizedFormat::RG , asRG);
|
|
|
|
fnSet(UnsizedFormat::RGB , asRGB);
|
|
|
|
fnSet(UnsizedFormat::RGBA, asRGBA);
|
|
|
|
fnSet(UnsizedFormat::L , asL);
|
|
|
|
fnSet(UnsizedFormat::A , asA);
|
|
|
|
fnSet(UnsizedFormat::LA , asLA);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SET_COPY_DECAY(src,asR,asRG,asRGB,asRGBA,asL,asA,asLA) \
|
|
|
|
fnSetCopyDecay(EffectiveFormat::src, EffectiveFormat::asR, EffectiveFormat::asRG, \
|
|
|
|
EffectiveFormat::asRGB, EffectiveFormat::asRGBA, EffectiveFormat::asL, \
|
|
|
|
EffectiveFormat::asA, EffectiveFormat::asLA);
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
#define SET_BY_SUFFIX(X) \
|
|
|
|
SET_COPY_DECAY( R##X, R##X, MAX, MAX, MAX, Luminance##X, MAX, MAX) \
|
|
|
|
SET_COPY_DECAY( RG##X, R##X, RG##X, MAX, MAX, Luminance##X, MAX, MAX) \
|
|
|
|
SET_COPY_DECAY(RGBA##X, R##X, RG##X, RGB##X, RGBA##X, Luminance##X, Alpha##X, Luminance##X##Alpha##X)
|
|
|
|
|
|
|
|
SET_BY_SUFFIX(8)
|
|
|
|
SET_BY_SUFFIX(16F)
|
|
|
|
SET_BY_SUFFIX(32F)
|
|
|
|
|
|
|
|
#undef SET_BY_SUFFIX
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
#define SET_BY_SUFFIX(X) \
|
|
|
|
SET_COPY_DECAY( R##X, R##X, MAX, MAX, MAX, MAX, MAX, MAX) \
|
|
|
|
SET_COPY_DECAY( RG##X, R##X, RG##X, MAX, MAX, MAX, MAX, MAX) \
|
|
|
|
SET_COPY_DECAY(RGBA##X, R##X, RG##X, RGB##X, RGBA##X, MAX, MAX, MAX)
|
|
|
|
|
|
|
|
SET_BY_SUFFIX(8I)
|
|
|
|
SET_BY_SUFFIX(8UI)
|
|
|
|
|
|
|
|
SET_BY_SUFFIX(16I)
|
|
|
|
SET_BY_SUFFIX(16UI)
|
|
|
|
|
|
|
|
SET_BY_SUFFIX(32I)
|
|
|
|
SET_BY_SUFFIX(32UI)
|
|
|
|
|
|
|
|
#undef SET_BY_SUFFIX
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
SET_COPY_DECAY( RGB8, R8, RG8, RGB8, MAX, Luminance8, MAX, MAX)
|
|
|
|
SET_COPY_DECAY( RGB565, R8, RG8, RGB565, MAX, Luminance8, MAX, MAX)
|
|
|
|
SET_COPY_DECAY( RGBA4, R8, RG8, RGB565, RGBA4, Luminance8, Alpha8, Luminance8Alpha8)
|
|
|
|
SET_COPY_DECAY( RGB5_A1, R8, RG8, RGB565, RGB5_A1, Luminance8, Alpha8, Luminance8Alpha8)
|
|
|
|
SET_COPY_DECAY( RGB10_A2, R8, RG8, RGB8, RGB10_A2, Luminance8, Alpha8, MAX)
|
|
|
|
|
|
|
|
SET_COPY_DECAY(RGB10_A2UI, R8UI, RG8UI, RGB8UI, RGB10_A2UI, MAX, MAX, MAX)
|
|
|
|
|
|
|
|
SET_COPY_DECAY(SRGB8_ALPHA8, MAX, MAX, MAX, SRGB8_ALPHA8, MAX, Alpha8, MAX)
|
|
|
|
|
|
|
|
SET_COPY_DECAY(R11F_G11F_B10F, R16F, RG16F, R11F_G11F_B10F, MAX, Luminance16F, MAX, MAX)
|
|
|
|
|
|
|
|
#undef SET_COPY_DECAY
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool gAreFormatTablesInitialized = false;
|
|
|
|
|
|
|
|
static void
|
2015-11-25 07:15:29 +03:00
|
|
|
EnsureInitFormatTables(const StaticMutexAutoLock&) // Prove that you locked it!
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
|
|
|
if (MOZ_LIKELY(gAreFormatTablesInitialized))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gAreFormatTablesInitialized = true;
|
|
|
|
|
|
|
|
InitCompressedFormatInfo();
|
2015-11-25 07:15:29 +03:00
|
|
|
InitFormatInfo();
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Public funcs
|
|
|
|
|
|
|
|
StaticMutex gFormatMapMutex;
|
|
|
|
|
|
|
|
const FormatInfo*
|
2015-11-25 07:15:29 +03:00
|
|
|
GetFormat(EffectiveFormat format)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(gFormatMapMutex);
|
2015-11-25 07:15:29 +03:00
|
|
|
EnsureInitFormatTables(lock);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
return GetFormatInfo_NoLock(format);
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-06 23:41:12 +03:00
|
|
|
const FormatInfo*
|
|
|
|
FormatInfo::GetCopyDecayFormat(UnsizedFormat uf) const
|
|
|
|
{
|
|
|
|
return FindOrNull(this->copyDecayFormats, uf);
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
uint8_t
|
|
|
|
BytesPerPixel(const PackingInfo& packing)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
uint8_t bytesPerChannel;
|
|
|
|
switch (packing.type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_24_8:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV:
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
// Alright, that's all the fixed-size unpackTypes.
|
|
|
|
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
bytesPerChannel = 1;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
|
|
|
bytesPerChannel = 2;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_INT:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
bytesPerChannel = 4;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: invalid PackingInfo");
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
uint8_t channels;
|
|
|
|
switch (packing.format) {
|
|
|
|
case LOCAL_GL_RG:
|
|
|
|
case LOCAL_GL_RG_INTEGER:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
channels = 2;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
case LOCAL_GL_RGB_INTEGER:
|
|
|
|
channels = 3;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_RGBA_INTEGER:
|
|
|
|
channels = 4;
|
|
|
|
break;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
default:
|
|
|
|
channels = 1;
|
|
|
|
break;
|
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return bytesPerChannel * channels;
|
2015-11-24 08:55:59 +03:00
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FormatUsageAuthority
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool
|
|
|
|
FormatUsageInfo::IsUnpackValid(const PackingInfo& key,
|
|
|
|
const DriverUnpackInfo** const out_value) const
|
|
|
|
{
|
|
|
|
auto itr = validUnpacks.find(key);
|
|
|
|
if (itr == validUnpacks.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*out_value = &(itr->second);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
void
|
|
|
|
FormatUsageInfo::ResolveMaxSamples(gl::GLContext* gl)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!this->maxSamplesKnown);
|
|
|
|
MOZ_ASSERT(this->maxSamples == 0);
|
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
|
|
|
|
this->maxSamplesKnown = true;
|
|
|
|
|
|
|
|
const GLenum internalFormat = this->format->sizedFormat;
|
|
|
|
if (!internalFormat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::internalformat_query))
|
|
|
|
return; // Leave it at 0.
|
|
|
|
|
|
|
|
GLint maxSamplesGL = 0;
|
|
|
|
gl->fGetInternalformativ(LOCAL_GL_RENDERBUFFER, internalFormat, LOCAL_GL_SAMPLES, 1,
|
|
|
|
&maxSamplesGL);
|
|
|
|
|
|
|
|
this->maxSamples = maxSamplesGL;
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddSimpleUnsized(FormatUsageAuthority* fua, GLenum unpackFormat, GLenum unpackType,
|
|
|
|
EffectiveFormat effFormat)
|
|
|
|
{
|
|
|
|
auto usage = fua->EditUsage(effFormat);
|
|
|
|
usage->isFilterable = true;
|
|
|
|
|
|
|
|
const PackingInfo pi = {unpackFormat, unpackType};
|
|
|
|
const DriverUnpackInfo dui = {unpackFormat, unpackFormat, unpackType};
|
|
|
|
fua->AddTexUnpack(usage, pi, dui);
|
|
|
|
|
|
|
|
fua->AllowUnsizedTexFormat(pi, usage);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*static*/ const GLint FormatUsageInfo::kLuminanceSwizzleRGBA[4] = { LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_ONE };
|
|
|
|
/*static*/ const GLint FormatUsageInfo::kAlphaSwizzleRGBA[4] = { LOCAL_GL_ZERO,
|
|
|
|
LOCAL_GL_ZERO,
|
|
|
|
LOCAL_GL_ZERO,
|
|
|
|
LOCAL_GL_RED };
|
|
|
|
/*static*/ const GLint FormatUsageInfo::kLumAlphaSwizzleRGBA[4] = { LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_RED,
|
|
|
|
LOCAL_GL_GREEN };
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AddLegacyFormats_LA8(FormatUsageAuthority* fua, gl::GLContext* gl)
|
|
|
|
{
|
|
|
|
if (gl->IsCoreProfile()) {
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::texture_swizzle))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PackingInfo pi;
|
|
|
|
DriverUnpackInfo dui;
|
|
|
|
|
|
|
|
const auto fnAdd = [fua, &pi, &dui](EffectiveFormat effFormat,
|
|
|
|
const GLint* swizzle)
|
|
|
|
{
|
|
|
|
auto usage = fua->EditUsage(effFormat);
|
|
|
|
usage->isFilterable = true;
|
|
|
|
usage->textureSwizzleRGBA = swizzle;
|
|
|
|
|
|
|
|
fua->AddTexUnpack(usage, pi, dui);
|
|
|
|
|
|
|
|
fua->AllowUnsizedTexFormat(pi, usage);
|
|
|
|
};
|
|
|
|
|
|
|
|
pi = {LOCAL_GL_LUMINANCE, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
dui = {LOCAL_GL_R8, LOCAL_GL_RED, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
fnAdd(EffectiveFormat::Luminance8, FormatUsageInfo::kLuminanceSwizzleRGBA);
|
|
|
|
|
|
|
|
pi = {LOCAL_GL_ALPHA, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
dui = {LOCAL_GL_R8, LOCAL_GL_RED, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
fnAdd(EffectiveFormat::Alpha8, FormatUsageInfo::kAlphaSwizzleRGBA);
|
|
|
|
|
|
|
|
pi = {LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
dui = {LOCAL_GL_RG8, LOCAL_GL_RG, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
fnAdd(EffectiveFormat::Luminance8Alpha8, FormatUsageInfo::kLumAlphaSwizzleRGBA);
|
|
|
|
} else {
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_LUMINANCE , LOCAL_GL_UNSIGNED_BYTE, EffectiveFormat::Luminance8 );
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_ALPHA , LOCAL_GL_UNSIGNED_BYTE, EffectiveFormat::Alpha8 );
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_UNSIGNED_BYTE, EffectiveFormat::Luminance8Alpha8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AddUnsizedFormats(FormatUsageAuthority* fua, gl::GLContext* gl)
|
|
|
|
{
|
|
|
|
// GLES 2.0.25, p63, Table 3.4
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE , EffectiveFormat::RGBA8 );
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_SHORT_4_4_4_4, EffectiveFormat::RGBA4 );
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_SHORT_5_5_5_1, EffectiveFormat::RGB5_A1);
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_RGB , LOCAL_GL_UNSIGNED_BYTE , EffectiveFormat::RGB8 );
|
|
|
|
AddSimpleUnsized(fua, LOCAL_GL_RGB , LOCAL_GL_UNSIGNED_SHORT_5_6_5 , EffectiveFormat::RGB565 );
|
|
|
|
|
|
|
|
// L, A, LA
|
|
|
|
return AddLegacyFormats_LA8(fua, gl);
|
|
|
|
}
|
|
|
|
|
2016-06-06 23:41:12 +03:00
|
|
|
void
|
|
|
|
FormatUsageInfo::SetRenderable()
|
|
|
|
{
|
|
|
|
this->isRenderable = true;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
const auto format = this->format;
|
|
|
|
if (format->isColorFormat) {
|
|
|
|
const auto& map = format->copyDecayFormats;
|
|
|
|
const auto itr = map.find(format->unsizedFormat);
|
|
|
|
MOZ_ASSERT(itr != map.end());
|
|
|
|
MOZ_ASSERT(itr->second == format);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
UniquePtr<FormatUsageAuthority>
|
2015-11-25 07:15:29 +03:00
|
|
|
FormatUsageAuthority::CreateForWebGL1(gl::GLContext* gl)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
|
|
|
UniquePtr<FormatUsageAuthority> ret(new FormatUsageAuthority);
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto ptr = ret.get();
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-11-25 07:15:29 +03:00
|
|
|
// Usages
|
|
|
|
|
|
|
|
const auto fnSet = [ptr](EffectiveFormat effFormat, bool isRenderable,
|
|
|
|
bool isFilterable)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!ptr->GetUsage(effFormat));
|
|
|
|
|
|
|
|
auto usage = ptr->EditUsage(effFormat);
|
|
|
|
usage->isFilterable = isFilterable;
|
2016-06-06 23:41:12 +03:00
|
|
|
|
|
|
|
if (isRenderable) {
|
|
|
|
usage->SetRenderable();
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
};
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// GLES 2.0.25, p117, Table 4.5
|
|
|
|
// RGBA8 is made renderable in WebGL 1.0, "Framebuffer Object Attachments"
|
2015-11-25 07:15:29 +03:00
|
|
|
// render filter
|
|
|
|
// able able
|
2015-12-18 01:41:53 +03:00
|
|
|
fnSet(EffectiveFormat::RGBA8 , true, true);
|
|
|
|
fnSet(EffectiveFormat::RGBA4 , true, true);
|
|
|
|
fnSet(EffectiveFormat::RGB5_A1, true, true);
|
|
|
|
fnSet(EffectiveFormat::RGB565 , true, true);
|
|
|
|
|
|
|
|
// RGB8 is not guaranteed to be renderable, but we should allow it for web-compat.
|
|
|
|
// Min-capability mode should mark this as non-renderable.
|
|
|
|
fnSet(EffectiveFormat::RGB8, true, true);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
fnSet(EffectiveFormat::Luminance8Alpha8, false, true);
|
|
|
|
fnSet(EffectiveFormat::Luminance8 , false, true);
|
|
|
|
fnSet(EffectiveFormat::Alpha8 , false, true);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
fnSet(EffectiveFormat::DEPTH_COMPONENT16, true, false);
|
|
|
|
fnSet(EffectiveFormat::STENCIL_INDEX8 , true, false);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// Added in WebGL 1.0 spec:
|
2015-11-25 07:15:29 +03:00
|
|
|
fnSet(EffectiveFormat::DEPTH24_STENCIL8, true, false);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
// RB formats
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#define FOO(x) ptr->AllowRBFormat(LOCAL_GL_ ## x, ptr->GetUsage(EffectiveFormat::x))
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
FOO(RGBA4 );
|
|
|
|
FOO(RGB5_A1 );
|
|
|
|
FOO(RGB565 );
|
|
|
|
FOO(DEPTH_COMPONENT16);
|
|
|
|
FOO(STENCIL_INDEX8 );
|
|
|
|
//FOO(DEPTH24_STENCIL8 ); // WebGL 1 uses DEPTH_STENCIL instead of DEPTH24_STENCIL8.
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#undef FOO
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
ptr->AllowRBFormat(LOCAL_GL_DEPTH_STENCIL,
|
|
|
|
ptr->GetUsage(EffectiveFormat::DEPTH24_STENCIL8));
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!AddUnsizedFormats(ptr, gl))
|
|
|
|
return nullptr;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return Move(ret);
|
2015-07-11 02:34:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UniquePtr<FormatUsageAuthority>
|
2015-11-25 07:15:29 +03:00
|
|
|
FormatUsageAuthority::CreateForWebGL2(gl::GLContext* gl)
|
2015-07-11 02:34:45 +03:00
|
|
|
{
|
|
|
|
UniquePtr<FormatUsageAuthority> ret(new FormatUsageAuthority);
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto ptr = ret.get();
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4 p111-113
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto fnAddSizedUnpack = [ptr](EffectiveFormat effFormat, GLenum internalFormat,
|
|
|
|
GLenum unpackFormat, GLenum unpackType)
|
|
|
|
{
|
|
|
|
auto usage = ptr->EditUsage(effFormat);
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const PackingInfo pi = {unpackFormat, unpackType};
|
|
|
|
const DriverUnpackInfo dui = {internalFormat, unpackFormat, unpackType};
|
|
|
|
ptr->AddTexUnpack(usage, pi, dui);
|
|
|
|
};
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#define FOO(x) EffectiveFormat::x, LOCAL_GL_ ## x
|
2015-11-24 08:55:59 +03:00
|
|
|
|
|
|
|
// RGBA
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RGBA8 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA4 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA4 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB5_A1 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 );
|
|
|
|
fnAddSizedUnpack(FOO(RGB5_A1 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB5_A1 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV);
|
|
|
|
fnAddSizedUnpack(FOO(SRGB8_ALPHA8), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA8_SNORM ), LOCAL_GL_RGBA, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB10_A2 ), LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV);
|
|
|
|
fnAddSizedUnpack(FOO(RGBA16F ), LOCAL_GL_RGBA, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA16F ), LOCAL_GL_RGBA, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA32F ), LOCAL_GL_RGBA, LOCAL_GL_FLOAT );
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
// RGBA_INTEGER
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RGBA8UI ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA8I ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA16UI ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_UNSIGNED_SHORT );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA16I ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_SHORT );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA32UI ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(RGBA32I ), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_INT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB10_A2UI), LOCAL_GL_RGBA_INTEGER, LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RGB
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RGB8 ), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(SRGB8 ), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB565 ), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_SHORT_5_6_5 );
|
|
|
|
fnAddSizedUnpack(FOO(RGB565 ), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB8_SNORM ), LOCAL_GL_RGB, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(R11F_G11F_B10F), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV);
|
|
|
|
fnAddSizedUnpack(FOO(R11F_G11F_B10F), LOCAL_GL_RGB, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(R11F_G11F_B10F), LOCAL_GL_RGB, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB16F ), LOCAL_GL_RGB, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB16F ), LOCAL_GL_RGB, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB9_E5 ), LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV );
|
|
|
|
fnAddSizedUnpack(FOO(RGB9_E5 ), LOCAL_GL_RGB, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB9_E5 ), LOCAL_GL_RGB, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB32F ), LOCAL_GL_RGB, LOCAL_GL_FLOAT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RGB_INTEGER
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RGB8UI ), LOCAL_GL_RGB_INTEGER, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB8I ), LOCAL_GL_RGB_INTEGER, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RGB16UI), LOCAL_GL_RGB_INTEGER, LOCAL_GL_UNSIGNED_SHORT);
|
|
|
|
fnAddSizedUnpack(FOO(RGB16I ), LOCAL_GL_RGB_INTEGER, LOCAL_GL_SHORT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB32UI), LOCAL_GL_RGB_INTEGER, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(RGB32I ), LOCAL_GL_RGB_INTEGER, LOCAL_GL_INT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RG
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RG8 ), LOCAL_GL_RG, LOCAL_GL_UNSIGNED_BYTE);
|
|
|
|
fnAddSizedUnpack(FOO(RG8_SNORM), LOCAL_GL_RG, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RG16F ), LOCAL_GL_RG, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RG16F ), LOCAL_GL_RG, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(RG32F ), LOCAL_GL_RG, LOCAL_GL_FLOAT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RG_INTEGER
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(RG8UI ), LOCAL_GL_RG_INTEGER, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RG8I ), LOCAL_GL_RG_INTEGER, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(RG16UI), LOCAL_GL_RG_INTEGER, LOCAL_GL_UNSIGNED_SHORT);
|
|
|
|
fnAddSizedUnpack(FOO(RG16I ), LOCAL_GL_RG_INTEGER, LOCAL_GL_SHORT );
|
|
|
|
fnAddSizedUnpack(FOO(RG32UI), LOCAL_GL_RG_INTEGER, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(RG32I ), LOCAL_GL_RG_INTEGER, LOCAL_GL_INT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RED
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(R8 ), LOCAL_GL_RED, LOCAL_GL_UNSIGNED_BYTE);
|
|
|
|
fnAddSizedUnpack(FOO(R8_SNORM), LOCAL_GL_RED, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(R16F ), LOCAL_GL_RED, LOCAL_GL_HALF_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(R16F ), LOCAL_GL_RED, LOCAL_GL_FLOAT );
|
|
|
|
fnAddSizedUnpack(FOO(R32F ), LOCAL_GL_RED, LOCAL_GL_FLOAT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// RED_INTEGER
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(R8UI ), LOCAL_GL_RED_INTEGER, LOCAL_GL_UNSIGNED_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(R8I ), LOCAL_GL_RED_INTEGER, LOCAL_GL_BYTE );
|
|
|
|
fnAddSizedUnpack(FOO(R16UI), LOCAL_GL_RED_INTEGER, LOCAL_GL_UNSIGNED_SHORT);
|
|
|
|
fnAddSizedUnpack(FOO(R16I ), LOCAL_GL_RED_INTEGER, LOCAL_GL_SHORT );
|
|
|
|
fnAddSizedUnpack(FOO(R32UI), LOCAL_GL_RED_INTEGER, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(R32I ), LOCAL_GL_RED_INTEGER, LOCAL_GL_INT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// DEPTH_COMPONENT
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(DEPTH_COMPONENT16 ), LOCAL_GL_DEPTH_COMPONENT, LOCAL_GL_UNSIGNED_SHORT);
|
|
|
|
fnAddSizedUnpack(FOO(DEPTH_COMPONENT16 ), LOCAL_GL_DEPTH_COMPONENT, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(DEPTH_COMPONENT24 ), LOCAL_GL_DEPTH_COMPONENT, LOCAL_GL_UNSIGNED_INT );
|
|
|
|
fnAddSizedUnpack(FOO(DEPTH_COMPONENT32F), LOCAL_GL_DEPTH_COMPONENT, LOCAL_GL_FLOAT );
|
2015-07-11 02:34:45 +03:00
|
|
|
|
|
|
|
// DEPTH_STENCIL
|
2015-11-25 07:15:29 +03:00
|
|
|
fnAddSizedUnpack(FOO(DEPTH24_STENCIL8 ), LOCAL_GL_DEPTH_STENCIL, LOCAL_GL_UNSIGNED_INT_24_8 );
|
|
|
|
fnAddSizedUnpack(FOO(DEPTH32F_STENCIL8), LOCAL_GL_DEPTH_STENCIL, LOCAL_GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#undef FOO
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// For renderable, see GLES 3.0.4, p212 "Framebuffer Completeness"
|
|
|
|
// For filterable, see GLES 3.0.4, p161 "...a texture is complete unless..."
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const auto fnAllowES3TexFormat = [ptr](GLenum sizedFormat, EffectiveFormat effFormat,
|
|
|
|
bool isRenderable, bool isFilterable)
|
|
|
|
{
|
|
|
|
auto usage = ptr->EditUsage(effFormat);
|
|
|
|
usage->isFilterable = isFilterable;
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2016-06-06 23:41:12 +03:00
|
|
|
if (isRenderable) {
|
|
|
|
usage->SetRenderable();
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
ptr->AllowSizedTexFormat(sizedFormat, usage);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (isRenderable) {
|
|
|
|
ptr->AllowRBFormat(sizedFormat, usage);
|
|
|
|
}
|
|
|
|
};
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
#define FOO(x) LOCAL_GL_ ## x, EffectiveFormat::x
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4, p128-129 "Required Texture Formats"
|
|
|
|
// GLES 3.0.4, p130-132, table 3.13
|
|
|
|
// render filter
|
|
|
|
// able able
|
|
|
|
fnAllowES3TexFormat(FOO(R8 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(R8_SNORM ), false, true );
|
|
|
|
fnAllowES3TexFormat(FOO(RG8 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RG8_SNORM ), false, true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB8 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB8_SNORM ), false, true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB565 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA4 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB5_A1 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA8 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA8_SNORM), false, true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB10_A2 ), true , true );
|
|
|
|
fnAllowES3TexFormat(FOO(RGB10_A2UI ), true , false);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(SRGB8 ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(SRGB8_ALPHA8), true , true);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(R16F ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(RG16F ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB16F ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA16F), false, true);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(R32F ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG32F ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB32F ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA32F), false, false);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(R11F_G11F_B10F), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB9_E5 ), false, true);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(R8I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(R8UI ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(R16I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(R16UI), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(R32I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(R32UI), true, false);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(RG8I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG8UI ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG16I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG16UI), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG32I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RG32UI), true, false);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(RGB8I ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB8UI ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB16I ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB16UI), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB32I ), false, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGB32UI), false, false);
|
|
|
|
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA8I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA8UI ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA16I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA16UI), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA32I ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(RGBA32UI), true, false);
|
2015-07-11 02:34:45 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4, p133, table 3.14
|
|
|
|
fnAllowES3TexFormat(FOO(DEPTH_COMPONENT16 ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(DEPTH_COMPONENT24 ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(DEPTH_COMPONENT32F), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(DEPTH24_STENCIL8 ), true, false);
|
|
|
|
fnAllowES3TexFormat(FOO(DEPTH32F_STENCIL8 ), true, false);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4, p147, table 3.19
|
|
|
|
// GLES 3.0.4, p286+, $C.1 "ETC Compressed Texture Image Formats"
|
2015-12-19 06:05:11 +03:00
|
|
|
#if ALLOW_ES3_FORMATS
|
2015-11-25 07:15:29 +03:00
|
|
|
// Note that all compressed texture formats are filterable:
|
|
|
|
// GLES 3.0.4 p161:
|
|
|
|
// "[A] texture is complete unless any of the following conditions hold true:
|
|
|
|
// [...]
|
|
|
|
// * The effective internal format specified for the texture arrays is a sized
|
|
|
|
// internal color format that is not texture-filterable (see table 3.13) and [the
|
|
|
|
// mag filter requires filtering]."
|
|
|
|
// Compressed formats are not sized internal color formats, and indeed they are not
|
|
|
|
// listed in table 3.13.
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_RGB8_ETC2 ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_SRGB8_ETC2 ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_RGBA8_ETC2_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_R11_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_RG11_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_SIGNED_R11_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_SIGNED_RG11_EAC ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), false, true);
|
|
|
|
fnAllowES3TexFormat(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), false, true);
|
2015-12-19 06:05:11 +03:00
|
|
|
#endif
|
2015-11-25 07:15:29 +03:00
|
|
|
#undef FOO
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// GLES 3.0.4, p206, "Required Renderbuffer Formats":
|
|
|
|
// "Implementations are also required to support STENCIL_INDEX8. Requesting this
|
|
|
|
// internal format for a renderbuffer will allocate at least 8 stencil bit planes."
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto usage = ptr->EditUsage(EffectiveFormat::STENCIL_INDEX8);
|
2016-06-06 23:41:12 +03:00
|
|
|
usage->SetRenderable();
|
2015-11-25 07:15:29 +03:00
|
|
|
ptr->AllowRBFormat(LOCAL_GL_STENCIL_INDEX8, usage);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////
|
|
|
|
// Legacy formats
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!AddUnsizedFormats(ptr, gl))
|
|
|
|
return nullptr;
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-01-22 05:46:05 +03:00
|
|
|
ptr->AllowRBFormat(LOCAL_GL_DEPTH_STENCIL,
|
|
|
|
ptr->GetUsage(EffectiveFormat::DEPTH24_STENCIL8));
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (gfxPrefs::WebGL2CompatMode()) {
|
|
|
|
AddSimpleUnsized(ptr, LOCAL_GL_RGBA, LOCAL_GL_FLOAT, EffectiveFormat::RGBA32F);
|
|
|
|
AddSimpleUnsized(ptr, LOCAL_GL_RGB , LOCAL_GL_FLOAT, EffectiveFormat::RGB32F );
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
AddSimpleUnsized(ptr, LOCAL_GL_RGBA, LOCAL_GL_HALF_FLOAT_OES, EffectiveFormat::RGBA16F);
|
|
|
|
AddSimpleUnsized(ptr, LOCAL_GL_RGB , LOCAL_GL_HALF_FLOAT_OES, EffectiveFormat::RGB16F );
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2016-06-06 23:41:12 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return Move(ret);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
FormatUsageAuthority::AddTexUnpack(FormatUsageInfo* usage, const PackingInfo& pi,
|
|
|
|
const DriverUnpackInfo& dui)
|
|
|
|
{
|
|
|
|
// Don't AlwaysInsert here, since we'll see duplicates from sized and unsized formats.
|
|
|
|
auto res = usage->validUnpacks.insert({ pi, dui });
|
|
|
|
auto itr = res.first;
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!usage->idealUnpack) {
|
|
|
|
// First one!
|
|
|
|
usage->idealUnpack = &(itr->second);
|
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
mValidTexUnpackFormats.insert(pi.format);
|
|
|
|
mValidTexUnpackTypes.insert(pi.type);
|
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
static bool
|
|
|
|
Contains(const std::set<GLenum>& set, GLenum key)
|
|
|
|
{
|
|
|
|
return set.find(key) != set.end();
|
|
|
|
}
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
bool
|
|
|
|
FormatUsageAuthority::IsInternalFormatEnumValid(GLenum internalFormat) const
|
|
|
|
{
|
|
|
|
return Contains(mValidTexInternalFormats, internalFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FormatUsageAuthority::AreUnpackEnumsValid(GLenum unpackFormat, GLenum unpackType) const
|
|
|
|
{
|
|
|
|
return (Contains(mValidTexUnpackFormats, unpackFormat) &&
|
|
|
|
Contains(mValidTexUnpackTypes, unpackType));
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
FormatUsageAuthority::AllowRBFormat(GLenum sizedFormat, const FormatUsageInfo* usage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!usage->format->compression);
|
|
|
|
MOZ_ASSERT(usage->format->sizedFormat);
|
2016-06-06 23:41:12 +03:00
|
|
|
MOZ_ASSERT(usage->IsRenderable());
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
AlwaysInsert(mRBFormatMap, sizedFormat, usage);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
FormatUsageAuthority::AllowSizedTexFormat(GLenum sizedFormat,
|
|
|
|
const FormatUsageInfo* usage)
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
if (usage->format->compression) {
|
|
|
|
MOZ_ASSERT(usage->isFilterable, "Compressed formats should be filterable.");
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(usage->validUnpacks.size() && usage->idealUnpack,
|
|
|
|
"AddTexUnpack() first.");
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
AlwaysInsert(mSizedTexFormatMap, sizedFormat, usage);
|
|
|
|
|
|
|
|
mValidTexInternalFormats.insert(sizedFormat);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
void
|
|
|
|
FormatUsageAuthority::AllowUnsizedTexFormat(const PackingInfo& pi,
|
|
|
|
const FormatUsageInfo* usage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!usage->format->compression);
|
|
|
|
MOZ_ASSERT(usage->validUnpacks.size() && usage->idealUnpack, "AddTexUnpack() first.");
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
AlwaysInsert(mUnsizedTexFormatMap, pi, usage);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
mValidTexInternalFormats.insert(pi.format);
|
|
|
|
mValidTexUnpackFormats.insert(pi.format);
|
|
|
|
mValidTexUnpackTypes.insert(pi.type);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const FormatUsageInfo*
|
|
|
|
FormatUsageAuthority::GetRBUsage(GLenum sizedFormat) const
|
|
|
|
{
|
|
|
|
return FindOrNull(mRBFormatMap, sizedFormat);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const FormatUsageInfo*
|
|
|
|
FormatUsageAuthority::GetSizedTexUsage(GLenum sizedFormat) const
|
|
|
|
{
|
|
|
|
return FindOrNull(mSizedTexFormatMap, sizedFormat);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const FormatUsageInfo*
|
|
|
|
FormatUsageAuthority::GetUnsizedTexUsage(const PackingInfo& pi) const
|
|
|
|
{
|
|
|
|
return FindOrNull(mUnsizedTexFormatMap, pi);
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
FormatUsageInfo*
|
|
|
|
FormatUsageAuthority::EditUsage(EffectiveFormat format)
|
|
|
|
{
|
|
|
|
auto itr = mUsageMap.find(format);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (itr == mUsageMap.end()) {
|
|
|
|
const FormatInfo* formatInfo = GetFormat(format);
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(formatInfo, "GFX: no format info set.");
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
FormatUsageInfo usage(formatInfo);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
auto res = mUsageMap.insert({ format, usage });
|
|
|
|
DebugOnly<bool> didInsert = res.second;
|
|
|
|
MOZ_ASSERT(didInsert);
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
itr = res.first;
|
|
|
|
}
|
2015-08-06 09:31:00 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
return &(itr->second);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const FormatUsageInfo*
|
|
|
|
FormatUsageAuthority::GetUsage(EffectiveFormat format) const
|
2015-08-06 09:31:00 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
auto itr = mUsageMap.find(format);
|
|
|
|
if (itr == mUsageMap.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &(itr->second);
|
2015-08-06 09:31:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-07-11 02:34:45 +03:00
|
|
|
} // namespace webgl
|
|
|
|
} // namespace mozilla
|