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