Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
| 9 | |
| 10 | #include "src/gpu/glsl/GrGLSL.h" |
| 11 | #include "src/gpu/glsl/GrGLSLShaderBuilder.h" |
| 12 | |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 13 | GrShaderVar GrGLSLUniformHandler::getUniformMapping(const GrFragmentProcessor& owner, |
| 14 | SkString rawName) const { |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 15 | for (int i = this->numUniforms() - 1; i >= 0; i--) { |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 16 | const UniformInfo& u = this->uniform(i); |
| 17 | if (u.fOwner == &owner && u.fRawName == rawName) { |
| 18 | return u.fVariable; |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 19 | } |
| 20 | } |
Michael Ludwig | e88320b | 2020-06-24 09:04:56 -0400 | [diff] [blame] | 21 | return GrShaderVar(); |
| 22 | } |
| 23 | |
| 24 | GrShaderVar GrGLSLUniformHandler::liftUniformToVertexShader(const GrFragmentProcessor& owner, |
| 25 | SkString rawName) { |
| 26 | for (int i = this->numUniforms() - 1; i >= 0; i--) { |
| 27 | UniformInfo& u = this->uniform(i); |
| 28 | if (u.fOwner == &owner && u.fRawName == rawName) { |
| 29 | u.fVisibility |= kVertex_GrShaderFlag; |
| 30 | return u.fVariable; |
| 31 | } |
| 32 | } |
| 33 | // Uniform not found; it's better to return a void variable than to assert because sample |
| 34 | // matrices that are const/uniform are treated the same for most of the code. When the sample |
| 35 | // matrix expression can't be found as a uniform, we can infer it's a constant. |
| 36 | return GrShaderVar(); |
Ethan Nicholas | 5843012 | 2020-04-14 09:54:02 -0400 | [diff] [blame] | 37 | } |