blob: 3aac25efadd073030d37da7a6a3460942dd459d1 [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
Shannon Woods4d161ba2014-03-17 18:13:30 -040010#include "common/mathutil.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000011#include "libGLESv2/formatutils.h"
12#include "libGLESv2/Context.h"
Shannon Woods4d161ba2014-03-17 18:13:30 -040013#include "libGLESv2/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014#include "libGLESv2/renderer/Renderer.h"
Geoff Langfe28ca02013-06-04 10:10:48 -040015#include "libGLESv2/renderer/imageformats.h"
16#include "libGLESv2/renderer/copyimage.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017
18namespace gl
19{
20
21// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
22// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
23// format and type combinations.
24
Geoff Langfe28ca02013-06-04 10:10:48 -040025struct FormatTypeInfo
26{
Geoff Lang005df412013-10-16 14:12:50 -040027 GLenum mInternalFormat;
Geoff Langfe28ca02013-06-04 10:10:48 -040028 ColorWriteFunction mColorWriteFunction;
29
Geoff Lang005df412013-10-16 14:12:50 -040030 FormatTypeInfo(GLenum internalFormat, ColorWriteFunction writeFunc)
Geoff Langfe28ca02013-06-04 10:10:48 -040031 : mInternalFormat(internalFormat), mColorWriteFunction(writeFunc)
32 { }
33};
34
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000035typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Langfe28ca02013-06-04 10:10:48 -040036typedef std::pair<FormatTypePair, FormatTypeInfo> FormatPair;
37typedef std::map<FormatTypePair, FormatTypeInfo> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000038
Jamie Madill89a0bf52013-09-18 14:36:24 -040039// A helper function to insert data into the format map with fewer characters.
Geoff Lang005df412013-10-16 14:12:50 -040040static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat, ColorWriteFunction writeFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000041{
Geoff Langfe28ca02013-06-04 10:10:48 -040042 map->insert(FormatPair(FormatTypePair(format, type), FormatTypeInfo(internalFormat, writeFunc)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000043}
44
Geoff Lang18591b72013-06-07 12:00:15 -040045FormatMap BuildES2FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000046{
47 FormatMap map;
48
Geoff Langfe28ca02013-06-04 10:10:48 -040049 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000050
Geoff Langfe28ca02013-06-04 10:10:48 -040051 // | Format | Type | Internal format | Color write function |
52 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
53 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
54 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055
Geoff Langfe28ca02013-06-04 10:10:48 -040056 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
57 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
58 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000059
Geoff Langfe28ca02013-06-04 10:10:48 -040060 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
61 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
62 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000063
Geoff Lang632192d2013-10-04 13:40:46 -040064 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8_EXT, WriteColor<R8, GLfloat> );
65 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F_EXT, WriteColor<R32F, GLfloat> );
66 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F_EXT, WriteColor<R16F, GLfloat> );
67
68 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8_EXT, WriteColor<R8G8, GLfloat> );
69 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F_EXT, WriteColor<R32G32F, GLfloat> );
70 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F_EXT, WriteColor<R16G16F, GLfloat> );
71
Geoff Langfe28ca02013-06-04 10:10:48 -040072 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES, WriteColor<R8G8B8, GLfloat> );
73 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
74 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT, WriteColor<R32G32B32F, GLfloat> );
75 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076
Geoff Langfe28ca02013-06-04 10:10:48 -040077 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES, WriteColor<R8G8B8A8, GLfloat> );
78 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
79 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
80 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT, WriteColor<R32G32B32A32F, GLfloat>);
81 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082
Geoff Langfe28ca02013-06-04 10:10:48 -040083 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
84 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
85 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000086
Geoff Langfe28ca02013-06-04 10:10:48 -040087 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL );
88 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL );
89 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL );
90 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000091
Geoff Langfe28ca02013-06-04 10:10:48 -040092 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
93 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES, NULL );
94
95 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 +000096
97 return map;
98}
99
Geoff Lang18591b72013-06-07 12:00:15 -0400100FormatMap BuildES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000101{
102 FormatMap map;
103
Geoff Langfe28ca02013-06-04 10:10:48 -0400104 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000105
Geoff Langfe28ca02013-06-04 10:10:48 -0400106 // | Format | Type | Internal format | Color write function |
107 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8, WriteColor<R8G8B8A8, GLfloat> );
108 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM, WriteColor<R8G8B8A8S, GLfloat> );
109 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
110 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
111 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, WriteColor<R10G10B10A2, GLfloat> );
112 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F, WriteColor<R32G32B32A32F, GLfloat>);
113 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000114
Geoff Langfe28ca02013-06-04 10:10:48 -0400115 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, WriteColor<R8G8B8A8, GLuint> );
116 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, WriteColor<R8G8B8A8S, GLint> );
117 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, WriteColor<R16G16B16A16, GLuint> );
118 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, WriteColor<R16G16B16A16S, GLint> );
119 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, WriteColor<R32G32B32A32, GLuint> );
120 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, WriteColor<R32G32B32A32S, GLint> );
Jamie Madill18a44702013-09-09 16:24:04 -0400121 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 +0000122
Geoff Langfe28ca02013-06-04 10:10:48 -0400123 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> );
124 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> );
125 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
126 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> );
127 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> );
128 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> );
129 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000130
Geoff Langfe28ca02013-06-04 10:10:48 -0400131 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> );
132 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> );
133 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> );
134 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> );
135 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> );
136 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000137
Geoff Langfe28ca02013-06-04 10:10:48 -0400138 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> );
139 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> );
140 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> );
141 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> );
142
143 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> );
144 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> );
145 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> );
146 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> );
147 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> );
148 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> );
149
150 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> );
151 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> );
152 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> );
153 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> );
154
155 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> );
156 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> );
157 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> );
158 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> );
159 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> );
160 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> );
161
162 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
163 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
164 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
165 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
166 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
167 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
168 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
169 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
170 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
171
172 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
173 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
174 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
175
176 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
177 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL );
178 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL );
179
180 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL );
181 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 +0000182
183 return map;
184}
185
Geoff Langfe28ca02013-06-04 10:10:48 -0400186static const FormatMap &GetFormatMap(GLuint clientVersion)
187{
188 if (clientVersion == 2)
189 {
190 static const FormatMap formats = BuildES2FormatMap();
191 return formats;
192 }
193 else if (clientVersion == 3)
194 {
195 static const FormatMap formats = BuildES3FormatMap();
196 return formats;
197 }
198 else
199 {
200 UNREACHABLE();
201 static FormatMap emptyMap;
202 return emptyMap;
203 }
204}
205
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000206struct FormatInfo
207{
Geoff Lang005df412013-10-16 14:12:50 -0400208 GLenum mInternalformat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000209 GLenum mFormat;
210 GLenum mType;
211
Geoff Lang005df412013-10-16 14:12:50 -0400212 FormatInfo(GLenum internalformat, GLenum format, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000213 : mInternalformat(internalformat), mFormat(format), mType(type) { }
214
215 bool operator<(const FormatInfo& other) const
216 {
217 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
218 }
219};
220
221// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
222typedef std::set<FormatInfo> ES3FormatSet;
223
Geoff Lang18591b72013-06-07 12:00:15 -0400224ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000225{
226 ES3FormatSet set;
227
228 // Format combinations from ES 3.0.1 spec, table 3.2
229
230 // | Internal format | Format | Type |
231 // | | | |
232 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
233 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
234 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
235 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
236 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
237 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
238 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
239 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000240 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000241 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
242 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
243 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
244 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
245 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
246 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
247 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
248 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
249 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
250 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
251 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
252 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
253 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
254 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
255 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
256 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
257 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
258 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
259 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
260 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
261 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
262 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
263 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
264 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
265 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
266 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
267 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
268 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
269 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
270 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
271 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
272 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
273 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
274 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
275 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
276 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
277 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
278 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
279 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
280 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
281 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
282 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
283 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
284 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
285 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
286 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
287 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
288 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
289 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
290 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
291 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
292 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
293
294 // Unsized formats
295 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
296 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
297 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
298 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
299 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
300 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
301 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
302 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
303
304 // Depth stencil formats
305 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
306 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
307 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
308 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
309 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
310 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
311
312 // From GL_OES_texture_float
313 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
314 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
315 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
316
317 // From GL_OES_texture_half_float
318 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
319 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
320 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
321
Geoff Langcdacacd2014-04-24 12:01:56 -0400322 // From GL_EXT_texture_format_BGRA8888
323 set.insert(FormatInfo(GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
324
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000325 // From GL_EXT_texture_storage
326 // | Internal format | Format | Type |
327 // | | | |
328 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
329 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
330 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
331 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
332 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
333 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
334 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
335 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
336 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
337
Geoff Langcdacacd2014-04-24 12:01:56 -0400338 // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000339 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
340 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
341 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
342 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
343 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
344
345 // From GL_ANGLE_depth_texture
346 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
347
348 // Compressed formats
349 // From ES 3.0.1 spec, table 3.16
350 // | Internal format | Format | Type |
351 // | | | |
352 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
353 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
354 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
355 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
356 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
357 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
358 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
359 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
360 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
361 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
362 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
363
364
365 // From GL_EXT_texture_compression_dxt1
366 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
367 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
368
369 // From GL_ANGLE_texture_compression_dxt3
370 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
371
372 // From GL_ANGLE_texture_compression_dxt5
373 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
374
375 return set;
376}
377
Geoff Lang18591b72013-06-07 12:00:15 -0400378static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000379{
Geoff Lang18591b72013-06-07 12:00:15 -0400380 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000381 return es3FormatSet;
382}
383
384// Map of sizes of input types
385struct TypeInfo
386{
387 GLuint mTypeBytes;
388 bool mSpecialInterpretation;
389
390 TypeInfo()
391 : mTypeBytes(0), mSpecialInterpretation(false) { }
392
393 TypeInfo(GLuint typeBytes, bool specialInterpretation)
394 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
395
396 bool operator<(const TypeInfo& other) const
397 {
398 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
399 }
400};
401
402typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
403typedef std::map<GLenum, TypeInfo> TypeInfoMap;
404
Geoff Lang18591b72013-06-07 12:00:15 -0400405static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000406{
407 TypeInfoMap map;
408
409 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
410 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
411 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
412 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
413 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
414 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
415 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
Jamie Madilla940ae42013-07-08 17:48:34 -0400416 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000417 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
418 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
419 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
420 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
421 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
422 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
423 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
424 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
425 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
426 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000427 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400428 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000429
430 return map;
431}
432
Geoff Lang18591b72013-06-07 12:00:15 -0400433static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000434{
Geoff Lang18591b72013-06-07 12:00:15 -0400435 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000436 TypeInfoMap::const_iterator iter = infoMap.find(type);
437 if (iter != infoMap.end())
438 {
439 if (outTypeInfo)
440 {
441 *outTypeInfo = iter->second;
442 }
443 return true;
444 }
445 else
446 {
447 return false;
448 }
449}
450
451// Information about internal formats
452typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
453typedef bool (*ContextSupportCheckFunction)(const Context *context);
454
455typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
456typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
457
458template <ContextSupportCheckMemberFunction func>
459bool CheckSupport(const Context *context)
460{
461 return (context->*func)();
462}
463
464template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
465bool CheckSupport(const Context *context, const rx::Renderer *renderer)
466{
467 if (context)
468 {
469 return (context->*contextFunc)();
470 }
471 else if (renderer)
472 {
473 return (renderer->*rendererFunc)();
474 }
475 else
476 {
477 UNREACHABLE();
478 return false;
479 }
480}
481
482template <typename objectType>
483bool AlwaysSupported(const objectType*)
484{
485 return true;
486}
487
488template <typename objectTypeA, typename objectTypeB>
489bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
490{
491 return true;
492}
493
494template <typename objectType>
495bool NeverSupported(const objectType*)
496{
497 return false;
498}
499
500template <typename objectTypeA, typename objectTypeB>
501bool NeverSupported(const objectTypeA *, const objectTypeB *)
502{
503 return false;
504}
505
506template <typename objectType>
507bool UnimplementedSupport(const objectType*)
508{
509 UNIMPLEMENTED();
510 return false;
511}
512
513template <typename objectTypeA, typename objectTypeB>
514bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
515{
516 UNIMPLEMENTED();
517 return false;
518}
519
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000520struct InternalFormatInfo
521{
522 GLuint mRedBits;
523 GLuint mGreenBits;
524 GLuint mBlueBits;
525
526 GLuint mLuminanceBits;
527
528 GLuint mAlphaBits;
529 GLuint mSharedBits;
530
531 GLuint mDepthBits;
532 GLuint mStencilBits;
533
534 GLuint mPixelBits;
535
536 GLuint mComponentCount;
537
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000538 GLuint mCompressedBlockWidth;
539 GLuint mCompressedBlockHeight;
540
541 GLenum mFormat;
542 GLenum mType;
543
Geoff Langb2f3d052013-08-13 12:49:27 -0400544 GLenum mComponentType;
545 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000546
Geoff Langb2f3d052013-08-13 12:49:27 -0400547 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000548
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000549 ContextRendererSupportCheckFunction mIsColorRenderable;
550 ContextRendererSupportCheckFunction mIsDepthRenderable;
551 ContextRendererSupportCheckFunction mIsStencilRenderable;
552 ContextRendererSupportCheckFunction mIsTextureFilterable;
553
554 ContextSupportCheckFunction mSupportFunction;
555
556 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 +0000557 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langb2f3d052013-08-13 12:49:27 -0400558 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mIsColorRenderable(NeverSupported),
559 mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported), mIsTextureFilterable(NeverSupported),
560 mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000561 {
562 }
563
564 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
565 {
566 InternalFormatInfo formatInfo;
567 formatInfo.mFormat = format;
568 formatInfo.mSupportFunction = supportFunction;
Shannon Woods9e73b212013-07-08 10:32:19 -0400569
570 if (format == GL_RGB || format == GL_RGBA)
571 formatInfo.mIsColorRenderable = AlwaysSupported;
572
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000573 return formatInfo;
574 }
575
576 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
Geoff Langb2f3d052013-08-13 12:49:27 -0400577 GLenum format, GLenum type, GLenum componentType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000578 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000579 ContextRendererSupportCheckFunction textureFilterable,
580 ContextSupportCheckFunction supportFunction)
581 {
582 InternalFormatInfo formatInfo;
583 formatInfo.mRedBits = red;
584 formatInfo.mGreenBits = green;
585 formatInfo.mBlueBits = blue;
586 formatInfo.mAlphaBits = alpha;
587 formatInfo.mSharedBits = shared;
588 formatInfo.mPixelBits = red + green + blue + alpha + shared;
589 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
590 formatInfo.mFormat = format;
591 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400592 formatInfo.mComponentType = componentType;
593 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000594 formatInfo.mIsColorRenderable = colorRenderable;
595 formatInfo.mIsTextureFilterable = textureFilterable;
596 formatInfo.mSupportFunction = supportFunction;
597 return formatInfo;
598 }
599
Geoff Langb2f3d052013-08-13 12:49:27 -0400600 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000601 ContextSupportCheckFunction supportFunction)
602 {
603 InternalFormatInfo formatInfo;
604 formatInfo.mLuminanceBits = luminance;
605 formatInfo.mAlphaBits = alpha;
606 formatInfo.mPixelBits = luminance + alpha;
607 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
608 formatInfo.mFormat = format;
609 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400610 formatInfo.mComponentType = componentType;
611 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000612 formatInfo.mIsTextureFilterable = AlwaysSupported;
613 formatInfo.mSupportFunction = supportFunction;
614 return formatInfo;
615 }
616
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400617 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
618 GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000619 ContextRendererSupportCheckFunction depthRenderable,
620 ContextRendererSupportCheckFunction stencilRenderable,
621 ContextSupportCheckFunction supportFunction)
622 {
623 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400624 formatInfo.mDepthBits = depthBits;
625 formatInfo.mStencilBits = stencilBits;
626 formatInfo.mPixelBits = depthBits + stencilBits + unusedBits;
627 formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628 formatInfo.mFormat = format;
629 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400630 formatInfo.mComponentType = componentType;
631 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000632 formatInfo.mIsDepthRenderable = depthRenderable;
633 formatInfo.mIsStencilRenderable = stencilRenderable;
Nicolas Capens08be89d2013-07-16 16:17:31 -0400634 formatInfo.mIsTextureFilterable = AlwaysSupported;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000635 formatInfo.mSupportFunction = supportFunction;
636 return formatInfo;
637 }
638
Geoff Langb2f3d052013-08-13 12:49:27 -0400639 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
640 GLuint componentCount, GLenum format, GLenum type, bool srgb,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000641 ContextSupportCheckFunction supportFunction)
642 {
643 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000644 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
645 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
646 formatInfo.mPixelBits = compressedBlockSize;
647 formatInfo.mComponentCount = componentCount;
648 formatInfo.mFormat = format;
649 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400650 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
651 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
652 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000653 formatInfo.mIsTextureFilterable = AlwaysSupported;
654 formatInfo.mSupportFunction = supportFunction;
655 return formatInfo;
656 }
657};
658
Geoff Lang005df412013-10-16 14:12:50 -0400659typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
660typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000661
Geoff Lang18591b72013-06-07 12:00:15 -0400662static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000663{
664 InternalFormatInfoMap map;
665
666 // From ES 3.0.1 spec, table 3.12
667 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
668
Geoff Langb2f3d052013-08-13 12:49:27 -0400669 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
670 // | | | | | | | | | | | | renderable | filterable | |
671 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
672 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
673 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
674 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
675 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
676 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 -0400677 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 -0400678 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 )));
679 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 )));
680 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
681 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
682 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 -0400683 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 -0400684 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
685 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 -0400686 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 -0400687 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 )));
688 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
689 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 )));
690 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
691 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 )));
692 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
693 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 )));
694 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 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 )));
696 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
697 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 )));
698 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
699 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 )));
700 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
701 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 )));
702 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
703 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 )));
704 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
705 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 )));
706 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
707 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 )));
708 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
709 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 )));
710 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
711 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 +0000712
Geoff Langb2f3d052013-08-13 12:49:27 -0400713 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 )));
714 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 )));
715 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 +0000716
717 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langb2f3d052013-08-13 12:49:27 -0400718 // | Internal format | | D |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
719 // | | | | | | | type | | | | |
720 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 )));
721 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 )));
722 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 )));
723 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 )));
724 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 )));
725 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 )));
726 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 )));
727 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 +0000728
729 // Depth stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400730 // | Internal format | | D |S | X | Format | Type | Component type | Depth | Stencil | Supported |
731 // | | | | | | | | | renderable | renderable | |
732 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
733 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
734 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported)));
735 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
736 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)));
737 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)));
738 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 +0000739
740 // Luminance alpha formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400741 // | Internal format | | L | A | Format | Type | Component type | Supported |
742 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
746 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
747 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
748 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
749 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
750 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 +0000751
752 // Unsized formats
753 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000754 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
755 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
756 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400757 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
758 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000759 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
760 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400761 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
762 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
763 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
764 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000765 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
766
767 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400768 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
769 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
770 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
771 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
772 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
773 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
774 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
775 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)));
776 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)));
777 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
778 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 +0000779
780 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400781 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
782 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)));
783 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 +0000784
785 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400786 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 +0000787
788 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400789 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 +0000790
791 return map;
792}
793
Geoff Lang18591b72013-06-07 12:00:15 -0400794static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000795{
796 InternalFormatInfoMap map;
797
798 // From ES 2.0.25 table 4.5
799 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
800
Geoff Langb2f3d052013-08-13 12:49:27 -0400801 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
802 // | | | | | | | | | | | | renderable | filterable | |
803 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)));
804 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)));
805 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 +0000806
807 // Extension formats
Geoff Lang632192d2013-10-04 13:40:46 -0400808 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>)));
809 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 -0400810 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)));
811 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)));
812 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)));
813 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)));
814 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 +0000815
816 // Floating point formats have to query the renderer for support
Geoff Langb2f3d052013-08-13 12:49:27 -0400817 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
818 // | | | | | | | | | | type | | | | |
Geoff Lang632192d2013-10-04 13:40:46 -0400819 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> )));
820 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> )));
821 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> )));
822 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 -0400823 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>)));
824 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>)));
825 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>)));
826 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 +0000827
828 // Depth and stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400829 // | Internal format | | D |S |X | Format | Type | Internal format | Depth | Stencil | Supported |
830 // | | | | | | | | type | renderable | renderable | |
831 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>)));
832 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>)));
833 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
834 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 +0000835
836 // Unsized formats
837 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000838 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
839 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
840 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Lang632192d2013-10-04 13:40:46 -0400841 map.insert(InternalFormatInfoPair(GL_RED_EXT, InternalFormatInfo::UnsizedFormat(GL_RED_EXT, CheckSupport<&Context::supportsRGTextures>)));
842 map.insert(InternalFormatInfoPair(GL_RG_EXT, InternalFormatInfo::UnsizedFormat(GL_RG_EXT, CheckSupport<&Context::supportsRGTextures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
844 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
845 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
846 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
847 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
848
849 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langb2f3d052013-08-13 12:49:27 -0400850 // | Internal format | | L | A | Format | Type | Component type | Supported |
851 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
852 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
853 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
854 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
855 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
856 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
857 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
858 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
859 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 +0000860
861 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400862 // | Internal format | |W |H | BS |CC|Format | Type | SRGB | Supported |
863 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>)));
864 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 +0000865
866 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400867 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 +0000868
869 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400870 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 +0000871
872 return map;
873}
874
Geoff Lang005df412013-10-16 14:12:50 -0400875static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000876{
877 const InternalFormatInfoMap* map = NULL;
878
879 if (clientVersion == 2)
880 {
Geoff Lang18591b72013-06-07 12:00:15 -0400881 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000882 map = &formatMap;
883 }
884 else if (clientVersion == 3)
885 {
Geoff Lang18591b72013-06-07 12:00:15 -0400886 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000887 map = &formatMap;
888 }
889 else
890 {
891 UNREACHABLE();
892 }
893
894 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
895 if (iter != map->end())
896 {
897 if (outFormatInfo)
898 {
899 *outFormatInfo = iter->second;
900 }
901 return true;
902 }
903 else
904 {
905 return false;
906 }
907}
908
909typedef std::set<GLenum> FormatSet;
910
Geoff Lang18591b72013-06-07 12:00:15 -0400911static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000912{
Geoff Langfe28ca02013-06-04 10:10:48 -0400913 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000914
915 FormatSet set;
916
917 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
918 {
919 const FormatTypePair& formatPair = i->first;
920 set.insert(formatPair.first);
921 }
922
923 return set;
924}
925
Geoff Lang18591b72013-06-07 12:00:15 -0400926static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000927{
Geoff Lang18591b72013-06-07 12:00:15 -0400928 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000929
930 FormatSet set;
931
932 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
933 {
934 const FormatInfo& formatInfo = *i;
935 set.insert(formatInfo.mFormat);
936 }
937
938 return set;
939}
940
941typedef std::set<GLenum> TypeSet;
942
Geoff Lang18591b72013-06-07 12:00:15 -0400943static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000944{
Geoff Langfe28ca02013-06-04 10:10:48 -0400945 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000946
947 TypeSet set;
948
949 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
950 {
951 const FormatTypePair& formatPair = i->first;
952 set.insert(formatPair.second);
953 }
954
955 return set;
956}
957
Geoff Lang18591b72013-06-07 12:00:15 -0400958static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000959{
Geoff Lang18591b72013-06-07 12:00:15 -0400960 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000961
962 TypeSet set;
963
964 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
965 {
966 const FormatInfo& formatInfo = *i;
967 set.insert(formatInfo.mType);
968 }
969
970 return set;
971}
972
Shannon Woods4d161ba2014-03-17 18:13:30 -0400973struct EffectiveInternalFormatInfo
974{
975 GLenum mEffectiveFormat;
976 GLenum mDestFormat;
977 GLuint mMinRedBits;
978 GLuint mMaxRedBits;
979 GLuint mMinGreenBits;
980 GLuint mMaxGreenBits;
981 GLuint mMinBlueBits;
982 GLuint mMaxBlueBits;
983 GLuint mMinAlphaBits;
984 GLuint mMaxAlphaBits;
985
986 EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits,
987 GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits,
988 GLuint minAlphaBits, GLuint maxAlphaBits)
989 : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits),
990 mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits),
991 mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits),
992 mMaxAlphaBits(maxAlphaBits) {};
993};
994
995typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList;
996
997static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList()
998{
999 EffectiveInternalFormatList list;
1000
1001 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
1002 // linear source buffer component sizes.
1003 // | Source channel min/max sizes |
1004 // Effective Internal Format | N/A | R | G | B | A |
1005 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8));
1006 list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0));
1007 list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0));
1008 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0));
1009 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0));
1010 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4));
1011 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1));
1012 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8));
1013 list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2));
1014
1015 return list;
1016}
1017
1018
1019static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList()
1020{
1021 EffectiveInternalFormatList list;
1022
1023 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
1024 // linear source buffer component sizes.
1025 // | Source channel min/max sizes |
1026 // Effective Internal Format | Dest Format | R | G | B | A |
1027 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1028 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX));
1029 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1030 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX));
1031 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX));
1032 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4));
1033 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1));
1034 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8));
1035
1036 return list;
1037}
1038
1039static bool GetEffectiveInternalFormat(const InternalFormatInfo &srcFormat, const InternalFormatInfo &destFormat,
1040 GLuint clientVersion, GLenum *outEffectiveFormat)
1041{
1042 const EffectiveInternalFormatList *list = NULL;
1043 GLenum targetFormat = GL_NONE;
1044
1045 if (gl::IsSizedInternalFormat(destFormat.mFormat, clientVersion))
1046 {
1047 static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList();
1048 list = &sizedList;
1049 }
1050 else
1051 {
1052 static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList();
1053 list = &unsizedList;
1054 targetFormat = destFormat.mFormat;
1055 }
1056
1057 for (size_t curFormat = 0; curFormat < list->size(); ++curFormat)
1058 {
1059 const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat);
1060 if ((formatInfo.mDestFormat == targetFormat) &&
1061 (formatInfo.mMinRedBits <= srcFormat.mRedBits && formatInfo.mMaxRedBits >= srcFormat.mRedBits) &&
1062 (formatInfo.mMinGreenBits <= srcFormat.mGreenBits && formatInfo.mMaxGreenBits >= srcFormat.mGreenBits) &&
1063 (formatInfo.mMinBlueBits <= srcFormat.mBlueBits && formatInfo.mMaxBlueBits >= srcFormat.mBlueBits) &&
1064 (formatInfo.mMinAlphaBits <= srcFormat.mAlphaBits && formatInfo.mMaxAlphaBits >= srcFormat.mAlphaBits))
1065 {
1066 *outEffectiveFormat = formatInfo.mEffectiveFormat;
1067 return true;
1068 }
1069 }
1070
1071 return false;
1072}
1073
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001074struct CopyConversion
1075{
1076 GLenum mTextureFormat;
1077 GLenum mFramebufferFormat;
1078
1079 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
1080 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
1081
1082 bool operator<(const CopyConversion& other) const
1083 {
1084 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
1085 }
1086};
1087
1088typedef std::set<CopyConversion> CopyConversionSet;
1089
Geoff Lang18591b72013-06-07 12:00:15 -04001090static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001091{
1092 CopyConversionSet set;
1093
1094 // From ES 3.0.1 spec, table 3.15
1095 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
1096 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
1097 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
1098 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
1099 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
1100 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
1101 set.insert(CopyConversion(GL_RED, GL_RED));
1102 set.insert(CopyConversion(GL_RED, GL_RG));
1103 set.insert(CopyConversion(GL_RED, GL_RGB));
1104 set.insert(CopyConversion(GL_RED, GL_RGBA));
1105 set.insert(CopyConversion(GL_RG, GL_RG));
1106 set.insert(CopyConversion(GL_RG, GL_RGB));
1107 set.insert(CopyConversion(GL_RG, GL_RGBA));
1108 set.insert(CopyConversion(GL_RGB, GL_RGB));
1109 set.insert(CopyConversion(GL_RGB, GL_RGBA));
1110 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
1111
Jamie Madillb70e5f72013-07-10 16:57:52 -04001112 // Necessary for ANGLE back-buffers
1113 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
1114 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
1115 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
1116 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
1117 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
1118 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
1119 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
1120
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001121 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
1122 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1123 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1124 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1125 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1126 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1127 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1128 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1129 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1130 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1131
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001132 return set;
1133}
1134
Geoff Lang005df412013-10-16 14:12:50 -04001135bool IsValidInternalFormat(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001136{
1137 if (!context)
1138 {
1139 return false;
1140 }
1141
1142 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001143 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144 {
1145 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1146 return internalFormatInfo.mSupportFunction(context);
1147 }
1148 else
1149 {
1150 return false;
1151 }
1152}
1153
1154bool IsValidFormat(GLenum format, GLuint clientVersion)
1155{
1156 if (clientVersion == 2)
1157 {
Geoff Lang18591b72013-06-07 12:00:15 -04001158 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001159 return formatSet.find(format) != formatSet.end();
1160 }
1161 else if (clientVersion == 3)
1162 {
Geoff Lang18591b72013-06-07 12:00:15 -04001163 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001164 return formatSet.find(format) != formatSet.end();
1165 }
1166 else
1167 {
1168 UNREACHABLE();
1169 return false;
1170 }
1171}
1172
1173bool IsValidType(GLenum type, GLuint clientVersion)
1174{
1175 if (clientVersion == 2)
1176 {
Geoff Lang18591b72013-06-07 12:00:15 -04001177 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001178 return typeSet.find(type) != typeSet.end();
1179 }
1180 else if (clientVersion == 3)
1181 {
Geoff Lang18591b72013-06-07 12:00:15 -04001182 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001183 return typeSet.find(type) != typeSet.end();
1184 }
1185 else
1186 {
1187 UNREACHABLE();
1188 return false;
1189 }
1190}
1191
Geoff Lang005df412013-10-16 14:12:50 -04001192bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001193{
1194 if (clientVersion == 2)
1195 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001196 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001197 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1198
Geoff Langfe28ca02013-06-04 10:10:48 -04001199 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001200 }
1201 else if (clientVersion == 3)
1202 {
Geoff Lang18591b72013-06-07 12:00:15 -04001203 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001204 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1205 }
1206 else
1207 {
1208 UNREACHABLE();
1209 return false;
1210 }
1211}
1212
Shannon Woods4d161ba2014-03-17 18:13:30 -04001213bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001214{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001215 InternalFormatInfo textureInternalFormatInfo;
1216 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001217 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1218 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001219 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001220 if (clientVersion == 2)
1221 {
1222 UNIMPLEMENTED();
1223 return false;
1224 }
1225 else if (clientVersion == 3)
1226 {
Geoff Lang18591b72013-06-07 12:00:15 -04001227 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001228 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1229 framebufferInternalFormatInfo.mFormat);
1230 if (conversionSet.find(conversion) != conversionSet.end())
1231 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001232 // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats
1233 // must both be signed, unsigned, or fixed point and both source and destinations
1234 // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed
1235 // conversion between fixed and floating point.
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001236
Geoff Langb2f3d052013-08-13 12:49:27 -04001237 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001238 {
1239 return false;
1240 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001241
Shannon Woods4d161ba2014-03-17 18:13:30 -04001242 if (((textureInternalFormatInfo.mComponentType == GL_INT) != (framebufferInternalFormatInfo.mComponentType == GL_INT)) ||
1243 ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT)))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001244 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001245 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001246 }
1247
Shannon Woods4d161ba2014-03-17 18:13:30 -04001248 if (gl::IsFloatOrFixedComponentType(textureInternalFormatInfo.mComponentType) &&
1249 !gl::IsFloatOrFixedComponentType(framebufferInternalFormatInfo.mComponentType))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001250 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001251 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001252 }
Shannon Woods4d161ba2014-03-17 18:13:30 -04001253
1254 // GLES specification 3.0.3, sec 3.8.5, pg 139-140:
1255 // The effective internal format of the source buffer is determined with the following rules applied in order:
1256 // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the
1257 // effective internal format is the source buffer's sized internal format.
1258 // * If the source buffer is a texture that was created with an unsized base internal format, then the
1259 // effective internal format is the source image array's effective internal format, as specified by table
1260 // 3.12, which is determined from the <format> and <type> that were used when the source image array was
1261 // specified by TexImage*.
1262 // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where
1263 // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent
1264 // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the
1265 // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING
1266 // is SRGB.
1267 InternalFormatInfo sourceEffectiveFormat;
1268 if (readBufferHandle != 0)
1269 {
1270 // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer
1271 if (gl::IsSizedInternalFormat(framebufferInternalFormatInfo.mFormat, clientVersion))
1272 {
1273 sourceEffectiveFormat = framebufferInternalFormatInfo;
1274 }
1275 else
1276 {
1277 // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format
1278 // texture. We can use the same table we use when creating textures to get its effective sized format.
1279 GLenum effectiveFormat = gl::GetSizedInternalFormat(framebufferInternalFormatInfo.mFormat,
1280 framebufferInternalFormatInfo.mType, clientVersion);
1281 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1282 }
1283 }
1284 else
1285 {
1286 // The effective internal format must be derived from the source framebuffer's channel sizes.
1287 // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17)
1288 if (framebufferInternalFormatInfo.mColorEncoding == GL_LINEAR)
1289 {
1290 GLenum effectiveFormat;
1291 if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, clientVersion, &effectiveFormat))
1292 {
1293 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1294 }
1295 else
1296 {
1297 return false;
1298 }
1299 }
1300 else if (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB)
1301 {
1302 // SRGB buffers can only be copied to sized format destinations according to table 3.18
1303 if (gl::IsSizedInternalFormat(textureInternalFormat, clientVersion) &&
1304 (framebufferInternalFormatInfo.mRedBits >= 1 && framebufferInternalFormatInfo.mRedBits <= 8) &&
1305 (framebufferInternalFormatInfo.mGreenBits >= 1 && framebufferInternalFormatInfo.mGreenBits <= 8) &&
1306 (framebufferInternalFormatInfo.mBlueBits >= 1 && framebufferInternalFormatInfo.mBlueBits <= 8) &&
1307 (framebufferInternalFormatInfo.mAlphaBits >= 1 && framebufferInternalFormatInfo.mAlphaBits <= 8))
1308 {
1309 gl::GetInternalFormatInfo(GL_SRGB8_ALPHA8, clientVersion, &sourceEffectiveFormat);
1310 }
1311 else
1312 {
1313 return false;
1314 }
1315 }
1316 else
1317 {
1318 UNREACHABLE();
1319 }
1320 }
1321
1322 if (gl::IsSizedInternalFormat(textureInternalFormatInfo.mFormat, clientVersion))
1323 {
1324 // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized,
1325 // component sizes of the source and destination formats must exactly match
1326 if (textureInternalFormatInfo.mRedBits != sourceEffectiveFormat.mRedBits ||
1327 textureInternalFormatInfo.mGreenBits != sourceEffectiveFormat.mGreenBits ||
1328 textureInternalFormatInfo.mBlueBits != sourceEffectiveFormat.mBlueBits ||
1329 textureInternalFormatInfo.mAlphaBits != sourceEffectiveFormat.mAlphaBits)
1330 {
1331 return false;
1332 }
1333 }
1334
1335
1336 return true; // A conversion function exists, and no rule in the specification has precluded conversion
1337 // between these formats.
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001338 }
1339
1340 return false;
1341 }
1342 else
1343 {
1344 UNREACHABLE();
1345 return false;
1346 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001347 }
1348 else
1349 {
1350 UNREACHABLE();
1351 return false;
1352 }
1353}
1354
Geoff Lang005df412013-10-16 14:12:50 -04001355bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001356{
1357 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001358 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001359 {
1360 return internalFormatInfo.mPixelBits > 0;
1361 }
1362 else
1363 {
1364 UNREACHABLE();
1365 return false;
1366 }
1367}
1368
Geoff Lang005df412013-10-16 14:12:50 -04001369GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001370{
Geoff Langfe28ca02013-06-04 10:10:48 -04001371 const FormatMap &formats = GetFormatMap(clientVersion);
1372 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1373 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001374}
1375
Geoff Lang005df412013-10-16 14:12:50 -04001376GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001377{
1378 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001379 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001380 {
1381 return internalFormatInfo.mPixelBits / 8;
1382 }
1383 else
1384 {
1385 UNREACHABLE();
1386 return 0;
1387 }
1388}
1389
Geoff Lang005df412013-10-16 14:12:50 -04001390GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001391{
1392 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001393 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001394 {
1395 return internalFormatInfo.mAlphaBits;
1396 }
1397 else
1398 {
1399 UNREACHABLE();
1400 return 0;
1401 }
1402}
1403
Geoff Lang005df412013-10-16 14:12:50 -04001404GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001405{
1406 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001407 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001408 {
1409 return internalFormatInfo.mRedBits;
1410 }
1411 else
1412 {
1413 UNREACHABLE();
1414 return 0;
1415 }
1416}
1417
Geoff Lang005df412013-10-16 14:12:50 -04001418GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001419{
1420 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001421 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001422 {
1423 return internalFormatInfo.mGreenBits;
1424 }
1425 else
1426 {
1427 UNREACHABLE();
1428 return 0;
1429 }
1430}
1431
Geoff Lang005df412013-10-16 14:12:50 -04001432GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001433{
1434 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001435 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001436 {
Geoff Lang24159222013-06-05 14:56:32 -04001437 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001438 }
1439 else
1440 {
1441 UNREACHABLE();
1442 return 0;
1443 }
1444}
1445
Geoff Lang005df412013-10-16 14:12:50 -04001446GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001447{
1448 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001449 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001450 {
1451 return internalFormatInfo.mLuminanceBits;
1452 }
1453 else
1454 {
1455 UNREACHABLE();
1456 return 0;
1457 }
1458}
1459
Geoff Lang005df412013-10-16 14:12:50 -04001460GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001461{
1462 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001463 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001464 {
1465 return internalFormatInfo.mDepthBits;
1466 }
1467 else
1468 {
1469 UNREACHABLE();
1470 return 0;
1471 }
1472}
1473
Geoff Lang005df412013-10-16 14:12:50 -04001474GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001475{
1476 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001477 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001478 {
1479 return internalFormatInfo.mStencilBits;
1480 }
1481 else
1482 {
1483 UNREACHABLE();
1484 return 0;
1485 }
1486}
1487
Geoff Langf23eb282013-07-22 10:52:19 -04001488GLuint GetTypeBytes(GLenum type)
1489{
1490 TypeInfo typeInfo;
1491 if (GetTypeInfo(type, &typeInfo))
1492 {
1493 return typeInfo.mTypeBytes;
1494 }
1495 else
1496 {
1497 UNREACHABLE();
1498 return 0;
1499 }
1500}
1501
1502bool IsSpecialInterpretationType(GLenum type)
1503{
1504 TypeInfo typeInfo;
1505 if (GetTypeInfo(type, &typeInfo))
1506 {
1507 return typeInfo.mSpecialInterpretation;
1508 }
1509 else
1510 {
1511 UNREACHABLE();
1512 return false;
1513 }
1514}
1515
Shannon Woods4d161ba2014-03-17 18:13:30 -04001516bool IsFloatOrFixedComponentType(GLenum type)
1517{
1518 if (type == GL_UNSIGNED_NORMALIZED ||
1519 type == GL_SIGNED_NORMALIZED ||
1520 type == GL_FLOAT)
1521 {
1522 return true;
1523 }
1524 else
1525 {
1526 return false;
1527 }
1528}
1529
Geoff Lang005df412013-10-16 14:12:50 -04001530GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001531{
1532 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001533 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001534 {
1535 return internalFormatInfo.mFormat;
1536 }
1537 else
1538 {
1539 UNREACHABLE();
1540 return GL_NONE;
1541 }
1542}
1543
Geoff Lang005df412013-10-16 14:12:50 -04001544GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001545{
1546 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001547 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001548 {
1549 return internalFormatInfo.mType;
1550 }
1551 else
1552 {
1553 UNREACHABLE();
1554 return GL_NONE;
1555 }
1556}
1557
Nicolas Capens0027fa92014-02-20 14:26:42 -05001558GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001559{
1560 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001561 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001562 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001563 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001564 }
1565 else
1566 {
1567 UNREACHABLE();
Nicolas Capens0027fa92014-02-20 14:26:42 -05001568 return GL_NONE;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001569 }
1570}
1571
Geoff Lang005df412013-10-16 14:12:50 -04001572GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001573{
1574 InternalFormatInfo internalFormatInfo;
1575 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1576 {
1577 return internalFormatInfo.mComponentCount;
1578 }
1579 else
1580 {
1581 UNREACHABLE();
1582 return false;
1583 }
1584}
1585
Geoff Lang005df412013-10-16 14:12:50 -04001586GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001587{
1588 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001589 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001590 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001591 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001592 }
1593 else
1594 {
1595 UNREACHABLE();
1596 return false;
1597 }
1598}
1599
Geoff Lang005df412013-10-16 14:12:50 -04001600bool IsColorRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001601{
1602 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001603 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001604 {
1605 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1606 }
1607 else
1608 {
1609 UNREACHABLE();
1610 return false;
1611 }
1612}
1613
Geoff Lang005df412013-10-16 14:12:50 -04001614bool IsColorRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001615{
1616 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001617 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001618 {
1619 return internalFormatInfo.mIsColorRenderable(context, NULL);
1620 }
1621 else
1622 {
1623 UNREACHABLE();
1624 return false;
1625 }
1626}
1627
Geoff Lang005df412013-10-16 14:12:50 -04001628bool IsTextureFilteringSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001629{
1630 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001631 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001632 {
1633 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1634 }
1635 else
1636 {
1637 UNREACHABLE();
1638 return false;
1639 }
1640}
1641
Geoff Lang005df412013-10-16 14:12:50 -04001642bool IsTextureFilteringSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001643{
1644 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001645 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001646 {
1647 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1648 }
1649 else
1650 {
1651 UNREACHABLE();
1652 return false;
1653 }
1654}
1655
Geoff Lang005df412013-10-16 14:12:50 -04001656bool IsDepthRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001657{
1658 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001659 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001660 {
1661 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1662 }
1663 else
1664 {
1665 UNREACHABLE();
1666 return false;
1667 }
1668}
1669
Geoff Lang005df412013-10-16 14:12:50 -04001670bool IsDepthRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001671{
1672 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001673 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001674 {
1675 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1676 }
1677 else
1678 {
1679 UNREACHABLE();
1680 return false;
1681 }
1682}
1683
Geoff Lang005df412013-10-16 14:12:50 -04001684bool IsStencilRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001685{
1686 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001687 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001688 {
1689 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1690 }
1691 else
1692 {
1693 UNREACHABLE();
1694 return false;
1695 }
1696}
1697
Geoff Lang005df412013-10-16 14:12:50 -04001698bool IsStencilRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001699{
1700 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001701 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001702 {
1703 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1704 }
1705 else
1706 {
1707 UNREACHABLE();
1708 return false;
1709 }
1710}
1711
Geoff Lang005df412013-10-16 14:12:50 -04001712GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001713{
1714 ASSERT(alignment > 0 && isPow2(alignment));
Jamie Madilleb9baab2014-03-24 13:19:43 -04001715 return rx::roundUp(GetBlockSize(internalFormat, type, clientVersion, width, 1), static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001716}
1717
Geoff Lang005df412013-10-16 14:12:50 -04001718GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001719{
Jamie Madill666e2862013-09-10 12:04:29 -04001720 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001721}
1722
Geoff Lang005df412013-10-16 14:12:50 -04001723GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001724{
1725 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001726 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001727 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001728 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001729 {
1730 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1731 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1732
1733 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1734 }
1735 else
1736 {
1737 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001738 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001739 {
1740 if (typeInfo.mSpecialInterpretation)
1741 {
1742 return typeInfo.mTypeBytes * width * height;
1743 }
1744 else
1745 {
1746 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1747 }
1748 }
1749 else
1750 {
1751 UNREACHABLE();
1752 return 0;
1753 }
1754 }
1755 }
1756 else
1757 {
1758 UNREACHABLE();
1759 return 0;
1760 }
1761}
1762
Geoff Lang005df412013-10-16 14:12:50 -04001763bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001764{
1765 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001766 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001767 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001768 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001769 }
1770 else
1771 {
1772 UNREACHABLE();
1773 return false;
1774 }
1775}
1776
Geoff Lang005df412013-10-16 14:12:50 -04001777GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001778{
1779 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001780 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001781 {
1782 return internalFormatInfo.mCompressedBlockWidth;
1783 }
1784 else
1785 {
1786 UNREACHABLE();
1787 return 0;
1788 }
1789}
1790
Geoff Lang005df412013-10-16 14:12:50 -04001791GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001792{
1793 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001794 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001795 {
1796 return internalFormatInfo.mCompressedBlockHeight;
1797 }
1798 else
1799 {
1800 UNREACHABLE();
1801 return 0;
1802 }
1803}
1804
Geoff Langfe28ca02013-06-04 10:10:48 -04001805ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1806{
1807 static const FormatMap &formats = GetFormatMap(clientVersion);
1808 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1809 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1810}
1811
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001812}