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