Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 3 | // 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 9 | // 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #include "Image.hpp" |
| 16 | |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 17 | #include "Renderer/Blitter.hpp" |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 18 | #include "../libEGL/Texture.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 19 | #include "../common/debug.h" |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 20 | #include "Common/Math.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 21 | #include "Common/Thread.hpp" |
| 22 | |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 23 | #include <GLES3/gl3.h> |
| 24 | |
| 25 | #include <string.h> |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 26 | |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 27 | namespace |
| 28 | { |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 29 | int getNumBlocks(int w, int h, int blockSizeX, int blockSizeY) |
| 30 | { |
| 31 | return ((w + blockSizeX - 1) / blockSizeX) * ((h + blockSizeY - 1) / blockSizeY); |
| 32 | } |
| 33 | |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 34 | enum DataType |
| 35 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 36 | Bytes_1, |
| 37 | Bytes_2, |
| 38 | Bytes_4, |
| 39 | Bytes_8, |
| 40 | Bytes_16, |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 41 | ByteRGB, |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 42 | UByteRGB, |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 43 | ShortRGB, |
| 44 | UShortRGB, |
| 45 | IntRGB, |
| 46 | UIntRGB, |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 47 | RGB565, |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 48 | FloatRGB, |
| 49 | HalfFloatRGB, |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 50 | RGBA4444, |
| 51 | RGBA5551, |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 52 | RGB10A2UI, |
| 53 | R11G11B10F, |
| 54 | RGB9E5, |
| 55 | SRGB, |
| 56 | SRGBA, |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 57 | D16, |
| 58 | D24, |
| 59 | D32, |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 60 | D32F, |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 61 | S8, |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 62 | S24_8, |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | template<DataType dataType> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 66 | void LoadImageRow(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 67 | { |
Alexis Hetu | 66d40e8 | 2015-01-27 14:09:34 -0500 | [diff] [blame] | 68 | UNIMPLEMENTED(); |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 71 | template<> |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 72 | void LoadImageRow<Bytes_1>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 73 | { |
| 74 | memcpy(dest + xoffset, source, width); |
| 75 | } |
| 76 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 77 | template<> |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 78 | 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 102 | 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 Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 116 | void LoadImageRow<UByteRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 117 | { |
| 118 | unsigned char *destB = dest + xoffset * 4; |
| 119 | |
| 120 | for(int x = 0; x < width; x++) |
| 121 | { |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 122 | destB[4 * x + 0] = source[x * 3 + 0]; |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 123 | destB[4 * x + 1] = source[x * 3 + 1]; |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 124 | destB[4 * x + 2] = source[x * 3 + 2]; |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 125 | destB[4 * x + 3] = 0xFF; |
| 126 | } |
| 127 | } |
| 128 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 129 | template<> |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 130 | 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 Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 190 | void LoadImageRow<RGB565>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 191 | { |
Nicolas Capens | 5a86ee9 | 2015-09-04 10:45:43 -0400 | [diff] [blame] | 192 | memcpy(dest + xoffset * 2, source, width * 2); |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 193 | } |
| 194 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 195 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 196 | void LoadImageRow<FloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 197 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 210 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 211 | void LoadImageRow<HalfFloatRGB>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 212 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 225 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 226 | void LoadImageRow<RGBA4444>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 227 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 241 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 242 | void LoadImageRow<RGBA5551>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 243 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 257 | template<> |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 258 | void LoadImageRow<RGB10A2UI>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 259 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 260 | 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 Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 273 | template<> |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 274 | void LoadImageRow<R11G11B10F>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 275 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 276 | 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 Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 329 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 330 | void LoadImageRow<D16>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 331 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 341 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 342 | void LoadImageRow<D24>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 343 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 353 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 354 | void LoadImageRow<D32>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 355 | { |
| 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 Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 365 | template<> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 366 | void LoadImageRow<S8>(const unsigned char *source, unsigned char *dest, GLint xoffset, GLsizei width) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 367 | { |
| 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 377 | 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 Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 403 | template<DataType dataType> |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 404 | 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 Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 405 | { |
| 406 | for(int z = 0; z < depth; ++z) |
| 407 | { |
Alexis Hetu | c7b0510 | 2015-04-23 16:19:53 -0400 | [diff] [blame] | 408 | const unsigned char *inputStart = static_cast<const unsigned char*>(input) + (z * inputPitch * inputHeight); |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 409 | unsigned char *destStart = static_cast<unsigned char*>(buffer) + ((zoffset + z) * destPitch * destHeight); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 410 | for(int y = 0; y < height; ++y) |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 411 | { |
| 412 | const unsigned char *source = inputStart + y * inputPitch; |
| 413 | unsigned char *dest = destStart + (y + yoffset) * destPitch; |
| 414 | |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 415 | LoadImageRow<dataType>(source, dest, xoffset, width); |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 421 | namespace egl |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 422 | { |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 423 | 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 434 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 435 | } |
| 436 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 437 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 443 | 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 450 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 451 | } |
| 452 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 453 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 459 | 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 468 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 469 | } |
| 470 | break; |
| 471 | case GL_BGRA_EXT: |
Alexis Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 472 | case GL_BGRA8_EXT: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 473 | switch(type) |
| 474 | { |
Nicolas Capens | 043c19f | 2016-02-12 17:06:31 -0500 | [diff] [blame] | 475 | 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 478 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 479 | } |
| 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 489 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 490 | } |
| 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 Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 499 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 500 | } |
| 501 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 502 | 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 Hetu | 1abb638 | 2016-02-08 11:21:16 -0500 | [diff] [blame] | 508 | 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 Sheu | bc07bf6 | 2016-04-18 18:53:47 -0700 | [diff] [blame] | 532 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 542 | default: |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 543 | UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return sw::FORMAT_NULL; |
| 547 | } |
| 548 | |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 549 | sw::Format SelectInternalFormat(GLenum format, GLenum type) |
| 550 | { |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 551 | switch(format) |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 552 | { |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 553 | case GL_ETC1_RGB8_OES: |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 554 | return sw::FORMAT_ETC1; |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 555 | 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 Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 631 | #if S3TC_SUPPORT |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 632 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 633 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 634 | return sw::FORMAT_DXT1; |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 635 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 636 | return sw::FORMAT_DXT3; |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 637 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 638 | return sw::FORMAT_DXT5; |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 639 | #endif |
Alexis Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 640 | default: |
| 641 | break; |
| 642 | } |
| 643 | |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 644 | switch(type) |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 645 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 646 | case GL_FLOAT: |
| 647 | switch(format) |
| 648 | { |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 649 | 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 658 | 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 Hetu | dbd1a8e | 2016-04-13 11:40:30 -0400 | [diff] [blame] | 666 | return sw::FORMAT_X32B32G32R32F; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 667 | case GL_RGBA: |
| 668 | case GL_RGBA32F: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 669 | return sw::FORMAT_A32B32G32R32F; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 670 | 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 Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 680 | 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 689 | 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 Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 699 | return sw::FORMAT_A16B16G16R16F; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 700 | default: |
| 701 | UNREACHABLE(format); |
| 702 | } |
| 703 | case GL_BYTE: |
| 704 | switch(format) |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 705 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 706 | 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 Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 742 | return sw::FORMAT_L8; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 743 | case GL_LUMINANCE_ALPHA: |
| 744 | case GL_LUMINANCE8_ALPHA8_EXT: |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 745 | return sw::FORMAT_A8L8; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 746 | 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 Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 764 | return sw::FORMAT_X8B8G8R8; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 765 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 777 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 778 | return sw::FORMAT_A8R8G8B8; |
| 779 | case GL_ALPHA: |
| 780 | case GL_ALPHA8_EXT: |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 781 | return sw::FORMAT_A8; |
Nicolas Capens | cbb8b39 | 2015-11-06 16:01:11 -0500 | [diff] [blame] | 782 | 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 788 | default: |
| 789 | UNREACHABLE(format); |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 790 | } |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 791 | case GL_SHORT: |
| 792 | switch(format) |
Nicolas Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 793 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 794 | 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 Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 808 | } |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 809 | case GL_UNSIGNED_SHORT: |
| 810 | switch(format) |
Nicolas Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 811 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 812 | 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 Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 829 | } |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 830 | case GL_INT: |
| 831 | switch(format) |
Nicolas Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 832 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 833 | 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 Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 847 | } |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 848 | 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 Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 873 | { |
| 874 | return sw::FORMAT_D32FS8_TEXTURE; |
| 875 | } |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 876 | else UNREACHABLE(format); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 877 | case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
| 878 | if(format == GL_DEPTH_STENCIL || format == GL_DEPTH32F_STENCIL8) |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 879 | { |
| 880 | return sw::FORMAT_D32FS8_TEXTURE; |
| 881 | } |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 882 | else UNREACHABLE(format); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 883 | case GL_UNSIGNED_SHORT_4_4_4_4: |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 884 | return sw::FORMAT_A8R8G8B8; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 885 | case GL_UNSIGNED_SHORT_5_5_5_1: |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 886 | return sw::FORMAT_A8R8G8B8; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 887 | case GL_UNSIGNED_SHORT_5_6_5: |
Nicolas Capens | 5a86ee9 | 2015-09-04 10:45:43 -0400 | [diff] [blame] | 888 | return sw::FORMAT_R5G6B5; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 889 | 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 Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 901 | default: |
| 902 | UNREACHABLE(type); |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 903 | } |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 904 | |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 905 | return sw::FORMAT_NULL; |
Nicolas Capens | 2c4edc2 | 2015-06-09 16:59:22 -0400 | [diff] [blame] | 906 | } |
| 907 | |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 908 | // Returns the size, in bytes, of a single texel in an Image |
Nicolas Capens | 8e8a7e8 | 2015-09-01 14:39:57 -0400 | [diff] [blame] | 909 | static int ComputePixelSize(GLenum format, GLenum type) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 910 | { |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 911 | switch(type) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 912 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 913 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 939 | case GL_UNSIGNED_BYTE: |
| 940 | switch(format) |
| 941 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 942 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 947 | case GL_ALPHA: return sizeof(unsigned char); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 948 | case GL_LUMINANCE8_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 949 | case GL_LUMINANCE: return sizeof(unsigned char); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 950 | case GL_LUMINANCE8_ALPHA8_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 951 | case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 952 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 959 | case GL_RGB: return sizeof(unsigned char) * 3; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 960 | case GL_RGB_INTEGER: return sizeof(unsigned char) * 3; |
| 961 | case GL_RGBA8: |
| 962 | case GL_RGBA8UI: |
| 963 | case GL_SRGB8_ALPHA8: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 964 | case GL_RGBA: return sizeof(unsigned char) * 4; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 965 | case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4; |
Alexis Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 966 | case GL_BGRA_EXT: |
| 967 | case GL_BGRA8_EXT: return sizeof(unsigned char)* 4; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 968 | default: UNREACHABLE(format); |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 969 | } |
| 970 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 971 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1033 | 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 Capens | 043c19f | 2016-02-12 17:06:31 -0500 | [diff] [blame] | 1036 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 1037 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1038 | return sizeof(unsigned short); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1039 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1042 | case GL_UNSIGNED_INT_24_8_OES: |
| 1043 | return sizeof(unsigned int); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1044 | case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
| 1045 | return sizeof(float) + sizeof(unsigned int); |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1046 | case GL_FLOAT: |
| 1047 | switch(format) |
| 1048 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1049 | case GL_DEPTH_COMPONENT32F: |
| 1050 | case GL_DEPTH_COMPONENT: return sizeof(float); |
| 1051 | case GL_ALPHA32F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1052 | case GL_ALPHA: return sizeof(float); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1053 | case GL_LUMINANCE32F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1054 | case GL_LUMINANCE: return sizeof(float); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1055 | case GL_LUMINANCE_ALPHA32F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1056 | case GL_LUMINANCE_ALPHA: return sizeof(float) * 2; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1057 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1061 | case GL_RGB: return sizeof(float) * 3; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1062 | case GL_RGB32F: return sizeof(float) * 3; |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1063 | case GL_RGBA: return sizeof(float) * 4; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1064 | case GL_RGBA32F: return sizeof(float) * 4; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1065 | default: UNREACHABLE(format); |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1066 | } |
| 1067 | break; |
Alexis Hetu | 6116150 | 2015-05-21 11:45:03 -0400 | [diff] [blame] | 1068 | case GL_HALF_FLOAT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1069 | case GL_HALF_FLOAT_OES: |
| 1070 | switch(format) |
| 1071 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1072 | case GL_ALPHA16F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1073 | case GL_ALPHA: return sizeof(unsigned short); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1074 | case GL_LUMINANCE16F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1075 | case GL_LUMINANCE: return sizeof(unsigned short); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1076 | case GL_LUMINANCE_ALPHA16F_EXT: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1077 | case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1078 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1082 | case GL_RGB: return sizeof(unsigned short) * 3; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1083 | case GL_RGB16F: return sizeof(unsigned short) * 3; |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1084 | case GL_RGBA: return sizeof(unsigned short) * 4; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1085 | case GL_RGBA16F: return sizeof(unsigned short) * 4; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1086 | default: UNREACHABLE(format); |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1087 | } |
| 1088 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1089 | default: UNREACHABLE(type); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | return 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1095 | GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment) |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 1096 | { |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1097 | ASSERT(alignment > 0 && sw::isPow2(alignment)); |
| 1098 | |
| 1099 | GLsizei rawPitch = ComputePixelSize(format, type) * width; |
| 1100 | return (rawPitch + alignment - 1) & ~(alignment - 1); |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
Alexis Hetu | 9bdbaa0 | 2016-02-08 11:08:03 -0500 | [diff] [blame] | 1103 | 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 Capens | 1c6f53c | 2015-12-31 11:30:40 -0500 | [diff] [blame] | 1109 | inline GLsizei ComputeCompressedPitch(GLsizei width, GLenum format) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1110 | { |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1111 | return ComputeCompressedSize(width, 1, format); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1114 | GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1115 | { |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1116 | switch(format) |
| 1117 | { |
| 1118 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1119 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1120 | case GL_ETC1_RGB8_OES: |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1121 | 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 Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 1127 | return 8 * getNumBlocks(width, height, 4, 4); |
Nicolas Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1128 | 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 Hetu | 460e41f | 2015-09-01 10:58:37 -0400 | [diff] [blame] | 1134 | 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 Capens | deda34b | 2015-04-28 15:21:53 -0700 | [diff] [blame] | 1176 | default: |
| 1177 | return 0; |
| 1178 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Alexis Hetu | 147f668 | 2017-02-09 17:14:34 -0500 | [diff] [blame] | 1181 | void Image::typeinfo() {} |
| 1182 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1183 | Image::~Image() |
| 1184 | { |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1185 | if(parentTexture) |
| 1186 | { |
Nicolas Capens | 35b16cf | 2016-02-07 22:25:26 -0500 | [diff] [blame] | 1187 | parentTexture->release(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1188 | } |
Nicolas Capens | b2022a7 | 2016-02-04 14:53:38 -0500 | [diff] [blame] | 1189 | |
Nicolas Capens | 35b16cf | 2016-02-07 22:25:26 -0500 | [diff] [blame] | 1190 | ASSERT(!shared); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | void Image::release() |
| 1194 | { |
Nicolas Capens | 35b16cf | 2016-02-07 22:25:26 -0500 | [diff] [blame] | 1195 | int refs = dereference(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1196 | |
Nicolas Capens | 35b16cf | 2016-02-07 22:25:26 -0500 | [diff] [blame] | 1197 | if(refs > 0) |
| 1198 | { |
| 1199 | if(parentTexture) |
| 1200 | { |
| 1201 | parentTexture->sweep(); |
| 1202 | } |
| 1203 | } |
| 1204 | else |
| 1205 | { |
| 1206 | delete this; |
| 1207 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1208 | } |
| 1209 | |
Nicolas Capens | fa0cc04 | 2014-12-10 10:17:07 -0500 | [diff] [blame] | 1210 | void Image::unbind(const egl::Texture *parent) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1211 | { |
Nicolas Capens | fa0cc04 | 2014-12-10 10:17:07 -0500 | [diff] [blame] | 1212 | if(parentTexture == parent) |
| 1213 | { |
Nicolas Capens | b2022a7 | 2016-02-04 14:53:38 -0500 | [diff] [blame] | 1214 | parentTexture = nullptr; |
Nicolas Capens | fa0cc04 | 2014-12-10 10:17:07 -0500 | [diff] [blame] | 1215 | } |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1216 | |
| 1217 | release(); |
| 1218 | } |
| 1219 | |
Nicolas Capens | c360363 | 2016-02-07 22:19:45 -0500 | [diff] [blame] | 1220 | bool Image::isChildOf(const egl::Texture *parent) const |
| 1221 | { |
| 1222 | return parentTexture == parent; |
| 1223 | } |
| 1224 | |
Alexis Hetu | c7b0510 | 2015-04-23 16:19:53 -0400 | [diff] [blame] | 1225 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1226 | { |
Alexis Hetu | 9bdbaa0 | 2016-02-08 11:08:03 -0500 | [diff] [blame] | 1227 | GLsizei inputWidth = (unpackInfo.rowLength == 0) ? width : unpackInfo.rowLength; |
| 1228 | GLsizei inputPitch = ComputePitch(inputWidth, format, type, unpackInfo.alignment); |
Alexis Hetu | c7b0510 | 2015-04-23 16:19:53 -0400 | [diff] [blame] | 1229 | GLsizei inputHeight = (unpackInfo.imageHeight == 0) ? height : unpackInfo.imageHeight; |
Alexis Hetu | 9bdbaa0 | 2016-02-08 11:08:03 -0500 | [diff] [blame] | 1230 | input = ((char*)input) + ComputePackingOffset(format, type, inputWidth, inputHeight, unpackInfo.alignment, unpackInfo.skipImages, unpackInfo.skipRows, unpackInfo.skipPixels); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1231 | sw::Format selectedInternalFormat = SelectInternalFormat(format, type); |
| 1232 | if(selectedInternalFormat == sw::FORMAT_NULL) |
| 1233 | { |
| 1234 | return; |
| 1235 | } |
Nicolas Capens | d45d14a | 2015-04-01 15:59:10 -0400 | [diff] [blame] | 1236 | |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1237 | if(selectedInternalFormat == internalFormat) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1238 | { |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1239 | void *buffer = lock(0, 0, sw::LOCK_WRITEONLY); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1240 | |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1241 | if(buffer) |
| 1242 | { |
| 1243 | switch(type) |
| 1244 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1245 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1281 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1282 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1287 | case GL_UNSIGNED_BYTE: |
| 1288 | switch(format) |
| 1289 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1290 | case GL_R8: |
| 1291 | case GL_R8UI: |
| 1292 | case GL_R8_SNORM: |
| 1293 | case GL_RED: |
| 1294 | case GL_RED_INTEGER: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1295 | case GL_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1296 | case GL_ALPHA8_EXT: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1297 | case GL_LUMINANCE: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1298 | case GL_LUMINANCE8_EXT: |
| 1299 | LoadImageData<Bytes_1>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1300 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1301 | case GL_RG8: |
| 1302 | case GL_RG8UI: |
| 1303 | case GL_RG8_SNORM: |
| 1304 | case GL_RG: |
| 1305 | case GL_RG_INTEGER: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1306 | case GL_LUMINANCE_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1307 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 1308 | LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1309 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1310 | case GL_RGB8: |
| 1311 | case GL_RGB8UI: |
| 1312 | case GL_RGB8_SNORM: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1313 | case GL_RGB: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1314 | case GL_RGB_INTEGER: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1315 | LoadImageData<UByteRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1316 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1317 | case GL_RGBA8: |
| 1318 | case GL_RGBA8UI: |
| 1319 | case GL_RGBA8_SNORM: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1320 | case GL_RGBA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1321 | case GL_RGBA_INTEGER: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1322 | case GL_BGRA_EXT: |
Alexis Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1323 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1324 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1331 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1332 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1333 | } |
| 1334 | break; |
| 1335 | case GL_UNSIGNED_SHORT_5_6_5: |
| 1336 | switch(format) |
| 1337 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1338 | case GL_RGB565: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1339 | case GL_RGB: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1340 | LoadImageData<RGB565>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1341 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1342 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1343 | } |
| 1344 | break; |
| 1345 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 1346 | switch(format) |
| 1347 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1348 | case GL_RGBA4: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1349 | case GL_RGBA: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1350 | LoadImageData<RGBA4444>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1351 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1352 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1353 | } |
| 1354 | break; |
| 1355 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 1356 | switch(format) |
| 1357 | { |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1358 | case GL_RGB5_A1: |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1359 | case GL_RGBA: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1360 | LoadImageData<RGBA5551>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1361 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1362 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1363 | } |
| 1364 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1365 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1399 | case GL_FLOAT: |
| 1400 | switch(format) |
| 1401 | { |
| 1402 | // float textures are converted to RGBA, not BGRA |
| 1403 | case GL_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1404 | case GL_ALPHA32F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1405 | LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1406 | break; |
| 1407 | case GL_LUMINANCE: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1408 | case GL_LUMINANCE32F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1409 | LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1410 | break; |
| 1411 | case GL_LUMINANCE_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1412 | case GL_LUMINANCE_ALPHA32F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1413 | LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1414 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1415 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1423 | case GL_RGB: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1424 | case GL_RGB32F: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1425 | LoadImageData<FloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1426 | break; |
| 1427 | case GL_RGBA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1428 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1434 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1435 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1436 | } |
| 1437 | break; |
| 1438 | case GL_HALF_FLOAT: |
| 1439 | case GL_HALF_FLOAT_OES: |
| 1440 | switch(format) |
| 1441 | { |
| 1442 | case GL_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1443 | case GL_ALPHA16F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1444 | LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1445 | break; |
| 1446 | case GL_LUMINANCE: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1447 | case GL_LUMINANCE16F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1448 | LoadImageData<Bytes_2>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1449 | break; |
| 1450 | case GL_LUMINANCE_ALPHA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1451 | case GL_LUMINANCE_ALPHA16F_EXT: |
Nicolas Capens | f33f4bc | 2015-10-28 18:53:23 -0400 | [diff] [blame] | 1452 | LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1453 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1454 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1462 | case GL_RGB: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1463 | case GL_RGB16F: |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1464 | LoadImageData<HalfFloatRGB>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1465 | break; |
| 1466 | case GL_RGBA: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1467 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1498 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1499 | LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1500 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1501 | default: UNREACHABLE(format); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1502 | } |
| 1503 | break; |
| 1504 | case GL_UNSIGNED_SHORT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1505 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1529 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1530 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1564 | case GL_BGRA8_EXT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1565 | LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
| 1566 | break; |
| 1567 | default: UNREACHABLE(format); |
| 1568 | } |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1569 | break; |
| 1570 | case GL_UNSIGNED_INT: |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1571 | 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 Hetu | d89ef67 | 2016-04-18 13:40:23 -0400 | [diff] [blame] | 1578 | LoadImageData<Bytes_4>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1579 | break; |
| 1580 | case GL_RG32UI: |
| 1581 | case GL_RG: |
| 1582 | case GL_RG_INTEGER: |
| 1583 | case GL_LUMINANCE_ALPHA: |
Alexis Hetu | d89ef67 | 2016-04-18 13:40:23 -0400 | [diff] [blame] | 1584 | LoadImageData<Bytes_8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1585 | 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 Hetu | d9a2e7b | 2015-10-15 17:22:57 -0400 | [diff] [blame] | 1595 | case GL_BGRA8_EXT: |
Alexis Hetu | d89ef67 | 2016-04-18 13:40:23 -0400 | [diff] [blame] | 1596 | LoadImageData<Bytes_16>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1597 | 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 Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1606 | break; |
| 1607 | case GL_UNSIGNED_INT_24_8_OES: |
| 1608 | loadD24S8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer); |
| 1609 | break; |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1610 | case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
| 1611 | loadD32FS8ImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, input, buffer); |
| 1612 | break; |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 1613 | default: UNREACHABLE(type); |
Nicolas Capens | 3d7a095 | 2015-06-09 17:01:52 -0400 | [diff] [blame] | 1614 | } |
| 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
Alexis Hetu | c7b0510 | 2015-04-23 16:19:53 -0400 | [diff] [blame] | 1628 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1629 | { |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1630 | LoadImageData<D24>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1631 | |
Alexis Hetu | a52dfbd | 2016-10-05 17:03:30 -0400 | [diff] [blame] | 1632 | unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1633 | |
| 1634 | if(stencil) |
| 1635 | { |
Nicolas Capens | 1dfcb93 | 2015-06-09 17:06:31 -0400 | [diff] [blame] | 1636 | LoadImageData<S8>(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getStencilPitchB(), getHeight(), input, stencil); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1637 | |
| 1638 | unlockStencil(); |
| 1639 | } |
| 1640 | } |
| 1641 | |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1642 | 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 Hetu | a52dfbd | 2016-10-05 17:03:30 -0400 | [diff] [blame] | 1646 | unsigned char *stencil = reinterpret_cast<unsigned char*>(lockStencil(0, 0, 0, sw::PUBLIC)); |
Alexis Hetu | 92ac42f | 2015-10-23 14:43:54 -0400 | [diff] [blame] | 1647 | |
| 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 Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 1656 | void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1657 | { |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 1658 | if(zoffset != 0 || depth != 1) |
| 1659 | { |
Nicolas Capens | de6b75c | 2015-03-29 00:27:33 -0400 | [diff] [blame] | 1660 | UNIMPLEMENTED(); // FIXME |
Alexis Hetu | b027aa9 | 2015-01-19 15:56:12 -0500 | [diff] [blame] | 1661 | } |
| 1662 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1663 | int inputPitch = ComputeCompressedPitch(width, format); |
| 1664 | int rows = imageSize / inputPitch; |
| 1665 | void *buffer = lock(xoffset, yoffset, sw::LOCK_WRITEONLY); |
| 1666 | |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 1667 | if(buffer) |
| 1668 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1669 | for(int i = 0; i < rows; i++) |
| 1670 | { |
| 1671 | memcpy((void*)((GLbyte*)buffer + i * getPitch()), (void*)((GLbyte*)pixels + i * inputPitch), inputPitch); |
| 1672 | } |
Alexis Hetu | fe7719c | 2015-01-22 16:49:40 -0500 | [diff] [blame] | 1673 | } |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 1674 | |
| 1675 | unlock(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1676 | } |
Ping-Hao Wu | b508ff8 | 2015-03-21 22:45:06 -0700 | [diff] [blame] | 1677 | } |