| 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 "GrGLFragmentOnlyProgramBuilder.h" | |
| 9 #include "../GrGpuGL.h" | |
| 10 | |
| 11 GrGLFragmentOnlyProgramBuilder::GrGLFragmentOnlyProgramBuilder(GrGpuGL* gpu, | |
| 12 const GrOptDrawSt
ate& optState, | |
| 13 const GrGLProgram
Desc& desc) | |
| 14 : INHERITED(gpu, optState, desc) { | |
| 15 SkASSERT(desc.getHeader().fUseFragShaderOnly); | |
| 16 SkASSERT(gpu->glCaps().pathRenderingSupport()); | |
| 17 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn
put); | |
| 18 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag
eInput); | |
| 19 } | |
| 20 | |
| 21 int GrGLFragmentOnlyProgramBuilder::addTexCoordSets(int count) { | |
| 22 int firstFreeCoordSet = fTexCoordSetCnt; | |
| 23 fTexCoordSetCnt += count; | |
| 24 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt)
; | |
| 25 return firstFreeCoordSet; | |
| 26 } | |
| 27 | |
| 28 void | |
| 29 GrGLFragmentOnlyProgramBuilder::createAndEmitEffects(const GrGeometryStage* geom
etryProcessor, | |
| 30 const GrFragmentStage* colo
rStages[], | |
| 31 const GrFragmentStage* cove
rageStages[], | |
| 32 GrGLSLExpr4* inputColor, | |
| 33 GrGLSLExpr4* inputCoverage)
{ | |
| 34 /////////////////////////////////////////////////////////////////////////// | |
| 35 // emit the per-effect code for both color and coverage effects | |
| 36 | |
| 37 EffectKeyProvider colorKeyProvider(&this->desc(), EffectKeyProvider::kColor_
EffectType); | |
| 38 fColorEffects.reset(this->onCreateAndEmitEffects(colorStages, | |
| 39 this->desc().numColorEffect
s(), | |
| 40 colorKeyProvider, | |
| 41 inputColor)); | |
| 42 | |
| 43 EffectKeyProvider coverageKeyProvider(&this->desc(), EffectKeyProvider::kCov
erage_EffectType); | |
| 44 fCoverageEffects.reset(this->onCreateAndEmitEffects(coverageStages, | |
| 45 this->desc().numCoverage
Effects(), | |
| 46 coverageKeyProvider, | |
| 47 inputCoverage)); | |
| 48 } | |
| 49 | |
| 50 GrGLProgramEffects* GrGLFragmentOnlyProgramBuilder::onCreateAndEmitEffects( | |
| 51 const GrFragmentStage* effectStages[], int effectCnt, | |
| 52 const GrGLProgramDesc::EffectKeyProvider& keyProvider, GrGLSLExpr4* inOu
tFSColor) { | |
| 53 fProgramEffects.reset(SkNEW_ARGS(GrGLPathTexGenProgramEffects, (effectCnt)))
; | |
| 54 this->INHERITED::createAndEmitEffects(effectStages, | |
| 55 effectCnt, | |
| 56 keyProvider, | |
| 57 inOutFSColor); | |
| 58 return fProgramEffects.detach(); | |
| 59 } | |
| 60 | |
| 61 void GrGLFragmentOnlyProgramBuilder::emitEffect(const GrProcessorStage& stage, | |
| 62 const GrProcessorKey& key, | |
| 63 const char* outColor, | |
| 64 const char* inColor, | |
| 65 int stageIndex) { | |
| 66 SkASSERT(fProgramEffects.get()); | |
| 67 const GrProcessor& effect = *stage.getProcessor(); | |
| 68 | |
| 69 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(effect.numTransforms()
); | |
| 70 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(effect.numTextures()); | |
| 71 | |
| 72 this->setupPathTexGen(stage, &coords); | |
| 73 this->emitSamplers(effect, &samplers); | |
| 74 | |
| 75 SkASSERT(fEffectEmitter); | |
| 76 GrGLProcessor* glEffect = fEffectEmitter->createGLInstance(); | |
| 77 fProgramEffects->addEffect(glEffect); | |
| 78 | |
| 79 GrGLFragmentShaderBuilder* fsBuilder = this->getFragmentShaderBuilder(); | |
| 80 // Enclose custom code in a block to avoid namespace conflicts | |
| 81 SkString openBrace; | |
| 82 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | |
| 83 fsBuilder->codeAppend(openBrace.c_str()); | |
| 84 | |
| 85 fEffectEmitter->emit(key, outColor, inColor, coords, samplers); | |
| 86 | |
| 87 fsBuilder->codeAppend("\t}\n"); | |
| 88 } | |
| 89 | |
| 90 void GrGLFragmentOnlyProgramBuilder::setupPathTexGen( | |
| 91 const GrProcessorStage& effectStage, GrGLProcessor::TransformedCoordsArr
ay* outCoords) { | |
| 92 int numTransforms = effectStage.getProcessor()->numTransforms(); | |
| 93 int texCoordIndex = this->addTexCoordSets(numTransforms); | |
| 94 | |
| 95 fProgramEffects->addTransforms(texCoordIndex); | |
| 96 | |
| 97 SkString name; | |
| 98 for (int t = 0; t < numTransforms; ++t) { | |
| 99 GrSLType type = | |
| 100 effectStage.isPerspectiveCoordTransform(t, false) ? | |
| 101 kVec3f_GrSLType : | |
| 102 kVec2f_GrSLType; | |
| 103 | |
| 104 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); | |
| 105 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, (nam
e, type)); | |
| 106 } | |
| 107 } | |
| OLD | NEW |