blob: 8f249b549c1e6aafe06f366c4429b7a98d5314cb [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00004// 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 Woods4d161ba2014-03-17 18:13:30 -040010#include "common/mathutil.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000011#include "libGLESv2/formatutils.h"
12#include "libGLESv2/Context.h"
Shannon Woods4d161ba2014-03-17 18:13:30 -040013#include "libGLESv2/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014#include "libGLESv2/renderer/Renderer.h"
Geoff Langfe28ca02013-06-04 10:10:48 -040015#include "libGLESv2/renderer/imageformats.h"
16#include "libGLESv2/renderer/copyimage.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017
18namespace 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 Langfe28ca02013-06-04 10:10:48 -040025struct FormatTypeInfo
26{
Geoff Lang005df412013-10-16 14:12:50 -040027 GLenum mInternalFormat;
Geoff Langfe28ca02013-06-04 10:10:48 -040028 ColorWriteFunction mColorWriteFunction;
29
Geoff Lang005df412013-10-16 14:12:50 -040030 FormatTypeInfo(GLenum internalFormat, ColorWriteFunction writeFunc)
Geoff Langfe28ca02013-06-04 10:10:48 -040031 : mInternalFormat(internalFormat), mColorWriteFunction(writeFunc)
32 { }
33};
34
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000035typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Langfe28ca02013-06-04 10:10:48 -040036typedef std::pair<FormatTypePair, FormatTypeInfo> FormatPair;
37typedef std::map<FormatTypePair, FormatTypeInfo> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000038
Jamie Madill89a0bf52013-09-18 14:36:24 -040039// A helper function to insert data into the format map with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -040040static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat, ColorWriteFunction writeFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000041{
Geoff Langfe28ca02013-06-04 10:10:48 -040042 map->insert(FormatPair(FormatTypePair(format, type), FormatTypeInfo(internalFormat, writeFunc)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000043}
44
Geoff Lang18591b72013-06-07 12:00:15 -040045FormatMap BuildES2FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000046{
47 FormatMap map;
48
Geoff Langfe28ca02013-06-04 10:10:48 -040049 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000050
Geoff Langfe28ca02013-06-04 10:10:48 -040051 // | 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.orgb8490f32013-05-30 00:08:00 +000055
Geoff Langfe28ca02013-06-04 10:10:48 -040056 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.orgb8490f32013-05-30 00:08:00 +000059
Geoff Langfe28ca02013-06-04 10:10:48 -040060 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.orgb8490f32013-05-30 00:08:00 +000063
Geoff Lang632192d2013-10-04 13:40:46 -040064 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 Langfe28ca02013-06-04 10:10:48 -040072 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.orgb8490f32013-05-30 00:08:00 +000076
Geoff Langfe28ca02013-06-04 10:10:48 -040077 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.orgb8490f32013-05-30 00:08:00 +000082
Geoff Langfe28ca02013-06-04 10:10:48 -040083 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.orgb8490f32013-05-30 00:08:00 +000086
Geoff Langfe28ca02013-06-04 10:10:48 -040087 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.orgb8490f32013-05-30 00:08:00 +000091
Geoff Langfe28ca02013-06-04 10:10:48 -040092 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 Langcec35902014-04-16 10:52:36 -040095 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8, NULL );
96
Geoff Langfe28ca02013-06-04 10:10:48 -040097 InsertFormatMapping(&map, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_DEPTH24_STENCIL8_OES, NULL );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000098
99 return map;
100}
101
Geoff Lang18591b72013-06-07 12:00:15 -0400102FormatMap BuildES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000103{
104 FormatMap map;
105
Geoff Langfe28ca02013-06-04 10:10:48 -0400106 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000107
Geoff Langfe28ca02013-06-04 10:10:48 -0400108 // | 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.orgb8490f32013-05-30 00:08:00 +0000116
Geoff Langfe28ca02013-06-04 10:10:48 -0400117 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 Madill18a44702013-09-09 16:24:04 -0400123 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, WriteColor<R10G10B10A2, GLuint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000124
Geoff Langfe28ca02013-06-04 10:10:48 -0400125 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.orgb8490f32013-05-30 00:08:00 +0000132
Geoff Langfe28ca02013-06-04 10:10:48 -0400133 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.orgb8490f32013-05-30 00:08:00 +0000139
Geoff Langfe28ca02013-06-04 10:10:48 -0400140 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 Langcec35902014-04-16 10:52:36 -0400178 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 Langfe28ca02013-06-04 10:10:48 -0400183 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.orgb8490f32013-05-30 00:08:00 +0000189
190 return map;
191}
192
Geoff Langfe28ca02013-06-04 10:10:48 -0400193static 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.orgb8490f32013-05-30 00:08:00 +0000213struct FormatInfo
214{
Geoff Lang005df412013-10-16 14:12:50 -0400215 GLenum mInternalformat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000216 GLenum mFormat;
217 GLenum mType;
218
Geoff Lang005df412013-10-16 14:12:50 -0400219 FormatInfo(GLenum internalformat, GLenum format, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000220 : 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.
229typedef std::set<FormatInfo> ES3FormatSet;
230
Geoff Lang18591b72013-06-07 12:00:15 -0400231ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000232{
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.orgd03f8972013-05-30 00:17:07 +0000247 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000248 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 Langcdacacd2014-04-24 12:01:56 -0400329 // From GL_EXT_texture_format_BGRA8888
330 set.insert(FormatInfo(GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
331
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000332 // 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 Langcdacacd2014-04-24 12:01:56 -0400345 // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000346 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 Lang18591b72013-06-07 12:00:15 -0400385static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000386{
Geoff Lang18591b72013-06-07 12:00:15 -0400387 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000388 return es3FormatSet;
389}
390
391// Map of sizes of input types
392struct 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
409typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
410typedef std::map<GLenum, TypeInfo> TypeInfoMap;
411
Geoff Lang18591b72013-06-07 12:00:15 -0400412static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000413{
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 Madilla940ae42013-07-08 17:48:34 -0400423 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000424 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.orgb8490f32013-05-30 00:08:00 +0000434 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400435 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000436
437 return map;
438}
439
Geoff Lang18591b72013-06-07 12:00:15 -0400440static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000441{
Geoff Lang18591b72013-06-07 12:00:15 -0400442 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000443 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 Langcec35902014-04-16 10:52:36 -0400459typedef bool (*SupportCheckFunction)(const Extensions &);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000460
Geoff Langcec35902014-04-16 10:52:36 -0400461static bool AlwaysSupported(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000462{
463 return true;
464}
465
Geoff Langcec35902014-04-16 10:52:36 -0400466static bool UnimplementedSupport(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000467{
468 UNIMPLEMENTED();
469 return false;
470}
471
Geoff Langcec35902014-04-16 10:52:36 -0400472static bool NeverSupported(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000473{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000474 return false;
475}
476
Geoff Langcec35902014-04-16 10:52:36 -0400477// Pointer to a boolean memeber of the Extensions struct
478typedef bool(Extensions::*ExtensionBool);
479
480// Check support for a single extension
481template <ExtensionBool bool1>
482static bool CheckSupport(const Extensions &caps)
483{
484 return (caps.*bool1);
485}
486
487// Check support for two extensions
488template <ExtensionBool bool1, ExtensionBool bool2>
489static bool CheckSupport(const Extensions &caps)
490{
491 return (caps.*bool1) && (caps.*bool2);
492}
493
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000494struct 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.orgb8490f32013-05-30 00:08:00 +0000512 GLuint mCompressedBlockWidth;
513 GLuint mCompressedBlockHeight;
514
515 GLenum mFormat;
516 GLenum mType;
517
Geoff Langb2f3d052013-08-13 12:49:27 -0400518 GLenum mComponentType;
519 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000520
Geoff Langb2f3d052013-08-13 12:49:27 -0400521 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000522
Geoff Langcec35902014-04-16 10:52:36 -0400523 SupportCheckFunction mSupportFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000524
525 InternalFormatInfo() : mRedBits(0), mGreenBits(0), mBlueBits(0), mLuminanceBits(0), mAlphaBits(0), mSharedBits(0), mDepthBits(0), mStencilBits(0),
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000526 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langcec35902014-04-16 10:52:36 -0400527 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000528 {
529 }
530
Geoff Langcec35902014-04-16 10:52:36 -0400531 static InternalFormatInfo UnsizedFormat(GLenum format, SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000532 {
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 Langb2f3d052013-08-13 12:49:27 -0400540 GLenum format, GLenum type, GLenum componentType, bool srgb,
Geoff Langcec35902014-04-16 10:52:36 -0400541 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000542 {
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 Langb2f3d052013-08-13 12:49:27 -0400553 formatInfo.mComponentType = componentType;
554 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000555 formatInfo.mSupportFunction = supportFunction;
556 return formatInfo;
557 }
558
Geoff Langb2f3d052013-08-13 12:49:27 -0400559 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
Geoff Langcec35902014-04-16 10:52:36 -0400560 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000561 {
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 Langb2f3d052013-08-13 12:49:27 -0400569 formatInfo.mComponentType = componentType;
570 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000571 formatInfo.mSupportFunction = supportFunction;
572 return formatInfo;
573 }
574
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400575 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
Geoff Langcec35902014-04-16 10:52:36 -0400576 GLenum type, GLenum componentType, SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000577 {
578 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400579 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.orgb8490f32013-05-30 00:08:00 +0000583 formatInfo.mFormat = format;
584 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400585 formatInfo.mComponentType = componentType;
586 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000587 formatInfo.mSupportFunction = supportFunction;
588 return formatInfo;
589 }
590
Geoff Langb2f3d052013-08-13 12:49:27 -0400591 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
592 GLuint componentCount, GLenum format, GLenum type, bool srgb,
Geoff Langcec35902014-04-16 10:52:36 -0400593 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000594 {
595 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
597 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
598 formatInfo.mPixelBits = compressedBlockSize;
599 formatInfo.mComponentCount = componentCount;
600 formatInfo.mFormat = format;
601 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400602 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
603 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
604 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000605 formatInfo.mSupportFunction = supportFunction;
606 return formatInfo;
607 }
608};
609
Geoff Lang005df412013-10-16 14:12:50 -0400610typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
611typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000612
Geoff Lang18591b72013-06-07 12:00:15 -0400613static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614{
615 InternalFormatInfoMap map;
616
617 // From ES 3.0.1 spec, table 3.12
618 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
619
Geoff Langcec35902014-04-16 10:52:36 -0400620 // | 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.orgb8490f32013-05-30 00:08:00 +0000662
Geoff Langcec35902014-04-16 10:52:36 -0400663 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.orgb8490f32013-05-30 00:08:00 +0000666
667 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langcec35902014-04-16 10:52:36 -0400668 // | 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.orgb8490f32013-05-30 00:08:00 +0000678
679 // Depth stencil formats
Geoff Langcec35902014-04-16 10:52:36 -0400680 // | 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.orgb8490f32013-05-30 00:08:00 +0000688
689 // Luminance alpha formats
Geoff Langcec35902014-04-16 10:52:36 -0400690 // | 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.orgb8490f32013-05-30 00:08:00 +0000700
701 // Unsized formats
702 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000703 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 Langd1e9a9a2013-09-30 15:22:57 -0400706 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
707 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000708 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
709 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400710 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.orgb8490f32013-05-30 00:08:00 +0000714 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 Langb2f3d052013-08-13 12:49:27 -0400717 // | 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.orgb8490f32013-05-30 00:08:00 +0000728
729 // From GL_EXT_texture_compression_dxt1
Geoff Langcec35902014-04-16 10:52:36 -0400730 // | 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.orgb8490f32013-05-30 00:08:00 +0000733
734 // From GL_ANGLE_texture_compression_dxt3
Geoff Langcec35902014-04-16 10:52:36 -0400735 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.orgb8490f32013-05-30 00:08:00 +0000736
737 // From GL_ANGLE_texture_compression_dxt5
Geoff Langcec35902014-04-16 10:52:36 -0400738 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.orgb8490f32013-05-30 00:08:00 +0000739
740 return map;
741}
742
Geoff Lang18591b72013-06-07 12:00:15 -0400743static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000744{
745 InternalFormatInfoMap map;
746
747 // From ES 2.0.25 table 4.5
748 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
749
Geoff Langcec35902014-04-16 10:52:36 -0400750 // | 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.orgb8490f32013-05-30 00:08:00 +0000754
755 // Extension formats
Geoff Langcec35902014-04-16 10:52:36 -0400756 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.orgb8490f32013-05-30 00:08:00 +0000763
764 // Floating point formats have to query the renderer for support
Geoff Langcec35902014-04-16 10:52:36 -0400765 // | 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.orgb8490f32013-05-30 00:08:00 +0000775
776 // Depth and stencil formats
Geoff Langcec35902014-04-16 10:52:36 -0400777 // | 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.orgb8490f32013-05-30 00:08:00 +0000783
784 // Unsized formats
Geoff Langcec35902014-04-16 10:52:36 -0400785 // | 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.orgb8490f32013-05-30 00:08:00 +0000796
797 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langcec35902014-04-16 10:52:36 -0400798 // | 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.orgb8490f32013-05-30 00:08:00 +0000808
809 // From GL_EXT_texture_compression_dxt1
Geoff Langcec35902014-04-16 10:52:36 -0400810 // | 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.orgb8490f32013-05-30 00:08:00 +0000813
814 // From GL_ANGLE_texture_compression_dxt3
Geoff Langcec35902014-04-16 10:52:36 -0400815 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.orgb8490f32013-05-30 00:08:00 +0000816
817 // From GL_ANGLE_texture_compression_dxt5
Geoff Langcec35902014-04-16 10:52:36 -0400818 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.orgb8490f32013-05-30 00:08:00 +0000819
820 return map;
821}
822
Geoff Langcec35902014-04-16 10:52:36 -0400823static const InternalFormatInfoMap &GetInternalFormatMap(GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000824{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000825 if (clientVersion == 2)
826 {
Geoff Lang18591b72013-06-07 12:00:15 -0400827 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
Geoff Langcec35902014-04-16 10:52:36 -0400828 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000829 }
830 else if (clientVersion == 3)
831 {
Geoff Lang18591b72013-06-07 12:00:15 -0400832 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
Geoff Langcec35902014-04-16 10:52:36 -0400833 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000834 }
835 else
836 {
837 UNREACHABLE();
Geoff Langcec35902014-04-16 10:52:36 -0400838 static const InternalFormatInfoMap emptyFormatMap;
839 return emptyFormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000840 }
Geoff Langcec35902014-04-16 10:52:36 -0400841}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000842
Geoff Langcec35902014-04-16 10:52:36 -0400843static 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.orgb8490f32013-05-30 00:08:00 +0000848 {
849 if (outFormatInfo)
850 {
851 *outFormatInfo = iter->second;
852 }
853 return true;
854 }
855 else
856 {
857 return false;
858 }
859}
860
Geoff Langcec35902014-04-16 10:52:36 -0400861static 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.orgb8490f32013-05-30 00:08:00 +0000876
Geoff Lang18591b72013-06-07 12:00:15 -0400877static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000878{
Geoff Langfe28ca02013-06-04 10:10:48 -0400879 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000880
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 Lang18591b72013-06-07 12:00:15 -0400892static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000893{
Geoff Lang18591b72013-06-07 12:00:15 -0400894 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000895
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
907typedef std::set<GLenum> TypeSet;
908
Geoff Lang18591b72013-06-07 12:00:15 -0400909static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000910{
Geoff Langfe28ca02013-06-04 10:10:48 -0400911 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000912
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 Lang18591b72013-06-07 12:00:15 -0400924static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000925{
Geoff Lang18591b72013-06-07 12:00:15 -0400926 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000927
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 Woods4d161ba2014-03-17 18:13:30 -0400939struct 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
961typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList;
962
963static 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
985static 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
1005static 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.orgb8490f32013-05-30 00:08:00 +00001040struct 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
1054typedef std::set<CopyConversion> CopyConversionSet;
1055
Geoff Lang18591b72013-06-07 12:00:15 -04001056static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001057{
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 Madillb70e5f72013-07-10 16:57:52 -04001078 // 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.orgffab47d2013-05-30 00:16:22 +00001087 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.orgb8490f32013-05-30 00:08:00 +00001098 return set;
1099}
1100
Geoff Langcec35902014-04-16 10:52:36 -04001101bool IsValidInternalFormat(GLenum internalFormat, const Extensions &extensions, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001102{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001103 InternalFormatInfo internalFormatInfo;
Geoff Langcec35902014-04-16 10:52:36 -04001104 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001105 {
1106 ASSERT(internalFormatInfo.mSupportFunction != NULL);
Geoff Langcec35902014-04-16 10:52:36 -04001107 return internalFormatInfo.mSupportFunction(extensions);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001108 }
1109 else
1110 {
1111 return false;
1112 }
1113}
1114
1115bool IsValidFormat(GLenum format, GLuint clientVersion)
1116{
1117 if (clientVersion == 2)
1118 {
Geoff Lang18591b72013-06-07 12:00:15 -04001119 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001120 return formatSet.find(format) != formatSet.end();
1121 }
1122 else if (clientVersion == 3)
1123 {
Geoff Lang18591b72013-06-07 12:00:15 -04001124 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001125 return formatSet.find(format) != formatSet.end();
1126 }
1127 else
1128 {
1129 UNREACHABLE();
1130 return false;
1131 }
1132}
1133
1134bool IsValidType(GLenum type, GLuint clientVersion)
1135{
1136 if (clientVersion == 2)
1137 {
Geoff Lang18591b72013-06-07 12:00:15 -04001138 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001139 return typeSet.find(type) != typeSet.end();
1140 }
1141 else if (clientVersion == 3)
1142 {
Geoff Lang18591b72013-06-07 12:00:15 -04001143 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144 return typeSet.find(type) != typeSet.end();
1145 }
1146 else
1147 {
1148 UNREACHABLE();
1149 return false;
1150 }
1151}
1152
Geoff Lang005df412013-10-16 14:12:50 -04001153bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001154{
1155 if (clientVersion == 2)
1156 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001157 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001158 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1159
Geoff Langfe28ca02013-06-04 10:10:48 -04001160 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001161 }
1162 else if (clientVersion == 3)
1163 {
Geoff Lang18591b72013-06-07 12:00:15 -04001164 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001165 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1166 }
1167 else
1168 {
1169 UNREACHABLE();
1170 return false;
1171 }
1172}
1173
Shannon Woods4d161ba2014-03-17 18:13:30 -04001174bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001175{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001176 InternalFormatInfo textureInternalFormatInfo;
1177 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001178 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1179 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001180 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001181 if (clientVersion == 2)
1182 {
1183 UNIMPLEMENTED();
1184 return false;
1185 }
1186 else if (clientVersion == 3)
1187 {
Geoff Lang18591b72013-06-07 12:00:15 -04001188 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001189 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1190 framebufferInternalFormatInfo.mFormat);
1191 if (conversionSet.find(conversion) != conversionSet.end())
1192 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001193 // 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.org96c62912013-05-30 00:17:00 +00001197
Geoff Langb2f3d052013-08-13 12:49:27 -04001198 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001199 {
1200 return false;
1201 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001202
Shannon Woods4d161ba2014-03-17 18:13:30 -04001203 if (((textureInternalFormatInfo.mComponentType == GL_INT) != (framebufferInternalFormatInfo.mComponentType == GL_INT)) ||
1204 ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT)))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001205 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001206 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001207 }
1208
Shannon Woods4d161ba2014-03-17 18:13:30 -04001209 if (gl::IsFloatOrFixedComponentType(textureInternalFormatInfo.mComponentType) &&
1210 !gl::IsFloatOrFixedComponentType(framebufferInternalFormatInfo.mComponentType))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001211 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001212 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001213 }
Shannon Woods4d161ba2014-03-17 18:13:30 -04001214
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.orgffab47d2013-05-30 00:16:22 +00001299 }
1300
1301 return false;
1302 }
1303 else
1304 {
1305 UNREACHABLE();
1306 return false;
1307 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001308 }
1309 else
1310 {
1311 UNREACHABLE();
1312 return false;
1313 }
1314}
1315
Geoff Lang005df412013-10-16 14:12:50 -04001316bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001317{
1318 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001319 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001320 {
1321 return internalFormatInfo.mPixelBits > 0;
1322 }
1323 else
1324 {
1325 UNREACHABLE();
1326 return false;
1327 }
1328}
1329
Geoff Lang005df412013-10-16 14:12:50 -04001330GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001331{
Geoff Langfe28ca02013-06-04 10:10:48 -04001332 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.orgb8490f32013-05-30 00:08:00 +00001335}
1336
Geoff Lang005df412013-10-16 14:12:50 -04001337GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001338{
1339 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001340 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001341 {
1342 return internalFormatInfo.mPixelBits / 8;
1343 }
1344 else
1345 {
1346 UNREACHABLE();
1347 return 0;
1348 }
1349}
1350
Geoff Lang005df412013-10-16 14:12:50 -04001351GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001352{
1353 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001354 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001355 {
1356 return internalFormatInfo.mAlphaBits;
1357 }
1358 else
1359 {
1360 UNREACHABLE();
1361 return 0;
1362 }
1363}
1364
Geoff Lang005df412013-10-16 14:12:50 -04001365GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001366{
1367 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001368 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001369 {
1370 return internalFormatInfo.mRedBits;
1371 }
1372 else
1373 {
1374 UNREACHABLE();
1375 return 0;
1376 }
1377}
1378
Geoff Lang005df412013-10-16 14:12:50 -04001379GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001380{
1381 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001382 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001383 {
1384 return internalFormatInfo.mGreenBits;
1385 }
1386 else
1387 {
1388 UNREACHABLE();
1389 return 0;
1390 }
1391}
1392
Geoff Lang005df412013-10-16 14:12:50 -04001393GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001394{
1395 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001396 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001397 {
Geoff Lang24159222013-06-05 14:56:32 -04001398 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001399 }
1400 else
1401 {
1402 UNREACHABLE();
1403 return 0;
1404 }
1405}
1406
Geoff Lang005df412013-10-16 14:12:50 -04001407GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001408{
1409 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001410 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001411 {
1412 return internalFormatInfo.mLuminanceBits;
1413 }
1414 else
1415 {
1416 UNREACHABLE();
1417 return 0;
1418 }
1419}
1420
Geoff Lang005df412013-10-16 14:12:50 -04001421GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001422{
1423 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001424 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001425 {
1426 return internalFormatInfo.mDepthBits;
1427 }
1428 else
1429 {
1430 UNREACHABLE();
1431 return 0;
1432 }
1433}
1434
Geoff Lang005df412013-10-16 14:12:50 -04001435GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001436{
1437 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001438 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001439 {
1440 return internalFormatInfo.mStencilBits;
1441 }
1442 else
1443 {
1444 UNREACHABLE();
1445 return 0;
1446 }
1447}
1448
Geoff Langf23eb282013-07-22 10:52:19 -04001449GLuint 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
1463bool 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 Woods4d161ba2014-03-17 18:13:30 -04001477bool 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 Lang005df412013-10-16 14:12:50 -04001491GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001492{
1493 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001494 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001495 {
1496 return internalFormatInfo.mFormat;
1497 }
1498 else
1499 {
1500 UNREACHABLE();
1501 return GL_NONE;
1502 }
1503}
1504
Geoff Lang005df412013-10-16 14:12:50 -04001505GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001506{
1507 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001508 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001509 {
1510 return internalFormatInfo.mType;
1511 }
1512 else
1513 {
1514 UNREACHABLE();
1515 return GL_NONE;
1516 }
1517}
1518
Nicolas Capens0027fa92014-02-20 14:26:42 -05001519GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001520{
1521 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001522 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001523 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001524 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001525 }
1526 else
1527 {
1528 UNREACHABLE();
Nicolas Capens0027fa92014-02-20 14:26:42 -05001529 return GL_NONE;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001530 }
1531}
1532
Geoff Lang005df412013-10-16 14:12:50 -04001533GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001534{
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 Lang005df412013-10-16 14:12:50 -04001547GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001548{
1549 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001550 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001551 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001552 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001553 }
1554 else
1555 {
1556 UNREACHABLE();
1557 return false;
1558 }
1559}
1560
Geoff Lang005df412013-10-16 14:12:50 -04001561GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001562{
1563 ASSERT(alignment > 0 && isPow2(alignment));
Jamie Madilleb9baab2014-03-24 13:19:43 -04001564 return rx::roundUp(GetBlockSize(internalFormat, type, clientVersion, width, 1), static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001565}
1566
Geoff Lang005df412013-10-16 14:12:50 -04001567GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001568{
Jamie Madill666e2862013-09-10 12:04:29 -04001569 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001570}
1571
Geoff Lang005df412013-10-16 14:12:50 -04001572GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001573{
1574 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001575 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001576 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001577 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001578 {
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 Lang18591b72013-06-07 12:00:15 -04001587 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001588 {
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 Lang005df412013-10-16 14:12:50 -04001612bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001613{
1614 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001615 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001616 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001617 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001618 }
1619 else
1620 {
1621 UNREACHABLE();
1622 return false;
1623 }
1624}
1625
Geoff Lang005df412013-10-16 14:12:50 -04001626GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001627{
1628 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001629 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001630 {
1631 return internalFormatInfo.mCompressedBlockWidth;
1632 }
1633 else
1634 {
1635 UNREACHABLE();
1636 return 0;
1637 }
1638}
1639
Geoff Lang005df412013-10-16 14:12:50 -04001640GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001641{
1642 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001643 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001644 {
1645 return internalFormatInfo.mCompressedBlockHeight;
1646 }
1647 else
1648 {
1649 UNREACHABLE();
1650 return 0;
1651 }
1652}
1653
Geoff Langcec35902014-04-16 10:52:36 -04001654const FormatSet &GetAllSizedInternalFormats(GLuint clientVersion)
1655{
1656 static FormatSet formatSet = BuildAllSizedInternalFormatSet(clientVersion);
1657 return formatSet;
1658}
1659
Geoff Langfe28ca02013-06-04 10:10:48 -04001660ColorWriteFunction 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.orgb8490f32013-05-30 00:08:00 +00001667}