blob: bc303feefece9563c68f206d236066e57fb9aedb [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// formatutils.cpp: Queries for GL image formats.
9
10#include "libGLESv2/formatutils.h"
11#include "libGLESv2/Context.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000012#include "common/mathutil.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000013#include "libGLESv2/renderer/Renderer.h"
Geoff Langfe28ca02013-06-04 10:10:48 -040014#include "libGLESv2/renderer/imageformats.h"
15#include "libGLESv2/renderer/copyimage.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000016
17namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
23
Geoff Langfe28ca02013-06-04 10:10:48 -040024struct FormatTypeInfo
25{
Geoff Lang005df412013-10-16 14:12:50 -040026 GLenum mInternalFormat;
Geoff Langfe28ca02013-06-04 10:10:48 -040027 ColorWriteFunction mColorWriteFunction;
28
Geoff Lang005df412013-10-16 14:12:50 -040029 FormatTypeInfo(GLenum internalFormat, ColorWriteFunction writeFunc)
Geoff Langfe28ca02013-06-04 10:10:48 -040030 : mInternalFormat(internalFormat), mColorWriteFunction(writeFunc)
31 { }
32};
33
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000034typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Langfe28ca02013-06-04 10:10:48 -040035typedef std::pair<FormatTypePair, FormatTypeInfo> FormatPair;
36typedef std::map<FormatTypePair, FormatTypeInfo> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000037
Jamie Madill89a0bf52013-09-18 14:36:24 -040038// A helper function to insert data into the format map with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -040039static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat, ColorWriteFunction writeFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000040{
Geoff Langfe28ca02013-06-04 10:10:48 -040041 map->insert(FormatPair(FormatTypePair(format, type), FormatTypeInfo(internalFormat, writeFunc)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000042}
43
Geoff Lang18591b72013-06-07 12:00:15 -040044FormatMap BuildES2FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045{
46 FormatMap map;
47
Geoff Langfe28ca02013-06-04 10:10:48 -040048 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000049
Geoff Langfe28ca02013-06-04 10:10:48 -040050 // | Format | Type | Internal format | Color write function |
51 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
52 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
53 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000054
Geoff Langfe28ca02013-06-04 10:10:48 -040055 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
56 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
57 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000058
Geoff Langfe28ca02013-06-04 10:10:48 -040059 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
60 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
61 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000062
Geoff Lang632192d2013-10-04 13:40:46 -040063 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8_EXT, WriteColor<R8, GLfloat> );
64 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F_EXT, WriteColor<R32F, GLfloat> );
65 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F_EXT, WriteColor<R16F, GLfloat> );
66
67 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8_EXT, WriteColor<R8G8, GLfloat> );
68 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F_EXT, WriteColor<R32G32F, GLfloat> );
69 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F_EXT, WriteColor<R16G16F, GLfloat> );
70
Geoff Langfe28ca02013-06-04 10:10:48 -040071 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES, WriteColor<R8G8B8, GLfloat> );
72 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
73 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT, WriteColor<R32G32B32F, GLfloat> );
74 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075
Geoff Langfe28ca02013-06-04 10:10:48 -040076 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES, WriteColor<R8G8B8A8, GLfloat> );
77 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
78 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
79 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT, WriteColor<R32G32B32A32F, GLfloat>);
80 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081
Geoff Langfe28ca02013-06-04 10:10:48 -040082 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
83 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
84 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 +000085
Geoff Langfe28ca02013-06-04 10:10:48 -040086 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL );
87 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL );
88 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL );
89 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 +000090
Geoff Langfe28ca02013-06-04 10:10:48 -040091 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
92 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES, NULL );
93
94 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 +000095
96 return map;
97}
98
Geoff Lang18591b72013-06-07 12:00:15 -040099FormatMap BuildES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000100{
101 FormatMap map;
102
Geoff Langfe28ca02013-06-04 10:10:48 -0400103 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000104
Geoff Langfe28ca02013-06-04 10:10:48 -0400105 // | Format | Type | Internal format | Color write function |
106 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8, WriteColor<R8G8B8A8, GLfloat> );
107 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM, WriteColor<R8G8B8A8S, GLfloat> );
108 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
109 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
110 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, WriteColor<R10G10B10A2, GLfloat> );
111 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F, WriteColor<R32G32B32A32F, GLfloat>);
112 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000113
Geoff Langfe28ca02013-06-04 10:10:48 -0400114 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, WriteColor<R8G8B8A8, GLuint> );
115 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, WriteColor<R8G8B8A8S, GLint> );
116 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, WriteColor<R16G16B16A16, GLuint> );
117 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, WriteColor<R16G16B16A16S, GLint> );
118 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, WriteColor<R32G32B32A32, GLuint> );
119 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, WriteColor<R32G32B32A32S, GLint> );
Jamie Madill18a44702013-09-09 16:24:04 -0400120 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI, WriteColor<R10G10B10A2, GLuint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000121
Geoff Langfe28ca02013-06-04 10:10:48 -0400122 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> );
123 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> );
124 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
125 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> );
126 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> );
127 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> );
128 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000129
Geoff Langfe28ca02013-06-04 10:10:48 -0400130 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> );
131 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> );
132 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> );
133 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> );
134 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> );
135 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000136
Geoff Langfe28ca02013-06-04 10:10:48 -0400137 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> );
138 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> );
139 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> );
140 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> );
141
142 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> );
143 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> );
144 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> );
145 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> );
146 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> );
147 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> );
148
149 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> );
150 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> );
151 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> );
152 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> );
153
154 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> );
155 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> );
156 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> );
157 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> );
158 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> );
159 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> );
160
161 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
162 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
163 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
164 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
165 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
166 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
167 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
168 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
169 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
170
171 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
172 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
173 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
174
175 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
176 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL );
177 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL );
178
179 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL );
180 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 +0000181
182 return map;
183}
184
Geoff Langfe28ca02013-06-04 10:10:48 -0400185static const FormatMap &GetFormatMap(GLuint clientVersion)
186{
187 if (clientVersion == 2)
188 {
189 static const FormatMap formats = BuildES2FormatMap();
190 return formats;
191 }
192 else if (clientVersion == 3)
193 {
194 static const FormatMap formats = BuildES3FormatMap();
195 return formats;
196 }
197 else
198 {
199 UNREACHABLE();
200 static FormatMap emptyMap;
201 return emptyMap;
202 }
203}
204
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000205struct FormatInfo
206{
Geoff Lang005df412013-10-16 14:12:50 -0400207 GLenum mInternalformat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000208 GLenum mFormat;
209 GLenum mType;
210
Geoff Lang005df412013-10-16 14:12:50 -0400211 FormatInfo(GLenum internalformat, GLenum format, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000212 : mInternalformat(internalformat), mFormat(format), mType(type) { }
213
214 bool operator<(const FormatInfo& other) const
215 {
216 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
217 }
218};
219
220// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
221typedef std::set<FormatInfo> ES3FormatSet;
222
Geoff Lang18591b72013-06-07 12:00:15 -0400223ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000224{
225 ES3FormatSet set;
226
227 // Format combinations from ES 3.0.1 spec, table 3.2
228
229 // | Internal format | Format | Type |
230 // | | | |
231 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
232 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
233 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
234 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
235 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
236 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
237 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
238 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000239 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000240 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
241 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
242 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
243 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
244 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
245 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
246 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
247 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
248 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
249 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
250 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
251 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
252 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
253 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
254 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
255 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
256 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
257 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
258 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
259 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
260 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
261 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
262 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
263 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
264 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
265 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
266 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
267 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
268 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
269 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
270 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
271 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
272 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
273 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
274 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
275 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
276 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
277 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
278 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
279 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
280 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
281 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
282 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
283 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
284 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
285 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
286 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
287 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
288 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
289 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
290 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
291 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
292
293 // Unsized formats
294 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
295 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
296 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
297 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
298 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
299 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
300 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
301 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
302
303 // Depth stencil formats
304 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
305 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
306 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
307 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
308 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
309 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
310
311 // From GL_OES_texture_float
312 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
313 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
314 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
315
316 // From GL_OES_texture_half_float
317 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
318 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
319 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
320
321 // From GL_EXT_texture_storage
322 // | Internal format | Format | Type |
323 // | | | |
324 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
325 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
326 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
327 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
328 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
329 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
330 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
331 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
332 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
333
334 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
335 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
336 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
337 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
338 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
339
340 // From GL_ANGLE_depth_texture
341 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
342
343 // Compressed formats
344 // From ES 3.0.1 spec, table 3.16
345 // | Internal format | Format | Type |
346 // | | | |
347 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
348 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
349 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
350 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
351 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
352 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
353 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
354 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
355 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
356 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
357 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
358
359
360 // From GL_EXT_texture_compression_dxt1
361 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
362 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
363
364 // From GL_ANGLE_texture_compression_dxt3
365 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
366
367 // From GL_ANGLE_texture_compression_dxt5
368 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
369
370 return set;
371}
372
Geoff Lang18591b72013-06-07 12:00:15 -0400373static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000374{
Geoff Lang18591b72013-06-07 12:00:15 -0400375 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000376 return es3FormatSet;
377}
378
379// Map of sizes of input types
380struct TypeInfo
381{
382 GLuint mTypeBytes;
383 bool mSpecialInterpretation;
384
385 TypeInfo()
386 : mTypeBytes(0), mSpecialInterpretation(false) { }
387
388 TypeInfo(GLuint typeBytes, bool specialInterpretation)
389 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
390
391 bool operator<(const TypeInfo& other) const
392 {
393 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
394 }
395};
396
397typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
398typedef std::map<GLenum, TypeInfo> TypeInfoMap;
399
Geoff Lang18591b72013-06-07 12:00:15 -0400400static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000401{
402 TypeInfoMap map;
403
404 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
405 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
406 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
407 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
408 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
409 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
410 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
Jamie Madilla940ae42013-07-08 17:48:34 -0400411 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000412 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
413 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
414 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
415 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
416 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
417 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
418 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
419 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
420 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
421 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000422 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400423 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000424
425 return map;
426}
427
Geoff Lang18591b72013-06-07 12:00:15 -0400428static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000429{
Geoff Lang18591b72013-06-07 12:00:15 -0400430 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000431 TypeInfoMap::const_iterator iter = infoMap.find(type);
432 if (iter != infoMap.end())
433 {
434 if (outTypeInfo)
435 {
436 *outTypeInfo = iter->second;
437 }
438 return true;
439 }
440 else
441 {
442 return false;
443 }
444}
445
446// Information about internal formats
447typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
448typedef bool (*ContextSupportCheckFunction)(const Context *context);
449
450typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
451typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
452
453template <ContextSupportCheckMemberFunction func>
454bool CheckSupport(const Context *context)
455{
456 return (context->*func)();
457}
458
459template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
460bool CheckSupport(const Context *context, const rx::Renderer *renderer)
461{
462 if (context)
463 {
464 return (context->*contextFunc)();
465 }
466 else if (renderer)
467 {
468 return (renderer->*rendererFunc)();
469 }
470 else
471 {
472 UNREACHABLE();
473 return false;
474 }
475}
476
477template <typename objectType>
478bool AlwaysSupported(const objectType*)
479{
480 return true;
481}
482
483template <typename objectTypeA, typename objectTypeB>
484bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
485{
486 return true;
487}
488
489template <typename objectType>
490bool NeverSupported(const objectType*)
491{
492 return false;
493}
494
495template <typename objectTypeA, typename objectTypeB>
496bool NeverSupported(const objectTypeA *, const objectTypeB *)
497{
498 return false;
499}
500
501template <typename objectType>
502bool UnimplementedSupport(const objectType*)
503{
504 UNIMPLEMENTED();
505 return false;
506}
507
508template <typename objectTypeA, typename objectTypeB>
509bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
510{
511 UNIMPLEMENTED();
512 return false;
513}
514
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000515struct 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
Geoff Langb2f3d052013-08-13 12:49:27 -0400539 GLenum mComponentType;
540 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000541
Geoff Langb2f3d052013-08-13 12:49:27 -0400542 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000543
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000544 ContextRendererSupportCheckFunction mIsColorRenderable;
545 ContextRendererSupportCheckFunction mIsDepthRenderable;
546 ContextRendererSupportCheckFunction mIsStencilRenderable;
547 ContextRendererSupportCheckFunction mIsTextureFilterable;
548
549 ContextSupportCheckFunction mSupportFunction;
550
551 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 +0000552 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langb2f3d052013-08-13 12:49:27 -0400553 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mIsColorRenderable(NeverSupported),
554 mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported), mIsTextureFilterable(NeverSupported),
555 mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000556 {
557 }
558
559 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
560 {
561 InternalFormatInfo formatInfo;
562 formatInfo.mFormat = format;
563 formatInfo.mSupportFunction = supportFunction;
Shannon Woods9e73b212013-07-08 10:32:19 -0400564
565 if (format == GL_RGB || format == GL_RGBA)
566 formatInfo.mIsColorRenderable = AlwaysSupported;
567
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000568 return formatInfo;
569 }
570
571 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
Geoff Langb2f3d052013-08-13 12:49:27 -0400572 GLenum format, GLenum type, GLenum componentType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000573 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000574 ContextRendererSupportCheckFunction textureFilterable,
575 ContextSupportCheckFunction supportFunction)
576 {
577 InternalFormatInfo formatInfo;
578 formatInfo.mRedBits = red;
579 formatInfo.mGreenBits = green;
580 formatInfo.mBlueBits = blue;
581 formatInfo.mAlphaBits = alpha;
582 formatInfo.mSharedBits = shared;
583 formatInfo.mPixelBits = red + green + blue + alpha + shared;
584 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
585 formatInfo.mFormat = format;
586 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400587 formatInfo.mComponentType = componentType;
588 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000589 formatInfo.mIsColorRenderable = colorRenderable;
590 formatInfo.mIsTextureFilterable = textureFilterable;
591 formatInfo.mSupportFunction = supportFunction;
592 return formatInfo;
593 }
594
Geoff Langb2f3d052013-08-13 12:49:27 -0400595 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596 ContextSupportCheckFunction supportFunction)
597 {
598 InternalFormatInfo formatInfo;
599 formatInfo.mLuminanceBits = luminance;
600 formatInfo.mAlphaBits = alpha;
601 formatInfo.mPixelBits = luminance + alpha;
602 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
603 formatInfo.mFormat = format;
604 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400605 formatInfo.mComponentType = componentType;
606 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000607 formatInfo.mIsTextureFilterable = AlwaysSupported;
608 formatInfo.mSupportFunction = supportFunction;
609 return formatInfo;
610 }
611
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400612 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
613 GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614 ContextRendererSupportCheckFunction depthRenderable,
615 ContextRendererSupportCheckFunction stencilRenderable,
616 ContextSupportCheckFunction supportFunction)
617 {
618 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400619 formatInfo.mDepthBits = depthBits;
620 formatInfo.mStencilBits = stencilBits;
621 formatInfo.mPixelBits = depthBits + stencilBits + unusedBits;
622 formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000623 formatInfo.mFormat = format;
624 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400625 formatInfo.mComponentType = componentType;
626 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000627 formatInfo.mIsDepthRenderable = depthRenderable;
628 formatInfo.mIsStencilRenderable = stencilRenderable;
Nicolas Capens08be89d2013-07-16 16:17:31 -0400629 formatInfo.mIsTextureFilterable = AlwaysSupported;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000630 formatInfo.mSupportFunction = supportFunction;
631 return formatInfo;
632 }
633
Geoff Langb2f3d052013-08-13 12:49:27 -0400634 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
635 GLuint componentCount, GLenum format, GLenum type, bool srgb,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636 ContextSupportCheckFunction supportFunction)
637 {
638 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000639 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
640 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
641 formatInfo.mPixelBits = compressedBlockSize;
642 formatInfo.mComponentCount = componentCount;
643 formatInfo.mFormat = format;
644 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400645 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
646 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
647 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648 formatInfo.mIsTextureFilterable = AlwaysSupported;
649 formatInfo.mSupportFunction = supportFunction;
650 return formatInfo;
651 }
652};
653
Geoff Lang005df412013-10-16 14:12:50 -0400654typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
655typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656
Geoff Lang18591b72013-06-07 12:00:15 -0400657static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000658{
659 InternalFormatInfoMap map;
660
661 // From ES 3.0.1 spec, table 3.12
662 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
663
Geoff Langb2f3d052013-08-13 12:49:27 -0400664 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
665 // | | | | | | | | | | | | renderable | filterable | |
666 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
667 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
668 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
669 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
670 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
671 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
Jamie Madill1d855fe2013-09-09 16:24:05 -0400672 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400673 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
674 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
675 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
676 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
677 map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
Jamie Madill18a44702013-09-09 16:24:04 -0400678 map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400679 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
680 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
Geoff Lang1ec57f82013-10-16 11:43:23 -0400681 map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400682 map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
683 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
684 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
685 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
686 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
687 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
688 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
689 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
690 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
691 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
692 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
693 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
694 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
696 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
697 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
698 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
699 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
700 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
701 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
702 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
703 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
704 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
705 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
706 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707
Geoff Langb2f3d052013-08-13 12:49:27 -0400708 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
709 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
710 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000711
712 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langb2f3d052013-08-13 12:49:27 -0400713 // | Internal format | | D |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
714 // | | | | | | | type | | | | |
715 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
716 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
717 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
718 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported )));
719 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
720 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
721 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
722 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000723
724 // Depth stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400725 // | Internal format | | D |S | X | Format | Type | Component type | Depth | Stencil | Supported |
726 // | | | | | | | | | renderable | renderable | |
727 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
728 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
729 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported)));
730 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
731 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
732 map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
733 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000734
735 // Luminance alpha formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400736 // | Internal format | | L | A | Format | Type | Component type | Supported |
737 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
738 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
739 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
740 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
741 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000746
747 // Unsized formats
748 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000749 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
750 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
751 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400752 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
753 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000754 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
755 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400756 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
757 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
758 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
759 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000760 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
761
762 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400763 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
764 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
765 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
766 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
767 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
768 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
769 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
770 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
771 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
772 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
773 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000774
775 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400776 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
777 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, AlwaysSupported)));
778 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000779
780 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400781 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000782
783 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400784 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000785
786 return map;
787}
788
Geoff Lang18591b72013-06-07 12:00:15 -0400789static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000790{
791 InternalFormatInfoMap map;
792
793 // From ES 2.0.25 table 4.5
794 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
795
Geoff Langb2f3d052013-08-13 12:49:27 -0400796 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
797 // | | | | | | | | | | | | renderable | filterable | |
798 map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
799 map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
800 map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000801
802 // Extension formats
Geoff Lang632192d2013-10-04 13:40:46 -0400803 map.insert(InternalFormatInfoPair(GL_R8_EXT, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures>)));
804 map.insert(InternalFormatInfoPair(GL_RG8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures>)));
Geoff Langb2f3d052013-08-13 12:49:27 -0400805 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
806 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
807 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported)));
808 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
809 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000810
811 // Floating point formats have to query the renderer for support
Geoff Langb2f3d052013-08-13 12:49:27 -0400812 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
813 // | | | | | | | | | | type | | | | |
Geoff Lang632192d2013-10-04 13:40:46 -0400814 map.insert(InternalFormatInfoPair(GL_R16F_EXT, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures> )));
815 map.insert(InternalFormatInfoPair(GL_R32F_EXT, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures> )));
816 map.insert(InternalFormatInfoPair(GL_RG16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures> )));
817 map.insert(InternalFormatInfoPair(GL_RG32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures, &rx::Renderer::getRGTextureSupport>, CheckSupport<&Context::supportsRGTextures> )));
Geoff Langb2f3d052013-08-13 12:49:27 -0400818 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
819 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
820 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>)));
821 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000822
823 // Depth and stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400824 // | Internal format | | D |S |X | Format | Type | Internal format | Depth | Stencil | Supported |
825 // | | | | | | | | type | renderable | renderable | |
826 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>)));
827 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>)));
828 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
829 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, NeverSupported, AlwaysSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000830
831 // Unsized formats
832 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000833 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
834 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
835 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Lang632192d2013-10-04 13:40:46 -0400836 map.insert(InternalFormatInfoPair(GL_RED_EXT, InternalFormatInfo::UnsizedFormat(GL_RED_EXT, CheckSupport<&Context::supportsRGTextures>)));
837 map.insert(InternalFormatInfoPair(GL_RG_EXT, InternalFormatInfo::UnsizedFormat(GL_RG_EXT, CheckSupport<&Context::supportsRGTextures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000838 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
839 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
840 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
841 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
842 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
843
844 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langb2f3d052013-08-13 12:49:27 -0400845 // | Internal format | | L | A | Format | Type | Component type | Supported |
846 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
847 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
848 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
849 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
850 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
851 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
852 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
853 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
854 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000855
856 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400857 // | Internal format | |W |H | BS |CC|Format | Type | SRGB | Supported |
858 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Context::supportsDXT1Textures>)));
859 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, CheckSupport<&Context::supportsDXT1Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000860
861 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400862 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Context::supportsDXT3Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000863
864 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400865 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, CheckSupport<&Context::supportsDXT5Textures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000866
867 return map;
868}
869
Geoff Lang005df412013-10-16 14:12:50 -0400870static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000871{
872 const InternalFormatInfoMap* map = NULL;
873
874 if (clientVersion == 2)
875 {
Geoff Lang18591b72013-06-07 12:00:15 -0400876 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000877 map = &formatMap;
878 }
879 else if (clientVersion == 3)
880 {
Geoff Lang18591b72013-06-07 12:00:15 -0400881 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000882 map = &formatMap;
883 }
884 else
885 {
886 UNREACHABLE();
887 }
888
889 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
890 if (iter != map->end())
891 {
892 if (outFormatInfo)
893 {
894 *outFormatInfo = iter->second;
895 }
896 return true;
897 }
898 else
899 {
900 return false;
901 }
902}
903
904typedef std::set<GLenum> FormatSet;
905
Geoff Lang18591b72013-06-07 12:00:15 -0400906static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000907{
Geoff Langfe28ca02013-06-04 10:10:48 -0400908 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000909
910 FormatSet set;
911
912 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
913 {
914 const FormatTypePair& formatPair = i->first;
915 set.insert(formatPair.first);
916 }
917
918 return set;
919}
920
Geoff Lang18591b72013-06-07 12:00:15 -0400921static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000922{
Geoff Lang18591b72013-06-07 12:00:15 -0400923 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000924
925 FormatSet set;
926
927 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
928 {
929 const FormatInfo& formatInfo = *i;
930 set.insert(formatInfo.mFormat);
931 }
932
933 return set;
934}
935
936typedef std::set<GLenum> TypeSet;
937
Geoff Lang18591b72013-06-07 12:00:15 -0400938static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000939{
Geoff Langfe28ca02013-06-04 10:10:48 -0400940 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000941
942 TypeSet set;
943
944 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
945 {
946 const FormatTypePair& formatPair = i->first;
947 set.insert(formatPair.second);
948 }
949
950 return set;
951}
952
Geoff Lang18591b72013-06-07 12:00:15 -0400953static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000954{
Geoff Lang18591b72013-06-07 12:00:15 -0400955 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000956
957 TypeSet set;
958
959 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
960 {
961 const FormatInfo& formatInfo = *i;
962 set.insert(formatInfo.mType);
963 }
964
965 return set;
966}
967
968struct CopyConversion
969{
970 GLenum mTextureFormat;
971 GLenum mFramebufferFormat;
972
973 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
974 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
975
976 bool operator<(const CopyConversion& other) const
977 {
978 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
979 }
980};
981
982typedef std::set<CopyConversion> CopyConversionSet;
983
Geoff Lang18591b72013-06-07 12:00:15 -0400984static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000985{
986 CopyConversionSet set;
987
988 // From ES 3.0.1 spec, table 3.15
989 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
990 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
991 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
992 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
993 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
994 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
995 set.insert(CopyConversion(GL_RED, GL_RED));
996 set.insert(CopyConversion(GL_RED, GL_RG));
997 set.insert(CopyConversion(GL_RED, GL_RGB));
998 set.insert(CopyConversion(GL_RED, GL_RGBA));
999 set.insert(CopyConversion(GL_RG, GL_RG));
1000 set.insert(CopyConversion(GL_RG, GL_RGB));
1001 set.insert(CopyConversion(GL_RG, GL_RGBA));
1002 set.insert(CopyConversion(GL_RGB, GL_RGB));
1003 set.insert(CopyConversion(GL_RGB, GL_RGBA));
1004 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
1005
Jamie Madillb70e5f72013-07-10 16:57:52 -04001006 // Necessary for ANGLE back-buffers
1007 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
1008 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
1009 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
1010 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
1011 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
1012 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
1013 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
1014
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001015 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
1016 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1017 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1018 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1019 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1020 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1021 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1022 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1023 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1024 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1025
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001026 return set;
1027}
1028
Geoff Lang005df412013-10-16 14:12:50 -04001029bool IsValidInternalFormat(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001030{
1031 if (!context)
1032 {
1033 return false;
1034 }
1035
1036 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001037 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001038 {
1039 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1040 return internalFormatInfo.mSupportFunction(context);
1041 }
1042 else
1043 {
1044 return false;
1045 }
1046}
1047
1048bool IsValidFormat(GLenum format, GLuint clientVersion)
1049{
1050 if (clientVersion == 2)
1051 {
Geoff Lang18591b72013-06-07 12:00:15 -04001052 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001053 return formatSet.find(format) != formatSet.end();
1054 }
1055 else if (clientVersion == 3)
1056 {
Geoff Lang18591b72013-06-07 12:00:15 -04001057 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001058 return formatSet.find(format) != formatSet.end();
1059 }
1060 else
1061 {
1062 UNREACHABLE();
1063 return false;
1064 }
1065}
1066
1067bool IsValidType(GLenum type, GLuint clientVersion)
1068{
1069 if (clientVersion == 2)
1070 {
Geoff Lang18591b72013-06-07 12:00:15 -04001071 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001072 return typeSet.find(type) != typeSet.end();
1073 }
1074 else if (clientVersion == 3)
1075 {
Geoff Lang18591b72013-06-07 12:00:15 -04001076 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001077 return typeSet.find(type) != typeSet.end();
1078 }
1079 else
1080 {
1081 UNREACHABLE();
1082 return false;
1083 }
1084}
1085
Geoff Lang005df412013-10-16 14:12:50 -04001086bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001087{
1088 if (clientVersion == 2)
1089 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001090 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001091 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1092
Geoff Langfe28ca02013-06-04 10:10:48 -04001093 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001094 }
1095 else if (clientVersion == 3)
1096 {
Geoff Lang18591b72013-06-07 12:00:15 -04001097 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001098 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1099 }
1100 else
1101 {
1102 UNREACHABLE();
1103 return false;
1104 }
1105}
1106
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001107bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001108{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001109 InternalFormatInfo textureInternalFormatInfo;
1110 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001111 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1112 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001113 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001114 if (clientVersion == 2)
1115 {
1116 UNIMPLEMENTED();
1117 return false;
1118 }
1119 else if (clientVersion == 3)
1120 {
Geoff Lang18591b72013-06-07 12:00:15 -04001121 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001122 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1123 framebufferInternalFormatInfo.mFormat);
1124 if (conversionSet.find(conversion) != conversionSet.end())
1125 {
1126 // 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 +00001127 // must both be signed or unsigned or fixed/floating point and both source and destinations
1128 // must be either both SRGB or both not SRGB
1129
Geoff Langb2f3d052013-08-13 12:49:27 -04001130 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001131 {
1132 return false;
1133 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001134
Geoff Langb2f3d052013-08-13 12:49:27 -04001135 if ((textureInternalFormatInfo.mComponentType == GL_INT && framebufferInternalFormatInfo.mComponentType == GL_INT ) ||
1136 (textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT && framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001137 {
1138 return true;
1139 }
1140
Geoff Langb2f3d052013-08-13 12:49:27 -04001141 if ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1142 textureInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1143 textureInternalFormatInfo.mComponentType == GL_FLOAT ) &&
1144 (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_NORMALIZED ||
1145 framebufferInternalFormatInfo.mComponentType == GL_SIGNED_NORMALIZED ||
1146 framebufferInternalFormatInfo.mComponentType == GL_FLOAT ))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001147 {
1148 return true;
1149 }
1150 }
1151
1152 return false;
1153 }
1154 else
1155 {
1156 UNREACHABLE();
1157 return false;
1158 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001159 }
1160 else
1161 {
1162 UNREACHABLE();
1163 return false;
1164 }
1165}
1166
Geoff Lang005df412013-10-16 14:12:50 -04001167bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001168{
1169 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001170 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001171 {
1172 return internalFormatInfo.mPixelBits > 0;
1173 }
1174 else
1175 {
1176 UNREACHABLE();
1177 return false;
1178 }
1179}
1180
Geoff Lang005df412013-10-16 14:12:50 -04001181GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001182{
Geoff Langfe28ca02013-06-04 10:10:48 -04001183 const FormatMap &formats = GetFormatMap(clientVersion);
1184 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1185 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001186}
1187
Geoff Lang005df412013-10-16 14:12:50 -04001188GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001189{
1190 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001191 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001192 {
1193 return internalFormatInfo.mPixelBits / 8;
1194 }
1195 else
1196 {
1197 UNREACHABLE();
1198 return 0;
1199 }
1200}
1201
Geoff Lang005df412013-10-16 14:12:50 -04001202GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001203{
1204 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001205 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001206 {
1207 return internalFormatInfo.mAlphaBits;
1208 }
1209 else
1210 {
1211 UNREACHABLE();
1212 return 0;
1213 }
1214}
1215
Geoff Lang005df412013-10-16 14:12:50 -04001216GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001217{
1218 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001219 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001220 {
1221 return internalFormatInfo.mRedBits;
1222 }
1223 else
1224 {
1225 UNREACHABLE();
1226 return 0;
1227 }
1228}
1229
Geoff Lang005df412013-10-16 14:12:50 -04001230GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001231{
1232 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001233 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001234 {
1235 return internalFormatInfo.mGreenBits;
1236 }
1237 else
1238 {
1239 UNREACHABLE();
1240 return 0;
1241 }
1242}
1243
Geoff Lang005df412013-10-16 14:12:50 -04001244GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001245{
1246 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001247 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001248 {
Geoff Lang24159222013-06-05 14:56:32 -04001249 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001250 }
1251 else
1252 {
1253 UNREACHABLE();
1254 return 0;
1255 }
1256}
1257
Geoff Lang005df412013-10-16 14:12:50 -04001258GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001259{
1260 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001261 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001262 {
1263 return internalFormatInfo.mLuminanceBits;
1264 }
1265 else
1266 {
1267 UNREACHABLE();
1268 return 0;
1269 }
1270}
1271
Geoff Lang005df412013-10-16 14:12:50 -04001272GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001273{
1274 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001275 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001276 {
1277 return internalFormatInfo.mDepthBits;
1278 }
1279 else
1280 {
1281 UNREACHABLE();
1282 return 0;
1283 }
1284}
1285
Geoff Lang005df412013-10-16 14:12:50 -04001286GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001287{
1288 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001289 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001290 {
1291 return internalFormatInfo.mStencilBits;
1292 }
1293 else
1294 {
1295 UNREACHABLE();
1296 return 0;
1297 }
1298}
1299
Geoff Langf23eb282013-07-22 10:52:19 -04001300GLuint GetTypeBytes(GLenum type)
1301{
1302 TypeInfo typeInfo;
1303 if (GetTypeInfo(type, &typeInfo))
1304 {
1305 return typeInfo.mTypeBytes;
1306 }
1307 else
1308 {
1309 UNREACHABLE();
1310 return 0;
1311 }
1312}
1313
1314bool IsSpecialInterpretationType(GLenum type)
1315{
1316 TypeInfo typeInfo;
1317 if (GetTypeInfo(type, &typeInfo))
1318 {
1319 return typeInfo.mSpecialInterpretation;
1320 }
1321 else
1322 {
1323 UNREACHABLE();
1324 return false;
1325 }
1326}
1327
Geoff Lang005df412013-10-16 14:12:50 -04001328GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001329{
1330 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001331 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001332 {
1333 return internalFormatInfo.mFormat;
1334 }
1335 else
1336 {
1337 UNREACHABLE();
1338 return GL_NONE;
1339 }
1340}
1341
Geoff Lang005df412013-10-16 14:12:50 -04001342GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001343{
1344 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001345 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001346 {
1347 return internalFormatInfo.mType;
1348 }
1349 else
1350 {
1351 UNREACHABLE();
1352 return GL_NONE;
1353 }
1354}
1355
Nicolas Capens0027fa92014-02-20 14:26:42 -05001356GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001357{
1358 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001359 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001360 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001361 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001362 }
1363 else
1364 {
1365 UNREACHABLE();
Nicolas Capens0027fa92014-02-20 14:26:42 -05001366 return GL_NONE;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001367 }
1368}
1369
Geoff Lang005df412013-10-16 14:12:50 -04001370GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001371{
1372 InternalFormatInfo internalFormatInfo;
1373 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1374 {
1375 return internalFormatInfo.mComponentCount;
1376 }
1377 else
1378 {
1379 UNREACHABLE();
1380 return false;
1381 }
1382}
1383
Geoff Lang005df412013-10-16 14:12:50 -04001384GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001385{
1386 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001387 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001388 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001389 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001390 }
1391 else
1392 {
1393 UNREACHABLE();
1394 return false;
1395 }
1396}
1397
Geoff Lang005df412013-10-16 14:12:50 -04001398bool IsColorRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001399{
1400 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001401 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001402 {
1403 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1404 }
1405 else
1406 {
1407 UNREACHABLE();
1408 return false;
1409 }
1410}
1411
Geoff Lang005df412013-10-16 14:12:50 -04001412bool IsColorRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001413{
1414 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001415 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001416 {
1417 return internalFormatInfo.mIsColorRenderable(context, NULL);
1418 }
1419 else
1420 {
1421 UNREACHABLE();
1422 return false;
1423 }
1424}
1425
Geoff Lang005df412013-10-16 14:12:50 -04001426bool IsTextureFilteringSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001427{
1428 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001429 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001430 {
1431 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1432 }
1433 else
1434 {
1435 UNREACHABLE();
1436 return false;
1437 }
1438}
1439
Geoff Lang005df412013-10-16 14:12:50 -04001440bool IsTextureFilteringSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001441{
1442 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001443 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001444 {
1445 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1446 }
1447 else
1448 {
1449 UNREACHABLE();
1450 return false;
1451 }
1452}
1453
Geoff Lang005df412013-10-16 14:12:50 -04001454bool IsDepthRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001455{
1456 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001457 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001458 {
1459 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1460 }
1461 else
1462 {
1463 UNREACHABLE();
1464 return false;
1465 }
1466}
1467
Geoff Lang005df412013-10-16 14:12:50 -04001468bool IsDepthRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001469{
1470 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001471 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001472 {
1473 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1474 }
1475 else
1476 {
1477 UNREACHABLE();
1478 return false;
1479 }
1480}
1481
Geoff Lang005df412013-10-16 14:12:50 -04001482bool IsStencilRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001483{
1484 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001485 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001486 {
1487 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1488 }
1489 else
1490 {
1491 UNREACHABLE();
1492 return false;
1493 }
1494}
1495
Geoff Lang005df412013-10-16 14:12:50 -04001496bool IsStencilRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001497{
1498 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001499 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001500 {
1501 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1502 }
1503 else
1504 {
1505 UNREACHABLE();
1506 return false;
1507 }
1508}
1509
Geoff Lang005df412013-10-16 14:12:50 -04001510GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001511{
1512 ASSERT(alignment > 0 && isPow2(alignment));
1513 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1514}
1515
Geoff Lang005df412013-10-16 14:12:50 -04001516GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001517{
Jamie Madill666e2862013-09-10 12:04:29 -04001518 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001519}
1520
Geoff Lang005df412013-10-16 14:12:50 -04001521GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001522{
1523 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001524 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001525 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001526 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001527 {
1528 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1529 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1530
1531 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1532 }
1533 else
1534 {
1535 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001536 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001537 {
1538 if (typeInfo.mSpecialInterpretation)
1539 {
1540 return typeInfo.mTypeBytes * width * height;
1541 }
1542 else
1543 {
1544 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1545 }
1546 }
1547 else
1548 {
1549 UNREACHABLE();
1550 return 0;
1551 }
1552 }
1553 }
1554 else
1555 {
1556 UNREACHABLE();
1557 return 0;
1558 }
1559}
1560
Geoff Lang005df412013-10-16 14:12:50 -04001561bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001562{
1563 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001564 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001565 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001566 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001567 }
1568 else
1569 {
1570 UNREACHABLE();
1571 return false;
1572 }
1573}
1574
Geoff Lang005df412013-10-16 14:12:50 -04001575GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001576{
1577 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001578 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001579 {
1580 return internalFormatInfo.mCompressedBlockWidth;
1581 }
1582 else
1583 {
1584 UNREACHABLE();
1585 return 0;
1586 }
1587}
1588
Geoff Lang005df412013-10-16 14:12:50 -04001589GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001590{
1591 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001592 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001593 {
1594 return internalFormatInfo.mCompressedBlockHeight;
1595 }
1596 else
1597 {
1598 UNREACHABLE();
1599 return 0;
1600 }
1601}
1602
Geoff Langfe28ca02013-06-04 10:10:48 -04001603ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1604{
1605 static const FormatMap &formats = GetFormatMap(clientVersion);
1606 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1607 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1608}
1609
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001610}