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