blob: 4145ac875aeb73fff813359aa07864c9c277c320 [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
322 // From GL_EXT_texture_storage
323 // | Internal format | Format | Type |
324 // | | | |
325 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
326 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
327 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
328 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
329 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
330 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
331 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
332 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
333 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
334
335 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
336 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
337 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
338 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
339 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
340
341 // From GL_ANGLE_depth_texture
342 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
343
344 // Compressed formats
345 // From ES 3.0.1 spec, table 3.16
346 // | Internal format | Format | Type |
347 // | | | |
348 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
349 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
350 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
351 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
352 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
353 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
354 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
355 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
356 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
357 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
358 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
359
360
361 // From GL_EXT_texture_compression_dxt1
362 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
363 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
364
365 // From GL_ANGLE_texture_compression_dxt3
366 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
367
368 // From GL_ANGLE_texture_compression_dxt5
369 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
370
371 return set;
372}
373
Geoff Lang18591b72013-06-07 12:00:15 -0400374static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000375{
Geoff Lang18591b72013-06-07 12:00:15 -0400376 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000377 return es3FormatSet;
378}
379
380// Map of sizes of input types
381struct TypeInfo
382{
383 GLuint mTypeBytes;
384 bool mSpecialInterpretation;
385
386 TypeInfo()
387 : mTypeBytes(0), mSpecialInterpretation(false) { }
388
389 TypeInfo(GLuint typeBytes, bool specialInterpretation)
390 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
391
392 bool operator<(const TypeInfo& other) const
393 {
394 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
395 }
396};
397
398typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
399typedef std::map<GLenum, TypeInfo> TypeInfoMap;
400
Geoff Lang18591b72013-06-07 12:00:15 -0400401static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000402{
403 TypeInfoMap map;
404
405 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
406 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
407 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
408 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
409 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
410 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
411 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
Jamie Madilla940ae42013-07-08 17:48:34 -0400412 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000413 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
414 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
415 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
416 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
417 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
418 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
419 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
420 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
421 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
422 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000423 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400424 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000425
426 return map;
427}
428
Geoff Lang18591b72013-06-07 12:00:15 -0400429static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000430{
Geoff Lang18591b72013-06-07 12:00:15 -0400431 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000432 TypeInfoMap::const_iterator iter = infoMap.find(type);
433 if (iter != infoMap.end())
434 {
435 if (outTypeInfo)
436 {
437 *outTypeInfo = iter->second;
438 }
439 return true;
440 }
441 else
442 {
443 return false;
444 }
445}
446
447// Information about internal formats
448typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const);
449typedef bool (*ContextSupportCheckFunction)(const Context *context);
450
451typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const);
452typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer);
453
454template <ContextSupportCheckMemberFunction func>
455bool CheckSupport(const Context *context)
456{
457 return (context->*func)();
458}
459
460template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc>
461bool CheckSupport(const Context *context, const rx::Renderer *renderer)
462{
463 if (context)
464 {
465 return (context->*contextFunc)();
466 }
467 else if (renderer)
468 {
469 return (renderer->*rendererFunc)();
470 }
471 else
472 {
473 UNREACHABLE();
474 return false;
475 }
476}
477
478template <typename objectType>
479bool AlwaysSupported(const objectType*)
480{
481 return true;
482}
483
484template <typename objectTypeA, typename objectTypeB>
485bool AlwaysSupported(const objectTypeA*, const objectTypeB*)
486{
487 return true;
488}
489
490template <typename objectType>
491bool NeverSupported(const objectType*)
492{
493 return false;
494}
495
496template <typename objectTypeA, typename objectTypeB>
497bool NeverSupported(const objectTypeA *, const objectTypeB *)
498{
499 return false;
500}
501
502template <typename objectType>
503bool UnimplementedSupport(const objectType*)
504{
505 UNIMPLEMENTED();
506 return false;
507}
508
509template <typename objectTypeA, typename objectTypeB>
510bool UnimplementedSupport(const objectTypeA*, const objectTypeB*)
511{
512 UNIMPLEMENTED();
513 return false;
514}
515
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000516struct InternalFormatInfo
517{
518 GLuint mRedBits;
519 GLuint mGreenBits;
520 GLuint mBlueBits;
521
522 GLuint mLuminanceBits;
523
524 GLuint mAlphaBits;
525 GLuint mSharedBits;
526
527 GLuint mDepthBits;
528 GLuint mStencilBits;
529
530 GLuint mPixelBits;
531
532 GLuint mComponentCount;
533
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000534 GLuint mCompressedBlockWidth;
535 GLuint mCompressedBlockHeight;
536
537 GLenum mFormat;
538 GLenum mType;
539
Geoff Langb2f3d052013-08-13 12:49:27 -0400540 GLenum mComponentType;
541 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000542
Geoff Langb2f3d052013-08-13 12:49:27 -0400543 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000544
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000545 ContextRendererSupportCheckFunction mIsColorRenderable;
546 ContextRendererSupportCheckFunction mIsDepthRenderable;
547 ContextRendererSupportCheckFunction mIsStencilRenderable;
548 ContextRendererSupportCheckFunction mIsTextureFilterable;
549
550 ContextSupportCheckFunction mSupportFunction;
551
552 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 +0000553 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langb2f3d052013-08-13 12:49:27 -0400554 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mIsColorRenderable(NeverSupported),
555 mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported), mIsTextureFilterable(NeverSupported),
556 mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000557 {
558 }
559
560 static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction)
561 {
562 InternalFormatInfo formatInfo;
563 formatInfo.mFormat = format;
564 formatInfo.mSupportFunction = supportFunction;
Shannon Woods9e73b212013-07-08 10:32:19 -0400565
566 if (format == GL_RGB || format == GL_RGBA)
567 formatInfo.mIsColorRenderable = AlwaysSupported;
568
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000569 return formatInfo;
570 }
571
572 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
Geoff Langb2f3d052013-08-13 12:49:27 -0400573 GLenum format, GLenum type, GLenum componentType, bool srgb,
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000574 ContextRendererSupportCheckFunction colorRenderable,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000575 ContextRendererSupportCheckFunction textureFilterable,
576 ContextSupportCheckFunction supportFunction)
577 {
578 InternalFormatInfo formatInfo;
579 formatInfo.mRedBits = red;
580 formatInfo.mGreenBits = green;
581 formatInfo.mBlueBits = blue;
582 formatInfo.mAlphaBits = alpha;
583 formatInfo.mSharedBits = shared;
584 formatInfo.mPixelBits = red + green + blue + alpha + shared;
585 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
586 formatInfo.mFormat = format;
587 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400588 formatInfo.mComponentType = componentType;
589 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000590 formatInfo.mIsColorRenderable = colorRenderable;
591 formatInfo.mIsTextureFilterable = textureFilterable;
592 formatInfo.mSupportFunction = supportFunction;
593 return formatInfo;
594 }
595
Geoff Langb2f3d052013-08-13 12:49:27 -0400596 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000597 ContextSupportCheckFunction supportFunction)
598 {
599 InternalFormatInfo formatInfo;
600 formatInfo.mLuminanceBits = luminance;
601 formatInfo.mAlphaBits = alpha;
602 formatInfo.mPixelBits = luminance + alpha;
603 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
604 formatInfo.mFormat = format;
605 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400606 formatInfo.mComponentType = componentType;
607 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000608 formatInfo.mIsTextureFilterable = AlwaysSupported;
609 formatInfo.mSupportFunction = supportFunction;
610 return formatInfo;
611 }
612
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400613 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
614 GLenum type, GLenum componentType,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000615 ContextRendererSupportCheckFunction depthRenderable,
616 ContextRendererSupportCheckFunction stencilRenderable,
617 ContextSupportCheckFunction supportFunction)
618 {
619 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400620 formatInfo.mDepthBits = depthBits;
621 formatInfo.mStencilBits = stencilBits;
622 formatInfo.mPixelBits = depthBits + stencilBits + unusedBits;
623 formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624 formatInfo.mFormat = format;
625 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400626 formatInfo.mComponentType = componentType;
627 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628 formatInfo.mIsDepthRenderable = depthRenderable;
629 formatInfo.mIsStencilRenderable = stencilRenderable;
Nicolas Capens08be89d2013-07-16 16:17:31 -0400630 formatInfo.mIsTextureFilterable = AlwaysSupported;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631 formatInfo.mSupportFunction = supportFunction;
632 return formatInfo;
633 }
634
Geoff Langb2f3d052013-08-13 12:49:27 -0400635 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
636 GLuint componentCount, GLenum format, GLenum type, bool srgb,
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000637 ContextSupportCheckFunction supportFunction)
638 {
639 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
641 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
642 formatInfo.mPixelBits = compressedBlockSize;
643 formatInfo.mComponentCount = componentCount;
644 formatInfo.mFormat = format;
645 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400646 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
647 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
648 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000649 formatInfo.mIsTextureFilterable = AlwaysSupported;
650 formatInfo.mSupportFunction = supportFunction;
651 return formatInfo;
652 }
653};
654
Geoff Lang005df412013-10-16 14:12:50 -0400655typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
656typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000657
Geoff Lang18591b72013-06-07 12:00:15 -0400658static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000659{
660 InternalFormatInfoMap map;
661
662 // From ES 3.0.1 spec, table 3.12
663 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
664
Geoff Langb2f3d052013-08-13 12:49:27 -0400665 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
666 // | | | | | | | | | | | | renderable | filterable | |
667 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
668 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
669 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
670 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
671 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
672 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 -0400673 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 -0400674 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 )));
675 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 )));
676 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, AlwaysSupported )));
677 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, AlwaysSupported, AlwaysSupported )));
678 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 -0400679 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 -0400680 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported )));
681 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 -0400682 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 -0400683 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 )));
684 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
685 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 )));
686 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
687 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 )));
688 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
689 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 )));
690 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
691 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 )));
692 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
693 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 )));
694 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
695 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 )));
696 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
697 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 )));
698 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
699 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 )));
700 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, NeverSupported, NeverSupported, AlwaysSupported )));
701 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 )));
702 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
703 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 )));
704 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
705 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 )));
706 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported, NeverSupported, AlwaysSupported )));
707 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 +0000708
Geoff Langb2f3d052013-08-13 12:49:27 -0400709 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 )));
710 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 )));
711 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 +0000712
713 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langb2f3d052013-08-13 12:49:27 -0400714 // | Internal format | | D |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
715 // | | | | | | | type | | | | |
716 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 )));
717 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 )));
718 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 )));
719 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 )));
720 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 )));
721 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 )));
722 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 )));
723 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 +0000724
725 // Depth stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400726 // | Internal format | | D |S | X | Format | Type | Component type | Depth | Stencil | Supported |
727 // | | | | | | | | | renderable | renderable | |
728 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
729 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
730 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported)));
731 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
732 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)));
733 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)));
734 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 +0000735
736 // Luminance alpha formats
Geoff Langb2f3d052013-08-13 12:49:27 -0400737 // | Internal format | | L | A | Format | Type | Component type | Supported |
738 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
739 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
740 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
741 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
742 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
743 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, AlwaysSupported)));
744 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
745 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
746 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 +0000747
748 // Unsized formats
749 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000750 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
751 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
752 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400753 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
754 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000755 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
756 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400757 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
758 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
759 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
760 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000761 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
762
763 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400764 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
765 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
766 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
767 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
768 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
769 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
770 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
771 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)));
772 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)));
773 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
774 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 +0000775
776 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400777 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
778 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)));
779 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 +0000780
781 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400782 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 +0000783
784 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400785 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 +0000786
787 return map;
788}
789
Geoff Lang18591b72013-06-07 12:00:15 -0400790static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000791{
792 InternalFormatInfoMap map;
793
794 // From ES 2.0.25 table 4.5
795 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
796
Geoff Langb2f3d052013-08-13 12:49:27 -0400797 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Color | Texture | Supported |
798 // | | | | | | | | | | | | renderable | filterable | |
799 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)));
800 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)));
801 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 +0000802
803 // Extension formats
Geoff Lang632192d2013-10-04 13:40:46 -0400804 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>)));
805 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 -0400806 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)));
807 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)));
808 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)));
809 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)));
810 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 +0000811
812 // Floating point formats have to query the renderer for support
Geoff Langb2f3d052013-08-13 12:49:27 -0400813 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Color renderable | Texture filterable | Supported |
814 // | | | | | | | | | | type | | | | |
Geoff Lang632192d2013-10-04 13:40:46 -0400815 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> )));
816 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> )));
817 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> )));
818 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 -0400819 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>)));
820 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>)));
821 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>)));
822 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 +0000823
824 // Depth and stencil formats
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400825 // | Internal format | | D |S |X | Format | Type | Internal format | Depth | Stencil | Supported |
826 // | | | | | | | | type | renderable | renderable | |
827 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>)));
828 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>)));
829 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported, NeverSupported, AlwaysSupported)));
830 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 +0000831
832 // Unsized formats
833 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000834 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
835 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
836 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Lang632192d2013-10-04 13:40:46 -0400837 map.insert(InternalFormatInfoPair(GL_RED_EXT, InternalFormatInfo::UnsizedFormat(GL_RED_EXT, CheckSupport<&Context::supportsRGTextures>)));
838 map.insert(InternalFormatInfoPair(GL_RG_EXT, InternalFormatInfo::UnsizedFormat(GL_RG_EXT, CheckSupport<&Context::supportsRGTextures>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
840 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
841 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
842 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported)));
843 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported)));
844
845 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langb2f3d052013-08-13 12:49:27 -0400846 // | Internal format | | L | A | Format | Type | Component type | Supported |
847 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
848 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
849 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
850 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
851 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
852 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, AlwaysSupported)));
853 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
854 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
855 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 +0000856
857 // From GL_EXT_texture_compression_dxt1
Geoff Langb2f3d052013-08-13 12:49:27 -0400858 // | Internal format | |W |H | BS |CC|Format | Type | SRGB | Supported |
859 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>)));
860 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 +0000861
862 // From GL_ANGLE_texture_compression_dxt3
Geoff Langb2f3d052013-08-13 12:49:27 -0400863 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 +0000864
865 // From GL_ANGLE_texture_compression_dxt5
Geoff Langb2f3d052013-08-13 12:49:27 -0400866 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 +0000867
868 return map;
869}
870
Geoff Lang005df412013-10-16 14:12:50 -0400871static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000872{
873 const InternalFormatInfoMap* map = NULL;
874
875 if (clientVersion == 2)
876 {
Geoff Lang18591b72013-06-07 12:00:15 -0400877 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000878 map = &formatMap;
879 }
880 else if (clientVersion == 3)
881 {
Geoff Lang18591b72013-06-07 12:00:15 -0400882 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000883 map = &formatMap;
884 }
885 else
886 {
887 UNREACHABLE();
888 }
889
890 InternalFormatInfoMap::const_iterator iter = map->find(internalFormat);
891 if (iter != map->end())
892 {
893 if (outFormatInfo)
894 {
895 *outFormatInfo = iter->second;
896 }
897 return true;
898 }
899 else
900 {
901 return false;
902 }
903}
904
905typedef std::set<GLenum> FormatSet;
906
Geoff Lang18591b72013-06-07 12:00:15 -0400907static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000908{
Geoff Langfe28ca02013-06-04 10:10:48 -0400909 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000910
911 FormatSet set;
912
913 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
914 {
915 const FormatTypePair& formatPair = i->first;
916 set.insert(formatPair.first);
917 }
918
919 return set;
920}
921
Geoff Lang18591b72013-06-07 12:00:15 -0400922static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923{
Geoff Lang18591b72013-06-07 12:00:15 -0400924 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000925
926 FormatSet set;
927
928 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
929 {
930 const FormatInfo& formatInfo = *i;
931 set.insert(formatInfo.mFormat);
932 }
933
934 return set;
935}
936
937typedef std::set<GLenum> TypeSet;
938
Geoff Lang18591b72013-06-07 12:00:15 -0400939static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000940{
Geoff Langfe28ca02013-06-04 10:10:48 -0400941 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000942
943 TypeSet set;
944
945 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
946 {
947 const FormatTypePair& formatPair = i->first;
948 set.insert(formatPair.second);
949 }
950
951 return set;
952}
953
Geoff Lang18591b72013-06-07 12:00:15 -0400954static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000955{
Geoff Lang18591b72013-06-07 12:00:15 -0400956 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000957
958 TypeSet set;
959
960 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
961 {
962 const FormatInfo& formatInfo = *i;
963 set.insert(formatInfo.mType);
964 }
965
966 return set;
967}
968
Shannon Woods4d161ba2014-03-17 18:13:30 -0400969struct EffectiveInternalFormatInfo
970{
971 GLenum mEffectiveFormat;
972 GLenum mDestFormat;
973 GLuint mMinRedBits;
974 GLuint mMaxRedBits;
975 GLuint mMinGreenBits;
976 GLuint mMaxGreenBits;
977 GLuint mMinBlueBits;
978 GLuint mMaxBlueBits;
979 GLuint mMinAlphaBits;
980 GLuint mMaxAlphaBits;
981
982 EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits,
983 GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits,
984 GLuint minAlphaBits, GLuint maxAlphaBits)
985 : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits),
986 mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits),
987 mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits),
988 mMaxAlphaBits(maxAlphaBits) {};
989};
990
991typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList;
992
993static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList()
994{
995 EffectiveInternalFormatList list;
996
997 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
998 // linear source buffer component sizes.
999 // | Source channel min/max sizes |
1000 // Effective Internal Format | N/A | R | G | B | A |
1001 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8));
1002 list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0));
1003 list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0));
1004 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0));
1005 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0));
1006 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4));
1007 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1));
1008 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8));
1009 list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2));
1010
1011 return list;
1012}
1013
1014
1015static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList()
1016{
1017 EffectiveInternalFormatList list;
1018
1019 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
1020 // linear source buffer component sizes.
1021 // | Source channel min/max sizes |
1022 // Effective Internal Format | Dest Format | R | G | B | A |
1023 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1024 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX));
1025 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1026 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX));
1027 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX));
1028 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4));
1029 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1));
1030 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8));
1031
1032 return list;
1033}
1034
1035static bool GetEffectiveInternalFormat(const InternalFormatInfo &srcFormat, const InternalFormatInfo &destFormat,
1036 GLuint clientVersion, GLenum *outEffectiveFormat)
1037{
1038 const EffectiveInternalFormatList *list = NULL;
1039 GLenum targetFormat = GL_NONE;
1040
1041 if (gl::IsSizedInternalFormat(destFormat.mFormat, clientVersion))
1042 {
1043 static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList();
1044 list = &sizedList;
1045 }
1046 else
1047 {
1048 static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList();
1049 list = &unsizedList;
1050 targetFormat = destFormat.mFormat;
1051 }
1052
1053 for (size_t curFormat = 0; curFormat < list->size(); ++curFormat)
1054 {
1055 const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat);
1056 if ((formatInfo.mDestFormat == targetFormat) &&
1057 (formatInfo.mMinRedBits <= srcFormat.mRedBits && formatInfo.mMaxRedBits >= srcFormat.mRedBits) &&
1058 (formatInfo.mMinGreenBits <= srcFormat.mGreenBits && formatInfo.mMaxGreenBits >= srcFormat.mGreenBits) &&
1059 (formatInfo.mMinBlueBits <= srcFormat.mBlueBits && formatInfo.mMaxBlueBits >= srcFormat.mBlueBits) &&
1060 (formatInfo.mMinAlphaBits <= srcFormat.mAlphaBits && formatInfo.mMaxAlphaBits >= srcFormat.mAlphaBits))
1061 {
1062 *outEffectiveFormat = formatInfo.mEffectiveFormat;
1063 return true;
1064 }
1065 }
1066
1067 return false;
1068}
1069
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001070struct CopyConversion
1071{
1072 GLenum mTextureFormat;
1073 GLenum mFramebufferFormat;
1074
1075 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
1076 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
1077
1078 bool operator<(const CopyConversion& other) const
1079 {
1080 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
1081 }
1082};
1083
1084typedef std::set<CopyConversion> CopyConversionSet;
1085
Geoff Lang18591b72013-06-07 12:00:15 -04001086static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001087{
1088 CopyConversionSet set;
1089
1090 // From ES 3.0.1 spec, table 3.15
1091 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
1092 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
1093 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
1094 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
1095 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
1096 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
1097 set.insert(CopyConversion(GL_RED, GL_RED));
1098 set.insert(CopyConversion(GL_RED, GL_RG));
1099 set.insert(CopyConversion(GL_RED, GL_RGB));
1100 set.insert(CopyConversion(GL_RED, GL_RGBA));
1101 set.insert(CopyConversion(GL_RG, GL_RG));
1102 set.insert(CopyConversion(GL_RG, GL_RGB));
1103 set.insert(CopyConversion(GL_RG, GL_RGBA));
1104 set.insert(CopyConversion(GL_RGB, GL_RGB));
1105 set.insert(CopyConversion(GL_RGB, GL_RGBA));
1106 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
1107
Jamie Madillb70e5f72013-07-10 16:57:52 -04001108 // Necessary for ANGLE back-buffers
1109 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
1110 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
1111 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
1112 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
1113 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
1114 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
1115 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
1116
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001117 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
1118 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1119 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1120 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1121 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1122 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1123 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1124 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1125 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1126 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1127
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001128 return set;
1129}
1130
Geoff Lang005df412013-10-16 14:12:50 -04001131bool IsValidInternalFormat(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001132{
1133 if (!context)
1134 {
1135 return false;
1136 }
1137
1138 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001139 if (GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001140 {
1141 ASSERT(internalFormatInfo.mSupportFunction != NULL);
1142 return internalFormatInfo.mSupportFunction(context);
1143 }
1144 else
1145 {
1146 return false;
1147 }
1148}
1149
1150bool IsValidFormat(GLenum format, GLuint clientVersion)
1151{
1152 if (clientVersion == 2)
1153 {
Geoff Lang18591b72013-06-07 12:00:15 -04001154 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001155 return formatSet.find(format) != formatSet.end();
1156 }
1157 else if (clientVersion == 3)
1158 {
Geoff Lang18591b72013-06-07 12:00:15 -04001159 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001160 return formatSet.find(format) != formatSet.end();
1161 }
1162 else
1163 {
1164 UNREACHABLE();
1165 return false;
1166 }
1167}
1168
1169bool IsValidType(GLenum type, GLuint clientVersion)
1170{
1171 if (clientVersion == 2)
1172 {
Geoff Lang18591b72013-06-07 12:00:15 -04001173 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001174 return typeSet.find(type) != typeSet.end();
1175 }
1176 else if (clientVersion == 3)
1177 {
Geoff Lang18591b72013-06-07 12:00:15 -04001178 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001179 return typeSet.find(type) != typeSet.end();
1180 }
1181 else
1182 {
1183 UNREACHABLE();
1184 return false;
1185 }
1186}
1187
Geoff Lang005df412013-10-16 14:12:50 -04001188bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001189{
1190 if (clientVersion == 2)
1191 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001192 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001193 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1194
Geoff Langfe28ca02013-06-04 10:10:48 -04001195 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001196 }
1197 else if (clientVersion == 3)
1198 {
Geoff Lang18591b72013-06-07 12:00:15 -04001199 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001200 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1201 }
1202 else
1203 {
1204 UNREACHABLE();
1205 return false;
1206 }
1207}
1208
Shannon Woods4d161ba2014-03-17 18:13:30 -04001209bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001210{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001211 InternalFormatInfo textureInternalFormatInfo;
1212 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001213 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1214 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001215 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001216 if (clientVersion == 2)
1217 {
1218 UNIMPLEMENTED();
1219 return false;
1220 }
1221 else if (clientVersion == 3)
1222 {
Geoff Lang18591b72013-06-07 12:00:15 -04001223 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001224 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1225 framebufferInternalFormatInfo.mFormat);
1226 if (conversionSet.find(conversion) != conversionSet.end())
1227 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001228 // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats
1229 // must both be signed, unsigned, or fixed point and both source and destinations
1230 // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed
1231 // conversion between fixed and floating point.
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001232
Geoff Langb2f3d052013-08-13 12:49:27 -04001233 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001234 {
1235 return false;
1236 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001237
Shannon Woods4d161ba2014-03-17 18:13:30 -04001238 if (((textureInternalFormatInfo.mComponentType == GL_INT) != (framebufferInternalFormatInfo.mComponentType == GL_INT)) ||
1239 ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT)))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001240 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001241 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001242 }
1243
Shannon Woods4d161ba2014-03-17 18:13:30 -04001244 if (gl::IsFloatOrFixedComponentType(textureInternalFormatInfo.mComponentType) &&
1245 !gl::IsFloatOrFixedComponentType(framebufferInternalFormatInfo.mComponentType))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001246 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001247 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001248 }
Shannon Woods4d161ba2014-03-17 18:13:30 -04001249
1250 // GLES specification 3.0.3, sec 3.8.5, pg 139-140:
1251 // The effective internal format of the source buffer is determined with the following rules applied in order:
1252 // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the
1253 // effective internal format is the source buffer's sized internal format.
1254 // * If the source buffer is a texture that was created with an unsized base internal format, then the
1255 // effective internal format is the source image array's effective internal format, as specified by table
1256 // 3.12, which is determined from the <format> and <type> that were used when the source image array was
1257 // specified by TexImage*.
1258 // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where
1259 // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent
1260 // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the
1261 // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING
1262 // is SRGB.
1263 InternalFormatInfo sourceEffectiveFormat;
1264 if (readBufferHandle != 0)
1265 {
1266 // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer
1267 if (gl::IsSizedInternalFormat(framebufferInternalFormatInfo.mFormat, clientVersion))
1268 {
1269 sourceEffectiveFormat = framebufferInternalFormatInfo;
1270 }
1271 else
1272 {
1273 // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format
1274 // texture. We can use the same table we use when creating textures to get its effective sized format.
1275 GLenum effectiveFormat = gl::GetSizedInternalFormat(framebufferInternalFormatInfo.mFormat,
1276 framebufferInternalFormatInfo.mType, clientVersion);
1277 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1278 }
1279 }
1280 else
1281 {
1282 // The effective internal format must be derived from the source framebuffer's channel sizes.
1283 // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17)
1284 if (framebufferInternalFormatInfo.mColorEncoding == GL_LINEAR)
1285 {
1286 GLenum effectiveFormat;
1287 if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, clientVersion, &effectiveFormat))
1288 {
1289 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1290 }
1291 else
1292 {
1293 return false;
1294 }
1295 }
1296 else if (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB)
1297 {
1298 // SRGB buffers can only be copied to sized format destinations according to table 3.18
1299 if (gl::IsSizedInternalFormat(textureInternalFormat, clientVersion) &&
1300 (framebufferInternalFormatInfo.mRedBits >= 1 && framebufferInternalFormatInfo.mRedBits <= 8) &&
1301 (framebufferInternalFormatInfo.mGreenBits >= 1 && framebufferInternalFormatInfo.mGreenBits <= 8) &&
1302 (framebufferInternalFormatInfo.mBlueBits >= 1 && framebufferInternalFormatInfo.mBlueBits <= 8) &&
1303 (framebufferInternalFormatInfo.mAlphaBits >= 1 && framebufferInternalFormatInfo.mAlphaBits <= 8))
1304 {
1305 gl::GetInternalFormatInfo(GL_SRGB8_ALPHA8, clientVersion, &sourceEffectiveFormat);
1306 }
1307 else
1308 {
1309 return false;
1310 }
1311 }
1312 else
1313 {
1314 UNREACHABLE();
1315 }
1316 }
1317
1318 if (gl::IsSizedInternalFormat(textureInternalFormatInfo.mFormat, clientVersion))
1319 {
1320 // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized,
1321 // component sizes of the source and destination formats must exactly match
1322 if (textureInternalFormatInfo.mRedBits != sourceEffectiveFormat.mRedBits ||
1323 textureInternalFormatInfo.mGreenBits != sourceEffectiveFormat.mGreenBits ||
1324 textureInternalFormatInfo.mBlueBits != sourceEffectiveFormat.mBlueBits ||
1325 textureInternalFormatInfo.mAlphaBits != sourceEffectiveFormat.mAlphaBits)
1326 {
1327 return false;
1328 }
1329 }
1330
1331
1332 return true; // A conversion function exists, and no rule in the specification has precluded conversion
1333 // between these formats.
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001334 }
1335
1336 return false;
1337 }
1338 else
1339 {
1340 UNREACHABLE();
1341 return false;
1342 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001343 }
1344 else
1345 {
1346 UNREACHABLE();
1347 return false;
1348 }
1349}
1350
Geoff Lang005df412013-10-16 14:12:50 -04001351bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001352{
1353 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001354 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001355 {
1356 return internalFormatInfo.mPixelBits > 0;
1357 }
1358 else
1359 {
1360 UNREACHABLE();
1361 return false;
1362 }
1363}
1364
Geoff Lang005df412013-10-16 14:12:50 -04001365GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001366{
Geoff Langfe28ca02013-06-04 10:10:48 -04001367 const FormatMap &formats = GetFormatMap(clientVersion);
1368 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1369 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001370}
1371
Geoff Lang005df412013-10-16 14:12:50 -04001372GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001373{
1374 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001375 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001376 {
1377 return internalFormatInfo.mPixelBits / 8;
1378 }
1379 else
1380 {
1381 UNREACHABLE();
1382 return 0;
1383 }
1384}
1385
Geoff Lang005df412013-10-16 14:12:50 -04001386GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001387{
1388 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001389 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001390 {
1391 return internalFormatInfo.mAlphaBits;
1392 }
1393 else
1394 {
1395 UNREACHABLE();
1396 return 0;
1397 }
1398}
1399
Geoff Lang005df412013-10-16 14:12:50 -04001400GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001401{
1402 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001403 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001404 {
1405 return internalFormatInfo.mRedBits;
1406 }
1407 else
1408 {
1409 UNREACHABLE();
1410 return 0;
1411 }
1412}
1413
Geoff Lang005df412013-10-16 14:12:50 -04001414GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001415{
1416 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001417 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001418 {
1419 return internalFormatInfo.mGreenBits;
1420 }
1421 else
1422 {
1423 UNREACHABLE();
1424 return 0;
1425 }
1426}
1427
Geoff Lang005df412013-10-16 14:12:50 -04001428GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001429{
1430 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001431 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001432 {
Geoff Lang24159222013-06-05 14:56:32 -04001433 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001434 }
1435 else
1436 {
1437 UNREACHABLE();
1438 return 0;
1439 }
1440}
1441
Geoff Lang005df412013-10-16 14:12:50 -04001442GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001443{
1444 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001445 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001446 {
1447 return internalFormatInfo.mLuminanceBits;
1448 }
1449 else
1450 {
1451 UNREACHABLE();
1452 return 0;
1453 }
1454}
1455
Geoff Lang005df412013-10-16 14:12:50 -04001456GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001457{
1458 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001459 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001460 {
1461 return internalFormatInfo.mDepthBits;
1462 }
1463 else
1464 {
1465 UNREACHABLE();
1466 return 0;
1467 }
1468}
1469
Geoff Lang005df412013-10-16 14:12:50 -04001470GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001471{
1472 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001473 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001474 {
1475 return internalFormatInfo.mStencilBits;
1476 }
1477 else
1478 {
1479 UNREACHABLE();
1480 return 0;
1481 }
1482}
1483
Geoff Langf23eb282013-07-22 10:52:19 -04001484GLuint GetTypeBytes(GLenum type)
1485{
1486 TypeInfo typeInfo;
1487 if (GetTypeInfo(type, &typeInfo))
1488 {
1489 return typeInfo.mTypeBytes;
1490 }
1491 else
1492 {
1493 UNREACHABLE();
1494 return 0;
1495 }
1496}
1497
1498bool IsSpecialInterpretationType(GLenum type)
1499{
1500 TypeInfo typeInfo;
1501 if (GetTypeInfo(type, &typeInfo))
1502 {
1503 return typeInfo.mSpecialInterpretation;
1504 }
1505 else
1506 {
1507 UNREACHABLE();
1508 return false;
1509 }
1510}
1511
Shannon Woods4d161ba2014-03-17 18:13:30 -04001512bool IsFloatOrFixedComponentType(GLenum type)
1513{
1514 if (type == GL_UNSIGNED_NORMALIZED ||
1515 type == GL_SIGNED_NORMALIZED ||
1516 type == GL_FLOAT)
1517 {
1518 return true;
1519 }
1520 else
1521 {
1522 return false;
1523 }
1524}
1525
Geoff Lang005df412013-10-16 14:12:50 -04001526GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001527{
1528 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001529 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001530 {
1531 return internalFormatInfo.mFormat;
1532 }
1533 else
1534 {
1535 UNREACHABLE();
1536 return GL_NONE;
1537 }
1538}
1539
Geoff Lang005df412013-10-16 14:12:50 -04001540GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001541{
1542 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001543 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001544 {
1545 return internalFormatInfo.mType;
1546 }
1547 else
1548 {
1549 UNREACHABLE();
1550 return GL_NONE;
1551 }
1552}
1553
Nicolas Capens0027fa92014-02-20 14:26:42 -05001554GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001555{
1556 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001557 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001558 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001559 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001560 }
1561 else
1562 {
1563 UNREACHABLE();
Nicolas Capens0027fa92014-02-20 14:26:42 -05001564 return GL_NONE;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001565 }
1566}
1567
Geoff Lang005df412013-10-16 14:12:50 -04001568GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001569{
1570 InternalFormatInfo internalFormatInfo;
1571 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1572 {
1573 return internalFormatInfo.mComponentCount;
1574 }
1575 else
1576 {
1577 UNREACHABLE();
1578 return false;
1579 }
1580}
1581
Geoff Lang005df412013-10-16 14:12:50 -04001582GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001583{
1584 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001585 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001586 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001587 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001588 }
1589 else
1590 {
1591 UNREACHABLE();
1592 return false;
1593 }
1594}
1595
Geoff Lang005df412013-10-16 14:12:50 -04001596bool IsColorRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001597{
1598 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001599 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001600 {
1601 return internalFormatInfo.mIsColorRenderable(NULL, renderer);
1602 }
1603 else
1604 {
1605 UNREACHABLE();
1606 return false;
1607 }
1608}
1609
Geoff Lang005df412013-10-16 14:12:50 -04001610bool IsColorRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001611{
1612 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001613 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001614 {
1615 return internalFormatInfo.mIsColorRenderable(context, NULL);
1616 }
1617 else
1618 {
1619 UNREACHABLE();
1620 return false;
1621 }
1622}
1623
Geoff Lang005df412013-10-16 14:12:50 -04001624bool IsTextureFilteringSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001625{
1626 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001627 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001628 {
1629 return internalFormatInfo.mIsTextureFilterable(NULL, renderer);
1630 }
1631 else
1632 {
1633 UNREACHABLE();
1634 return false;
1635 }
1636}
1637
Geoff Lang005df412013-10-16 14:12:50 -04001638bool IsTextureFilteringSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001639{
1640 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001641 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001642 {
1643 return internalFormatInfo.mIsTextureFilterable(context, NULL);
1644 }
1645 else
1646 {
1647 UNREACHABLE();
1648 return false;
1649 }
1650}
1651
Geoff Lang005df412013-10-16 14:12:50 -04001652bool IsDepthRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001653{
1654 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001655 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001656 {
1657 return internalFormatInfo.mIsDepthRenderable(NULL, renderer);
1658 }
1659 else
1660 {
1661 UNREACHABLE();
1662 return false;
1663 }
1664}
1665
Geoff Lang005df412013-10-16 14:12:50 -04001666bool IsDepthRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001667{
1668 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001669 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001670 {
1671 return internalFormatInfo.mIsDepthRenderable(context, NULL);
1672 }
1673 else
1674 {
1675 UNREACHABLE();
1676 return false;
1677 }
1678}
1679
Geoff Lang005df412013-10-16 14:12:50 -04001680bool IsStencilRenderingSupported(GLenum internalFormat, const rx::Renderer *renderer)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001681{
1682 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001683 if (renderer && GetInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001684 {
1685 return internalFormatInfo.mIsStencilRenderable(NULL, renderer);
1686 }
1687 else
1688 {
1689 UNREACHABLE();
1690 return false;
1691 }
1692}
1693
Geoff Lang005df412013-10-16 14:12:50 -04001694bool IsStencilRenderingSupported(GLenum internalFormat, const Context *context)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001695{
1696 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001697 if (context && GetInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001698 {
1699 return internalFormatInfo.mIsStencilRenderable(context, NULL);
1700 }
1701 else
1702 {
1703 UNREACHABLE();
1704 return false;
1705 }
1706}
1707
Geoff Lang005df412013-10-16 14:12:50 -04001708GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001709{
1710 ASSERT(alignment > 0 && isPow2(alignment));
1711 return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1);
1712}
1713
Geoff Lang005df412013-10-16 14:12:50 -04001714GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001715{
Jamie Madill666e2862013-09-10 12:04:29 -04001716 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001717}
1718
Geoff Lang005df412013-10-16 14:12:50 -04001719GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001720{
1721 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001722 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001723 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001724 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001725 {
1726 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1727 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1728
1729 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1730 }
1731 else
1732 {
1733 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001734 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001735 {
1736 if (typeInfo.mSpecialInterpretation)
1737 {
1738 return typeInfo.mTypeBytes * width * height;
1739 }
1740 else
1741 {
1742 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1743 }
1744 }
1745 else
1746 {
1747 UNREACHABLE();
1748 return 0;
1749 }
1750 }
1751 }
1752 else
1753 {
1754 UNREACHABLE();
1755 return 0;
1756 }
1757}
1758
Geoff Lang005df412013-10-16 14:12:50 -04001759bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001760{
1761 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001762 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001763 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001764 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001765 }
1766 else
1767 {
1768 UNREACHABLE();
1769 return false;
1770 }
1771}
1772
Geoff Lang005df412013-10-16 14:12:50 -04001773GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001774{
1775 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001776 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001777 {
1778 return internalFormatInfo.mCompressedBlockWidth;
1779 }
1780 else
1781 {
1782 UNREACHABLE();
1783 return 0;
1784 }
1785}
1786
Geoff Lang005df412013-10-16 14:12:50 -04001787GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001788{
1789 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001790 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001791 {
1792 return internalFormatInfo.mCompressedBlockHeight;
1793 }
1794 else
1795 {
1796 UNREACHABLE();
1797 return 0;
1798 }
1799}
1800
Geoff Langfe28ca02013-06-04 10:10:48 -04001801ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1802{
1803 static const FormatMap &formats = GetFormatMap(clientVersion);
1804 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1805 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1806}
1807
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001808}