Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // ProgramGL.cpp: Implements the class methods for ProgramGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/ProgramGL.h" |
| 10 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 11 | #include "common/bitset_utils.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 12 | #include "common/angleutils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 13 | #include "common/debug.h" |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 14 | #include "common/string_utils.h" |
Geoff Lang | 5ed74cf | 2015-04-14 13:57:07 -0400 | [diff] [blame] | 15 | #include "common/utilities.h" |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 16 | #include "libANGLE/renderer/gl/ContextGL.h" |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 18 | #include "libANGLE/renderer/gl/ShaderGL.h" |
| 19 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/gl/WorkaroundsGL.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 21 | #include "libANGLE/Uniform.h" |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 22 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 23 | |
| 24 | namespace rx |
| 25 | { |
| 26 | |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 27 | ProgramGL::ProgramGL(const gl::ProgramState &data, |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 28 | const FunctionsGL *functions, |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 29 | const WorkaroundsGL &workarounds, |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 30 | StateManagerGL *stateManager, |
| 31 | bool enablePathRendering) |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 32 | : ProgramImpl(data), |
| 33 | mFunctions(functions), |
| 34 | mWorkarounds(workarounds), |
| 35 | mStateManager(stateManager), |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 36 | mEnablePathRendering(enablePathRendering), |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 37 | mProgramID(0) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 38 | { |
| 39 | ASSERT(mFunctions); |
| 40 | ASSERT(mStateManager); |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 41 | |
| 42 | mProgramID = mFunctions->createProgram(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 43 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 44 | |
| 45 | ProgramGL::~ProgramGL() |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 46 | { |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 47 | mFunctions->deleteProgram(mProgramID); |
| 48 | mProgramID = 0; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 49 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 50 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 51 | LinkResult ProgramGL::load(const ContextImpl *contextImpl, |
| 52 | gl::InfoLog &infoLog, |
| 53 | gl::BinaryInputStream *stream) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 54 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 55 | preLink(); |
| 56 | |
| 57 | // Read the binary format, size and blob |
| 58 | GLenum binaryFormat = stream->readInt<GLenum>(); |
| 59 | GLint binaryLength = stream->readInt<GLint>(); |
| 60 | const uint8_t *binary = stream->data() + stream->offset(); |
| 61 | stream->skip(binaryLength); |
| 62 | |
| 63 | // Load the binary |
| 64 | mFunctions->programBinary(mProgramID, binaryFormat, binary, binaryLength); |
| 65 | |
| 66 | // Verify that the program linked |
| 67 | if (!checkLinkStatus(infoLog)) |
| 68 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 69 | return false; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | postLink(); |
| 73 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 74 | // Re-apply UBO bindings to work around driver bugs. |
| 75 | const WorkaroundsGL &workaroundsGL = GetAs<ContextGL>(contextImpl)->getWorkaroundsGL(); |
| 76 | if (workaroundsGL.reapplyUBOBindingsAfterLoadingBinaryProgram) |
| 77 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame^] | 78 | for (size_t bindingIndex : mState.getActiveUniformBlockBindingsMask()) |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 79 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame^] | 80 | GLuint uintIndex = static_cast<GLuint>(bindingIndex); |
| 81 | setUniformBlockBinding(uintIndex, mState.getUniformBlockBinding(uintIndex)); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 85 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | gl::Error ProgramGL::save(gl::BinaryOutputStream *stream) |
| 89 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 90 | GLint binaryLength = 0; |
| 91 | mFunctions->getProgramiv(mProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength); |
| 92 | |
| 93 | std::vector<uint8_t> binary(binaryLength); |
| 94 | GLenum binaryFormat = GL_NONE; |
| 95 | mFunctions->getProgramBinary(mProgramID, binaryLength, &binaryLength, &binaryFormat, |
| 96 | &binary[0]); |
| 97 | |
| 98 | stream->writeInt(binaryFormat); |
| 99 | stream->writeInt(binaryLength); |
| 100 | stream->writeBytes(&binary[0], binaryLength); |
| 101 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 102 | return gl::NoError(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 103 | } |
| 104 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 105 | void ProgramGL::setBinaryRetrievableHint(bool retrievable) |
| 106 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 107 | // glProgramParameteri isn't always available on ES backends. |
| 108 | if (mFunctions->programParameteri) |
| 109 | { |
| 110 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, |
| 111 | retrievable ? GL_TRUE : GL_FALSE); |
| 112 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 113 | } |
| 114 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 115 | void ProgramGL::setSeparable(bool separable) |
| 116 | { |
| 117 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_SEPARABLE, separable ? GL_TRUE : GL_FALSE); |
| 118 | } |
| 119 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 120 | LinkResult ProgramGL::link(ContextImpl *contextImpl, |
Jamie Madill | 192745a | 2016-12-22 15:58:21 -0500 | [diff] [blame] | 121 | const gl::VaryingPacking &packing, |
| 122 | gl::InfoLog &infoLog) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 123 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 124 | preLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 125 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 126 | if (mState.getAttachedComputeShader()) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 127 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 128 | const ShaderGL *computeShaderGL = GetImplAs<ShaderGL>(mState.getAttachedComputeShader()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 129 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 130 | mFunctions->attachShader(mProgramID, computeShaderGL->getShaderID()); |
| 131 | |
| 132 | // Link and verify |
| 133 | mFunctions->linkProgram(mProgramID); |
| 134 | |
| 135 | // Detach the shaders |
| 136 | mFunctions->detachShader(mProgramID, computeShaderGL->getShaderID()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 137 | } |
| 138 | else |
| 139 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 140 | // Set the transform feedback state |
| 141 | std::vector<const GLchar *> transformFeedbackVaryings; |
| 142 | for (const auto &tfVarying : mState.getTransformFeedbackVaryingNames()) |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 143 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 144 | transformFeedbackVaryings.push_back(tfVarying.c_str()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 147 | if (transformFeedbackVaryings.empty()) |
| 148 | { |
| 149 | if (mFunctions->transformFeedbackVaryings) |
| 150 | { |
| 151 | mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr, |
| 152 | mState.getTransformFeedbackBufferMode()); |
| 153 | } |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | ASSERT(mFunctions->transformFeedbackVaryings); |
| 158 | mFunctions->transformFeedbackVaryings( |
| 159 | mProgramID, static_cast<GLsizei>(transformFeedbackVaryings.size()), |
| 160 | &transformFeedbackVaryings[0], mState.getTransformFeedbackBufferMode()); |
| 161 | } |
| 162 | |
| 163 | const ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(mState.getAttachedVertexShader()); |
| 164 | const ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(mState.getAttachedFragmentShader()); |
| 165 | |
| 166 | // Attach the shaders |
| 167 | mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 168 | mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID()); |
| 169 | |
| 170 | // Bind attribute locations to match the GL layer. |
| 171 | for (const sh::Attribute &attribute : mState.getAttributes()) |
| 172 | { |
Corentin Wallez | 6c1cbf5 | 2016-11-23 12:44:35 -0500 | [diff] [blame] | 173 | if (!attribute.staticUse || attribute.isBuiltIn()) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 174 | { |
| 175 | continue; |
| 176 | } |
| 177 | |
| 178 | mFunctions->bindAttribLocation(mProgramID, attribute.location, attribute.name.c_str()); |
| 179 | } |
| 180 | |
| 181 | // Link and verify |
| 182 | mFunctions->linkProgram(mProgramID); |
| 183 | |
| 184 | // Detach the shaders |
| 185 | mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 186 | mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 189 | // Verify the link |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 190 | if (!checkLinkStatus(infoLog)) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 191 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 192 | return false; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 193 | } |
| 194 | |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 195 | if (mWorkarounds.alwaysCallUseProgramAfterLink) |
| 196 | { |
| 197 | mStateManager->forceUseProgram(mProgramID); |
| 198 | } |
| 199 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 200 | postLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 201 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 202 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 205 | GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/) |
| 206 | { |
| 207 | // TODO(jmadill): implement validate |
| 208 | return true; |
| 209 | } |
| 210 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 211 | void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 212 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 213 | if (mFunctions->programUniform1fv != nullptr) |
| 214 | { |
| 215 | mFunctions->programUniform1fv(mProgramID, uniLoc(location), count, v); |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | mStateManager->useProgram(mProgramID); |
| 220 | mFunctions->uniform1fv(uniLoc(location), count, v); |
| 221 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 225 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 226 | if (mFunctions->programUniform2fv != nullptr) |
| 227 | { |
| 228 | mFunctions->programUniform2fv(mProgramID, uniLoc(location), count, v); |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | mStateManager->useProgram(mProgramID); |
| 233 | mFunctions->uniform2fv(uniLoc(location), count, v); |
| 234 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 238 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 239 | if (mFunctions->programUniform3fv != nullptr) |
| 240 | { |
| 241 | mFunctions->programUniform3fv(mProgramID, uniLoc(location), count, v); |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | mStateManager->useProgram(mProgramID); |
| 246 | mFunctions->uniform3fv(uniLoc(location), count, v); |
| 247 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 251 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 252 | if (mFunctions->programUniform4fv != nullptr) |
| 253 | { |
| 254 | mFunctions->programUniform4fv(mProgramID, uniLoc(location), count, v); |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | mStateManager->useProgram(mProgramID); |
| 259 | mFunctions->uniform4fv(uniLoc(location), count, v); |
| 260 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 264 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 265 | if (mFunctions->programUniform1iv != nullptr) |
| 266 | { |
| 267 | mFunctions->programUniform1iv(mProgramID, uniLoc(location), count, v); |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | mStateManager->useProgram(mProgramID); |
| 272 | mFunctions->uniform1iv(uniLoc(location), count, v); |
| 273 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 277 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 278 | if (mFunctions->programUniform2iv != nullptr) |
| 279 | { |
| 280 | mFunctions->programUniform2iv(mProgramID, uniLoc(location), count, v); |
| 281 | } |
| 282 | else |
| 283 | { |
| 284 | mStateManager->useProgram(mProgramID); |
| 285 | mFunctions->uniform2iv(uniLoc(location), count, v); |
| 286 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 290 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 291 | if (mFunctions->programUniform3iv != nullptr) |
| 292 | { |
| 293 | mFunctions->programUniform3iv(mProgramID, uniLoc(location), count, v); |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | mStateManager->useProgram(mProgramID); |
| 298 | mFunctions->uniform3iv(uniLoc(location), count, v); |
| 299 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 303 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 304 | if (mFunctions->programUniform4iv != nullptr) |
| 305 | { |
| 306 | mFunctions->programUniform4iv(mProgramID, uniLoc(location), count, v); |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | mStateManager->useProgram(mProgramID); |
| 311 | mFunctions->uniform4iv(uniLoc(location), count, v); |
| 312 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 316 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 317 | if (mFunctions->programUniform1uiv != nullptr) |
| 318 | { |
| 319 | mFunctions->programUniform1uiv(mProgramID, uniLoc(location), count, v); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | mStateManager->useProgram(mProgramID); |
| 324 | mFunctions->uniform1uiv(uniLoc(location), count, v); |
| 325 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 329 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 330 | if (mFunctions->programUniform2uiv != nullptr) |
| 331 | { |
| 332 | mFunctions->programUniform2uiv(mProgramID, uniLoc(location), count, v); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | mStateManager->useProgram(mProgramID); |
| 337 | mFunctions->uniform2uiv(uniLoc(location), count, v); |
| 338 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 342 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 343 | if (mFunctions->programUniform3uiv != nullptr) |
| 344 | { |
| 345 | mFunctions->programUniform3uiv(mProgramID, uniLoc(location), count, v); |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | mStateManager->useProgram(mProgramID); |
| 350 | mFunctions->uniform3uiv(uniLoc(location), count, v); |
| 351 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 355 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 356 | if (mFunctions->programUniform4uiv != nullptr) |
| 357 | { |
| 358 | mFunctions->programUniform4uiv(mProgramID, uniLoc(location), count, v); |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | mStateManager->useProgram(mProgramID); |
| 363 | mFunctions->uniform4uiv(uniLoc(location), count, v); |
| 364 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 368 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 369 | if (mFunctions->programUniformMatrix2fv != nullptr) |
| 370 | { |
| 371 | mFunctions->programUniformMatrix2fv(mProgramID, uniLoc(location), count, transpose, value); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | mStateManager->useProgram(mProgramID); |
| 376 | mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value); |
| 377 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 381 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 382 | if (mFunctions->programUniformMatrix3fv != nullptr) |
| 383 | { |
| 384 | mFunctions->programUniformMatrix3fv(mProgramID, uniLoc(location), count, transpose, value); |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | mStateManager->useProgram(mProgramID); |
| 389 | mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value); |
| 390 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 394 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 395 | if (mFunctions->programUniformMatrix4fv != nullptr) |
| 396 | { |
| 397 | mFunctions->programUniformMatrix4fv(mProgramID, uniLoc(location), count, transpose, value); |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | mStateManager->useProgram(mProgramID); |
| 402 | mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value); |
| 403 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 407 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 408 | if (mFunctions->programUniformMatrix2x3fv != nullptr) |
| 409 | { |
| 410 | mFunctions->programUniformMatrix2x3fv(mProgramID, uniLoc(location), count, transpose, |
| 411 | value); |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | mStateManager->useProgram(mProgramID); |
| 416 | mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value); |
| 417 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 421 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 422 | if (mFunctions->programUniformMatrix3x2fv != nullptr) |
| 423 | { |
| 424 | mFunctions->programUniformMatrix3x2fv(mProgramID, uniLoc(location), count, transpose, |
| 425 | value); |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | mStateManager->useProgram(mProgramID); |
| 430 | mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value); |
| 431 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 435 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 436 | if (mFunctions->programUniformMatrix2x4fv != nullptr) |
| 437 | { |
| 438 | mFunctions->programUniformMatrix2x4fv(mProgramID, uniLoc(location), count, transpose, |
| 439 | value); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | mStateManager->useProgram(mProgramID); |
| 444 | mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value); |
| 445 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 449 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 450 | if (mFunctions->programUniformMatrix4x2fv != nullptr) |
| 451 | { |
| 452 | mFunctions->programUniformMatrix4x2fv(mProgramID, uniLoc(location), count, transpose, |
| 453 | value); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | mStateManager->useProgram(mProgramID); |
| 458 | mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value); |
| 459 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 463 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 464 | if (mFunctions->programUniformMatrix3x4fv != nullptr) |
| 465 | { |
| 466 | mFunctions->programUniformMatrix3x4fv(mProgramID, uniLoc(location), count, transpose, |
| 467 | value); |
| 468 | } |
| 469 | else |
| 470 | { |
| 471 | mStateManager->useProgram(mProgramID); |
| 472 | mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value); |
| 473 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 477 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 478 | if (mFunctions->programUniformMatrix4x3fv != nullptr) |
| 479 | { |
| 480 | mFunctions->programUniformMatrix4x3fv(mProgramID, uniLoc(location), count, transpose, |
| 481 | value); |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | mStateManager->useProgram(mProgramID); |
| 486 | mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value); |
| 487 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 488 | } |
| 489 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 490 | void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 491 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 492 | // Lazy init |
| 493 | if (mUniformBlockRealLocationMap.empty()) |
| 494 | { |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 495 | mUniformBlockRealLocationMap.reserve(mState.getUniformBlocks().size()); |
| 496 | for (const gl::UniformBlock &uniformBlock : mState.getUniformBlocks()) |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 497 | { |
| 498 | const std::string &nameWithIndex = uniformBlock.nameWithArrayIndex(); |
| 499 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, nameWithIndex.c_str()); |
| 500 | mUniformBlockRealLocationMap.push_back(blockIndex); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex]; |
| 505 | if (realBlockIndex != GL_INVALID_INDEX) |
| 506 | { |
| 507 | mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding); |
| 508 | } |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 511 | GLuint ProgramGL::getProgramID() const |
| 512 | { |
| 513 | return mProgramID; |
| 514 | } |
| 515 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 516 | bool ProgramGL::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 517 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 518 | ASSERT(mProgramID != 0u); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 519 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 520 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockName.c_str()); |
| 521 | if (blockIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 522 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 523 | *sizeOut = 0; |
| 524 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 525 | } |
| 526 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 527 | GLint dataSize = 0; |
| 528 | mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, |
| 529 | &dataSize); |
| 530 | *sizeOut = static_cast<size_t>(dataSize); |
| 531 | return true; |
| 532 | } |
| 533 | |
| 534 | bool ProgramGL::getUniformBlockMemberInfo(const std::string &memberUniformName, |
| 535 | sh::BlockMemberInfo *memberInfoOut) const |
| 536 | { |
| 537 | GLuint uniformIndex; |
| 538 | const GLchar *memberNameGLStr = memberUniformName.c_str(); |
| 539 | mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex); |
| 540 | |
| 541 | if (uniformIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 542 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 543 | *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); |
| 544 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 545 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 546 | |
| 547 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET, |
| 548 | &memberInfoOut->offset); |
| 549 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE, |
| 550 | &memberInfoOut->arrayStride); |
| 551 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE, |
| 552 | &memberInfoOut->matrixStride); |
| 553 | |
| 554 | // TODO(jmadill): possibly determine this at the gl::Program level. |
| 555 | GLint isRowMajorMatrix = 0; |
| 556 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR, |
| 557 | &isRowMajorMatrix); |
| 558 | memberInfoOut->isRowMajorMatrix = isRowMajorMatrix != GL_FALSE; |
| 559 | return true; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 560 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 561 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 562 | void ProgramGL::setPathFragmentInputGen(const std::string &inputName, |
| 563 | GLenum genMode, |
| 564 | GLint components, |
| 565 | const GLfloat *coeffs) |
| 566 | { |
| 567 | ASSERT(mEnablePathRendering); |
| 568 | |
| 569 | for (const auto &input : mPathRenderingFragmentInputs) |
| 570 | { |
| 571 | if (input.name == inputName) |
| 572 | { |
| 573 | mFunctions->programPathFragmentInputGenNV(mProgramID, input.location, genMode, |
| 574 | components, coeffs); |
| 575 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 576 | return; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | } |
| 581 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 582 | void ProgramGL::preLink() |
| 583 | { |
| 584 | // Reset the program state |
| 585 | mUniformRealLocationMap.clear(); |
| 586 | mUniformBlockRealLocationMap.clear(); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 587 | mPathRenderingFragmentInputs.clear(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | bool ProgramGL::checkLinkStatus(gl::InfoLog &infoLog) |
| 591 | { |
| 592 | GLint linkStatus = GL_FALSE; |
| 593 | mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus); |
| 594 | if (linkStatus == GL_FALSE) |
| 595 | { |
| 596 | // Linking failed, put the error into the info log |
| 597 | GLint infoLogLength = 0; |
| 598 | mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 599 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 600 | // Info log length includes the null terminator, so 1 means that the info log is an empty |
| 601 | // string. |
| 602 | if (infoLogLength > 1) |
| 603 | { |
| 604 | std::vector<char> buf(infoLogLength); |
| 605 | mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]); |
| 606 | |
| 607 | mFunctions->deleteProgram(mProgramID); |
| 608 | mProgramID = 0; |
| 609 | |
| 610 | infoLog << buf.data(); |
| 611 | |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 612 | WARN() << "Program link failed unexpectedly: " << buf.data(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 613 | } |
| 614 | else |
| 615 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 616 | WARN() << "Program link failed unexpectedly with no info log."; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 617 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 618 | |
| 619 | // TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case |
| 620 | return false; |
| 621 | } |
| 622 | |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | void ProgramGL::postLink() |
| 627 | { |
| 628 | // Query the uniform information |
| 629 | ASSERT(mUniformRealLocationMap.empty()); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 630 | const auto &uniformLocations = mState.getUniformLocations(); |
| 631 | const auto &uniforms = mState.getUniforms(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 632 | mUniformRealLocationMap.resize(uniformLocations.size(), GL_INVALID_INDEX); |
| 633 | for (size_t uniformLocation = 0; uniformLocation < uniformLocations.size(); uniformLocation++) |
| 634 | { |
| 635 | const auto &entry = uniformLocations[uniformLocation]; |
| 636 | if (!entry.used) |
| 637 | { |
| 638 | continue; |
| 639 | } |
| 640 | |
| 641 | // From the spec: |
| 642 | // "Locations for sequential array indices are not required to be sequential." |
| 643 | const gl::LinkedUniform &uniform = uniforms[entry.index]; |
| 644 | std::stringstream fullNameStr; |
| 645 | fullNameStr << uniform.name; |
| 646 | if (uniform.isArray()) |
| 647 | { |
| 648 | fullNameStr << "[" << entry.element << "]"; |
| 649 | } |
| 650 | const std::string &fullName = fullNameStr.str(); |
| 651 | |
| 652 | GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str()); |
| 653 | mUniformRealLocationMap[uniformLocation] = realLocation; |
| 654 | } |
| 655 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 656 | // Discover CHROMIUM_path_rendering fragment inputs if enabled. |
| 657 | if (!mEnablePathRendering) |
| 658 | return; |
| 659 | |
| 660 | GLint numFragmentInputs = 0; |
| 661 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_ACTIVE_RESOURCES, |
| 662 | &numFragmentInputs); |
| 663 | if (numFragmentInputs <= 0) |
| 664 | return; |
| 665 | |
| 666 | GLint maxNameLength = 0; |
| 667 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH, |
| 668 | &maxNameLength); |
| 669 | ASSERT(maxNameLength); |
| 670 | |
| 671 | for (GLint i = 0; i < numFragmentInputs; ++i) |
| 672 | { |
| 673 | std::string name; |
| 674 | name.resize(maxNameLength); |
| 675 | |
| 676 | GLsizei nameLen = 0; |
| 677 | mFunctions->getProgramResourceName(mProgramID, GL_FRAGMENT_INPUT_NV, i, maxNameLength, |
| 678 | &nameLen, &name[0]); |
| 679 | name.resize(nameLen); |
| 680 | |
| 681 | // Ignore built-ins |
| 682 | if (angle::BeginsWith(name, "gl_")) |
| 683 | continue; |
| 684 | |
| 685 | const GLenum kQueryProperties[] = {GL_LOCATION, GL_ARRAY_SIZE}; |
| 686 | GLint queryResults[ArraySize(kQueryProperties)]; |
| 687 | GLsizei queryLength = 0; |
| 688 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 689 | mFunctions->getProgramResourceiv( |
| 690 | mProgramID, GL_FRAGMENT_INPUT_NV, i, static_cast<GLsizei>(ArraySize(kQueryProperties)), |
| 691 | kQueryProperties, static_cast<GLsizei>(ArraySize(queryResults)), &queryLength, |
| 692 | queryResults); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 693 | |
Olli Etuaho | e319171 | 2016-07-18 16:01:10 +0300 | [diff] [blame] | 694 | ASSERT(queryLength == static_cast<GLsizei>(ArraySize(kQueryProperties))); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 695 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 696 | PathRenderingFragmentInput baseElementInput; |
| 697 | baseElementInput.name = name; |
| 698 | baseElementInput.location = queryResults[0]; |
| 699 | mPathRenderingFragmentInputs.push_back(std::move(baseElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 700 | |
| 701 | // If the input is an array it's denoted by [0] suffix on the variable |
| 702 | // name. We'll then create an entry per each array index where index > 0 |
| 703 | if (angle::EndsWith(name, "[0]")) |
| 704 | { |
| 705 | // drop the suffix |
| 706 | name.resize(name.size() - 3); |
| 707 | |
| 708 | const auto arraySize = queryResults[1]; |
| 709 | const auto baseLocation = queryResults[0]; |
| 710 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 711 | for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 712 | { |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 713 | PathRenderingFragmentInput arrayElementInput; |
Corentin Wallez | 054f7ed | 2016-09-20 17:15:59 -0400 | [diff] [blame] | 714 | arrayElementInput.name = name + "[" + ToString(arrayIndex) + "]"; |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 715 | arrayElementInput.location = baseLocation + arrayIndex; |
| 716 | mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 720 | } |
| 721 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 722 | } // namespace rx |