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