blob: 5d3ef020e740d938fd591da1251a2c9d4138a650 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// formatutils.cpp: Queries for GL image formats.
9
10#include "libGLESv2/formatutils.h"
11#include "libGLESv2/Context.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000012#include "common/mathutil.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000013#include "libGLESv2/renderer/Renderer.h"
Geoff Langfe28ca02013-06-04 10:10:48 -040014#include "libGLESv2/renderer/imageformats.h"
15#include "libGLESv2/renderer/copyimage.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000016
17namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
23
Geoff Langfe28ca02013-06-04 10:10:48 -040024struct FormatTypeInfo
25{
Geoff Lang005df412013-10-16 14:12:50 -040026 GLenum mInternalFormat;
Geoff Langfe28ca02013-06-04 10:10:48 -040027 ColorWriteFunction mColorWriteFunction;
28
Geoff Lang005df412013-10-16 14:12:50 -040029 FormatTypeInfo(GLenum internalFormat, ColorWriteFunction writeFunc)
Geoff Langfe28ca02013-06-04 10:10:48 -040030 : mInternalFormat(internalFormat), mColorWriteFunction(writeFunc)
31 { }
32};
33
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000034typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Langfe28ca02013-06-04 10:10:48 -040035typedef std::pair<FormatTypePair, FormatTypeInfo> FormatPair;
36typedef std::map<FormatTypePair, FormatTypeInfo> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000037
Jamie Madill89a0bf52013-09-18 14:36:24 -040038// A helper function to insert data into the format map with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -040039static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat, ColorWriteFunction writeFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000040{
Geoff Langfe28ca02013-06-04 10:10:48 -040041 map->insert(FormatPair(FormatTypePair(format, type), FormatTypeInfo(internalFormat, writeFunc)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000042}
43
Geoff Lang18591b72013-06-07 12:00:15 -040044FormatMap BuildES2FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045{
46 FormatMap map;
47
Geoff Langfe28ca02013-06-04 10:10:48 -040048 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000049
Geoff Langfe28ca02013-06-04 10:10:48 -040050 // | Format | Type | Internal format | Color write function |
51 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
52 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
53 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000054
Geoff Langfe28ca02013-06-04 10:10:48 -040055 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
56 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
57 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000058
Geoff Langfe28ca02013-06-04 10:10:48 -040059 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
60 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
61 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000062
Geoff Langfe28ca02013-06-04 10:10:48 -040063 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES, WriteColor<R8G8B8, GLfloat> );
64 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
65 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT, WriteColor<R32G32B32F, GLfloat> );
66 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000067
Geoff Langfe28ca02013-06-04 10:10:48 -040068 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES, WriteColor<R8G8B8A8, GLfloat> );
69 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
70 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
71 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT, WriteColor<R32G32B32A32F, GLfloat>);
72 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073
Geoff Langfe28ca02013-06-04 10:10:48 -040074 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
75 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
76 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 +000077
Geoff Langfe28ca02013-06-04 10:10:48 -040078 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL );
79 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL );
80 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL );
81 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 +000082
Geoff Langfe28ca02013-06-04 10:10:48 -040083 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
84 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES, NULL );
85
86 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 +000087
88 return map;
89}
90
Geoff Lang18591b72013-06-07 12:00:15 -040091FormatMap BuildES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000092{
93 FormatMap map;
94
Geoff Langfe28ca02013-06-04 10:10:48 -040095 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000096
Geoff Langfe28ca02013-06-04 10:10:48 -040097 // | Format | Type | Internal format | Color write function |
98 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8, WriteColor<R8G8B8A8, GLfloat> );
99 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM, WriteColor<R8G8B8A8S, GLfloat> );
100 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
101 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
102 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, WriteColor<R10G10B10A2, GLfloat> );
103 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F, WriteColor<R32G32B32A32F, GLfloat>);
104 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000105
Geoff Langfe28ca02013-06-04 10:10:48 -0400106 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, WriteColor<R8G8B8A8, GLuint> );
107 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, WriteColor<R8G8B8A8S, GLint> );
108 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, WriteColor<R16G16B16A16, GLuint> );
109 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, WriteColor<R16G16B16A16S, GLint> );
110 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, WriteColor<R32G32B32A32, GLuint> );
111 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, WriteColor<R32G32B32A32S, GLint> );
Jamie Madill18a44702013-09-09 16:24:04 -0400112 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 +0000113
Geoff Langfe28ca02013-06-04 10:10:48 -0400114 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> );
115 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> );
116 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
117 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> );
118 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> );
119 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> );
120 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000121
Geoff Langfe28ca02013-06-04 10:10:48 -0400122 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> );
123 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> );
124 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> );
125 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> );
126 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> );
127 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000128
Geoff Langfe28ca02013-06-04 10:10:48 -0400129 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> );
130 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> );
131 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> );
132 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> );
133
134 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> );
135 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> );
136 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> );
137 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> );
138 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> );
139 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> );
140
141 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> );
142 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> );
143 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> );
144 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> );
145
146 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> );
147 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> );
148 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> );
149 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> );
150 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> );
151 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> );
152
153 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
154 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
155 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
156 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
157 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
158 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
159 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
160 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
161 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
162
163 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
164 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
165 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
166
167 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
168 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL );
169 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL );
170
171 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL );
172 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 +0000173
174 return map;
175}
176
Geoff Langfe28ca02013-06-04 10:10:48 -0400177static const FormatMap &GetFormatMap(GLuint clientVersion)
178{
179 if (clientVersion == 2)
180 {
181 static const FormatMap formats = BuildES2FormatMap();
182 return formats;
183 }
184 else if (clientVersion == 3)
185 {
186 static const FormatMap formats = BuildES3FormatMap();
187 return formats;
188 }
189 else
190 {
191 UNREACHABLE();
192 static FormatMap emptyMap;
193 return emptyMap;
194 }
195}
196
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000197struct FormatInfo
198{
Geoff Lang005df412013-10-16 14:12:50 -0400199 GLenum mInternalformat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000200 GLenum mFormat;
201 GLenum mType;
202
Geoff Lang005df412013-10-16 14:12:50 -0400203 FormatInfo(GLenum internalformat, GLenum format, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000204 : mInternalformat(internalformat), mFormat(format), mType(type) { }
205
206 bool operator<(const FormatInfo& other) const
207 {
208 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
209 }
210};
211
212// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
213typedef std::set<FormatInfo> ES3FormatSet;
214
Geoff Lang18591b72013-06-07 12:00:15 -0400215ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000216{
217 ES3FormatSet set;
218
219 // Format combinations from ES 3.0.1 spec, table 3.2
220
221 // | Internal format | Format | Type |
222 // | | | |
223 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
224 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
225 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
226 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
227 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
228 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
229 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
230 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000231 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000232 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
233 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
234 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
235 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
236 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
237 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
238 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
239 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
240 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
241 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
242 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
243 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
244 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
245 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
246 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
247 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
248 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
249 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
250 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
251 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
252 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
253 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
254 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
255 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
256 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
257 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
258 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
259 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
260 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
261 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
262 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
263 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
264 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
265 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
266 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
267 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
268 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
269 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
270 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
271 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
272 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
273 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
274 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
275 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
276 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
277 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
278 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
279 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
280 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
281 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
282 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
283 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
284
285 // Unsized formats
286 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
287 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
288 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
289 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
290 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
291 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
292 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
293 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
294
295 // Depth stencil formats
296 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
297 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
298 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
299 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
300 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
301 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
302
303 // From GL_OES_texture_float
304 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
305 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
306 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
307
308 // From GL_OES_texture_half_float
309 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
310 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
311 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
312
313 // From GL_EXT_texture_storage
314 // | Internal format | Format | Type |
315 // | | | |
316 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
317 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
318 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
319 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
320 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
321 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
322 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
323 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
324 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
325
326 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
327 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
328 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
329 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
330 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
331
332 // From GL_ANGLE_depth_texture
333 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
334
335 // Compressed formats
336 // From ES 3.0.1 spec, table 3.16
337 // | Internal format | Format | Type |
338 // | | | |
339 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
340 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
341 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
342 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
343 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
344 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
345 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
346 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
347 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
348 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
349 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
350
351
352 // From GL_EXT_texture_compression_dxt1
353 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
354 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
355
356 // From GL_ANGLE_texture_compression_dxt3
357 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
358
359 // From GL_ANGLE_texture_compression_dxt5
360 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
361
362 return set;
363}
364
Geoff Lang18591b72013-06-07 12:00:15 -0400365static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000366{
Geoff Lang18591b72013-06-07 12:00:15 -0400367 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000368 return es3FormatSet;
369}
370
371// Map of sizes of input types
372struct TypeInfo
373{
374 GLuint mTypeBytes;
375 bool mSpecialInterpretation;
376
377 TypeInfo()
378 : mTypeBytes(0), mSpecialInterpretation(false) { }
379
380 TypeInfo(GLuint typeBytes, bool specialInterpretation)
381 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
382
383 bool operator<(const TypeInfo& other) const
384 {
385 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
386 }
387};
388
389typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
390typedef std::map<GLenum, TypeInfo> TypeInfoMap;
391
Geoff Lang18591b72013-06-07 12:00:15 -0400392static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000393{
394 TypeInfoMap map;
395
396 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
397 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
398 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
399 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
400 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
401 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
402 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
Jamie Madilla940ae42013-07-08 17:48:34 -0400403 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000404 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
405 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
406 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
407 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
408 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
409 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
410 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
411 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
412 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
413 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000414 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400415 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000416
417 return map;
418}
419
Geoff Lang18591b72013-06-07 12:00:15 -0400420static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000421{
Geoff Lang18591b72013-06-07 12:00:15 -0400422 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000423 TypeInfoMap::const_iterator iter = infoMap.find(type);
424 if (iter != infoMap.end())
425 {
426 if (outTypeInfo)
427 {
428 *outTypeInfo = iter->second;
429 }
430 return true;
431 }
432 else
433 {
434 return false;
435 }
436}
437
438// Information about internal formats
439typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
440typedef bool (*ContextSupportCheckFunction)(const Context *context);
441
442typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
443typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
444
445template <ContextSupportCheckMemberFunction func>
446bool CheckSupport(const Context *context)
447{
448 return (context->*func)();
449}
450
451template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
452bool CheckSupport(const Context *context, const rx::Renderer *renderer)
453{
454 if (context)
455 {
456 return (context->*contextFunc)();
457 }
458 else if (renderer)
459 {
460 return (renderer->*rendererFunc)();
461 }
462 else
463 {
464 UNREACHABLE();
465 return false;
466 }
467}
468
469template <typename objectType>
470bool AlwaysSupported(const objectType*)
471{
472 return true;
473}
474
475template <typename objectTypeA, typename objectTypeB>
476bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
477{
478 return true;
479}
480
481template <typename objectType>
482bool NeverSupported(const objectType*)
483{
484 return false;
485}
486
487template <typename objectTypeA, typename objectTypeB>
488bool NeverSupported(const objectTypeA *, const objectTypeB *)
489{
490 return false;
491}
492
493template <typename objectType>
494bool UnimplementedSupport(const objectType*)
495{
496 UNIMPLEMENTED();
497 return false;
498}
499
500template <typename objectTypeA, typename objectTypeB>
501bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
502{
503 UNIMPLEMENTED();
504 return false;
505}
506
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000507struct InternalFormatInfo
508{
509 GLuint mRedBits;
510 GLuint mGreenBits;
511 GLuint mBlueBits;
512
513 GLuint mLuminanceBits;
514
515 GLuint mAlphaBits;
516 GLuint mSharedBits;
517
518 GLuint mDepthBits;
519 GLuint mStencilBits;
520
521 GLuint mPixelBits;
522
523 GLuint mComponentCount;
524
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000525 GLuint mCompressedBlockWidth;
526 GLuint mCompressedBlockHeight;
527
528 GLenum mFormat;
529 GLenum mType;
530
Geoff Langb2f3d052013-08-13 12:49:27 -0400531 GLenum mComponentType;
532 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000533
Geoff Langb2f3d052013-08-13 12:49:27 -0400534 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000535
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000536 ContextRendererSupportCheckFunction mIsColorRenderable;
537 ContextRendererSupportCheckFunction mIsDepthRenderable;
538 ContextRendererSupportCheckFunction mIsStencilRenderable;
539 ContextRendererSupportCheckFunction mIsTextureFilterable;
540
541 ContextSupportCheckFunction mSupportFunction;
542
543 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 +0000544 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langb2f3d052013-08-13 12:49:27 -0400545 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mIsColorRenderable(NeverSupported),
546 mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported), mIsTextureFilterable(NeverSupported),
547 mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000548 {
549 }
550
551 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
552 {
553 InternalFormatInfo formatInfo;
554 formatInfo.mFormat = format;
555 formatInfo.mSupportFunction = supportFunction;
Shannon Woods9e73b212013-07-08 10:32:19 -0400556
557 if (format == GL_RGB || format == GL_RGBA)
558 formatInfo.mIsColorRenderable = AlwaysSupported;
559
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000560 return formatInfo;
561 }
562
563 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
Geoff Langb2f3d052013-08-13 12:49:27 -0400564 GLenum format, GLenum type, GLenum componentType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000565 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000566 ContextRendererSupportCheckFunction textureFilterable,
567 ContextSupportCheckFunction supportFunction)
568 {
569 InternalFormatInfo formatInfo;
570 formatInfo.mRedBits = red;
571 formatInfo.mGreenBits = green;
572 formatInfo.mBlueBits = blue;
573 formatInfo.mAlphaBits = alpha;
574 formatInfo.mSharedBits = shared;
575 formatInfo.mPixelBits = red + green + blue + alpha + shared;
576 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
577 formatInfo.mFormat = format;
578 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400579 formatInfo.mComponentType = componentType;
580 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000581 formatInfo.mIsColorRenderable = colorRenderable;
582 formatInfo.mIsTextureFilterable = textureFilterable;
583 formatInfo.mSupportFunction = supportFunction;
584 return formatInfo;
585 }
586
Geoff Langb2f3d052013-08-13 12:49:27 -0400587 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000588 ContextSupportCheckFunction supportFunction)
589 {
590 InternalFormatInfo formatInfo;
591 formatInfo.mLuminanceBits = luminance;
592 formatInfo.mAlphaBits = alpha;
593 formatInfo.mPixelBits = luminance + alpha;
594 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
595 formatInfo.mFormat = format;
596 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400597 formatInfo.mComponentType = componentType;
598 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000599 formatInfo.mIsTextureFilterable = AlwaysSupported;
600 formatInfo.mSupportFunction = supportFunction;
601 return formatInfo;
602 }
603
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400604 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
605 GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000606 ContextRendererSupportCheckFunction depthRenderable,
607 ContextRendererSupportCheckFunction stencilRenderable,
608 ContextSupportCheckFunction supportFunction)
609 {
610 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400611 formatInfo.mDepthBits = depthBits;
612 formatInfo.mStencilBits = stencilBits;
613 formatInfo.mPixelBits = depthBits + stencilBits + unusedBits;
614 formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000615 formatInfo.mFormat = format;
616 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400617 formatInfo.mComponentType = componentType;
618 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000619 formatInfo.mIsDepthRenderable = depthRenderable;
620 formatInfo.mIsStencilRenderable = stencilRenderable;
Nicolas Capens08be89d2013-07-16 16:17:31 -0400621 formatInfo.mIsTextureFilterable = AlwaysSupported;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000622 formatInfo.mSupportFunction = supportFunction;
623 return formatInfo;
624 }
625
Geoff Langb2f3d052013-08-13 12:49:27 -0400626 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
627 GLuint componentCount, GLenum format, GLenum type, bool srgb,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628 ContextSupportCheckFunction supportFunction)
629 {
630 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
632 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
633 formatInfo.mPixelBits = compressedBlockSize;
634 formatInfo.mComponentCount = componentCount;
635 formatInfo.mFormat = format;
636 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400637 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
638 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
639 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640 formatInfo.mIsTextureFilterable = AlwaysSupported;
641 formatInfo.mSupportFunction = supportFunction;
642 return formatInfo;
643 }
644};
645
Geoff Lang005df412013-10-16 14:12:50 -0400646typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
647typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648
Geoff Lang18591b72013-06-07 12:00:15 -0400649static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000650{
651 InternalFormatInfoMap map;
652
653 // From ES 3.0.1 spec, table 3.12
654 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
655
Geoff Langb2f3d052013-08-13 12:49:27 -0400656 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
657 // | | | | | | | | | | | | renderable | filterable | |
658 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
659 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
660 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
661 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
662 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
663 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
Jamie Madill1d855fe2013-09-09 16:24:05 -0400664 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, AlwaysSupported, AlwaysSupported )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400665 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, AlwaysSupported, AlwaysSupported )));
666 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, AlwaysSupported, AlwaysSupported )));
667 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
668 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
669 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, AlwaysSupported, AlwaysSupported )));
Jamie Madill18a44702013-09-09 16:24:04 -0400670 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, NeverSupported, AlwaysSupported )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400671 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
672 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
673 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, NeverSupported, AlwaysSupported, AlwaysSupported )));
674 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, NeverSupported, AlwaysSupported, AlwaysSupported )));
675 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
676 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
677 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
678 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
679 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
680 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
681 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
682 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
683 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
684 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
685 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
686 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
687 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
688 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
689 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
690 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
691 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
692 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
693 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
694 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
696 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
697 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
698 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000699
Geoff Langb2f3d052013-08-13 12:49:27 -0400700 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
701 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, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
702 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, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000703
704 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langb2f3d052013-08-13 12:49:27 -0400705 // | Internal format | | D |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
706 // | | | | | | | type | | | | |
707 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
708 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
709 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
710 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
711 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
712 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
713 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
714 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000715
716 // Depth stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400717 // | Internal format | | D |S | X | Format | Type | Component type | Depth | Stencil | Supported |
718 // | | | | | | | | | renderable | renderable | |
719 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
720 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
721 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported)));
722 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
723 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
724 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, AlwaysSupported, AlwaysSupported)));
725 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000726
727 // Luminance alpha formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400728 // | Internal format | | L | A | Format | Type | Component type | Supported |
729 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
730 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
731 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
732 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
733 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
734 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
735 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
736 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
737 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000738
739 // Unsized formats
740 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000741 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400744 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000746 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
747 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400748 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
749 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
750 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
751 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000752 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
753
754 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400755 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
756 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
757 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
758 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
759 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
760 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
761 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
762 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)));
763 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)));
764 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
765 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 +0000766
767 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400768 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
769 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, AlwaysSupported)));
770 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, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000771
772 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400773 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, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000774
775 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400776 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, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000777
778 return map;
779}
780
Geoff Lang18591b72013-06-07 12:00:15 -0400781static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000782{
783 InternalFormatInfoMap map;
784
785 // From ES 2.0.25 table 4.5
786 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
787
Geoff Langb2f3d052013-08-13 12:49:27 -0400788 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
789 // | | | | | | | | | | | | renderable | filterable | |
790 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, AlwaysSupported, AlwaysSupported)));
791 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, AlwaysSupported, AlwaysSupported)));
792 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, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000793
794 // Extension formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400795 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
796 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
797 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
798 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, NeverSupported, AlwaysSupported, AlwaysSupported)));
799 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, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000800
801 // Floating point formats have to query the renderer for support
Geoff Langb2f3d052013-08-13 12:49:27 -0400802 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
803 // | | | | | | | | | | type | | | | |
804 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
805 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
806 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
807 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000808
809 // Depth and stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400810 // | Internal format | | D |S |X | Format | Type | Internal format | Depth | Stencil | Supported |
811 // | | | | | | | | type | renderable | renderable | |
812 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
813 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, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>)));
814 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
815 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000816
817 // Unsized formats
818 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000819 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
820 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
821 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
822 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
823 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
824 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
825 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
826 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
827
828 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langb2f3d052013-08-13 12:49:27 -0400829 // | Internal format | | L | A | Format | Type | Component type | Supported |
830 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
831 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
832 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
833 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
834 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
835 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
836 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
837 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
838 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839
840 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400841 // | Internal format | |W |H | BS |CC|Format | Type | SRGB | Supported |
842 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<&Context::supportsDXT1Textures>)));
843 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<&Context::supportsDXT1Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000844
845 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400846 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<&Context::supportsDXT3Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000847
848 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400849 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<&Context::supportsDXT5Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000850
851 return map;
852}
853
Geoff Lang005df412013-10-16 14:12:50 -0400854static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000855{
856 const InternalFormatInfoMap* map = NULL;
857
858 if (clientVersion == 2)
859 {
Geoff Lang18591b72013-06-07 12:00:15 -0400860 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000861 map = &formatMap;
862 }
863 else if (clientVersion == 3)
864 {
Geoff Lang18591b72013-06-07 12:00:15 -0400865 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000866 map = &formatMap;
867 }
868 else
869 {
870 UNREACHABLE();
871 }
872
873 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
874 if (iter != map->end())
875 {
876 if (outFormatInfo)
877 {
878 *outFormatInfo = iter->second;
879 }
880 return true;
881 }
882 else
883 {
884 return false;
885 }
886}
887
888typedef std::set<GLenum> FormatSet;
889
Geoff Lang18591b72013-06-07 12:00:15 -0400890static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000891{
Geoff Langfe28ca02013-06-04 10:10:48 -0400892 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000893
894 FormatSet set;
895
896 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
897 {
898 const FormatTypePair& formatPair = i->first;
899 set.insert(formatPair.first);
900 }
901
902 return set;
903}
904
Geoff Lang18591b72013-06-07 12:00:15 -0400905static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000906{
Geoff Lang18591b72013-06-07 12:00:15 -0400907 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000908
909 FormatSet set;
910
911 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
912 {
913 const FormatInfo& formatInfo = *i;
914 set.insert(formatInfo.mFormat);
915 }
916
917 return set;
918}
919
920typedef std::set<GLenum> TypeSet;
921
Geoff Lang18591b72013-06-07 12:00:15 -0400922static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923{
Geoff Langfe28ca02013-06-04 10:10:48 -0400924 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000925
926 TypeSet set;
927
928 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
929 {
930 const FormatTypePair& formatPair = i->first;
931 set.insert(formatPair.second);
932 }
933
934 return set;
935}
936
Geoff Lang18591b72013-06-07 12:00:15 -0400937static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000938{
Geoff Lang18591b72013-06-07 12:00:15 -0400939 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000940
941 TypeSet set;
942
943 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
944 {
945 const FormatInfo& formatInfo = *i;
946 set.insert(formatInfo.mType);
947 }
948
949 return set;
950}
951
952struct CopyConversion
953{
954 GLenum mTextureFormat;
955 GLenum mFramebufferFormat;
956
957 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
958 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
959
960 bool operator<(const CopyConversion& other) const
961 {
962 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
963 }
964};
965
966typedef std::set<CopyConversion> CopyConversionSet;
967
Geoff Lang18591b72013-06-07 12:00:15 -0400968static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000969{
970 CopyConversionSet set;
971
972 // From ES 3.0.1 spec, table 3.15
973 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
974 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
975 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
976 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
977 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
978 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
979 set.insert(CopyConversion(GL_RED, GL_RED));
980 set.insert(CopyConversion(GL_RED, GL_RG));
981 set.insert(CopyConversion(GL_RED, GL_RGB));
982 set.insert(CopyConversion(GL_RED, GL_RGBA));
983 set.insert(CopyConversion(GL_RG, GL_RG));
984 set.insert(CopyConversion(GL_RG, GL_RGB));
985 set.insert(CopyConversion(GL_RG, GL_RGBA));
986 set.insert(CopyConversion(GL_RGB, GL_RGB));
987 set.insert(CopyConversion(GL_RGB, GL_RGBA));
988 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
989
Jamie Madillb70e5f72013-07-10 16:57:52 -0400990 // Necessary for ANGLE back-buffers
991 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
992 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
993 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
994 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
995 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
996 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
997 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
998
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +0000999 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
1000 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1001 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1002 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1003 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1004 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1005 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1006 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1007 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1008 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1009
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001010 return set;
1011}
1012
Geoff Lang005df412013-10-16 14:12:50 -04001013bool IsValidInternalFormat(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001014{
1015 if (!context)
1016 {
1017 return false;
1018 }
1019
1020 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001021 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001022 {
1023 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1024 return internalFormatInfo.mSupportFunction(context);
1025 }
1026 else
1027 {
1028 return false;
1029 }
1030}
1031
1032bool IsValidFormat(GLenum format, GLuint clientVersion)
1033{
1034 if (clientVersion == 2)
1035 {
Geoff Lang18591b72013-06-07 12:00:15 -04001036 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001037 return formatSet.find(format) != formatSet.end();
1038 }
1039 else if (clientVersion == 3)
1040 {
Geoff Lang18591b72013-06-07 12:00:15 -04001041 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001042 return formatSet.find(format) != formatSet.end();
1043 }
1044 else
1045 {
1046 UNREACHABLE();
1047 return false;
1048 }
1049}
1050
1051bool IsValidType(GLenum type, GLuint clientVersion)
1052{
1053 if (clientVersion == 2)
1054 {
Geoff Lang18591b72013-06-07 12:00:15 -04001055 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001056 return typeSet.find(type) != typeSet.end();
1057 }
1058 else if (clientVersion == 3)
1059 {
Geoff Lang18591b72013-06-07 12:00:15 -04001060 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001061 return typeSet.find(type) != typeSet.end();
1062 }
1063 else
1064 {
1065 UNREACHABLE();
1066 return false;
1067 }
1068}
1069
Geoff Lang005df412013-10-16 14:12:50 -04001070bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001071{
1072 if (clientVersion == 2)
1073 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001074 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001075 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1076
Geoff Langfe28ca02013-06-04 10:10:48 -04001077 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001078 }
1079 else if (clientVersion == 3)
1080 {
Geoff Lang18591b72013-06-07 12:00:15 -04001081 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001082 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1083 }
1084 else
1085 {
1086 UNREACHABLE();
1087 return false;
1088 }
1089}
1090
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001091bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001092{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001093 InternalFormatInfo textureInternalFormatInfo;
1094 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001095 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1096 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001097 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001098 if (clientVersion == 2)
1099 {
1100 UNIMPLEMENTED();
1101 return false;
1102 }
1103 else if (clientVersion == 3)
1104 {
Geoff Lang18591b72013-06-07 12:00:15 -04001105 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001106 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1107 framebufferInternalFormatInfo.mFormat);
1108 if (conversionSet.find(conversion) != conversionSet.end())
1109 {
1110 // Section 3.8.5 of the GLES3 3.0.2 spec states that source and destination formats
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001111 // must both be signed or unsigned or fixed/floating point and both source and destinations
1112 // must be either both SRGB or both not SRGB
1113
Geoff Langb2f3d052013-08-13 12:49:27 -04001114 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001115 {
1116 return false;
1117 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001118
Geoff Langb2f3d052013-08-13 12:49:27 -04001119 if ((textureInternalFormatInfo.mComponentType == GL_INT && framebufferInternalFormatInfo.mComponentType == GL_INT ) ||
1120 (textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT && framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001121 {
1122 return true;
1123 }
1124
Geoff Langb2f3d052013-08-13 12:49:27 -04001125 if ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1126 textureInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1127 textureInternalFormatInfo.mComponentType == GL_FLOAT ) &&
1128 (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1129 framebufferInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1130 framebufferInternalFormatInfo.mComponentType == GL_FLOAT ))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001131 {
1132 return true;
1133 }
1134 }
1135
1136 return false;
1137 }
1138 else
1139 {
1140 UNREACHABLE();
1141 return false;
1142 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001143 }
1144 else
1145 {
1146 UNREACHABLE();
1147 return false;
1148 }
1149}
1150
Geoff Lang005df412013-10-16 14:12:50 -04001151bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001152{
1153 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001154 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001155 {
1156 return internalFormatInfo.mPixelBits > 0;
1157 }
1158 else
1159 {
1160 UNREACHABLE();
1161 return false;
1162 }
1163}
1164
Geoff Lang005df412013-10-16 14:12:50 -04001165GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001166{
Geoff Langfe28ca02013-06-04 10:10:48 -04001167 const FormatMap &formats = GetFormatMap(clientVersion);
1168 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1169 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001170}
1171
Geoff Lang005df412013-10-16 14:12:50 -04001172GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001173{
1174 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001175 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001176 {
1177 return internalFormatInfo.mPixelBits / 8;
1178 }
1179 else
1180 {
1181 UNREACHABLE();
1182 return 0;
1183 }
1184}
1185
Geoff Lang005df412013-10-16 14:12:50 -04001186GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001187{
1188 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001189 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001190 {
1191 return internalFormatInfo.mAlphaBits;
1192 }
1193 else
1194 {
1195 UNREACHABLE();
1196 return 0;
1197 }
1198}
1199
Geoff Lang005df412013-10-16 14:12:50 -04001200GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001201{
1202 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001203 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001204 {
1205 return internalFormatInfo.mRedBits;
1206 }
1207 else
1208 {
1209 UNREACHABLE();
1210 return 0;
1211 }
1212}
1213
Geoff Lang005df412013-10-16 14:12:50 -04001214GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001215{
1216 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001217 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001218 {
1219 return internalFormatInfo.mGreenBits;
1220 }
1221 else
1222 {
1223 UNREACHABLE();
1224 return 0;
1225 }
1226}
1227
Geoff Lang005df412013-10-16 14:12:50 -04001228GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001229{
1230 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001231 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001232 {
Geoff Lang24159222013-06-05 14:56:32 -04001233 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001234 }
1235 else
1236 {
1237 UNREACHABLE();
1238 return 0;
1239 }
1240}
1241
Geoff Lang005df412013-10-16 14:12:50 -04001242GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001243{
1244 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001245 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001246 {
1247 return internalFormatInfo.mLuminanceBits;
1248 }
1249 else
1250 {
1251 UNREACHABLE();
1252 return 0;
1253 }
1254}
1255
Geoff Lang005df412013-10-16 14:12:50 -04001256GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001257{
1258 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001259 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001260 {
1261 return internalFormatInfo.mDepthBits;
1262 }
1263 else
1264 {
1265 UNREACHABLE();
1266 return 0;
1267 }
1268}
1269
Geoff Lang005df412013-10-16 14:12:50 -04001270GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001271{
1272 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001273 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001274 {
1275 return internalFormatInfo.mStencilBits;
1276 }
1277 else
1278 {
1279 UNREACHABLE();
1280 return 0;
1281 }
1282}
1283
Geoff Langf23eb282013-07-22 10:52:19 -04001284GLuint GetTypeBytes(GLenum type)
1285{
1286 TypeInfo typeInfo;
1287 if (GetTypeInfo(type, &typeInfo))
1288 {
1289 return typeInfo.mTypeBytes;
1290 }
1291 else
1292 {
1293 UNREACHABLE();
1294 return 0;
1295 }
1296}
1297
1298bool IsSpecialInterpretationType(GLenum type)
1299{
1300 TypeInfo typeInfo;
1301 if (GetTypeInfo(type, &typeInfo))
1302 {
1303 return typeInfo.mSpecialInterpretation;
1304 }
1305 else
1306 {
1307 UNREACHABLE();
1308 return false;
1309 }
1310}
1311
Geoff Lang005df412013-10-16 14:12:50 -04001312GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001313{
1314 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001315 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001316 {
1317 return internalFormatInfo.mFormat;
1318 }
1319 else
1320 {
1321 UNREACHABLE();
1322 return GL_NONE;
1323 }
1324}
1325
Geoff Lang005df412013-10-16 14:12:50 -04001326GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001327{
1328 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001329 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001330 {
1331 return internalFormatInfo.mType;
1332 }
1333 else
1334 {
1335 UNREACHABLE();
1336 return GL_NONE;
1337 }
1338}
1339
Geoff Lang005df412013-10-16 14:12:50 -04001340GLuint GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001341{
1342 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001343 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001344 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001345 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001346 }
1347 else
1348 {
1349 UNREACHABLE();
1350 return false;
1351 }
1352}
1353
Geoff Lang005df412013-10-16 14:12:50 -04001354GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001355{
1356 InternalFormatInfo internalFormatInfo;
1357 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1358 {
1359 return internalFormatInfo.mComponentCount;
1360 }
1361 else
1362 {
1363 UNREACHABLE();
1364 return false;
1365 }
1366}
1367
Geoff Lang005df412013-10-16 14:12:50 -04001368GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001369{
1370 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001371 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001372 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001373 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001374 }
1375 else
1376 {
1377 UNREACHABLE();
1378 return false;
1379 }
1380}
1381
Geoff Lang005df412013-10-16 14:12:50 -04001382bool IsColorRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001383{
1384 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001385 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001386 {
1387 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1388 }
1389 else
1390 {
1391 UNREACHABLE();
1392 return false;
1393 }
1394}
1395
Geoff Lang005df412013-10-16 14:12:50 -04001396bool IsColorRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001397{
1398 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001399 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001400 {
1401 return internalFormatInfo.mIsColorRenderable(context, NULL);
1402 }
1403 else
1404 {
1405 UNREACHABLE();
1406 return false;
1407 }
1408}
1409
Geoff Lang005df412013-10-16 14:12:50 -04001410bool IsTextureFilteringSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001411{
1412 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001413 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001414 {
1415 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1416 }
1417 else
1418 {
1419 UNREACHABLE();
1420 return false;
1421 }
1422}
1423
Geoff Lang005df412013-10-16 14:12:50 -04001424bool IsTextureFilteringSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001425{
1426 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001427 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001428 {
1429 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1430 }
1431 else
1432 {
1433 UNREACHABLE();
1434 return false;
1435 }
1436}
1437
Geoff Lang005df412013-10-16 14:12:50 -04001438bool IsDepthRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001439{
1440 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001441 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001442 {
1443 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1444 }
1445 else
1446 {
1447 UNREACHABLE();
1448 return false;
1449 }
1450}
1451
Geoff Lang005df412013-10-16 14:12:50 -04001452bool IsDepthRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001453{
1454 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001455 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001456 {
1457 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1458 }
1459 else
1460 {
1461 UNREACHABLE();
1462 return false;
1463 }
1464}
1465
Geoff Lang005df412013-10-16 14:12:50 -04001466bool IsStencilRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001467{
1468 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001469 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001470 {
1471 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1472 }
1473 else
1474 {
1475 UNREACHABLE();
1476 return false;
1477 }
1478}
1479
Geoff Lang005df412013-10-16 14:12:50 -04001480bool IsStencilRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001481{
1482 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001483 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001484 {
1485 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1486 }
1487 else
1488 {
1489 UNREACHABLE();
1490 return false;
1491 }
1492}
1493
Geoff Lang005df412013-10-16 14:12:50 -04001494GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001495{
1496 ASSERT(alignment > 0 && isPow2(alignment));
1497 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1498}
1499
Geoff Lang005df412013-10-16 14:12:50 -04001500GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001501{
Jamie Madill666e2862013-09-10 12:04:29 -04001502 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001503}
1504
Geoff Lang005df412013-10-16 14:12:50 -04001505GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
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 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001510 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001511 {
1512 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1513 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1514
1515 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1516 }
1517 else
1518 {
1519 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001520 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001521 {
1522 if (typeInfo.mSpecialInterpretation)
1523 {
1524 return typeInfo.mTypeBytes * width * height;
1525 }
1526 else
1527 {
1528 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1529 }
1530 }
1531 else
1532 {
1533 UNREACHABLE();
1534 return 0;
1535 }
1536 }
1537 }
1538 else
1539 {
1540 UNREACHABLE();
1541 return 0;
1542 }
1543}
1544
Geoff Lang005df412013-10-16 14:12:50 -04001545bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001546{
1547 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001548 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001549 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001550 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001551 }
1552 else
1553 {
1554 UNREACHABLE();
1555 return false;
1556 }
1557}
1558
Geoff Lang005df412013-10-16 14:12:50 -04001559GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001560{
1561 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001562 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001563 {
1564 return internalFormatInfo.mCompressedBlockWidth;
1565 }
1566 else
1567 {
1568 UNREACHABLE();
1569 return 0;
1570 }
1571}
1572
Geoff Lang005df412013-10-16 14:12:50 -04001573GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001574{
1575 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001576 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001577 {
1578 return internalFormatInfo.mCompressedBlockHeight;
1579 }
1580 else
1581 {
1582 UNREACHABLE();
1583 return 0;
1584 }
1585}
1586
Geoff Langfe28ca02013-06-04 10:10:48 -04001587ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1588{
1589 static const FormatMap &formats = GetFormatMap(clientVersion);
1590 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1591 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1592}
1593
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001594}