OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrGLNvprProgramBuilder.h" | 8 #include "GrGLNvprProgramBuilder.h" |
9 #include "../GrGpuGL.h" | 9 #include "../GrGpuGL.h" |
10 | 10 |
11 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) | 11 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) |
12 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) | 12 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) |
13 | 13 |
14 GrGLNvprProgramBuilder::GrGLNvprProgramBuilder(GrGpuGL* gpu, | 14 GrGLNvprProgramBuilder::GrGLNvprProgramBuilder(GrGpuGL* gpu, |
15 const GrOptDrawState& optState, | 15 const GrOptDrawState& optState, |
16 const GrGLProgramDesc& desc) | 16 const GrGLProgramDesc& desc) |
17 : INHERITED(gpu, optState, desc) | 17 : INHERITED(gpu, optState, desc) |
18 , fSeparableVaryingInfos(kVarsPerBlock) { | 18 , fSeparableVaryingInfos(kVarsPerBlock) { |
19 } | 19 } |
20 | 20 |
21 void GrGLNvprProgramBuilder::emitTransforms(const GrFragmentStage& processorStag
e, | 21 void GrGLNvprProgramBuilder::emitTransforms(const GrProcessorStage& processorSta
ge, |
22 GrGLProcessor::TransformedCoordsArra
y* outCoords, | 22 GrGLProcessor::TransformedCoordsArra
y* outCoords, |
23 GrGLInstalledFragProc* ifp) { | 23 GrGLInstalledProcessors* installedPr
ocessors) { |
24 const GrFragmentProcessor* effect = processorStage.getProcessor(); | 24 const GrProcessor* effect = processorStage.getProcessor(); |
25 int numTransforms = effect->numTransforms(); | 25 int numTransforms = effect->numTransforms(); |
26 | 26 |
27 ifp->fTransforms.push_back_n(numTransforms); | 27 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = |
| 28 installedProcessors->addTransforms(); |
| 29 transforms.push_back_n(numTransforms); |
28 | 30 |
29 for (int t = 0; t < numTransforms; t++) { | 31 for (int t = 0; t < numTransforms; t++) { |
30 GrSLType varyingType = | 32 GrSLType varyingType = |
31 processorStage.isPerspectiveCoordTransform(t, false) ? | 33 processorStage.isPerspectiveCoordTransform(t, false) ? |
32 kVec3f_GrSLType : | 34 kVec3f_GrSLType : |
33 kVec2f_GrSLType; | 35 kVec2f_GrSLType; |
34 | 36 |
35 const char* varyingName = "MatrixCoord"; | 37 const char* varyingName = "MatrixCoord"; |
36 SkString suffixedVaryingName; | 38 SkString suffixedVaryingName; |
37 if (0 != t) { | 39 if (0 != t) { |
38 suffixedVaryingName.append(varyingName); | 40 suffixedVaryingName.append(varyingName); |
39 suffixedVaryingName.appendf("_%i", t); | 41 suffixedVaryingName.appendf("_%i", t); |
40 varyingName = suffixedVaryingName.c_str(); | 42 varyingName = suffixedVaryingName.c_str(); |
41 } | 43 } |
42 const char* vsVaryingName; | 44 const char* vsVaryingName; |
43 const char* fsVaryingName; | 45 const char* fsVaryingName; |
44 ifp->fTransforms[t].fHandle = this->addSeparableVarying(varyingType, var
yingName, | 46 transforms[t].fHandle = this->addSeparableVarying(varyingType, varyingNa
me, |
45 &vsVaryingName,
&fsVaryingName); | 47 &vsVaryingName, &fsVar
yingName); |
46 ifp->fTransforms[t].fType = varyingType; | 48 transforms[t].fType = varyingType; |
47 | 49 |
48 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, | 50 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, |
49 (SkString(fsVaryingName), varyingType)); | 51 (SkString(fsVaryingName), varyingType)); |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
53 GrGLInstalledFragProc::ShaderVarHandle | 55 GrGLInstalledProcessors::ShaderVarHandle |
54 GrGLNvprProgramBuilder::addSeparableVarying(GrSLType type, | 56 GrGLNvprProgramBuilder::addSeparableVarying(GrSLType type, |
55 const char* name, | 57 const char* name, |
56 const char** vsOutName, | 58 const char** vsOutName, |
57 const char** fsInName) { | 59 const char** fsInName) { |
58 addVarying(type, name, vsOutName, fsInName); | 60 addVarying(type, name, vsOutName, fsInName); |
59 SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); | 61 SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); |
60 varying.fVariable = fFS.fInputs.back(); | 62 varying.fVariable = fFS.fInputs.back(); |
61 return GrGLInstalledFragProc::ShaderVarHandle(fSeparableVaryingInfos.count()
- 1); | 63 return GrGLInstalledProcessors::ShaderVarHandle(fSeparableVaryingInfos.count
() - 1); |
62 } | 64 } |
63 | 65 |
64 void GrGLNvprProgramBuilder::resolveSeparableVaryings(GrGLuint programId) { | 66 void GrGLNvprProgramBuilder::resolveSeparableVaryings(GrGLuint programId) { |
65 int count = fSeparableVaryingInfos.count(); | 67 int count = fSeparableVaryingInfos.count(); |
66 for (int i = 0; i < count; ++i) { | 68 for (int i = 0; i < count; ++i) { |
67 GrGLint location; | 69 GrGLint location; |
68 GL_CALL_RET(location, | 70 GL_CALL_RET(location, |
69 GetProgramResourceLocation(programId, | 71 GetProgramResourceLocation(programId, |
70 GR_GL_FRAGMENT_INPUT, | 72 GR_GL_FRAGMENT_INPUT, |
71 fSeparableVaryingInfos[i].fVariab
le.c_str())); | 73 fSeparableVaryingInfos[i].fVariab
le.c_str())); |
72 fSeparableVaryingInfos[i].fLocation = location; | 74 fSeparableVaryingInfos[i].fLocation = location; |
73 } | 75 } |
74 } | 76 } |
75 | 77 |
76 GrGLProgram* GrGLNvprProgramBuilder::createProgram(GrGLuint programID) { | 78 GrGLProgram* GrGLNvprProgramBuilder::createProgram(GrGLuint programID) { |
77 // this is just for nvpr es, which has separable varyings that are plugged i
n after | 79 // this is just for nvpr es, which has separable varyings that are plugged i
n after |
78 // building | 80 // building |
79 this->resolveSeparableVaryings(programID); | 81 this->resolveSeparableVaryings(programID); |
80 return SkNEW_ARGS(GrGLNvprProgram, (fGpu, fDesc, fUniformHandles, programID,
fUniforms, | 82 return SkNEW_ARGS(GrGLNvprProgram, (fGpu, fDesc, fUniformHandles, programID,
fUniforms, |
81 fFragmentProcessors.get(), fSeparableVar
yingInfos)); | 83 fColorEffects, fCoverageEffects, fSepara
bleVaryingInfos)); |
82 } | 84 } |
OLD | NEW |