Hash :
dab84368
Author :
Date :
2015-03-02T15:43:57
Add texture format utilities for GL and generate GL texture caps. BUG=angleproject:884 Change-Id: Ib1b13f59a6b21399c4b35695c704c369f572914e Reviewed-on: https://chromium-review.googlesource.com/264399 Tested-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// formatutilsgl.cpp: Queries for GL image formats and their translations to native
// GL formats.
#include "libANGLE/renderer/gl/formatutilsgl.h"
#include <map>
namespace rx
{
namespace nativegl
{
// Information about internal formats
static bool AlwaysSupported(GLuint, GLuint, const std::vector<std::string> &)
{
return true;
}
static bool UnimplementedSupport(GLuint, GLuint, const std::vector<std::string> &)
{
return false;
}
static bool NeverSupported(GLuint, GLuint, const std::vector<std::string> &)
{
return false;
}
template <GLuint minMajorVersion, GLuint minMinorVersion>
static bool RequireGL(GLuint major, GLuint minor, const std::vector<std::string> &)
{
return major > minMajorVersion || (major == minMajorVersion && minor >= minMinorVersion);
}
InternalFormat::InternalFormat()
: textureSupport(NeverSupported),
renderSupport(NeverSupported),
filterSupport(NeverSupported)
{
}
typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
// A helper function to insert data into the format map with fewer characters.
static inline void InsertFormatMapping(InternalFormatInfoMap *map, GLenum internalFormat,
InternalFormat::SupportCheckFunction textureSupport,
InternalFormat::SupportCheckFunction renderSupport,
InternalFormat::SupportCheckFunction filterSupport)
{
InternalFormat formatInfo;
formatInfo.textureSupport = textureSupport;
formatInfo.renderSupport = renderSupport;
formatInfo.filterSupport = filterSupport;
map->insert(std::make_pair(internalFormat, formatInfo));
}
static InternalFormatInfoMap BuildInternalFormatInfoMap()
{
InternalFormatInfoMap map;
// From ES 3.0.1 spec, table 3.12
InsertFormatMapping(&map, GL_NONE, NeverSupported, NeverSupported, NeverSupported);
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_R8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R8_SNORM, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG8_SNORM, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB8, AlwaysSupported, AlwaysSupported, AlwaysSupported );
InsertFormatMapping(&map, GL_RGB8_SNORM, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB565, AlwaysSupported, AlwaysSupported, AlwaysSupported );
InsertFormatMapping(&map, GL_RGBA4, AlwaysSupported, AlwaysSupported, AlwaysSupported );
InsertFormatMapping(&map, GL_RGB5_A1, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA8, AlwaysSupported, AlwaysSupported, AlwaysSupported );
InsertFormatMapping(&map, GL_RGBA8_SNORM, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB10_A2, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB10_A2UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_SRGB8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_SRGB8_ALPHA8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R11F_G11F_B10F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB9_E5, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R8I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R8UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R16I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R16UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R32I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R32UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG8I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG8UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG16I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG16UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG32I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG32UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB8I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB8UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB16I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB16UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB32I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB32UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA8I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA8UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA16I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA16UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA32I, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA32UI, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_BGRA8_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// Floating point formats
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_R16F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG16F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB16F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA16F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_R32F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG32F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB32F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA32F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// Depth stencil formats
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_DEPTH_COMPONENT16, AlwaysSupported, AlwaysSupported, NeverSupported );
InsertFormatMapping(&map, GL_DEPTH_COMPONENT24, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH_COMPONENT32F, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH_COMPONENT32_OES, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH24_STENCIL8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH32F_STENCIL8, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_STENCIL_INDEX8, AlwaysSupported, AlwaysSupported, NeverSupported );
// Luminance alpha formats
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_ALPHA8_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE8_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_ALPHA32F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE32F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_ALPHA16F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE16F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE8_ALPHA8_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE_ALPHA32F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE_ALPHA16F_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// Unsized formats
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_ALPHA, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RED, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RED_INTEGER, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RG_INTEGER, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGB_INTEGER, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_RGBA_INTEGER, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_BGRA_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH_COMPONENT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_DEPTH_STENCIL, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_SRGB_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// Compressed formats, From ES 3.0.1 spec, table 3.16
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_COMPRESSED_R11_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_R11_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_RG11_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_RG11_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_RGB8_ETC2, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ETC2, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// From GL_EXT_texture_compression_dxt1
// | Internal format | Texture support | Render support | Filter support |
InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// From GL_ANGLE_texture_compression_dxt3
InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
// From GL_ANGLE_texture_compression_dxt5
InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport);
return map;
}
static const InternalFormatInfoMap &GetInternalFormatMap()
{
static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
return formatMap;
}
const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
{
const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
if (iter != formatMap.end())
{
return iter->second;
}
else
{
static const InternalFormat defaultInternalFormat;
return defaultInternalFormat;
}
}
}
}