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