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