OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 Google Inc. | |
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 "GrGLNvprProgramBuilder.h" | |
9 #include "../GrGLGpu.h" | |
10 | |
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) | |
13 | |
14 GrGLNvprProgramBuilder::GrGLNvprProgramBuilder(GrGLGpu* gpu, | |
15 const GrOptDrawState& optState) | |
16 : INHERITED(gpu, optState) | |
17 , fSeparableVaryingInfos(kVarsPerBlock) { | |
18 } | |
19 | |
20 void GrGLNvprProgramBuilder::emitTransforms(const GrPendingFragmentStage& proces
sorStage, | |
21 GrGLProcessor::TransformedCoordsArra
y* outCoords, | |
22 GrGLInstalledFragProc* ifp) { | |
23 const GrFragmentProcessor* effect = processorStage.processor(); | |
24 int numTransforms = effect->numTransforms(); | |
25 | |
26 ifp->fTransforms.push_back_n(numTransforms); | |
27 | |
28 for (int t = 0; t < numTransforms; t++) { | |
29 GrSLType varyingType = | |
30 processorStage.isPerspectiveCoordTransform(t) ? | |
31 kVec3f_GrSLType : | |
32 kVec2f_GrSLType; | |
33 | |
34 const char* varyingName = "MatrixCoord"; | |
35 SkString suffixedVaryingName; | |
36 if (0 != t) { | |
37 suffixedVaryingName.append(varyingName); | |
38 suffixedVaryingName.appendf("_%i", t); | |
39 varyingName = suffixedVaryingName.c_str(); | |
40 } | |
41 GrGLVertToFrag v(varyingType); | |
42 ifp->fTransforms[t].fHandle = this->addSeparableVarying(varyingName, &v)
; | |
43 ifp->fTransforms[t].fType = varyingType; | |
44 | |
45 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, | |
46 (SkString(v.fsIn()), varyingType)); | |
47 } | |
48 } | |
49 | |
50 GrGLInstalledFragProc::ShaderVarHandle | |
51 GrGLNvprProgramBuilder::addSeparableVarying(const char* name, GrGLVarying* v) { | |
52 this->addVarying(name, v); | |
53 SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); | |
54 varying.fVariable = fFS.fInputs.back(); | |
55 return GrGLInstalledFragProc::ShaderVarHandle(fSeparableVaryingInfos.count()
- 1); | |
56 } | |
57 | |
58 void GrGLNvprProgramBuilder::resolveSeparableVaryings(GrGLuint programId) { | |
59 int count = fSeparableVaryingInfos.count(); | |
60 for (int i = 0; i < count; ++i) { | |
61 GrGLint location; | |
62 GL_CALL_RET(location, | |
63 GetProgramResourceLocation(programId, | |
64 GR_GL_FRAGMENT_INPUT, | |
65 fSeparableVaryingInfos[i].fVariab
le.c_str())); | |
66 fSeparableVaryingInfos[i].fLocation = location; | |
67 } | |
68 } | |
69 | |
70 GrGLProgram* GrGLNvprProgramBuilder::createProgram(GrGLuint programID) { | |
71 // this is just for nvpr es, which has separable varyings that are plugged i
n after | |
72 // building | |
73 this->resolveSeparableVaryings(programID); | |
74 return SkNEW_ARGS(GrGLNvprProgram, (fGpu, fDesc, fUniformHandles, programID,
fUniforms, | |
75 fGeometryProcessor, | |
76 fXferProcessor, fFragmentProcessors.get(
), | |
77 fSeparableVaryingInfos)); | |
78 } | |
OLD | NEW |