OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gl/GrGLUniformHandler.h" | 8 #include "gl/GrGLUniformHandler.h" |
9 | 9 |
10 #include "gl/GrGLCaps.h" | 10 #include "gl/GrGLCaps.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 uni.fVariable.setArrayCount(arrayCount); | 45 uni.fVariable.setArrayCount(arrayCount); |
46 uni.fVisibility = visibility; | 46 uni.fVisibility = visibility; |
47 uni.fVariable.setPrecision(precision); | 47 uni.fVariable.setPrecision(precision); |
48 | 48 |
49 if (outName) { | 49 if (outName) { |
50 *outName = uni.fVariable.c_str(); | 50 *outName = uni.fVariable.c_str(); |
51 } | 51 } |
52 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); | 52 return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1); |
53 } | 53 } |
54 | 54 |
| 55 GrGLSLUniformHandler::SamplerHandle GrGLUniformHandler::internalAddSampler(uint3
2_t visibility, |
| 56 GrPix
elConfig config, |
| 57 GrSLT
ype type, |
| 58 GrSLP
recision precision, |
| 59 const
char* name) { |
| 60 SkASSERT(name && strlen(name)); |
| 61 SkDEBUGCODE(static const uint32_t kVisMask = kVertex_GrShaderFlag | kFragmen
t_GrShaderFlag); |
| 62 SkASSERT(0 == (~kVisMask & visibility)); |
| 63 SkASSERT(0 != visibility); |
| 64 SkString mangleName; |
| 65 char prefix = 'u'; |
| 66 fProgramBuilder->nameVariable(&mangleName, prefix, name, true); |
| 67 fSamplers.emplace_back(visibility, config, type, precision, mangleName.c_str
()); |
| 68 return GrGLSLUniformHandler::SamplerHandle(fSamplers.count() - 1); |
| 69 } |
| 70 |
55 void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { | 71 void GrGLUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString*
out) const { |
56 for (int i = 0; i < fUniforms.count(); ++i) { | 72 for (int i = 0; i < fUniforms.count(); ++i) { |
57 if (fUniforms[i].fVisibility & visibility) { | 73 if (fUniforms[i].fVisibility & visibility) { |
58 fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out); | 74 fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out); |
59 out->append(";\n"); | 75 out->append(";\n"); |
60 } | 76 } |
61 } | 77 } |
| 78 for (int i = 0; i < fSamplers.count(); ++i) { |
| 79 if (fSamplers[i].visibility() & visibility) { |
| 80 fSamplers[i].fShaderVar.appendDecl(fProgramBuilder->glslCaps(), out)
; |
| 81 out->append(";\n"); |
| 82 } |
| 83 } |
62 } | 84 } |
63 | 85 |
64 void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
& caps) { | 86 void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps
& caps) { |
65 if (caps.bindUniformLocationSupport()) { | 87 if (caps.bindUniformLocationSupport()) { |
66 int count = fUniforms.count(); | 88 int count = fUniforms.count(); |
67 for (int i = 0; i < count; ++i) { | 89 for (int i = 0; i < count; ++i) { |
68 GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_s
tr())); | 90 GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_s
tr())); |
69 fUniforms[i].fLocation = i; | 91 fUniforms[i].fLocation = i; |
70 } | 92 } |
| 93 for (int i = 0; i < fSamplers.count(); ++i) { |
| 94 GL_CALL(BindUniformLocation(programID, i, fSamplers[i].fVariable.c_s
tr())); |
| 95 fSamplers[i].fLocation = i; |
| 96 } |
71 } | 97 } |
72 } | 98 } |
73 | 99 |
74 void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
caps) { | 100 void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps&
caps) { |
75 if (!caps.bindUniformLocationSupport()) { | 101 if (!caps.bindUniformLocationSupport()) { |
76 int count = fUniforms.count(); | 102 int count = fUniforms.count(); |
77 for (int i = 0; i < count; ++i) { | 103 for (int i = 0; i < count; ++i) { |
78 GrGLint location; | 104 GrGLint location; |
79 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa
riable.c_str())); | 105 GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVa
riable.c_str())); |
80 fUniforms[i].fLocation = location; | 106 fUniforms[i].fLocation = location; |
81 } | 107 } |
| 108 for (int i = 0; i < fSamplers.count(); ++i) { |
| 109 GrGLint location; |
| 110 GL_CALL_RET(location, GetUniformLocation(programID, fSamplers[i].fVa
riable.c_str())); |
| 111 fSamplers[i].fLocation = location; |
| 112 } |
82 } | 113 } |
83 } | 114 } |
84 | 115 |
85 const GrGLGpu* GrGLUniformHandler::glGpu() const { | 116 const GrGLGpu* GrGLUniformHandler::glGpu() const { |
86 GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder; | 117 GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder; |
87 return glPB->gpu(); | 118 return glPB->gpu(); |
88 } | 119 } |
OLD | NEW |