blob: c0f6d9ebcb397799cee2f3a5a26e80efe9c58833 [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{
26 GLint mInternalFormat;
27 ColorWriteFunction mColorWriteFunction;
28
29 FormatTypeInfo(GLint internalFormat, ColorWriteFunction writeFunc)
30 : 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 Langfe28ca02013-06-04 10:10:48 -040039static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLint 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{
199 GLint mInternalformat;
200 GLenum mFormat;
201 GLenum mType;
202
203 FormatInfo(GLint internalformat, GLenum format, GLenum type)
204 : 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 )));
414 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 4, true )));
415 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
416
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 Langb2f3d052013-08-13 12:49:27 -0400604 static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000605 ContextRendererSupportCheckFunction depthRenderable,
606 ContextRendererSupportCheckFunction stencilRenderable,
607 ContextSupportCheckFunction supportFunction)
608 {
609 InternalFormatInfo formatInfo;
610 formatInfo.mDepthBits = depth;
611 formatInfo.mStencilBits = stencil;
612 formatInfo.mPixelBits = depth + stencil;
613 formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0);
614 formatInfo.mFormat = format;
615 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400616 formatInfo.mComponentType = componentType;
617 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000618 formatInfo.mIsDepthRenderable = depthRenderable;
619 formatInfo.mIsStencilRenderable = stencilRenderable;
Nicolas Capens08be89d2013-07-16 16:17:31 -0400620 formatInfo.mIsTextureFilterable = AlwaysSupported;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000621 formatInfo.mSupportFunction = supportFunction;
622 return formatInfo;
623 }
624
Geoff Langb2f3d052013-08-13 12:49:27 -0400625 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
626 GLuint componentCount, GLenum format, GLenum type, bool srgb,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000627 ContextSupportCheckFunction supportFunction)
628 {
629 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000630 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
631 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
632 formatInfo.mPixelBits = compressedBlockSize;
633 formatInfo.mComponentCount = componentCount;
634 formatInfo.mFormat = format;
635 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400636 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
637 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
638 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000639 formatInfo.mIsTextureFilterable = AlwaysSupported;
640 formatInfo.mSupportFunction = supportFunction;
641 return formatInfo;
642 }
643};
644
645typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair;
646typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap;
647
Geoff Lang18591b72013-06-07 12:00:15 -0400648static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000649{
650 InternalFormatInfoMap map;
651
652 // From ES 3.0.1 spec, table 3.12
653 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
654
Geoff Langb2f3d052013-08-13 12:49:27 -0400655 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
656 // | | | | | | | | | | | | renderable | filterable | |
657 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
658 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
659 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
660 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
661 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
662 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 -0400663 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 -0400664 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 )));
665 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 )));
666 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
667 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
668 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 -0400669 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 -0400670 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
671 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 )));
672 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 )));
673 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 )));
674 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
675 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 )));
676 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
677 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 )));
678 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
679 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 )));
680 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
681 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 )));
682 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
683 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 )));
684 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
685 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 )));
686 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
687 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 )));
688 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
689 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 )));
690 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
691 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 )));
692 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
693 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 )));
694 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 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 )));
696 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
697 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 +0000698
Geoff Langb2f3d052013-08-13 12:49:27 -0400699 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 )));
700 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 )));
701 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 +0000702
703 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langb2f3d052013-08-13 12:49:27 -0400704 // | Internal format | | D |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
705 // | | | | | | | type | | | | |
706 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 )));
707 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 )));
708 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 )));
709 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 )));
710 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 )));
711 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 )));
712 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 )));
713 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 +0000714
715 // Depth stencil formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400716 // | Internal format | | D |S | Format | Type | Component type | Depth | Stencil | Supported |
717 // | | | | | | | | renderable | renderable | |
718 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
719 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
720 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported)));
721 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
722 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
723 map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
724 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000725
726 // Luminance alpha formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400727 // | Internal format | | L | A | Format | Type | Component type | Supported |
728 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
729 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
730 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
731 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
732 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
733 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
734 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
735 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
736 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 +0000737
738 // Unsized formats
739 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000740 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
741 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400743 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000745 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
746 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400747 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
748 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
749 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
750 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000751 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
752
753 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400754 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
755 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
756 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
757 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
758 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
759 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
760 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
761 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)));
762 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)));
763 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
764 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 +0000765
766 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400767 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
768 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)));
769 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 +0000770
771 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400772 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 +0000773
774 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400775 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 +0000776
777 return map;
778}
779
Geoff Lang18591b72013-06-07 12:00:15 -0400780static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000781{
782 InternalFormatInfoMap map;
783
784 // From ES 2.0.25 table 4.5
785 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
786
Geoff Langb2f3d052013-08-13 12:49:27 -0400787 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
788 // | | | | | | | | | | | | renderable | filterable | |
789 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)));
790 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)));
791 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 +0000792
793 // Extension formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400794 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)));
795 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)));
796 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)));
797 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)));
798 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 +0000799
800 // Floating point formats have to query the renderer for support
Geoff Langb2f3d052013-08-13 12:49:27 -0400801 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
802 // | | | | | | | | | | type | | | | |
803 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>)));
804 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>)));
805 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>)));
806 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 +0000807
808 // Depth and stencil formats
Shannon Woods9e73b212013-07-08 10:32:19 -0400809 // | Internal format | | D |S | Format | Type | Internal format | Depth | Stencil | Supported |
810 // | | | | | | | type | renderable | renderable | |
Geoff Langb2f3d052013-08-13 12:49:27 -0400811 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
812 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>)));
813 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
814 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000815
816 // Unsized formats
817 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000818 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
819 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
820 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
821 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
822 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
823 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
824 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
825 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
826
827 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langb2f3d052013-08-13 12:49:27 -0400828 // | Internal format | | L | A | Format | Type | Component type | Supported |
829 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
830 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
831 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
832 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
833 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
834 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
835 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
836 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
837 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 +0000838
839 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400840 // | Internal format | |W |H | BS |CC|Format | Type | SRGB | Supported |
841 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>)));
842 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 +0000843
844 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400845 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 +0000846
847 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400848 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 +0000849
850 return map;
851}
852
Geoff Lang18591b72013-06-07 12:00:15 -0400853static bool GetInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000854{
855 const InternalFormatInfoMap* map = NULL;
856
857 if (clientVersion == 2)
858 {
Geoff Lang18591b72013-06-07 12:00:15 -0400859 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000860 map = &formatMap;
861 }
862 else if (clientVersion == 3)
863 {
Geoff Lang18591b72013-06-07 12:00:15 -0400864 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000865 map = &formatMap;
866 }
867 else
868 {
869 UNREACHABLE();
870 }
871
872 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
873 if (iter != map->end())
874 {
875 if (outFormatInfo)
876 {
877 *outFormatInfo = iter->second;
878 }
879 return true;
880 }
881 else
882 {
883 return false;
884 }
885}
886
887typedef std::set<GLenum> FormatSet;
888
Geoff Lang18591b72013-06-07 12:00:15 -0400889static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000890{
Geoff Langfe28ca02013-06-04 10:10:48 -0400891 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000892
893 FormatSet set;
894
895 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
896 {
897 const FormatTypePair& formatPair = i->first;
898 set.insert(formatPair.first);
899 }
900
901 return set;
902}
903
Geoff Lang18591b72013-06-07 12:00:15 -0400904static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000905{
Geoff Lang18591b72013-06-07 12:00:15 -0400906 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000907
908 FormatSet set;
909
910 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
911 {
912 const FormatInfo& formatInfo = *i;
913 set.insert(formatInfo.mFormat);
914 }
915
916 return set;
917}
918
919typedef std::set<GLenum> TypeSet;
920
Geoff Lang18591b72013-06-07 12:00:15 -0400921static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000922{
Geoff Langfe28ca02013-06-04 10:10:48 -0400923 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000924
925 TypeSet set;
926
927 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
928 {
929 const FormatTypePair& formatPair = i->first;
930 set.insert(formatPair.second);
931 }
932
933 return set;
934}
935
Geoff Lang18591b72013-06-07 12:00:15 -0400936static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000937{
Geoff Lang18591b72013-06-07 12:00:15 -0400938 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000939
940 TypeSet set;
941
942 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
943 {
944 const FormatInfo& formatInfo = *i;
945 set.insert(formatInfo.mType);
946 }
947
948 return set;
949}
950
951struct CopyConversion
952{
953 GLenum mTextureFormat;
954 GLenum mFramebufferFormat;
955
956 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
957 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
958
959 bool operator<(const CopyConversion& other) const
960 {
961 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
962 }
963};
964
965typedef std::set<CopyConversion> CopyConversionSet;
966
Geoff Lang18591b72013-06-07 12:00:15 -0400967static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000968{
969 CopyConversionSet set;
970
971 // From ES 3.0.1 spec, table 3.15
972 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
973 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
974 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
975 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
976 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
977 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
978 set.insert(CopyConversion(GL_RED, GL_RED));
979 set.insert(CopyConversion(GL_RED, GL_RG));
980 set.insert(CopyConversion(GL_RED, GL_RGB));
981 set.insert(CopyConversion(GL_RED, GL_RGBA));
982 set.insert(CopyConversion(GL_RG, GL_RG));
983 set.insert(CopyConversion(GL_RG, GL_RGB));
984 set.insert(CopyConversion(GL_RG, GL_RGBA));
985 set.insert(CopyConversion(GL_RGB, GL_RGB));
986 set.insert(CopyConversion(GL_RGB, GL_RGBA));
987 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
988
Jamie Madillb70e5f72013-07-10 16:57:52 -0400989 // Necessary for ANGLE back-buffers
990 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
991 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
992 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
993 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
994 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
995 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
996 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
997
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +0000998 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
999 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1000 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1001 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1002 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1003 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1004 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1005 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1006 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1007 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1008
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001009 return set;
1010}
1011
1012bool IsValidInternalFormat(GLint internalFormat, const Context *context)
1013{
1014 if (!context)
1015 {
1016 return false;
1017 }
1018
1019 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001020 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001021 {
1022 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1023 return internalFormatInfo.mSupportFunction(context);
1024 }
1025 else
1026 {
1027 return false;
1028 }
1029}
1030
1031bool IsValidFormat(GLenum format, GLuint clientVersion)
1032{
1033 if (clientVersion == 2)
1034 {
Geoff Lang18591b72013-06-07 12:00:15 -04001035 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001036 return formatSet.find(format) != formatSet.end();
1037 }
1038 else if (clientVersion == 3)
1039 {
Geoff Lang18591b72013-06-07 12:00:15 -04001040 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001041 return formatSet.find(format) != formatSet.end();
1042 }
1043 else
1044 {
1045 UNREACHABLE();
1046 return false;
1047 }
1048}
1049
1050bool IsValidType(GLenum type, GLuint clientVersion)
1051{
1052 if (clientVersion == 2)
1053 {
Geoff Lang18591b72013-06-07 12:00:15 -04001054 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001055 return typeSet.find(type) != typeSet.end();
1056 }
1057 else if (clientVersion == 3)
1058 {
Geoff Lang18591b72013-06-07 12:00:15 -04001059 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001060 return typeSet.find(type) != typeSet.end();
1061 }
1062 else
1063 {
1064 UNREACHABLE();
1065 return false;
1066 }
1067}
1068
1069bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion)
1070{
1071 if (clientVersion == 2)
1072 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001073 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001074 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1075
Geoff Langfe28ca02013-06-04 10:10:48 -04001076 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001077 }
1078 else if (clientVersion == 3)
1079 {
Geoff Lang18591b72013-06-07 12:00:15 -04001080 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001081 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1082 }
1083 else
1084 {
1085 UNREACHABLE();
1086 return false;
1087 }
1088}
1089
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001090bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001091{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001092 InternalFormatInfo textureInternalFormatInfo;
1093 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001094 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1095 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001096 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001097 if (clientVersion == 2)
1098 {
1099 UNIMPLEMENTED();
1100 return false;
1101 }
1102 else if (clientVersion == 3)
1103 {
Geoff Lang18591b72013-06-07 12:00:15 -04001104 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001105 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1106 framebufferInternalFormatInfo.mFormat);
1107 if (conversionSet.find(conversion) != conversionSet.end())
1108 {
1109 // 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 +00001110 // must both be signed or unsigned or fixed/floating point and both source and destinations
1111 // must be either both SRGB or both not SRGB
1112
Geoff Langb2f3d052013-08-13 12:49:27 -04001113 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001114 {
1115 return false;
1116 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001117
Geoff Langb2f3d052013-08-13 12:49:27 -04001118 if ((textureInternalFormatInfo.mComponentType == GL_INT && framebufferInternalFormatInfo.mComponentType == GL_INT ) ||
1119 (textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT && framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001120 {
1121 return true;
1122 }
1123
Geoff Langb2f3d052013-08-13 12:49:27 -04001124 if ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1125 textureInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1126 textureInternalFormatInfo.mComponentType == GL_FLOAT ) &&
1127 (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1128 framebufferInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1129 framebufferInternalFormatInfo.mComponentType == GL_FLOAT ))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001130 {
1131 return true;
1132 }
1133 }
1134
1135 return false;
1136 }
1137 else
1138 {
1139 UNREACHABLE();
1140 return false;
1141 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001142 }
1143 else
1144 {
1145 UNREACHABLE();
1146 return false;
1147 }
1148}
1149
1150bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1151{
1152 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001153 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001154 {
1155 return internalFormatInfo.mPixelBits > 0;
1156 }
1157 else
1158 {
1159 UNREACHABLE();
1160 return false;
1161 }
1162}
1163
1164GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1165{
Geoff Langfe28ca02013-06-04 10:10:48 -04001166 const FormatMap &formats = GetFormatMap(clientVersion);
1167 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1168 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001169}
1170
1171GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1172{
1173 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001174 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001175 {
1176 return internalFormatInfo.mPixelBits / 8;
1177 }
1178 else
1179 {
1180 UNREACHABLE();
1181 return 0;
1182 }
1183}
1184
1185GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion)
1186{
1187 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001188 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001189 {
1190 return internalFormatInfo.mAlphaBits;
1191 }
1192 else
1193 {
1194 UNREACHABLE();
1195 return 0;
1196 }
1197}
1198
1199GLuint GetRedBits(GLint internalFormat, GLuint clientVersion)
1200{
1201 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001202 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001203 {
1204 return internalFormatInfo.mRedBits;
1205 }
1206 else
1207 {
1208 UNREACHABLE();
1209 return 0;
1210 }
1211}
1212
1213GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion)
1214{
1215 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001216 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001217 {
1218 return internalFormatInfo.mGreenBits;
1219 }
1220 else
1221 {
1222 UNREACHABLE();
1223 return 0;
1224 }
1225}
1226
1227GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion)
1228{
1229 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001230 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001231 {
Geoff Lang24159222013-06-05 14:56:32 -04001232 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001233 }
1234 else
1235 {
1236 UNREACHABLE();
1237 return 0;
1238 }
1239}
1240
1241GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion)
1242{
1243 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001244 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001245 {
1246 return internalFormatInfo.mLuminanceBits;
1247 }
1248 else
1249 {
1250 UNREACHABLE();
1251 return 0;
1252 }
1253}
1254
1255GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion)
1256{
1257 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001258 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001259 {
1260 return internalFormatInfo.mDepthBits;
1261 }
1262 else
1263 {
1264 UNREACHABLE();
1265 return 0;
1266 }
1267}
1268
1269GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion)
1270{
1271 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001272 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001273 {
1274 return internalFormatInfo.mStencilBits;
1275 }
1276 else
1277 {
1278 UNREACHABLE();
1279 return 0;
1280 }
1281}
1282
Geoff Langf23eb282013-07-22 10:52:19 -04001283GLuint GetTypeBytes(GLenum type)
1284{
1285 TypeInfo typeInfo;
1286 if (GetTypeInfo(type, &typeInfo))
1287 {
1288 return typeInfo.mTypeBytes;
1289 }
1290 else
1291 {
1292 UNREACHABLE();
1293 return 0;
1294 }
1295}
1296
1297bool IsSpecialInterpretationType(GLenum type)
1298{
1299 TypeInfo typeInfo;
1300 if (GetTypeInfo(type, &typeInfo))
1301 {
1302 return typeInfo.mSpecialInterpretation;
1303 }
1304 else
1305 {
1306 UNREACHABLE();
1307 return false;
1308 }
1309}
1310
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001311GLenum GetFormat(GLint internalFormat, GLuint clientVersion)
1312{
1313 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001314 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001315 {
1316 return internalFormatInfo.mFormat;
1317 }
1318 else
1319 {
1320 UNREACHABLE();
1321 return GL_NONE;
1322 }
1323}
1324
1325GLenum GetType(GLint internalFormat, GLuint clientVersion)
1326{
1327 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001328 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001329 {
1330 return internalFormatInfo.mType;
1331 }
1332 else
1333 {
1334 UNREACHABLE();
1335 return GL_NONE;
1336 }
1337}
1338
Geoff Langb2f3d052013-08-13 12:49:27 -04001339GLuint GetComponentType(GLint internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001340{
1341 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001342 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001343 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001344 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001345 }
1346 else
1347 {
1348 UNREACHABLE();
1349 return false;
1350 }
1351}
1352
Jamie Madill3466a4d2013-09-18 14:36:20 -04001353GLuint GetComponentCount(GLint internalFormat, GLuint clientVersion)
1354{
1355 InternalFormatInfo internalFormatInfo;
1356 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1357 {
1358 return internalFormatInfo.mComponentCount;
1359 }
1360 else
1361 {
1362 UNREACHABLE();
1363 return false;
1364 }
1365}
1366
Geoff Langb2f3d052013-08-13 12:49:27 -04001367GLenum GetColorEncoding(GLint internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001368{
1369 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001370 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001371 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001372 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001373 }
1374 else
1375 {
1376 UNREACHABLE();
1377 return false;
1378 }
1379}
1380
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001381bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1382{
1383 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001384 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001385 {
1386 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1387 }
1388 else
1389 {
1390 UNREACHABLE();
1391 return false;
1392 }
1393}
1394
1395bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1396{
1397 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001398 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001399 {
1400 return internalFormatInfo.mIsColorRenderable(context, NULL);
1401 }
1402 else
1403 {
1404 UNREACHABLE();
1405 return false;
1406 }
1407}
1408
1409bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1410{
1411 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001412 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001413 {
1414 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1415 }
1416 else
1417 {
1418 UNREACHABLE();
1419 return false;
1420 }
1421}
1422
1423bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1424{
1425 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001426 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001427 {
1428 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1429 }
1430 else
1431 {
1432 UNREACHABLE();
1433 return false;
1434 }
1435}
1436
1437bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1438{
1439 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001440 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001441 {
1442 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1443 }
1444 else
1445 {
1446 UNREACHABLE();
1447 return false;
1448 }
1449}
1450
1451bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1452{
1453 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001454 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001455 {
1456 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1457 }
1458 else
1459 {
1460 UNREACHABLE();
1461 return false;
1462 }
1463}
1464
1465bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1466{
1467 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001468 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001469 {
1470 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1471 }
1472 else
1473 {
1474 UNREACHABLE();
1475 return false;
1476 }
1477}
1478
1479bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1480{
1481 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001482 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001483 {
1484 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1485 }
1486 else
1487 {
1488 UNREACHABLE();
1489 return false;
1490 }
1491}
1492
1493GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1494{
1495 ASSERT(alignment > 0 && isPow2(alignment));
1496 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1497}
1498
1499GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1500{
Jamie Madill666e2862013-09-10 12:04:29 -04001501 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001502}
1503
1504GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1505{
1506 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001507 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001508 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001509 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001510 {
1511 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1512 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1513
1514 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1515 }
1516 else
1517 {
1518 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001519 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001520 {
1521 if (typeInfo.mSpecialInterpretation)
1522 {
1523 return typeInfo.mTypeBytes * width * height;
1524 }
1525 else
1526 {
1527 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1528 }
1529 }
1530 else
1531 {
1532 UNREACHABLE();
1533 return 0;
1534 }
1535 }
1536 }
1537 else
1538 {
1539 UNREACHABLE();
1540 return 0;
1541 }
1542}
1543
1544bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1545{
1546 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001547 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001548 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001549 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001550 }
1551 else
1552 {
1553 UNREACHABLE();
1554 return false;
1555 }
1556}
1557
1558GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1559{
1560 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001561 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001562 {
1563 return internalFormatInfo.mCompressedBlockWidth;
1564 }
1565 else
1566 {
1567 UNREACHABLE();
1568 return 0;
1569 }
1570}
1571
1572GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1573{
1574 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001575 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001576 {
1577 return internalFormatInfo.mCompressedBlockHeight;
1578 }
1579 else
1580 {
1581 UNREACHABLE();
1582 return 0;
1583 }
1584}
1585
Geoff Langfe28ca02013-06-04 10:10:48 -04001586ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1587{
1588 static const FormatMap &formats = GetFormatMap(clientVersion);
1589 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1590 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1591}
1592
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001593}