blob: cd27753b2c2eb1db41ed81d13b6cccb941eaa480 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15#include "Image.hpp"
16
Nicolas Capens3d7a0952015-06-09 17:01:52 -040017#include "Renderer/Blitter.hpp"
Nicolas Capensdeda34b2015-04-28 15:21:53 -070018#include "../libEGL/Texture.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040019#include "../common/debug.h"
Alexis Hetu92ac42f2015-10-23 14:43:54 -040020#include "Common/Math.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040021#include "Common/Thread.hpp"
22
Nicolas Capensdeda34b2015-04-28 15:21:53 -070023#include <GLES3/gl3.h>
24
25#include <string.h>
John Bauman66b8ab22014-05-06 15:57:45 -040026
Alexis Hetufe7719c2015-01-22 16:49:40 -050027namespace
28{
Alexis Hetu460e41f2015-09-01 10:58:37 -040029 int getNumBlocks(int w, int h, int blockSizeX, int blockSizeY)
30 {
31 return ((w + blockSizeX - 1) / blockSizeX) * ((h + blockSizeY - 1) / blockSizeY);
32 }
33
Alexis Hetufe7719c2015-01-22 16:49:40 -050034 enum DataType
35 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -040036 Bytes_1,
37 Bytes_2,
38 Bytes_4,
39 Bytes_8,
40 Bytes_16,
Alexis Hetu92ac42f2015-10-23 14:43:54 -040041 ByteRGB,
Nicolas Capensde6b75c2015-03-29 00:27:33 -040042 UByteRGB,
Alexis Hetu92ac42f2015-10-23 14:43:54 -040043 ShortRGB,
44 UShortRGB,
45 IntRGB,
46 UIntRGB,
Alexis Hetub027aa92015-01-19 15:56:12 -050047 RGB565,
Nicolas Capensde6b75c2015-03-29 00:27:33 -040048 FloatRGB,
49 HalfFloatRGB,
Alexis Hetub027aa92015-01-19 15:56:12 -050050 RGBA4444,
51 RGBA5551,
Alexis Hetu92ac42f2015-10-23 14:43:54 -040052 RGB10A2UI,
53 R11G11B10F,
54 RGB9E5,
55 SRGB,
56 SRGBA,
Alexis Hetub027aa92015-01-19 15:56:12 -050057 D16,
58 D24,
59 D32,
Alexis Hetu92ac42f2015-10-23 14:43:54 -040060 D32F,
Alexis Hetufe7719c2015-01-22 16:49:40 -050061 S8,
Alexis Hetu92ac42f2015-10-23 14:43:54 -040062 S24_8,
Alexis Hetufe7719c2015-01-22 16:49:40 -050063 };
64
65 template<DataType dataType>
Nicolas Capens1dfcb932015-06-09 17:06:31 -040066 void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -050067 {
Alexis Hetu66d40e82015-01-27 14:09:34 -050068 UNIMPLEMENTED();
Alexis Hetufe7719c2015-01-22 16:49:40 -050069 }
70
Ping-Hao Wub508ff82015-03-21 22:45:06 -070071 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -040072 void LoadImageRow<Bytes_1>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -050073 {
74 memcpy(dest + xoffset, source, width);
75 }
76
Ping-Hao Wub508ff82015-03-21 22:45:06 -070077 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -040078 void LoadImageRow<Bytes_2>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
79 {
80 memcpy(dest + xoffset * 2, source, width * 2);
81 }
82
83 template<>
84 void LoadImageRow<Bytes_4>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
85 {
86 memcpy(dest + xoffset * 4, source, width * 4);
87 }
88
89 template<>
90 void LoadImageRow<Bytes_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
91 {
92 memcpy(dest + xoffset * 8, source, width * 8);
93 }
94
95 template<>
96 void LoadImageRow<Bytes_16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
97 {
98 memcpy(dest + xoffset * 16, source, width * 16);
99 }
100
101 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400102 void LoadImageRow<ByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
103 {
104 unsigned char *destB = dest + xoffset * 4;
105
106 for(int x = 0; x < width; x++)
107 {
108 destB[4 * x + 0] = source[x * 3 + 0];
109 destB[4 * x + 1] = source[x * 3 + 1];
110 destB[4 * x + 2] = source[x * 3 + 2];
111 destB[4 * x + 3] = 0x7F;
112 }
113 }
114
115 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400116 void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500117 {
118 unsigned char *destB = dest + xoffset * 4;
119
120 for(int x = 0; x < width; x++)
121 {
Nicolas Capensde6b75c2015-03-29 00:27:33 -0400122 destB[4 * x + 0] = source[x * 3 + 0];
Alexis Hetufe7719c2015-01-22 16:49:40 -0500123 destB[4 * x + 1] = source[x * 3 + 1];
Nicolas Capensde6b75c2015-03-29 00:27:33 -0400124 destB[4 * x + 2] = source[x * 3 + 2];
Alexis Hetufe7719c2015-01-22 16:49:40 -0500125 destB[4 * x + 3] = 0xFF;
126 }
127 }
128
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700129 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400130 void LoadImageRow<ShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
131 {
132 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
133 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
134
135 for(int x = 0; x < width; x++)
136 {
137 destS[4 * x + 0] = sourceS[x * 3 + 0];
138 destS[4 * x + 1] = sourceS[x * 3 + 1];
139 destS[4 * x + 2] = sourceS[x * 3 + 2];
140 destS[4 * x + 3] = 0x7FFF;
141 }
142 }
143
144 template<>
145 void LoadImageRow<UShortRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
146 {
147 const unsigned short *sourceS = reinterpret_cast<const unsigned short*>(source);
148 unsigned short *destS = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
149
150 for(int x = 0; x < width; x++)
151 {
152 destS[4 * x + 0] = sourceS[x * 3 + 0];
153 destS[4 * x + 1] = sourceS[x * 3 + 1];
154 destS[4 * x + 2] = sourceS[x * 3 + 2];
155 destS[4 * x + 3] = 0xFFFF;
156 }
157 }
158
159 template<>
160 void LoadImageRow<IntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
161 {
162 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
163 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
164
165 for(int x = 0; x < width; x++)
166 {
167 destI[4 * x + 0] = sourceI[x * 3 + 0];
168 destI[4 * x + 1] = sourceI[x * 3 + 1];
169 destI[4 * x + 2] = sourceI[x * 3 + 2];
170 destI[4 * x + 3] = 0x7FFFFFFF;
171 }
172 }
173
174 template<>
175 void LoadImageRow<UIntRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
176 {
177 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
178 unsigned int *destI = reinterpret_cast<unsigned int*>(dest + xoffset * 16);
179
180 for(int x = 0; x < width; x++)
181 {
182 destI[4 * x + 0] = sourceI[x * 3 + 0];
183 destI[4 * x + 1] = sourceI[x * 3 + 1];
184 destI[4 * x + 2] = sourceI[x * 3 + 2];
185 destI[4 * x + 3] = 0xFFFFFFFF;
186 }
187 }
188
189 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400190 void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500191 {
Nicolas Capens5a86ee92015-09-04 10:45:43 -0400192 memcpy(dest + xoffset * 2, source, width * 2);
Alexis Hetufe7719c2015-01-22 16:49:40 -0500193 }
194
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700195 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400196 void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500197 {
198 const float *sourceF = reinterpret_cast<const float*>(source);
199 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
200
201 for(int x = 0; x < width; x++)
202 {
203 destF[4 * x + 0] = sourceF[x * 3 + 0];
204 destF[4 * x + 1] = sourceF[x * 3 + 1];
205 destF[4 * x + 2] = sourceF[x * 3 + 2];
206 destF[4 * x + 3] = 1.0f;
207 }
208 }
209
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700210 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400211 void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500212 {
213 const unsigned short *sourceH = reinterpret_cast<const unsigned short*>(source);
214 unsigned short *destH = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
215
216 for(int x = 0; x < width; x++)
217 {
218 destH[4 * x + 0] = sourceH[x * 3 + 0];
219 destH[4 * x + 1] = sourceH[x * 3 + 1];
220 destH[4 * x + 2] = sourceH[x * 3 + 2];
221 destH[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
222 }
223 }
224
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700225 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400226 void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500227 {
228 const unsigned short *source4444 = reinterpret_cast<const unsigned short*>(source);
229 unsigned char *dest4444 = dest + xoffset * 4;
230
231 for(int x = 0; x < width; x++)
232 {
233 unsigned short rgba = source4444[x];
234 dest4444[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
235 dest4444[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
236 dest4444[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
237 dest4444[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
238 }
239 }
240
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700241 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400242 void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500243 {
244 const unsigned short *source5551 = reinterpret_cast<const unsigned short*>(source);
245 unsigned char *dest5551 = dest + xoffset * 4;
246
247 for(int x = 0; x < width; x++)
248 {
249 unsigned short rgba = source5551[x];
250 dest5551[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
251 dest5551[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
252 dest5551[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
253 dest5551[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
254 }
255 }
256
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700257 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400258 void LoadImageRow<RGB10A2UI>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500259 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400260 const unsigned int *source1010102U = reinterpret_cast<const unsigned int*>(source);
261 unsigned short *dest16U = reinterpret_cast<unsigned short*>(dest + xoffset * 8);
262
263 for(int x = 0; x < width; x++)
264 {
265 unsigned int rgba = source1010102U[x];
266 dest16U[4 * x + 0] = (rgba & 0x00000FFC) >> 2;
267 dest16U[4 * x + 1] = (rgba & 0x003FF000) >> 12;
268 dest16U[4 * x + 2] = (rgba & 0xFFC00000) >> 22;
269 dest16U[4 * x + 3] = (rgba & 0x00000003);
270 }
Alexis Hetufe7719c2015-01-22 16:49:40 -0500271 }
272
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700273 template<>
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400274 void LoadImageRow<R11G11B10F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500275 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400276 const sw::R11G11B10FData *sourceRGB = reinterpret_cast<const sw::R11G11B10FData*>(source);
277 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
278
279 for(int x = 0; x < width; x++, sourceRGB++, destF+=4)
280 {
281 sourceRGB->toRGBFloats(destF);
282 destF[3] = 1.0f;
283 }
284 }
285
286 template<>
287 void LoadImageRow<RGB9E5>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
288 {
289 const sw::RGB9E5Data *sourceRGB = reinterpret_cast<const sw::RGB9E5Data*>(source);
290 float *destF = reinterpret_cast<float*>(dest + xoffset * 16);
291
292 for(int x = 0; x < width; x++, sourceRGB++, destF += 4)
293 {
294 sourceRGB->toRGBFloats(destF);
295 destF[3] = 1.0f;
296 }
297 }
298
299 template<>
300 void LoadImageRow<SRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
301 {
302 dest += xoffset * 4;
303
304 for(int x = 0; x < width; x++)
305 {
306 for(int rgb = 0; rgb < 3; ++rgb)
307 {
308 *dest++ = sw::sRGB8toLinear8(*source++);
309 }
310 *dest++ = 255;
311 }
312 }
313
314 template<>
315 void LoadImageRow<SRGBA>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
316 {
317 dest += xoffset * 4;
318
319 for(int x = 0; x < width; x++)
320 {
321 for(int rgb = 0; rgb < 3; ++rgb)
322 {
323 *dest++ = sw::sRGB8toLinear8(*source++);
324 }
325 *dest++ = *source++;
326 }
Alexis Hetufe7719c2015-01-22 16:49:40 -0500327 }
328
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700329 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400330 void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500331 {
332 const unsigned short *sourceD16 = reinterpret_cast<const unsigned short*>(source);
333 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
334
335 for(int x = 0; x < width; x++)
336 {
337 destF[x] = (float)sourceD16[x] / 0xFFFF;
338 }
339 }
340
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700341 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400342 void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500343 {
344 const unsigned int *sourceD24 = reinterpret_cast<const unsigned int*>(source);
345 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
346
347 for(int x = 0; x < width; x++)
348 {
349 destF[x] = (float)(sourceD24[x] & 0xFFFFFF00) / 0xFFFFFF00;
350 }
351 }
352
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700353 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400354 void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500355 {
356 const unsigned int *sourceD32 = reinterpret_cast<const unsigned int*>(source);
357 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
358
359 for(int x = 0; x < width; x++)
360 {
361 destF[x] = (float)sourceD32[x] / 0xFFFFFFFF;
362 }
363 }
364
Ping-Hao Wub508ff82015-03-21 22:45:06 -0700365 template<>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400366 void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500367 {
368 const unsigned int *sourceI = reinterpret_cast<const unsigned int*>(source);
369 unsigned char *destI = dest + xoffset;
370
371 for(int x = 0; x < width; x++)
372 {
373 destI[x] = static_cast<unsigned char>(sourceI[x] & 0x000000FF); // FIXME: Quad layout
374 }
375 }
376
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400377 template<>
378 void LoadImageRow<D32F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
379 {
380 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
381 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
382 float *destF = reinterpret_cast<float*>(dest + xoffset * 4);
383
384 for(int x = 0; x < width; x++)
385 {
386 destF[x] = sourceD32FS8[x].depth32f;
387 }
388 }
389
390 template<>
391 void LoadImageRow<S24_8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width)
392 {
393 struct D32FS8 { float depth32f; unsigned int stencil24_8; };
394 const D32FS8 *sourceD32FS8 = reinterpret_cast<const D32FS8*>(source);
395 unsigned char *destI = dest + xoffset;
396
397 for(int x = 0; x < width; x++)
398 {
399 destI[x] = static_cast<unsigned char>(sourceD32FS8[x].stencil24_8 & 0x000000FF); // FIXME: Quad layout
400 }
401 }
402
Alexis Hetufe7719c2015-01-22 16:49:40 -0500403 template<DataType dataType>
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400404 void LoadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, int destPitch, GLsizei destHeight, const void *input, void *buffer)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500405 {
406 for(int z = 0; z < depth; ++z)
407 {
Alexis Hetuc7b05102015-04-23 16:19:53 -0400408 const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight);
Nicolas Capensde6b75c2015-03-29 00:27:33 -0400409 unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight);
Alexis Hetub027aa92015-01-19 15:56:12 -0500410 for(int y = 0; y < height; ++y)
Alexis Hetufe7719c2015-01-22 16:49:40 -0500411 {
412 const unsigned char *source = inputStart + y * inputPitch;
413 unsigned char *dest = destStart + (y + yoffset) * destPitch;
414
Nicolas Capens1dfcb932015-06-09 17:06:31 -0400415 LoadImageRow<dataType>(source, dest, xoffset, width);
Alexis Hetufe7719c2015-01-22 16:49:40 -0500416 }
417 }
418 }
419}
420
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700421namespace egl
John Bauman66b8ab22014-05-06 15:57:45 -0400422{
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400423 sw::Format ConvertFormatType(GLenum format, GLenum type)
424 {
425 switch(format)
426 {
427 case GL_LUMINANCE:
428 switch(type)
429 {
430 case GL_UNSIGNED_BYTE: return sw::FORMAT_L8;
431 case GL_HALF_FLOAT: return sw::FORMAT_L16F;
432 case GL_HALF_FLOAT_OES: return sw::FORMAT_L16F;
433 case GL_FLOAT: return sw::FORMAT_L32F;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400434 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400435 }
436 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400437 case GL_LUMINANCE8_EXT:
438 return sw::FORMAT_L8;
439 case GL_LUMINANCE16F_EXT:
440 return sw::FORMAT_L16F;
441 case GL_LUMINANCE32F_EXT:
442 return sw::FORMAT_L32F;
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400443 case GL_LUMINANCE_ALPHA:
444 switch(type)
445 {
446 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8L8;
447 case GL_HALF_FLOAT: return sw::FORMAT_A16L16F;
448 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16L16F;
449 case GL_FLOAT: return sw::FORMAT_A32L32F;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400450 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400451 }
452 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400453 case GL_LUMINANCE8_ALPHA8_EXT:
454 return sw::FORMAT_A8L8;
455 case GL_LUMINANCE_ALPHA16F_EXT:
456 return sw::FORMAT_A16L16F;
457 case GL_LUMINANCE_ALPHA32F_EXT:
458 return sw::FORMAT_A32L32F;
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400459 case GL_RGBA:
460 switch(type)
461 {
462 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8B8G8R8;
463 case GL_UNSIGNED_SHORT_4_4_4_4: return sw::FORMAT_R4G4B4A4;
464 case GL_UNSIGNED_SHORT_5_5_5_1: return sw::FORMAT_R5G5B5A1;
465 case GL_HALF_FLOAT: return sw::FORMAT_A16B16G16R16F;
466 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16B16G16R16F;
467 case GL_FLOAT: return sw::FORMAT_A32B32G32R32F;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400468 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400469 }
470 break;
471 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -0400472 case GL_BGRA8_EXT:
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400473 switch(type)
474 {
Nicolas Capens043c19f2016-02-12 17:06:31 -0500475 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8R8G8B8;
476 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: return sw::FORMAT_A4R4G4B4;
477 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: return sw::FORMAT_A1R5G5B5;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400478 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400479 }
480 break;
481 case GL_RGB:
482 switch(type)
483 {
484 case GL_UNSIGNED_BYTE: return sw::FORMAT_B8G8R8;
485 case GL_UNSIGNED_SHORT_5_6_5: return sw::FORMAT_R5G6B5;
486 case GL_HALF_FLOAT: return sw::FORMAT_B16G16R16F;
487 case GL_HALF_FLOAT_OES: return sw::FORMAT_B16G16R16F;
488 case GL_FLOAT: return sw::FORMAT_B32G32R32F;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400489 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400490 }
491 break;
492 case GL_ALPHA:
493 switch(type)
494 {
495 case GL_UNSIGNED_BYTE: return sw::FORMAT_A8;
496 case GL_HALF_FLOAT: return sw::FORMAT_A16F;
497 case GL_HALF_FLOAT_OES: return sw::FORMAT_A16F;
498 case GL_FLOAT: return sw::FORMAT_A32F;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400499 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400500 }
501 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400502 case GL_ALPHA8_EXT:
503 return sw::FORMAT_A8;
504 case GL_ALPHA16F_EXT:
505 return sw::FORMAT_A16F;
506 case GL_ALPHA32F_EXT:
507 return sw::FORMAT_A32F;
Alexis Hetu1abb6382016-02-08 11:21:16 -0500508 case GL_RED_INTEGER:
509 switch(type)
510 {
511 case GL_INT: return sw::FORMAT_R32I;
512 case GL_UNSIGNED_INT: return sw::FORMAT_R32UI;
513 default: UNREACHABLE(type);
514 }
515 break;
516 case GL_RG_INTEGER:
517 switch(type)
518 {
519 case GL_INT: return sw::FORMAT_G32R32I;
520 case GL_UNSIGNED_INT: return sw::FORMAT_G32R32UI;
521 default: UNREACHABLE(type);
522 }
523 break;
524 case GL_RGBA_INTEGER:
525 switch(type)
526 {
527 case GL_INT: return sw::FORMAT_A32B32G32R32I;
528 case GL_UNSIGNED_INT: return sw::FORMAT_A32B32G32R32UI;
529 default: UNREACHABLE(type);
530 }
531 break;
John Sheubc07bf62016-04-18 18:53:47 -0700532 case GL_DEPTH_COMPONENT:
533 switch(type)
534 {
535 case GL_UNSIGNED_SHORT: return sw::FORMAT_D16;
536 case GL_UNSIGNED_INT_24_8_OES: return sw::FORMAT_D24S8;
537 case GL_UNSIGNED_INT: return sw::FORMAT_D32;
538 case GL_FLOAT: return sw::FORMAT_D32F;
539 default: UNREACHABLE(type);
540 }
541 break;
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400542 default:
Nicolas Capens3713cd42015-06-22 10:41:54 -0400543 UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -0400544 }
545
546 return sw::FORMAT_NULL;
547 }
548
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400549 sw::Format SelectInternalFormat(GLenum format, GLenum type)
550 {
Alexis Hetu460e41f2015-09-01 10:58:37 -0400551 switch(format)
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400552 {
Alexis Hetu460e41f2015-09-01 10:58:37 -0400553 case GL_ETC1_RGB8_OES:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400554 return sw::FORMAT_ETC1;
Alexis Hetu460e41f2015-09-01 10:58:37 -0400555 case GL_COMPRESSED_R11_EAC:
556 return sw::FORMAT_R11_EAC;
557 case GL_COMPRESSED_SIGNED_R11_EAC:
558 return sw::FORMAT_SIGNED_R11_EAC;
559 case GL_COMPRESSED_RG11_EAC:
560 return sw::FORMAT_RG11_EAC;
561 case GL_COMPRESSED_SIGNED_RG11_EAC:
562 return sw::FORMAT_SIGNED_RG11_EAC;
563 case GL_COMPRESSED_RGB8_ETC2:
564 return sw::FORMAT_RGB8_ETC2;
565 case GL_COMPRESSED_SRGB8_ETC2:
566 return sw::FORMAT_SRGB8_ETC2;
567 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
568 return sw::FORMAT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
569 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
570 return sw::FORMAT_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
571 case GL_COMPRESSED_RGBA8_ETC2_EAC:
572 return sw::FORMAT_RGBA8_ETC2_EAC;
573 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
574 return sw::FORMAT_SRGB8_ALPHA8_ETC2_EAC;
575 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
576 return sw::FORMAT_RGBA_ASTC_4x4_KHR;
577 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
578 return sw::FORMAT_RGBA_ASTC_5x4_KHR;
579 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
580 return sw::FORMAT_RGBA_ASTC_5x5_KHR;
581 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
582 return sw::FORMAT_RGBA_ASTC_6x5_KHR;
583 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
584 return sw::FORMAT_RGBA_ASTC_6x6_KHR;
585 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
586 return sw::FORMAT_RGBA_ASTC_8x5_KHR;
587 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
588 return sw::FORMAT_RGBA_ASTC_8x6_KHR;
589 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
590 return sw::FORMAT_RGBA_ASTC_8x8_KHR;
591 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
592 return sw::FORMAT_RGBA_ASTC_10x5_KHR;
593 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
594 return sw::FORMAT_RGBA_ASTC_10x6_KHR;
595 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
596 return sw::FORMAT_RGBA_ASTC_10x8_KHR;
597 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
598 return sw::FORMAT_RGBA_ASTC_10x10_KHR;
599 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
600 return sw::FORMAT_RGBA_ASTC_12x10_KHR;
601 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
602 return sw::FORMAT_RGBA_ASTC_12x12_KHR;
603 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
604 return sw::FORMAT_SRGB8_ALPHA8_ASTC_4x4_KHR;
605 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
606 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x4_KHR;
607 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
608 return sw::FORMAT_SRGB8_ALPHA8_ASTC_5x5_KHR;
609 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
610 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x5_KHR;
611 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
612 return sw::FORMAT_SRGB8_ALPHA8_ASTC_6x6_KHR;
613 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
614 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x5_KHR;
615 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
616 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x6_KHR;
617 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
618 return sw::FORMAT_SRGB8_ALPHA8_ASTC_8x8_KHR;
619 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
620 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x5_KHR;
621 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
622 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x6_KHR;
623 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
624 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x8_KHR;
625 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
626 return sw::FORMAT_SRGB8_ALPHA8_ASTC_10x10_KHR;
627 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
628 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x10_KHR;
629 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
630 return sw::FORMAT_SRGB8_ALPHA8_ASTC_12x12_KHR;
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400631 #if S3TC_SUPPORT
Alexis Hetu460e41f2015-09-01 10:58:37 -0400632 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
633 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400634 return sw::FORMAT_DXT1;
Alexis Hetu460e41f2015-09-01 10:58:37 -0400635 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400636 return sw::FORMAT_DXT3;
Alexis Hetu460e41f2015-09-01 10:58:37 -0400637 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400638 return sw::FORMAT_DXT5;
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400639 #endif
Alexis Hetu460e41f2015-09-01 10:58:37 -0400640 default:
641 break;
642 }
643
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400644 switch(type)
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400645 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400646 case GL_FLOAT:
647 switch(format)
648 {
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400649 case GL_ALPHA:
650 case GL_ALPHA32F_EXT:
651 return sw::FORMAT_A32F;
652 case GL_LUMINANCE:
653 case GL_LUMINANCE32F_EXT:
654 return sw::FORMAT_L32F;
655 case GL_LUMINANCE_ALPHA:
656 case GL_LUMINANCE_ALPHA32F_EXT:
657 return sw::FORMAT_A32L32F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400658 case GL_RED:
659 case GL_R32F:
660 return sw::FORMAT_R32F;
661 case GL_RG:
662 case GL_RG32F:
663 return sw::FORMAT_G32R32F;
664 case GL_RGB:
665 case GL_RGB32F:
Alexis Hetudbd1a8e2016-04-13 11:40:30 -0400666 return sw::FORMAT_X32B32G32R32F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400667 case GL_RGBA:
668 case GL_RGBA32F:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400669 return sw::FORMAT_A32B32G32R32F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400670 case GL_DEPTH_COMPONENT:
671 case GL_DEPTH_COMPONENT32F:
672 return sw::FORMAT_D32F;
673 default:
674 UNREACHABLE(format);
675 }
676 case GL_HALF_FLOAT:
677 case GL_HALF_FLOAT_OES:
678 switch(format)
679 {
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400680 case GL_ALPHA:
681 case GL_ALPHA16F_EXT:
682 return sw::FORMAT_A16F;
683 case GL_LUMINANCE:
684 case GL_LUMINANCE16F_EXT:
685 return sw::FORMAT_L16F;
686 case GL_LUMINANCE_ALPHA:
687 case GL_LUMINANCE_ALPHA16F_EXT:
688 return sw::FORMAT_A16L16F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400689 case GL_RED:
690 case GL_R16F:
691 return sw::FORMAT_R16F;
692 case GL_RG:
693 case GL_RG16F:
694 return sw::FORMAT_G16R16F;
695 case GL_RGB:
696 case GL_RGB16F:
697 case GL_RGBA:
698 case GL_RGBA16F:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -0400699 return sw::FORMAT_A16B16G16R16F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400700 default:
701 UNREACHABLE(format);
702 }
703 case GL_BYTE:
704 switch(format)
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400705 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400706 case GL_R8_SNORM:
707 case GL_R8:
708 case GL_RED:
709 return sw::FORMAT_R8I_SNORM;
710 case GL_R8I:
711 case GL_RED_INTEGER:
712 return sw::FORMAT_R8I;
713 case GL_RG8_SNORM:
714 case GL_RG8:
715 case GL_RG:
716 return sw::FORMAT_G8R8I_SNORM;
717 case GL_RG8I:
718 case GL_RG_INTEGER:
719 return sw::FORMAT_G8R8I;
720 case GL_RGB8_SNORM:
721 case GL_RGB8:
722 case GL_RGB:
723 return sw::FORMAT_X8B8G8R8I_SNORM;
724 case GL_RGB8I:
725 case GL_RGB_INTEGER:
726 return sw::FORMAT_X8B8G8R8I;
727 case GL_RGBA8_SNORM:
728 case GL_RGBA8:
729 case GL_RGBA:
730 return sw::FORMAT_A8B8G8R8I_SNORM;
731 case GL_RGBA8I:
732 case GL_RGBA_INTEGER:
733 return sw::FORMAT_A8B8G8R8I;
734 default:
735 UNREACHABLE(format);
736 }
737 case GL_UNSIGNED_BYTE:
738 switch(format)
739 {
740 case GL_LUMINANCE:
741 case GL_LUMINANCE8_EXT:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400742 return sw::FORMAT_L8;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400743 case GL_LUMINANCE_ALPHA:
744 case GL_LUMINANCE8_ALPHA8_EXT:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400745 return sw::FORMAT_A8L8;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400746 case GL_R8_SNORM:
747 case GL_R8:
748 case GL_RED:
749 return sw::FORMAT_R8;
750 case GL_R8UI:
751 case GL_RED_INTEGER:
752 return sw::FORMAT_R8UI;
753 case GL_RG8_SNORM:
754 case GL_RG8:
755 case GL_RG:
756 return sw::FORMAT_G8R8;
757 case GL_RG8UI:
758 case GL_RG_INTEGER:
759 return sw::FORMAT_G8R8UI;
760 case GL_RGB8_SNORM:
761 case GL_RGB8:
762 case GL_RGB:
763 case GL_SRGB8:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400764 return sw::FORMAT_X8B8G8R8;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400765 case GL_RGB8UI:
766 case GL_RGB_INTEGER:
767 return sw::FORMAT_X8B8G8R8UI;
768 case GL_RGBA8_SNORM:
769 case GL_RGBA8:
770 case GL_RGBA:
771 case GL_SRGB8_ALPHA8:
772 return sw::FORMAT_A8B8G8R8;
773 case GL_RGBA8UI:
774 case GL_RGBA_INTEGER:
775 return sw::FORMAT_A8B8G8R8UI;
776 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -0400777 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400778 return sw::FORMAT_A8R8G8B8;
779 case GL_ALPHA:
780 case GL_ALPHA8_EXT:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400781 return sw::FORMAT_A8;
Nicolas Capenscbb8b392015-11-06 16:01:11 -0500782 case SW_YV12_BT601:
783 return sw::FORMAT_YV12_BT601;
784 case SW_YV12_BT709:
785 return sw::FORMAT_YV12_BT709;
786 case SW_YV12_JFIF:
787 return sw::FORMAT_YV12_JFIF;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400788 default:
789 UNREACHABLE(format);
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400790 }
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400791 case GL_SHORT:
792 switch(format)
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400793 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400794 case GL_R16I:
795 case GL_RED_INTEGER:
796 return sw::FORMAT_R16I;
797 case GL_RG16I:
798 case GL_RG_INTEGER:
799 return sw::FORMAT_G16R16I;
800 case GL_RGB16I:
801 case GL_RGB_INTEGER:
802 return sw::FORMAT_X16B16G16R16I;
803 case GL_RGBA16I:
804 case GL_RGBA_INTEGER:
805 return sw::FORMAT_A16B16G16R16I;
806 default:
807 UNREACHABLE(format);
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400808 }
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400809 case GL_UNSIGNED_SHORT:
810 switch(format)
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400811 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400812 case GL_R16UI:
813 case GL_RED_INTEGER:
814 return sw::FORMAT_R16UI;
815 case GL_RG16UI:
816 case GL_RG_INTEGER:
817 return sw::FORMAT_G16R16UI;
818 case GL_RGB16UI:
819 case GL_RGB_INTEGER:
820 return sw::FORMAT_X16B16G16R16UI;
821 case GL_RGBA16UI:
822 case GL_RGBA_INTEGER:
823 return sw::FORMAT_A16B16G16R16UI;
824 case GL_DEPTH_COMPONENT:
825 case GL_DEPTH_COMPONENT16:
826 return sw::FORMAT_D32FS8_TEXTURE;
827 default:
828 UNREACHABLE(format);
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400829 }
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400830 case GL_INT:
831 switch(format)
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400832 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400833 case GL_RED_INTEGER:
834 case GL_R32I:
835 return sw::FORMAT_R32I;
836 case GL_RG_INTEGER:
837 case GL_RG32I:
838 return sw::FORMAT_G32R32I;
839 case GL_RGB_INTEGER:
840 case GL_RGB32I:
841 return sw::FORMAT_X32B32G32R32I;
842 case GL_RGBA_INTEGER:
843 case GL_RGBA32I:
844 return sw::FORMAT_A32B32G32R32I;
845 default:
846 UNREACHABLE(format);
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400847 }
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400848 case GL_UNSIGNED_INT:
849 switch(format)
850 {
851 case GL_RED_INTEGER:
852 case GL_R32UI:
853 return sw::FORMAT_R32UI;
854 case GL_RG_INTEGER:
855 case GL_RG32UI:
856 return sw::FORMAT_G32R32UI;
857 case GL_RGB_INTEGER:
858 case GL_RGB32UI:
859 return sw::FORMAT_X32B32G32R32UI;
860 case GL_RGBA_INTEGER:
861 case GL_RGBA32UI:
862 return sw::FORMAT_A32B32G32R32UI;
863 case GL_DEPTH_COMPONENT:
864 case GL_DEPTH_COMPONENT16:
865 case GL_DEPTH_COMPONENT24:
866 case GL_DEPTH_COMPONENT32_OES:
867 return sw::FORMAT_D32FS8_TEXTURE;
868 default:
869 UNREACHABLE(format);
870 }
871 case GL_UNSIGNED_INT_24_8_OES:
872 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH24_STENCIL8)
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400873 {
874 return sw::FORMAT_D32FS8_TEXTURE;
875 }
Nicolas Capens3713cd42015-06-22 10:41:54 -0400876 else UNREACHABLE(format);
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400877 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
878 if(format == GL_DEPTH_STENCIL || format == GL_DEPTH32F_STENCIL8)
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400879 {
880 return sw::FORMAT_D32FS8_TEXTURE;
881 }
Nicolas Capens3713cd42015-06-22 10:41:54 -0400882 else UNREACHABLE(format);
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400883 case GL_UNSIGNED_SHORT_4_4_4_4:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400884 return sw::FORMAT_A8R8G8B8;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400885 case GL_UNSIGNED_SHORT_5_5_5_1:
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400886 return sw::FORMAT_A8R8G8B8;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400887 case GL_UNSIGNED_SHORT_5_6_5:
Nicolas Capens5a86ee92015-09-04 10:45:43 -0400888 return sw::FORMAT_R5G6B5;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400889 case GL_UNSIGNED_INT_2_10_10_10_REV:
890 if(format == GL_RGB10_A2UI)
891 {
892 return sw::FORMAT_A16B16G16R16UI;
893 }
894 else
895 {
896 return sw::FORMAT_A2B10G10R10;
897 }
898 case GL_UNSIGNED_INT_10F_11F_11F_REV:
899 case GL_UNSIGNED_INT_5_9_9_9_REV:
900 return sw::FORMAT_A32B32G32R32F;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400901 default:
902 UNREACHABLE(type);
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400903 }
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400904
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400905 return sw::FORMAT_NULL;
Nicolas Capens2c4edc22015-06-09 16:59:22 -0400906 }
907
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700908 // Returns the size, in bytes, of a single texel in an Image
Nicolas Capens8e8a7e82015-09-01 14:39:57 -0400909 static int ComputePixelSize(GLenum format, GLenum type)
John Bauman66b8ab22014-05-06 15:57:45 -0400910 {
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700911 switch(type)
John Baumand4ae8632014-05-06 16:18:33 -0400912 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400913 case GL_BYTE:
914 switch(format)
915 {
916 case GL_R8:
917 case GL_R8I:
918 case GL_R8_SNORM:
919 case GL_RED: return sizeof(char);
920 case GL_RED_INTEGER: return sizeof(char);
921 case GL_RG8:
922 case GL_RG8I:
923 case GL_RG8_SNORM:
924 case GL_RG: return sizeof(char) * 2;
925 case GL_RG_INTEGER: return sizeof(char) * 2;
926 case GL_RGB8:
927 case GL_RGB8I:
928 case GL_RGB8_SNORM:
929 case GL_RGB: return sizeof(char) * 3;
930 case GL_RGB_INTEGER: return sizeof(char) * 3;
931 case GL_RGBA8:
932 case GL_RGBA8I:
933 case GL_RGBA8_SNORM:
934 case GL_RGBA: return sizeof(char) * 4;
935 case GL_RGBA_INTEGER: return sizeof(char) * 4;
936 default: UNREACHABLE(format);
937 }
938 break;
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700939 case GL_UNSIGNED_BYTE:
940 switch(format)
941 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400942 case GL_R8:
943 case GL_R8UI:
944 case GL_RED: return sizeof(unsigned char);
945 case GL_RED_INTEGER: return sizeof(unsigned char);
946 case GL_ALPHA8_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700947 case GL_ALPHA: return sizeof(unsigned char);
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400948 case GL_LUMINANCE8_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700949 case GL_LUMINANCE: return sizeof(unsigned char);
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400950 case GL_LUMINANCE8_ALPHA8_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700951 case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400952 case GL_RG8:
953 case GL_RG8UI:
954 case GL_RG: return sizeof(unsigned char) * 2;
955 case GL_RG_INTEGER: return sizeof(unsigned char) * 2;
956 case GL_RGB8:
957 case GL_RGB8UI:
958 case GL_SRGB8:
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700959 case GL_RGB: return sizeof(unsigned char) * 3;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400960 case GL_RGB_INTEGER: return sizeof(unsigned char) * 3;
961 case GL_RGBA8:
962 case GL_RGBA8UI:
963 case GL_SRGB8_ALPHA8:
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700964 case GL_RGBA: return sizeof(unsigned char) * 4;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400965 case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4;
Alexis Hetud9a2e7b2015-10-15 17:22:57 -0400966 case GL_BGRA_EXT:
967 case GL_BGRA8_EXT: return sizeof(unsigned char)* 4;
Nicolas Capens3713cd42015-06-22 10:41:54 -0400968 default: UNREACHABLE(format);
Nicolas Capensdeda34b2015-04-28 15:21:53 -0700969 }
970 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -0400971 case GL_SHORT:
972 switch(format)
973 {
974 case GL_R16I:
975 case GL_RED_INTEGER: return sizeof(short);
976 case GL_RG16I:
977 case GL_RG_INTEGER: return sizeof(short) * 2;
978 case GL_RGB16I:
979 case GL_RGB_INTEGER: return sizeof(short) * 3;
980 case GL_RGBA16I:
981 case GL_RGBA_INTEGER: return sizeof(short) * 4;
982 default: UNREACHABLE(format);
983 }
984 break;
985 case GL_UNSIGNED_SHORT:
986 switch(format)
987 {
988 case GL_DEPTH_COMPONENT16:
989 case GL_DEPTH_COMPONENT: return sizeof(unsigned short);
990 case GL_R16UI:
991 case GL_RED_INTEGER: return sizeof(unsigned short);
992 case GL_RG16UI:
993 case GL_RG_INTEGER: return sizeof(unsigned short) * 2;
994 case GL_RGB16UI:
995 case GL_RGB_INTEGER: return sizeof(unsigned short) * 3;
996 case GL_RGBA16UI:
997 case GL_RGBA_INTEGER: return sizeof(unsigned short) * 4;
998 default: UNREACHABLE(format);
999 }
1000 break;
1001 case GL_INT:
1002 switch(format)
1003 {
1004 case GL_R32I:
1005 case GL_RED_INTEGER: return sizeof(int);
1006 case GL_RG32I:
1007 case GL_RG_INTEGER: return sizeof(int) * 2;
1008 case GL_RGB32I:
1009 case GL_RGB_INTEGER: return sizeof(int) * 3;
1010 case GL_RGBA32I:
1011 case GL_RGBA_INTEGER: return sizeof(int) * 4;
1012 default: UNREACHABLE(format);
1013 }
1014 break;
1015 case GL_UNSIGNED_INT:
1016 switch(format)
1017 {
1018 case GL_DEPTH_COMPONENT16:
1019 case GL_DEPTH_COMPONENT24:
1020 case GL_DEPTH_COMPONENT32_OES:
1021 case GL_DEPTH_COMPONENT: return sizeof(unsigned int);
1022 case GL_R32UI:
1023 case GL_RED_INTEGER: return sizeof(unsigned int);
1024 case GL_RG32UI:
1025 case GL_RG_INTEGER: return sizeof(unsigned int) * 2;
1026 case GL_RGB32UI:
1027 case GL_RGB_INTEGER: return sizeof(unsigned int) * 3;
1028 case GL_RGBA32UI:
1029 case GL_RGBA_INTEGER: return sizeof(unsigned int) * 4;
1030 default: UNREACHABLE(format);
1031 }
1032 break;
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001033 case GL_UNSIGNED_SHORT_4_4_4_4:
1034 case GL_UNSIGNED_SHORT_5_5_5_1:
1035 case GL_UNSIGNED_SHORT_5_6_5:
Nicolas Capens043c19f2016-02-12 17:06:31 -05001036 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1037 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001038 return sizeof(unsigned short);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001039 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1040 case GL_UNSIGNED_INT_5_9_9_9_REV:
1041 case GL_UNSIGNED_INT_2_10_10_10_REV:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001042 case GL_UNSIGNED_INT_24_8_OES:
1043 return sizeof(unsigned int);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001044 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1045 return sizeof(float) + sizeof(unsigned int);
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001046 case GL_FLOAT:
1047 switch(format)
1048 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001049 case GL_DEPTH_COMPONENT32F:
1050 case GL_DEPTH_COMPONENT: return sizeof(float);
1051 case GL_ALPHA32F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001052 case GL_ALPHA: return sizeof(float);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001053 case GL_LUMINANCE32F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001054 case GL_LUMINANCE: return sizeof(float);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001055 case GL_LUMINANCE_ALPHA32F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001056 case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001057 case GL_RED: return sizeof(float);
1058 case GL_R32F: return sizeof(float);
1059 case GL_RG: return sizeof(float) * 2;
1060 case GL_RG32F: return sizeof(float) * 2;
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001061 case GL_RGB: return sizeof(float) * 3;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001062 case GL_RGB32F: return sizeof(float) * 3;
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001063 case GL_RGBA: return sizeof(float) * 4;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001064 case GL_RGBA32F: return sizeof(float) * 4;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001065 default: UNREACHABLE(format);
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001066 }
1067 break;
Alexis Hetu61161502015-05-21 11:45:03 -04001068 case GL_HALF_FLOAT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001069 case GL_HALF_FLOAT_OES:
1070 switch(format)
1071 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001072 case GL_ALPHA16F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001073 case GL_ALPHA: return sizeof(unsigned short);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001074 case GL_LUMINANCE16F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001075 case GL_LUMINANCE: return sizeof(unsigned short);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001076 case GL_LUMINANCE_ALPHA16F_EXT:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001077 case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001078 case GL_RED: return sizeof(unsigned short);
1079 case GL_R16F: return sizeof(unsigned short);
1080 case GL_RG: return sizeof(unsigned short) * 2;
1081 case GL_RG16F: return sizeof(unsigned short) * 2;
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001082 case GL_RGB: return sizeof(unsigned short) * 3;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001083 case GL_RGB16F: return sizeof(unsigned short) * 3;
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001084 case GL_RGBA: return sizeof(unsigned short) * 4;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001085 case GL_RGBA16F: return sizeof(unsigned short) * 4;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001086 default: UNREACHABLE(format);
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001087 }
1088 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001089 default: UNREACHABLE(type);
John Baumand4ae8632014-05-06 16:18:33 -04001090 }
1091
1092 return 0;
John Bauman66b8ab22014-05-06 15:57:45 -04001093 }
1094
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001095 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
Alexis Hetub027aa92015-01-19 15:56:12 -05001096 {
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001097 ASSERT(alignment > 0 && sw::isPow2(alignment));
1098
1099 GLsizei rawPitch = ComputePixelSize(format, type) * width;
1100 return (rawPitch + alignment - 1) & ~(alignment - 1);
Alexis Hetub027aa92015-01-19 15:56:12 -05001101 }
1102
Alexis Hetu9bdbaa02016-02-08 11:08:03 -05001103 size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, GLint skipImages, GLint skipRows, GLint skipPixels)
1104 {
1105 GLsizei pitchB = ComputePitch(width, format, type, alignment);
1106 return (skipImages * height + skipRows) * pitchB + skipPixels * ComputePixelSize(format, type);
1107 }
1108
Nicolas Capens1c6f53c2015-12-31 11:30:40 -05001109 inline GLsizei ComputeCompressedPitch(GLsizei width, GLenum format)
John Bauman66b8ab22014-05-06 15:57:45 -04001110 {
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001111 return ComputeCompressedSize(width, 1, format);
John Baumand4ae8632014-05-06 16:18:33 -04001112 }
1113
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001114 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format)
John Baumand4ae8632014-05-06 16:18:33 -04001115 {
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001116 switch(format)
1117 {
1118 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1119 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
Nicolas Capens0bac2852016-05-07 06:09:58 -04001120 case GL_ETC1_RGB8_OES:
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001121 case GL_COMPRESSED_R11_EAC:
1122 case GL_COMPRESSED_SIGNED_R11_EAC:
1123 case GL_COMPRESSED_RGB8_ETC2:
1124 case GL_COMPRESSED_SRGB8_ETC2:
1125 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1126 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
Alexis Hetu460e41f2015-09-01 10:58:37 -04001127 return 8 * getNumBlocks(width, height, 4, 4);
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001128 case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
1129 case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
1130 case GL_COMPRESSED_RG11_EAC:
1131 case GL_COMPRESSED_SIGNED_RG11_EAC:
1132 case GL_COMPRESSED_RGBA8_ETC2_EAC:
1133 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
Alexis Hetu460e41f2015-09-01 10:58:37 -04001134 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1135 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1136 return 16 * getNumBlocks(width, height, 4, 4);
1137 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1138 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1139 return 16 * getNumBlocks(width, height, 5, 4);
1140 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1141 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1142 return 16 * getNumBlocks(width, height, 5, 5);
1143 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1144 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1145 return 16 * getNumBlocks(width, height, 6, 5);
1146 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1147 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1148 return 16 * getNumBlocks(width, height, 6, 6);
1149 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1150 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1151 return 16 * getNumBlocks(width, height, 8, 5);
1152 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1153 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1154 return 16 * getNumBlocks(width, height, 8, 6);
1155 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1156 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1157 return 16 * getNumBlocks(width, height, 8, 8);
1158 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1159 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1160 return 16 * getNumBlocks(width, height, 10, 5);
1161 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1162 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1163 return 16 * getNumBlocks(width, height, 10, 6);
1164 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1165 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1166 return 16 * getNumBlocks(width, height, 10, 8);
1167 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1168 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1169 return 16 * getNumBlocks(width, height, 10, 10);
1170 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1171 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1172 return 16 * getNumBlocks(width, height, 12, 10);
1173 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1174 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1175 return 16 * getNumBlocks(width, height, 12, 12);
Nicolas Capensdeda34b2015-04-28 15:21:53 -07001176 default:
1177 return 0;
1178 }
John Bauman66b8ab22014-05-06 15:57:45 -04001179 }
1180
Alexis Hetu147f6682017-02-09 17:14:34 -05001181 void Image::typeinfo() {}
1182
John Bauman66b8ab22014-05-06 15:57:45 -04001183 Image::~Image()
1184 {
John Baumand4ae8632014-05-06 16:18:33 -04001185 if(parentTexture)
1186 {
Nicolas Capens35b16cf2016-02-07 22:25:26 -05001187 parentTexture->release();
John Baumand4ae8632014-05-06 16:18:33 -04001188 }
Nicolas Capensb2022a72016-02-04 14:53:38 -05001189
Nicolas Capens35b16cf2016-02-07 22:25:26 -05001190 ASSERT(!shared);
John Bauman66b8ab22014-05-06 15:57:45 -04001191 }
1192
1193 void Image::release()
1194 {
Nicolas Capens35b16cf2016-02-07 22:25:26 -05001195 int refs = dereference();
John Baumand4ae8632014-05-06 16:18:33 -04001196
Nicolas Capens35b16cf2016-02-07 22:25:26 -05001197 if(refs > 0)
1198 {
1199 if(parentTexture)
1200 {
1201 parentTexture->sweep();
1202 }
1203 }
1204 else
1205 {
1206 delete this;
1207 }
John Bauman66b8ab22014-05-06 15:57:45 -04001208 }
1209
Nicolas Capensfa0cc042014-12-10 10:17:07 -05001210 void Image::unbind(const egl::Texture *parent)
John Baumand4ae8632014-05-06 16:18:33 -04001211 {
Nicolas Capensfa0cc042014-12-10 10:17:07 -05001212 if(parentTexture == parent)
1213 {
Nicolas Capensb2022a72016-02-04 14:53:38 -05001214 parentTexture = nullptr;
Nicolas Capensfa0cc042014-12-10 10:17:07 -05001215 }
John Baumand4ae8632014-05-06 16:18:33 -04001216
1217 release();
1218 }
1219
Nicolas Capensc3603632016-02-07 22:19:45 -05001220 bool Image::isChildOf(const egl::Texture *parent) const
1221 {
1222 return parentTexture == parent;
1223 }
1224
Alexis Hetuc7b05102015-04-23 16:19:53 -04001225 void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input)
John Bauman66b8ab22014-05-06 15:57:45 -04001226 {
Alexis Hetu9bdbaa02016-02-08 11:08:03 -05001227 GLsizei inputWidth = (unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength;
1228 GLsizei inputPitch = ComputePitch(inputWidth, format, type, unpackInfo.alignment);
Alexis Hetuc7b05102015-04-23 16:19:53 -04001229 GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight;
Alexis Hetu9bdbaa02016-02-08 11:08:03 -05001230 input = ((char*)input) + ComputePackingOffset(format, type, inputWidth, inputHeight, unpackInfo.alignment, unpackInfo.skipImages, unpackInfo.skipRows, unpackInfo.skipPixels);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001231 sw::Format selectedInternalFormat = SelectInternalFormat(format, type);
1232 if(selectedInternalFormat == sw::FORMAT_NULL)
1233 {
1234 return;
1235 }
Nicolas Capensd45d14a2015-04-01 15:59:10 -04001236
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001237 if(selectedInternalFormat == internalFormat)
John Bauman66b8ab22014-05-06 15:57:45 -04001238 {
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001239 void *buffer = lock(0, 0, sw::LOCK_WRITEONLY);
John Baumand4ae8632014-05-06 16:18:33 -04001240
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001241 if(buffer)
1242 {
1243 switch(type)
1244 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001245 case GL_BYTE:
1246 switch(format)
1247 {
1248 case GL_R8:
1249 case GL_R8I:
1250 case GL_R8_SNORM:
1251 case GL_RED:
1252 case GL_RED_INTEGER:
1253 case GL_ALPHA:
1254 case GL_ALPHA8_EXT:
1255 case GL_LUMINANCE:
1256 case GL_LUMINANCE8_EXT:
1257 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1258 break;
1259 case GL_RG8:
1260 case GL_RG8I:
1261 case GL_RG8_SNORM:
1262 case GL_RG:
1263 case GL_RG_INTEGER:
1264 case GL_LUMINANCE_ALPHA:
1265 case GL_LUMINANCE8_ALPHA8_EXT:
1266 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1267 break;
1268 case GL_RGB8:
1269 case GL_RGB8I:
1270 case GL_RGB8_SNORM:
1271 case GL_RGB:
1272 case GL_RGB_INTEGER:
1273 LoadImageData<ByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1274 break;
1275 case GL_RGBA8:
1276 case GL_RGBA8I:
1277 case GL_RGBA8_SNORM:
1278 case GL_RGBA:
1279 case GL_RGBA_INTEGER:
1280 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001281 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001282 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1283 break;
1284 default: UNREACHABLE(format);
1285 }
1286 break;
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001287 case GL_UNSIGNED_BYTE:
1288 switch(format)
1289 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001290 case GL_R8:
1291 case GL_R8UI:
1292 case GL_R8_SNORM:
1293 case GL_RED:
1294 case GL_RED_INTEGER:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001295 case GL_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001296 case GL_ALPHA8_EXT:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001297 case GL_LUMINANCE:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001298 case GL_LUMINANCE8_EXT:
1299 LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001300 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001301 case GL_RG8:
1302 case GL_RG8UI:
1303 case GL_RG8_SNORM:
1304 case GL_RG:
1305 case GL_RG_INTEGER:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001306 case GL_LUMINANCE_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001307 case GL_LUMINANCE8_ALPHA8_EXT:
1308 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001309 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001310 case GL_RGB8:
1311 case GL_RGB8UI:
1312 case GL_RGB8_SNORM:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001313 case GL_RGB:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001314 case GL_RGB_INTEGER:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001315 LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001316 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001317 case GL_RGBA8:
1318 case GL_RGBA8UI:
1319 case GL_RGBA8_SNORM:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001320 case GL_RGBA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001321 case GL_RGBA_INTEGER:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001322 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001323 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001324 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1325 break;
1326 case GL_SRGB8:
1327 LoadImageData<SRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1328 break;
1329 case GL_SRGB8_ALPHA8:
1330 LoadImageData<SRGBA>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001331 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001332 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001333 }
1334 break;
1335 case GL_UNSIGNED_SHORT_5_6_5:
1336 switch(format)
1337 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001338 case GL_RGB565:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001339 case GL_RGB:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001340 LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001341 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001342 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001343 }
1344 break;
1345 case GL_UNSIGNED_SHORT_4_4_4_4:
1346 switch(format)
1347 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001348 case GL_RGBA4:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001349 case GL_RGBA:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001350 LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001351 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001352 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001353 }
1354 break;
1355 case GL_UNSIGNED_SHORT_5_5_5_1:
1356 switch(format)
1357 {
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001358 case GL_RGB5_A1:
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001359 case GL_RGBA:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001360 LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001361 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001362 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001363 }
1364 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001365 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1366 switch(format)
1367 {
1368 case GL_R11F_G11F_B10F:
1369 case GL_RGB:
1370 LoadImageData<R11G11B10F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1371 break;
1372 default: UNREACHABLE(format);
1373 }
1374 break;
1375 case GL_UNSIGNED_INT_5_9_9_9_REV:
1376 switch(format)
1377 {
1378 case GL_RGB9_E5:
1379 case GL_RGB:
1380 LoadImageData<RGB9E5>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1381 break;
1382 default: UNREACHABLE(format);
1383 }
1384 break;
1385 case GL_UNSIGNED_INT_2_10_10_10_REV:
1386 switch(format)
1387 {
1388 case GL_RGB10_A2UI:
1389 LoadImageData<RGB10A2UI>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1390 break;
1391 case GL_RGB10_A2:
1392 case GL_RGBA:
1393 case GL_RGBA_INTEGER:
1394 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1395 break;
1396 default: UNREACHABLE(format);
1397 }
1398 break;
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001399 case GL_FLOAT:
1400 switch(format)
1401 {
1402 // float textures are converted to RGBA, not BGRA
1403 case GL_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001404 case GL_ALPHA32F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001405 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001406 break;
1407 case GL_LUMINANCE:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001408 case GL_LUMINANCE32F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001409 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001410 break;
1411 case GL_LUMINANCE_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001412 case GL_LUMINANCE_ALPHA32F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001413 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001414 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001415 case GL_RED:
1416 case GL_R32F:
1417 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1418 break;
1419 case GL_RG:
1420 case GL_RG32F:
1421 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1422 break;
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001423 case GL_RGB:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001424 case GL_RGB32F:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001425 LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001426 break;
1427 case GL_RGBA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001428 case GL_RGBA32F:
1429 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1430 break;
1431 case GL_DEPTH_COMPONENT:
1432 case GL_DEPTH_COMPONENT32F:
1433 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001434 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001435 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001436 }
1437 break;
1438 case GL_HALF_FLOAT:
1439 case GL_HALF_FLOAT_OES:
1440 switch(format)
1441 {
1442 case GL_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001443 case GL_ALPHA16F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001444 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001445 break;
1446 case GL_LUMINANCE:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001447 case GL_LUMINANCE16F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001448 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001449 break;
1450 case GL_LUMINANCE_ALPHA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001451 case GL_LUMINANCE_ALPHA16F_EXT:
Nicolas Capensf33f4bc2015-10-28 18:53:23 -04001452 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001453 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001454 case GL_RED:
1455 case GL_R16F:
1456 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1457 break;
1458 case GL_RG:
1459 case GL_RG16F:
1460 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1461 break;
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001462 case GL_RGB:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001463 case GL_RGB16F:
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001464 LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001465 break;
1466 case GL_RGBA:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001467 case GL_RGBA16F:
1468 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1469 break;
1470 default: UNREACHABLE(format);
1471 }
1472 break;
1473 case GL_SHORT:
1474 switch(format)
1475 {
1476 case GL_R16I:
1477 case GL_RED:
1478 case GL_RED_INTEGER:
1479 case GL_ALPHA:
1480 case GL_LUMINANCE:
1481 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1482 break;
1483 case GL_RG16I:
1484 case GL_RG:
1485 case GL_RG_INTEGER:
1486 case GL_LUMINANCE_ALPHA:
1487 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1488 break;
1489 case GL_RGB16I:
1490 case GL_RGB:
1491 case GL_RGB_INTEGER:
1492 LoadImageData<ShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1493 break;
1494 case GL_RGBA16I:
1495 case GL_RGBA:
1496 case GL_RGBA_INTEGER:
1497 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001498 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001499 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001500 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001501 default: UNREACHABLE(format);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001502 }
1503 break;
1504 case GL_UNSIGNED_SHORT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001505 switch(format)
1506 {
1507 case GL_R16UI:
1508 case GL_RED:
1509 case GL_RED_INTEGER:
1510 case GL_ALPHA:
1511 case GL_LUMINANCE:
1512 LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1513 break;
1514 case GL_RG16UI:
1515 case GL_RG:
1516 case GL_RG_INTEGER:
1517 case GL_LUMINANCE_ALPHA:
1518 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1519 break;
1520 case GL_RGB16UI:
1521 case GL_RGB:
1522 case GL_RGB_INTEGER:
1523 LoadImageData<UShortRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1524 break;
1525 case GL_RGBA16UI:
1526 case GL_RGBA:
1527 case GL_RGBA_INTEGER:
1528 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001529 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001530 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1531 break;
1532 case GL_DEPTH_COMPONENT:
1533 case GL_DEPTH_COMPONENT16:
1534 LoadImageData<D16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1535 break;
1536 default: UNREACHABLE(format);
1537 }
1538 break;
1539 case GL_INT:
1540 switch(format)
1541 {
1542 case GL_R32I:
1543 case GL_RED:
1544 case GL_RED_INTEGER:
1545 case GL_ALPHA:
1546 case GL_LUMINANCE:
1547 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1548 break;
1549 case GL_RG32I:
1550 case GL_RG:
1551 case GL_RG_INTEGER:
1552 case GL_LUMINANCE_ALPHA:
1553 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1554 break;
1555 case GL_RGB32I:
1556 case GL_RGB:
1557 case GL_RGB_INTEGER:
1558 LoadImageData<IntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1559 break;
1560 case GL_RGBA32I:
1561 case GL_RGBA:
1562 case GL_RGBA_INTEGER:
1563 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001564 case GL_BGRA8_EXT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001565 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1566 break;
1567 default: UNREACHABLE(format);
1568 }
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001569 break;
1570 case GL_UNSIGNED_INT:
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001571 switch(format)
1572 {
1573 case GL_R32UI:
1574 case GL_RED:
1575 case GL_RED_INTEGER:
1576 case GL_ALPHA:
1577 case GL_LUMINANCE:
Alexis Hetud89ef672016-04-18 13:40:23 -04001578 LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001579 break;
1580 case GL_RG32UI:
1581 case GL_RG:
1582 case GL_RG_INTEGER:
1583 case GL_LUMINANCE_ALPHA:
Alexis Hetud89ef672016-04-18 13:40:23 -04001584 LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001585 break;
1586 case GL_RGB32UI:
1587 case GL_RGB:
1588 case GL_RGB_INTEGER:
1589 LoadImageData<UIntRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1590 break;
1591 case GL_RGBA32UI:
1592 case GL_RGBA:
1593 case GL_RGBA_INTEGER:
1594 case GL_BGRA_EXT:
Alexis Hetud9a2e7b2015-10-15 17:22:57 -04001595 case GL_BGRA8_EXT:
Alexis Hetud89ef672016-04-18 13:40:23 -04001596 LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001597 break;
1598 case GL_DEPTH_COMPONENT16:
1599 case GL_DEPTH_COMPONENT24:
1600 case GL_DEPTH_COMPONENT32_OES:
1601 case GL_DEPTH_COMPONENT:
1602 LoadImageData<D32>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1603 break;
1604 default: UNREACHABLE(format);
1605 }
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001606 break;
1607 case GL_UNSIGNED_INT_24_8_OES:
1608 loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1609 break;
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001610 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1611 loadD32FS8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer);
1612 break;
Nicolas Capens3713cd42015-06-22 10:41:54 -04001613 default: UNREACHABLE(type);
Nicolas Capens3d7a0952015-06-09 17:01:52 -04001614 }
1615 }
1616
1617 unlock();
1618 }
1619 else
1620 {
1621 sw::Surface source(width, height, depth, ConvertFormatType(format, type), const_cast<void*>(input), inputPitch, inputPitch * inputHeight);
1622 sw::Rect sourceRect(0, 0, width, height);
1623 sw::Rect destRect(xoffset, yoffset, xoffset + width, yoffset + height);
1624 sw::blitter.blit(&source, sourceRect, this, destRect, false);
1625 }
John Bauman66b8ab22014-05-06 15:57:45 -04001626 }
1627
Alexis Hetuc7b05102015-04-23 16:19:53 -04001628 void Image::loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
John Bauman66b8ab22014-05-06 15:57:45 -04001629 {
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001630 LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
John Bauman66b8ab22014-05-06 15:57:45 -04001631
Alexis Hetua52dfbd2016-10-05 17:03:30 -04001632 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC));
John Bauman66b8ab22014-05-06 15:57:45 -04001633
1634 if(stencil)
1635 {
Nicolas Capens1dfcb932015-06-09 17:06:31 -04001636 LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
John Bauman66b8ab22014-05-06 15:57:45 -04001637
1638 unlockStencil();
1639 }
1640 }
1641
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001642 void Image::loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer)
1643 {
1644 LoadImageData<D32F>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer);
1645
Alexis Hetua52dfbd2016-10-05 17:03:30 -04001646 unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC));
Alexis Hetu92ac42f2015-10-23 14:43:54 -04001647
1648 if(stencil)
1649 {
1650 LoadImageData<S24_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil);
1651
1652 unlockStencil();
1653 }
1654 }
1655
Alexis Hetub027aa92015-01-19 15:56:12 -05001656 void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
John Bauman66b8ab22014-05-06 15:57:45 -04001657 {
Alexis Hetub027aa92015-01-19 15:56:12 -05001658 if(zoffset != 0 || depth != 1)
1659 {
Nicolas Capensde6b75c2015-03-29 00:27:33 -04001660 UNIMPLEMENTED(); // FIXME
Alexis Hetub027aa92015-01-19 15:56:12 -05001661 }
1662
John Bauman66b8ab22014-05-06 15:57:45 -04001663 int inputPitch = ComputeCompressedPitch(width, format);
1664 int rows = imageSize / inputPitch;
1665 void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY);
1666
Alexis Hetufe7719c2015-01-22 16:49:40 -05001667 if(buffer)
1668 {
John Bauman66b8ab22014-05-06 15:57:45 -04001669 for(int i = 0; i < rows; i++)
1670 {
1671 memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch);
1672 }
Alexis Hetufe7719c2015-01-22 16:49:40 -05001673 }
John Baumand4ae8632014-05-06 16:18:33 -04001674
1675 unlock();
John Bauman66b8ab22014-05-06 15:57:45 -04001676 }
Ping-Hao Wub508ff82015-03-21 22:45:06 -07001677}