blob: 9f3acfe182a63675911ba7999e02edd3771043da [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
38// A helper function to insert data into the D3D11LoadFunctionMap 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> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000112
Geoff Langfe28ca02013-06-04 10:10:48 -0400113 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> );
114 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> );
115 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
116 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> );
117 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> );
118 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> );
119 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000120
Geoff Langfe28ca02013-06-04 10:10:48 -0400121 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> );
122 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> );
123 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> );
124 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> );
125 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> );
126 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000127
Geoff Langfe28ca02013-06-04 10:10:48 -0400128 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> );
129 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> );
130 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> );
131 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> );
132
133 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> );
134 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> );
135 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> );
136 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> );
137 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> );
138 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> );
139
140 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> );
141 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> );
142 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> );
143 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> );
144
145 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> );
146 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> );
147 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> );
148 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> );
149 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> );
150 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> );
151
152 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
153 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
154 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
155 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
156 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
157 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
158 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
159 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
160 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
161
162 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
163 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
164 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
165
166 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
167 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL );
168 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL );
169
170 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL );
171 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 +0000172
173 return map;
174}
175
Geoff Langfe28ca02013-06-04 10:10:48 -0400176static const FormatMap &GetFormatMap(GLuint clientVersion)
177{
178 if (clientVersion == 2)
179 {
180 static const FormatMap formats = BuildES2FormatMap();
181 return formats;
182 }
183 else if (clientVersion == 3)
184 {
185 static const FormatMap formats = BuildES3FormatMap();
186 return formats;
187 }
188 else
189 {
190 UNREACHABLE();
191 static FormatMap emptyMap;
192 return emptyMap;
193 }
194}
195
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000196struct FormatInfo
197{
198 GLint mInternalformat;
199 GLenum mFormat;
200 GLenum mType;
201
202 FormatInfo(GLint internalformat, GLenum format, GLenum type)
203 : mInternalformat(internalformat), mFormat(format), mType(type) { }
204
205 bool operator<(const FormatInfo& other) const
206 {
207 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
208 }
209};
210
211// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
212typedef std::set<FormatInfo> ES3FormatSet;
213
Geoff Lang18591b72013-06-07 12:00:15 -0400214ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000215{
216 ES3FormatSet set;
217
218 // Format combinations from ES 3.0.1 spec, table 3.2
219
220 // | Internal format | Format | Type |
221 // | | | |
222 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
223 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
224 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
225 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
226 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
227 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
228 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
229 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000230 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000231 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
232 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
233 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
234 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
235 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
236 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
237 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
238 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
239 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
240 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
241 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
242 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
243 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
244 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
245 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
246 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
247 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
248 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
249 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
250 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
251 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
252 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
253 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
254 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
255 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
256 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
257 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
258 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
259 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
260 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
261 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
262 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
263 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
264 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
265 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
266 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
267 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
268 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
269 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
270 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
271 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
272 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
273 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
274 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
275 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
276 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
277 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
278 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
279 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
280 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
281 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
282 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
283
284 // Unsized formats
285 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
286 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
287 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
288 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
289 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
290 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
291 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
292 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
293
294 // Depth stencil formats
295 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
296 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
297 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
298 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
299 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
300 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
301
302 // From GL_OES_texture_float
303 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
304 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
305 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
306
307 // From GL_OES_texture_half_float
308 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
309 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
310 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
311
312 // From GL_EXT_texture_storage
313 // | Internal format | Format | Type |
314 // | | | |
315 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
316 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
317 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
318 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
319 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
320 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
321 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
322 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
323 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
324
325 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
326 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
327 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
328 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
329 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
330
331 // From GL_ANGLE_depth_texture
332 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
333
334 // Compressed formats
335 // From ES 3.0.1 spec, table 3.16
336 // | Internal format | Format | Type |
337 // | | | |
338 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
339 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
340 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
341 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
342 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
343 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
344 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
345 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
346 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
347 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
348 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
349
350
351 // From GL_EXT_texture_compression_dxt1
352 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
353 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
354
355 // From GL_ANGLE_texture_compression_dxt3
356 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
357
358 // From GL_ANGLE_texture_compression_dxt5
359 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
360
361 return set;
362}
363
Geoff Lang18591b72013-06-07 12:00:15 -0400364static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000365{
Geoff Lang18591b72013-06-07 12:00:15 -0400366 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000367 return es3FormatSet;
368}
369
370// Map of sizes of input types
371struct TypeInfo
372{
373 GLuint mTypeBytes;
374 bool mSpecialInterpretation;
375
376 TypeInfo()
377 : mTypeBytes(0), mSpecialInterpretation(false) { }
378
379 TypeInfo(GLuint typeBytes, bool specialInterpretation)
380 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
381
382 bool operator<(const TypeInfo& other) const
383 {
384 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
385 }
386};
387
388typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
389typedef std::map<GLenum, TypeInfo> TypeInfoMap;
390
Geoff Lang18591b72013-06-07 12:00:15 -0400391static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000392{
393 TypeInfoMap map;
394
395 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
396 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
397 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
398 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
399 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
400 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
401 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
402 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
403 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
404 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
405 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
406 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
407 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
408 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
409 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
410 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
411 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
412 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 4, true )));
413 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
414
415 return map;
416}
417
Geoff Lang18591b72013-06-07 12:00:15 -0400418static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000419{
Geoff Lang18591b72013-06-07 12:00:15 -0400420 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000421 TypeInfoMap::const_iterator iter = infoMap.find(type);
422 if (iter != infoMap.end())
423 {
424 if (outTypeInfo)
425 {
426 *outTypeInfo = iter->second;
427 }
428 return true;
429 }
430 else
431 {
432 return false;
433 }
434}
435
436// Information about internal formats
437typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
438typedef bool (*ContextSupportCheckFunction)(const Context *context);
439
440typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
441typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
442
443template <ContextSupportCheckMemberFunction func>
444bool CheckSupport(const Context *context)
445{
446 return (context->*func)();
447}
448
449template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
450bool CheckSupport(const Context *context, const rx::Renderer *renderer)
451{
452 if (context)
453 {
454 return (context->*contextFunc)();
455 }
456 else if (renderer)
457 {
458 return (renderer->*rendererFunc)();
459 }
460 else
461 {
462 UNREACHABLE();
463 return false;
464 }
465}
466
467template <typename objectType>
468bool AlwaysSupported(const objectType*)
469{
470 return true;
471}
472
473template <typename objectTypeA, typename objectTypeB>
474bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
475{
476 return true;
477}
478
479template <typename objectType>
480bool NeverSupported(const objectType*)
481{
482 return false;
483}
484
485template <typename objectTypeA, typename objectTypeB>
486bool NeverSupported(const objectTypeA *, const objectTypeB *)
487{
488 return false;
489}
490
491template <typename objectType>
492bool UnimplementedSupport(const objectType*)
493{
494 UNIMPLEMENTED();
495 return false;
496}
497
498template <typename objectTypeA, typename objectTypeB>
499bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
500{
501 UNIMPLEMENTED();
502 return false;
503}
504
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000505enum InternalFormatStorageType
506{
507 Unknown,
508 NormalizedFixedPoint,
509 FloatingPoint,
510 SignedInteger,
511 UnsignedInteger,
512 Compressed,
513};
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000514
515struct InternalFormatInfo
516{
517 GLuint mRedBits;
518 GLuint mGreenBits;
519 GLuint mBlueBits;
520
521 GLuint mLuminanceBits;
522
523 GLuint mAlphaBits;
524 GLuint mSharedBits;
525
526 GLuint mDepthBits;
527 GLuint mStencilBits;
528
529 GLuint mPixelBits;
530
531 GLuint mComponentCount;
532
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000533 GLuint mCompressedBlockWidth;
534 GLuint mCompressedBlockHeight;
535
536 GLenum mFormat;
537 GLenum mType;
538
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000539 InternalFormatStorageType mStorageType;
540
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000541 bool mIsSRGB;
542
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000543 ContextRendererSupportCheckFunction mIsColorRenderable;
544 ContextRendererSupportCheckFunction mIsDepthRenderable;
545 ContextRendererSupportCheckFunction mIsStencilRenderable;
546 ContextRendererSupportCheckFunction mIsTextureFilterable;
547
548 ContextSupportCheckFunction mSupportFunction;
549
550 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 +0000551 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000552 mStorageType(Unknown), mIsSRGB(false), mIsColorRenderable(NeverSupported), mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported),
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000553 mIsTextureFilterable(NeverSupported), mSupportFunction(NeverSupported)
554 {
555 }
556
557 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
558 {
559 InternalFormatInfo formatInfo;
560 formatInfo.mFormat = format;
561 formatInfo.mSupportFunction = supportFunction;
562 return formatInfo;
563 }
564
565 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000566 GLenum format, GLenum type, InternalFormatStorageType storageType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000567 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000568 ContextRendererSupportCheckFunction textureFilterable,
569 ContextSupportCheckFunction supportFunction)
570 {
571 InternalFormatInfo formatInfo;
572 formatInfo.mRedBits = red;
573 formatInfo.mGreenBits = green;
574 formatInfo.mBlueBits = blue;
575 formatInfo.mAlphaBits = alpha;
576 formatInfo.mSharedBits = shared;
577 formatInfo.mPixelBits = red + green + blue + alpha + shared;
578 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
579 formatInfo.mFormat = format;
580 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000581 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000582 formatInfo.mIsSRGB = srgb;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000583 formatInfo.mIsColorRenderable = colorRenderable;
584 formatInfo.mIsTextureFilterable = textureFilterable;
585 formatInfo.mSupportFunction = supportFunction;
586 return formatInfo;
587 }
588
589 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000590 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000591 ContextSupportCheckFunction supportFunction)
592 {
593 InternalFormatInfo formatInfo;
594 formatInfo.mLuminanceBits = luminance;
595 formatInfo.mAlphaBits = alpha;
596 formatInfo.mPixelBits = luminance + alpha;
597 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
598 formatInfo.mFormat = format;
599 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000600 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000601 formatInfo.mIsTextureFilterable = AlwaysSupported;
602 formatInfo.mSupportFunction = supportFunction;
603 return formatInfo;
604 }
605
606 static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000607 InternalFormatStorageType storageType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000608 ContextRendererSupportCheckFunction depthRenderable,
609 ContextRendererSupportCheckFunction stencilRenderable,
610 ContextSupportCheckFunction supportFunction)
611 {
612 InternalFormatInfo formatInfo;
613 formatInfo.mDepthBits = depth;
614 formatInfo.mStencilBits = stencil;
615 formatInfo.mPixelBits = depth + stencil;
616 formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0);
617 formatInfo.mFormat = format;
618 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000619 formatInfo.mStorageType = storageType;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000620 formatInfo.mIsDepthRenderable = depthRenderable;
621 formatInfo.mIsStencilRenderable = stencilRenderable;
622 formatInfo.mSupportFunction = supportFunction;
623 return formatInfo;
624 }
625
626 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight,
627 GLuint compressedBlockSize, GLuint componentCount, GLenum format, GLenum type,
628 ContextSupportCheckFunction supportFunction)
629 {
630 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
632 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
633 formatInfo.mPixelBits = compressedBlockSize;
634 formatInfo.mComponentCount = componentCount;
635 formatInfo.mFormat = format;
636 formatInfo.mType = type;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000637 formatInfo.mStorageType = Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000638 formatInfo.mIsTextureFilterable = AlwaysSupported;
639 formatInfo.mSupportFunction = supportFunction;
640 return formatInfo;
641 }
642};
643
644typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair;
645typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap;
646
Geoff Lang18591b72013-06-07 12:00:15 -0400647static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648{
649 InternalFormatInfoMap map;
650
651 // From ES 3.0.1 spec, table 3.12
652 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
653
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000654 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
655 // | | | | | | | | | | type | | renderable | filterable | |
656 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
657 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
658 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
659 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
660 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
661 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
662 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
Geoff Lang74eb9152013-05-29 16:09:05 -0400663 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000664 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
665 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
666 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
667 map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
668 map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
669 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
670 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, true, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
671 map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, FloatingPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
672 map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, FloatingPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
673 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
674 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
675 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
676 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
677 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
678 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
679 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
680 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
681 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
682 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
683 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
684 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
685 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
686 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
687 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
688 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
689 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, SignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
690 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, NeverSupported, NeverSupported, AlwaysSupported )));
691 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
692 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
693 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
694 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, SignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
696 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, UnsignedInteger, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000697
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000698 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
699 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, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
700 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, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000701
702 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000703 // | Internal format | | D |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
704 // | | | | | | | type | | renderable | filterable | |
705 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
706 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
707 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
708 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
709 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
710 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
711 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
712 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000713
714 // Depth stencil formats
Geoff Langa3495322013-06-18 15:16:15 -0400715 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
716 // | | | | | | | type | renderable | filterable | |
717 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
718 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
719 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, FloatingPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
720 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
721 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
722 map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, FloatingPoint, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000723
724 // Luminance alpha formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000725 // | Internal format | | L | A | Format | Type | Internal format | Supported |
726 // | | | | | | | type | |
727 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
728 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
729 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
730 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
731 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
732 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
733 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
734 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
735 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, FloatingPoint, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000736
737 // Unsized formats
738 // | Internal format | | Format | Supported |
739 // | | | | |
740 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)));
743 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
746
747 // Compressed formats, From ES 3.0.1 spec, table 3.16
748 // | Internal format | |W |H | B |C | Format | Type | Supported |
749 // | | | | | S |C | | | |
750 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
751 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
752 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
753 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
754 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
755 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
756 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
757 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport)));
758 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
759 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport)));
760
761 // From GL_EXT_texture_compression_dxt1
762 // | Internal format | |W |H | B |C | Format | Type | Supported |
763 // | | | | | S |C | | | |
764 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported)));
765 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported)));
766
767 // From GL_ANGLE_texture_compression_dxt3
768 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported)));
769
770 // From GL_ANGLE_texture_compression_dxt5
771 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported)));
772
773 return map;
774}
775
Geoff Lang18591b72013-06-07 12:00:15 -0400776static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000777{
778 InternalFormatInfoMap map;
779
780 // From ES 2.0.25 table 4.5
781 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
782
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000783 // | Internal format | | R | G | B | A |S | Format | Type | Internal format | SRGB | Color | Texture | Supported |
784 // | | | | | | | | | | type | | renderable | filterable | |
785 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
786 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
Geoff Lang42b8b902013-06-05 16:08:21 -0400787 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000788
789 // Extension formats
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000790 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
791 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
792 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NormalizedFixedPoint, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
793 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
794 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_5_5_1, NormalizedFixedPoint, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000795
796 // Floating point formats have to query the renderer for support
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000797 // | Internal format | | R | G | B | A |S | Format | Type | Internal fmt | SRGB | Color | Texture | Supported |
798 // | | | | | | | | | | type | | renderable | filterable | |
799 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
800 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
801 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, FloatingPoint, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
802 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, FloatingPoint, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000803
804 // Depth and stencil formats
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000805 // | Internal format | | D |S | Format | Type | Internal format | Color | Texture | Supported |
806 // | | | | | | | type | renderable | filterable | |
807 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
808 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NormalizedFixedPoint, AlwaysSupported, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>)));
809 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NormalizedFixedPoint, AlwaysSupported, NeverSupported, AlwaysSupported)));
810 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, NormalizedFixedPoint, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000811
812 // Unsized formats
813 // | Internal format | | Format | Supported |
814 // | | | | |
815 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
816 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
817 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
818 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
819 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
820 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
821 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
822 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
823
824 // Luminance alpha formats from GL_EXT_texture_storage
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000825 // | Internal format | | L | A | Format | Type | Internal format | Supported |
826 // | | | | | | | type | |
827 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
828 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
829 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
830 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, FloatingPoint, AlwaysSupported)));
831 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
832 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
833 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NormalizedFixedPoint, AlwaysSupported)));
834 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, FloatingPoint, AlwaysSupported)));
835 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, FloatingPoint, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000836
837 // From GL_EXT_texture_compression_dxt1
838 // | Internal format | |W |H | B |C |Format | Type | Supported |
839 // | | | | | S |C | | | |
840 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>)));
841 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>)));
842
843 // From GL_ANGLE_texture_compression_dxt3
844 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT3Textures>)));
845
846 // From GL_ANGLE_texture_compression_dxt5
847 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT5Textures>)));
848
849 return map;
850}
851
Geoff Lang18591b72013-06-07 12:00:15 -0400852static bool GetInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000853{
854 const InternalFormatInfoMap* map = NULL;
855
856 if (clientVersion == 2)
857 {
Geoff Lang18591b72013-06-07 12:00:15 -0400858 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000859 map = &formatMap;
860 }
861 else if (clientVersion == 3)
862 {
Geoff Lang18591b72013-06-07 12:00:15 -0400863 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000864 map = &formatMap;
865 }
866 else
867 {
868 UNREACHABLE();
869 }
870
871 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
872 if (iter != map->end())
873 {
874 if (outFormatInfo)
875 {
876 *outFormatInfo = iter->second;
877 }
878 return true;
879 }
880 else
881 {
882 return false;
883 }
884}
885
886typedef std::set<GLenum> FormatSet;
887
Geoff Lang18591b72013-06-07 12:00:15 -0400888static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000889{
Geoff Langfe28ca02013-06-04 10:10:48 -0400890 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000891
892 FormatSet set;
893
894 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
895 {
896 const FormatTypePair& formatPair = i->first;
897 set.insert(formatPair.first);
898 }
899
900 return set;
901}
902
Geoff Lang18591b72013-06-07 12:00:15 -0400903static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000904{
Geoff Lang18591b72013-06-07 12:00:15 -0400905 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000906
907 FormatSet set;
908
909 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
910 {
911 const FormatInfo& formatInfo = *i;
912 set.insert(formatInfo.mFormat);
913 }
914
915 return set;
916}
917
918typedef std::set<GLenum> TypeSet;
919
Geoff Lang18591b72013-06-07 12:00:15 -0400920static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000921{
Geoff Langfe28ca02013-06-04 10:10:48 -0400922 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923
924 TypeSet set;
925
926 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
927 {
928 const FormatTypePair& formatPair = i->first;
929 set.insert(formatPair.second);
930 }
931
932 return set;
933}
934
Geoff Lang18591b72013-06-07 12:00:15 -0400935static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000936{
Geoff Lang18591b72013-06-07 12:00:15 -0400937 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000938
939 TypeSet set;
940
941 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
942 {
943 const FormatInfo& formatInfo = *i;
944 set.insert(formatInfo.mType);
945 }
946
947 return set;
948}
949
950struct CopyConversion
951{
952 GLenum mTextureFormat;
953 GLenum mFramebufferFormat;
954
955 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
956 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
957
958 bool operator<(const CopyConversion& other) const
959 {
960 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
961 }
962};
963
964typedef std::set<CopyConversion> CopyConversionSet;
965
Geoff Lang18591b72013-06-07 12:00:15 -0400966static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000967{
968 CopyConversionSet set;
969
970 // From ES 3.0.1 spec, table 3.15
971 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
972 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
973 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
974 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
975 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
976 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
977 set.insert(CopyConversion(GL_RED, GL_RED));
978 set.insert(CopyConversion(GL_RED, GL_RG));
979 set.insert(CopyConversion(GL_RED, GL_RGB));
980 set.insert(CopyConversion(GL_RED, GL_RGBA));
981 set.insert(CopyConversion(GL_RG, GL_RG));
982 set.insert(CopyConversion(GL_RG, GL_RGB));
983 set.insert(CopyConversion(GL_RG, GL_RGBA));
984 set.insert(CopyConversion(GL_RGB, GL_RGB));
985 set.insert(CopyConversion(GL_RGB, GL_RGBA));
986 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
987
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +0000988 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
989 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
990 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
991 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
992 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
993 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
994 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
995 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
996 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
997 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
998
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000999 return set;
1000}
1001
1002bool IsValidInternalFormat(GLint internalFormat, const Context *context)
1003{
1004 if (!context)
1005 {
1006 return false;
1007 }
1008
1009 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001010 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001011 {
1012 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1013 return internalFormatInfo.mSupportFunction(context);
1014 }
1015 else
1016 {
1017 return false;
1018 }
1019}
1020
1021bool IsValidFormat(GLenum format, GLuint clientVersion)
1022{
1023 if (clientVersion == 2)
1024 {
Geoff Lang18591b72013-06-07 12:00:15 -04001025 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001026 return formatSet.find(format) != formatSet.end();
1027 }
1028 else if (clientVersion == 3)
1029 {
Geoff Lang18591b72013-06-07 12:00:15 -04001030 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001031 return formatSet.find(format) != formatSet.end();
1032 }
1033 else
1034 {
1035 UNREACHABLE();
1036 return false;
1037 }
1038}
1039
1040bool IsValidType(GLenum type, GLuint clientVersion)
1041{
1042 if (clientVersion == 2)
1043 {
Geoff Lang18591b72013-06-07 12:00:15 -04001044 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001045 return typeSet.find(type) != typeSet.end();
1046 }
1047 else if (clientVersion == 3)
1048 {
Geoff Lang18591b72013-06-07 12:00:15 -04001049 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001050 return typeSet.find(type) != typeSet.end();
1051 }
1052 else
1053 {
1054 UNREACHABLE();
1055 return false;
1056 }
1057}
1058
1059bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion)
1060{
1061 if (clientVersion == 2)
1062 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001063 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001064 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1065
Geoff Langfe28ca02013-06-04 10:10:48 -04001066 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001067 }
1068 else if (clientVersion == 3)
1069 {
Geoff Lang18591b72013-06-07 12:00:15 -04001070 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001071 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1072 }
1073 else
1074 {
1075 UNREACHABLE();
1076 return false;
1077 }
1078}
1079
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001080bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001081{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001082 InternalFormatInfo textureInternalFormatInfo;
1083 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001084 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1085 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001086 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001087 if (clientVersion == 2)
1088 {
1089 UNIMPLEMENTED();
1090 return false;
1091 }
1092 else if (clientVersion == 3)
1093 {
Geoff Lang18591b72013-06-07 12:00:15 -04001094 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001095 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1096 framebufferInternalFormatInfo.mFormat);
1097 if (conversionSet.find(conversion) != conversionSet.end())
1098 {
1099 // 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 +00001100 // must both be signed or unsigned or fixed/floating point and both source and destinations
1101 // must be either both SRGB or both not SRGB
1102
1103 if (textureInternalFormatInfo.mIsSRGB != framebufferInternalFormatInfo.mIsSRGB)
1104 {
1105 return false;
1106 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001107
1108 if ((textureInternalFormatInfo.mStorageType == SignedInteger && framebufferInternalFormatInfo.mStorageType == SignedInteger ) ||
1109 (textureInternalFormatInfo.mStorageType == UnsignedInteger && framebufferInternalFormatInfo.mStorageType == UnsignedInteger))
1110 {
1111 return true;
1112 }
1113
1114 if ((textureInternalFormatInfo.mStorageType == NormalizedFixedPoint || textureInternalFormatInfo.mStorageType == FloatingPoint) &&
1115 (framebufferInternalFormatInfo.mStorageType == NormalizedFixedPoint || framebufferInternalFormatInfo.mStorageType == FloatingPoint))
1116 {
1117 return true;
1118 }
1119 }
1120
1121 return false;
1122 }
1123 else
1124 {
1125 UNREACHABLE();
1126 return false;
1127 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001128 }
1129 else
1130 {
1131 UNREACHABLE();
1132 return false;
1133 }
1134}
1135
1136bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion)
1137{
1138 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001139 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001140 {
1141 return internalFormatInfo.mPixelBits > 0;
1142 }
1143 else
1144 {
1145 UNREACHABLE();
1146 return false;
1147 }
1148}
1149
1150GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
1151{
Geoff Langfe28ca02013-06-04 10:10:48 -04001152 const FormatMap &formats = GetFormatMap(clientVersion);
1153 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1154 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001155}
1156
1157GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion)
1158{
1159 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001160 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001161 {
1162 return internalFormatInfo.mPixelBits / 8;
1163 }
1164 else
1165 {
1166 UNREACHABLE();
1167 return 0;
1168 }
1169}
1170
1171GLuint GetAlphaBits(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.mAlphaBits;
1177 }
1178 else
1179 {
1180 UNREACHABLE();
1181 return 0;
1182 }
1183}
1184
1185GLuint GetRedBits(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.mRedBits;
1191 }
1192 else
1193 {
1194 UNREACHABLE();
1195 return 0;
1196 }
1197}
1198
1199GLuint GetGreenBits(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.mGreenBits;
1205 }
1206 else
1207 {
1208 UNREACHABLE();
1209 return 0;
1210 }
1211}
1212
1213GLuint GetBlueBits(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 {
Geoff Lang24159222013-06-05 14:56:32 -04001218 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001219 }
1220 else
1221 {
1222 UNREACHABLE();
1223 return 0;
1224 }
1225}
1226
1227GLuint GetLuminanceBits(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 {
1232 return internalFormatInfo.mLuminanceBits;
1233 }
1234 else
1235 {
1236 UNREACHABLE();
1237 return 0;
1238 }
1239}
1240
1241GLuint GetDepthBits(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.mDepthBits;
1247 }
1248 else
1249 {
1250 UNREACHABLE();
1251 return 0;
1252 }
1253}
1254
1255GLuint GetStencilBits(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.mStencilBits;
1261 }
1262 else
1263 {
1264 UNREACHABLE();
1265 return 0;
1266 }
1267}
1268
1269GLenum GetFormat(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.mFormat;
1275 }
1276 else
1277 {
1278 UNREACHABLE();
1279 return GL_NONE;
1280 }
1281}
1282
1283GLenum GetType(GLint internalFormat, GLuint clientVersion)
1284{
1285 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001286 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001287 {
1288 return internalFormatInfo.mType;
1289 }
1290 else
1291 {
1292 UNREACHABLE();
1293 return GL_NONE;
1294 }
1295}
1296
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001297bool IsNormalizedFixedPointFormat(GLint internalFormat, GLuint clientVersion)
1298{
1299 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001300 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001301 {
1302 return internalFormatInfo.mStorageType == NormalizedFixedPoint;
1303 }
1304 else
1305 {
1306 UNREACHABLE();
1307 return false;
1308 }
1309}
1310
1311bool IsIntegerFormat(GLint internalFormat, GLuint clientVersion)
1312{
1313 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001314 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001315 {
1316 return internalFormatInfo.mStorageType == UnsignedInteger ||
1317 internalFormatInfo.mStorageType == SignedInteger;
1318 }
1319 else
1320 {
1321 UNREACHABLE();
1322 return false;
1323 }
1324}
1325
1326bool IsSignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1327{
1328 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001329 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001330 {
1331 return internalFormatInfo.mStorageType == SignedInteger;
1332 }
1333 else
1334 {
1335 UNREACHABLE();
1336 return false;
1337 }
1338}
1339
1340bool IsUnsignedIntegerFormat(GLint internalFormat, GLuint clientVersion)
1341{
1342 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001343 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001344 {
1345 return internalFormatInfo.mStorageType == UnsignedInteger;
1346 }
1347 else
1348 {
1349 UNREACHABLE();
1350 return false;
1351 }
1352}
1353
1354bool IsFloatingPointFormat(GLint internalFormat, GLuint clientVersion)
1355{
1356 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001357 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001358 {
1359 return internalFormatInfo.mStorageType == FloatingPoint;
1360 }
1361 else
1362 {
1363 UNREACHABLE();
1364 return false;
1365 }
1366}
1367
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001368bool IsSRGBFormat(GLint internalFormat, GLuint clientVersion)
1369{
1370 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001371 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001372 {
1373 return internalFormatInfo.mIsSRGB;
1374 }
1375 else
1376 {
1377 UNREACHABLE();
1378 return false;
1379 }
1380}
1381
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001382bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1383{
1384 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001385 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001386 {
1387 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1388 }
1389 else
1390 {
1391 UNREACHABLE();
1392 return false;
1393 }
1394}
1395
1396bool IsColorRenderingSupported(GLint internalFormat, const Context *context)
1397{
1398 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001399 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001400 {
1401 return internalFormatInfo.mIsColorRenderable(context, NULL);
1402 }
1403 else
1404 {
1405 UNREACHABLE();
1406 return false;
1407 }
1408}
1409
1410bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer)
1411{
1412 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001413 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001414 {
1415 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1416 }
1417 else
1418 {
1419 UNREACHABLE();
1420 return false;
1421 }
1422}
1423
1424bool IsTextureFilteringSupported(GLint internalFormat, const Context *context)
1425{
1426 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001427 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001428 {
1429 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1430 }
1431 else
1432 {
1433 UNREACHABLE();
1434 return false;
1435 }
1436}
1437
1438bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1439{
1440 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001441 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001442 {
1443 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1444 }
1445 else
1446 {
1447 UNREACHABLE();
1448 return false;
1449 }
1450}
1451
1452bool IsDepthRenderingSupported(GLint internalFormat, const Context *context)
1453{
1454 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001455 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001456 {
1457 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1458 }
1459 else
1460 {
1461 UNREACHABLE();
1462 return false;
1463 }
1464}
1465
1466bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer)
1467{
1468 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001469 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001470 {
1471 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1472 }
1473 else
1474 {
1475 UNREACHABLE();
1476 return false;
1477 }
1478}
1479
1480bool IsStencilRenderingSupported(GLint internalFormat, const Context *context)
1481{
1482 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001483 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001484 {
1485 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1486 }
1487 else
1488 {
1489 UNREACHABLE();
1490 return false;
1491 }
1492}
1493
1494GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
1495{
1496 ASSERT(alignment > 0 && isPow2(alignment));
1497 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1498}
1499
1500GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
1501{
1502 return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1);
1503}
1504
1505GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
1506{
1507 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001508 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001509 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001510 if (internalFormatInfo.mStorageType == Compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001511 {
1512 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1513 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1514
1515 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1516 }
1517 else
1518 {
1519 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001520 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001521 {
1522 if (typeInfo.mSpecialInterpretation)
1523 {
1524 return typeInfo.mTypeBytes * width * height;
1525 }
1526 else
1527 {
1528 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1529 }
1530 }
1531 else
1532 {
1533 UNREACHABLE();
1534 return 0;
1535 }
1536 }
1537 }
1538 else
1539 {
1540 UNREACHABLE();
1541 return 0;
1542 }
1543}
1544
1545bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion)
1546{
1547 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001548 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001549 {
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001550 return internalFormatInfo.mStorageType == Compressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001551 }
1552 else
1553 {
1554 UNREACHABLE();
1555 return false;
1556 }
1557}
1558
1559GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion)
1560{
1561 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001562 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001563 {
1564 return internalFormatInfo.mCompressedBlockWidth;
1565 }
1566 else
1567 {
1568 UNREACHABLE();
1569 return 0;
1570 }
1571}
1572
1573GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion)
1574{
1575 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001576 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001577 {
1578 return internalFormatInfo.mCompressedBlockHeight;
1579 }
1580 else
1581 {
1582 UNREACHABLE();
1583 return 0;
1584 }
1585}
1586
Geoff Langfe28ca02013-06-04 10:10:48 -04001587ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1588{
1589 static const FormatMap &formats = GetFormatMap(clientVersion);
1590 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1591 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1592}
1593
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001594}