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 | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 15 | #include "libANGLE/AttributeMap.h" |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 16 | #include "libANGLE/Context.h" |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 17 | #include "libANGLE/formatutils.h" |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 18 | #include "libANGLE/renderer/ContextImpl.h" |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 19 | #include "libANGLE/renderer/Format.h" |
Geoff Lang | 6e4cfce | 2016-06-13 15:06:31 -0400 | [diff] [blame] | 20 | |
| 21 | #include <string.h> |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 22 | #include "common/utilities.h" |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 23 | |
| 24 | namespace rx |
| 25 | { |
| 26 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 27 | namespace |
| 28 | { |
| 29 | typedef std::pair<gl::FormatType, ColorWriteFunction> FormatWriteFunctionPair; |
| 30 | typedef std::map<gl::FormatType, ColorWriteFunction> FormatWriteFunctionMap; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 31 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 32 | static inline void InsertFormatWriteFunctionMapping(FormatWriteFunctionMap *map, |
| 33 | GLenum format, |
| 34 | GLenum type, |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 35 | ColorWriteFunction writeFunc) |
| 36 | { |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 37 | map->insert(FormatWriteFunctionPair(gl::FormatType(format, type), writeFunc)); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static FormatWriteFunctionMap BuildFormatWriteFunctionMap() |
| 41 | { |
Geoff Lang | 6e4cfce | 2016-06-13 15:06:31 -0400 | [diff] [blame] | 42 | using namespace angle; // For image writing functions |
| 43 | |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 44 | FormatWriteFunctionMap map; |
| 45 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 46 | // clang-format off |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 47 | // | Format | Type | Color write function | |
| 48 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> ); |
| 49 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_BYTE, WriteColor<R8G8B8A8S, GLfloat> ); |
| 50 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, WriteColor<R4G4B4A4, GLfloat> ); |
| 51 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, WriteColor<R5G5B5A1, GLfloat> ); |
| 52 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLfloat> ); |
| 53 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_FLOAT, WriteColor<R32G32B32A32F, GLfloat>); |
| 54 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT, WriteColor<R16G16B16A16F, GLfloat>); |
| 55 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, WriteColor<R16G16B16A16F, GLfloat>); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 56 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT, |
| 57 | WriteColor<R16G16B16A16, GLfloat>); |
| 58 | InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_SHORT, WriteColor<R16G16B16A16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 59 | |
| 60 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLuint> ); |
| 61 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_BYTE, WriteColor<R8G8B8A8S, GLint> ); |
| 62 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16A16, GLuint> ); |
| 63 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_SHORT, WriteColor<R16G16B16A16S, GLint> ); |
| 64 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32A32, GLuint> ); |
| 65 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_INT, WriteColor<R32G32B32A32S, GLint> ); |
| 66 | InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLuint> ); |
| 67 | |
| 68 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> ); |
| 69 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_BYTE, WriteColor<R8G8B8S, GLfloat> ); |
| 70 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, WriteColor<R5G6B5, GLfloat> ); |
| 71 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, WriteColor<R11G11B10F, GLfloat> ); |
| 72 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, WriteColor<R9G9B9E5, GLfloat> ); |
| 73 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_FLOAT, WriteColor<R32G32B32F, GLfloat> ); |
| 74 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT, WriteColor<R16G16B16F, GLfloat> ); |
| 75 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, WriteColor<R16G16B16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 76 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT, |
| 77 | WriteColor<R16G16B16, GLfloat>); |
| 78 | InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_SHORT, WriteColor<R16G16B16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 79 | |
| 80 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLuint> ); |
| 81 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_BYTE, WriteColor<R8G8B8S, GLint> ); |
| 82 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16, GLuint> ); |
| 83 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_SHORT, WriteColor<R16G16B16S, GLint> ); |
| 84 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32, GLuint> ); |
| 85 | InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_INT, WriteColor<R32G32B32S, GLint> ); |
| 86 | |
| 87 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLfloat> ); |
| 88 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_BYTE, WriteColor<R8G8S, GLfloat> ); |
| 89 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_FLOAT, WriteColor<R32G32F, GLfloat> ); |
| 90 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT, WriteColor<R16G16F, GLfloat> ); |
| 91 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT_OES, WriteColor<R16G16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 92 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLfloat>); |
| 93 | InsertFormatWriteFunctionMapping(&map, GL_RG, GL_SHORT, WriteColor<R16G16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 94 | |
| 95 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLuint> ); |
| 96 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_BYTE, WriteColor<R8G8S, GLint> ); |
| 97 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLuint> ); |
| 98 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_SHORT, WriteColor<R16G16S, GLint> ); |
| 99 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32, GLuint> ); |
| 100 | InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_INT, WriteColor<R32G32S, GLint> ); |
| 101 | |
| 102 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_BYTE, WriteColor<R8, GLfloat> ); |
| 103 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_BYTE, WriteColor<R8S, GLfloat> ); |
| 104 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_FLOAT, WriteColor<R32F, GLfloat> ); |
| 105 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT, WriteColor<R16F, GLfloat> ); |
| 106 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT_OES, WriteColor<R16F, GLfloat> ); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 107 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_SHORT, WriteColor<R16, GLfloat>); |
| 108 | InsertFormatWriteFunctionMapping(&map, GL_RED, GL_SHORT, WriteColor<R16S, GLfloat>); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 109 | |
| 110 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8, GLuint> ); |
| 111 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_BYTE, WriteColor<R8S, GLint> ); |
| 112 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16, GLuint> ); |
| 113 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_SHORT, WriteColor<R16S, GLint> ); |
| 114 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, WriteColor<R32, GLuint> ); |
| 115 | InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_INT, WriteColor<R32S, GLint> ); |
| 116 | |
| 117 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, WriteColor<L8A8, GLfloat> ); |
| 118 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, WriteColor<L8, GLfloat> ); |
| 119 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, WriteColor<A8, GLfloat> ); |
| 120 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, WriteColor<L32A32F, GLfloat> ); |
| 121 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_FLOAT, WriteColor<L32F, GLfloat> ); |
| 122 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_FLOAT, WriteColor<A32F, GLfloat> ); |
| 123 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, WriteColor<L16A16F, GLfloat> ); |
| 124 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, WriteColor<L16A16F, GLfloat> ); |
| 125 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, WriteColor<L16F, GLfloat> ); |
| 126 | InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, WriteColor<L16F, GLfloat> ); |
| 127 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT, WriteColor<A16F, GLfloat> ); |
| 128 | InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, WriteColor<A16F, GLfloat> ); |
| 129 | |
| 130 | InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, WriteColor<B8G8R8A8, GLfloat> ); |
Austin Kinross | 5cf0f98 | 2015-08-12 09:35:10 -0700 | [diff] [blame] | 131 | InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, WriteColor<A4R4G4B4, GLfloat> ); |
| 132 | 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] | 133 | |
| 134 | InsertFormatWriteFunctionMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> ); |
| 135 | InsertFormatWriteFunctionMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> ); |
| 136 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 137 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, nullptr ); |
| 138 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, nullptr ); |
| 139 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, nullptr ); |
| 140 | InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, nullptr ); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 141 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 142 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, nullptr ); |
| 143 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr ); |
| 144 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr ); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 145 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 146 | InsertFormatWriteFunctionMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, nullptr ); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 147 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 148 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr ); |
| 149 | InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, nullptr ); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 150 | // clang-format on |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 151 | |
| 152 | return map; |
| 153 | } |
Geoff Lang | d93cd6c | 2017-08-11 16:32:41 -0400 | [diff] [blame] | 154 | |
| 155 | void CopyColor(gl::ColorF *color) |
| 156 | { |
| 157 | // No-op |
| 158 | } |
| 159 | |
| 160 | void PremultiplyAlpha(gl::ColorF *color) |
| 161 | { |
| 162 | color->red *= color->alpha; |
| 163 | color->green *= color->alpha; |
| 164 | color->blue *= color->alpha; |
| 165 | } |
| 166 | |
| 167 | void UnmultiplyAlpha(gl::ColorF *color) |
| 168 | { |
| 169 | if (color->alpha != 0.0f) |
| 170 | { |
| 171 | float invAlpha = 1.0f / color->alpha; |
| 172 | color->red *= invAlpha; |
| 173 | color->green *= invAlpha; |
| 174 | color->blue *= invAlpha; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void ClipChannelsR(gl::ColorF *color) |
| 179 | { |
| 180 | color->green = 0.0f; |
| 181 | color->blue = 0.0f; |
| 182 | color->alpha = 1.0f; |
| 183 | } |
| 184 | |
| 185 | void ClipChannelsRG(gl::ColorF *color) |
| 186 | { |
| 187 | color->blue = 0.0f; |
| 188 | color->alpha = 1.0f; |
| 189 | } |
| 190 | |
| 191 | void ClipChannelsRGB(gl::ColorF *color) |
| 192 | { |
| 193 | color->alpha = 1.0f; |
| 194 | } |
| 195 | |
| 196 | void ClipChannelsLuminance(gl::ColorF *color) |
| 197 | { |
| 198 | color->alpha = 1.0f; |
| 199 | } |
| 200 | |
| 201 | void ClipChannelsAlpha(gl::ColorF *color) |
| 202 | { |
| 203 | color->red = 0.0f; |
| 204 | color->green = 0.0f; |
| 205 | color->blue = 0.0f; |
| 206 | } |
| 207 | |
| 208 | void ClipChannelsNoOp(gl::ColorF *color) |
| 209 | { |
| 210 | } |
| 211 | |
| 212 | void WriteUintColor(const gl::ColorF &color, |
| 213 | ColorWriteFunction colorWriteFunction, |
| 214 | uint8_t *destPixelData) |
| 215 | { |
| 216 | gl::ColorUI destColor( |
| 217 | static_cast<unsigned int>(color.red * 255), static_cast<unsigned int>(color.green * 255), |
| 218 | static_cast<unsigned int>(color.blue * 255), static_cast<unsigned int>(color.alpha * 255)); |
| 219 | colorWriteFunction(reinterpret_cast<const uint8_t *>(&destColor), destPixelData); |
| 220 | } |
| 221 | |
| 222 | void WriteFloatColor(const gl::ColorF &color, |
| 223 | ColorWriteFunction colorWriteFunction, |
| 224 | uint8_t *destPixelData) |
| 225 | { |
| 226 | colorWriteFunction(reinterpret_cast<const uint8_t *>(&color), destPixelData); |
| 227 | } |
| 228 | |
Luc Ferron | 46bcea5 | 2018-05-31 09:48:36 -0400 | [diff] [blame] | 229 | template <typename T, int cols, int rows> |
| 230 | bool TransposeExpandMatrix(T *target, const GLfloat *value) |
| 231 | { |
| 232 | constexpr int targetWidth = 4; |
| 233 | constexpr int targetHeight = rows; |
| 234 | constexpr int srcWidth = rows; |
| 235 | constexpr int srcHeight = cols; |
| 236 | |
| 237 | constexpr int copyWidth = std::min(targetHeight, srcWidth); |
| 238 | constexpr int copyHeight = std::min(targetWidth, srcHeight); |
| 239 | |
| 240 | T staging[targetWidth * targetHeight] = {0}; |
| 241 | |
| 242 | for (int x = 0; x < copyWidth; x++) |
| 243 | { |
| 244 | for (int y = 0; y < copyHeight; y++) |
| 245 | { |
| 246 | staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0) |
| 251 | { |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | memcpy(target, staging, targetWidth * targetHeight * sizeof(T)); |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | template <typename T, int cols, int rows> |
| 260 | bool ExpandMatrix(T *target, const GLfloat *value) |
| 261 | { |
| 262 | constexpr int kTargetWidth = 4; |
| 263 | constexpr int kTargetHeight = rows; |
| 264 | constexpr int kSrcWidth = cols; |
| 265 | constexpr int kSrcHeight = rows; |
| 266 | |
| 267 | constexpr int kCopyWidth = std::min(kTargetWidth, kSrcWidth); |
| 268 | constexpr int kCopyHeight = std::min(kTargetHeight, kSrcHeight); |
| 269 | |
| 270 | T staging[kTargetWidth * kTargetHeight] = {0}; |
| 271 | |
| 272 | for (int y = 0; y < kCopyHeight; y++) |
| 273 | { |
| 274 | for (int x = 0; x < kCopyWidth; x++) |
| 275 | { |
| 276 | staging[y * kTargetWidth + x] = static_cast<T>(value[y * kSrcWidth + x]); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if (memcmp(target, staging, kTargetWidth * kTargetHeight * sizeof(T)) == 0) |
| 281 | { |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | memcpy(target, staging, kTargetWidth * kTargetHeight * sizeof(T)); |
| 286 | return true; |
| 287 | } |
| 288 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 289 | } // anonymous namespace |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 290 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 291 | PackPixelsParams::PackPixelsParams() |
| 292 | : format(GL_NONE), type(GL_NONE), outputPitch(0), packBuffer(nullptr), offset(0) |
| 293 | { |
| 294 | } |
| 295 | |
| 296 | PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn, |
| 297 | GLenum formatIn, |
| 298 | GLenum typeIn, |
| 299 | GLuint outputPitchIn, |
| 300 | const gl::PixelPackState &packIn, |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 301 | gl::Buffer *packBufferIn, |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 302 | ptrdiff_t offsetIn) |
| 303 | : area(areaIn), |
| 304 | format(formatIn), |
| 305 | type(typeIn), |
| 306 | outputPitch(outputPitchIn), |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 307 | packBuffer(packBufferIn), |
| 308 | pack(), |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 309 | offset(offsetIn) |
| 310 | { |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 311 | pack.alignment = packIn.alignment; |
| 312 | pack.reverseRowOrder = packIn.reverseRowOrder; |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 315 | void PackPixels(const PackPixelsParams ¶ms, |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 316 | const angle::Format &sourceFormat, |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 317 | int inputPitchIn, |
| 318 | const uint8_t *sourceIn, |
| 319 | uint8_t *destWithoutOffset) |
| 320 | { |
| 321 | uint8_t *destWithOffset = destWithoutOffset + params.offset; |
| 322 | |
| 323 | const uint8_t *source = sourceIn; |
| 324 | int inputPitch = inputPitchIn; |
| 325 | |
| 326 | if (params.pack.reverseRowOrder) |
| 327 | { |
| 328 | source += inputPitch * (params.area.height - 1); |
| 329 | inputPitch = -inputPitch; |
| 330 | } |
| 331 | |
Luc Ferron | 339b95e | 2018-06-12 10:21:52 -0400 | [diff] [blame] | 332 | const gl::InternalFormat &internalFormat = |
| 333 | gl::GetInternalFormatInfo(params.format, params.type); |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 334 | |
Luc Ferron | 339b95e | 2018-06-12 10:21:52 -0400 | [diff] [blame] | 335 | if (sourceFormat.glInternalFormat == internalFormat.sizedInternalFormat) |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 336 | { |
| 337 | // Direct copy possible |
| 338 | for (int y = 0; y < params.area.height; ++y) |
| 339 | { |
| 340 | memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch, |
Luc Ferron | 339b95e | 2018-06-12 10:21:52 -0400 | [diff] [blame] | 341 | params.area.width * sourceFormat.pixelBytes); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 342 | } |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | gl::FormatType formatType(params.format, params.type); |
Jamie Madill | 3071206 | 2016-08-09 11:10:36 -0400 | [diff] [blame] | 347 | ColorCopyFunction fastCopyFunc = |
| 348 | GetFastCopyFunction(sourceFormat.fastCopyFunctions, formatType); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 349 | const auto &destFormatInfo = gl::GetInternalFormatInfo(formatType.format, formatType.type); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 350 | |
| 351 | if (fastCopyFunc) |
| 352 | { |
| 353 | // Fast copy is possible through some special function |
| 354 | for (int y = 0; y < params.area.height; ++y) |
| 355 | { |
| 356 | for (int x = 0; x < params.area.width; ++x) |
| 357 | { |
| 358 | uint8_t *dest = |
| 359 | destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; |
Luc Ferron | 339b95e | 2018-06-12 10:21:52 -0400 | [diff] [blame] | 360 | const uint8_t *src = source + y * inputPitch + x * sourceFormat.pixelBytes; |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 361 | |
| 362 | fastCopyFunc(src, dest); |
| 363 | } |
| 364 | } |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | ColorWriteFunction colorWriteFunction = GetColorWriteFunction(formatType); |
| 369 | |
| 370 | // Maximum size of any Color<T> type used. |
| 371 | uint8_t temp[16]; |
| 372 | static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) && |
| 373 | sizeof(temp) >= sizeof(gl::ColorI), |
| 374 | "Unexpected size of gl::Color struct."); |
| 375 | |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 376 | const auto &colorReadFunction = sourceFormat.colorReadFunction; |
| 377 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 378 | for (int y = 0; y < params.area.height; ++y) |
| 379 | { |
| 380 | for (int x = 0; x < params.area.width; ++x) |
| 381 | { |
| 382 | uint8_t *dest = destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; |
Luc Ferron | 339b95e | 2018-06-12 10:21:52 -0400 | [diff] [blame] | 383 | const uint8_t *src = source + y * inputPitch + x * sourceFormat.pixelBytes; |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 384 | |
| 385 | // readFunc and writeFunc will be using the same type of color, CopyTexImage |
| 386 | // will not allow the copy otherwise. |
| 387 | colorReadFunction(src, temp); |
| 388 | colorWriteFunction(temp, dest); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType) |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 394 | { |
| 395 | static const FormatWriteFunctionMap formatTypeMap = BuildFormatWriteFunctionMap(); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 396 | auto iter = formatTypeMap.find(formatType); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 397 | ASSERT(iter != formatTypeMap.end()); |
| 398 | if (iter != formatTypeMap.end()) |
| 399 | { |
| 400 | return iter->second; |
| 401 | } |
| 402 | else |
| 403 | { |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 404 | return nullptr; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 408 | ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions, |
| 409 | const gl::FormatType &formatType) |
| 410 | { |
Jamie Madill | 4f57e5f | 2016-10-27 17:36:53 -0400 | [diff] [blame] | 411 | return fastCopyFunctions.get(formatType); |
| 412 | } |
| 413 | |
| 414 | bool FastCopyFunctionMap::has(const gl::FormatType &formatType) const |
| 415 | { |
| 416 | return (get(formatType) != nullptr); |
| 417 | } |
| 418 | |
| 419 | ColorCopyFunction FastCopyFunctionMap::get(const gl::FormatType &formatType) const |
| 420 | { |
| 421 | for (size_t index = 0; index < mSize; ++index) |
| 422 | { |
| 423 | if (mData[index].format == formatType.format && mData[index].type == formatType.type) |
| 424 | { |
| 425 | return mData[index].func; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return nullptr; |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 430 | } |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 431 | |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 432 | bool ShouldUseDebugLayers(const egl::AttributeMap &attribs) |
| 433 | { |
| 434 | EGLAttrib debugSetting = |
| 435 | attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE); |
| 436 | |
| 437 | // Prefer to enable debug layers if compiling in Debug, and disabled in Release. |
Geoff Lang | 58ba6bf | 2017-11-28 16:40:58 -0500 | [diff] [blame] | 438 | #if defined(ANGLE_ENABLE_ASSERTS) |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 439 | return (debugSetting != EGL_FALSE); |
| 440 | #else |
| 441 | return (debugSetting == EGL_TRUE); |
Geoff Lang | 58ba6bf | 2017-11-28 16:40:58 -0500 | [diff] [blame] | 442 | #endif // defined(ANGLE_ENABLE_ASSERTS) |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 443 | } |
| 444 | |
Geoff Lang | 24ddc7a | 2018-06-11 14:56:34 -0400 | [diff] [blame^] | 445 | bool ShouldUseVirtualizedContexts(const egl::AttributeMap &attribs, bool defaultValue) |
| 446 | { |
| 447 | EGLAttrib virtualizedContextRequest = |
| 448 | attribs.get(EGL_PLATFORM_ANGLE_CONTEXT_VIRTUALIZATION_ANGLE, EGL_DONT_CARE); |
| 449 | if (defaultValue) |
| 450 | { |
| 451 | return (virtualizedContextRequest != EGL_FALSE); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | return (virtualizedContextRequest == EGL_TRUE); |
| 456 | } |
| 457 | } |
| 458 | |
Geoff Lang | d93cd6c | 2017-08-11 16:32:41 -0400 | [diff] [blame] | 459 | void CopyImageCHROMIUM(const uint8_t *sourceData, |
| 460 | size_t sourceRowPitch, |
| 461 | size_t sourcePixelBytes, |
| 462 | ColorReadFunction colorReadFunction, |
| 463 | uint8_t *destData, |
| 464 | size_t destRowPitch, |
| 465 | size_t destPixelBytes, |
| 466 | ColorWriteFunction colorWriteFunction, |
| 467 | GLenum destUnsizedFormat, |
| 468 | GLenum destComponentType, |
| 469 | size_t width, |
| 470 | size_t height, |
| 471 | bool unpackFlipY, |
| 472 | bool unpackPremultiplyAlpha, |
| 473 | bool unpackUnmultiplyAlpha) |
| 474 | { |
| 475 | using ConversionFunction = void (*)(gl::ColorF *); |
| 476 | ConversionFunction conversionFunction = CopyColor; |
| 477 | if (unpackPremultiplyAlpha != unpackUnmultiplyAlpha) |
| 478 | { |
| 479 | if (unpackPremultiplyAlpha) |
| 480 | { |
| 481 | conversionFunction = PremultiplyAlpha; |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | conversionFunction = UnmultiplyAlpha; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | auto clipChannelsFunction = ClipChannelsNoOp; |
| 490 | switch (destUnsizedFormat) |
| 491 | { |
| 492 | case GL_RED: |
| 493 | clipChannelsFunction = ClipChannelsR; |
| 494 | break; |
| 495 | case GL_RG: |
| 496 | clipChannelsFunction = ClipChannelsRG; |
| 497 | break; |
| 498 | case GL_RGB: |
| 499 | clipChannelsFunction = ClipChannelsRGB; |
| 500 | break; |
| 501 | case GL_LUMINANCE: |
| 502 | clipChannelsFunction = ClipChannelsLuminance; |
| 503 | break; |
| 504 | case GL_ALPHA: |
| 505 | clipChannelsFunction = ClipChannelsAlpha; |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | auto writeFunction = (destComponentType == GL_UNSIGNED_INT) ? WriteUintColor : WriteFloatColor; |
| 510 | |
| 511 | for (size_t y = 0; y < height; y++) |
| 512 | { |
| 513 | for (size_t x = 0; x < width; x++) |
| 514 | { |
| 515 | const uint8_t *sourcePixelData = sourceData + y * sourceRowPitch + x * sourcePixelBytes; |
| 516 | |
| 517 | gl::ColorF sourceColor; |
| 518 | colorReadFunction(sourcePixelData, reinterpret_cast<uint8_t *>(&sourceColor)); |
| 519 | |
| 520 | conversionFunction(&sourceColor); |
| 521 | clipChannelsFunction(&sourceColor); |
| 522 | |
| 523 | size_t destY = 0; |
| 524 | if (unpackFlipY) |
| 525 | { |
| 526 | destY += (height - 1); |
| 527 | destY -= y; |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | destY += y; |
| 532 | } |
| 533 | |
| 534 | uint8_t *destPixelData = destData + destY * destRowPitch + x * destPixelBytes; |
| 535 | writeFunction(sourceColor, colorWriteFunction, destPixelData); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 540 | // IncompleteTextureSet implementation. |
| 541 | IncompleteTextureSet::IncompleteTextureSet() |
| 542 | { |
| 543 | } |
| 544 | |
| 545 | IncompleteTextureSet::~IncompleteTextureSet() |
| 546 | { |
| 547 | } |
| 548 | |
| 549 | void IncompleteTextureSet::onDestroy(const gl::Context *context) |
| 550 | { |
| 551 | // Clear incomplete textures. |
| 552 | for (auto &incompleteTexture : mIncompleteTextures) |
| 553 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 554 | if (incompleteTexture.get() != nullptr) |
| 555 | { |
| 556 | ANGLE_SWALLOW_ERR(incompleteTexture->onDestroy(context)); |
| 557 | incompleteTexture.set(context, nullptr); |
| 558 | } |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 559 | } |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | gl::Error IncompleteTextureSet::getIncompleteTexture( |
| 563 | const gl::Context *context, |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 564 | gl::TextureType type, |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 565 | MultisampleTextureInitializer *multisampleInitializer, |
| 566 | gl::Texture **textureOut) |
| 567 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 568 | *textureOut = mIncompleteTextures[type].get(); |
| 569 | if (*textureOut != nullptr) |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 570 | { |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 571 | return gl::NoError(); |
| 572 | } |
| 573 | |
| 574 | ContextImpl *implFactory = context->getImplementation(); |
| 575 | |
| 576 | const GLubyte color[] = {0, 0, 0, 255}; |
| 577 | const gl::Extents colorSize(1, 1, 1); |
Corentin Wallez | cda6af1 | 2017-10-30 19:20:37 -0400 | [diff] [blame] | 578 | gl::PixelUnpackState unpack; |
| 579 | unpack.alignment = 1; |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 580 | const gl::Box area(0, 0, 0, 1, 1, 1); |
| 581 | |
| 582 | // If a texture is external use a 2D texture for the incomplete texture |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 583 | gl::TextureType createType = (type == gl::TextureType::External) ? gl::TextureType::_2D : type; |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 584 | |
| 585 | gl::Texture *tex = new gl::Texture(implFactory, std::numeric_limits<GLuint>::max(), createType); |
| 586 | angle::UniqueObjectPointer<gl::Texture, gl::Context> t(tex, context); |
| 587 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 588 | if (createType == gl::TextureType::_2DMultisample) |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 589 | { |
| 590 | ANGLE_TRY(t->setStorageMultisample(context, createType, 1, GL_RGBA8, colorSize, true)); |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | ANGLE_TRY(t->setStorage(context, createType, 1, GL_RGBA8, colorSize)); |
| 595 | } |
| 596 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 597 | if (type == gl::TextureType::CubeMap) |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 598 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 599 | for (gl::TextureTarget face : gl::AllCubeFaceTextureTargets()) |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 600 | { |
| 601 | ANGLE_TRY( |
| 602 | t->setSubImage(context, unpack, face, 0, area, GL_RGBA, GL_UNSIGNED_BYTE, color)); |
| 603 | } |
| 604 | } |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 605 | else if (type == gl::TextureType::_2DMultisample) |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 606 | { |
| 607 | // Call a specialized clear function to init a multisample texture. |
| 608 | ANGLE_TRY(multisampleInitializer->initializeMultisampleTextureToBlack(context, t.get())); |
| 609 | } |
| 610 | else |
| 611 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 612 | ANGLE_TRY(t->setSubImage(context, unpack, gl::NonCubeTextureTypeToTarget(createType), 0, |
| 613 | area, GL_RGBA, GL_UNSIGNED_BYTE, color)); |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Luc Ferron | 4bba74f | 2018-04-19 14:40:45 -0400 | [diff] [blame] | 616 | ANGLE_TRY(t->syncState(context)); |
Jamie Madill | 4297564 | 2017-10-12 12:31:51 -0400 | [diff] [blame] | 617 | |
| 618 | mIncompleteTextures[type].set(context, t.release()); |
| 619 | *textureOut = mIncompleteTextures[type].get(); |
| 620 | return gl::NoError(); |
| 621 | } |
| 622 | |
Luc Ferron | 46bcea5 | 2018-05-31 09:48:36 -0400 | [diff] [blame] | 623 | #define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(cols, rows) \ |
| 624 | template bool SetFloatUniformMatrix<cols, rows>(unsigned int, unsigned int, GLsizei, \ |
| 625 | GLboolean, const GLfloat *, uint8_t *) |
| 626 | |
| 627 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 2); |
| 628 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 3); |
| 629 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 4); |
| 630 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 3); |
| 631 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 2); |
| 632 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 4); |
| 633 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 2); |
| 634 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 4); |
| 635 | ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 3); |
| 636 | |
| 637 | #undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC |
| 638 | |
| 639 | template <int cols, int rows> |
| 640 | bool SetFloatUniformMatrix(unsigned int arrayElementOffset, |
| 641 | unsigned int elementCount, |
| 642 | GLsizei countIn, |
| 643 | GLboolean transpose, |
| 644 | const GLfloat *value, |
| 645 | uint8_t *targetData) |
| 646 | { |
| 647 | unsigned int count = |
| 648 | std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn)); |
| 649 | |
| 650 | const unsigned int targetMatrixStride = (4 * rows); |
| 651 | GLfloat *target = reinterpret_cast<GLfloat *>( |
| 652 | targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride); |
| 653 | |
| 654 | bool dirty = false; |
| 655 | |
| 656 | for (unsigned int i = 0; i < count; i++) |
| 657 | { |
| 658 | if (transpose == GL_FALSE) |
| 659 | { |
| 660 | dirty = ExpandMatrix<GLfloat, cols, rows>(target, value) || dirty; |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | dirty = TransposeExpandMatrix<GLfloat, cols, rows>(target, value) || dirty; |
| 665 | } |
| 666 | target += targetMatrixStride; |
| 667 | value += cols * rows; |
| 668 | } |
| 669 | |
| 670 | return dirty; |
| 671 | } |
| 672 | |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 673 | template void GetMatrixUniform<GLint>(GLenum, GLint *, const GLint *, bool); |
| 674 | template void GetMatrixUniform<GLuint>(GLenum, GLuint *, const GLuint *, bool); |
| 675 | |
| 676 | void GetMatrixUniform(GLenum type, GLfloat *dataOut, const GLfloat *source, bool transpose) |
| 677 | { |
| 678 | int columns = gl::VariableColumnCount(type); |
| 679 | int rows = gl::VariableRowCount(type); |
| 680 | for (GLint col = 0; col < columns; ++col) |
| 681 | { |
| 682 | for (GLint row = 0; row < rows; ++row) |
| 683 | { |
| 684 | GLfloat *outptr = dataOut + ((col * rows) + row); |
| 685 | const GLfloat *inptr = |
| 686 | transpose ? source + ((row * 4) + col) : source + ((col * 4) + row); |
| 687 | *outptr = *inptr; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | template <typename NonFloatT> |
| 693 | void GetMatrixUniform(GLenum type, NonFloatT *dataOut, const NonFloatT *source, bool transpose) |
| 694 | { |
| 695 | UNREACHABLE(); |
| 696 | } |
| 697 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 698 | } // namespace rx |