blob: ed6e05f11c6c3079b33703967288f4043c0f9659 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00004// 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 Lang05b05022014-06-11 15:31:45 -040083 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8, WriteColor<R8G8B8, GLfloat> );
84 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8, WriteColor<R8G8B8A8, GLfloat> );
85
Geoff Langfe28ca02013-06-04 10:10:48 -040086 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
87 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
88 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 +000089
Geoff Langfe28ca02013-06-04 10:10:48 -040090 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL );
91 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL );
92 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL );
93 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 +000094
Geoff Langfe28ca02013-06-04 10:10:48 -040095 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
96 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES, NULL );
97
Geoff Langcec35902014-04-16 10:52:36 -040098 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8, NULL );
99
Geoff Langfe28ca02013-06-04 10:10:48 -0400100 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 +0000101
102 return map;
103}
104
Geoff Lang18591b72013-06-07 12:00:15 -0400105FormatMap BuildES3FormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000106{
107 FormatMap map;
108
Geoff Langfe28ca02013-06-04 10:10:48 -0400109 using namespace rx;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000110
Geoff Langfe28ca02013-06-04 10:10:48 -0400111 // | Format | Type | Internal format | Color write function |
112 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8, WriteColor<R8G8B8A8, GLfloat> );
113 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM, WriteColor<R8G8B8A8S, GLfloat> );
114 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4, WriteColor<R4G4B4A4, GLfloat> );
115 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1, WriteColor<R5G5B5A1, GLfloat> );
116 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2, WriteColor<R10G10B10A2, GLfloat> );
117 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F, WriteColor<R32G32B32A32F, GLfloat>);
118 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F, WriteColor<R16G16B16A16F, GLfloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000119
Geoff Langfe28ca02013-06-04 10:10:48 -0400120 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI, WriteColor<R8G8B8A8, GLuint> );
121 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I, WriteColor<R8G8B8A8S, GLint> );
122 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI, WriteColor<R16G16B16A16, GLuint> );
123 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I, WriteColor<R16G16B16A16S, GLint> );
124 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI, WriteColor<R32G32B32A32, GLuint> );
125 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I, WriteColor<R32G32B32A32S, GLint> );
Jamie Madill18a44702013-09-09 16:24:04 -0400126 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 +0000127
Geoff Langfe28ca02013-06-04 10:10:48 -0400128 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8, WriteColor<R8G8B8, GLfloat> );
129 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM, WriteColor<R8G8B8S, GLfloat> );
130 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565, WriteColor<R5G6B5, GLfloat> );
131 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F, WriteColor<R11G11B10F, GLfloat> );
132 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5, WriteColor<R9G9B9E5, GLfloat> );
133 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F, WriteColor<R32G32B32F, GLfloat> );
134 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F, WriteColor<R16G16B16F, GLfloat> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000135
Geoff Langfe28ca02013-06-04 10:10:48 -0400136 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI, WriteColor<R8G8B8, GLuint> );
137 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I, WriteColor<R8G8B8S, GLint> );
138 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI, WriteColor<R16G16B16, GLuint> );
139 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I, WriteColor<R16G16B16S, GLint> );
140 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI, WriteColor<R32G32B32, GLuint> );
141 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I, WriteColor<R32G32B32S, GLint> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000142
Geoff Langfe28ca02013-06-04 10:10:48 -0400143 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8, WriteColor<R8G8, GLfloat> );
144 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM, WriteColor<R8G8S, GLfloat> );
145 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F, WriteColor<R32G32F, GLfloat> );
146 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F, WriteColor<R16G16F, GLfloat> );
147
148 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI, WriteColor<R8G8, GLuint> );
149 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I, WriteColor<R8G8S, GLint> );
150 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI, WriteColor<R16G16, GLuint> );
151 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I, WriteColor<R16G16S, GLint> );
152 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI, WriteColor<R32G32, GLuint> );
153 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I, WriteColor<R32G32S, GLint> );
154
155 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8, WriteColor<R8, GLfloat> );
156 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM, WriteColor<R8S, GLfloat> );
157 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F, WriteColor<R32F, GLfloat> );
158 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F, WriteColor<R16F, GLfloat> );
159
160 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI, WriteColor<R8, GLuint> );
161 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I, WriteColor<R8S, GLint> );
162 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI, WriteColor<R16, GLuint> );
163 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I, WriteColor<R16S, GLint> );
164 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI, WriteColor<R32, GLuint> );
165 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I, WriteColor<R32S, GLint> );
166
167 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT, WriteColor<L8A8, GLfloat> );
168 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT, WriteColor<L8, GLfloat> );
169 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT, WriteColor<A8, GLfloat> );
170 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT, WriteColor<L32A32F, GLfloat> );
171 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT, WriteColor<L32F, GLfloat> );
172 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT, WriteColor<A32F, GLfloat> );
173 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT, WriteColor<L16A16F, GLfloat> );
174 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT, WriteColor<L16F, GLfloat> );
175 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT, WriteColor<A16F, GLfloat> );
176
177 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT, WriteColor<B8G8R8A8, GLfloat> );
178 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX, WriteColor<B4G4R4A4, GLfloat> );
179 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX, WriteColor<B5G5R5A1, GLfloat> );
180
Geoff Lang05b05022014-06-11 15:31:45 -0400181 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8, WriteColor<R8G8B8, GLfloat> );
182 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8, WriteColor<R8G8B8A8, GLfloat> );
183
Geoff Langcec35902014-04-16 10:52:36 -0400184 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, NULL );
185 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL );
186 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL );
187 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL );
188
Geoff Langfe28ca02013-06-04 10:10:48 -0400189 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16, NULL );
190 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24, NULL );
191 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F, NULL );
192
193 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8, NULL );
194 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 +0000195
196 return map;
197}
198
Geoff Langfe28ca02013-06-04 10:10:48 -0400199static const FormatMap &GetFormatMap(GLuint clientVersion)
200{
201 if (clientVersion == 2)
202 {
203 static const FormatMap formats = BuildES2FormatMap();
204 return formats;
205 }
206 else if (clientVersion == 3)
207 {
208 static const FormatMap formats = BuildES3FormatMap();
209 return formats;
210 }
211 else
212 {
213 UNREACHABLE();
214 static FormatMap emptyMap;
215 return emptyMap;
216 }
217}
218
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000219struct FormatInfo
220{
Geoff Lang005df412013-10-16 14:12:50 -0400221 GLenum mInternalformat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000222 GLenum mFormat;
223 GLenum mType;
224
Geoff Lang005df412013-10-16 14:12:50 -0400225 FormatInfo(GLenum internalformat, GLenum format, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000226 : mInternalformat(internalformat), mFormat(format), mType(type) { }
227
228 bool operator<(const FormatInfo& other) const
229 {
230 return memcmp(this, &other, sizeof(FormatInfo)) < 0;
231 }
232};
233
234// ES3 has a specific set of permutations of internal formats, formats and types which are acceptable.
235typedef std::set<FormatInfo> ES3FormatSet;
236
Geoff Lang18591b72013-06-07 12:00:15 -0400237ES3FormatSet BuildES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000238{
239 ES3FormatSet set;
240
241 // Format combinations from ES 3.0.1 spec, table 3.2
242
243 // | Internal format | Format | Type |
244 // | | | |
245 set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ));
246 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ));
247 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ));
248 set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ));
249 set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ));
250 set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
251 set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
252 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ));
shannonwoods@chromium.orgd03f8972013-05-30 00:17:07 +0000253 set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000254 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ));
255 set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT ));
256 set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT ));
257 set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ));
258 set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ));
259 set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ));
260 set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ));
261 set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ));
262 set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ));
263 set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ));
264 set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ));
265 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ));
266 set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ));
267 set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE ));
268 set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
269 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ));
270 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ));
271 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT ));
272 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ));
273 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ));
274 set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT ));
275 set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT ));
276 set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ));
277 set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT ));
278 set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ));
279 set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ));
280 set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ));
281 set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ));
282 set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ));
283 set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT ));
284 set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE ));
285 set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE ));
286 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT ));
287 set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT ));
288 set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT ));
289 set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ));
290 set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE ));
291 set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ));
292 set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT ));
293 set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ));
294 set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT ));
295 set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE ));
296 set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE ));
297 set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT ));
298 set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT ));
299 set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT ));
300 set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ));
301 set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE ));
302 set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ));
303 set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT ));
304 set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ));
305 set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT ));
306
307 // Unsized formats
308 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ));
309 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ));
310 set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ));
311 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ));
312 set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ));
313 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
314 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
315 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ));
Geoff Lang05b05022014-06-11 15:31:45 -0400316 set.insert(FormatInfo(GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ));
317 set.insert(FormatInfo(GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE ));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000318
319 // Depth stencil formats
320 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ));
321 set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
322 set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ));
323 set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ));
324 set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ));
325 set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV));
326
Geoff Lang05b05022014-06-11 15:31:45 -0400327 // From GL_EXT_sRGB
328 set.insert(FormatInfo(GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ));
329 set.insert(FormatInfo(GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE ));
330
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000331 // From GL_OES_texture_float
332 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ));
333 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ));
334 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT ));
335
336 // From GL_OES_texture_half_float
337 set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
338 set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ));
339 set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ));
340
Geoff Langcdacacd2014-04-24 12:01:56 -0400341 // From GL_EXT_texture_format_BGRA8888
342 set.insert(FormatInfo(GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
343
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000344 // From GL_EXT_texture_storage
345 // | Internal format | Format | Type |
346 // | | | |
347 set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ));
348 set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ));
349 set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ));
350 set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ));
351 set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ));
352 set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ));
353 set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ));
354 set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ));
355 set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ));
356
Geoff Langcdacacd2014-04-24 12:01:56 -0400357 // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000358 set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
359 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT));
360 set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
361 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT));
362 set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ));
363
364 // From GL_ANGLE_depth_texture
365 set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ));
366
367 // Compressed formats
368 // From ES 3.0.1 spec, table 3.16
369 // | Internal format | Format | Type |
370 // | | | |
371 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
372 set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE));
373 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE));
374 set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE));
375 set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE));
376 set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE));
377 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE));
378 set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
379 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE));
380 set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE));
381 set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE));
382
383
384 // From GL_EXT_texture_compression_dxt1
385 set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
386 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE));
387
388 // From GL_ANGLE_texture_compression_dxt3
389 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE));
390
391 // From GL_ANGLE_texture_compression_dxt5
392 set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE));
393
394 return set;
395}
396
Geoff Lang18591b72013-06-07 12:00:15 -0400397static const ES3FormatSet &GetES3FormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000398{
Geoff Lang18591b72013-06-07 12:00:15 -0400399 static const ES3FormatSet es3FormatSet = BuildES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000400 return es3FormatSet;
401}
402
403// Map of sizes of input types
404struct TypeInfo
405{
406 GLuint mTypeBytes;
407 bool mSpecialInterpretation;
408
409 TypeInfo()
410 : mTypeBytes(0), mSpecialInterpretation(false) { }
411
412 TypeInfo(GLuint typeBytes, bool specialInterpretation)
413 : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { }
414
415 bool operator<(const TypeInfo& other) const
416 {
417 return memcmp(this, &other, sizeof(TypeInfo)) < 0;
418 }
419};
420
421typedef std::pair<GLenum, TypeInfo> TypeInfoPair;
422typedef std::map<GLenum, TypeInfo> TypeInfoMap;
423
Geoff Lang18591b72013-06-07 12:00:15 -0400424static TypeInfoMap BuildTypeInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000425{
426 TypeInfoMap map;
427
428 map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false)));
429 map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false)));
430 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false)));
431 map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false)));
432 map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false)));
433 map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false)));
434 map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false)));
Jamie Madilla940ae42013-07-08 17:48:34 -0400435 map.insert(TypeInfoPair(GL_HALF_FLOAT_OES, TypeInfo( 2, false)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000436 map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false)));
437 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true )));
438 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true )));
439 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true )));
440 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true )));
441 map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true )));
442 map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true )));
443 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true )));
444 map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true )));
445 map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000446 map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true )));
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400447 map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 8, true )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000448
449 return map;
450}
451
Geoff Lang18591b72013-06-07 12:00:15 -0400452static bool GetTypeInfo(GLenum type, TypeInfo *outTypeInfo)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000453{
Geoff Lang18591b72013-06-07 12:00:15 -0400454 static const TypeInfoMap infoMap = BuildTypeInfoMap();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000455 TypeInfoMap::const_iterator iter = infoMap.find(type);
456 if (iter != infoMap.end())
457 {
458 if (outTypeInfo)
459 {
460 *outTypeInfo = iter->second;
461 }
462 return true;
463 }
464 else
465 {
466 return false;
467 }
468}
469
470// Information about internal formats
Geoff Langcec35902014-04-16 10:52:36 -0400471typedef bool (*SupportCheckFunction)(const Extensions &);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000472
Geoff Langcec35902014-04-16 10:52:36 -0400473static bool AlwaysSupported(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000474{
475 return true;
476}
477
Geoff Langcec35902014-04-16 10:52:36 -0400478static bool UnimplementedSupport(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000479{
480 UNIMPLEMENTED();
481 return false;
482}
483
Geoff Langcec35902014-04-16 10:52:36 -0400484static bool NeverSupported(const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000485{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000486 return false;
487}
488
Geoff Langcec35902014-04-16 10:52:36 -0400489// Pointer to a boolean memeber of the Extensions struct
490typedef bool(Extensions::*ExtensionBool);
491
492// Check support for a single extension
493template <ExtensionBool bool1>
494static bool CheckSupport(const Extensions &caps)
495{
496 return (caps.*bool1);
497}
498
499// Check support for two extensions
500template <ExtensionBool bool1, ExtensionBool bool2>
501static bool CheckSupport(const Extensions &caps)
502{
503 return (caps.*bool1) && (caps.*bool2);
504}
505
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000506struct InternalFormatInfo
507{
508 GLuint mRedBits;
509 GLuint mGreenBits;
510 GLuint mBlueBits;
511
512 GLuint mLuminanceBits;
513
514 GLuint mAlphaBits;
515 GLuint mSharedBits;
516
517 GLuint mDepthBits;
518 GLuint mStencilBits;
519
520 GLuint mPixelBits;
521
522 GLuint mComponentCount;
523
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000524 GLuint mCompressedBlockWidth;
525 GLuint mCompressedBlockHeight;
526
527 GLenum mFormat;
528 GLenum mType;
529
Geoff Langb2f3d052013-08-13 12:49:27 -0400530 GLenum mComponentType;
531 GLenum mColorEncoding;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +0000532
Geoff Langb2f3d052013-08-13 12:49:27 -0400533 bool mIsCompressed;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +0000534
Geoff Langcec35902014-04-16 10:52:36 -0400535 SupportCheckFunction mSupportFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000536
537 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 +0000538 mPixelBits(0), mComponentCount(0), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE),
Geoff Langcec35902014-04-16 10:52:36 -0400539 mComponentType(GL_NONE), mColorEncoding(GL_NONE), mIsCompressed(false), mSupportFunction(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000540 {
541 }
542
Geoff Langcec35902014-04-16 10:52:36 -0400543 static InternalFormatInfo UnsizedFormat(GLenum format, SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000544 {
545 InternalFormatInfo formatInfo;
546 formatInfo.mFormat = format;
547 formatInfo.mSupportFunction = supportFunction;
548 return formatInfo;
549 }
550
551 static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
Geoff Langb2f3d052013-08-13 12:49:27 -0400552 GLenum format, GLenum type, GLenum componentType, bool srgb,
Geoff Langcec35902014-04-16 10:52:36 -0400553 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000554 {
555 InternalFormatInfo formatInfo;
556 formatInfo.mRedBits = red;
557 formatInfo.mGreenBits = green;
558 formatInfo.mBlueBits = blue;
559 formatInfo.mAlphaBits = alpha;
560 formatInfo.mSharedBits = shared;
561 formatInfo.mPixelBits = red + green + blue + alpha + shared;
562 formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
563 formatInfo.mFormat = format;
564 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400565 formatInfo.mComponentType = componentType;
566 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000567 formatInfo.mSupportFunction = supportFunction;
568 return formatInfo;
569 }
570
Geoff Langb2f3d052013-08-13 12:49:27 -0400571 static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
Geoff Langcec35902014-04-16 10:52:36 -0400572 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000573 {
574 InternalFormatInfo formatInfo;
575 formatInfo.mLuminanceBits = luminance;
576 formatInfo.mAlphaBits = alpha;
577 formatInfo.mPixelBits = luminance + alpha;
578 formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
579 formatInfo.mFormat = format;
580 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400581 formatInfo.mComponentType = componentType;
582 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000583 formatInfo.mSupportFunction = supportFunction;
584 return formatInfo;
585 }
586
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400587 static InternalFormatInfo DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
Geoff Langcec35902014-04-16 10:52:36 -0400588 GLenum type, GLenum componentType, SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000589 {
590 InternalFormatInfo formatInfo;
Geoff Lang85ea9ab2013-10-10 13:50:34 -0400591 formatInfo.mDepthBits = depthBits;
592 formatInfo.mStencilBits = stencilBits;
593 formatInfo.mPixelBits = depthBits + stencilBits + unusedBits;
594 formatInfo.mComponentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000595 formatInfo.mFormat = format;
596 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400597 formatInfo.mComponentType = componentType;
598 formatInfo.mColorEncoding = GL_LINEAR;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000599 formatInfo.mSupportFunction = supportFunction;
600 return formatInfo;
601 }
602
Geoff Langb2f3d052013-08-13 12:49:27 -0400603 static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
604 GLuint componentCount, GLenum format, GLenum type, bool srgb,
Geoff Langcec35902014-04-16 10:52:36 -0400605 SupportCheckFunction supportFunction)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000606 {
607 InternalFormatInfo formatInfo;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000608 formatInfo.mCompressedBlockWidth = compressedBlockWidth;
609 formatInfo.mCompressedBlockHeight = compressedBlockHeight;
610 formatInfo.mPixelBits = compressedBlockSize;
611 formatInfo.mComponentCount = componentCount;
612 formatInfo.mFormat = format;
613 formatInfo.mType = type;
Geoff Langb2f3d052013-08-13 12:49:27 -0400614 formatInfo.mComponentType = GL_UNSIGNED_NORMALIZED;
615 formatInfo.mColorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
616 formatInfo.mIsCompressed = true;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000617 formatInfo.mSupportFunction = supportFunction;
618 return formatInfo;
619 }
620};
621
Geoff Lang005df412013-10-16 14:12:50 -0400622typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
623typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624
Geoff Lang18591b72013-06-07 12:00:15 -0400625static InternalFormatInfoMap BuildES3InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000626{
627 InternalFormatInfoMap map;
628
629 // From ES 3.0.1 spec, table 3.12
630 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
631
Geoff Langcec35902014-04-16 10:52:36 -0400632 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Supported |
633 map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported)));
634 map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported)));
635 map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported)));
636 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported)));
637 map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported)));
638 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported)));
639 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)));
640 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)));
641 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)));
642 map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported)));
643 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, AlwaysSupported)));
644 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)));
645 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)));
646 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported)));
647 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, AlwaysSupported)));
648 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)));
649 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, AlwaysSupported)));
650 map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported)));
651 map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported)));
652 map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported)));
653 map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported)));
654 map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, AlwaysSupported)));
655 map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported)));
656 map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported)));
657 map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported)));
658 map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported)));
659 map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported)));
660 map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, AlwaysSupported)));
661 map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported)));
662 map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported)));
663 map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported)));
664 map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported)));
665 map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported)));
666 map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, AlwaysSupported)));
667 map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported)));
668 map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, AlwaysSupported)));
669 map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, AlwaysSupported)));
670 map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, AlwaysSupported)));
671 map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, AlwaysSupported)));
672 map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, AlwaysSupported)));
673 map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000674
Geoff Langcec35902014-04-16 10:52:36 -0400675 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>)));
676 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, CheckSupport<&Extensions::textureFormatBGRA8888>)));
677 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, CheckSupport<&Extensions::textureFormatBGRA8888>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000678
679 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langcec35902014-04-16 10:52:36 -0400680 // | Internal format | | D |S | Format | Type | Comp | SRGB | Supported |
681 // | | | | | | | type | | |
682 map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
683 map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
684 map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
685 map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
686 map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
687 map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
688 map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
689 map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000690
691 // Depth stencil formats
Geoff Langcec35902014-04-16 10:52:36 -0400692 // | Internal format | | D |S | X | Format | Type | Component type | Supported |
693 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
694 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
695 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, AlwaysSupported)));
696 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
697 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, AlwaysSupported)));
698 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)));
699 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000700
701 // Luminance alpha formats
Geoff Langcec35902014-04-16 10:52:36 -0400702 // | Internal format | | L | A | Format | Type | Component type | Supported |
703 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
704 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
705 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
706 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
707 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
708 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
709 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
710 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
711 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000712
713 // Unsized formats
714 // | Internal format | | Format | Supported |
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000715 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported)));
716 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported)));
717 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400718 map.insert(InternalFormatInfoPair(GL_RED, InternalFormatInfo::UnsizedFormat(GL_RED, AlwaysSupported)));
719 map.insert(InternalFormatInfoPair(GL_RG, InternalFormatInfo::UnsizedFormat(GL_RG, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000720 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported)));
721 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported)));
Geoff Langd1e9a9a2013-09-30 15:22:57 -0400722 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RED_INTEGER, AlwaysSupported)));
723 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RG_INTEGER, AlwaysSupported)));
724 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGB_INTEGER, AlwaysSupported)));
725 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, InternalFormatInfo::UnsizedFormat(GL_RGBA_INTEGER, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000726 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported)));
Geoff Lang05b05022014-06-11 15:31:45 -0400727 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, InternalFormatInfo::UnsizedFormat(GL_RGB, CheckSupport<&Extensions::sRGB>)));
728 map.insert(InternalFormatInfoPair(GL_SRGB_ALPHA_EXT, InternalFormatInfo::UnsizedFormat(GL_RGBA, CheckSupport<&Extensions::sRGB>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000729
730 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langb2f3d052013-08-13 12:49:27 -0400731 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
732 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
733 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
734 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
735 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
736 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
737 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport)));
738 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)));
739 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)));
740 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport)));
741 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 +0000742
743 // From GL_EXT_texture_compression_dxt1
Geoff Langcec35902014-04-16 10:52:36 -0400744 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
745 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<&Extensions::textureCompressionDXT1>)));
746 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<&Extensions::textureCompressionDXT1>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000747
748 // From GL_ANGLE_texture_compression_dxt3
Geoff Langcec35902014-04-16 10:52:36 -0400749 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<&Extensions::textureCompressionDXT5>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000750
751 // From GL_ANGLE_texture_compression_dxt5
Geoff Langcec35902014-04-16 10:52:36 -0400752 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<&Extensions::textureCompressionDXT5>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000753
754 return map;
755}
756
Geoff Lang18591b72013-06-07 12:00:15 -0400757static InternalFormatInfoMap BuildES2InternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000758{
759 InternalFormatInfoMap map;
760
761 // From ES 2.0.25 table 4.5
762 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo()));
763
Geoff Langcec35902014-04-16 10:52:36 -0400764 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Supported |
765 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 )));
766 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 )));
767 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 )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000768
769 // Extension formats
Geoff Langcec35902014-04-16 10:52:36 -0400770 map.insert(InternalFormatInfoPair(GL_R8_EXT, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureRG> )));
771 map.insert(InternalFormatInfoPair(GL_RG8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureRG> )));
772 map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::rgb8rgba8> )));
773 map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::rgb8rgba8> )));
774 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, CheckSupport<&Extensions::textureFormatBGRA8888>)));
775 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, CheckSupport<&Extensions::textureFormatBGRA8888>)));
776 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, CheckSupport<&Extensions::textureFormatBGRA8888>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000777
Geoff Lang05b05022014-06-11 15:31:45 -0400778 // From GL_EXT_sRGB
779 map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, CheckSupport<&Extensions::sRGB>)));
780 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, CheckSupport<&Extensions::sRGB>)));
781
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000782 // Floating point formats have to query the renderer for support
Geoff Langcec35902014-04-16 10:52:36 -0400783 // | Internal format | | R | G | B | A |S | Format | Type | Comp | SRGB | Supported |
784 // | | | | | | | | | | type | | |
785 map.insert(InternalFormatInfoPair(GL_R16F_EXT, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat, &Extensions::textureRG>)));
786 map.insert(InternalFormatInfoPair(GL_R32F_EXT, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat, &Extensions::textureRG>)));
787 map.insert(InternalFormatInfoPair(GL_RG16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat, &Extensions::textureRG>)));
788 map.insert(InternalFormatInfoPair(GL_RG32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat, &Extensions::textureRG>)));
789 map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
790 map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
791 map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, CheckSupport<&Extensions::textureHalfFloat> )));
792 map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, CheckSupport<&Extensions::textureFloat> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000793
794 // Depth and stencil formats
Geoff Langcec35902014-04-16 10:52:36 -0400795 // | Internal format | | D |S |X | Format | Type | Internal format | Supported |
796 // | | | | | | | | type | |
797 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::depthTextures>)));
798 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 )));
799 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, AlwaysSupported )));
800 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000801
802 // Unsized formats
Geoff Langcec35902014-04-16 10:52:36 -0400803 // | Internal format | | Format | Supported |
804 map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported )));
805 map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported )));
806 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported )));
807 map.insert(InternalFormatInfoPair(GL_RED_EXT, InternalFormatInfo::UnsizedFormat(GL_RED_EXT, CheckSupport<&Extensions::textureRG> )));
808 map.insert(InternalFormatInfoPair(GL_RG_EXT, InternalFormatInfo::UnsizedFormat(GL_RG_EXT, CheckSupport<&Extensions::textureRG> )));
809 map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported )));
810 map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported )));
811 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, CheckSupport<&Extensions::textureFormatBGRA8888>)));
812 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported )));
813 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, CheckSupport<&Extensions::packedDepthStencil> )));
Geoff Lang05b05022014-06-11 15:31:45 -0400814 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, InternalFormatInfo::UnsizedFormat(GL_RGB, CheckSupport<&Extensions::sRGB> )));
815 map.insert(InternalFormatInfoPair(GL_SRGB_ALPHA_EXT, InternalFormatInfo::UnsizedFormat(GL_RGBA, CheckSupport<&Extensions::sRGB> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000816
817 // Luminance alpha formats from GL_EXT_texture_storage
Geoff Langcec35902014-04-16 10:52:36 -0400818 // | Internal format | | L | A | Format | Type | Component type | Supported |
819 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
820 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
821 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
822 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
823 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
824 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
825 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, CheckSupport<&Extensions::textureStorage> )));
826 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureFloat> )));
827 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, CheckSupport<&Extensions::textureStorage, &Extensions::textureHalfFloat>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000828
829 // From GL_EXT_texture_compression_dxt1
Geoff Langcec35902014-04-16 10:52:36 -0400830 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported |
831 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<&Extensions::textureCompressionDXT1>)));
832 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<&Extensions::textureCompressionDXT1>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000833
834 // From GL_ANGLE_texture_compression_dxt3
Geoff Langcec35902014-04-16 10:52:36 -0400835 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<&Extensions::textureCompressionDXT3>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000836
837 // From GL_ANGLE_texture_compression_dxt5
Geoff Langcec35902014-04-16 10:52:36 -0400838 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<&Extensions::textureCompressionDXT5>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839
840 return map;
841}
842
Geoff Langcec35902014-04-16 10:52:36 -0400843static const InternalFormatInfoMap &GetInternalFormatMap(GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000844{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000845 if (clientVersion == 2)
846 {
Geoff Lang18591b72013-06-07 12:00:15 -0400847 static const InternalFormatInfoMap formatMap = BuildES2InternalFormatInfoMap();
Geoff Langcec35902014-04-16 10:52:36 -0400848 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000849 }
850 else if (clientVersion == 3)
851 {
Geoff Lang18591b72013-06-07 12:00:15 -0400852 static const InternalFormatInfoMap formatMap = BuildES3InternalFormatInfoMap();
Geoff Langcec35902014-04-16 10:52:36 -0400853 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000854 }
855 else
856 {
857 UNREACHABLE();
Geoff Langcec35902014-04-16 10:52:36 -0400858 static const InternalFormatInfoMap emptyFormatMap;
859 return emptyFormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000860 }
Geoff Langcec35902014-04-16 10:52:36 -0400861}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000862
Geoff Langcec35902014-04-16 10:52:36 -0400863static bool GetInternalFormatInfo(GLenum internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo)
864{
865 const InternalFormatInfoMap &map = GetInternalFormatMap(clientVersion);
866 InternalFormatInfoMap::const_iterator iter = map.find(internalFormat);
867 if (iter != map.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000868 {
869 if (outFormatInfo)
870 {
871 *outFormatInfo = iter->second;
872 }
873 return true;
874 }
875 else
876 {
877 return false;
878 }
879}
880
Geoff Langcec35902014-04-16 10:52:36 -0400881static FormatSet BuildAllSizedInternalFormatSet(GLuint clientVersion)
882{
883 FormatSet result;
884
885 const InternalFormatInfoMap &formats = GetInternalFormatMap(clientVersion);
886 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
887 {
888 if (i->second.mPixelBits > 0)
889 {
890 result.insert(i->first);
891 }
892 }
893
894 return result;
895}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000896
Geoff Lang18591b72013-06-07 12:00:15 -0400897static FormatSet BuildES2ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000898{
Geoff Langfe28ca02013-06-04 10:10:48 -0400899 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000900
901 FormatSet set;
902
903 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
904 {
905 const FormatTypePair& formatPair = i->first;
906 set.insert(formatPair.first);
907 }
908
909 return set;
910}
911
Geoff Lang18591b72013-06-07 12:00:15 -0400912static FormatSet BuildES3ValidFormatSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000913{
Geoff Lang18591b72013-06-07 12:00:15 -0400914 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000915
916 FormatSet set;
917
918 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
919 {
920 const FormatInfo& formatInfo = *i;
921 set.insert(formatInfo.mFormat);
922 }
923
924 return set;
925}
926
927typedef std::set<GLenum> TypeSet;
928
Geoff Lang18591b72013-06-07 12:00:15 -0400929static TypeSet BuildES2ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000930{
Geoff Langfe28ca02013-06-04 10:10:48 -0400931 static const FormatMap &formatMap = GetFormatMap(2);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000932
933 TypeSet set;
934
935 for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++)
936 {
937 const FormatTypePair& formatPair = i->first;
938 set.insert(formatPair.second);
939 }
940
941 return set;
942}
943
Geoff Lang18591b72013-06-07 12:00:15 -0400944static TypeSet BuildES3ValidTypeSet()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000945{
Geoff Lang18591b72013-06-07 12:00:15 -0400946 static const ES3FormatSet &formatSet = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000947
948 TypeSet set;
949
950 for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++)
951 {
952 const FormatInfo& formatInfo = *i;
953 set.insert(formatInfo.mType);
954 }
955
956 return set;
957}
958
Shannon Woods4d161ba2014-03-17 18:13:30 -0400959struct EffectiveInternalFormatInfo
960{
961 GLenum mEffectiveFormat;
962 GLenum mDestFormat;
963 GLuint mMinRedBits;
964 GLuint mMaxRedBits;
965 GLuint mMinGreenBits;
966 GLuint mMaxGreenBits;
967 GLuint mMinBlueBits;
968 GLuint mMaxBlueBits;
969 GLuint mMinAlphaBits;
970 GLuint mMaxAlphaBits;
971
972 EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits,
973 GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits,
974 GLuint minAlphaBits, GLuint maxAlphaBits)
975 : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits),
976 mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits),
977 mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits),
978 mMaxAlphaBits(maxAlphaBits) {};
979};
980
981typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList;
982
983static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList()
984{
985 EffectiveInternalFormatList list;
986
987 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
988 // linear source buffer component sizes.
989 // | Source channel min/max sizes |
990 // Effective Internal Format | N/A | R | G | B | A |
991 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8));
992 list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0));
993 list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0));
994 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0));
995 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0));
996 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4));
997 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1));
998 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8));
999 list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2));
1000
1001 return list;
1002}
1003
1004
1005static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList()
1006{
1007 EffectiveInternalFormatList list;
1008
1009 // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
1010 // linear source buffer component sizes.
1011 // | Source channel min/max sizes |
1012 // Effective Internal Format | Dest Format | R | G | B | A |
1013 list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1014 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX));
1015 list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
1016 list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX));
1017 list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX));
1018 list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4));
1019 list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1));
1020 list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8));
1021
1022 return list;
1023}
1024
1025static bool GetEffectiveInternalFormat(const InternalFormatInfo &srcFormat, const InternalFormatInfo &destFormat,
1026 GLuint clientVersion, GLenum *outEffectiveFormat)
1027{
1028 const EffectiveInternalFormatList *list = NULL;
1029 GLenum targetFormat = GL_NONE;
1030
1031 if (gl::IsSizedInternalFormat(destFormat.mFormat, clientVersion))
1032 {
1033 static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList();
1034 list = &sizedList;
1035 }
1036 else
1037 {
1038 static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList();
1039 list = &unsizedList;
1040 targetFormat = destFormat.mFormat;
1041 }
1042
1043 for (size_t curFormat = 0; curFormat < list->size(); ++curFormat)
1044 {
1045 const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat);
1046 if ((formatInfo.mDestFormat == targetFormat) &&
1047 (formatInfo.mMinRedBits <= srcFormat.mRedBits && formatInfo.mMaxRedBits >= srcFormat.mRedBits) &&
1048 (formatInfo.mMinGreenBits <= srcFormat.mGreenBits && formatInfo.mMaxGreenBits >= srcFormat.mGreenBits) &&
1049 (formatInfo.mMinBlueBits <= srcFormat.mBlueBits && formatInfo.mMaxBlueBits >= srcFormat.mBlueBits) &&
1050 (formatInfo.mMinAlphaBits <= srcFormat.mAlphaBits && formatInfo.mMaxAlphaBits >= srcFormat.mAlphaBits))
1051 {
1052 *outEffectiveFormat = formatInfo.mEffectiveFormat;
1053 return true;
1054 }
1055 }
1056
1057 return false;
1058}
1059
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001060struct CopyConversion
1061{
1062 GLenum mTextureFormat;
1063 GLenum mFramebufferFormat;
1064
1065 CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
1066 : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
1067
1068 bool operator<(const CopyConversion& other) const
1069 {
1070 return memcmp(this, &other, sizeof(CopyConversion)) < 0;
1071 }
1072};
1073
1074typedef std::set<CopyConversion> CopyConversionSet;
1075
Geoff Lang18591b72013-06-07 12:00:15 -04001076static CopyConversionSet BuildValidES3CopyTexImageCombinations()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001077{
1078 CopyConversionSet set;
1079
1080 // From ES 3.0.1 spec, table 3.15
1081 set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
1082 set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
1083 set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
1084 set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
1085 set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
1086 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
1087 set.insert(CopyConversion(GL_RED, GL_RED));
1088 set.insert(CopyConversion(GL_RED, GL_RG));
1089 set.insert(CopyConversion(GL_RED, GL_RGB));
1090 set.insert(CopyConversion(GL_RED, GL_RGBA));
1091 set.insert(CopyConversion(GL_RG, GL_RG));
1092 set.insert(CopyConversion(GL_RG, GL_RGB));
1093 set.insert(CopyConversion(GL_RG, GL_RGBA));
1094 set.insert(CopyConversion(GL_RGB, GL_RGB));
1095 set.insert(CopyConversion(GL_RGB, GL_RGBA));
1096 set.insert(CopyConversion(GL_RGBA, GL_RGBA));
1097
Jamie Madillb70e5f72013-07-10 16:57:52 -04001098 // Necessary for ANGLE back-buffers
1099 set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
1100 set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
1101 set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
1102 set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
1103 set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
1104 set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
1105 set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
1106
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001107 set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
1108 set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
1109 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
1110 set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
1111 set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
1112 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
1113 set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
1114 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
1115 set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
1116 set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
1117
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001118 return set;
1119}
1120
Geoff Langcec35902014-04-16 10:52:36 -04001121bool IsValidInternalFormat(GLenum internalFormat, const Extensions &extensions, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001122{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001123 InternalFormatInfo internalFormatInfo;
Geoff Langcec35902014-04-16 10:52:36 -04001124 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001125 {
1126 ASSERT(internalFormatInfo.mSupportFunction != NULL);
Geoff Langcec35902014-04-16 10:52:36 -04001127 return internalFormatInfo.mSupportFunction(extensions);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001128 }
1129 else
1130 {
1131 return false;
1132 }
1133}
1134
1135bool IsValidFormat(GLenum format, GLuint clientVersion)
1136{
1137 if (clientVersion == 2)
1138 {
Geoff Lang18591b72013-06-07 12:00:15 -04001139 static const FormatSet formatSet = BuildES2ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001140 return formatSet.find(format) != formatSet.end();
1141 }
1142 else if (clientVersion == 3)
1143 {
Geoff Lang18591b72013-06-07 12:00:15 -04001144 static const FormatSet formatSet = BuildES3ValidFormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001145 return formatSet.find(format) != formatSet.end();
1146 }
1147 else
1148 {
1149 UNREACHABLE();
1150 return false;
1151 }
1152}
1153
1154bool IsValidType(GLenum type, GLuint clientVersion)
1155{
1156 if (clientVersion == 2)
1157 {
Geoff Lang18591b72013-06-07 12:00:15 -04001158 static const TypeSet typeSet = BuildES2ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001159 return typeSet.find(type) != typeSet.end();
1160 }
1161 else if (clientVersion == 3)
1162 {
Geoff Lang18591b72013-06-07 12:00:15 -04001163 static const TypeSet typeSet = BuildES3ValidTypeSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001164 return typeSet.find(type) != typeSet.end();
1165 }
1166 else
1167 {
1168 UNREACHABLE();
1169 return false;
1170 }
1171}
1172
Geoff Lang005df412013-10-16 14:12:50 -04001173bool IsValidFormatCombination(GLenum internalFormat, GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001174{
1175 if (clientVersion == 2)
1176 {
Geoff Langfe28ca02013-06-04 10:10:48 -04001177 static const FormatMap &formats = GetFormatMap(clientVersion);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001178 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1179
Geoff Langfe28ca02013-06-04 10:10:48 -04001180 return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second.mInternalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001181 }
1182 else if (clientVersion == 3)
1183 {
Geoff Lang18591b72013-06-07 12:00:15 -04001184 static const ES3FormatSet &formats = GetES3FormatSet();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001185 return formats.find(FormatInfo(internalFormat, format, type)) != formats.end();
1186 }
1187 else
1188 {
1189 UNREACHABLE();
1190 return false;
1191 }
1192}
1193
Shannon Woods4d161ba2014-03-17 18:13:30 -04001194bool IsValidCopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001195{
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001196 InternalFormatInfo textureInternalFormatInfo;
1197 InternalFormatInfo framebufferInternalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001198 if (GetInternalFormatInfo(textureInternalFormat, clientVersion, &textureInternalFormatInfo) &&
1199 GetInternalFormatInfo(frameBufferInternalFormat, clientVersion, &framebufferInternalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001200 {
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001201 if (clientVersion == 2)
1202 {
1203 UNIMPLEMENTED();
1204 return false;
1205 }
1206 else if (clientVersion == 3)
1207 {
Geoff Lang18591b72013-06-07 12:00:15 -04001208 static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001209 const CopyConversion conversion = CopyConversion(textureInternalFormatInfo.mFormat,
1210 framebufferInternalFormatInfo.mFormat);
1211 if (conversionSet.find(conversion) != conversionSet.end())
1212 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001213 // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats
1214 // must both be signed, unsigned, or fixed point and both source and destinations
1215 // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed
1216 // conversion between fixed and floating point.
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001217
Geoff Langb2f3d052013-08-13 12:49:27 -04001218 if ((textureInternalFormatInfo.mColorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB))
shannonwoods@chromium.org96c62912013-05-30 00:17:00 +00001219 {
1220 return false;
1221 }
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001222
Shannon Woods4d161ba2014-03-17 18:13:30 -04001223 if (((textureInternalFormatInfo.mComponentType == GL_INT) != (framebufferInternalFormatInfo.mComponentType == GL_INT)) ||
1224 ((textureInternalFormatInfo.mComponentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.mComponentType == GL_UNSIGNED_INT)))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001225 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001226 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001227 }
1228
Shannon Woods4d161ba2014-03-17 18:13:30 -04001229 if (gl::IsFloatOrFixedComponentType(textureInternalFormatInfo.mComponentType) &&
1230 !gl::IsFloatOrFixedComponentType(framebufferInternalFormatInfo.mComponentType))
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001231 {
Shannon Woods4d161ba2014-03-17 18:13:30 -04001232 return false;
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001233 }
Shannon Woods4d161ba2014-03-17 18:13:30 -04001234
1235 // GLES specification 3.0.3, sec 3.8.5, pg 139-140:
1236 // The effective internal format of the source buffer is determined with the following rules applied in order:
1237 // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the
1238 // effective internal format is the source buffer's sized internal format.
1239 // * If the source buffer is a texture that was created with an unsized base internal format, then the
1240 // effective internal format is the source image array's effective internal format, as specified by table
1241 // 3.12, which is determined from the <format> and <type> that were used when the source image array was
1242 // specified by TexImage*.
1243 // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where
1244 // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent
1245 // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the
1246 // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING
1247 // is SRGB.
1248 InternalFormatInfo sourceEffectiveFormat;
1249 if (readBufferHandle != 0)
1250 {
1251 // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer
1252 if (gl::IsSizedInternalFormat(framebufferInternalFormatInfo.mFormat, clientVersion))
1253 {
1254 sourceEffectiveFormat = framebufferInternalFormatInfo;
1255 }
1256 else
1257 {
1258 // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format
1259 // texture. We can use the same table we use when creating textures to get its effective sized format.
1260 GLenum effectiveFormat = gl::GetSizedInternalFormat(framebufferInternalFormatInfo.mFormat,
1261 framebufferInternalFormatInfo.mType, clientVersion);
1262 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1263 }
1264 }
1265 else
1266 {
1267 // The effective internal format must be derived from the source framebuffer's channel sizes.
1268 // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17)
1269 if (framebufferInternalFormatInfo.mColorEncoding == GL_LINEAR)
1270 {
1271 GLenum effectiveFormat;
1272 if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, clientVersion, &effectiveFormat))
1273 {
1274 gl::GetInternalFormatInfo(effectiveFormat, clientVersion, &sourceEffectiveFormat);
1275 }
1276 else
1277 {
1278 return false;
1279 }
1280 }
1281 else if (framebufferInternalFormatInfo.mColorEncoding == GL_SRGB)
1282 {
1283 // SRGB buffers can only be copied to sized format destinations according to table 3.18
1284 if (gl::IsSizedInternalFormat(textureInternalFormat, clientVersion) &&
1285 (framebufferInternalFormatInfo.mRedBits >= 1 && framebufferInternalFormatInfo.mRedBits <= 8) &&
1286 (framebufferInternalFormatInfo.mGreenBits >= 1 && framebufferInternalFormatInfo.mGreenBits <= 8) &&
1287 (framebufferInternalFormatInfo.mBlueBits >= 1 && framebufferInternalFormatInfo.mBlueBits <= 8) &&
1288 (framebufferInternalFormatInfo.mAlphaBits >= 1 && framebufferInternalFormatInfo.mAlphaBits <= 8))
1289 {
1290 gl::GetInternalFormatInfo(GL_SRGB8_ALPHA8, clientVersion, &sourceEffectiveFormat);
1291 }
1292 else
1293 {
1294 return false;
1295 }
1296 }
1297 else
1298 {
1299 UNREACHABLE();
1300 }
1301 }
1302
1303 if (gl::IsSizedInternalFormat(textureInternalFormatInfo.mFormat, clientVersion))
1304 {
1305 // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized,
1306 // component sizes of the source and destination formats must exactly match
1307 if (textureInternalFormatInfo.mRedBits != sourceEffectiveFormat.mRedBits ||
1308 textureInternalFormatInfo.mGreenBits != sourceEffectiveFormat.mGreenBits ||
1309 textureInternalFormatInfo.mBlueBits != sourceEffectiveFormat.mBlueBits ||
1310 textureInternalFormatInfo.mAlphaBits != sourceEffectiveFormat.mAlphaBits)
1311 {
1312 return false;
1313 }
1314 }
1315
1316
1317 return true; // A conversion function exists, and no rule in the specification has precluded conversion
1318 // between these formats.
shannonwoods@chromium.orgffab47d2013-05-30 00:16:22 +00001319 }
1320
1321 return false;
1322 }
1323 else
1324 {
1325 UNREACHABLE();
1326 return false;
1327 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001328 }
1329 else
1330 {
1331 UNREACHABLE();
1332 return false;
1333 }
1334}
1335
Geoff Lang005df412013-10-16 14:12:50 -04001336bool IsSizedInternalFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001337{
1338 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001339 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001340 {
1341 return internalFormatInfo.mPixelBits > 0;
1342 }
1343 else
1344 {
1345 UNREACHABLE();
1346 return false;
1347 }
1348}
1349
Geoff Lang005df412013-10-16 14:12:50 -04001350GLenum GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001351{
Geoff Langfe28ca02013-06-04 10:10:48 -04001352 const FormatMap &formats = GetFormatMap(clientVersion);
1353 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1354 return (iter != formats.end()) ? iter->second.mInternalFormat : GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001355}
1356
Geoff Lang005df412013-10-16 14:12:50 -04001357GLuint GetPixelBytes(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001358{
1359 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001360 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001361 {
1362 return internalFormatInfo.mPixelBits / 8;
1363 }
1364 else
1365 {
1366 UNREACHABLE();
1367 return 0;
1368 }
1369}
1370
Geoff Lang005df412013-10-16 14:12:50 -04001371GLuint GetAlphaBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001372{
1373 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001374 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001375 {
1376 return internalFormatInfo.mAlphaBits;
1377 }
1378 else
1379 {
1380 UNREACHABLE();
1381 return 0;
1382 }
1383}
1384
Geoff Lang005df412013-10-16 14:12:50 -04001385GLuint GetRedBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001386{
1387 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001388 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001389 {
1390 return internalFormatInfo.mRedBits;
1391 }
1392 else
1393 {
1394 UNREACHABLE();
1395 return 0;
1396 }
1397}
1398
Geoff Lang005df412013-10-16 14:12:50 -04001399GLuint GetGreenBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001400{
1401 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001402 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001403 {
1404 return internalFormatInfo.mGreenBits;
1405 }
1406 else
1407 {
1408 UNREACHABLE();
1409 return 0;
1410 }
1411}
1412
Geoff Lang005df412013-10-16 14:12:50 -04001413GLuint GetBlueBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001414{
1415 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001416 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001417 {
Geoff Lang24159222013-06-05 14:56:32 -04001418 return internalFormatInfo.mBlueBits;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001419 }
1420 else
1421 {
1422 UNREACHABLE();
1423 return 0;
1424 }
1425}
1426
Geoff Lang005df412013-10-16 14:12:50 -04001427GLuint GetLuminanceBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001428{
1429 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001430 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001431 {
1432 return internalFormatInfo.mLuminanceBits;
1433 }
1434 else
1435 {
1436 UNREACHABLE();
1437 return 0;
1438 }
1439}
1440
Geoff Lang005df412013-10-16 14:12:50 -04001441GLuint GetDepthBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001442{
1443 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001444 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001445 {
1446 return internalFormatInfo.mDepthBits;
1447 }
1448 else
1449 {
1450 UNREACHABLE();
1451 return 0;
1452 }
1453}
1454
Geoff Lang005df412013-10-16 14:12:50 -04001455GLuint GetStencilBits(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001456{
1457 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001458 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001459 {
1460 return internalFormatInfo.mStencilBits;
1461 }
1462 else
1463 {
1464 UNREACHABLE();
1465 return 0;
1466 }
1467}
1468
Geoff Langf23eb282013-07-22 10:52:19 -04001469GLuint GetTypeBytes(GLenum type)
1470{
1471 TypeInfo typeInfo;
1472 if (GetTypeInfo(type, &typeInfo))
1473 {
1474 return typeInfo.mTypeBytes;
1475 }
1476 else
1477 {
1478 UNREACHABLE();
1479 return 0;
1480 }
1481}
1482
1483bool IsSpecialInterpretationType(GLenum type)
1484{
1485 TypeInfo typeInfo;
1486 if (GetTypeInfo(type, &typeInfo))
1487 {
1488 return typeInfo.mSpecialInterpretation;
1489 }
1490 else
1491 {
1492 UNREACHABLE();
1493 return false;
1494 }
1495}
1496
Shannon Woods4d161ba2014-03-17 18:13:30 -04001497bool IsFloatOrFixedComponentType(GLenum type)
1498{
1499 if (type == GL_UNSIGNED_NORMALIZED ||
1500 type == GL_SIGNED_NORMALIZED ||
1501 type == GL_FLOAT)
1502 {
1503 return true;
1504 }
1505 else
1506 {
1507 return false;
1508 }
1509}
1510
Geoff Lang005df412013-10-16 14:12:50 -04001511GLenum GetFormat(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001512{
1513 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001514 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001515 {
1516 return internalFormatInfo.mFormat;
1517 }
1518 else
1519 {
1520 UNREACHABLE();
1521 return GL_NONE;
1522 }
1523}
1524
Geoff Lang005df412013-10-16 14:12:50 -04001525GLenum GetType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001526{
1527 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001528 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001529 {
1530 return internalFormatInfo.mType;
1531 }
1532 else
1533 {
1534 UNREACHABLE();
1535 return GL_NONE;
1536 }
1537}
1538
Nicolas Capens0027fa92014-02-20 14:26:42 -05001539GLenum GetComponentType(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001540{
1541 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001542 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001543 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001544 return internalFormatInfo.mComponentType;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001545 }
1546 else
1547 {
1548 UNREACHABLE();
Nicolas Capens0027fa92014-02-20 14:26:42 -05001549 return GL_NONE;
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001550 }
1551}
1552
Geoff Lang005df412013-10-16 14:12:50 -04001553GLuint GetComponentCount(GLenum internalFormat, GLuint clientVersion)
Jamie Madill3466a4d2013-09-18 14:36:20 -04001554{
1555 InternalFormatInfo internalFormatInfo;
1556 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
1557 {
1558 return internalFormatInfo.mComponentCount;
1559 }
1560 else
1561 {
1562 UNREACHABLE();
1563 return false;
1564 }
1565}
1566
Geoff Lang005df412013-10-16 14:12:50 -04001567GLenum GetColorEncoding(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001568{
1569 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001570 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orge19409b2013-05-30 00:16:15 +00001571 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001572 return internalFormatInfo.mColorEncoding;
shannonwoods@chromium.orge81ea502013-05-30 00:16:53 +00001573 }
1574 else
1575 {
1576 UNREACHABLE();
1577 return false;
1578 }
1579}
1580
Geoff Lang005df412013-10-16 14:12:50 -04001581GLuint GetRowPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001582{
1583 ASSERT(alignment > 0 && isPow2(alignment));
Jamie Madilleb9baab2014-03-24 13:19:43 -04001584 return rx::roundUp(GetBlockSize(internalFormat, type, clientVersion, width, 1), static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001585}
1586
Geoff Lang005df412013-10-16 14:12:50 -04001587GLuint GetDepthPitch(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001588{
Jamie Madill666e2862013-09-10 12:04:29 -04001589 return GetRowPitch(internalFormat, type, clientVersion, width, alignment) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001590}
1591
Geoff Lang005df412013-10-16 14:12:50 -04001592GLuint GetBlockSize(GLenum internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001593{
1594 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001595 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001596 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001597 if (internalFormatInfo.mIsCompressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001598 {
1599 GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth;
1600 GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight;
1601
1602 return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
1603 }
1604 else
1605 {
1606 TypeInfo typeInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001607 if (GetTypeInfo(type, &typeInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001608 {
1609 if (typeInfo.mSpecialInterpretation)
1610 {
1611 return typeInfo.mTypeBytes * width * height;
1612 }
1613 else
1614 {
1615 return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height;
1616 }
1617 }
1618 else
1619 {
1620 UNREACHABLE();
1621 return 0;
1622 }
1623 }
1624 }
1625 else
1626 {
1627 UNREACHABLE();
1628 return 0;
1629 }
1630}
1631
Geoff Lang005df412013-10-16 14:12:50 -04001632bool IsFormatCompressed(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001633{
1634 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001635 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001636 {
Geoff Langb2f3d052013-08-13 12:49:27 -04001637 return internalFormatInfo.mIsCompressed;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001638 }
1639 else
1640 {
1641 UNREACHABLE();
1642 return false;
1643 }
1644}
1645
Geoff Lang005df412013-10-16 14:12:50 -04001646GLuint GetCompressedBlockWidth(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001647{
1648 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001649 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001650 {
1651 return internalFormatInfo.mCompressedBlockWidth;
1652 }
1653 else
1654 {
1655 UNREACHABLE();
1656 return 0;
1657 }
1658}
1659
Geoff Lang005df412013-10-16 14:12:50 -04001660GLuint GetCompressedBlockHeight(GLenum internalFormat, GLuint clientVersion)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001661{
1662 InternalFormatInfo internalFormatInfo;
Geoff Lang18591b72013-06-07 12:00:15 -04001663 if (GetInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001664 {
1665 return internalFormatInfo.mCompressedBlockHeight;
1666 }
1667 else
1668 {
1669 UNREACHABLE();
1670 return 0;
1671 }
1672}
1673
Geoff Langcec35902014-04-16 10:52:36 -04001674const FormatSet &GetAllSizedInternalFormats(GLuint clientVersion)
1675{
1676 static FormatSet formatSet = BuildAllSizedInternalFormatSet(clientVersion);
1677 return formatSet;
1678}
1679
Geoff Langfe28ca02013-06-04 10:10:48 -04001680ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type, GLuint clientVersion)
1681{
1682 static const FormatMap &formats = GetFormatMap(clientVersion);
1683 FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type));
1684 return (iter != formats.end()) ? iter->second.mColorWriteFunction : NULL;
1685}
1686
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001687}