Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 1 | // |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 6 | // renderer_utils: |
| 7 | // Helper methods pertaining to most or all back-ends. |
| 8 | // |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 9 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 10 | #include "libANGLE/renderer/renderer_utils.h" |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 11 | |
Geoff Lang | 6e4cfce | 2016-06-13 15:06:31 -0400 | [diff] [blame^] | 12 | #include "image_util/copyimage.h" |
| 13 | #include "image_util/imageformats.h" |
| 14 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 15 | #include "libANGLE/formatutils.h" |
Geoff Lang | 6e4cfce | 2016-06-13 15:06:31 -0400 | [diff] [blame^] | 16 | |
| 17 | #include <string.h> |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 18 | |
| 19 | namespace rx |
| 20 | { |
| 21 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 22 | namespace |
| 23 | { |
| 24 | typedef std::pair<gl::FormatType, ColorWriteFunction> FormatWriteFunctionPair; |
| 25 | typedef std::map<gl::FormatType, ColorWriteFunction> FormatWriteFunctionMap; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 26 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 27 | static inline void InsertFormatWriteFunctionMapping(FormatWriteFunctionMap *map, |
| 28 | GLenum format, |
| 29 | GLenum type, |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 30 | ColorWriteFunction writeFunc) |
| 31 | { |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 32 | map->insert(FormatWriteFunctionPair(gl::FormatType(format, type), writeFunc)); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static FormatWriteFunctionMap BuildFormatWriteFunctionMap() |
| 36 | { |
Geoff Lang | 6e4cfce | 2016-06-13 15:06:31 -0400 | [diff] [blame^] | 37 | using namespace angle; // For image writing functions |
| 38 | |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 39 | FormatWriteFunctionMap map; |
| 40 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 41 | // clang-format off |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 42 | // | Format | Type | Color write function | |
| 43 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> ); |
| 44 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_BYTE, WriteColor<R8G8B8A8S, GLfloat> ); |
| 45 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, WriteColor<R4G4B4A4, GLfloat> ); |
| 46 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, WriteColor<R5G5B5A1, GLfloat> ); |
| 47 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLfloat> ); |
| 48 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_FLOAT, WriteColor<R32G32B32A32F, GLfloat>); |
| 49 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT, WriteColor<R16G16B16A16F, GLfloat>); |
| 50 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, WriteColor<R16G16B16A16F, GLfloat>); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 51 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT, |
| 52 | WriteColor<R16G16B16A16, GLfloat>); |
| 53 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_SHORT, WriteColor<R16G16B16A16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 54 | |
| 55 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLuint> ); |
| 56 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_BYTE, WriteColor<R8G8B8A8S, GLint> ); |
| 57 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16A16, GLuint> ); |
| 58 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_SHORT, WriteColor<R16G16B16A16S, GLint> ); |
| 59 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32A32, GLuint> ); |
| 60 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_INT, WriteColor<R32G32B32A32S, GLint> ); |
| 61 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLuint> ); |
| 62 | |
| 63 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> ); |
| 64 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_BYTE, WriteColor<R8G8B8S, GLfloat> ); |
| 65 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, WriteColor<R5G6B5, GLfloat> ); |
| 66 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, WriteColor<R11G11B10F, GLfloat> ); |
| 67 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, WriteColor<R9G9B9E5, GLfloat> ); |
| 68 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_FLOAT, WriteColor<R32G32B32F, GLfloat> ); |
| 69 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT, WriteColor<R16G16B16F, GLfloat> ); |
| 70 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, WriteColor<R16G16B16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 71 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT, |
| 72 | WriteColor<R16G16B16, GLfloat>); |
| 73 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_SHORT, WriteColor<R16G16B16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 74 | |
| 75 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLuint> ); |
| 76 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_BYTE, WriteColor<R8G8B8S, GLint> ); |
| 77 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16, GLuint> ); |
| 78 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_SHORT, WriteColor<R16G16B16S, GLint> ); |
| 79 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32, GLuint> ); |
| 80 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_INT, WriteColor<R32G32B32S, GLint> ); |
| 81 | |
| 82 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLfloat> ); |
| 83 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_BYTE, WriteColor<R8G8S, GLfloat> ); |
| 84 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_FLOAT, WriteColor<R32G32F, GLfloat> ); |
| 85 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT, WriteColor<R16G16F, GLfloat> ); |
| 86 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT_OES, WriteColor<R16G16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 87 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLfloat>); |
| 88 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_SHORT, WriteColor<R16G16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 89 | |
| 90 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLuint> ); |
| 91 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_BYTE, WriteColor<R8G8S, GLint> ); |
| 92 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLuint> ); |
| 93 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_SHORT, WriteColor<R16G16S, GLint> ); |
| 94 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32, GLuint> ); |
| 95 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_INT, WriteColor<R32G32S, GLint> ); |
| 96 | |
| 97 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_BYTE, WriteColor<R8, GLfloat> ); |
| 98 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_BYTE, WriteColor<R8S, GLfloat> ); |
| 99 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_FLOAT, WriteColor<R32F, GLfloat> ); |
| 100 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT, WriteColor<R16F, GLfloat> ); |
| 101 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT_OES, WriteColor<R16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 102 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_SHORT, WriteColor<R16, GLfloat>); |
| 103 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_SHORT, WriteColor<R16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 104 | |
| 105 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8, GLuint> ); |
| 106 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_BYTE, WriteColor<R8S, GLint> ); |
| 107 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16, GLuint> ); |
| 108 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_SHORT, WriteColor<R16S, GLint> ); |
| 109 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, WriteColor<R32, GLuint> ); |
| 110 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_INT, WriteColor<R32S, GLint> ); |
| 111 | |
| 112 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, WriteColor<L8A8, GLfloat> ); |
| 113 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, WriteColor<L8, GLfloat> ); |
| 114 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, WriteColor<A8, GLfloat> ); |
| 115 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, WriteColor<L32A32F, GLfloat> ); |
| 116 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_FLOAT, WriteColor<L32F, GLfloat> ); |
| 117 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_FLOAT, WriteColor<A32F, GLfloat> ); |
| 118 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, WriteColor<L16A16F, GLfloat> ); |
| 119 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, WriteColor<L16A16F, GLfloat> ); |
| 120 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, WriteColor<L16F, GLfloat> ); |
| 121 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, WriteColor<L16F, GLfloat> ); |
| 122 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT, WriteColor<A16F, GLfloat> ); |
| 123 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, WriteColor<A16F, GLfloat> ); |
| 124 | |
| 125 | InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, WriteColor<B8G8R8A8, GLfloat> ); |
Austin Kinross | 5cf0f98 | 2015-08-12 09:35:10 -0700 | [diff] [blame] | 126 | InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, WriteColor<A4R4G4B4, GLfloat> ); |
| 127 | InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, WriteColor<A1R5G5B5, GLfloat> ); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 128 | |
| 129 | InsertFormatWriteFunctionMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> ); |
| 130 | InsertFormatWriteFunctionMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> ); |
| 131 | |
| 132 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, NULL ); |
| 133 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, NULL ); |
| 134 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, NULL ); |
| 135 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, NULL ); |
| 136 | |
| 137 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL ); |
| 138 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL ); |
| 139 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, NULL ); |
| 140 | |
| 141 | InsertFormatWriteFunctionMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, NULL ); |
| 142 | |
| 143 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL ); |
| 144 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL ); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 145 | // clang-format on |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 146 | |
| 147 | return map; |
| 148 | } |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 149 | } // anonymous namespace |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 150 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 151 | PackPixelsParams::PackPixelsParams() |
| 152 | : format(GL_NONE), type(GL_NONE), outputPitch(0), packBuffer(nullptr), offset(0) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn, |
| 157 | GLenum formatIn, |
| 158 | GLenum typeIn, |
| 159 | GLuint outputPitchIn, |
| 160 | const gl::PixelPackState &packIn, |
| 161 | ptrdiff_t offsetIn) |
| 162 | : area(areaIn), |
| 163 | format(formatIn), |
| 164 | type(typeIn), |
| 165 | outputPitch(outputPitchIn), |
| 166 | packBuffer(packIn.pixelBuffer.get()), |
| 167 | pack(packIn.alignment, packIn.reverseRowOrder), |
| 168 | offset(offsetIn) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | void PackPixels(const PackPixelsParams ¶ms, |
| 173 | const gl::InternalFormat &sourceFormatInfo, |
| 174 | const FastCopyFunctionMap &fastCopyFunctionsMap, |
| 175 | ColorReadFunction colorReadFunction, |
| 176 | int inputPitchIn, |
| 177 | const uint8_t *sourceIn, |
| 178 | uint8_t *destWithoutOffset) |
| 179 | { |
| 180 | uint8_t *destWithOffset = destWithoutOffset + params.offset; |
| 181 | |
| 182 | const uint8_t *source = sourceIn; |
| 183 | int inputPitch = inputPitchIn; |
| 184 | |
| 185 | if (params.pack.reverseRowOrder) |
| 186 | { |
| 187 | source += inputPitch * (params.area.height - 1); |
| 188 | inputPitch = -inputPitch; |
| 189 | } |
| 190 | |
| 191 | if (sourceFormatInfo.format == params.format && sourceFormatInfo.type == params.type) |
| 192 | { |
| 193 | // Direct copy possible |
| 194 | for (int y = 0; y < params.area.height; ++y) |
| 195 | { |
| 196 | memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch, |
| 197 | params.area.width * sourceFormatInfo.pixelBytes); |
| 198 | } |
| 199 | return; |
| 200 | } |
| 201 | |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 202 | ASSERT(sourceFormatInfo.pixelBytes > 0); |
| 203 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 204 | gl::FormatType formatType(params.format, params.type); |
| 205 | ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType); |
| 206 | GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(formatType.format, formatType.type); |
| 207 | const auto &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat); |
| 208 | |
| 209 | if (fastCopyFunc) |
| 210 | { |
| 211 | // Fast copy is possible through some special function |
| 212 | for (int y = 0; y < params.area.height; ++y) |
| 213 | { |
| 214 | for (int x = 0; x < params.area.width; ++x) |
| 215 | { |
| 216 | uint8_t *dest = |
| 217 | destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; |
| 218 | const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes; |
| 219 | |
| 220 | fastCopyFunc(src, dest); |
| 221 | } |
| 222 | } |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | ColorWriteFunction colorWriteFunction = GetColorWriteFunction(formatType); |
| 227 | |
| 228 | // Maximum size of any Color<T> type used. |
| 229 | uint8_t temp[16]; |
| 230 | static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) && |
| 231 | sizeof(temp) >= sizeof(gl::ColorI), |
| 232 | "Unexpected size of gl::Color struct."); |
| 233 | |
| 234 | for (int y = 0; y < params.area.height; ++y) |
| 235 | { |
| 236 | for (int x = 0; x < params.area.width; ++x) |
| 237 | { |
| 238 | uint8_t *dest = destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; |
| 239 | const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes; |
| 240 | |
| 241 | // readFunc and writeFunc will be using the same type of color, CopyTexImage |
| 242 | // will not allow the copy otherwise. |
| 243 | colorReadFunction(src, temp); |
| 244 | colorWriteFunction(temp, dest); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType) |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 250 | { |
| 251 | static const FormatWriteFunctionMap formatTypeMap = BuildFormatWriteFunctionMap(); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 252 | auto iter = formatTypeMap.find(formatType); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 253 | ASSERT(iter != formatTypeMap.end()); |
| 254 | if (iter != formatTypeMap.end()) |
| 255 | { |
| 256 | return iter->second; |
| 257 | } |
| 258 | else |
| 259 | { |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 260 | return nullptr; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 264 | ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions, |
| 265 | const gl::FormatType &formatType) |
| 266 | { |
| 267 | auto iter = fastCopyFunctions.find(formatType); |
| 268 | return (iter != fastCopyFunctions.end()) ? iter->second : nullptr; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 269 | } |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 270 | |
| 271 | } // namespace rx |