blob: 8109a56d7949b854a641ea3665257bf66229c51e [file] [log] [blame]
Geoff Lang051dbc72015-01-05 15:48:58 -05001//
Jamie Madilld2b50a02016-06-09 00:13:35 -07002// Copyright 2016 The ANGLE Project Authors. All rights reserved.
Geoff Lang051dbc72015-01-05 15:48:58 -05003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
Jamie Madilld2b50a02016-06-09 00:13:35 -07006// renderer_utils:
7// Helper methods pertaining to most or all back-ends.
8//
Geoff Lang051dbc72015-01-05 15:48:58 -05009
Jamie Madilld2b50a02016-06-09 00:13:35 -070010#include "libANGLE/renderer/renderer_utils.h"
Geoff Lang051dbc72015-01-05 15:48:58 -050011
Geoff Lang6e4cfce2016-06-13 15:06:31 -040012#include "image_util/copyimage.h"
13#include "image_util/imageformats.h"
14
Jamie Madill222c5172017-07-19 16:15:42 -040015#include "libANGLE/AttributeMap.h"
Jamie Madilld2b50a02016-06-09 00:13:35 -070016#include "libANGLE/formatutils.h"
Jamie Madill86e0b7f2016-08-09 11:10:29 -040017#include "libANGLE/renderer/Format.h"
Geoff Lang6e4cfce2016-06-13 15:06:31 -040018
19#include <string.h>
Geoff Lang051dbc72015-01-05 15:48:58 -050020
21namespace rx
22{
23
Jamie Madilld2b50a02016-06-09 00:13:35 -070024namespace
25{
26typedef std::pair<gl::FormatType, ColorWriteFunction> FormatWriteFunctionPair;
27typedef std::map<gl::FormatType, ColorWriteFunction> FormatWriteFunctionMap;
Geoff Lang051dbc72015-01-05 15:48:58 -050028
Jamie Madilld2b50a02016-06-09 00:13:35 -070029static inline void InsertFormatWriteFunctionMapping(FormatWriteFunctionMap *map,
30 GLenum format,
31 GLenum type,
Geoff Lang051dbc72015-01-05 15:48:58 -050032 ColorWriteFunction writeFunc)
33{
Jamie Madilld2b50a02016-06-09 00:13:35 -070034 map->insert(FormatWriteFunctionPair(gl::FormatType(format, type), writeFunc));
Geoff Lang051dbc72015-01-05 15:48:58 -050035}
36
37static FormatWriteFunctionMap BuildFormatWriteFunctionMap()
38{
Geoff Lang6e4cfce2016-06-13 15:06:31 -040039 using namespace angle; // For image writing functions
40
Geoff Lang051dbc72015-01-05 15:48:58 -050041 FormatWriteFunctionMap map;
42
Jamie Madilld2b50a02016-06-09 00:13:35 -070043 // clang-format off
Geoff Lang051dbc72015-01-05 15:48:58 -050044 // | Format | Type | Color write function |
45 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> );
46 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_BYTE, WriteColor<R8G8B8A8S, GLfloat> );
47 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, WriteColor<R4G4B4A4, GLfloat> );
48 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, WriteColor<R5G5B5A1, GLfloat> );
49 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLfloat> );
50 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_FLOAT, WriteColor<R32G32B32A32F, GLfloat>);
51 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT, WriteColor<R16G16B16A16F, GLfloat>);
52 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, WriteColor<R16G16B16A16F, GLfloat>);
Vincent Lang25ab4512016-05-13 18:13:59 +020053 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT,
54 WriteColor<R16G16B16A16, GLfloat>);
55 InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_SHORT, WriteColor<R16G16B16A16S, GLfloat>);
Geoff Lang051dbc72015-01-05 15:48:58 -050056
57 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLuint> );
58 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_BYTE, WriteColor<R8G8B8A8S, GLint> );
59 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16A16, GLuint> );
60 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_SHORT, WriteColor<R16G16B16A16S, GLint> );
61 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32A32, GLuint> );
62 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_INT, WriteColor<R32G32B32A32S, GLint> );
63 InsertFormatWriteFunctionMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, WriteColor<R10G10B10A2, GLuint> );
64
65 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> );
66 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_BYTE, WriteColor<R8G8B8S, GLfloat> );
67 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, WriteColor<R5G6B5, GLfloat> );
68 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, WriteColor<R11G11B10F, GLfloat> );
69 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, WriteColor<R9G9B9E5, GLfloat> );
70 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_FLOAT, WriteColor<R32G32B32F, GLfloat> );
71 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT, WriteColor<R16G16B16F, GLfloat> );
72 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, WriteColor<R16G16B16F, GLfloat> );
Vincent Lang25ab4512016-05-13 18:13:59 +020073 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_UNSIGNED_SHORT,
74 WriteColor<R16G16B16, GLfloat>);
75 InsertFormatWriteFunctionMapping(&map, GL_RGB, GL_SHORT, WriteColor<R16G16B16S, GLfloat>);
Geoff Lang051dbc72015-01-05 15:48:58 -050076
77 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLuint> );
78 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_BYTE, WriteColor<R8G8B8S, GLint> );
79 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16B16, GLuint> );
80 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_SHORT, WriteColor<R16G16B16S, GLint> );
81 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32B32, GLuint> );
82 InsertFormatWriteFunctionMapping(&map, GL_RGB_INTEGER, GL_INT, WriteColor<R32G32B32S, GLint> );
83
84 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLfloat> );
85 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_BYTE, WriteColor<R8G8S, GLfloat> );
86 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_FLOAT, WriteColor<R32G32F, GLfloat> );
87 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT, WriteColor<R16G16F, GLfloat> );
88 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_HALF_FLOAT_OES, WriteColor<R16G16F, GLfloat> );
Vincent Lang25ab4512016-05-13 18:13:59 +020089 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLfloat>);
90 InsertFormatWriteFunctionMapping(&map, GL_RG, GL_SHORT, WriteColor<R16G16S, GLfloat>);
Geoff Lang051dbc72015-01-05 15:48:58 -050091
92 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8G8, GLuint> );
93 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_BYTE, WriteColor<R8G8S, GLint> );
94 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16G16, GLuint> );
95 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_SHORT, WriteColor<R16G16S, GLint> );
96 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, WriteColor<R32G32, GLuint> );
97 InsertFormatWriteFunctionMapping(&map, GL_RG_INTEGER, GL_INT, WriteColor<R32G32S, GLint> );
98
99 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_BYTE, WriteColor<R8, GLfloat> );
100 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_BYTE, WriteColor<R8S, GLfloat> );
101 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_FLOAT, WriteColor<R32F, GLfloat> );
102 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT, WriteColor<R16F, GLfloat> );
103 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_HALF_FLOAT_OES, WriteColor<R16F, GLfloat> );
Vincent Lang25ab4512016-05-13 18:13:59 +0200104 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_UNSIGNED_SHORT, WriteColor<R16, GLfloat>);
105 InsertFormatWriteFunctionMapping(&map, GL_RED, GL_SHORT, WriteColor<R16S, GLfloat>);
Geoff Lang051dbc72015-01-05 15:48:58 -0500106
107 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, WriteColor<R8, GLuint> );
108 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_BYTE, WriteColor<R8S, GLint> );
109 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, WriteColor<R16, GLuint> );
110 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_SHORT, WriteColor<R16S, GLint> );
111 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, WriteColor<R32, GLuint> );
112 InsertFormatWriteFunctionMapping(&map, GL_RED_INTEGER, GL_INT, WriteColor<R32S, GLint> );
113
114 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, WriteColor<L8A8, GLfloat> );
115 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, WriteColor<L8, GLfloat> );
116 InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, WriteColor<A8, GLfloat> );
117 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, WriteColor<L32A32F, GLfloat> );
118 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_FLOAT, WriteColor<L32F, GLfloat> );
119 InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_FLOAT, WriteColor<A32F, GLfloat> );
120 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, WriteColor<L16A16F, GLfloat> );
121 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, WriteColor<L16A16F, GLfloat> );
122 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, WriteColor<L16F, GLfloat> );
123 InsertFormatWriteFunctionMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, WriteColor<L16F, GLfloat> );
124 InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT, WriteColor<A16F, GLfloat> );
125 InsertFormatWriteFunctionMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, WriteColor<A16F, GLfloat> );
126
127 InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, WriteColor<B8G8R8A8, GLfloat> );
Austin Kinross5cf0f982015-08-12 09:35:10 -0700128 InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, WriteColor<A4R4G4B4, GLfloat> );
129 InsertFormatWriteFunctionMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, WriteColor<A1R5G5B5, GLfloat> );
Geoff Lang051dbc72015-01-05 15:48:58 -0500130
131 InsertFormatWriteFunctionMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8, GLfloat> );
132 InsertFormatWriteFunctionMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> );
133
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800134 InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, nullptr );
135 InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, nullptr );
136 InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, nullptr );
137 InsertFormatWriteFunctionMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, nullptr );
Geoff Lang051dbc72015-01-05 15:48:58 -0500138
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800139 InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, nullptr );
140 InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr );
141 InsertFormatWriteFunctionMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr );
Geoff Lang051dbc72015-01-05 15:48:58 -0500142
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800143 InsertFormatWriteFunctionMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, nullptr );
Geoff Lang051dbc72015-01-05 15:48:58 -0500144
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800145 InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr );
146 InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, nullptr );
Jamie Madilld2b50a02016-06-09 00:13:35 -0700147 // clang-format on
Geoff Lang051dbc72015-01-05 15:48:58 -0500148
149 return map;
150}
Jamie Madilld2b50a02016-06-09 00:13:35 -0700151} // anonymous namespace
Geoff Lang051dbc72015-01-05 15:48:58 -0500152
Jamie Madilld2b50a02016-06-09 00:13:35 -0700153PackPixelsParams::PackPixelsParams()
154 : format(GL_NONE), type(GL_NONE), outputPitch(0), packBuffer(nullptr), offset(0)
155{
156}
157
158PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
159 GLenum formatIn,
160 GLenum typeIn,
161 GLuint outputPitchIn,
162 const gl::PixelPackState &packIn,
163 ptrdiff_t offsetIn)
164 : area(areaIn),
165 format(formatIn),
166 type(typeIn),
167 outputPitch(outputPitchIn),
168 packBuffer(packIn.pixelBuffer.get()),
169 pack(packIn.alignment, packIn.reverseRowOrder),
170 offset(offsetIn)
171{
172}
173
Jamie Madill4928b7c2017-06-20 12:57:39 -0400174PackPixelsParams::PackPixelsParams(const gl::Context *context, const PackPixelsParams &other)
175 : area(other.area),
176 format(other.format),
177 type(other.type),
178 outputPitch(other.outputPitch),
179 packBuffer(other.packBuffer),
180 pack(),
181 offset(other.offset)
182{
183 pack.copyFrom(context, other.pack);
184}
185
Jamie Madilld2b50a02016-06-09 00:13:35 -0700186void PackPixels(const PackPixelsParams &params,
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400187 const angle::Format &sourceFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700188 int inputPitchIn,
189 const uint8_t *sourceIn,
190 uint8_t *destWithoutOffset)
191{
192 uint8_t *destWithOffset = destWithoutOffset + params.offset;
193
194 const uint8_t *source = sourceIn;
195 int inputPitch = inputPitchIn;
196
197 if (params.pack.reverseRowOrder)
198 {
199 source += inputPitch * (params.area.height - 1);
200 inputPitch = -inputPitch;
201 }
202
Geoff Langca271392017-04-05 12:30:00 -0400203 const auto &sourceGLInfo = gl::GetSizedInternalFormatInfo(sourceFormat.glInternalFormat);
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400204
205 if (sourceGLInfo.format == params.format && sourceGLInfo.type == params.type)
Jamie Madilld2b50a02016-06-09 00:13:35 -0700206 {
207 // Direct copy possible
208 for (int y = 0; y < params.area.height; ++y)
209 {
210 memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch,
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400211 params.area.width * sourceGLInfo.pixelBytes);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700212 }
213 return;
214 }
215
Geoff Langca271392017-04-05 12:30:00 -0400216 ASSERT(sourceGLInfo.sized);
Jamie Madillec0b5802016-07-04 13:11:59 -0400217
Jamie Madilld2b50a02016-06-09 00:13:35 -0700218 gl::FormatType formatType(params.format, params.type);
Jamie Madill30712062016-08-09 11:10:36 -0400219 ColorCopyFunction fastCopyFunc =
220 GetFastCopyFunction(sourceFormat.fastCopyFunctions, formatType);
Geoff Langca271392017-04-05 12:30:00 -0400221 const auto &destFormatInfo = gl::GetInternalFormatInfo(formatType.format, formatType.type);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700222
223 if (fastCopyFunc)
224 {
225 // Fast copy is possible through some special function
226 for (int y = 0; y < params.area.height; ++y)
227 {
228 for (int x = 0; x < params.area.width; ++x)
229 {
230 uint8_t *dest =
231 destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400232 const uint8_t *src = source + y * inputPitch + x * sourceGLInfo.pixelBytes;
Jamie Madilld2b50a02016-06-09 00:13:35 -0700233
234 fastCopyFunc(src, dest);
235 }
236 }
237 return;
238 }
239
240 ColorWriteFunction colorWriteFunction = GetColorWriteFunction(formatType);
241
242 // Maximum size of any Color<T> type used.
243 uint8_t temp[16];
244 static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) &&
245 sizeof(temp) >= sizeof(gl::ColorI),
246 "Unexpected size of gl::Color struct.");
247
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400248 const auto &colorReadFunction = sourceFormat.colorReadFunction;
249
Jamie Madilld2b50a02016-06-09 00:13:35 -0700250 for (int y = 0; y < params.area.height; ++y)
251 {
252 for (int x = 0; x < params.area.width; ++x)
253 {
254 uint8_t *dest = destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400255 const uint8_t *src = source + y * inputPitch + x * sourceGLInfo.pixelBytes;
Jamie Madilld2b50a02016-06-09 00:13:35 -0700256
257 // readFunc and writeFunc will be using the same type of color, CopyTexImage
258 // will not allow the copy otherwise.
259 colorReadFunction(src, temp);
260 colorWriteFunction(temp, dest);
261 }
262 }
263}
264
265ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType)
Geoff Lang051dbc72015-01-05 15:48:58 -0500266{
267 static const FormatWriteFunctionMap formatTypeMap = BuildFormatWriteFunctionMap();
Jamie Madilld2b50a02016-06-09 00:13:35 -0700268 auto iter = formatTypeMap.find(formatType);
Geoff Lang051dbc72015-01-05 15:48:58 -0500269 ASSERT(iter != formatTypeMap.end());
270 if (iter != formatTypeMap.end())
271 {
272 return iter->second;
273 }
274 else
275 {
Jamie Madilld2b50a02016-06-09 00:13:35 -0700276 return nullptr;
Geoff Lang051dbc72015-01-05 15:48:58 -0500277 }
278}
279
Jamie Madilld2b50a02016-06-09 00:13:35 -0700280ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
281 const gl::FormatType &formatType)
282{
Jamie Madill4f57e5f2016-10-27 17:36:53 -0400283 return fastCopyFunctions.get(formatType);
284}
285
286bool FastCopyFunctionMap::has(const gl::FormatType &formatType) const
287{
288 return (get(formatType) != nullptr);
289}
290
291ColorCopyFunction FastCopyFunctionMap::get(const gl::FormatType &formatType) const
292{
293 for (size_t index = 0; index < mSize; ++index)
294 {
295 if (mData[index].format == formatType.format && mData[index].type == formatType.type)
296 {
297 return mData[index].func;
298 }
299 }
300
301 return nullptr;
Geoff Lang051dbc72015-01-05 15:48:58 -0500302}
Jamie Madilld2b50a02016-06-09 00:13:35 -0700303
Jamie Madill222c5172017-07-19 16:15:42 -0400304bool ShouldUseDebugLayers(const egl::AttributeMap &attribs)
305{
306 EGLAttrib debugSetting =
307 attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE);
308
309// Prefer to enable debug layers if compiling in Debug, and disabled in Release.
310#if !defined(NDEBUG)
311 return (debugSetting != EGL_FALSE);
312#else
313 return (debugSetting == EGL_TRUE);
314#endif // !defined(NDEBUG)
315}
316
Jamie Madilld2b50a02016-06-09 00:13:35 -0700317} // namespace rx