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 | |
| 11 | #include "common/debug.h" |
Geoff Lang | 5ed74cf | 2015-04-14 13:57:07 -0400 | [diff] [blame] | 12 | #include "common/utilities.h" |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 13 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 14 | #include "libANGLE/renderer/gl/ShaderGL.h" |
| 15 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 16 | #include "platform/Platform.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 17 | |
| 18 | namespace rx |
| 19 | { |
| 20 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 21 | ProgramGL::ProgramGL(const gl::Program::Data &data, |
| 22 | const FunctionsGL *functions, |
| 23 | StateManagerGL *stateManager) |
| 24 | : ProgramImpl(data), mFunctions(functions), mStateManager(stateManager), mProgramID(0) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 25 | { |
| 26 | ASSERT(mFunctions); |
| 27 | ASSERT(mStateManager); |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 28 | |
| 29 | mProgramID = mFunctions->createProgram(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 30 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 31 | |
| 32 | ProgramGL::~ProgramGL() |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 33 | { |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 34 | mFunctions->deleteProgram(mProgramID); |
| 35 | mProgramID = 0; |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 36 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 37 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 38 | LinkResult ProgramGL::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) |
| 39 | { |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 40 | UNIMPLEMENTED(); |
| 41 | return LinkResult(false, gl::Error(GL_INVALID_OPERATION)); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | gl::Error ProgramGL::save(gl::BinaryOutputStream *stream) |
| 45 | { |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 46 | UNIMPLEMENTED(); |
| 47 | return gl::Error(GL_INVALID_OPERATION); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 50 | void ProgramGL::setBinaryRetrievableHint(bool retrievable) |
| 51 | { |
| 52 | UNIMPLEMENTED(); |
| 53 | } |
| 54 | |
Jamie Madill | f5f4ad2 | 2015-09-02 18:32:38 +0000 | [diff] [blame] | 55 | LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 56 | { |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 57 | // Reset the program state, delete the current program if one exists |
| 58 | reset(); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 59 | |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 60 | // Set the transform feedback state |
| 61 | std::vector<const GLchar *> transformFeedbackVaryings; |
| 62 | for (const auto &tfVarying : mData.getTransformFeedbackVaryingNames()) |
| 63 | { |
| 64 | transformFeedbackVaryings.push_back(tfVarying.c_str()); |
| 65 | } |
| 66 | |
| 67 | if (transformFeedbackVaryings.empty()) |
| 68 | { |
| 69 | if (mFunctions->transformFeedbackVaryings) |
| 70 | { |
| 71 | mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr, |
| 72 | mData.getTransformFeedbackBufferMode()); |
| 73 | } |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | ASSERT(mFunctions->transformFeedbackVaryings); |
| 78 | mFunctions->transformFeedbackVaryings( |
| 79 | mProgramID, static_cast<GLsizei>(transformFeedbackVaryings.size()), |
| 80 | &transformFeedbackVaryings[0], mData.getTransformFeedbackBufferMode()); |
| 81 | } |
| 82 | |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 83 | const gl::Shader *vertexShader = mData.getAttachedVertexShader(); |
| 84 | const gl::Shader *fragmentShader = mData.getAttachedFragmentShader(); |
| 85 | |
| 86 | const ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(vertexShader); |
| 87 | const ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(fragmentShader); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 88 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 89 | // Attach the shaders |
| 90 | mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 91 | mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID()); |
| 92 | |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 93 | // Bind attribute locations to match the GL layer. |
| 94 | for (const sh::Attribute &attribute : mData.getAttributes()) |
| 95 | { |
| 96 | if (!attribute.staticUse) |
| 97 | { |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | mFunctions->bindAttribLocation(mProgramID, attribute.location, attribute.name.c_str()); |
Geoff Lang | 1528e56 | 2015-08-24 15:10:58 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 104 | // Link and verify |
| 105 | mFunctions->linkProgram(mProgramID); |
| 106 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 107 | // Detach the shaders |
| 108 | mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID()); |
| 109 | mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID()); |
| 110 | |
| 111 | // Verify the link |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 112 | GLint linkStatus = GL_FALSE; |
| 113 | mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 114 | if (linkStatus == GL_FALSE) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 115 | { |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 116 | // Linking failed, put the error into the info log |
| 117 | GLint infoLogLength = 0; |
| 118 | mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 119 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 120 | std::string warning; |
| 121 | if (infoLogLength > 0) |
| 122 | { |
| 123 | std::vector<char> buf(infoLogLength); |
| 124 | mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 125 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 126 | mFunctions->deleteProgram(mProgramID); |
| 127 | mProgramID = 0; |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 128 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 129 | infoLog << buf.data(); |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 130 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 131 | warning = FormatString("Program link failed unexpectedly: %s", buf.data()); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | warning = "Program link failed unexpectedly with no info log."; |
| 136 | } |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 137 | ANGLEPlatformCurrent()->logWarning(warning.c_str()); |
| 138 | TRACE("\n%s", warning.c_str()); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 139 | |
| 140 | // TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 141 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
| 142 | } |
| 143 | |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 144 | // Query the uniform information |
| 145 | ASSERT(mUniformRealLocationMap.empty()); |
| 146 | const auto &uniforms = mData.getUniforms(); |
| 147 | for (const gl::VariableLocation &entry : mData.getUniformLocations()) |
| 148 | { |
| 149 | // From the spec: |
| 150 | // "Locations for sequential array indices are not required to be sequential." |
| 151 | const gl::LinkedUniform &uniform = uniforms[entry.index]; |
| 152 | std::stringstream fullNameStr; |
| 153 | fullNameStr << uniform.name; |
| 154 | if (uniform.isArray()) |
| 155 | { |
| 156 | fullNameStr << "[" << entry.element << "]"; |
| 157 | } |
| 158 | const std::string &fullName = fullNameStr.str(); |
| 159 | |
| 160 | GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str()); |
| 161 | mUniformRealLocationMap.push_back(realLocation); |
| 162 | } |
| 163 | |
| 164 | mUniformIndexToSamplerIndex.resize(mData.getUniforms().size(), GL_INVALID_INDEX); |
| 165 | |
| 166 | for (size_t uniformId = 0; uniformId < uniforms.size(); ++uniformId) |
| 167 | { |
| 168 | const gl::LinkedUniform &linkedUniform = uniforms[uniformId]; |
| 169 | |
| 170 | if (!linkedUniform.isSampler() || !linkedUniform.staticUse) |
| 171 | continue; |
| 172 | |
| 173 | mUniformIndexToSamplerIndex[uniformId] = mSamplerBindings.size(); |
| 174 | |
| 175 | // If uniform is a sampler type, insert it into the mSamplerBindings array |
| 176 | SamplerBindingGL samplerBinding; |
| 177 | samplerBinding.textureType = gl::SamplerTypeToTextureType(linkedUniform.type); |
| 178 | samplerBinding.boundTextureUnits.resize(linkedUniform.elementCount(), 0); |
| 179 | mSamplerBindings.push_back(samplerBinding); |
| 180 | } |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 181 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 182 | return LinkResult(true, gl::Error(GL_NO_ERROR)); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 185 | GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/) |
| 186 | { |
| 187 | // TODO(jmadill): implement validate |
| 188 | return true; |
| 189 | } |
| 190 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 191 | void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 192 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 193 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 194 | mFunctions->uniform1fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 198 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 199 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 200 | mFunctions->uniform2fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 204 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 205 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 206 | mFunctions->uniform3fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 210 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 211 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 212 | mFunctions->uniform4fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 216 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 217 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 218 | mFunctions->uniform1iv(uniLoc(location), count, v); |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 219 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 220 | const gl::VariableLocation &locationEntry = mData.getUniformLocations()[location]; |
| 221 | |
| 222 | size_t samplerIndex = mUniformIndexToSamplerIndex[locationEntry.index]; |
| 223 | if (samplerIndex != GL_INVALID_INDEX) |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 224 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 225 | std::vector<GLuint> &boundTextureUnits = mSamplerBindings[samplerIndex].boundTextureUnits; |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 226 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 227 | size_t copyCount = |
| 228 | std::max<size_t>(count, boundTextureUnits.size() - locationEntry.element); |
| 229 | std::copy(v, v + copyCount, boundTextureUnits.begin() + locationEntry.element); |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 230 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 234 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 235 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 236 | mFunctions->uniform2iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 240 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 241 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 242 | mFunctions->uniform3iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 246 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 247 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 248 | mFunctions->uniform4iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 252 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 253 | mStateManager->useProgram(mProgramID); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 254 | mFunctions->uniform1uiv(location, count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 258 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 259 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 260 | mFunctions->uniform2uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 264 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 265 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 266 | mFunctions->uniform3uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 270 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 271 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 272 | mFunctions->uniform4uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 276 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 277 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 278 | mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 282 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 283 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 284 | mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 288 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 289 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 290 | mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 294 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 295 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 296 | mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 300 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 301 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 302 | mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 306 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 307 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 308 | mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 312 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 313 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 314 | mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 318 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 319 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 320 | mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 324 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 325 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 326 | mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 329 | void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 330 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 331 | // Lazy init |
| 332 | if (mUniformBlockRealLocationMap.empty()) |
| 333 | { |
| 334 | mUniformBlockRealLocationMap.reserve(mData.getUniformBlocks().size()); |
| 335 | for (const gl::UniformBlock &uniformBlock : mData.getUniformBlocks()) |
| 336 | { |
| 337 | const std::string &nameWithIndex = uniformBlock.nameWithArrayIndex(); |
| 338 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, nameWithIndex.c_str()); |
| 339 | mUniformBlockRealLocationMap.push_back(blockIndex); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex]; |
| 344 | if (realBlockIndex != GL_INVALID_INDEX) |
| 345 | { |
| 346 | mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding); |
| 347 | } |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 350 | void ProgramGL::reset() |
| 351 | { |
| 352 | mUniformRealLocationMap.clear(); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 353 | mUniformBlockRealLocationMap.clear(); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 354 | mSamplerBindings.clear(); |
| 355 | mUniformIndexToSamplerIndex.clear(); |
| 356 | } |
| 357 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 358 | GLuint ProgramGL::getProgramID() const |
| 359 | { |
| 360 | return mProgramID; |
| 361 | } |
| 362 | |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 363 | const std::vector<SamplerBindingGL> &ProgramGL::getAppliedSamplerUniforms() const |
| 364 | { |
| 365 | return mSamplerBindings; |
| 366 | } |
| 367 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 368 | bool ProgramGL::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 369 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 370 | ASSERT(mProgramID != 0u); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 371 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 372 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockName.c_str()); |
| 373 | if (blockIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 374 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 375 | *sizeOut = 0; |
| 376 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 379 | GLint dataSize = 0; |
| 380 | mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, |
| 381 | &dataSize); |
| 382 | *sizeOut = static_cast<size_t>(dataSize); |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | bool ProgramGL::getUniformBlockMemberInfo(const std::string &memberUniformName, |
| 387 | sh::BlockMemberInfo *memberInfoOut) const |
| 388 | { |
| 389 | GLuint uniformIndex; |
| 390 | const GLchar *memberNameGLStr = memberUniformName.c_str(); |
| 391 | mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex); |
| 392 | |
| 393 | if (uniformIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 394 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 395 | *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); |
| 396 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 397 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 398 | |
| 399 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET, |
| 400 | &memberInfoOut->offset); |
| 401 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE, |
| 402 | &memberInfoOut->arrayStride); |
| 403 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE, |
| 404 | &memberInfoOut->matrixStride); |
| 405 | |
| 406 | // TODO(jmadill): possibly determine this at the gl::Program level. |
| 407 | GLint isRowMajorMatrix = 0; |
| 408 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR, |
| 409 | &isRowMajorMatrix); |
| 410 | memberInfoOut->isRowMajorMatrix = isRowMajorMatrix != GL_FALSE; |
| 411 | return true; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 412 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 413 | |
| 414 | } // namespace rx |