shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 3 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // formatutils.cpp: Queries for GL image formats. |
| 9 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 10 | #include "common/mathutil.h" |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 11 | #include "libGLESv2/formatutils.h" |
| 12 | #include "libGLESv2/Context.h" |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 13 | #include "libGLESv2/Framebuffer.h" |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 14 | #include "libGLESv2/renderer/Renderer.h" |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 15 | #include "libGLESv2/renderer/imageformats.h" |
| 16 | #include "libGLESv2/renderer/copyimage.h" |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 17 | |
| 18 | namespace gl |
| 19 | { |
| 20 | |
| 21 | // ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation |
| 22 | // can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid |
| 23 | // format and type combinations. |
| 24 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 25 | struct FormatTypeInfo |
| 26 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 27 | GLenum mInternalFormat; |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 28 | ColorWriteFunction mColorWriteFunction; |
| 29 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 30 | FormatTypeInfo(GLenum internalFormat, ColorWriteFunction writeFunc) |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 31 | : mInternalFormat(internalFormat), mColorWriteFunction(writeFunc) |
| 32 | { } |
| 33 | }; |
| 34 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 35 | typedef std::pair<GLenum, GLenum> FormatTypePair; |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 36 | typedef std::pair<FormatTypePair, FormatTypeInfo> FormatPair; |
| 37 | typedef std::map<FormatTypePair, FormatTypeInfo> FormatMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 38 | |
Jamie Madill | 89a0bf5 | 2013-09-18 14:36:24 -0400 | [diff] [blame] | 39 | // A helper function to insert data into the format map with fewer characters. |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 40 | static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat, ColorWriteFunction writeFunc) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 41 | { |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 42 | map->insert(FormatPair(FormatTypePair(format, type), FormatTypeInfo(internalFormat, writeFunc))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 45 | FormatMap BuildES2FormatMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 46 | { |
| 47 | FormatMap map; |
| 48 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 49 | using namespace rx; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 50 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 51 | // | Format | Type | Internal format | Color write function | |
| 52 | InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> ); |
| 53 | InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> ); |
| 54 | InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 55 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 56 | InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> ); |
| 57 | InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> ); |
| 58 | InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 59 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 60 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> ); |
| 61 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> ); |
| 62 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 63 | |
Geoff Lang | 632192d | 2013-10-04 13:40:46 -0400 | [diff] [blame] | 64 | InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8_EXT, WriteColor<R8, GLfloat> ); |
| 65 | InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F_EXT, WriteColor<R32F, GLfloat> ); |
| 66 | InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F_EXT, WriteColor<R16F, GLfloat> ); |
| 67 | |
| 68 | InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8_EXT, WriteColor<R8G8, GLfloat> ); |
| 69 | InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F_EXT, WriteColor<R32G32F, GLfloat> ); |
| 70 | InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F_EXT, WriteColor<R16G16F, GLfloat> ); |
| 71 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 72 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES, WriteColor<R8G8B8, GLfloat> ); |
| 73 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> ); |
| 74 | InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT, WriteColor<R32G32B32F, GLfloat> ); |
| 75 | InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT, WriteColor<R16G16B16F, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 76 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 77 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES, WriteColor<R8G8B8A8, GLfloat> ); |
| 78 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> ); |
| 79 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> ); |
| 80 | InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT, WriteColor<R32G32B32A32F, GLfloat>); |
| 81 | InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT, WriteColor<R16G16B16A16F, GLfloat>); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 82 | |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 83 | InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8, WriteColor<R8G8B8, GLfloat> ); |
| 84 | InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8, WriteColor<R8G8B8A8, GLfloat> ); |
| 85 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 86 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> ); |
| 87 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> ); |
| 88 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 89 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 90 | InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL ); |
| 91 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL ); |
| 92 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL ); |
| 93 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 94 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 95 | InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL ); |
| 96 | InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES, NULL ); |
| 97 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 98 | InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8, NULL ); |
| 99 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 100 | InsertFormatMapping(&map, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_DEPTH24_STENCIL8_OES, NULL ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 101 | |
| 102 | return map; |
| 103 | } |
| 104 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 105 | FormatMap BuildES3FormatMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 106 | { |
| 107 | FormatMap map; |
| 108 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 109 | using namespace rx; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 110 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 111 | // | Format | Type | Internal format | Color write function | |
| 112 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8, WriteColor<R8G8B8A8, GLfloat> ); |
| 113 | InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM, WriteColor<R8G8B8A8S, GLfloat> ); |
| 114 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> ); |
| 115 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> ); |
| 116 | InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, WriteColor<R10G10B10A2, GLfloat> ); |
| 117 | InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F, WriteColor<R32G32B32A32F, GLfloat>); |
| 118 | InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, WriteColor<R16G16B16A16F, GLfloat>); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 119 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 120 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, WriteColor<R8G8B8A8, GLuint> ); |
| 121 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, WriteColor<R8G8B8A8S, GLint> ); |
| 122 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, WriteColor<R16G16B16A16, GLuint> ); |
| 123 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, WriteColor<R16G16B16A16S, GLint> ); |
| 124 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, WriteColor<R32G32B32A32, GLuint> ); |
| 125 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, WriteColor<R32G32B32A32S, GLint> ); |
Jamie Madill | 18a4470 | 2013-09-09 16:24:04 -0400 | [diff] [blame] | 126 | InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, WriteColor<R10G10B10A2, GLuint> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 127 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 128 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> ); |
| 129 | InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> ); |
| 130 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> ); |
| 131 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> ); |
| 132 | InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> ); |
| 133 | InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> ); |
| 134 | InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 135 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 136 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> ); |
| 137 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> ); |
| 138 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> ); |
| 139 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> ); |
| 140 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> ); |
| 141 | InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 142 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 143 | InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> ); |
| 144 | InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> ); |
| 145 | InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> ); |
| 146 | InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> ); |
| 147 | |
| 148 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> ); |
| 149 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> ); |
| 150 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> ); |
| 151 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> ); |
| 152 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> ); |
| 153 | InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> ); |
| 154 | |
| 155 | InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> ); |
| 156 | InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> ); |
| 157 | InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> ); |
| 158 | InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> ); |
| 159 | |
| 160 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> ); |
| 161 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> ); |
| 162 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> ); |
| 163 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> ); |
| 164 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> ); |
| 165 | InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> ); |
| 166 | |
| 167 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> ); |
| 168 | InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> ); |
| 169 | InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> ); |
| 170 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> ); |
| 171 | InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> ); |
| 172 | InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> ); |
| 173 | InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> ); |
| 174 | InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> ); |
| 175 | InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> ); |
| 176 | |
| 177 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> ); |
| 178 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> ); |
| 179 | InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> ); |
| 180 | |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 181 | InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8, WriteColor<R8G8B8, GLfloat> ); |
| 182 | InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8, WriteColor<R8G8B8A8, GLfloat> ); |
| 183 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 184 | InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL ); |
| 185 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL ); |
| 186 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL ); |
| 187 | InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL ); |
| 188 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 189 | InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL ); |
| 190 | InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL ); |
| 191 | InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL ); |
| 192 | |
| 193 | InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL ); |
| 194 | InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8, NULL ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 195 | |
| 196 | return map; |
| 197 | } |
| 198 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 199 | static const FormatMap &GetFormatMap(GLuint clientVersion) |
| 200 | { |
| 201 | if (clientVersion == 2) |
| 202 | { |
| 203 | static const FormatMap formats = BuildES2FormatMap(); |
| 204 | return formats; |
| 205 | } |
| 206 | else if (clientVersion == 3) |
| 207 | { |
| 208 | static const FormatMap formats = BuildES3FormatMap(); |
| 209 | return formats; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | UNREACHABLE(); |
| 214 | static FormatMap emptyMap; |
| 215 | return emptyMap; |
| 216 | } |
| 217 | } |
| 218 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 219 | struct FormatInfo |
| 220 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 221 | GLenum mInternalformat; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 222 | GLenum mFormat; |
| 223 | GLenum mType; |
| 224 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 225 | FormatInfo(GLenum internalformat, GLenum format, GLenum type) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 226 | : mInternalformat(internalformat), mFormat(format), mType(type) { } |
| 227 | |
| 228 | bool operator<(const FormatInfo& other) const |
| 229 | { |
| 230 | return memcmp(this, &other, sizeof(FormatInfo)) < 0; |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | // ES3 has a specific set of permutations of internal formats, formats and types which are acceptable. |
| 235 | typedef std::set<FormatInfo> ES3FormatSet; |
| 236 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 237 | ES3FormatSet BuildES3FormatSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 238 | { |
| 239 | ES3FormatSet set; |
| 240 | |
| 241 | // Format combinations from ES 3.0.1 spec, table 3.2 |
| 242 | |
| 243 | // | Internal format | Format | Type | |
| 244 | // | | | | |
| 245 | set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 246 | set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 247 | set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 248 | set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 249 | set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE )); |
| 250 | set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 )); |
| 251 | set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV )); |
| 252 | set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV )); |
shannonwoods@chromium.org | d03f897 | 2013-05-30 00:17:07 +0000 | [diff] [blame] | 253 | set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 )); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 254 | set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT )); |
| 255 | set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT )); |
| 256 | set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT )); |
| 257 | set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE )); |
| 258 | set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE )); |
| 259 | set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT )); |
| 260 | set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT )); |
| 261 | set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT )); |
| 262 | set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT )); |
| 263 | set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV )); |
| 264 | set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE )); |
| 265 | set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE )); |
| 266 | set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE )); |
| 267 | set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE )); |
| 268 | set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 )); |
| 269 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV )); |
| 270 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV )); |
| 271 | set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT )); |
| 272 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT )); |
| 273 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT )); |
| 274 | set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT )); |
| 275 | set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT )); |
| 276 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT )); |
| 277 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT )); |
| 278 | set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE )); |
| 279 | set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE )); |
| 280 | set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT )); |
| 281 | set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT )); |
| 282 | set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT )); |
| 283 | set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT )); |
| 284 | set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE )); |
| 285 | set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE )); |
| 286 | set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT )); |
| 287 | set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT )); |
| 288 | set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT )); |
| 289 | set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE )); |
| 290 | set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE )); |
| 291 | set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT )); |
| 292 | set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT )); |
| 293 | set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT )); |
| 294 | set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT )); |
| 295 | set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE )); |
| 296 | set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE )); |
| 297 | set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT )); |
| 298 | set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT )); |
| 299 | set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT )); |
| 300 | set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE )); |
| 301 | set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE )); |
| 302 | set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT )); |
| 303 | set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT )); |
| 304 | set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT )); |
| 305 | set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT )); |
| 306 | |
| 307 | // Unsized formats |
| 308 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 309 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 )); |
| 310 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 )); |
| 311 | set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE )); |
| 312 | set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 )); |
| 313 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE )); |
| 314 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE )); |
| 315 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE )); |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 316 | set.insert(FormatInfo(GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE )); |
| 317 | set.insert(FormatInfo(GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE )); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 318 | |
| 319 | // Depth stencil formats |
| 320 | set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT )); |
| 321 | set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT )); |
| 322 | set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT )); |
| 323 | set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT )); |
| 324 | set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 )); |
| 325 | set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV)); |
| 326 | |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 327 | // From GL_EXT_sRGB |
| 328 | set.insert(FormatInfo(GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE )); |
| 329 | set.insert(FormatInfo(GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE )); |
| 330 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 331 | // From GL_OES_texture_float |
| 332 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT )); |
| 333 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT )); |
| 334 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT )); |
| 335 | |
| 336 | // From GL_OES_texture_half_float |
| 337 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT )); |
| 338 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT )); |
| 339 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT )); |
| 340 | |
Geoff Lang | cdacacd | 2014-04-24 12:01:56 -0400 | [diff] [blame] | 341 | // From GL_EXT_texture_format_BGRA8888 |
| 342 | set.insert(FormatInfo(GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 343 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 344 | // From GL_EXT_texture_storage |
| 345 | // | Internal format | Format | Type | |
| 346 | // | | | | |
| 347 | set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE )); |
| 348 | set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE )); |
| 349 | set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE )); |
| 350 | set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT )); |
| 351 | set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT )); |
| 352 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT )); |
| 353 | set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT )); |
| 354 | set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT )); |
| 355 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT )); |
| 356 | |
Geoff Lang | cdacacd | 2014-04-24 12:01:56 -0400 | [diff] [blame] | 357 | // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888 |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 358 | set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 359 | set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT)); |
| 360 | set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 361 | set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT)); |
| 362 | set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 363 | |
| 364 | // From GL_ANGLE_depth_texture |
| 365 | set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES )); |
| 366 | |
| 367 | // Compressed formats |
| 368 | // From ES 3.0.1 spec, table 3.16 |
| 369 | // | Internal format | Format | Type | |
| 370 | // | | | | |
| 371 | set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 372 | set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 373 | set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 374 | set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE)); |
| 375 | set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE)); |
| 376 | set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE)); |
| 377 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE)); |
| 378 | set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE)); |
| 379 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE)); |
| 380 | set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE)); |
| 381 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE)); |
| 382 | |
| 383 | |
| 384 | // From GL_EXT_texture_compression_dxt1 |
| 385 | set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE)); |
| 386 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE)); |
| 387 | |
| 388 | // From GL_ANGLE_texture_compression_dxt3 |
| 389 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE)); |
| 390 | |
| 391 | // From GL_ANGLE_texture_compression_dxt5 |
| 392 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE)); |
| 393 | |
| 394 | return set; |
| 395 | } |
| 396 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 397 | static const ES3FormatSet &GetES3FormatSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 398 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 399 | static const ES3FormatSet es3FormatSet = BuildES3FormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 400 | return es3FormatSet; |
| 401 | } |
| 402 | |
| 403 | // Map of sizes of input types |
| 404 | struct TypeInfo |
| 405 | { |
| 406 | GLuint mTypeBytes; |
| 407 | bool mSpecialInterpretation; |
| 408 | |
| 409 | TypeInfo() |
| 410 | : mTypeBytes(0), mSpecialInterpretation(false) { } |
| 411 | |
| 412 | TypeInfo(GLuint typeBytes, bool specialInterpretation) |
| 413 | : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { } |
| 414 | |
| 415 | bool operator<(const TypeInfo& other) const |
| 416 | { |
| 417 | return memcmp(this, &other, sizeof(TypeInfo)) < 0; |
| 418 | } |
| 419 | }; |
| 420 | |
| 421 | typedef std::pair<GLenum, TypeInfo> TypeInfoPair; |
| 422 | typedef std::map<GLenum, TypeInfo> TypeInfoMap; |
| 423 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 424 | static TypeInfoMap BuildTypeInfoMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 425 | { |
| 426 | TypeInfoMap map; |
| 427 | |
| 428 | map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false))); |
| 429 | map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false))); |
| 430 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false))); |
| 431 | map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false))); |
| 432 | map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false))); |
| 433 | map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false))); |
| 434 | map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false))); |
Jamie Madill | a940ae4 | 2013-07-08 17:48:34 -0400 | [diff] [blame] | 435 | map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 436 | map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false))); |
| 437 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true ))); |
| 438 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true ))); |
| 439 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true ))); |
| 440 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true ))); |
| 441 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true ))); |
| 442 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true ))); |
| 443 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true ))); |
| 444 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true ))); |
| 445 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 446 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true ))); |
Geoff Lang | 85ea9ab | 2013-10-10 13:50:34 -0400 | [diff] [blame] | 447 | map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 448 | |
| 449 | return map; |
| 450 | } |
| 451 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 452 | static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 453 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 454 | static const TypeInfoMap infoMap = BuildTypeInfoMap(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 455 | TypeInfoMap::const_iterator iter = infoMap.find(type); |
| 456 | if (iter != infoMap.end()) |
| 457 | { |
| 458 | if (outTypeInfo) |
| 459 | { |
| 460 | *outTypeInfo = iter->second; |
| 461 | } |
| 462 | return true; |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | return false; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // Information about internal formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 471 | typedef bool (*SupportCheckFunction)(const Extensions &); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 472 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 473 | static bool AlwaysSupported(const Extensions &) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 474 | { |
| 475 | return true; |
| 476 | } |
| 477 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 478 | static bool UnimplementedSupport(const Extensions &) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 479 | { |
| 480 | UNIMPLEMENTED(); |
| 481 | return false; |
| 482 | } |
| 483 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 484 | static bool NeverSupported(const Extensions &) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 485 | { |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 486 | return false; |
| 487 | } |
| 488 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 489 | // Pointer to a boolean memeber of the Extensions struct |
| 490 | typedef bool(Extensions::*ExtensionBool); |
| 491 | |
| 492 | // Check support for a single extension |
| 493 | template <ExtensionBool bool1> |
| 494 | static bool CheckSupport(const Extensions &caps) |
| 495 | { |
| 496 | return (caps.*bool1); |
| 497 | } |
| 498 | |
| 499 | // Check support for two extensions |
| 500 | template <ExtensionBool bool1, ExtensionBool bool2> |
| 501 | static bool CheckSupport(const Extensions &caps) |
| 502 | { |
| 503 | return (caps.*bool1) && (caps.*bool2); |
| 504 | } |
| 505 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 506 | struct InternalFormatInfo |
| 507 | { |
| 508 | GLuint mRedBits; |
| 509 | GLuint mGreenBits; |
| 510 | GLuint mBlueBits; |
| 511 | |
| 512 | GLuint mLuminanceBits; |
| 513 | |
| 514 | GLuint mAlphaBits; |
| 515 | GLuint mSharedBits; |
| 516 | |
| 517 | GLuint mDepthBits; |
| 518 | GLuint mStencilBits; |
| 519 | |
| 520 | GLuint mPixelBits; |
| 521 | |
| 522 | GLuint mComponentCount; |
| 523 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 524 | GLuint mCompressedBlockWidth; |
| 525 | GLuint mCompressedBlockHeight; |
| 526 | |
| 527 | GLenum mFormat; |
| 528 | GLenum mType; |
| 529 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 530 | GLenum mComponentType; |
| 531 | GLenum mColorEncoding; |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 532 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 533 | bool mIsCompressed; |
shannonwoods@chromium.org | e81ea50 | 2013-05-30 00:16:53 +0000 | [diff] [blame] | 534 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 535 | SupportCheckFunction mSupportFunction; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 536 | |
| 537 | InternalFormatInfo() : mRedBits(0), mGreenBits(0), mBlueBits(0), mLuminanceBits(0), mAlphaBits(0), mSharedBits(0), mDepthBits(0), mStencilBits(0), |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 538 | mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE), |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 539 | mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mSupportFunction(NeverSupported) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 540 | { |
| 541 | } |
| 542 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 543 | static InternalFormatInfo UnsizedFormat(GLenum format, SupportCheckFunction supportFunction) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 544 | { |
| 545 | InternalFormatInfo formatInfo; |
| 546 | formatInfo.mFormat = format; |
| 547 | formatInfo.mSupportFunction = supportFunction; |
| 548 | return formatInfo; |
| 549 | } |
| 550 | |
| 551 | static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared, |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 552 | GLenum format, GLenum type, GLenum componentType, bool srgb, |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 553 | SupportCheckFunction supportFunction) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 554 | { |
| 555 | InternalFormatInfo formatInfo; |
| 556 | formatInfo.mRedBits = red; |
| 557 | formatInfo.mGreenBits = green; |
| 558 | formatInfo.mBlueBits = blue; |
| 559 | formatInfo.mAlphaBits = alpha; |
| 560 | formatInfo.mSharedBits = shared; |
| 561 | formatInfo.mPixelBits = red + green + blue + alpha + shared; |
| 562 | formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 563 | formatInfo.mFormat = format; |
| 564 | formatInfo.mType = type; |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 565 | formatInfo.mComponentType = componentType; |
| 566 | formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 567 | formatInfo.mSupportFunction = supportFunction; |
| 568 | return formatInfo; |
| 569 | } |
| 570 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 571 | static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType, |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 572 | SupportCheckFunction supportFunction) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 573 | { |
| 574 | InternalFormatInfo formatInfo; |
| 575 | formatInfo.mLuminanceBits = luminance; |
| 576 | formatInfo.mAlphaBits = alpha; |
| 577 | formatInfo.mPixelBits = luminance + alpha; |
| 578 | formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 579 | formatInfo.mFormat = format; |
| 580 | formatInfo.mType = type; |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 581 | formatInfo.mComponentType = componentType; |
| 582 | formatInfo.mColorEncoding = GL_LINEAR; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 583 | formatInfo.mSupportFunction = supportFunction; |
| 584 | return formatInfo; |
| 585 | } |
| 586 | |
Geoff Lang | 85ea9ab | 2013-10-10 13:50:34 -0400 | [diff] [blame] | 587 | static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format, |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 588 | GLenum type, GLenum componentType, SupportCheckFunction supportFunction) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 589 | { |
| 590 | InternalFormatInfo formatInfo; |
Geoff Lang | 85ea9ab | 2013-10-10 13:50:34 -0400 | [diff] [blame] | 591 | formatInfo.mDepthBits = depthBits; |
| 592 | formatInfo.mStencilBits = stencilBits; |
| 593 | formatInfo.mPixelBits = depthBits + stencilBits + unusedBits; |
| 594 | formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 595 | formatInfo.mFormat = format; |
| 596 | formatInfo.mType = type; |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 597 | formatInfo.mComponentType = componentType; |
| 598 | formatInfo.mColorEncoding = GL_LINEAR; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 599 | formatInfo.mSupportFunction = supportFunction; |
| 600 | return formatInfo; |
| 601 | } |
| 602 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 603 | static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize, |
| 604 | GLuint componentCount, GLenum format, GLenum type, bool srgb, |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 605 | SupportCheckFunction supportFunction) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 606 | { |
| 607 | InternalFormatInfo formatInfo; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 608 | formatInfo.mCompressedBlockWidth = compressedBlockWidth; |
| 609 | formatInfo.mCompressedBlockHeight = compressedBlockHeight; |
| 610 | formatInfo.mPixelBits = compressedBlockSize; |
| 611 | formatInfo.mComponentCount = componentCount; |
| 612 | formatInfo.mFormat = format; |
| 613 | formatInfo.mType = type; |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 614 | formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED; |
| 615 | formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR); |
| 616 | formatInfo.mIsCompressed = true; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 617 | formatInfo.mSupportFunction = supportFunction; |
| 618 | return formatInfo; |
| 619 | } |
| 620 | }; |
| 621 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 622 | typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair; |
| 623 | typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 624 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 625 | static InternalFormatInfoMap BuildES3InternalFormatInfoMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 626 | { |
| 627 | InternalFormatInfoMap map; |
| 628 | |
| 629 | // From ES 3.0.1 spec, table 3.12 |
| 630 | map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo())); |
| 631 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 632 | // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Supported | |
| 633 | map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 634 | map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported))); |
| 635 | map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 636 | map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported))); |
| 637 | map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 638 | map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported))); |
| 639 | map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 640 | map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 641 | map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 642 | map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 643 | map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported))); |
| 644 | map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported))); |
| 645 | map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 646 | map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported))); |
| 647 | map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported))); |
| 648 | map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, AlwaysSupported))); |
| 649 | map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, AlwaysSupported))); |
| 650 | map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported))); |
| 651 | map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 652 | map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported))); |
| 653 | map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 654 | map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported))); |
| 655 | map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 656 | map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported))); |
| 657 | map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 658 | map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported))); |
| 659 | map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 660 | map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported))); |
| 661 | map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 662 | map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported))); |
| 663 | map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 664 | map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported))); |
| 665 | map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 666 | map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, AlwaysSupported))); |
| 667 | map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 668 | map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported))); |
| 669 | map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 670 | map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported))); |
| 671 | map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
| 672 | map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported))); |
| 673 | map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 674 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 675 | map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
| 676 | map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
| 677 | map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 678 | |
| 679 | // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 680 | // | Internal format | | D |S | Format | Type | Comp | SRGB | Supported | |
| 681 | // | | | | | | | type | | | |
| 682 | map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 683 | map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 684 | map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 685 | map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 686 | map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
| 687 | map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
| 688 | map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
| 689 | map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 690 | |
| 691 | // Depth stencil formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 692 | // | Internal format | | D |S | X | Format | Type | Component type | Supported | |
| 693 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported))); |
| 694 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported))); |
| 695 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported))); |
| 696 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported))); |
| 697 | map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, AlwaysSupported))); |
| 698 | map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, AlwaysSupported))); |
| 699 | map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 700 | |
| 701 | // Luminance alpha formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 702 | // | Internal format | | L | A | Format | Type | Component type | Supported | |
| 703 | map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 704 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 705 | map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 706 | map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 707 | map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
| 708 | map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
| 709 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 710 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 711 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 712 | |
| 713 | // Unsized formats |
| 714 | // | Internal format | | Format | Supported | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 715 | map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported))); |
| 716 | map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported))); |
| 717 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported))); |
Geoff Lang | d1e9a9a | 2013-09-30 15:22:57 -0400 | [diff] [blame] | 718 | map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported))); |
| 719 | map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 720 | map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported))); |
| 721 | map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported))); |
Geoff Lang | d1e9a9a | 2013-09-30 15:22:57 -0400 | [diff] [blame] | 722 | map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported))); |
| 723 | map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported))); |
| 724 | map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported))); |
| 725 | map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 726 | map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported))); |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 727 | map.insert(InternalFormatInfoPair(GL_SRGB_EXT, InternalFormatInfo::UnsizedFormat(GL_RGB, CheckSupport<&Extensions::sRGB>))); |
| 728 | map.insert(InternalFormatInfoPair(GL_SRGB_ALPHA_EXT, InternalFormatInfo::UnsizedFormat(GL_RGBA, CheckSupport<&Extensions::sRGB>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 729 | |
| 730 | // Compressed formats, From ES 3.0.1 spec, table 3.16 |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 731 | // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | |
| 732 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 733 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 734 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 735 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 736 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 737 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport))); |
| 738 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 739 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport))); |
| 740 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport))); |
| 741 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, true, UnimplementedSupport))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 742 | |
| 743 | // From GL_EXT_texture_compression_dxt1 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 744 | // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | |
| 745 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT1>))); |
| 746 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT1>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 747 | |
| 748 | // From GL_ANGLE_texture_compression_dxt3 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 749 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT5>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 750 | |
| 751 | // From GL_ANGLE_texture_compression_dxt5 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 752 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT5>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 753 | |
| 754 | return map; |
| 755 | } |
| 756 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 757 | static InternalFormatInfoMap BuildES2InternalFormatInfoMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 758 | { |
| 759 | InternalFormatInfoMap map; |
| 760 | |
| 761 | // From ES 2.0.25 table 4.5 |
| 762 | map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo())); |
| 763 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 764 | // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Supported | |
| 765 | map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported ))); |
| 766 | map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported ))); |
| 767 | map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 768 | |
| 769 | // Extension formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 770 | map.insert(InternalFormatInfoPair(GL_R8_EXT, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureRG> ))); |
| 771 | map.insert(InternalFormatInfoPair(GL_RG8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureRG> ))); |
| 772 | map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::rgb8rgba8> ))); |
| 773 | map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::rgb8rgba8> ))); |
| 774 | map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
| 775 | map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
| 776 | map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 777 | |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 778 | // From GL_EXT_sRGB |
| 779 | map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, CheckSupport<&Extensions::sRGB>))); |
| 780 | map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, CheckSupport<&Extensions::sRGB>))); |
| 781 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 782 | // Floating point formats have to query the renderer for support |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 783 | // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Supported | |
| 784 | // | | | | | | | | | | type | | | |
| 785 | map.insert(InternalFormatInfoPair(GL_R16F_EXT, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat, &Extensions::textureRG>))); |
| 786 | map.insert(InternalFormatInfoPair(GL_R32F_EXT, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat, &Extensions::textureRG>))); |
| 787 | map.insert(InternalFormatInfoPair(GL_RG16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat, &Extensions::textureRG>))); |
| 788 | map.insert(InternalFormatInfoPair(GL_RG32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat, &Extensions::textureRG>))); |
| 789 | map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 790 | map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
| 791 | map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> ))); |
| 792 | map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 793 | |
| 794 | // Depth and stencil formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 795 | // | Internal format | | D |S |X | Format | Type | Internal format | Supported | |
| 796 | // | | | | | | | | type | | |
| 797 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::depthTextures>))); |
| 798 | map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_UNSIGNED_NORMALIZED, AlwaysSupported ))); |
| 799 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported ))); |
| 800 | map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 801 | |
| 802 | // Unsized formats |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 803 | // | Internal format | | Format | Supported | |
| 804 | map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported ))); |
| 805 | map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported ))); |
| 806 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported ))); |
| 807 | map.insert(InternalFormatInfoPair(GL_RED_EXT, InternalFormatInfo::UnsizedFormat(GL_RED_EXT, CheckSupport<&Extensions::textureRG> ))); |
| 808 | map.insert(InternalFormatInfoPair(GL_RG_EXT, InternalFormatInfo::UnsizedFormat(GL_RG_EXT, CheckSupport<&Extensions::textureRG> ))); |
| 809 | map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported ))); |
| 810 | map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported ))); |
| 811 | map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, CheckSupport<&Extensions::textureFormatBGRA8888>))); |
| 812 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported ))); |
| 813 | map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, CheckSupport<&Extensions::packedDepthStencil> ))); |
Geoff Lang | 05b0502 | 2014-06-11 15:31:45 -0400 | [diff] [blame^] | 814 | map.insert(InternalFormatInfoPair(GL_SRGB_EXT, InternalFormatInfo::UnsizedFormat(GL_RGB, CheckSupport<&Extensions::sRGB> ))); |
| 815 | map.insert(InternalFormatInfoPair(GL_SRGB_ALPHA_EXT, InternalFormatInfo::UnsizedFormat(GL_RGBA, CheckSupport<&Extensions::sRGB> ))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 816 | |
| 817 | // Luminance alpha formats from GL_EXT_texture_storage |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 818 | // | Internal format | | L | A | Format | Type | Component type | Supported | |
| 819 | map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 820 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 821 | map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 822 | map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 823 | map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
| 824 | map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
| 825 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> ))); |
| 826 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> ))); |
| 827 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 828 | |
| 829 | // From GL_EXT_texture_compression_dxt1 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 830 | // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | |
| 831 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT1>))); |
| 832 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT1>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 833 | |
| 834 | // From GL_ANGLE_texture_compression_dxt3 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 835 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT3>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 836 | |
| 837 | // From GL_ANGLE_texture_compression_dxt5 |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 838 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Extensions::textureCompressionDXT5>))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 839 | |
| 840 | return map; |
| 841 | } |
| 842 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 843 | static const InternalFormatInfoMap &GetInternalFormatMap(GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 844 | { |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 845 | if (clientVersion == 2) |
| 846 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 847 | static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 848 | return formatMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 849 | } |
| 850 | else if (clientVersion == 3) |
| 851 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 852 | static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 853 | return formatMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 854 | } |
| 855 | else |
| 856 | { |
| 857 | UNREACHABLE(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 858 | static const InternalFormatInfoMap emptyFormatMap; |
| 859 | return emptyFormatMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 860 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 861 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 862 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 863 | static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo) |
| 864 | { |
| 865 | const InternalFormatInfoMap &map = GetInternalFormatMap(clientVersion); |
| 866 | InternalFormatInfoMap::const_iterator iter = map.find(internalFormat); |
| 867 | if (iter != map.end()) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 868 | { |
| 869 | if (outFormatInfo) |
| 870 | { |
| 871 | *outFormatInfo = iter->second; |
| 872 | } |
| 873 | return true; |
| 874 | } |
| 875 | else |
| 876 | { |
| 877 | return false; |
| 878 | } |
| 879 | } |
| 880 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 881 | static FormatSet BuildAllSizedInternalFormatSet(GLuint clientVersion) |
| 882 | { |
| 883 | FormatSet result; |
| 884 | |
| 885 | const InternalFormatInfoMap &formats = GetInternalFormatMap(clientVersion); |
| 886 | for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++) |
| 887 | { |
| 888 | if (i->second.mPixelBits > 0) |
| 889 | { |
| 890 | result.insert(i->first); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | return result; |
| 895 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 896 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 897 | static FormatSet BuildES2ValidFormatSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 898 | { |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 899 | static const FormatMap &formatMap = GetFormatMap(2); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 900 | |
| 901 | FormatSet set; |
| 902 | |
| 903 | for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++) |
| 904 | { |
| 905 | const FormatTypePair& formatPair = i->first; |
| 906 | set.insert(formatPair.first); |
| 907 | } |
| 908 | |
| 909 | return set; |
| 910 | } |
| 911 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 912 | static FormatSet BuildES3ValidFormatSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 913 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 914 | static const ES3FormatSet &formatSet = GetES3FormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 915 | |
| 916 | FormatSet set; |
| 917 | |
| 918 | for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++) |
| 919 | { |
| 920 | const FormatInfo& formatInfo = *i; |
| 921 | set.insert(formatInfo.mFormat); |
| 922 | } |
| 923 | |
| 924 | return set; |
| 925 | } |
| 926 | |
| 927 | typedef std::set<GLenum> TypeSet; |
| 928 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 929 | static TypeSet BuildES2ValidTypeSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 930 | { |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 931 | static const FormatMap &formatMap = GetFormatMap(2); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 932 | |
| 933 | TypeSet set; |
| 934 | |
| 935 | for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++) |
| 936 | { |
| 937 | const FormatTypePair& formatPair = i->first; |
| 938 | set.insert(formatPair.second); |
| 939 | } |
| 940 | |
| 941 | return set; |
| 942 | } |
| 943 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 944 | static TypeSet BuildES3ValidTypeSet() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 945 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 946 | static const ES3FormatSet &formatSet = GetES3FormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 947 | |
| 948 | TypeSet set; |
| 949 | |
| 950 | for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++) |
| 951 | { |
| 952 | const FormatInfo& formatInfo = *i; |
| 953 | set.insert(formatInfo.mType); |
| 954 | } |
| 955 | |
| 956 | return set; |
| 957 | } |
| 958 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 959 | struct EffectiveInternalFormatInfo |
| 960 | { |
| 961 | GLenum mEffectiveFormat; |
| 962 | GLenum mDestFormat; |
| 963 | GLuint mMinRedBits; |
| 964 | GLuint mMaxRedBits; |
| 965 | GLuint mMinGreenBits; |
| 966 | GLuint mMaxGreenBits; |
| 967 | GLuint mMinBlueBits; |
| 968 | GLuint mMaxBlueBits; |
| 969 | GLuint mMinAlphaBits; |
| 970 | GLuint mMaxAlphaBits; |
| 971 | |
| 972 | EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits, |
| 973 | GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits, |
| 974 | GLuint minAlphaBits, GLuint maxAlphaBits) |
| 975 | : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits), |
| 976 | mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits), |
| 977 | mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits), |
| 978 | mMaxAlphaBits(maxAlphaBits) {}; |
| 979 | }; |
| 980 | |
| 981 | typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; |
| 982 | |
| 983 | static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() |
| 984 | { |
| 985 | EffectiveInternalFormatList list; |
| 986 | |
| 987 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 988 | // linear source buffer component sizes. |
| 989 | // | Source channel min/max sizes | |
| 990 | // Effective Internal Format | N/A | R | G | B | A | |
| 991 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); |
| 992 | list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); |
| 993 | list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); |
| 994 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); |
| 995 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); |
| 996 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 997 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 998 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); |
| 999 | list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); |
| 1000 | |
| 1001 | return list; |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() |
| 1006 | { |
| 1007 | EffectiveInternalFormatList list; |
| 1008 | |
| 1009 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 1010 | // linear source buffer component sizes. |
| 1011 | // | Source channel min/max sizes | |
| 1012 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 1013 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 1014 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); |
| 1015 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 1016 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); |
| 1017 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); |
| 1018 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 1019 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 1020 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); |
| 1021 | |
| 1022 | return list; |
| 1023 | } |
| 1024 | |
| 1025 | static bool GetEffectiveInternalFormat(const InternalFormatInfo &srcFormat, const InternalFormatInfo &destFormat, |
| 1026 | GLuint clientVersion, GLenum *outEffectiveFormat) |
| 1027 | { |
| 1028 | const EffectiveInternalFormatList *list = NULL; |
| 1029 | GLenum targetFormat = GL_NONE; |
| 1030 | |
| 1031 | if (gl::IsSizedInternalFormat(destFormat.mFormat, clientVersion)) |
| 1032 | { |
| 1033 | static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); |
| 1034 | list = &sizedList; |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); |
| 1039 | list = &unsizedList; |
| 1040 | targetFormat = destFormat.mFormat; |
| 1041 | } |
| 1042 | |
| 1043 | for (size_t curFormat = 0; curFormat < list->size(); ++curFormat) |
| 1044 | { |
| 1045 | const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat); |
| 1046 | if ((formatInfo.mDestFormat == targetFormat) && |
| 1047 | (formatInfo.mMinRedBits <= srcFormat.mRedBits && formatInfo.mMaxRedBits >= srcFormat.mRedBits) && |
| 1048 | (formatInfo.mMinGreenBits <= srcFormat.mGreenBits && formatInfo.mMaxGreenBits >= srcFormat.mGreenBits) && |
| 1049 | (formatInfo.mMinBlueBits <= srcFormat.mBlueBits && formatInfo.mMaxBlueBits >= srcFormat.mBlueBits) && |
| 1050 | (formatInfo.mMinAlphaBits <= srcFormat.mAlphaBits && formatInfo.mMaxAlphaBits >= srcFormat.mAlphaBits)) |
| 1051 | { |
| 1052 | *outEffectiveFormat = formatInfo.mEffectiveFormat; |
| 1053 | return true; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | return false; |
| 1058 | } |
| 1059 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1060 | struct CopyConversion |
| 1061 | { |
| 1062 | GLenum mTextureFormat; |
| 1063 | GLenum mFramebufferFormat; |
| 1064 | |
| 1065 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 1066 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 1067 | |
| 1068 | bool operator<(const CopyConversion& other) const |
| 1069 | { |
| 1070 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 1071 | } |
| 1072 | }; |
| 1073 | |
| 1074 | typedef std::set<CopyConversion> CopyConversionSet; |
| 1075 | |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1076 | static CopyConversionSet BuildValidES3CopyTexImageCombinations() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1077 | { |
| 1078 | CopyConversionSet set; |
| 1079 | |
| 1080 | // From ES 3.0.1 spec, table 3.15 |
| 1081 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 1082 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 1083 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 1084 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 1085 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 1086 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 1087 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 1088 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 1089 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 1090 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 1091 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 1092 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 1093 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 1094 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 1095 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 1096 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 1097 | |
Jamie Madill | b70e5f7 | 2013-07-10 16:57:52 -0400 | [diff] [blame] | 1098 | // Necessary for ANGLE back-buffers |
| 1099 | set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT)); |
| 1100 | set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT)); |
| 1101 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT)); |
| 1102 | set.insert(CopyConversion(GL_RED, GL_BGRA_EXT)); |
| 1103 | set.insert(CopyConversion(GL_RG, GL_BGRA_EXT)); |
| 1104 | set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT)); |
| 1105 | set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT)); |
| 1106 | |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1107 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER)); |
| 1108 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER)); |
| 1109 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER)); |
| 1110 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER)); |
| 1111 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER)); |
| 1112 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER)); |
| 1113 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER)); |
| 1114 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER)); |
| 1115 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER)); |
| 1116 | set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER)); |
| 1117 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1118 | return set; |
| 1119 | } |
| 1120 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1121 | bool IsValidInternalFormat(GLenum internalFormat, const Extensions &extensions, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1122 | { |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1123 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1124 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1125 | { |
| 1126 | ASSERT(internalFormatInfo.mSupportFunction != NULL); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1127 | return internalFormatInfo.mSupportFunction(extensions); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1128 | } |
| 1129 | else |
| 1130 | { |
| 1131 | return false; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | bool IsValidFormat(GLenum format, GLuint clientVersion) |
| 1136 | { |
| 1137 | if (clientVersion == 2) |
| 1138 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1139 | static const FormatSet formatSet = BuildES2ValidFormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1140 | return formatSet.find(format) != formatSet.end(); |
| 1141 | } |
| 1142 | else if (clientVersion == 3) |
| 1143 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1144 | static const FormatSet formatSet = BuildES3ValidFormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1145 | return formatSet.find(format) != formatSet.end(); |
| 1146 | } |
| 1147 | else |
| 1148 | { |
| 1149 | UNREACHABLE(); |
| 1150 | return false; |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | bool IsValidType(GLenum type, GLuint clientVersion) |
| 1155 | { |
| 1156 | if (clientVersion == 2) |
| 1157 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1158 | static const TypeSet typeSet = BuildES2ValidTypeSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1159 | return typeSet.find(type) != typeSet.end(); |
| 1160 | } |
| 1161 | else if (clientVersion == 3) |
| 1162 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1163 | static const TypeSet typeSet = BuildES3ValidTypeSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1164 | return typeSet.find(type) != typeSet.end(); |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | UNREACHABLE(); |
| 1169 | return false; |
| 1170 | } |
| 1171 | } |
| 1172 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1173 | bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1174 | { |
| 1175 | if (clientVersion == 2) |
| 1176 | { |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 1177 | static const FormatMap &formats = GetFormatMap(clientVersion); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1178 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 1179 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 1180 | return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat)); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1181 | } |
| 1182 | else if (clientVersion == 3) |
| 1183 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1184 | static const ES3FormatSet &formats = GetES3FormatSet(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1185 | return formats.find(FormatInfo(internalFormat, format, type)) != formats.end(); |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | UNREACHABLE(); |
| 1190 | return false; |
| 1191 | } |
| 1192 | } |
| 1193 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1194 | bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1195 | { |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1196 | InternalFormatInfo textureInternalFormatInfo; |
| 1197 | InternalFormatInfo framebufferInternalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1198 | if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) && |
| 1199 | GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1200 | { |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1201 | if (clientVersion == 2) |
| 1202 | { |
| 1203 | UNIMPLEMENTED(); |
| 1204 | return false; |
| 1205 | } |
| 1206 | else if (clientVersion == 3) |
| 1207 | { |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1208 | static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations(); |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1209 | const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat, |
| 1210 | framebufferInternalFormatInfo.mFormat); |
| 1211 | if (conversionSet.find(conversion) != conversionSet.end()) |
| 1212 | { |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1213 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 1214 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 1215 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 1216 | // conversion between fixed and floating point. |
shannonwoods@chromium.org | 96c6291 | 2013-05-30 00:17:00 +0000 | [diff] [blame] | 1217 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1218 | if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB)) |
shannonwoods@chromium.org | 96c6291 | 2013-05-30 00:17:00 +0000 | [diff] [blame] | 1219 | { |
| 1220 | return false; |
| 1221 | } |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1222 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1223 | if (((textureInternalFormatInfo.mComponentType == GL_INT) != (framebufferInternalFormatInfo.mComponentType == GL_INT)) || |
| 1224 | ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT))) |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1225 | { |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1226 | return false; |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1229 | if (gl::IsFloatOrFixedComponentType(textureInternalFormatInfo.mComponentType) && |
| 1230 | !gl::IsFloatOrFixedComponentType(framebufferInternalFormatInfo.mComponentType)) |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1231 | { |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1232 | return false; |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1233 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1234 | |
| 1235 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 1236 | // The effective internal format of the source buffer is determined with the following rules applied in order: |
| 1237 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the |
| 1238 | // effective internal format is the source buffer's sized internal format. |
| 1239 | // * If the source buffer is a texture that was created with an unsized base internal format, then the |
| 1240 | // effective internal format is the source image array's effective internal format, as specified by table |
| 1241 | // 3.12, which is determined from the <format> and <type> that were used when the source image array was |
| 1242 | // specified by TexImage*. |
| 1243 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where |
| 1244 | // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent |
| 1245 | // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the |
| 1246 | // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING |
| 1247 | // is SRGB. |
| 1248 | InternalFormatInfo sourceEffectiveFormat; |
| 1249 | if (readBufferHandle != 0) |
| 1250 | { |
| 1251 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer |
| 1252 | if (gl::IsSizedInternalFormat(framebufferInternalFormatInfo.mFormat, clientVersion)) |
| 1253 | { |
| 1254 | sourceEffectiveFormat = framebufferInternalFormatInfo; |
| 1255 | } |
| 1256 | else |
| 1257 | { |
| 1258 | // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format |
| 1259 | // texture. We can use the same table we use when creating textures to get its effective sized format. |
| 1260 | GLenum effectiveFormat = gl::GetSizedInternalFormat(framebufferInternalFormatInfo.mFormat, |
| 1261 | framebufferInternalFormatInfo.mType, clientVersion); |
| 1262 | gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat); |
| 1263 | } |
| 1264 | } |
| 1265 | else |
| 1266 | { |
| 1267 | // The effective internal format must be derived from the source framebuffer's channel sizes. |
| 1268 | // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 1269 | if (framebufferInternalFormatInfo.mColorEncoding == GL_LINEAR) |
| 1270 | { |
| 1271 | GLenum effectiveFormat; |
| 1272 | if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, clientVersion, &effectiveFormat)) |
| 1273 | { |
| 1274 | gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat); |
| 1275 | } |
| 1276 | else |
| 1277 | { |
| 1278 | return false; |
| 1279 | } |
| 1280 | } |
| 1281 | else if (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB) |
| 1282 | { |
| 1283 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 1284 | if (gl::IsSizedInternalFormat(textureInternalFormat, clientVersion) && |
| 1285 | (framebufferInternalFormatInfo.mRedBits >= 1 && framebufferInternalFormatInfo.mRedBits <= 8) && |
| 1286 | (framebufferInternalFormatInfo.mGreenBits >= 1 && framebufferInternalFormatInfo.mGreenBits <= 8) && |
| 1287 | (framebufferInternalFormatInfo.mBlueBits >= 1 && framebufferInternalFormatInfo.mBlueBits <= 8) && |
| 1288 | (framebufferInternalFormatInfo.mAlphaBits >= 1 && framebufferInternalFormatInfo.mAlphaBits <= 8)) |
| 1289 | { |
| 1290 | gl::GetInternalFormatInfo(GL_SRGB8_ALPHA8, clientVersion, &sourceEffectiveFormat); |
| 1291 | } |
| 1292 | else |
| 1293 | { |
| 1294 | return false; |
| 1295 | } |
| 1296 | } |
| 1297 | else |
| 1298 | { |
| 1299 | UNREACHABLE(); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | if (gl::IsSizedInternalFormat(textureInternalFormatInfo.mFormat, clientVersion)) |
| 1304 | { |
| 1305 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized, |
| 1306 | // component sizes of the source and destination formats must exactly match |
| 1307 | if (textureInternalFormatInfo.mRedBits != sourceEffectiveFormat.mRedBits || |
| 1308 | textureInternalFormatInfo.mGreenBits != sourceEffectiveFormat.mGreenBits || |
| 1309 | textureInternalFormatInfo.mBlueBits != sourceEffectiveFormat.mBlueBits || |
| 1310 | textureInternalFormatInfo.mAlphaBits != sourceEffectiveFormat.mAlphaBits) |
| 1311 | { |
| 1312 | return false; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | return true; // A conversion function exists, and no rule in the specification has precluded conversion |
| 1318 | // between these formats. |
shannonwoods@chromium.org | ffab47d | 2013-05-30 00:16:22 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | return false; |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | UNREACHABLE(); |
| 1326 | return false; |
| 1327 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1328 | } |
| 1329 | else |
| 1330 | { |
| 1331 | UNREACHABLE(); |
| 1332 | return false; |
| 1333 | } |
| 1334 | } |
| 1335 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1336 | bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1337 | { |
| 1338 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1339 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1340 | { |
| 1341 | return internalFormatInfo.mPixelBits > 0; |
| 1342 | } |
| 1343 | else |
| 1344 | { |
| 1345 | UNREACHABLE(); |
| 1346 | return false; |
| 1347 | } |
| 1348 | } |
| 1349 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1350 | GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1351 | { |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 1352 | const FormatMap &formats = GetFormatMap(clientVersion); |
| 1353 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 1354 | return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1357 | GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1358 | { |
| 1359 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1360 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1361 | { |
| 1362 | return internalFormatInfo.mPixelBits / 8; |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | UNREACHABLE(); |
| 1367 | return 0; |
| 1368 | } |
| 1369 | } |
| 1370 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1371 | GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1372 | { |
| 1373 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1374 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1375 | { |
| 1376 | return internalFormatInfo.mAlphaBits; |
| 1377 | } |
| 1378 | else |
| 1379 | { |
| 1380 | UNREACHABLE(); |
| 1381 | return 0; |
| 1382 | } |
| 1383 | } |
| 1384 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1385 | GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1386 | { |
| 1387 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1388 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1389 | { |
| 1390 | return internalFormatInfo.mRedBits; |
| 1391 | } |
| 1392 | else |
| 1393 | { |
| 1394 | UNREACHABLE(); |
| 1395 | return 0; |
| 1396 | } |
| 1397 | } |
| 1398 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1399 | GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1400 | { |
| 1401 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1402 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1403 | { |
| 1404 | return internalFormatInfo.mGreenBits; |
| 1405 | } |
| 1406 | else |
| 1407 | { |
| 1408 | UNREACHABLE(); |
| 1409 | return 0; |
| 1410 | } |
| 1411 | } |
| 1412 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1413 | GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1414 | { |
| 1415 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1416 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1417 | { |
Geoff Lang | 2415922 | 2013-06-05 14:56:32 -0400 | [diff] [blame] | 1418 | return internalFormatInfo.mBlueBits; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1419 | } |
| 1420 | else |
| 1421 | { |
| 1422 | UNREACHABLE(); |
| 1423 | return 0; |
| 1424 | } |
| 1425 | } |
| 1426 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1427 | GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1428 | { |
| 1429 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1430 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1431 | { |
| 1432 | return internalFormatInfo.mLuminanceBits; |
| 1433 | } |
| 1434 | else |
| 1435 | { |
| 1436 | UNREACHABLE(); |
| 1437 | return 0; |
| 1438 | } |
| 1439 | } |
| 1440 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1441 | GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1442 | { |
| 1443 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1444 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1445 | { |
| 1446 | return internalFormatInfo.mDepthBits; |
| 1447 | } |
| 1448 | else |
| 1449 | { |
| 1450 | UNREACHABLE(); |
| 1451 | return 0; |
| 1452 | } |
| 1453 | } |
| 1454 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1455 | GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1456 | { |
| 1457 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1458 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1459 | { |
| 1460 | return internalFormatInfo.mStencilBits; |
| 1461 | } |
| 1462 | else |
| 1463 | { |
| 1464 | UNREACHABLE(); |
| 1465 | return 0; |
| 1466 | } |
| 1467 | } |
| 1468 | |
Geoff Lang | f23eb28 | 2013-07-22 10:52:19 -0400 | [diff] [blame] | 1469 | GLuint GetTypeBytes(GLenum type) |
| 1470 | { |
| 1471 | TypeInfo typeInfo; |
| 1472 | if (GetTypeInfo(type, &typeInfo)) |
| 1473 | { |
| 1474 | return typeInfo.mTypeBytes; |
| 1475 | } |
| 1476 | else |
| 1477 | { |
| 1478 | UNREACHABLE(); |
| 1479 | return 0; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | bool IsSpecialInterpretationType(GLenum type) |
| 1484 | { |
| 1485 | TypeInfo typeInfo; |
| 1486 | if (GetTypeInfo(type, &typeInfo)) |
| 1487 | { |
| 1488 | return typeInfo.mSpecialInterpretation; |
| 1489 | } |
| 1490 | else |
| 1491 | { |
| 1492 | UNREACHABLE(); |
| 1493 | return false; |
| 1494 | } |
| 1495 | } |
| 1496 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 1497 | bool IsFloatOrFixedComponentType(GLenum type) |
| 1498 | { |
| 1499 | if (type == GL_UNSIGNED_NORMALIZED || |
| 1500 | type == GL_SIGNED_NORMALIZED || |
| 1501 | type == GL_FLOAT) |
| 1502 | { |
| 1503 | return true; |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | return false; |
| 1508 | } |
| 1509 | } |
| 1510 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1511 | GLenum GetFormat(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1512 | { |
| 1513 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1514 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1515 | { |
| 1516 | return internalFormatInfo.mFormat; |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | UNREACHABLE(); |
| 1521 | return GL_NONE; |
| 1522 | } |
| 1523 | } |
| 1524 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1525 | GLenum GetType(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1526 | { |
| 1527 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1528 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1529 | { |
| 1530 | return internalFormatInfo.mType; |
| 1531 | } |
| 1532 | else |
| 1533 | { |
| 1534 | UNREACHABLE(); |
| 1535 | return GL_NONE; |
| 1536 | } |
| 1537 | } |
| 1538 | |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1539 | GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1540 | { |
| 1541 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1542 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1543 | { |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1544 | return internalFormatInfo.mComponentType; |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1545 | } |
| 1546 | else |
| 1547 | { |
| 1548 | UNREACHABLE(); |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1549 | return GL_NONE; |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1553 | GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion) |
Jamie Madill | 3466a4d | 2013-09-18 14:36:20 -0400 | [diff] [blame] | 1554 | { |
| 1555 | InternalFormatInfo internalFormatInfo; |
| 1556 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1557 | { |
| 1558 | return internalFormatInfo.mComponentCount; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
| 1562 | UNREACHABLE(); |
| 1563 | return false; |
| 1564 | } |
| 1565 | } |
| 1566 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1567 | GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1568 | { |
| 1569 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1570 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | e19409b | 2013-05-30 00:16:15 +0000 | [diff] [blame] | 1571 | { |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1572 | return internalFormatInfo.mColorEncoding; |
shannonwoods@chromium.org | e81ea50 | 2013-05-30 00:16:53 +0000 | [diff] [blame] | 1573 | } |
| 1574 | else |
| 1575 | { |
| 1576 | UNREACHABLE(); |
| 1577 | return false; |
| 1578 | } |
| 1579 | } |
| 1580 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1581 | GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1582 | { |
| 1583 | ASSERT(alignment > 0 && isPow2(alignment)); |
Jamie Madill | eb9baab | 2014-03-24 13:19:43 -0400 | [diff] [blame] | 1584 | return rx::roundUp(GetBlockSize(internalFormat, type, clientVersion, width, 1), static_cast<GLuint>(alignment)); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1587 | GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1588 | { |
Jamie Madill | 666e286 | 2013-09-10 12:04:29 -0400 | [diff] [blame] | 1589 | return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1592 | GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1593 | { |
| 1594 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1595 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1596 | { |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1597 | if (internalFormatInfo.mIsCompressed) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1598 | { |
| 1599 | GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth; |
| 1600 | GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight; |
| 1601 | |
| 1602 | return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8; |
| 1603 | } |
| 1604 | else |
| 1605 | { |
| 1606 | TypeInfo typeInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1607 | if (GetTypeInfo(type, &typeInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1608 | { |
| 1609 | if (typeInfo.mSpecialInterpretation) |
| 1610 | { |
| 1611 | return typeInfo.mTypeBytes * width * height; |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height; |
| 1616 | } |
| 1617 | } |
| 1618 | else |
| 1619 | { |
| 1620 | UNREACHABLE(); |
| 1621 | return 0; |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | else |
| 1626 | { |
| 1627 | UNREACHABLE(); |
| 1628 | return 0; |
| 1629 | } |
| 1630 | } |
| 1631 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1632 | bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1633 | { |
| 1634 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1635 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1636 | { |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1637 | return internalFormatInfo.mIsCompressed; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1638 | } |
| 1639 | else |
| 1640 | { |
| 1641 | UNREACHABLE(); |
| 1642 | return false; |
| 1643 | } |
| 1644 | } |
| 1645 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1646 | GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1647 | { |
| 1648 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1649 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1650 | { |
| 1651 | return internalFormatInfo.mCompressedBlockWidth; |
| 1652 | } |
| 1653 | else |
| 1654 | { |
| 1655 | UNREACHABLE(); |
| 1656 | return 0; |
| 1657 | } |
| 1658 | } |
| 1659 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 1660 | GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1661 | { |
| 1662 | InternalFormatInfo internalFormatInfo; |
Geoff Lang | 18591b7 | 2013-06-07 12:00:15 -0400 | [diff] [blame] | 1663 | if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1664 | { |
| 1665 | return internalFormatInfo.mCompressedBlockHeight; |
| 1666 | } |
| 1667 | else |
| 1668 | { |
| 1669 | UNREACHABLE(); |
| 1670 | return 0; |
| 1671 | } |
| 1672 | } |
| 1673 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1674 | const FormatSet &GetAllSizedInternalFormats(GLuint clientVersion) |
| 1675 | { |
| 1676 | static FormatSet formatSet = BuildAllSizedInternalFormatSet(clientVersion); |
| 1677 | return formatSet; |
| 1678 | } |
| 1679 | |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 1680 | ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion) |
| 1681 | { |
| 1682 | static const FormatMap &formats = GetFormatMap(clientVersion); |
| 1683 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 1684 | return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL; |
| 1685 | } |
| 1686 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1687 | } |