blob: 7290cb6112cf62cd6a70b2cea5669b7a06411bbf [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 Madill42975642017-10-12 12:31:51 -040016#include "libANGLE/Context.h"
Jamie Madilld2b50a02016-06-09 00:13:35 -070017#include "libANGLE/formatutils.h"
Jamie Madill42975642017-10-12 12:31:51 -040018#include "libANGLE/renderer/ContextImpl.h"
Jamie Madill86e0b7f2016-08-09 11:10:29 -040019#include "libANGLE/renderer/Format.h"
Geoff Lang6e4cfce2016-06-13 15:06:31 -040020
21#include <string.h>
Luc Ferron48cdc2e2018-05-31 09:58:34 -040022#include "common/utilities.h"
Geoff Lang051dbc72015-01-05 15:48:58 -050023
24namespace rx
25{
26
Jamie Madilld2b50a02016-06-09 00:13:35 -070027namespace
28{
Geoff Langd93cd6c2017-08-11 16:32:41 -040029void CopyColor(gl::ColorF *color)
30{
31 // No-op
32}
33
34void PremultiplyAlpha(gl::ColorF *color)
35{
36 color->red *= color->alpha;
37 color->green *= color->alpha;
38 color->blue *= color->alpha;
39}
40
41void UnmultiplyAlpha(gl::ColorF *color)
42{
43 if (color->alpha != 0.0f)
44 {
45 float invAlpha = 1.0f / color->alpha;
46 color->red *= invAlpha;
47 color->green *= invAlpha;
48 color->blue *= invAlpha;
49 }
50}
51
52void ClipChannelsR(gl::ColorF *color)
53{
54 color->green = 0.0f;
55 color->blue = 0.0f;
56 color->alpha = 1.0f;
57}
58
59void ClipChannelsRG(gl::ColorF *color)
60{
61 color->blue = 0.0f;
62 color->alpha = 1.0f;
63}
64
65void ClipChannelsRGB(gl::ColorF *color)
66{
67 color->alpha = 1.0f;
68}
69
70void ClipChannelsLuminance(gl::ColorF *color)
71{
72 color->alpha = 1.0f;
73}
74
75void ClipChannelsAlpha(gl::ColorF *color)
76{
77 color->red = 0.0f;
78 color->green = 0.0f;
79 color->blue = 0.0f;
80}
81
82void ClipChannelsNoOp(gl::ColorF *color)
83{
84}
85
86void WriteUintColor(const gl::ColorF &color,
87 ColorWriteFunction colorWriteFunction,
88 uint8_t *destPixelData)
89{
90 gl::ColorUI destColor(
91 static_cast<unsigned int>(color.red * 255), static_cast<unsigned int>(color.green * 255),
92 static_cast<unsigned int>(color.blue * 255), static_cast<unsigned int>(color.alpha * 255));
93 colorWriteFunction(reinterpret_cast<const uint8_t *>(&destColor), destPixelData);
94}
95
96void WriteFloatColor(const gl::ColorF &color,
97 ColorWriteFunction colorWriteFunction,
98 uint8_t *destPixelData)
99{
100 colorWriteFunction(reinterpret_cast<const uint8_t *>(&color), destPixelData);
101}
102
Luc Ferron46bcea52018-05-31 09:48:36 -0400103template <typename T, int cols, int rows>
104bool TransposeExpandMatrix(T *target, const GLfloat *value)
105{
106 constexpr int targetWidth = 4;
107 constexpr int targetHeight = rows;
108 constexpr int srcWidth = rows;
109 constexpr int srcHeight = cols;
110
111 constexpr int copyWidth = std::min(targetHeight, srcWidth);
112 constexpr int copyHeight = std::min(targetWidth, srcHeight);
113
114 T staging[targetWidth * targetHeight] = {0};
115
116 for (int x = 0; x < copyWidth; x++)
117 {
118 for (int y = 0; y < copyHeight; y++)
119 {
120 staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]);
121 }
122 }
123
124 if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
125 {
126 return false;
127 }
128
129 memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
130 return true;
131}
132
133template <typename T, int cols, int rows>
134bool ExpandMatrix(T *target, const GLfloat *value)
135{
136 constexpr int kTargetWidth = 4;
137 constexpr int kTargetHeight = rows;
138 constexpr int kSrcWidth = cols;
139 constexpr int kSrcHeight = rows;
140
141 constexpr int kCopyWidth = std::min(kTargetWidth, kSrcWidth);
142 constexpr int kCopyHeight = std::min(kTargetHeight, kSrcHeight);
143
144 T staging[kTargetWidth * kTargetHeight] = {0};
145
146 for (int y = 0; y < kCopyHeight; y++)
147 {
148 for (int x = 0; x < kCopyWidth; x++)
149 {
150 staging[y * kTargetWidth + x] = static_cast<T>(value[y * kSrcWidth + x]);
151 }
152 }
153
154 if (memcmp(target, staging, kTargetWidth * kTargetHeight * sizeof(T)) == 0)
155 {
156 return false;
157 }
158
159 memcpy(target, staging, kTargetWidth * kTargetHeight * sizeof(T));
160 return true;
161}
Jamie Madilld2b50a02016-06-09 00:13:35 -0700162} // anonymous namespace
Geoff Lang051dbc72015-01-05 15:48:58 -0500163
Jamie Madilld2b50a02016-06-09 00:13:35 -0700164PackPixelsParams::PackPixelsParams()
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400165 : destFormat(nullptr), outputPitch(0), packBuffer(nullptr), offset(0)
Jamie Madilld2b50a02016-06-09 00:13:35 -0700166{
167}
168
169PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400170 const angle::Format &destFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700171 GLuint outputPitchIn,
172 const gl::PixelPackState &packIn,
Corentin Wallezcda6af12017-10-30 19:20:37 -0400173 gl::Buffer *packBufferIn,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700174 ptrdiff_t offsetIn)
175 : area(areaIn),
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400176 destFormat(&destFormat),
Jamie Madilld2b50a02016-06-09 00:13:35 -0700177 outputPitch(outputPitchIn),
Corentin Wallezcda6af12017-10-30 19:20:37 -0400178 packBuffer(packBufferIn),
179 pack(),
Jamie Madilld2b50a02016-06-09 00:13:35 -0700180 offset(offsetIn)
181{
Corentin Wallezcda6af12017-10-30 19:20:37 -0400182 pack.alignment = packIn.alignment;
183 pack.reverseRowOrder = packIn.reverseRowOrder;
Jamie Madill4928b7c2017-06-20 12:57:39 -0400184}
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
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400203 if (sourceFormat == *params.destFormat)
Jamie Madilld2b50a02016-06-09 00:13:35 -0700204 {
205 // Direct copy possible
206 for (int y = 0; y < params.area.height; ++y)
207 {
208 memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch,
Luc Ferron339b95e2018-06-12 10:21:52 -0400209 params.area.width * sourceFormat.pixelBytes);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700210 }
211 return;
212 }
213
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400214 ColorCopyFunction fastCopyFunc = sourceFormat.fastCopyFunctions.get(params.destFormat->id);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700215
216 if (fastCopyFunc)
217 {
218 // Fast copy is possible through some special function
219 for (int y = 0; y < params.area.height; ++y)
220 {
221 for (int x = 0; x < params.area.width; ++x)
222 {
223 uint8_t *dest =
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400224 destWithOffset + y * params.outputPitch + x * params.destFormat->pixelBytes;
Luc Ferron339b95e2018-06-12 10:21:52 -0400225 const uint8_t *src = source + y * inputPitch + x * sourceFormat.pixelBytes;
Jamie Madilld2b50a02016-06-09 00:13:35 -0700226
227 fastCopyFunc(src, dest);
228 }
229 }
230 return;
231 }
232
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400233 ColorWriteFunction colorWriteFunction = params.destFormat->colorWriteFunction;
Luc Ferron1617e692018-07-11 11:08:19 -0400234 ASSERT(colorWriteFunction != nullptr);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700235
236 // Maximum size of any Color<T> type used.
237 uint8_t temp[16];
238 static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) &&
239 sizeof(temp) >= sizeof(gl::ColorI),
240 "Unexpected size of gl::Color struct.");
241
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400242 ColorReadFunction colorReadFunction = sourceFormat.colorReadFunction;
243 ASSERT(colorReadFunction != nullptr);
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400244
Jamie Madilld2b50a02016-06-09 00:13:35 -0700245 for (int y = 0; y < params.area.height; ++y)
246 {
247 for (int x = 0; x < params.area.width; ++x)
248 {
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400249 uint8_t *dest =
250 destWithOffset + y * params.outputPitch + x * params.destFormat->pixelBytes;
Luc Ferron339b95e2018-06-12 10:21:52 -0400251 const uint8_t *src = source + y * inputPitch + x * sourceFormat.pixelBytes;
Jamie Madilld2b50a02016-06-09 00:13:35 -0700252
253 // readFunc and writeFunc will be using the same type of color, CopyTexImage
254 // will not allow the copy otherwise.
255 colorReadFunction(src, temp);
256 colorWriteFunction(temp, dest);
257 }
258 }
259}
260
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400261bool FastCopyFunctionMap::has(angle::FormatID formatID) const
Geoff Lang051dbc72015-01-05 15:48:58 -0500262{
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400263 return (get(formatID) != nullptr);
Geoff Lang051dbc72015-01-05 15:48:58 -0500264}
265
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400266ColorCopyFunction FastCopyFunctionMap::get(angle::FormatID formatID) const
Jamie Madill4f57e5f2016-10-27 17:36:53 -0400267{
268 for (size_t index = 0; index < mSize; ++index)
269 {
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400270 if (mData[index].formatID == formatID)
Jamie Madill4f57e5f2016-10-27 17:36:53 -0400271 {
272 return mData[index].func;
273 }
274 }
275
276 return nullptr;
Geoff Lang051dbc72015-01-05 15:48:58 -0500277}
Jamie Madilld2b50a02016-06-09 00:13:35 -0700278
Jamie Madill222c5172017-07-19 16:15:42 -0400279bool ShouldUseDebugLayers(const egl::AttributeMap &attribs)
280{
281 EGLAttrib debugSetting =
282 attribs.get(EGL_PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED_ANGLE, EGL_DONT_CARE);
283
284// Prefer to enable debug layers if compiling in Debug, and disabled in Release.
Geoff Lang58ba6bf2017-11-28 16:40:58 -0500285#if defined(ANGLE_ENABLE_ASSERTS)
Jamie Madill222c5172017-07-19 16:15:42 -0400286 return (debugSetting != EGL_FALSE);
287#else
288 return (debugSetting == EGL_TRUE);
Geoff Lang58ba6bf2017-11-28 16:40:58 -0500289#endif // defined(ANGLE_ENABLE_ASSERTS)
Jamie Madill222c5172017-07-19 16:15:42 -0400290}
291
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400292bool ShouldUseVirtualizedContexts(const egl::AttributeMap &attribs, bool defaultValue)
293{
294 EGLAttrib virtualizedContextRequest =
295 attribs.get(EGL_PLATFORM_ANGLE_CONTEXT_VIRTUALIZATION_ANGLE, EGL_DONT_CARE);
296 if (defaultValue)
297 {
298 return (virtualizedContextRequest != EGL_FALSE);
299 }
300 else
301 {
302 return (virtualizedContextRequest == EGL_TRUE);
303 }
304}
305
Geoff Langd93cd6c2017-08-11 16:32:41 -0400306void CopyImageCHROMIUM(const uint8_t *sourceData,
307 size_t sourceRowPitch,
308 size_t sourcePixelBytes,
309 ColorReadFunction colorReadFunction,
310 uint8_t *destData,
311 size_t destRowPitch,
312 size_t destPixelBytes,
313 ColorWriteFunction colorWriteFunction,
314 GLenum destUnsizedFormat,
315 GLenum destComponentType,
316 size_t width,
317 size_t height,
318 bool unpackFlipY,
319 bool unpackPremultiplyAlpha,
320 bool unpackUnmultiplyAlpha)
321{
322 using ConversionFunction = void (*)(gl::ColorF *);
323 ConversionFunction conversionFunction = CopyColor;
324 if (unpackPremultiplyAlpha != unpackUnmultiplyAlpha)
325 {
326 if (unpackPremultiplyAlpha)
327 {
328 conversionFunction = PremultiplyAlpha;
329 }
330 else
331 {
332 conversionFunction = UnmultiplyAlpha;
333 }
334 }
335
336 auto clipChannelsFunction = ClipChannelsNoOp;
337 switch (destUnsizedFormat)
338 {
339 case GL_RED:
340 clipChannelsFunction = ClipChannelsR;
341 break;
342 case GL_RG:
343 clipChannelsFunction = ClipChannelsRG;
344 break;
345 case GL_RGB:
346 clipChannelsFunction = ClipChannelsRGB;
347 break;
348 case GL_LUMINANCE:
349 clipChannelsFunction = ClipChannelsLuminance;
350 break;
351 case GL_ALPHA:
352 clipChannelsFunction = ClipChannelsAlpha;
353 break;
354 }
355
356 auto writeFunction = (destComponentType == GL_UNSIGNED_INT) ? WriteUintColor : WriteFloatColor;
357
358 for (size_t y = 0; y < height; y++)
359 {
360 for (size_t x = 0; x < width; x++)
361 {
362 const uint8_t *sourcePixelData = sourceData + y * sourceRowPitch + x * sourcePixelBytes;
363
364 gl::ColorF sourceColor;
365 colorReadFunction(sourcePixelData, reinterpret_cast<uint8_t *>(&sourceColor));
366
367 conversionFunction(&sourceColor);
368 clipChannelsFunction(&sourceColor);
369
370 size_t destY = 0;
371 if (unpackFlipY)
372 {
373 destY += (height - 1);
374 destY -= y;
375 }
376 else
377 {
378 destY += y;
379 }
380
381 uint8_t *destPixelData = destData + destY * destRowPitch + x * destPixelBytes;
382 writeFunction(sourceColor, colorWriteFunction, destPixelData);
383 }
384 }
385}
386
Jamie Madill42975642017-10-12 12:31:51 -0400387// IncompleteTextureSet implementation.
388IncompleteTextureSet::IncompleteTextureSet()
389{
390}
391
392IncompleteTextureSet::~IncompleteTextureSet()
393{
394}
395
396void IncompleteTextureSet::onDestroy(const gl::Context *context)
397{
398 // Clear incomplete textures.
399 for (auto &incompleteTexture : mIncompleteTextures)
400 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500401 if (incompleteTexture.get() != nullptr)
402 {
403 ANGLE_SWALLOW_ERR(incompleteTexture->onDestroy(context));
404 incompleteTexture.set(context, nullptr);
405 }
Jamie Madill42975642017-10-12 12:31:51 -0400406 }
Jamie Madill42975642017-10-12 12:31:51 -0400407}
408
409gl::Error IncompleteTextureSet::getIncompleteTexture(
410 const gl::Context *context,
Corentin Wallez99d492c2018-02-27 15:17:10 -0500411 gl::TextureType type,
Jamie Madill42975642017-10-12 12:31:51 -0400412 MultisampleTextureInitializer *multisampleInitializer,
413 gl::Texture **textureOut)
414{
Corentin Wallez99d492c2018-02-27 15:17:10 -0500415 *textureOut = mIncompleteTextures[type].get();
416 if (*textureOut != nullptr)
Jamie Madill42975642017-10-12 12:31:51 -0400417 {
Jamie Madill42975642017-10-12 12:31:51 -0400418 return gl::NoError();
419 }
420
421 ContextImpl *implFactory = context->getImplementation();
422
423 const GLubyte color[] = {0, 0, 0, 255};
424 const gl::Extents colorSize(1, 1, 1);
Corentin Wallezcda6af12017-10-30 19:20:37 -0400425 gl::PixelUnpackState unpack;
426 unpack.alignment = 1;
Jamie Madill42975642017-10-12 12:31:51 -0400427 const gl::Box area(0, 0, 0, 1, 1, 1);
428
429 // If a texture is external use a 2D texture for the incomplete texture
Corentin Wallez99d492c2018-02-27 15:17:10 -0500430 gl::TextureType createType = (type == gl::TextureType::External) ? gl::TextureType::_2D : type;
Jamie Madill42975642017-10-12 12:31:51 -0400431
432 gl::Texture *tex = new gl::Texture(implFactory, std::numeric_limits<GLuint>::max(), createType);
433 angle::UniqueObjectPointer<gl::Texture, gl::Context> t(tex, context);
434
Corentin Wallez99d492c2018-02-27 15:17:10 -0500435 if (createType == gl::TextureType::_2DMultisample)
Jamie Madill42975642017-10-12 12:31:51 -0400436 {
437 ANGLE_TRY(t->setStorageMultisample(context, createType, 1, GL_RGBA8, colorSize, true));
438 }
439 else
440 {
441 ANGLE_TRY(t->setStorage(context, createType, 1, GL_RGBA8, colorSize));
442 }
443
Corentin Wallez99d492c2018-02-27 15:17:10 -0500444 if (type == gl::TextureType::CubeMap)
Jamie Madill42975642017-10-12 12:31:51 -0400445 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500446 for (gl::TextureTarget face : gl::AllCubeFaceTextureTargets())
Jamie Madill42975642017-10-12 12:31:51 -0400447 {
448 ANGLE_TRY(
449 t->setSubImage(context, unpack, face, 0, area, GL_RGBA, GL_UNSIGNED_BYTE, color));
450 }
451 }
Corentin Wallez99d492c2018-02-27 15:17:10 -0500452 else if (type == gl::TextureType::_2DMultisample)
Jamie Madill42975642017-10-12 12:31:51 -0400453 {
454 // Call a specialized clear function to init a multisample texture.
455 ANGLE_TRY(multisampleInitializer->initializeMultisampleTextureToBlack(context, t.get()));
456 }
457 else
458 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500459 ANGLE_TRY(t->setSubImage(context, unpack, gl::NonCubeTextureTypeToTarget(createType), 0,
460 area, GL_RGBA, GL_UNSIGNED_BYTE, color));
Jamie Madill42975642017-10-12 12:31:51 -0400461 }
462
Luc Ferron4bba74f2018-04-19 14:40:45 -0400463 ANGLE_TRY(t->syncState(context));
Jamie Madill42975642017-10-12 12:31:51 -0400464
465 mIncompleteTextures[type].set(context, t.release());
466 *textureOut = mIncompleteTextures[type].get();
467 return gl::NoError();
468}
469
Luc Ferron46bcea52018-05-31 09:48:36 -0400470#define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(cols, rows) \
471 template bool SetFloatUniformMatrix<cols, rows>(unsigned int, unsigned int, GLsizei, \
472 GLboolean, const GLfloat *, uint8_t *)
473
474ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 2);
475ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 3);
476ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 4);
477ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 3);
478ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 2);
479ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 4);
480ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 2);
481ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 4);
482ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 3);
483
484#undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC
485
486template <int cols, int rows>
487bool SetFloatUniformMatrix(unsigned int arrayElementOffset,
488 unsigned int elementCount,
489 GLsizei countIn,
490 GLboolean transpose,
491 const GLfloat *value,
492 uint8_t *targetData)
493{
494 unsigned int count =
495 std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
496
497 const unsigned int targetMatrixStride = (4 * rows);
498 GLfloat *target = reinterpret_cast<GLfloat *>(
499 targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride);
500
501 bool dirty = false;
502
503 for (unsigned int i = 0; i < count; i++)
504 {
505 if (transpose == GL_FALSE)
506 {
507 dirty = ExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
508 }
509 else
510 {
511 dirty = TransposeExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
512 }
513 target += targetMatrixStride;
514 value += cols * rows;
515 }
516
517 return dirty;
518}
519
Luc Ferron48cdc2e2018-05-31 09:58:34 -0400520template void GetMatrixUniform<GLint>(GLenum, GLint *, const GLint *, bool);
521template void GetMatrixUniform<GLuint>(GLenum, GLuint *, const GLuint *, bool);
522
523void GetMatrixUniform(GLenum type, GLfloat *dataOut, const GLfloat *source, bool transpose)
524{
525 int columns = gl::VariableColumnCount(type);
526 int rows = gl::VariableRowCount(type);
527 for (GLint col = 0; col < columns; ++col)
528 {
529 for (GLint row = 0; row < rows; ++row)
530 {
531 GLfloat *outptr = dataOut + ((col * rows) + row);
532 const GLfloat *inptr =
533 transpose ? source + ((row * 4) + col) : source + ((col * 4) + row);
534 *outptr = *inptr;
535 }
536 }
537}
538
539template <typename NonFloatT>
540void GetMatrixUniform(GLenum type, NonFloatT *dataOut, const NonFloatT *source, bool transpose)
541{
542 UNREACHABLE();
543}
544
Jamie Madilldb9c69e2018-07-18 17:23:47 -0400545const angle::Format &GetFormatFromFormatType(GLenum format, GLenum type)
546{
547 GLenum sizedInternalFormat = gl::GetInternalFormatInfo(format, type).sizedInternalFormat;
548 angle::FormatID angleFormatID = angle::Format::InternalFormatToID(sizedInternalFormat);
549 return angle::Format::Get(angleFormatID);
550}
Jamie Madilld2b50a02016-06-09 00:13:35 -0700551} // namespace rx