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), |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 38 | mMultiviewBaseViewLayerIndexUniformLocation(-1), |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 39 | mProgramID(0) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 40 | { |
| 41 | ASSERT(mFunctions); |
| 42 | ASSERT(mStateManager); |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 43 | |
| 44 | mProgramID = mFunctions->createProgram(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 45 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 46 | |
| 47 | ProgramGL::~ProgramGL() |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 48 | { |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 49 | mFunctions->deleteProgram(mProgramID); |
| 50 | mProgramID = 0; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 51 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 52 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 53 | gl::LinkResult ProgramGL::load(const gl::Context *context, |
| 54 | gl::InfoLog &infoLog, |
| 55 | gl::BinaryInputStream *stream) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 56 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 57 | preLink(); |
| 58 | |
| 59 | // Read the binary format, size and blob |
| 60 | GLenum binaryFormat = stream->readInt<GLenum>(); |
| 61 | GLint binaryLength = stream->readInt<GLint>(); |
| 62 | const uint8_t *binary = stream->data() + stream->offset(); |
| 63 | stream->skip(binaryLength); |
| 64 | |
| 65 | // Load the binary |
| 66 | mFunctions->programBinary(mProgramID, binaryFormat, binary, binaryLength); |
| 67 | |
| 68 | // Verify that the program linked |
| 69 | if (!checkLinkStatus(infoLog)) |
| 70 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 71 | return false; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | postLink(); |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 75 | reapplyUBOBindingsIfNeeded(context); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 76 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 77 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 80 | void ProgramGL::save(const gl::Context *context, gl::BinaryOutputStream *stream) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 81 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 82 | GLint binaryLength = 0; |
| 83 | mFunctions->getProgramiv(mProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength); |
| 84 | |
| 85 | std::vector<uint8_t> binary(binaryLength); |
| 86 | GLenum binaryFormat = GL_NONE; |
| 87 | mFunctions->getProgramBinary(mProgramID, binaryLength, &binaryLength, &binaryFormat, |
| 88 | &binary[0]); |
| 89 | |
| 90 | stream->writeInt(binaryFormat); |
| 91 | stream->writeInt(binaryLength); |
| 92 | stream->writeBytes(&binary[0], binaryLength); |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 93 | |
| 94 | reapplyUBOBindingsIfNeeded(context); |
| 95 | } |
| 96 | |
| 97 | void ProgramGL::reapplyUBOBindingsIfNeeded(const gl::Context *context) |
| 98 | { |
| 99 | // Re-apply UBO bindings to work around driver bugs. |
| 100 | const WorkaroundsGL &workaroundsGL = GetImplAs<ContextGL>(context)->getWorkaroundsGL(); |
| 101 | if (workaroundsGL.reapplyUBOBindingsAfterUsingBinaryProgram) |
| 102 | { |
| 103 | const auto &blocks = mState.getUniformBlocks(); |
| 104 | for (size_t blockIndex : mState.getActiveUniformBlockBindingsMask()) |
| 105 | { |
| 106 | setUniformBlockBinding(static_cast<GLuint>(blockIndex), blocks[blockIndex].binding); |
| 107 | } |
| 108 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 109 | } |
| 110 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 111 | void ProgramGL::setBinaryRetrievableHint(bool retrievable) |
| 112 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 113 | // glProgramParameteri isn't always available on ES backends. |
| 114 | if (mFunctions->programParameteri) |
| 115 | { |
| 116 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, |
| 117 | retrievable ? GL_TRUE : GL_FALSE); |
| 118 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 121 | void ProgramGL::setSeparable(bool separable) |
| 122 | { |
| 123 | mFunctions->programParameteri(mProgramID, GL_PROGRAM_SEPARABLE, separable ? GL_TRUE : GL_FALSE); |
| 124 | } |
| 125 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 126 | gl::LinkResult ProgramGL::link(const gl::Context *context, |
| 127 | const gl::VaryingPacking &packing, |
| 128 | gl::InfoLog &infoLog) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 129 | { |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 130 | preLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 131 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 132 | if (mState.getAttachedComputeShader()) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 133 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 134 | const ShaderGL *computeShaderGL = GetImplAs<ShaderGL>(mState.getAttachedComputeShader()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 135 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 136 | mFunctions->attachShader(mProgramID, computeShaderGL->getShaderID()); |
| 137 | |
| 138 | // Link and verify |
| 139 | mFunctions->linkProgram(mProgramID); |
| 140 | |
| 141 | // Detach the shaders |
| 142 | mFunctions->detachShader(mProgramID, computeShaderGL->getShaderID()); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 143 | } |
| 144 | else |
| 145 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 146 | // Set the transform feedback state |
| 147 | std::vector<const GLchar *> transformFeedbackVaryings; |
| 148 | for (const auto &tfVarying : mState.getTransformFeedbackVaryingNames()) |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 149 | { |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 150 | transformFeedbackVaryings.push_back(tfVarying.c_str()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 153 | if (transformFeedbackVaryings.empty()) |
| 154 | { |
| 155 | if (mFunctions->transformFeedbackVaryings) |
| 156 | { |
| 157 | mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr, |
| 158 | mState.getTransformFeedbackBufferMode()); |
| 159 | } |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | ASSERT(mFunctions->transformFeedbackVaryings); |
| 164 | mFunctions->transformFeedbackVaryings( |
| 165 | mProgramID, static_cast<GLsizei>(transformFeedbackVaryings.size()), |
| 166 | &transformFeedbackVaryings[0], mState.getTransformFeedbackBufferMode()); |
| 167 | } |
| 168 | |
| 169 | const ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(mState.getAttachedVertexShader()); |
| 170 | const ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(mState.getAttachedFragmentShader()); |
| 171 | |
| 172 | // Attach the shaders |
| 173 | mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 174 | mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID()); |
| 175 | |
| 176 | // Bind attribute locations to match the GL layer. |
| 177 | for (const sh::Attribute &attribute : mState.getAttributes()) |
| 178 | { |
Corentin Wallez | 6c1cbf5 | 2016-11-23 12:44:35 -0500 | [diff] [blame] | 179 | if (!attribute.staticUse || attribute.isBuiltIn()) |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 180 | { |
| 181 | continue; |
| 182 | } |
| 183 | |
| 184 | mFunctions->bindAttribLocation(mProgramID, attribute.location, attribute.name.c_str()); |
| 185 | } |
| 186 | |
| 187 | // Link and verify |
| 188 | mFunctions->linkProgram(mProgramID); |
| 189 | |
| 190 | // Detach the shaders |
| 191 | mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 192 | mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 195 | // Verify the link |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 196 | if (!checkLinkStatus(infoLog)) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 197 | { |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 198 | return false; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Philippe Hamel | 4091119 | 2016-04-07 16:45:50 -0400 | [diff] [blame] | 201 | if (mWorkarounds.alwaysCallUseProgramAfterLink) |
| 202 | { |
| 203 | mStateManager->forceUseProgram(mProgramID); |
| 204 | } |
| 205 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 206 | postLink(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 207 | |
Jamie Madill | b0a838b | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 208 | return true; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 209 | } |
| 210 | |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 211 | GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/) |
| 212 | { |
| 213 | // TODO(jmadill): implement validate |
| 214 | return true; |
| 215 | } |
| 216 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 217 | void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 218 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 219 | if (mFunctions->programUniform1fv != nullptr) |
| 220 | { |
| 221 | mFunctions->programUniform1fv(mProgramID, uniLoc(location), count, v); |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | mStateManager->useProgram(mProgramID); |
| 226 | mFunctions->uniform1fv(uniLoc(location), count, v); |
| 227 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 231 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 232 | if (mFunctions->programUniform2fv != nullptr) |
| 233 | { |
| 234 | mFunctions->programUniform2fv(mProgramID, uniLoc(location), count, v); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | mStateManager->useProgram(mProgramID); |
| 239 | mFunctions->uniform2fv(uniLoc(location), count, v); |
| 240 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 244 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 245 | if (mFunctions->programUniform3fv != nullptr) |
| 246 | { |
| 247 | mFunctions->programUniform3fv(mProgramID, uniLoc(location), count, v); |
| 248 | } |
| 249 | else |
| 250 | { |
| 251 | mStateManager->useProgram(mProgramID); |
| 252 | mFunctions->uniform3fv(uniLoc(location), count, v); |
| 253 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 257 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 258 | if (mFunctions->programUniform4fv != nullptr) |
| 259 | { |
| 260 | mFunctions->programUniform4fv(mProgramID, uniLoc(location), count, v); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | mStateManager->useProgram(mProgramID); |
| 265 | mFunctions->uniform4fv(uniLoc(location), count, v); |
| 266 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 270 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 271 | if (mFunctions->programUniform1iv != nullptr) |
| 272 | { |
| 273 | mFunctions->programUniform1iv(mProgramID, uniLoc(location), count, v); |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | mStateManager->useProgram(mProgramID); |
| 278 | mFunctions->uniform1iv(uniLoc(location), count, v); |
| 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 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 522 | bool ProgramGL::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 523 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 524 | ASSERT(mProgramID != 0u); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 525 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 526 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockName.c_str()); |
| 527 | if (blockIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 528 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 529 | *sizeOut = 0; |
| 530 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 531 | } |
| 532 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 533 | GLint dataSize = 0; |
| 534 | mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, |
| 535 | &dataSize); |
| 536 | *sizeOut = static_cast<size_t>(dataSize); |
| 537 | return true; |
| 538 | } |
| 539 | |
| 540 | bool ProgramGL::getUniformBlockMemberInfo(const std::string &memberUniformName, |
| 541 | sh::BlockMemberInfo *memberInfoOut) const |
| 542 | { |
| 543 | GLuint uniformIndex; |
| 544 | const GLchar *memberNameGLStr = memberUniformName.c_str(); |
| 545 | mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex); |
| 546 | |
| 547 | if (uniformIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 548 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 549 | *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); |
| 550 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 551 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 552 | |
| 553 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET, |
| 554 | &memberInfoOut->offset); |
| 555 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE, |
| 556 | &memberInfoOut->arrayStride); |
| 557 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE, |
| 558 | &memberInfoOut->matrixStride); |
| 559 | |
| 560 | // TODO(jmadill): possibly determine this at the gl::Program level. |
| 561 | GLint isRowMajorMatrix = 0; |
| 562 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR, |
| 563 | &isRowMajorMatrix); |
| 564 | memberInfoOut->isRowMajorMatrix = isRowMajorMatrix != GL_FALSE; |
| 565 | return true; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 566 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 567 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 568 | void ProgramGL::setPathFragmentInputGen(const std::string &inputName, |
| 569 | GLenum genMode, |
| 570 | GLint components, |
| 571 | const GLfloat *coeffs) |
| 572 | { |
| 573 | ASSERT(mEnablePathRendering); |
| 574 | |
| 575 | for (const auto &input : mPathRenderingFragmentInputs) |
| 576 | { |
| 577 | if (input.name == inputName) |
| 578 | { |
| 579 | mFunctions->programPathFragmentInputGenNV(mProgramID, input.location, genMode, |
| 580 | components, coeffs); |
| 581 | ASSERT(mFunctions->getError() == GL_NO_ERROR); |
| 582 | return; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | } |
| 587 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 588 | void ProgramGL::preLink() |
| 589 | { |
| 590 | // Reset the program state |
| 591 | mUniformRealLocationMap.clear(); |
| 592 | mUniformBlockRealLocationMap.clear(); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 593 | mPathRenderingFragmentInputs.clear(); |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 594 | |
| 595 | mMultiviewBaseViewLayerIndexUniformLocation = -1; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | bool ProgramGL::checkLinkStatus(gl::InfoLog &infoLog) |
| 599 | { |
| 600 | GLint linkStatus = GL_FALSE; |
| 601 | mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus); |
| 602 | if (linkStatus == GL_FALSE) |
| 603 | { |
| 604 | // Linking failed, put the error into the info log |
| 605 | GLint infoLogLength = 0; |
| 606 | mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 607 | |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 608 | // Info log length includes the null terminator, so 1 means that the info log is an empty |
| 609 | // string. |
| 610 | if (infoLogLength > 1) |
| 611 | { |
| 612 | std::vector<char> buf(infoLogLength); |
| 613 | mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]); |
| 614 | |
| 615 | mFunctions->deleteProgram(mProgramID); |
| 616 | mProgramID = 0; |
| 617 | |
| 618 | infoLog << buf.data(); |
| 619 | |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 620 | WARN() << "Program link failed unexpectedly: " << buf.data(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 621 | } |
| 622 | else |
| 623 | { |
Yuly Novikov | bcb3f9b | 2017-01-27 22:45:18 -0500 | [diff] [blame] | 624 | WARN() << "Program link failed unexpectedly with no info log."; |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 625 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 626 | |
| 627 | // TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | return true; |
| 632 | } |
| 633 | |
| 634 | void ProgramGL::postLink() |
| 635 | { |
| 636 | // Query the uniform information |
| 637 | ASSERT(mUniformRealLocationMap.empty()); |
Jamie Madill | 48ef11b | 2016-04-27 15:21:52 -0400 | [diff] [blame] | 638 | const auto &uniformLocations = mState.getUniformLocations(); |
| 639 | const auto &uniforms = mState.getUniforms(); |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 640 | mUniformRealLocationMap.resize(uniformLocations.size(), GL_INVALID_INDEX); |
| 641 | for (size_t uniformLocation = 0; uniformLocation < uniformLocations.size(); uniformLocation++) |
| 642 | { |
| 643 | const auto &entry = uniformLocations[uniformLocation]; |
| 644 | if (!entry.used) |
| 645 | { |
| 646 | continue; |
| 647 | } |
| 648 | |
| 649 | // From the spec: |
| 650 | // "Locations for sequential array indices are not required to be sequential." |
| 651 | const gl::LinkedUniform &uniform = uniforms[entry.index]; |
| 652 | std::stringstream fullNameStr; |
| 653 | fullNameStr << uniform.name; |
| 654 | if (uniform.isArray()) |
| 655 | { |
| 656 | fullNameStr << "[" << entry.element << "]"; |
| 657 | } |
| 658 | const std::string &fullName = fullNameStr.str(); |
| 659 | |
| 660 | GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str()); |
| 661 | mUniformRealLocationMap[uniformLocation] = realLocation; |
| 662 | } |
| 663 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 664 | if (mState.usesMultiview()) |
| 665 | { |
| 666 | mMultiviewBaseViewLayerIndexUniformLocation = |
| 667 | mFunctions->getUniformLocation(mProgramID, "webgl_angle_multiviewBaseViewLayerIndex"); |
| 668 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 669 | } |
| 670 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 671 | // Discover CHROMIUM_path_rendering fragment inputs if enabled. |
| 672 | if (!mEnablePathRendering) |
| 673 | return; |
| 674 | |
| 675 | GLint numFragmentInputs = 0; |
| 676 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_ACTIVE_RESOURCES, |
| 677 | &numFragmentInputs); |
| 678 | if (numFragmentInputs <= 0) |
| 679 | return; |
| 680 | |
| 681 | GLint maxNameLength = 0; |
| 682 | mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH, |
| 683 | &maxNameLength); |
| 684 | ASSERT(maxNameLength); |
| 685 | |
| 686 | for (GLint i = 0; i < numFragmentInputs; ++i) |
| 687 | { |
| 688 | std::string name; |
| 689 | name.resize(maxNameLength); |
| 690 | |
| 691 | GLsizei nameLen = 0; |
| 692 | mFunctions->getProgramResourceName(mProgramID, GL_FRAGMENT_INPUT_NV, i, maxNameLength, |
| 693 | &nameLen, &name[0]); |
| 694 | name.resize(nameLen); |
| 695 | |
| 696 | // Ignore built-ins |
| 697 | if (angle::BeginsWith(name, "gl_")) |
| 698 | continue; |
| 699 | |
| 700 | const GLenum kQueryProperties[] = {GL_LOCATION, GL_ARRAY_SIZE}; |
| 701 | GLint queryResults[ArraySize(kQueryProperties)]; |
| 702 | GLsizei queryLength = 0; |
| 703 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 704 | mFunctions->getProgramResourceiv( |
| 705 | mProgramID, GL_FRAGMENT_INPUT_NV, i, static_cast<GLsizei>(ArraySize(kQueryProperties)), |
| 706 | kQueryProperties, static_cast<GLsizei>(ArraySize(queryResults)), &queryLength, |
| 707 | queryResults); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 708 | |
Olli Etuaho | e319171 | 2016-07-18 16:01:10 +0300 | [diff] [blame] | 709 | ASSERT(queryLength == static_cast<GLsizei>(ArraySize(kQueryProperties))); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 710 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 711 | PathRenderingFragmentInput baseElementInput; |
| 712 | baseElementInput.name = name; |
| 713 | baseElementInput.location = queryResults[0]; |
| 714 | mPathRenderingFragmentInputs.push_back(std::move(baseElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 715 | |
| 716 | // If the input is an array it's denoted by [0] suffix on the variable |
| 717 | // name. We'll then create an entry per each array index where index > 0 |
| 718 | if (angle::EndsWith(name, "[0]")) |
| 719 | { |
| 720 | // drop the suffix |
| 721 | name.resize(name.size() - 3); |
| 722 | |
| 723 | const auto arraySize = queryResults[1]; |
| 724 | const auto baseLocation = queryResults[0]; |
| 725 | |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 726 | for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex) |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 727 | { |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 728 | PathRenderingFragmentInput arrayElementInput; |
Corentin Wallez | 054f7ed | 2016-09-20 17:15:59 -0400 | [diff] [blame] | 729 | arrayElementInput.name = name + "[" + ToString(arrayIndex) + "]"; |
Geoff Lang | 3f6a398 | 2016-07-15 15:20:45 -0400 | [diff] [blame] | 730 | arrayElementInput.location = baseLocation + arrayIndex; |
| 731 | mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput)); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
Geoff Lang | 65a0be9 | 2015-10-02 09:57:30 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Martin Radev | 4e619f5 | 2017-08-09 11:50:06 +0300 | [diff] [blame] | 737 | void ProgramGL::enableSideBySideRenderingPath() const |
| 738 | { |
| 739 | ASSERT(mState.usesMultiview()); |
| 740 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 741 | |
| 742 | ASSERT(mFunctions->programUniform1i != nullptr); |
| 743 | mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, -1); |
| 744 | } |
| 745 | |
| 746 | void ProgramGL::enableLayeredRenderingPath(int baseViewIndex) const |
| 747 | { |
| 748 | ASSERT(mState.usesMultiview()); |
| 749 | ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1); |
| 750 | |
| 751 | ASSERT(mFunctions->programUniform1i != nullptr); |
| 752 | mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, |
| 753 | baseViewIndex); |
| 754 | } |
| 755 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 756 | } // namespace rx |