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 "GrGLSkiaProgramBuilder.h" |
| 9 #include "../GrGLProgram.h" |
| 10 |
| 11 GrGLSkiaProgramBuilder::GrGLSkiaProgramBuilder(GrGpuGL* gpu, |
| 12 const GrGLProgramDesc& desc) |
| 13 : INHERITED(gpu, desc) { |
| 14 } |
| 15 |
| 16 void GrGLSkiaProgramBuilder::emitTransforms(const GrProcessorStage& effectStage, |
| 17 GrGLProcessor::TransformedCoordsArra
y* outCoords, |
| 18 GrGLInstalledProcessors* installedPr
ocessors) { |
| 19 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = |
| 20 installedProcessors->addTransforms(); |
| 21 const GrProcessor* effect = effectStage.getProcessor(); |
| 22 int numTransforms = effect->numTransforms(); |
| 23 transforms.push_back_n(numTransforms); |
| 24 |
| 25 for (int t = 0; t < numTransforms; t++) { |
| 26 const char* uniName = "StageMatrix"; |
| 27 GrSLType varyingType = |
| 28 effectStage.isPerspectiveCoordTransform(t, fVS.hasExplicitLocalC
oords()) ? |
| 29 kVec3f_GrSLType : |
| 30 kVec2f_GrSLType; |
| 31 |
| 32 SkString suffixedUniName; |
| 33 if (0 != t) { |
| 34 suffixedUniName.append(uniName); |
| 35 suffixedUniName.appendf("_%i", t); |
| 36 uniName = suffixedUniName.c_str(); |
| 37 } |
| 38 transforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVertex_Vis
ibility, |
| 39 kMat33f_GrSLType, |
| 40 uniName, |
| 41 &uniName).toShaderBuilderIndex(
); |
| 42 |
| 43 const char* varyingName = "MatrixCoord"; |
| 44 SkString suffixedVaryingName; |
| 45 if (0 != t) { |
| 46 suffixedVaryingName.append(varyingName); |
| 47 suffixedVaryingName.appendf("_%i", t); |
| 48 varyingName = suffixedVaryingName.c_str(); |
| 49 } |
| 50 const char* vsVaryingName; |
| 51 const char* fsVaryingName; |
| 52 this->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingNam
e); |
| 53 |
| 54 const GrGLShaderVar& coords = |
| 55 kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords()
? |
| 56 fVS.positionAttribute() : |
| 57 fVS.localCoordsAttribute(); |
| 58 |
| 59 // varying = matrix * coords (logically) |
| 60 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); |
| 61 if (kVec2f_GrSLType == varyingType) { |
| 62 fVS.codeAppendf("%s = (%s * vec3(%s, 1)).xy;", |
| 63 vsVaryingName, uniName, coords.c_str()); |
| 64 } else { |
| 65 fVS.codeAppendf("%s = %s * vec3(%s, 1);", |
| 66 vsVaryingName, uniName, coords.c_str()); |
| 67 } |
| 68 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, |
| 69 (SkString(fsVaryingName), varyingType)); |
| 70 } |
| 71 } |
| 72 |
| 73 GrGLProgram* GrGLSkiaProgramBuilder::createProgram(GrGLuint programID) { |
| 74 return SkNEW_ARGS(GrGLSkiaProgram, (fGpu, fDesc, fUniformHandles, programID,
fUniforms, |
| 75 fGeometryProcessor, fColorEffects, fCove
rageEffects)); |
| 76 } |
OLD | NEW |