diff options
author | joshualitt <joshualitt@chromium.org> | 2014-09-17 07:00:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-17 07:00:35 -0700 |
commit | 408d6125b32c86e1f81ce60465e3bf4491e755fc (patch) | |
tree | b134bbf7bd027899121539ee1db93405af9723ed /src/gpu | |
parent | 963504bd0a8ced7e1177ae136da03a9cc343d886 (diff) |
Breaking out full program and frag only
BUG=skia:
R=bsalomon@google.com
Author: joshualitt@chromium.org
Review URL: https://codereview.chromium.org/576543005
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrAAConvexPathRenderer.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrAARectRenderer.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrOvalRenderer.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrBezierEffect.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrCustomCoordsTextureEffect.cpp | 2 | ||||
-rw-r--r-- | src/gpu/effects/GrDashingEffect.cpp | 2 | ||||
-rwxr-xr-x | src/gpu/effects/GrDistanceFieldTextureEffect.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramEffects.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.cpp | 39 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.h | 38 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFullProgramBuilder.cpp | 149 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLFullProgramBuilder.h | 77 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 174 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.h | 93 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLShaderBuilder.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp | 2 |
17 files changed, 317 insertions, 278 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index a479310c5d..a132e7de31 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -6,7 +6,6 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrAAConvexPathRenderer.h" #include "GrContext.h" @@ -19,6 +18,7 @@ #include "SkStrokeRec.h" #include "SkTraceEvent.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp index a08362264d..45247ffd3b 100644 --- a/src/gpu/GrAARectRenderer.cpp +++ b/src/gpu/GrAARectRenderer.cpp @@ -5,9 +5,9 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrAARectRenderer.h" #include "GrGpu.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLGeometryProcessor.h" #include "GrTBackendEffectFactory.h" diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index 77434947f9..ae992ec4fb 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -5,13 +5,13 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrOvalRenderer.h" -#include "GrEffect.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" +#include "GrEffect.h" #include "GrTBackendEffectFactory.h" #include "GrDrawState.h" diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp index 1b4191cc52..c342291523 100644 --- a/src/gpu/effects/GrBezierEffect.cpp +++ b/src/gpu/effects/GrBezierEffect.cpp @@ -5,9 +5,9 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrBezierEffect.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLGeometryProcessor.h" diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp index 9998bdde40..212d181a22 100644 --- a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp +++ b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrCustomCoordsTextureEffect.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 53aba0e388..38a2d4e4ba 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -5,12 +5,12 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrDashingEffect.h" #include "../GrAARectRenderer.h" #include "effects/GrGeometryProcessor.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/GrGLSL.h" diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp index 28035efa86..ab76525719 100755 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrDistanceFieldTextureEffect.h" +#include "gl/builders/GrGLFullProgramBuilder.h" #include "gl/GrGLEffect.h" #include "gl/GrGLSL.h" #include "gl/GrGLTexture.h" diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 112cecd995..8c2dd966b0 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -6,6 +6,8 @@ */ #include "GrGLProgram.h" +#include "builders/GrGLFragmentOnlyProgramBuilder.h" +#include "builders/GrGLFullProgramBuilder.h" #include "GrAllocator.h" #include "GrEffect.h" #include "GrCoordTransform.h" diff --git a/src/gpu/gl/GrGLProgramEffects.cpp b/src/gpu/gl/GrGLProgramEffects.cpp index d69cbbb452..30cec29a8e 100644 --- a/src/gpu/gl/GrGLProgramEffects.cpp +++ b/src/gpu/gl/GrGLProgramEffects.cpp @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#include "gl/builders/GrGLProgramBuilder.h" #include "GrGLProgramEffects.h" #include "gl/GrGLEffect.h" #include "gl/GrGLPathRendering.h" -#include "gl/builders/GrGLProgramBuilder.h" +#include "gl/builders/GrGLFullProgramBuilder.h" +#include "gl/builders/GrGLFragmentOnlyProgramBuilder.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/GrGpuGL.h" diff --git a/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.cpp new file mode 100644 index 0000000000..3ad6b446c1 --- /dev/null +++ b/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrGLFragmentOnlyProgramBuilder.h" +#include "../GrGpuGL.h" + +GrGLFragmentOnlyProgramBuilder::GrGLFragmentOnlyProgramBuilder(GrGpuGL* gpu, + const GrGLProgramDesc& desc) + : INHERITED(gpu, desc) { + SkASSERT(!desc.getHeader().fRequiresVertexShader); + SkASSERT(gpu->glCaps().pathRenderingSupport()); + SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorInput); + SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverageInput); +} + +int GrGLFragmentOnlyProgramBuilder::addTexCoordSets(int count) { + int firstFreeCoordSet = fTexCoordSetCnt; + fTexCoordSetCnt += count; + SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt); + return firstFreeCoordSet; +} + +GrGLProgramEffects* GrGLFragmentOnlyProgramBuilder::createAndEmitEffects( + const GrEffectStage* effectStages[], int effectCnt, + const GrGLProgramDesc::EffectKeyProvider& keyProvider, GrGLSLExpr4* inOutFSColor) { + + GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, + effectCnt); + this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, + effectStages, + effectCnt, + keyProvider, + inOutFSColor); + return pathTexGenEffectsBuilder.finish(); +} diff --git a/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.h b/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.h new file mode 100644 index 0000000000..5a4c4ad369 --- /dev/null +++ b/src/gpu/gl/builders/GrGLFragmentOnlyProgramBuilder.h @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGLFragmentOnlyProgramBuilder_DEFINED +#define GrGLFragmentOnlyProgramBuilder_DEFINED + +#include "GrGLProgramBuilder.h" + +class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { +public: + GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); + + int addTexCoordSets(int count); + +private: + virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, + GrGLSLExpr4* coverage) SK_OVERRIDE {} + + virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, + GrGLSLExpr4* coverage) SK_OVERRIDE { + SkASSERT(NULL == geometryProcessor); + } + + virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[], + int effectCnt, + const GrGLProgramDesc::EffectKeyProvider&, + GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; + + virtual void emitCodeAfterEffects() SK_OVERRIDE {} + + typedef GrGLProgramBuilder INHERITED; +}; + +#endif diff --git a/src/gpu/gl/builders/GrGLFullProgramBuilder.cpp b/src/gpu/gl/builders/GrGLFullProgramBuilder.cpp new file mode 100644 index 0000000000..8a791c0d93 --- /dev/null +++ b/src/gpu/gl/builders/GrGLFullProgramBuilder.cpp @@ -0,0 +1,149 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrGLFullProgramBuilder.h" +#include "../GrGpuGL.h" + +GrGLFullProgramBuilder::GrGLFullProgramBuilder(GrGpuGL* gpu, + const GrGLProgramDesc& desc) + : INHERITED(gpu, desc) + , fGS(this) + , fVS(this) { +} + +void GrGLFullProgramBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, + GrGLSLExpr4* coverage) { + fVS.emitCodeBeforeEffects(color, coverage); +} + +void GrGLFullProgramBuilder::emitGeometryProcessor(const GrEffectStage* geometryProcessor, + GrGLSLExpr4* coverage) { + if (geometryProcessor) { + GrGLProgramDesc::EffectKeyProvider geometryProcessorKeyProvider( + &this->desc(), GrGLProgramDesc::EffectKeyProvider::kGeometryProcessor_EffectType); + fGeometryProcessor.reset(this->createAndEmitEffect( + geometryProcessor, + geometryProcessorKeyProvider, + coverage)); + } +} + +void GrGLFullProgramBuilder::emitCodeAfterEffects() { + fVS.emitCodeAfterEffects(); +} + +void GrGLFullProgramBuilder::addVarying(GrSLType type, + const char* name, + const char** vsOutName, + const char** fsInName, + GrGLShaderVar::Precision fsPrecision) { + fVS.addVarying(type, name, vsOutName); + + SkString* fsInputName = fVS.fOutputs.back().accessName(); + +#if GR_GL_EXPERIMENTAL_GS + if (desc().getHeader().fExperimentalGS) { + // TODO let the caller use these names + fGS.addVarying(type, fsInputName->c_str(), NULL); + fsInputName = fGS.fOutputs.back().accessName(); + } +#endif + fFS.addVarying(type, fsInputName->c_str(), fsInName, fsPrecision); +} + +GrGLFullProgramBuilder::VaryingHandle +GrGLFullProgramBuilder::addSeparableVarying(GrSLType type, + const char* name, + const char** vsOutName, + const char** fsInName) { + addVarying(type, name, vsOutName, fsInName); + SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); + varying.fVariable = fFS.fInputs.back(); + return VaryingHandle::CreateFromSeparableVaryingIndex(fSeparableVaryingInfos.count() - 1); +} + + +GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffects( + const GrEffectStage* effectStages[], + int effectCnt, + const GrGLProgramDesc::EffectKeyProvider& keyProvider, + GrGLSLExpr4* inOutFSColor) { + + GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt); + this->INHERITED::createAndEmitEffects(&programEffectsBuilder, + effectStages, + effectCnt, + keyProvider, + inOutFSColor); + return programEffectsBuilder.finish(); +} + +void GrGLFullProgramBuilder::createAndEmitEffect(GrGLProgramEffectsBuilder* programEffectsBuilder, + const GrEffectStage* effectStages, + const GrGLProgramDesc::EffectKeyProvider& keyProvider, + GrGLSLExpr4* fsInOutColor) { + GrGLSLExpr4 inColor = *fsInOutColor; + GrGLSLExpr4 outColor; + + SkASSERT(effectStages && effectStages->getEffect()); + const GrEffectStage& stage = *effectStages; + + // Using scope to force ASR destructor to be triggered + { + CodeStage::AutoStageRestore csar(&fCodeStage, &stage); + + if (inColor.isZeros()) { + SkString inColorName; + + // Effects have no way to communicate zeros, they treat an empty string as ones. + this->nameVariable(&inColorName, '\0', "input"); + fFS.codeAppendf("vec4 %s = %s;", inColorName.c_str(), inColor.c_str()); + inColor = inColorName; + } + + // create var to hold stage result + SkString outColorName; + this->nameVariable(&outColorName, '\0', "output"); + fFS.codeAppendf("vec4 %s;", outColorName.c_str()); + outColor = outColorName; + + + programEffectsBuilder->emitEffect(stage, + keyProvider.get(0), + outColor.c_str(), + inColor.isOnes() ? NULL : inColor.c_str(), + fCodeStage.stageIndex()); + } + + *fsInOutColor = outColor; +} + +GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffect( + const GrEffectStage* geometryProcessor, + const GrGLProgramDesc::EffectKeyProvider& keyProvider, + GrGLSLExpr4* inOutFSColor) { + + GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, 1); + this->createAndEmitEffect(&programEffectsBuilder, geometryProcessor, keyProvider, inOutFSColor); + return programEffectsBuilder.finish(); +} + +bool GrGLFullProgramBuilder::compileAndAttachShaders(GrGLuint programId, + SkTDArray<GrGLuint>* shaderIds) const { + return INHERITED::compileAndAttachShaders(programId, shaderIds) + && fVS.compileAndAttachShaders(programId, shaderIds) +#if GR_GL_EXPERIMENTAL_GS + && (!desc().getHeader().fExperimentalGS + || fGS.compileAndAttachShaders(programId, shaderIds)) +#endif + ; +} + +void GrGLFullProgramBuilder::bindProgramLocations(GrGLuint programId) { + fVS.bindProgramLocations(programId); + INHERITED::bindProgramLocations(programId); +} diff --git a/src/gpu/gl/builders/GrGLFullProgramBuilder.h b/src/gpu/gl/builders/GrGLFullProgramBuilder.h new file mode 100644 index 0000000000..3ba5724578 --- /dev/null +++ b/src/gpu/gl/builders/GrGLFullProgramBuilder.h @@ -0,0 +1,77 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGLFullProgramBuilder_DEFINED +#define GrGLFullProgramBuilder_DEFINED + +#include "GrGLProgramBuilder.h" + +class GrGLFullProgramBuilder : public GrGLProgramBuilder { +public: + GrGLFullProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); + + /** Add a varying variable to the current program to pass values between vertex and fragment + shaders. If the last two parameters are non-NULL, they are filled in with the name + generated. */ + void addVarying(GrSLType type, + const char* name, + const char** vsOutName = NULL, + const char** fsInName = NULL, + GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precision); + + /** Add a separable varying input variable to the current program. + * A separable varying (fragment shader input) is a varying that can be used also when vertex + * shaders are not used. With a vertex shader, the operation is same as with other + * varyings. Without a vertex shader, such as with NV_path_rendering, GL APIs are used to + * populate the variable. The APIs can refer to the variable through the returned handle. + */ + VaryingHandle addSeparableVarying(GrSLType type, + const char* name, + const char** vsOutName, + const char** fsInName); + + GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } + +private: + virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, + GrGLSLExpr4* coverage) SK_OVERRIDE; + + virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, + GrGLSLExpr4* coverage) SK_OVERRIDE; + + virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[], + int effectCnt, + const GrGLProgramDesc::EffectKeyProvider&, + GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; + + /* + * These functions are temporary and will eventually operate not on effects but on + * geometry processors + */ + void createAndEmitEffect(GrGLProgramEffectsBuilder*, + const GrEffectStage* effectStage, + const GrGLProgramDesc::EffectKeyProvider&, + GrGLSLExpr4* inOutFSColor); + + GrGLProgramEffects* createAndEmitEffect(const GrEffectStage* geometryProcessor, + const GrGLProgramDesc::EffectKeyProvider&, + GrGLSLExpr4* inOutFSColor); + + virtual void emitCodeAfterEffects() SK_OVERRIDE; + + virtual bool compileAndAttachShaders(GrGLuint programId, + SkTDArray<GrGLuint>* shaderIds) const SK_OVERRIDE; + + virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; + + GrGLGeometryShaderBuilder fGS; + GrGLVertexShaderBuilder fVS; + + typedef GrGLProgramBuilder INHERITED; +}; + +#endif diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 279f3a2d53..d306776441 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -326,177 +326,3 @@ void GrGLProgramBuilder::resolveProgramLocations(GrGLuint programId) { const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { return fGpu->ctxInfo(); } - -//////////////////////////////////////////////////////////////////////////////// - -GrGLFullProgramBuilder::GrGLFullProgramBuilder(GrGpuGL* gpu, - const GrGLProgramDesc& desc) - : INHERITED(gpu, desc) - , fGS(this) - , fVS(this) { -} - -void GrGLFullProgramBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, - GrGLSLExpr4* coverage) { - fVS.emitCodeBeforeEffects(color, coverage); -} - -void GrGLFullProgramBuilder::emitGeometryProcessor(const GrEffectStage* geometryProcessor, - GrGLSLExpr4* coverage) { - if (geometryProcessor) { - GrGLProgramDesc::EffectKeyProvider geometryProcessorKeyProvider( - &this->desc(), GrGLProgramDesc::EffectKeyProvider::kGeometryProcessor_EffectType); - fGeometryProcessor.reset(this->createAndEmitEffect( - geometryProcessor, - geometryProcessorKeyProvider, - coverage)); - } -} - -void GrGLFullProgramBuilder::emitCodeAfterEffects() { - fVS.emitCodeAfterEffects(); -} - -void GrGLFullProgramBuilder::addVarying(GrSLType type, - const char* name, - const char** vsOutName, - const char** fsInName, - GrGLShaderVar::Precision fsPrecision) { - fVS.addVarying(type, name, vsOutName); - - SkString* fsInputName = fVS.fOutputs.back().accessName(); - -#if GR_GL_EXPERIMENTAL_GS - if (desc().getHeader().fExperimentalGS) { - // TODO let the caller use these names - fGS.addVarying(type, fsInputName->c_str(), NULL); - fsInputName = fGS.fOutputs.back().accessName(); - } -#endif - fFS.addVarying(type, fsInputName->c_str(), fsInName, fsPrecision); -} - -GrGLFullProgramBuilder::VaryingHandle -GrGLFullProgramBuilder::addSeparableVarying(GrSLType type, - const char* name, - const char** vsOutName, - const char** fsInName) { - addVarying(type, name, vsOutName, fsInName); - SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back(); - varying.fVariable = fFS.fInputs.back(); - return VaryingHandle::CreateFromSeparableVaryingIndex(fSeparableVaryingInfos.count() - 1); -} - - -GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffects( - const GrEffectStage* effectStages[], - int effectCnt, - const GrGLProgramDesc::EffectKeyProvider& keyProvider, - GrGLSLExpr4* inOutFSColor) { - - GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt); - this->INHERITED::createAndEmitEffects(&programEffectsBuilder, - effectStages, - effectCnt, - keyProvider, - inOutFSColor); - return programEffectsBuilder.finish(); -} - -void GrGLFullProgramBuilder::createAndEmitEffect(GrGLProgramEffectsBuilder* programEffectsBuilder, - const GrEffectStage* effectStages, - const GrGLProgramDesc::EffectKeyProvider& keyProvider, - GrGLSLExpr4* fsInOutColor) { - GrGLSLExpr4 inColor = *fsInOutColor; - GrGLSLExpr4 outColor; - - SkASSERT(effectStages && effectStages->getEffect()); - const GrEffectStage& stage = *effectStages; - - // Using scope to force ASR destructor to be triggered - { - CodeStage::AutoStageRestore csar(&fCodeStage, &stage); - - if (inColor.isZeros()) { - SkString inColorName; - - // Effects have no way to communicate zeros, they treat an empty string as ones. - this->nameVariable(&inColorName, '\0', "input"); - fFS.codeAppendf("vec4 %s = %s;", inColorName.c_str(), inColor.c_str()); - inColor = inColorName; - } - - // create var to hold stage result - SkString outColorName; - this->nameVariable(&outColorName, '\0', "output"); - fFS.codeAppendf("vec4 %s;", outColorName.c_str()); - outColor = outColorName; - - - programEffectsBuilder->emitEffect(stage, - keyProvider.get(0), - outColor.c_str(), - inColor.isOnes() ? NULL : inColor.c_str(), - fCodeStage.stageIndex()); - } - - *fsInOutColor = outColor; -} - -GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffect( - const GrEffectStage* geometryProcessor, - const GrGLProgramDesc::EffectKeyProvider& keyProvider, - GrGLSLExpr4* inOutFSColor) { - - GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, 1); - this->createAndEmitEffect(&programEffectsBuilder, geometryProcessor, keyProvider, inOutFSColor); - return programEffectsBuilder.finish(); -} - -bool GrGLFullProgramBuilder::compileAndAttachShaders(GrGLuint programId, - SkTDArray<GrGLuint>* shaderIds) const { - return INHERITED::compileAndAttachShaders(programId, shaderIds) - && fVS.compileAndAttachShaders(programId, shaderIds) -#if GR_GL_EXPERIMENTAL_GS - && (!desc().getHeader().fExperimentalGS - || fGS.compileAndAttachShaders(programId, shaderIds)) -#endif - ; -} - -void GrGLFullProgramBuilder::bindProgramLocations(GrGLuint programId) { - fVS.bindProgramLocations(programId); - INHERITED::bindProgramLocations(programId); -} - -//////////////////////////////////////////////////////////////////////////////// - -GrGLFragmentOnlyProgramBuilder::GrGLFragmentOnlyProgramBuilder(GrGpuGL* gpu, - const GrGLProgramDesc& desc) - : INHERITED(gpu, desc) { - SkASSERT(!desc.getHeader().fRequiresVertexShader); - SkASSERT(gpu->glCaps().pathRenderingSupport()); - SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorInput); - SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverageInput); -} - -int GrGLFragmentOnlyProgramBuilder::addTexCoordSets(int count) { - int firstFreeCoordSet = fTexCoordSetCnt; - fTexCoordSetCnt += count; - SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt); - return firstFreeCoordSet; -} - -GrGLProgramEffects* GrGLFragmentOnlyProgramBuilder::createAndEmitEffects( - const GrEffectStage* effectStages[], int effectCnt, - const GrGLProgramDesc::EffectKeyProvider& keyProvider, GrGLSLExpr4* inOutFSColor) { - - GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, - effectCnt); - this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, - effectStages, - effectCnt, - keyProvider, - inOutFSColor); - return pathTexGenEffectsBuilder.finish(); -} diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 6eaf575ba3..9915ad3f05 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -281,97 +281,4 @@ private: friend class GrGLGeometryShaderBuilder; }; -//////////////////////////////////////////////////////////////////////////////// - -class GrGLFullProgramBuilder : public GrGLProgramBuilder { -public: - GrGLFullProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); - - /** Add a varying variable to the current program to pass values between vertex and fragment - shaders. If the last two parameters are non-NULL, they are filled in with the name - generated. */ - void addVarying(GrSLType type, - const char* name, - const char** vsOutName = NULL, - const char** fsInName = NULL, - GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precision); - - /** Add a separable varying input variable to the current program. - * A separable varying (fragment shader input) is a varying that can be used also when vertex - * shaders are not used. With a vertex shader, the operation is same as with other - * varyings. Without a vertex shader, such as with NV_path_rendering, GL APIs are used to - * populate the variable. The APIs can refer to the variable through the returned handle. - */ - VaryingHandle addSeparableVarying(GrSLType type, - const char* name, - const char** vsOutName, - const char** fsInName); - - GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } - -private: - virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, - GrGLSLExpr4* coverage) SK_OVERRIDE; - - virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, - GrGLSLExpr4* coverage) SK_OVERRIDE; - - virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[], - int effectCnt, - const GrGLProgramDesc::EffectKeyProvider&, - GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; - - /* - * These functions are temporary and will eventually operate not on effects but on - * geometry processors - */ - void createAndEmitEffect(GrGLProgramEffectsBuilder*, - const GrEffectStage* effectStage, - const GrGLProgramDesc::EffectKeyProvider&, - GrGLSLExpr4* inOutFSColor); - - GrGLProgramEffects* createAndEmitEffect(const GrEffectStage* geometryProcessor, - const GrGLProgramDesc::EffectKeyProvider&, - GrGLSLExpr4* inOutFSColor); - - virtual void emitCodeAfterEffects() SK_OVERRIDE; - - virtual bool compileAndAttachShaders(GrGLuint programId, - SkTDArray<GrGLuint>* shaderIds) const SK_OVERRIDE; - - virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; - - GrGLGeometryShaderBuilder fGS; - GrGLVertexShaderBuilder fVS; - - typedef GrGLProgramBuilder INHERITED; -}; - -//////////////////////////////////////////////////////////////////////////////// - -class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { -public: - GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); - - int addTexCoordSets(int count); - -private: - virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, - GrGLSLExpr4* coverage) SK_OVERRIDE {} - - virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, - GrGLSLExpr4* coverage) SK_OVERRIDE { - SkASSERT(NULL == geometryProcessor); - } - - virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[], - int effectCnt, - const GrGLProgramDesc::EffectKeyProvider&, - GrGLSLExpr4* inOutFSColor) SK_OVERRIDE; - - virtual void emitCodeAfterEffects() SK_OVERRIDE {} - - typedef GrGLProgramBuilder INHERITED; -}; - #endif diff --git a/src/gpu/gl/builders/GrGLShaderBuilder.cpp b/src/gpu/gl/builders/GrGLShaderBuilder.cpp index b7c7bbf532..004e09b37b 100644 --- a/src/gpu/gl/builders/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderBuilder.cpp @@ -6,6 +6,7 @@ */ #include "GrGLShaderBuilder.h" +#include "GrGLFullProgramBuilder.h" #include "GrGLProgramBuilder.h" #include "../GrGpuGL.h" #include "../GrGLShaderVar.h" diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp index 5c074a2901..7445676f58 100644 --- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp @@ -6,7 +6,7 @@ */ #include "GrGLVertexShaderBuilder.h" -#include "GrGLProgramBuilder.h" +#include "GrGLFullProgramBuilder.h" #include "GrGLShaderStringBuilder.h" #include "../GrGpuGL.h" #include "../../GrOptDrawState.h" |