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; |
Olli Etuaho | 6794676 | 2016-03-08 15:43:55 +0200 | [diff] [blame^] | 121 | |
| 122 | // Info log length includes the null terminator, so 1 means that the info log is an empty |
| 123 | // string. |
| 124 | if (infoLogLength > 1) |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 125 | { |
| 126 | std::vector<char> buf(infoLogLength); |
| 127 | mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[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 | mFunctions->deleteProgram(mProgramID); |
| 130 | mProgramID = 0; |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 131 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 132 | infoLog << buf.data(); |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 133 | |
Corentin Wallez | 01ad644 | 2016-03-03 13:53:45 -0500 | [diff] [blame] | 134 | warning = FormatString("Program link failed unexpectedly: %s", buf.data()); |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | warning = "Program link failed unexpectedly with no info log."; |
| 139 | } |
unknown | b4a3af2 | 2015-11-25 15:02:51 -0500 | [diff] [blame] | 140 | ANGLEPlatformCurrent()->logWarning(warning.c_str()); |
| 141 | TRACE("\n%s", warning.c_str()); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 142 | |
| 143 | // 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] | 144 | return LinkResult(false, gl::Error(GL_NO_ERROR)); |
| 145 | } |
| 146 | |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 147 | // Query the uniform information |
| 148 | ASSERT(mUniformRealLocationMap.empty()); |
| 149 | const auto &uniforms = mData.getUniforms(); |
| 150 | for (const gl::VariableLocation &entry : mData.getUniformLocations()) |
| 151 | { |
| 152 | // From the spec: |
| 153 | // "Locations for sequential array indices are not required to be sequential." |
| 154 | const gl::LinkedUniform &uniform = uniforms[entry.index]; |
| 155 | std::stringstream fullNameStr; |
| 156 | fullNameStr << uniform.name; |
| 157 | if (uniform.isArray()) |
| 158 | { |
| 159 | fullNameStr << "[" << entry.element << "]"; |
| 160 | } |
| 161 | const std::string &fullName = fullNameStr.str(); |
| 162 | |
| 163 | GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str()); |
| 164 | mUniformRealLocationMap.push_back(realLocation); |
| 165 | } |
| 166 | |
| 167 | mUniformIndexToSamplerIndex.resize(mData.getUniforms().size(), GL_INVALID_INDEX); |
| 168 | |
| 169 | for (size_t uniformId = 0; uniformId < uniforms.size(); ++uniformId) |
| 170 | { |
| 171 | const gl::LinkedUniform &linkedUniform = uniforms[uniformId]; |
| 172 | |
| 173 | if (!linkedUniform.isSampler() || !linkedUniform.staticUse) |
| 174 | continue; |
| 175 | |
| 176 | mUniformIndexToSamplerIndex[uniformId] = mSamplerBindings.size(); |
| 177 | |
| 178 | // If uniform is a sampler type, insert it into the mSamplerBindings array |
| 179 | SamplerBindingGL samplerBinding; |
| 180 | samplerBinding.textureType = gl::SamplerTypeToTextureType(linkedUniform.type); |
| 181 | samplerBinding.boundTextureUnits.resize(linkedUniform.elementCount(), 0); |
| 182 | mSamplerBindings.push_back(samplerBinding); |
| 183 | } |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 184 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 185 | return LinkResult(true, gl::Error(GL_NO_ERROR)); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Jamie Madill | 36cfd6a | 2015-08-18 10:46:20 -0400 | [diff] [blame] | 188 | GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/) |
| 189 | { |
| 190 | // TODO(jmadill): implement validate |
| 191 | return true; |
| 192 | } |
| 193 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 194 | void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 195 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 196 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 197 | mFunctions->uniform1fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 201 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 202 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 203 | mFunctions->uniform2fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 207 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 208 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 209 | mFunctions->uniform3fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 213 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 214 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 215 | mFunctions->uniform4fv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 219 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 220 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 221 | mFunctions->uniform1iv(uniLoc(location), count, v); |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 222 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 223 | const gl::VariableLocation &locationEntry = mData.getUniformLocations()[location]; |
| 224 | |
| 225 | size_t samplerIndex = mUniformIndexToSamplerIndex[locationEntry.index]; |
| 226 | if (samplerIndex != GL_INVALID_INDEX) |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 227 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 228 | std::vector<GLuint> &boundTextureUnits = mSamplerBindings[samplerIndex].boundTextureUnits; |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 229 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 230 | size_t copyCount = |
| 231 | std::max<size_t>(count, boundTextureUnits.size() - locationEntry.element); |
| 232 | std::copy(v, v + copyCount, boundTextureUnits.begin() + locationEntry.element); |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 233 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 237 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 238 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 239 | mFunctions->uniform2iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 243 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 244 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 245 | mFunctions->uniform3iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 249 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 250 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 251 | mFunctions->uniform4iv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 255 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 256 | mStateManager->useProgram(mProgramID); |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 257 | mFunctions->uniform1uiv(location, count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 261 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 262 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 263 | mFunctions->uniform2uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 267 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 268 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 269 | mFunctions->uniform3uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 273 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 274 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 275 | mFunctions->uniform4uiv(uniLoc(location), count, v); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 279 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 280 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 281 | mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 285 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 286 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 287 | mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 291 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 292 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 293 | mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 297 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 298 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 299 | mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 303 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 304 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 305 | mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 309 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 310 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 311 | mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 315 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 316 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 317 | mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 321 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 322 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 323 | mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) |
| 327 | { |
Geoff Lang | 63cbace | 2015-02-26 10:03:12 -0500 | [diff] [blame] | 328 | mStateManager->useProgram(mProgramID); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 329 | mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 330 | } |
| 331 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 332 | void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) |
| 333 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 334 | // Lazy init |
| 335 | if (mUniformBlockRealLocationMap.empty()) |
| 336 | { |
| 337 | mUniformBlockRealLocationMap.reserve(mData.getUniformBlocks().size()); |
| 338 | for (const gl::UniformBlock &uniformBlock : mData.getUniformBlocks()) |
| 339 | { |
| 340 | const std::string &nameWithIndex = uniformBlock.nameWithArrayIndex(); |
| 341 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, nameWithIndex.c_str()); |
| 342 | mUniformBlockRealLocationMap.push_back(blockIndex); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex]; |
| 347 | if (realBlockIndex != GL_INVALID_INDEX) |
| 348 | { |
| 349 | mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding); |
| 350 | } |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 353 | void ProgramGL::reset() |
| 354 | { |
| 355 | mUniformRealLocationMap.clear(); |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 356 | mUniformBlockRealLocationMap.clear(); |
Geoff Lang | 01306fc | 2015-10-05 16:53:10 +0000 | [diff] [blame] | 357 | mSamplerBindings.clear(); |
| 358 | mUniformIndexToSamplerIndex.clear(); |
| 359 | } |
| 360 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 361 | GLuint ProgramGL::getProgramID() const |
| 362 | { |
| 363 | return mProgramID; |
| 364 | } |
| 365 | |
Geoff Lang | f51bc79 | 2015-05-04 14:57:03 -0400 | [diff] [blame] | 366 | const std::vector<SamplerBindingGL> &ProgramGL::getAppliedSamplerUniforms() const |
| 367 | { |
| 368 | return mSamplerBindings; |
| 369 | } |
| 370 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 371 | bool ProgramGL::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 372 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 373 | ASSERT(mProgramID != 0u); |
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 | GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockName.c_str()); |
| 376 | if (blockIndex == GL_INVALID_INDEX) |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 377 | { |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 378 | *sizeOut = 0; |
| 379 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 380 | } |
| 381 | |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 382 | GLint dataSize = 0; |
| 383 | mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, |
| 384 | &dataSize); |
| 385 | *sizeOut = static_cast<size_t>(dataSize); |
| 386 | return true; |
| 387 | } |
| 388 | |
| 389 | bool ProgramGL::getUniformBlockMemberInfo(const std::string &memberUniformName, |
| 390 | sh::BlockMemberInfo *memberInfoOut) const |
| 391 | { |
| 392 | GLuint uniformIndex; |
| 393 | const GLchar *memberNameGLStr = memberUniformName.c_str(); |
| 394 | mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex); |
| 395 | |
| 396 | if (uniformIndex == GL_INVALID_INDEX) |
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 | *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); |
| 399 | return false; |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 400 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 401 | |
| 402 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET, |
| 403 | &memberInfoOut->offset); |
| 404 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE, |
| 405 | &memberInfoOut->arrayStride); |
| 406 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE, |
| 407 | &memberInfoOut->matrixStride); |
| 408 | |
| 409 | // TODO(jmadill): possibly determine this at the gl::Program level. |
| 410 | GLint isRowMajorMatrix = 0; |
| 411 | mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR, |
| 412 | &isRowMajorMatrix); |
| 413 | memberInfoOut->isRowMajorMatrix = isRowMajorMatrix != GL_FALSE; |
| 414 | return true; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 415 | } |
Jamie Madill | 4a3c234 | 2015-10-08 12:58:45 -0400 | [diff] [blame] | 416 | |
| 417 | } // namespace rx |