joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame^] | 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 "../GrGpuGL.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(GrGpuGL* gpu, |
| 15 | const GrOptDrawState& optState, |
| 16 | const GrGLProgramDesc& desc) |
| 17 | : INHERITED(gpu, optState, desc) |
| 18 | , fSeparableVaryingInfos(kVarsPerBlock) { |
| 19 | } |
| 20 | |
| 21 | void GrGLNvprProgramBuilder::emitTransforms(const GrProcessorStage& processorStage, |
| 22 | GrGLProcessor::TransformedCoordsArray* outCoords, |
| 23 | GrGLInstalledProcessors* installedProcessors) { |
| 24 | const GrProcessor* effect = processorStage.getProcessor(); |
| 25 | int numTransforms = effect->numTransforms(); |
| 26 | |
| 27 | SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = |
| 28 | installedProcessors->addTransforms(); |
| 29 | transforms.push_back_n(numTransforms); |
| 30 | |
| 31 | for (int t = 0; t < numTransforms; t++) { |
| 32 | GrSLType varyingType = |
| 33 | processorStage.isPerspectiveCoordTransform(t, false) ? |
| 34 | kVec3f_GrSLType : |
| 35 | kVec2f_GrSLType; |
| 36 | |
| 37 | const char* varyingName = "MatrixCoord"; |
| 38 | SkString suffixedVaryingName; |
| 39 | if (0 != t) { |
| 40 | suffixedVaryingName.append(varyingName); |
| 41 | suffixedVaryingName.appendf("_%i", t); |
| 42 | varyingName = suffixedVaryingName.c_str(); |
| 43 | } |
| 44 | const char* vsVaryingName; |
| 45 | const char* fsVaryingName; |
| 46 | transforms[t].fHandle = this->addSeparableVarying(varyingType, varyingName, |
| 47 | &vsVaryingName, &fsVaryingName); |
| 48 | transforms[t].fType = varyingType; |
| 49 | |
| 50 | SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, |
| 51 | (SkString(fsVaryingName), varyingType)); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | GrGLInstalledProcessors::ShaderVarHandle |
| 56 | GrGLNvprProgramBuilder::addSeparableVarying(GrSLType type, |
| 57 | const char* name, |
| 58 | const char** vsOutName, |
| 59 | const char** fsInName) { |
| 60 | addVarying(type, name, vsOutName, fsInName); |
| 61 | SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); |
| 62 | varying.fVariable = fFS.fInputs.back(); |
| 63 | return GrGLInstalledProcessors::ShaderVarHandle(fSeparableVaryingInfos.count() - 1); |
| 64 | } |
| 65 | |
| 66 | void GrGLNvprProgramBuilder::resolveSeparableVaryings(GrGLuint programId) { |
| 67 | int count = fSeparableVaryingInfos.count(); |
| 68 | for (int i = 0; i < count; ++i) { |
| 69 | GrGLint location; |
| 70 | GL_CALL_RET(location, |
| 71 | GetProgramResourceLocation(programId, |
| 72 | GR_GL_FRAGMENT_INPUT, |
| 73 | fSeparableVaryingInfos[i].fVariable.c_str())); |
| 74 | fSeparableVaryingInfos[i].fLocation = location; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | GrGLProgram* GrGLNvprProgramBuilder::createProgram(GrGLuint programID) { |
| 79 | // this is just for nvpr es, which has separable varyings that are plugged in after |
| 80 | // building |
| 81 | this->resolveSeparableVaryings(programID); |
| 82 | return SkNEW_ARGS(GrGLNvprProgram, (fGpu, fDesc, fUniformHandles, programID, fUniforms, |
| 83 | fColorEffects, fCoverageEffects, fSeparableVaryingInfos)); |
| 84 | } |