Add a requiresVertexShader method to GrGLEffect
Adds requiresVertexShader to GrGLEffect and updates the necessary effects to override it and return true. Also reworks GrGLProgram and GrGLShaderBuilder so the program creates all the GL effects at the beginning, and determines if it needs a vertex shader before creating the shader builder. R=bsalomon@google.com Author: cdalton@nvidia.com Review URL: https://chromiumcodereview.appspot.com/23471008 git-svn-id: http://skia.googlecode.com/svn/trunk@11140 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
e65d76f0fc
commit
a91f031653
@ -524,6 +524,8 @@ public:
|
|||||||
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
||||||
: INHERITED (factory) {}
|
: INHERITED (factory) {}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
|
@ -44,6 +44,8 @@ public:
|
|||||||
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
||||||
: INHERITED (factory) {}
|
: INHERITED (factory) {}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
@ -164,6 +166,8 @@ public:
|
|||||||
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
||||||
: INHERITED (factory) {}
|
: INHERITED (factory) {}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
|
@ -91,6 +91,8 @@ public:
|
|||||||
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
||||||
: INHERITED (factory) {}
|
: INHERITED (factory) {}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
@ -205,6 +207,8 @@ public:
|
|||||||
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
|
||||||
: INHERITED (factory) {}
|
: INHERITED (factory) {}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
|
@ -15,6 +15,8 @@ class GrGLConicEffect : public GrGLEffect {
|
|||||||
public:
|
public:
|
||||||
GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
@ -158,6 +160,8 @@ class GrGLQuadEffect : public GrGLEffect {
|
|||||||
public:
|
public:
|
||||||
GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
@ -290,6 +294,8 @@ class GrGLCubicEffect : public GrGLEffect {
|
|||||||
public:
|
public:
|
||||||
GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const SK_OVERRIDE { return true; }
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
|
@ -24,6 +24,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
|
||||||
|
const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
|
||||||
|
return GrEffect::kCustom_CoordsType == ste.coordsType();
|
||||||
|
}
|
||||||
|
|
||||||
virtual void emitCode(GrGLShaderBuilder* builder,
|
virtual void emitCode(GrGLShaderBuilder* builder,
|
||||||
const GrDrawEffect& drawEffect,
|
const GrDrawEffect& drawEffect,
|
||||||
EffectKey key,
|
EffectKey key,
|
||||||
|
@ -51,6 +51,13 @@ public:
|
|||||||
|
|
||||||
virtual ~GrGLEffect();
|
virtual ~GrGLEffect();
|
||||||
|
|
||||||
|
/** Called when GrGLProgram is about to create its GrGLShaderBuilder. When possible, effects
|
||||||
|
should handle programs that don't have a vertex shader. But if an effect requires special
|
||||||
|
vertex processing that can't be accomplished with the fixed pipeline, it can override this
|
||||||
|
method and return true to guarantee the GrGLShaderBuilder in emitCode has a VertexBuilder.
|
||||||
|
*/
|
||||||
|
virtual bool requiresVertexShader(const GrDrawEffect&) const { return false; }
|
||||||
|
|
||||||
/** Called when the program stage should insert its code into the shaders. The code in each
|
/** Called when the program stage should insert its code into the shaders. The code in each
|
||||||
shader will be in its own block ({}) and so locally scoped names will not collide across
|
shader will be in its own block ({}) and so locally scoped names will not collide across
|
||||||
stages.
|
stages.
|
||||||
|
@ -48,6 +48,7 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
|
|||||||
SkString* fsCoordName,
|
SkString* fsCoordName,
|
||||||
SkString* vsCoordName,
|
SkString* vsCoordName,
|
||||||
const char* suffix) {
|
const char* suffix) {
|
||||||
|
// TODO: Handle vertexless shaders here before we start enabling them.
|
||||||
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
|
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
|
||||||
SkASSERT(NULL != vertexBuilder);
|
SkASSERT(NULL != vertexBuilder);
|
||||||
|
|
||||||
|
@ -446,10 +446,32 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
|
|||||||
SkASSERT(0 == fProgramID);
|
SkASSERT(0 == fProgramID);
|
||||||
|
|
||||||
const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
|
const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
|
||||||
|
bool hasExplicitLocalCoords = -1 != header.fLocalCoordAttributeIndex;
|
||||||
|
|
||||||
bool needsVertexShader = true;
|
// Get the coeffs for the Mode-based color filter, determine if color is needed.
|
||||||
|
SkXfermode::Coeff colorCoeff;
|
||||||
|
SkXfermode::Coeff filterColorCoeff;
|
||||||
|
SkAssertResult(
|
||||||
|
SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilterXfermode),
|
||||||
|
&filterColorCoeff,
|
||||||
|
&colorCoeff));
|
||||||
|
bool needColor, needFilterColor;
|
||||||
|
need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor);
|
||||||
|
|
||||||
GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, needsVertexShader);
|
// Create the GL effects.
|
||||||
|
bool hasVertexShaderEffects = false;
|
||||||
|
|
||||||
|
SkTArray<GrDrawEffect> colorDrawEffects(needColor ? fDesc.numColorEffects() : 0);
|
||||||
|
if (needColor) {
|
||||||
|
this->buildGLEffects(&GrGLProgram::fColorEffects, colorStages, fDesc.numColorEffects(),
|
||||||
|
hasExplicitLocalCoords, &colorDrawEffects, &hasVertexShaderEffects);
|
||||||
|
}
|
||||||
|
|
||||||
|
SkTArray<GrDrawEffect> coverageDrawEffects(fDesc.numCoverageEffects());
|
||||||
|
this->buildGLEffects(&GrGLProgram::fCoverageEffects, coverageStages, fDesc.numCoverageEffects(),
|
||||||
|
hasExplicitLocalCoords, &coverageDrawEffects, &hasVertexShaderEffects);
|
||||||
|
|
||||||
|
GrGLShaderBuilder builder(fGpu->ctxInfo(), fUniformManager, fDesc, hasVertexShaderEffects);
|
||||||
|
|
||||||
if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuilder()) {
|
if (GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder.getVertexBuilder()) {
|
||||||
const char* viewMName;
|
const char* viewMName;
|
||||||
@ -486,16 +508,6 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
|
|||||||
SkString inColor;
|
SkString inColor;
|
||||||
GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor);
|
GrSLConstantVec knownColorValue = this->genInputColor(&builder, &inColor);
|
||||||
|
|
||||||
// Get the coeffs for the Mode-based color filter, determine if color is needed.
|
|
||||||
SkXfermode::Coeff colorCoeff;
|
|
||||||
SkXfermode::Coeff filterColorCoeff;
|
|
||||||
SkAssertResult(
|
|
||||||
SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilterXfermode),
|
|
||||||
&filterColorCoeff,
|
|
||||||
&colorCoeff));
|
|
||||||
bool needColor, needFilterColor;
|
|
||||||
need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor);
|
|
||||||
|
|
||||||
// used in order for builder to return the per-stage uniform handles.
|
// used in order for builder to return the per-stage uniform handles.
|
||||||
typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr;
|
typedef SkTArray<GrGLUniformManager::UniformHandle, true>* UniHandleArrayPtr;
|
||||||
int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverageEffects());
|
int maxColorOrCovEffectCnt = GrMax(fDesc.numColorEffects(), fDesc.numCoverageEffects());
|
||||||
@ -504,20 +516,17 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
|
|||||||
|
|
||||||
if (needColor) {
|
if (needColor) {
|
||||||
for (int e = 0; e < fDesc.numColorEffects(); ++e) {
|
for (int e = 0; e < fDesc.numColorEffects(); ++e) {
|
||||||
|
glEffects[e] = fColorEffects[e].fGLEffect;
|
||||||
effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis;
|
effectUniformArrays[e] = &fColorEffects[e].fSamplerUnis;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.emitEffects(colorStages,
|
builder.emitEffects(glEffects.get(),
|
||||||
|
colorDrawEffects.begin(),
|
||||||
fDesc.effectKeys(),
|
fDesc.effectKeys(),
|
||||||
fDesc.numColorEffects(),
|
fDesc.numColorEffects(),
|
||||||
&inColor,
|
&inColor,
|
||||||
&knownColorValue,
|
&knownColorValue,
|
||||||
effectUniformArrays.get(),
|
effectUniformArrays.get());
|
||||||
glEffects.get());
|
|
||||||
|
|
||||||
for (int e = 0; e < fDesc.numColorEffects(); ++e) {
|
|
||||||
fColorEffects[e].fGLEffect = glEffects[e];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the color filter. This will soon be replaced by a color effect.
|
// Insert the color filter. This will soon be replaced by a color effect.
|
||||||
@ -548,19 +557,17 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
|
|||||||
GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCoverage);
|
GrSLConstantVec knownCoverageValue = this->genInputCoverage(&builder, &inCoverage);
|
||||||
|
|
||||||
for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
|
for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
|
||||||
|
glEffects[e] = fCoverageEffects[e].fGLEffect;
|
||||||
effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis;
|
effectUniformArrays[e] = &fCoverageEffects[e].fSamplerUnis;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.emitEffects(coverageStages,
|
builder.emitEffects(glEffects.get(),
|
||||||
|
coverageDrawEffects.begin(),
|
||||||
fDesc.getEffectKeys() + fDesc.numColorEffects(),
|
fDesc.getEffectKeys() + fDesc.numColorEffects(),
|
||||||
fDesc.numCoverageEffects(),
|
fDesc.numCoverageEffects(),
|
||||||
&inCoverage,
|
&inCoverage,
|
||||||
&knownCoverageValue,
|
&knownCoverageValue,
|
||||||
effectUniformArrays.get(),
|
effectUniformArrays.get());
|
||||||
glEffects.get());
|
|
||||||
for (int e = 0; e < fDesc.numCoverageEffects(); ++e) {
|
|
||||||
fCoverageEffects[e].fGLEffect = glEffects[e];
|
|
||||||
}
|
|
||||||
|
|
||||||
// discard if coverage is zero
|
// discard if coverage is zero
|
||||||
if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageValue) {
|
if (header.fDiscardIfZeroCoverage && kOnes_GrSLConstantVec != knownCoverageValue) {
|
||||||
@ -689,6 +696,28 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GrGLProgram::buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effectSet,
|
||||||
|
const GrEffectStage* stages[],
|
||||||
|
int count,
|
||||||
|
bool hasExplicitLocalCoords,
|
||||||
|
SkTArray<GrDrawEffect>* drawEffects,
|
||||||
|
bool* hasVertexShaderEffects) {
|
||||||
|
for (int e = 0; e < count; ++e) {
|
||||||
|
SkASSERT(NULL != stages[e] && NULL != stages[e]->getEffect());
|
||||||
|
|
||||||
|
const GrEffectStage& stage = *stages[e];
|
||||||
|
SkNEW_APPEND_TO_TARRAY(drawEffects, GrDrawEffect, (stage, hasExplicitLocalCoords));
|
||||||
|
|
||||||
|
const GrDrawEffect& drawEffect = (*drawEffects)[e];
|
||||||
|
GrGLEffect* effect = (this->*effectSet)[e].fGLEffect =
|
||||||
|
(*stage.getEffect())->getFactory().createGLInstance(drawEffect);
|
||||||
|
|
||||||
|
if (!*hasVertexShaderEffects && effect->requiresVertexShader(drawEffect)) {
|
||||||
|
*hasVertexShaderEffects = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
|
bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
|
||||||
bool bindColorOut,
|
bool bindColorOut,
|
||||||
bool bindDualSrcOut) {
|
bool bindDualSrcOut) {
|
||||||
|
@ -178,6 +178,14 @@ private:
|
|||||||
|
|
||||||
void genGeometryShader(GrGLShaderBuilder::VertexBuilder* vertexBuilder) const;
|
void genGeometryShader(GrGLShaderBuilder::VertexBuilder* vertexBuilder) const;
|
||||||
|
|
||||||
|
// Creates a set of GrGLEffects and GrGLDrawEffects.
|
||||||
|
void buildGLEffects(SkTArray<EffectAndSamplers> GrGLProgram::* effectSet,
|
||||||
|
const GrEffectStage* stages[],
|
||||||
|
int count,
|
||||||
|
bool hasExplicitLocalCoords,
|
||||||
|
SkTArray<GrDrawEffect>* drawEffects,
|
||||||
|
bool* hasVertexShaderEffects);
|
||||||
|
|
||||||
// Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program
|
// Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program
|
||||||
bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
|
bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder,
|
||||||
bool bindColorOut,
|
bool bindColorOut,
|
||||||
|
@ -94,7 +94,7 @@ static const char kDstCopyColorName[] = "_dstColor";
|
|||||||
GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
||||||
GrGLUniformManager& uniformManager,
|
GrGLUniformManager& uniformManager,
|
||||||
const GrGLProgramDesc& desc,
|
const GrGLProgramDesc& desc,
|
||||||
bool needsVertexShader)
|
bool hasVertexShaderEffects)
|
||||||
: fUniforms(kVarsPerBlock)
|
: fUniforms(kVarsPerBlock)
|
||||||
, fCtxInfo(ctxInfo)
|
, fCtxInfo(ctxInfo)
|
||||||
, fUniformManager(uniformManager)
|
, fUniformManager(uniformManager)
|
||||||
@ -106,9 +106,8 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
|||||||
|
|
||||||
const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
|
const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
|
||||||
|
|
||||||
if (needsVertexShader) {
|
// TODO: go vertexless when possible.
|
||||||
fVertexBuilder.reset(SkNEW_ARGS(VertexBuilder, (this, desc)));
|
fVertexBuilder.reset(SkNEW_ARGS(VertexBuilder, (this, desc)));
|
||||||
}
|
|
||||||
|
|
||||||
// Emit code to read the dst copy textue if necessary.
|
// Emit code to read the dst copy textue if necessary.
|
||||||
if (kNoDstRead_DstReadKey != header.fDstReadKey &&
|
if (kNoDstRead_DstReadKey != header.fDstReadKey &&
|
||||||
@ -217,7 +216,7 @@ void GrGLShaderBuilder::nameVariable(SkString* out, char prefix, const char* nam
|
|||||||
|
|
||||||
const char* GrGLShaderBuilder::dstColor() {
|
const char* GrGLShaderBuilder::dstColor() {
|
||||||
if (fCodeStage.inStageCode()) {
|
if (fCodeStage.inStageCode()) {
|
||||||
const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
|
const GrEffectRef& effect = *fCodeStage.effect();
|
||||||
if (!effect->willReadDstColor()) {
|
if (!effect->willReadDstColor()) {
|
||||||
GrDebugCrash("GrGLEffect asked for dst color but its generating GrEffect "
|
GrDebugCrash("GrGLEffect asked for dst color but its generating GrEffect "
|
||||||
"did not request access.");
|
"did not request access.");
|
||||||
@ -363,7 +362,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
|
|||||||
|
|
||||||
const char* GrGLShaderBuilder::fragmentPosition() {
|
const char* GrGLShaderBuilder::fragmentPosition() {
|
||||||
if (fCodeStage.inStageCode()) {
|
if (fCodeStage.inStageCode()) {
|
||||||
const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
|
const GrEffectRef& effect = *fCodeStage.effect();
|
||||||
if (!effect->willReadFragmentPosition()) {
|
if (!effect->willReadFragmentPosition()) {
|
||||||
GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
|
GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
|
||||||
"did not request access.");
|
"did not request access.");
|
||||||
@ -500,24 +499,23 @@ void GrGLShaderBuilder::finished(GrGLuint programID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrGLShaderBuilder::emitEffects(
|
void GrGLShaderBuilder::emitEffects(
|
||||||
const GrEffectStage* effectStages[],
|
GrGLEffect* const glEffects[],
|
||||||
|
const GrDrawEffect drawEffects[],
|
||||||
const GrBackendEffectFactory::EffectKey effectKeys[],
|
const GrBackendEffectFactory::EffectKey effectKeys[],
|
||||||
int effectCnt,
|
int effectCnt,
|
||||||
SkString* fsInOutColor,
|
SkString* fsInOutColor,
|
||||||
GrSLConstantVec* fsInOutColorKnownValue,
|
GrSLConstantVec* fsInOutColorKnownValue,
|
||||||
SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
|
SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[]) {
|
||||||
GrGLEffect* glEffects[]) {
|
|
||||||
bool effectEmitted = false;
|
bool effectEmitted = false;
|
||||||
|
|
||||||
SkString inColor = *fsInOutColor;
|
SkString inColor = *fsInOutColor;
|
||||||
SkString outColor;
|
SkString outColor;
|
||||||
|
|
||||||
for (int e = 0; e < effectCnt; ++e) {
|
for (int e = 0; e < effectCnt; ++e) {
|
||||||
SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect());
|
const GrDrawEffect& drawEffect = drawEffects[e];
|
||||||
const GrEffectStage& stage = *effectStages[e];
|
const GrEffectRef& effect = *drawEffect.effect();
|
||||||
const GrEffectRef& effect = *stage.getEffect();
|
|
||||||
|
|
||||||
CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
|
CodeStage::AutoStageRestore csar(&fCodeStage, &effect);
|
||||||
|
|
||||||
int numTextures = effect->numTextures();
|
int numTextures = effect->numTextures();
|
||||||
SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
|
SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
|
||||||
@ -526,11 +524,9 @@ void GrGLShaderBuilder::emitEffects(
|
|||||||
textureSamplers[t].init(this, &effect->textureAccess(t), t);
|
textureSamplers[t].init(this, &effect->textureAccess(t), t);
|
||||||
effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform);
|
effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform);
|
||||||
}
|
}
|
||||||
GrDrawEffect drawEffect(stage, fVertexBuilder.get()
|
|
||||||
&& fVertexBuilder->hasExplicitLocalCoords());
|
|
||||||
|
|
||||||
int numAttributes = stage.getVertexAttribIndexCount();
|
int numAttributes = drawEffect.getVertexAttribIndexCount();
|
||||||
const int* attributeIndices = stage.getVertexAttribIndices();
|
const int* attributeIndices = drawEffect.getVertexAttribIndices();
|
||||||
SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames;
|
SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames;
|
||||||
for (int a = 0; a < numAttributes; ++a) {
|
for (int a = 0; a < numAttributes; ++a) {
|
||||||
// TODO: Make addAttribute mangle the name.
|
// TODO: Make addAttribute mangle the name.
|
||||||
@ -542,8 +538,6 @@ void GrGLShaderBuilder::emitEffects(
|
|||||||
attributeName);
|
attributeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
glEffects[e] = effect->getFactory().createGLInstance(drawEffect);
|
|
||||||
|
|
||||||
if (kZeros_GrSLConstantVec == *fsInOutColorKnownValue) {
|
if (kZeros_GrSLConstantVec == *fsInOutColorKnownValue) {
|
||||||
// Effects have no way to communicate zeros, they treat an empty string as ones.
|
// Effects have no way to communicate zeros, they treat an empty string as ones.
|
||||||
this->nameVariable(&inColor, '\0', "input");
|
this->nameVariable(&inColor, '\0', "input");
|
||||||
|
@ -107,7 +107,7 @@ public:
|
|||||||
GrGLShaderBuilder(const GrGLContextInfo&,
|
GrGLShaderBuilder(const GrGLContextInfo&,
|
||||||
GrGLUniformManager&,
|
GrGLUniformManager&,
|
||||||
const GrGLProgramDesc&,
|
const GrGLProgramDesc&,
|
||||||
bool needsVertexShader);
|
bool hasVertexShaderEffects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use of these features may require a GLSL extension to be enabled. Shaders may not compile
|
* Use of these features may require a GLSL extension to be enabled. Shaders may not compile
|
||||||
@ -256,13 +256,13 @@ public:
|
|||||||
* glEffects array is updated to contain the GrGLEffect generated for each entry in
|
* glEffects array is updated to contain the GrGLEffect generated for each entry in
|
||||||
* effectStages.
|
* effectStages.
|
||||||
*/
|
*/
|
||||||
void emitEffects(const GrEffectStage* effectStages[],
|
void emitEffects(GrGLEffect* const glEffects[],
|
||||||
|
const GrDrawEffect drawEffects[],
|
||||||
const GrBackendEffectFactory::EffectKey effectKeys[],
|
const GrBackendEffectFactory::EffectKey effectKeys[],
|
||||||
int effectCnt,
|
int effectCnt,
|
||||||
SkString* inOutFSColor,
|
SkString* inOutFSColor,
|
||||||
GrSLConstantVec* fsInOutColorKnownValue,
|
GrSLConstantVec* fsInOutColorKnownValue,
|
||||||
SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
|
SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[]);
|
||||||
GrGLEffect* glEffects[]);
|
|
||||||
|
|
||||||
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
|
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
|
||||||
GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
|
GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
|
||||||
@ -388,16 +388,16 @@ private:
|
|||||||
private:
|
private:
|
||||||
class CodeStage : GrNoncopyable {
|
class CodeStage : GrNoncopyable {
|
||||||
public:
|
public:
|
||||||
CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {}
|
CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffect(NULL) {}
|
||||||
|
|
||||||
bool inStageCode() const {
|
bool inStageCode() const {
|
||||||
this->validate();
|
this->validate();
|
||||||
return NULL != fEffectStage;
|
return NULL != fEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GrEffectStage* effectStage() const {
|
const GrEffectRef* effect() const {
|
||||||
this->validate();
|
this->validate();
|
||||||
return fEffectStage;
|
return fEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stageIndex() const {
|
int stageIndex() const {
|
||||||
@ -407,34 +407,34 @@ private:
|
|||||||
|
|
||||||
class AutoStageRestore : GrNoncopyable {
|
class AutoStageRestore : GrNoncopyable {
|
||||||
public:
|
public:
|
||||||
AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage) {
|
AutoStageRestore(CodeStage* codeStage, const GrEffectRef* effect) {
|
||||||
SkASSERT(NULL != codeStage);
|
SkASSERT(NULL != codeStage);
|
||||||
fSavedIndex = codeStage->fCurrentIndex;
|
fSavedIndex = codeStage->fCurrentIndex;
|
||||||
fSavedEffectStage = codeStage->fEffectStage;
|
fSavedEffect = codeStage->fEffect;
|
||||||
|
|
||||||
if (NULL == newStage) {
|
if (NULL == effect) {
|
||||||
codeStage->fCurrentIndex = -1;
|
codeStage->fCurrentIndex = -1;
|
||||||
} else {
|
} else {
|
||||||
codeStage->fCurrentIndex = codeStage->fNextIndex++;
|
codeStage->fCurrentIndex = codeStage->fNextIndex++;
|
||||||
}
|
}
|
||||||
codeStage->fEffectStage = newStage;
|
codeStage->fEffect = effect;
|
||||||
|
|
||||||
fCodeStage = codeStage;
|
fCodeStage = codeStage;
|
||||||
}
|
}
|
||||||
~AutoStageRestore() {
|
~AutoStageRestore() {
|
||||||
fCodeStage->fCurrentIndex = fSavedIndex;
|
fCodeStage->fCurrentIndex = fSavedIndex;
|
||||||
fCodeStage->fEffectStage = fSavedEffectStage;
|
fCodeStage->fEffect = fSavedEffect;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
CodeStage* fCodeStage;
|
CodeStage* fCodeStage;
|
||||||
int fSavedIndex;
|
int fSavedIndex;
|
||||||
const GrEffectStage* fSavedEffectStage;
|
const GrEffectRef* fSavedEffect;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurrentIndex)); }
|
void validate() const { SkASSERT((NULL == fEffect) == (-1 == fCurrentIndex)); }
|
||||||
int fNextIndex;
|
int fNextIndex;
|
||||||
int fCurrentIndex;
|
int fCurrentIndex;
|
||||||
const GrEffectStage* fEffectStage;
|
const GrEffectRef* fEffect;
|
||||||
} fCodeStage;
|
} fCodeStage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user