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