Remove uniform names from top of GrGLProgram.cpp, builder responsible for "u" and stage num tags.
Also add LF eol-style property to some files in src/gpu/effects. Review URL: http://codereview.appspot.com/6448049/ git-svn-id: http://skia.googlecode.com/svn/trunk@4770 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
09640d6bac
commit
777c3aab0a
@ -361,7 +361,7 @@ private:
|
|||||||
class GrGLLight {
|
class GrGLLight {
|
||||||
public:
|
public:
|
||||||
virtual ~GrGLLight() {}
|
virtual ~GrGLLight() {}
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder, int stage);
|
virtual void setupVariables(GrGLShaderBuilder* builder);
|
||||||
virtual void emitVS(SkString* out) const {}
|
virtual void emitVS(SkString* out) const {}
|
||||||
virtual void emitFuncs(const GrGLShaderBuilder* builder, SkString* out) const {}
|
virtual void emitFuncs(const GrGLShaderBuilder* builder, SkString* out) const {}
|
||||||
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
||||||
@ -384,7 +384,7 @@ protected:
|
|||||||
class GrGLDistantLight : public GrGLLight {
|
class GrGLDistantLight : public GrGLLight {
|
||||||
public:
|
public:
|
||||||
virtual ~GrGLDistantLight() {}
|
virtual ~GrGLDistantLight() {}
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder, int stage) SK_OVERRIDE;
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
||||||
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
||||||
SkString* out,
|
SkString* out,
|
||||||
@ -399,7 +399,7 @@ private:
|
|||||||
class GrGLPointLight : public GrGLLight {
|
class GrGLPointLight : public GrGLLight {
|
||||||
public:
|
public:
|
||||||
virtual ~GrGLPointLight() {}
|
virtual ~GrGLPointLight() {}
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder, int stage) SK_OVERRIDE;
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
||||||
virtual void emitVS(SkString* out) const SK_OVERRIDE;
|
virtual void emitVS(SkString* out) const SK_OVERRIDE;
|
||||||
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
virtual void emitSurfaceToLight(const GrGLShaderBuilder*,
|
||||||
@ -416,7 +416,7 @@ private:
|
|||||||
class GrGLSpotLight : public GrGLLight {
|
class GrGLSpotLight : public GrGLLight {
|
||||||
public:
|
public:
|
||||||
virtual ~GrGLSpotLight() {}
|
virtual ~GrGLSpotLight() {}
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder, int stage) SK_OVERRIDE;
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const SK_OVERRIDE;
|
||||||
virtual void emitVS(SkString* out) const SK_OVERRIDE;
|
virtual void emitVS(SkString* out) const SK_OVERRIDE;
|
||||||
virtual void emitFuncs(const GrGLShaderBuilder* builder, SkString* out) const;
|
virtual void emitFuncs(const GrGLShaderBuilder* builder, SkString* out) const;
|
||||||
@ -869,8 +869,7 @@ public:
|
|||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
virtual ~GrGLLightingEffect();
|
virtual ~GrGLLightingEffect();
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* builder,
|
virtual void emitVS(GrGLShaderBuilder* builder,
|
||||||
const char* vertexCoords) SK_OVERRIDE;
|
const char* vertexCoords) SK_OVERRIDE;
|
||||||
virtual void emitFS(GrGLShaderBuilder* builder,
|
virtual void emitFS(GrGLShaderBuilder* builder,
|
||||||
@ -901,8 +900,7 @@ class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
|
|||||||
public:
|
public:
|
||||||
GrGLDiffuseLightingEffect(const GrProgramStageFactory& factory,
|
GrGLDiffuseLightingEffect(const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitLightFunc(const GrGLShaderBuilder*, SkString* funcs) SK_OVERRIDE;
|
virtual void emitLightFunc(const GrGLShaderBuilder*, SkString* funcs) SK_OVERRIDE;
|
||||||
virtual void setData(const GrGLUniformManager&,
|
virtual void setData(const GrGLUniformManager&,
|
||||||
const GrCustomStage&,
|
const GrCustomStage&,
|
||||||
@ -921,8 +919,7 @@ class GrGLSpecularLightingEffect : public GrGLLightingEffect {
|
|||||||
public:
|
public:
|
||||||
GrGLSpecularLightingEffect(const GrProgramStageFactory& factory,
|
GrGLSpecularLightingEffect(const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitLightFunc(const GrGLShaderBuilder*, SkString* funcs) SK_OVERRIDE;
|
virtual void emitLightFunc(const GrGLShaderBuilder*, SkString* funcs) SK_OVERRIDE;
|
||||||
virtual void setData(const GrGLUniformManager&,
|
virtual void setData(const GrGLUniformManager&,
|
||||||
const GrCustomStage&,
|
const GrCustomStage&,
|
||||||
@ -989,14 +986,14 @@ GrGLLightingEffect::~GrGLLightingEffect() {
|
|||||||
delete fLight;
|
delete fLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLLightingEffect::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLLightingEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec2f_GrSLType,
|
kVec2f_GrSLType,
|
||||||
"uImageIncrement", stage);
|
"ImageIncrement");
|
||||||
fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType,
|
kFloat_GrSLType,
|
||||||
"uSurfaceScale", stage);
|
"SurfaceScale");
|
||||||
fLight->setupVariables(builder, stage);
|
fLight->setupVariables(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLLightingEffect::emitVS(GrGLShaderBuilder* builder,
|
void GrGLLightingEffect::emitVS(GrGLShaderBuilder* builder,
|
||||||
@ -1078,10 +1075,9 @@ GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProgramStageFactory
|
|||||||
, fKDUni(kInvalidUniformHandle) {
|
, fKDUni(kInvalidUniformHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLDiffuseLightingEffect::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLDiffuseLightingEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
INHERITED::setupVariables(builder, stage);
|
INHERITED::setupVariables(builder);
|
||||||
fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType, "uKD",
|
fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType, "KD");
|
||||||
stage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLDiffuseLightingEffect::emitLightFunc(const GrGLShaderBuilder* builder, SkString* funcs) {
|
void GrGLDiffuseLightingEffect::emitLightFunc(const GrGLShaderBuilder* builder, SkString* funcs) {
|
||||||
@ -1131,12 +1127,12 @@ GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProgramStageFacto
|
|||||||
, fShininessUni(kInvalidUniformHandle) {
|
, fShininessUni(kInvalidUniformHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLSpecularLightingEffect::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLSpecularLightingEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
INHERITED::setupVariables(builder, stage);
|
INHERITED::setupVariables(builder);
|
||||||
fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uKS", stage);
|
kFloat_GrSLType, "KS");
|
||||||
fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uShininess", stage);
|
kFloat_GrSLType, "Shininess");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLSpecularLightingEffect::emitLightFunc(const GrGLShaderBuilder* builder, SkString* funcs) {
|
void GrGLSpecularLightingEffect::emitLightFunc(const GrGLShaderBuilder* builder, SkString* funcs) {
|
||||||
@ -1169,9 +1165,9 @@ void GrGLLight::emitLightColor(const GrGLShaderBuilder* builder,
|
|||||||
out->append(color);
|
out->append(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLLight::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLLight::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec3f_GrSLType, "uLightColor", stage);
|
kVec3f_GrSLType, "LightColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLLight::setData(const GrGLUniformManager& uman,
|
void GrGLLight::setData(const GrGLUniformManager& uman,
|
||||||
@ -1186,10 +1182,10 @@ GrGLLight* SkDistantLight::createGLLight() const {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GrGLDistantLight::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLDistantLight::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
INHERITED::setupVariables(builder, stage);
|
INHERITED::setupVariables(builder);
|
||||||
fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
|
fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
|
||||||
"uLightDirection", stage);
|
"LightDirection");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLDistantLight::setData(const GrGLUniformManager& uman,
|
void GrGLDistantLight::setData(const GrGLUniformManager& uman,
|
||||||
@ -1210,10 +1206,10 @@ void GrGLDistantLight::emitSurfaceToLight(const GrGLShaderBuilder* builder,
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GrGLPointLight::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLPointLight::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
INHERITED::setupVariables(builder, stage);
|
INHERITED::setupVariables(builder);
|
||||||
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
|
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
|
||||||
"uLightLocation", stage);
|
"LightLocation");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLPointLight::setData(const GrGLUniformManager& uman,
|
void GrGLPointLight::setData(const GrGLUniformManager& uman,
|
||||||
@ -1237,20 +1233,20 @@ void GrGLPointLight::emitSurfaceToLight(const GrGLShaderBuilder* builder,
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GrGLSpotLight::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLSpotLight::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
INHERITED::setupVariables(builder, stage);
|
INHERITED::setupVariables(builder);
|
||||||
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec3f_GrSLType, "uLightLocation", stage);
|
kVec3f_GrSLType, "LightLocation");
|
||||||
fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uExponent", stage);
|
kFloat_GrSLType, "Exponent");
|
||||||
fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uCosInnerConeAngle", stage);
|
kFloat_GrSLType, "CosInnerConeAngle");
|
||||||
fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uCosOuterConeAngle", stage);
|
kFloat_GrSLType, "CosOuterConeAngle");
|
||||||
fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uConeScale", stage);
|
kFloat_GrSLType, "ConeScale");
|
||||||
fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec3f_GrSLType, "uS", stage);
|
kVec3f_GrSLType, "S");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLSpotLight::setData(const GrGLUniformManager& uman,
|
void GrGLSpotLight::setData(const GrGLUniformManager& uman,
|
||||||
|
@ -17,8 +17,7 @@ public:
|
|||||||
GrGLColorTableEffect(const GrProgramStageFactory& factory,
|
GrGLColorTableEffect(const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* state,
|
virtual void setupVariables(GrGLShaderBuilder* state) SK_OVERRIDE {}
|
||||||
int stage) SK_OVERRIDE {}
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* state,
|
virtual void emitVS(GrGLShaderBuilder* state,
|
||||||
const char* vertexCoords) SK_OVERRIDE {}
|
const char* vertexCoords) SK_OVERRIDE {}
|
||||||
virtual void emitFS(GrGLShaderBuilder* state,
|
virtual void emitFS(GrGLShaderBuilder* state,
|
||||||
|
@ -20,8 +20,7 @@ public:
|
|||||||
GrGLConvolutionEffect(const GrProgramStageFactory& factory,
|
GrGLConvolutionEffect(const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* builder,
|
virtual void emitVS(GrGLShaderBuilder* builder,
|
||||||
const char* vertexCoords) SK_OVERRIDE;
|
const char* vertexCoords) SK_OVERRIDE;
|
||||||
virtual void emitFS(GrGLShaderBuilder* builder,
|
virtual void emitFS(GrGLShaderBuilder* builder,
|
||||||
@ -56,13 +55,12 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProgramStageFactory& factor
|
|||||||
fRadius = c.radius();
|
fRadius = c.radius();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLConvolutionEffect::setupVariables(GrGLShaderBuilder* builder,
|
void GrGLConvolutionEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
int stage) {
|
|
||||||
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType |
|
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType |
|
||||||
GrGLShaderBuilder::kVertex_ShaderType,
|
GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
kVec2f_GrSLType, "uImageIncrement", stage);
|
kVec2f_GrSLType, "ImageIncrement");
|
||||||
fKernelUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uKernel", stage, this->width());
|
kFloat_GrSLType, "Kernel", this->width());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLConvolutionEffect::emitVS(GrGLShaderBuilder* builder,
|
void GrGLConvolutionEffect::emitVS(GrGLShaderBuilder* builder,
|
||||||
|
@ -214,8 +214,7 @@ public:
|
|||||||
const GrCustomStage&);
|
const GrCustomStage&);
|
||||||
virtual ~GrGLRadial2Gradient() { }
|
virtual ~GrGLRadial2Gradient() { }
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* builder,
|
virtual void emitVS(GrGLShaderBuilder* builder,
|
||||||
const char* vertexCoords) SK_OVERRIDE;
|
const char* vertexCoords) SK_OVERRIDE;
|
||||||
virtual void emitFS(GrGLShaderBuilder* builder,
|
virtual void emitFS(GrGLShaderBuilder* builder,
|
||||||
@ -273,19 +272,19 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(
|
|||||||
fIsDegenerate = data.isDegenerate();
|
fIsDegenerate = data.isDegenerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
|
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
|
||||||
// to work around Xoom bug. Doesn't seem to cause performance decrease
|
// to work around Xoom bug. Doesn't seem to cause performance decrease
|
||||||
// in test apps, but need to keep an eye on it.
|
// in test apps, but need to keep an eye on it.
|
||||||
fVSParamUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
kFloat_GrSLType, "uRadial2VSParams", stage, 6);
|
kFloat_GrSLType, "Radial2VSParams", 6);
|
||||||
fFSParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uRadial2FSParams", stage, 6);
|
kFloat_GrSLType, "Radial2FSParams", 6);
|
||||||
|
|
||||||
// For radial gradients without perspective we can pass the linear
|
// For radial gradients without perspective we can pass the linear
|
||||||
// part of the quadratic as a varying.
|
// part of the quadratic as a varying.
|
||||||
if (builder->fVaryingDims == builder->fCoordDims) {
|
if (builder->fVaryingDims == builder->fCoordDims) {
|
||||||
builder->addVarying(kFloat_GrSLType, "Radial2BCoeff", stage,
|
builder->addVarying(kFloat_GrSLType, "Radial2BCoeff",
|
||||||
&fVSVaryingName, &fFSVaryingName);
|
&fVSVaryingName, &fFSVaryingName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,8 +466,7 @@ public:
|
|||||||
const GrCustomStage&);
|
const GrCustomStage&);
|
||||||
virtual ~GrGLConical2Gradient() { }
|
virtual ~GrGLConical2Gradient() { }
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* builder,
|
virtual void emitVS(GrGLShaderBuilder* builder,
|
||||||
const char* vertexCoords) SK_OVERRIDE;
|
const char* vertexCoords) SK_OVERRIDE;
|
||||||
virtual void emitFS(GrGLShaderBuilder* builder,
|
virtual void emitFS(GrGLShaderBuilder* builder,
|
||||||
@ -528,14 +526,14 @@ GrGLConical2Gradient::GrGLConical2Gradient(
|
|||||||
fIsDegenerate = data.isDegenerate();
|
fIsDegenerate = data.isDegenerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
|
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
|
||||||
// to work around Xoom bug. Doesn't seem to cause performance decrease
|
// to work around Xoom bug. Doesn't seem to cause performance decrease
|
||||||
// in test apps, but need to keep an eye on it.
|
// in test apps, but need to keep an eye on it.
|
||||||
fVSParamUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
kFloat_GrSLType, "uConical2VSParams", stage, 6);
|
kFloat_GrSLType, "Conical2VSParams", 6);
|
||||||
fFSParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kFloat_GrSLType, "uConical2FSParams", stage, 6);
|
kFloat_GrSLType, "Conical2FSParams", 6);
|
||||||
|
|
||||||
fVSParamLocation = GrGLProgramStage::kUseUniform;
|
fVSParamLocation = GrGLProgramStage::kUseUniform;
|
||||||
fFSParamLocation = GrGLProgramStage::kUseUniform;
|
fFSParamLocation = GrGLProgramStage::kUseUniform;
|
||||||
@ -543,7 +541,7 @@ void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder, int stage)
|
|||||||
// For radial gradients without perspective we can pass the linear
|
// For radial gradients without perspective we can pass the linear
|
||||||
// part of the quadratic as a varying.
|
// part of the quadratic as a varying.
|
||||||
if (builder->fVaryingDims == builder->fCoordDims) {
|
if (builder->fVaryingDims == builder->fCoordDims) {
|
||||||
builder->addVarying(kFloat_GrSLType, "Conical2BCoeff", stage,
|
builder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
|
||||||
&fVSVaryingName, &fFSVaryingName);
|
&fVSVaryingName, &fFSVaryingName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,7 @@ public:
|
|||||||
GrGLMorphologyEffect (const GrProgramStageFactory& factory,
|
GrGLMorphologyEffect (const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* state,
|
virtual void emitVS(GrGLShaderBuilder* state,
|
||||||
const char* vertexCoords) SK_OVERRIDE;
|
const char* vertexCoords) SK_OVERRIDE;
|
||||||
virtual void emitFS(GrGLShaderBuilder* state,
|
virtual void emitFS(GrGLShaderBuilder* state,
|
||||||
@ -53,10 +52,10 @@ GrGLMorphologyEffect ::GrGLMorphologyEffect(const GrProgramStageFactory& factory
|
|||||||
fType = m.type();
|
fType = m.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLMorphologyEffect::setupVariables(GrGLShaderBuilder* builder, int stage) {
|
void GrGLMorphologyEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType |
|
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType |
|
||||||
GrGLShaderBuilder::kVertex_ShaderType,
|
GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
kVec2f_GrSLType, "uImageIncrement", stage);
|
kVec2f_GrSLType, "ImageIncrement");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLMorphologyEffect::emitVS(GrGLShaderBuilder* builder,
|
void GrGLMorphologyEffect::emitVS(GrGLShaderBuilder* builder,
|
||||||
|
@ -14,8 +14,7 @@ public:
|
|||||||
GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
|
GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
|
||||||
const GrCustomStage& stage);
|
const GrCustomStage& stage);
|
||||||
|
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder,
|
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
|
||||||
int stage) SK_OVERRIDE;
|
|
||||||
virtual void emitVS(GrGLShaderBuilder* builder,
|
virtual void emitVS(GrGLShaderBuilder* builder,
|
||||||
const char* vertexCoords) SK_OVERRIDE { }
|
const char* vertexCoords) SK_OVERRIDE { }
|
||||||
virtual void emitFS(GrGLShaderBuilder* builder,
|
virtual void emitFS(GrGLShaderBuilder* builder,
|
||||||
@ -42,10 +41,9 @@ GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProgramStageFactory& fa
|
|||||||
, fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
|
, fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLTextureDomainEffect::setupVariables(GrGLShaderBuilder* builder,
|
void GrGLTextureDomainEffect::setupVariables(GrGLShaderBuilder* builder) {
|
||||||
int stage) {
|
|
||||||
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec4f_GrSLType, "uTexDom", stage);
|
kVec4f_GrSLType, "TexDom");
|
||||||
};
|
};
|
||||||
|
|
||||||
void GrGLTextureDomainEffect::emitFS(GrGLShaderBuilder* builder,
|
void GrGLTextureDomainEffect::emitFS(GrGLShaderBuilder* builder,
|
||||||
|
@ -25,17 +25,10 @@ SK_DEFINE_INST_COUNT(GrGLProgram)
|
|||||||
|
|
||||||
typedef GrGLProgram::Desc::StageDesc StageDesc;
|
typedef GrGLProgram::Desc::StageDesc StageDesc;
|
||||||
|
|
||||||
#define VIEW_MATRIX_NAME "uViewM"
|
|
||||||
|
|
||||||
#define POS_ATTR_NAME "aPosition"
|
#define POS_ATTR_NAME "aPosition"
|
||||||
#define COL_ATTR_NAME "aColor"
|
#define COL_ATTR_NAME "aColor"
|
||||||
#define COV_ATTR_NAME "aCoverage"
|
#define COV_ATTR_NAME "aCoverage"
|
||||||
#define EDGE_ATTR_NAME "aEdge"
|
#define EDGE_ATTR_NAME "aEdge"
|
||||||
#define COL_UNI_NAME "uColor"
|
|
||||||
#define COV_UNI_NAME "uCoverage"
|
|
||||||
#define COL_FILTER_UNI_NAME "uColorFilter"
|
|
||||||
#define COL_MATRIX_UNI_NAME "uColorMatrix"
|
|
||||||
#define COL_MATRIX_VEC_UNI_NAME "uColorMatrixVec"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
inline void tex_attr_name(int coordIdx, SkString* s) {
|
inline void tex_attr_name(int coordIdx, SkString* s) {
|
||||||
@ -70,15 +63,6 @@ inline const char* all_zeros_vec(int count) {
|
|||||||
inline const char* declared_color_output_name() { return "fsColorOut"; }
|
inline const char* declared_color_output_name() { return "fsColorOut"; }
|
||||||
inline const char* dual_source_output_name() { return "dualSourceOut"; }
|
inline const char* dual_source_output_name() { return "dualSourceOut"; }
|
||||||
|
|
||||||
inline void tex_matrix_name(int stage, SkString* s) {
|
|
||||||
*s = "uTexM";
|
|
||||||
s->appendS32(stage);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void sampler_name(int stage, SkString* s) {
|
|
||||||
*s = "uSampler";
|
|
||||||
s->appendS32(stage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl,
|
GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl,
|
||||||
@ -308,24 +292,14 @@ static void blendTermString(SkString* str, SkXfermode::Coeff coeff,
|
|||||||
static void addColorFilter(SkString* fsCode, const char * outputVar,
|
static void addColorFilter(SkString* fsCode, const char * outputVar,
|
||||||
SkXfermode::Coeff uniformCoeff,
|
SkXfermode::Coeff uniformCoeff,
|
||||||
SkXfermode::Coeff colorCoeff,
|
SkXfermode::Coeff colorCoeff,
|
||||||
|
const char* filterColor,
|
||||||
const char* inColor) {
|
const char* inColor) {
|
||||||
SkString colorStr, constStr;
|
SkString colorStr, constStr;
|
||||||
blendTermString(&colorStr, colorCoeff, COL_FILTER_UNI_NAME,
|
blendTermString(&colorStr, colorCoeff, filterColor, inColor, inColor);
|
||||||
inColor, inColor);
|
blendTermString(&constStr, uniformCoeff, filterColor, inColor, filterColor);
|
||||||
blendTermString(&constStr, uniformCoeff, COL_FILTER_UNI_NAME,
|
|
||||||
inColor, COL_FILTER_UNI_NAME);
|
|
||||||
|
|
||||||
add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode);
|
add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Adds code to the fragment shader code which modifies the color by
|
|
||||||
* the specified color matrix.
|
|
||||||
*/
|
|
||||||
static void addColorMatrix(SkString* fsCode, const char * outputVar,
|
|
||||||
const char* inColor) {
|
|
||||||
fsCode->appendf("\t%s = %s * vec4(%s.rgb / %s.a, %s.a) + %s;\n", outputVar, COL_MATRIX_UNI_NAME, inColor, inColor, inColor, COL_MATRIX_VEC_UNI_NAME);
|
|
||||||
fsCode->appendf("\t%s.rgb *= %s.a;\n", outputVar, outputVar);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GrGLProgram::genEdgeCoverage(SkString* coverageVar,
|
void GrGLProgram::genEdgeCoverage(SkString* coverageVar,
|
||||||
GrGLShaderBuilder* segments) const {
|
GrGLShaderBuilder* segments) const {
|
||||||
@ -400,11 +374,13 @@ void GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString* inColor) {
|
|||||||
builder->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName);
|
builder->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName);
|
||||||
*inColor = fsName;
|
*inColor = fsName;
|
||||||
} break;
|
} break;
|
||||||
case GrGLProgram::Desc::kUniform_ColorInput:
|
case GrGLProgram::Desc::kUniform_ColorInput: {
|
||||||
|
const char* name;
|
||||||
fUniforms.fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fUniforms.fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec4f_GrSLType, COL_UNI_NAME);
|
kVec4f_GrSLType, "Color", &name);
|
||||||
*inColor = COL_UNI_NAME;
|
*inColor = name;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case GrGLProgram::Desc::kTransBlack_ColorInput:
|
case GrGLProgram::Desc::kTransBlack_ColorInput:
|
||||||
GrAssert(!"needComputedColor should be false.");
|
GrAssert(!"needComputedColor should be false.");
|
||||||
break;
|
break;
|
||||||
@ -417,14 +393,15 @@ void GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString* inColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrGLProgram::genUniformCoverage(GrGLShaderBuilder* builder, SkString* inOutCoverage) {
|
void GrGLProgram::genUniformCoverage(GrGLShaderBuilder* builder, SkString* inOutCoverage) {
|
||||||
|
const char* covUniName;
|
||||||
fUniforms.fCoverageUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fUniforms.fCoverageUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec4f_GrSLType, COV_UNI_NAME);
|
kVec4f_GrSLType, "Coverage", &covUniName);
|
||||||
if (inOutCoverage->size()) {
|
if (inOutCoverage->size()) {
|
||||||
builder->fFSCode.appendf("\tvec4 uniCoverage = %s * %s;\n",
|
builder->fFSCode.appendf("\tvec4 uniCoverage = %s * %s;\n",
|
||||||
COV_UNI_NAME, inOutCoverage->c_str());
|
covUniName, inOutCoverage->c_str());
|
||||||
*inOutCoverage = "uniCoverage";
|
*inOutCoverage = "uniCoverage";
|
||||||
} else {
|
} else {
|
||||||
*inOutCoverage = COV_UNI_NAME;
|
*inOutCoverage = covUniName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,16 +632,18 @@ bool GrGLProgram::genProgram(GrCustomStage** customStages) {
|
|||||||
builder.fFSOutputs.push_back(colorOutput);
|
builder.fFSOutputs.push_back(colorOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* viewMName;
|
||||||
fUniforms.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
fUniforms.fViewMatrixUni = builder.addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
kMat33f_GrSLType, VIEW_MATRIX_NAME);
|
kMat33f_GrSLType, "ViewM", &viewMName);
|
||||||
|
|
||||||
builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
|
builder.fVSAttrs.push_back().set(kVec2f_GrSLType,
|
||||||
GrGLShaderVar::kAttribute_TypeModifier,
|
GrGLShaderVar::kAttribute_TypeModifier,
|
||||||
POS_ATTR_NAME);
|
POS_ATTR_NAME);
|
||||||
|
|
||||||
builder.fVSCode.append("void main() {\n"
|
builder.fVSCode.appendf("void main() {\n"
|
||||||
"\tvec3 pos3 = " VIEW_MATRIX_NAME " * vec3("POS_ATTR_NAME", 1);\n"
|
"\tvec3 pos3 = %s * vec3("POS_ATTR_NAME", 1);\n"
|
||||||
"\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n");
|
"\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n",
|
||||||
|
viewMName);
|
||||||
|
|
||||||
// incoming color to current stage being processed.
|
// incoming color to current stage being processed.
|
||||||
SkString inColor;
|
SkString inColor;
|
||||||
@ -743,9 +722,11 @@ bool GrGLProgram::genProgram(GrCustomStage** customStages) {
|
|||||||
&needColorFilterUniform, &bogus);
|
&needColorFilterUniform, &bogus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const char* colorFilterColorUniName = NULL;
|
||||||
if (needColorFilterUniform) {
|
if (needColorFilterUniform) {
|
||||||
fUniforms.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fUniforms.fColorFilterUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec4f_GrSLType, COL_FILTER_UNI_NAME);
|
kVec4f_GrSLType, "FilterColor",
|
||||||
|
&colorFilterColorUniName);
|
||||||
}
|
}
|
||||||
bool wroteFragColorZero = false;
|
bool wroteFragColorZero = false;
|
||||||
if (SkXfermode::kZero_Coeff == uniformCoeff &&
|
if (SkXfermode::kZero_Coeff == uniformCoeff &&
|
||||||
@ -759,17 +740,23 @@ bool GrGLProgram::genProgram(GrCustomStage** customStages) {
|
|||||||
builder.fFSCode.append("\tvec4 filteredColor;\n");
|
builder.fFSCode.append("\tvec4 filteredColor;\n");
|
||||||
const char* color = adjustInColor(inColor);
|
const char* color = adjustInColor(inColor);
|
||||||
addColorFilter(&builder.fFSCode, "filteredColor", uniformCoeff,
|
addColorFilter(&builder.fFSCode, "filteredColor", uniformCoeff,
|
||||||
colorCoeff, color);
|
colorCoeff, colorFilterColorUniName, color);
|
||||||
inColor = "filteredColor";
|
inColor = "filteredColor";
|
||||||
}
|
}
|
||||||
if (applyColorMatrix) {
|
if (applyColorMatrix) {
|
||||||
|
const char* colMatrixName;
|
||||||
|
const char* colMatrixVecName;
|
||||||
fUniforms.fColorMatrixUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fUniforms.fColorMatrixUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kMat44f_GrSLType, COL_MATRIX_UNI_NAME);
|
kMat44f_GrSLType, "ColorMatrix",
|
||||||
|
&colMatrixName);
|
||||||
fUniforms.fColorMatrixVecUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
fUniforms.fColorMatrixVecUni = builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
kVec4f_GrSLType, COL_MATRIX_VEC_UNI_NAME);
|
kVec4f_GrSLType, "ColorMatrixVec",
|
||||||
builder.fFSCode.append("\tvec4 matrixedColor;\n");
|
&colMatrixVecName);
|
||||||
const char* color = adjustInColor(inColor);
|
const char* color = adjustInColor(inColor);
|
||||||
addColorMatrix(&builder.fFSCode, "matrixedColor", color);
|
builder.fFSCode.appendf("\tvec4 matrixedColor = %s * vec4(%s.rgb / %s.a, %s.a) + %s;\n",
|
||||||
|
colMatrixName, color, color, color, colMatrixVecName);
|
||||||
|
builder.fFSCode.append("\tmatrixedColor.rgb *= matrixedColor.a;\n");
|
||||||
|
|
||||||
inColor = "matrixedColor";
|
inColor = "matrixedColor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -835,6 +822,7 @@ bool GrGLProgram::genProgram(GrCustomStage** customStages) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) {
|
if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) {
|
||||||
builder.fFSOutputs.push_back().set(kVec4f_GrSLType,
|
builder.fFSOutputs.push_back().set(kVec4f_GrSLType,
|
||||||
GrGLShaderVar::kOut_TypeModifier,
|
GrGLShaderVar::kOut_TypeModifier,
|
||||||
@ -1004,7 +992,7 @@ void GrGLProgram::genStageCode(int stageNum,
|
|||||||
const char* fsInColor, // NULL means no incoming color
|
const char* fsInColor, // NULL means no incoming color
|
||||||
const char* fsOutColor,
|
const char* fsOutColor,
|
||||||
const char* vsInCoord,
|
const char* vsInCoord,
|
||||||
GrGLShaderBuilder* segments) {
|
GrGLShaderBuilder* builder) {
|
||||||
GrAssert(stageNum >= 0 && stageNum <= GrDrawState::kNumStages);
|
GrAssert(stageNum >= 0 && stageNum <= GrDrawState::kNumStages);
|
||||||
|
|
||||||
const GrGLProgram::StageDesc& desc = fDesc.fStages[stageNum];
|
const GrGLProgram::StageDesc& desc = fDesc.fStages[stageNum];
|
||||||
@ -1013,67 +1001,63 @@ void GrGLProgram::genStageCode(int stageNum,
|
|||||||
|
|
||||||
GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) == desc.fInConfigFlags);
|
GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) == desc.fInConfigFlags);
|
||||||
|
|
||||||
|
builder->setCurrentStage(stageNum);
|
||||||
|
|
||||||
/// Vertex Shader Stuff
|
/// Vertex Shader Stuff
|
||||||
|
|
||||||
// decide whether we need a matrix to transform texture coords and whether the varying needs a
|
// decide whether we need a matrix to transform texture coords and whether the varying needs a
|
||||||
// perspective coord.
|
// perspective coord.
|
||||||
const char* matName = NULL;
|
const char* matName = NULL;
|
||||||
if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) {
|
if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) {
|
||||||
segments->fVaryingDims = segments->fCoordDims;
|
builder->fVaryingDims = builder->fCoordDims;
|
||||||
} else {
|
} else {
|
||||||
SkString texMatName;
|
uniforms.fTextureMatrixUni = builder->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
||||||
tex_matrix_name(stageNum, &texMatName);
|
kMat33f_GrSLType, "TexM", &matName);
|
||||||
uniforms.fTextureMatrixUni = segments->addUniform(GrGLShaderBuilder::kVertex_ShaderType,
|
const GrGLShaderVar& mat = builder->getUniformVariable(uniforms.fTextureMatrixUni);
|
||||||
kMat33f_GrSLType, texMatName.c_str());
|
|
||||||
const GrGLShaderVar& mat = segments->getUniformVariable(uniforms.fTextureMatrixUni);
|
|
||||||
// Can't use texMatName.c_str() because it's on the stack!
|
|
||||||
matName = mat.getName().c_str();
|
|
||||||
|
|
||||||
if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) {
|
if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) {
|
||||||
segments->fVaryingDims = segments->fCoordDims;
|
builder->fVaryingDims = builder->fCoordDims;
|
||||||
} else {
|
} else {
|
||||||
segments->fVaryingDims = segments->fCoordDims + 1;
|
builder->fVaryingDims = builder->fCoordDims + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GrAssert(segments->fVaryingDims > 0);
|
GrAssert(builder->fVaryingDims > 0);
|
||||||
|
|
||||||
// Must setup variables after computing segments->fVaryingDims
|
// Must setup variables after computing segments->fVaryingDims
|
||||||
if (NULL != customStage) {
|
if (NULL != customStage) {
|
||||||
customStage->setupVariables(segments, stageNum);
|
customStage->setupVariables(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString samplerName;
|
const char* samplerName;
|
||||||
sampler_name(stageNum, &samplerName);
|
uniforms.fSamplerUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
||||||
uniforms.fSamplerUni = segments->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
|
kSampler2D_GrSLType, "Sampler", &samplerName);
|
||||||
kSampler2D_GrSLType, samplerName.c_str());
|
|
||||||
|
|
||||||
const char *varyingVSName, *varyingFSName;
|
const char *varyingVSName, *varyingFSName;
|
||||||
segments->addVarying(GrSLFloatVectorType(segments->fVaryingDims),
|
builder->addVarying(GrSLFloatVectorType(builder->fVaryingDims),
|
||||||
"Stage",
|
"Stage",
|
||||||
stageNum,
|
&varyingVSName,
|
||||||
&varyingVSName,
|
&varyingFSName);
|
||||||
&varyingFSName);
|
|
||||||
|
|
||||||
if (!matName) {
|
if (!matName) {
|
||||||
GrAssert(segments->fVaryingDims == segments->fCoordDims);
|
GrAssert(builder->fVaryingDims == builder->fCoordDims);
|
||||||
segments->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord);
|
builder->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord);
|
||||||
} else {
|
} else {
|
||||||
// varying = texMatrix * texCoord
|
// varying = texMatrix * texCoord
|
||||||
segments->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n",
|
builder->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n",
|
||||||
varyingVSName, matName, vsInCoord,
|
varyingVSName, matName, vsInCoord,
|
||||||
vector_all_coords(segments->fVaryingDims));
|
vector_all_coords(builder->fVaryingDims));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != customStage) {
|
if (NULL != customStage) {
|
||||||
segments->fVSCode.appendf("\t{ // stage %d %s\n",
|
builder->fVSCode.appendf("\t{ // stage %d %s\n",
|
||||||
stageNum, customStage->name());
|
stageNum, customStage->name());
|
||||||
customStage->emitVS(segments, varyingVSName);
|
customStage->emitVS(builder, varyingVSName);
|
||||||
segments->fVSCode.appendf("\t}\n");
|
builder->fVSCode.appendf("\t}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fragment Shader Stuff
|
/// Fragment Shader Stuff
|
||||||
|
|
||||||
segments->fSampleCoords = varyingFSName;
|
builder->fSampleCoords = varyingFSName;
|
||||||
|
|
||||||
GrGLShaderBuilder::SamplerMode sampleMode =
|
GrGLShaderBuilder::SamplerMode sampleMode =
|
||||||
GrGLShaderBuilder::kExplicitDivide_SamplerMode;
|
GrGLShaderBuilder::kExplicitDivide_SamplerMode;
|
||||||
@ -1083,10 +1067,10 @@ void GrGLProgram::genStageCode(int stageNum,
|
|||||||
} else if (NULL == customStage) {
|
} else if (NULL == customStage) {
|
||||||
sampleMode = GrGLShaderBuilder::kProj_SamplerMode;
|
sampleMode = GrGLShaderBuilder::kProj_SamplerMode;
|
||||||
}
|
}
|
||||||
segments->setupTextureAccess(sampleMode, stageNum);
|
builder->setupTextureAccess(sampleMode, stageNum);
|
||||||
|
|
||||||
segments->computeSwizzle(desc.fInConfigFlags);
|
builder->computeSwizzle(desc.fInConfigFlags);
|
||||||
segments->computeModulate(fsInColor);
|
builder->computeModulate(fsInColor);
|
||||||
|
|
||||||
static const uint32_t kMulByAlphaMask =
|
static const uint32_t kMulByAlphaMask =
|
||||||
(StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag |
|
(StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag |
|
||||||
@ -1101,33 +1085,34 @@ void GrGLProgram::genStageCode(int stageNum,
|
|||||||
StageDesc::kSmearAlpha_InConfigFlag));
|
StageDesc::kSmearAlpha_InConfigFlag));
|
||||||
GrAssert(!(desc.fInConfigFlags &
|
GrAssert(!(desc.fInConfigFlags &
|
||||||
StageDesc::kSmearRed_InConfigFlag));
|
StageDesc::kSmearRed_InConfigFlag));
|
||||||
segments->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n",
|
builder->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n",
|
||||||
fsOutColor,
|
fsOutColor,
|
||||||
segments->fTexFunc.c_str(),
|
builder->fTexFunc.c_str(),
|
||||||
samplerName.c_str(),
|
samplerName,
|
||||||
segments->fSampleCoords.c_str(),
|
builder->fSampleCoords.c_str(),
|
||||||
segments->fSwizzle.c_str());
|
builder->fSwizzle.c_str());
|
||||||
if (desc.fInConfigFlags &
|
if (desc.fInConfigFlags &
|
||||||
StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) {
|
StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) {
|
||||||
segments->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
|
builder->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
|
||||||
fsOutColor, fsOutColor, fsOutColor,
|
fsOutColor, fsOutColor, fsOutColor,
|
||||||
fsOutColor, segments->fModulate.c_str());
|
fsOutColor, builder->fModulate.c_str());
|
||||||
} else {
|
} else {
|
||||||
segments->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
|
builder->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n",
|
||||||
fsOutColor, fsOutColor, fsOutColor,
|
fsOutColor, fsOutColor, fsOutColor,
|
||||||
fsOutColor, segments->fModulate.c_str());
|
fsOutColor, builder->fModulate.c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
segments->emitDefaultFetch(fsOutColor, samplerName.c_str());
|
builder->emitDefaultFetch(fsOutColor, samplerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != customStage) {
|
if (NULL != customStage) {
|
||||||
// Enclose custom code in a block to avoid namespace conflicts
|
// Enclose custom code in a block to avoid namespace conflicts
|
||||||
segments->fFSCode.appendf("\t{ // stage %d %s \n",
|
builder->fFSCode.appendf("\t{ // stage %d %s \n",
|
||||||
stageNum, customStage->name());
|
stageNum, customStage->name());
|
||||||
customStage->emitFS(segments, fsOutColor, fsInColor,
|
customStage->emitFS(builder, fsOutColor, fsInColor,
|
||||||
samplerName.c_str());
|
samplerName);
|
||||||
segments->fFSCode.appendf("\t}\n");
|
builder->fFSCode.appendf("\t}\n");
|
||||||
}
|
}
|
||||||
|
builder->setNonStage();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ GrGLProgramStage::~GrGLProgramStage() {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GrGLProgramStage::setupVariables(GrGLShaderBuilder*, int stage) {
|
void GrGLProgramStage::setupVariables(GrGLShaderBuilder*) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
virtual ~GrGLProgramStage();
|
virtual ~GrGLProgramStage();
|
||||||
|
|
||||||
/** Create any uniforms or varyings the vertex shader requires. */
|
/** Create any uniforms or varyings the vertex shader requires. */
|
||||||
virtual void setupVariables(GrGLShaderBuilder* builder, int stage);
|
virtual void setupVariables(GrGLShaderBuilder* builder);
|
||||||
|
|
||||||
/** Appends vertex code to the appropriate SkString
|
/** Appends vertex code to the appropriate SkString
|
||||||
on the state.
|
on the state.
|
||||||
|
@ -38,7 +38,8 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctx, GrGLUniformMana
|
|||||||
, fVaryingDims(0)
|
, fVaryingDims(0)
|
||||||
, fComplexCoord(false)
|
, fComplexCoord(false)
|
||||||
, fContext(ctx)
|
, fContext(ctx)
|
||||||
, fUniformManager(uniformManager) {
|
, fUniformManager(uniformManager)
|
||||||
|
, fCurrentStage(kNonStageIdx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLShaderBuilder::computeSwizzle(uint32_t configFlags) {
|
void GrGLShaderBuilder::computeSwizzle(uint32_t configFlags) {
|
||||||
@ -119,11 +120,11 @@ void GrGLShaderBuilder::emitDefaultFetch(const char* outColor,
|
|||||||
fFSCode.appendf("%s%s;\n", fSwizzle.c_str(), fModulate.c_str());
|
fFSCode.appendf("%s%s;\n", fSwizzle.c_str(), fModulate.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniform(uint32_t visibility,
|
GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t visibility,
|
||||||
GrSLType type,
|
GrSLType type,
|
||||||
const char* name,
|
const char* name,
|
||||||
int stageNum,
|
int count,
|
||||||
int count) {
|
const char** outName) {
|
||||||
GrAssert(name && strlen(name));
|
GrAssert(name && strlen(name));
|
||||||
static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType;
|
static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType;
|
||||||
GrAssert(0 == (~kVisibilityMask & visibility));
|
GrAssert(0 == (~kVisibilityMask & visibility));
|
||||||
@ -138,9 +139,11 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniform(uint32_t visibil
|
|||||||
GrAssert(h2 == h);
|
GrAssert(h2 == h);
|
||||||
uni.fVariable.setType(type);
|
uni.fVariable.setType(type);
|
||||||
uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
|
uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
|
||||||
uni.fVariable.setName(name);
|
SkString* uniName = uni.fVariable.accessName();
|
||||||
if (stageNum >= 0) {
|
if (kNonStageIdx == fCurrentStage) {
|
||||||
uni.fVariable.accessName()->appendS32(stageNum);
|
uniName->printf("u%s", name);
|
||||||
|
} else {
|
||||||
|
uniName->printf("u%s%d", name, fCurrentStage);
|
||||||
}
|
}
|
||||||
uni.fVariable.setArrayCount(count);
|
uni.fVariable.setArrayCount(count);
|
||||||
uni.fVisibility = visibility;
|
uni.fVisibility = visibility;
|
||||||
@ -153,6 +156,10 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniform(uint32_t visibil
|
|||||||
uni.fVariable.setPrecision(kDefaultFragmentPrecision);
|
uni.fVariable.setPrecision(kDefaultFragmentPrecision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NULL != outName) {
|
||||||
|
*outName = uni.fVariable.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +174,11 @@ void GrGLShaderBuilder::addVarying(GrSLType type,
|
|||||||
fVSOutputs.push_back();
|
fVSOutputs.push_back();
|
||||||
fVSOutputs.back().setType(type);
|
fVSOutputs.back().setType(type);
|
||||||
fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
|
fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
|
||||||
fVSOutputs.back().accessName()->printf("v%s", name);
|
if (kNonStageIdx == fCurrentStage) {
|
||||||
|
fVSOutputs.back().accessName()->printf("v%s", name);
|
||||||
|
} else {
|
||||||
|
fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStage);
|
||||||
|
}
|
||||||
if (vsOutName) {
|
if (vsOutName) {
|
||||||
*vsOutName = fVSOutputs.back().getName().c_str();
|
*vsOutName = fVSOutputs.back().getName().c_str();
|
||||||
}
|
}
|
||||||
@ -198,15 +209,6 @@ void GrGLShaderBuilder::addVarying(GrSLType type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLShaderBuilder::addVarying(GrSLType type,
|
|
||||||
const char* name,
|
|
||||||
int stageNum,
|
|
||||||
const char** vsOutName,
|
|
||||||
const char** fsInName) {
|
|
||||||
SkString nameWithStage(name);
|
|
||||||
nameWithStage.appendS32(stageNum);
|
|
||||||
this->addVarying(type, nameWithStage.c_str(), vsOutName, fsInName);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -56,16 +56,23 @@ public:
|
|||||||
const char* samplerName);
|
const char* samplerName);
|
||||||
|
|
||||||
/** Add a uniform variable to the current program, that has visibilty in one or more shaders.
|
/** Add a uniform variable to the current program, that has visibilty in one or more shaders.
|
||||||
If stageNum is specified, it is appended to the name to guarantee uniqueness; if count is
|
visibility is a bitfield of ShaderType values indicating from which shaders the uniform
|
||||||
specified, the uniform is an array. visibility is a bitfield of ShaderType values indicating
|
should be accessible. At least one bit must be set. Geometry shader uniforms are not
|
||||||
from which shaders the uniform should be accessible. At least one bit must be set. Geometry
|
supported at this time. The actual uniform name will be mangled. If outName is not NULL then
|
||||||
shader uniforms are not supported at this time.
|
it will refer to the final uniform name after return. Use the addUniformArray variant to add
|
||||||
|
an array of uniforms.
|
||||||
*/
|
*/
|
||||||
GrGLUniformManager::UniformHandle addUniform(uint32_t visibility,
|
GrGLUniformManager::UniformHandle addUniform(uint32_t visibility,
|
||||||
GrSLType type,
|
GrSLType type,
|
||||||
const char* name,
|
const char* name,
|
||||||
int stageNum = -1,
|
const char** outName = NULL) {
|
||||||
int count = GrGLShaderVar::kNonArray);
|
return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNonArray, outName);
|
||||||
|
}
|
||||||
|
GrGLUniformManager::UniformHandle addUniformArray(uint32_t visibility,
|
||||||
|
GrSLType type,
|
||||||
|
const char* name,
|
||||||
|
int arrayCount,
|
||||||
|
const char** outName = NULL);
|
||||||
|
|
||||||
const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const;
|
const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const;
|
||||||
|
|
||||||
@ -84,23 +91,21 @@ public:
|
|||||||
const char** vsOutName = NULL,
|
const char** vsOutName = NULL,
|
||||||
const char** fsInName = NULL);
|
const char** fsInName = NULL);
|
||||||
|
|
||||||
/** Add a varying variable to the current program to pass values between vertex and fragment
|
|
||||||
shaders; stageNum is appended to the name to guarantee uniqueness. If the last two
|
|
||||||
parameters are non-NULL, they are filled in with the name generated. */
|
|
||||||
void addVarying(GrSLType type,
|
|
||||||
const char* name,
|
|
||||||
int stageNum,
|
|
||||||
const char** vsOutName = NULL,
|
|
||||||
const char** fsInName = NULL);
|
|
||||||
|
|
||||||
/** Called after building is complete to get the final shader string. */
|
/** Called after building is complete to get the final shader string. */
|
||||||
void getShader(ShaderType, SkString*) const;
|
void getShader(ShaderType, SkString*) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Make this do all the compiling, linking, etc. Hide this from the custom stages
|
* TODO: Make this do all the compiling, linking, etc. Hide from the custom stages
|
||||||
*/
|
*/
|
||||||
void finished(GrGLuint programID);
|
void finished(GrGLuint programID);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current stage (used to make variable names unique).
|
||||||
|
* TODO: Hide from the custom stages
|
||||||
|
*/
|
||||||
|
void setCurrentStage(int stage) { fCurrentStage = stage; }
|
||||||
|
void setNonStage() { fCurrentStage = kNonStageIdx; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef GrTAllocator<GrGLShaderVar> VarArray;
|
typedef GrTAllocator<GrGLShaderVar> VarArray;
|
||||||
@ -147,8 +152,13 @@ public:
|
|||||||
//@}
|
//@}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum {
|
||||||
|
kNonStageIdx = -1,
|
||||||
|
};
|
||||||
|
|
||||||
const GrGLContextInfo& fContext;
|
const GrGLContextInfo& fContext;
|
||||||
GrGLUniformManager& fUniformManager;
|
GrGLUniformManager& fUniformManager;
|
||||||
|
int fCurrentStage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "gl/GrGLShaderVar.h"
|
#include "gl/GrGLShaderVar.h"
|
||||||
#include "gl/GrGLSL.h"
|
#include "gl/GrGLSL.h"
|
||||||
|
#include "GrAllocator.h"
|
||||||
|
|
||||||
#include "SkTArray.h"
|
#include "SkTArray.h"
|
||||||
|
|
||||||
@ -50,7 +51,10 @@ public:
|
|||||||
GrGLShaderVar fVariable;
|
GrGLShaderVar fVariable;
|
||||||
uint32_t fVisibility;
|
uint32_t fVisibility;
|
||||||
};
|
};
|
||||||
typedef SkTArray<BuilderUniform, true> BuilderUniformArray;
|
// This uses an allocator rather than array so that the GrGLShaderVars don't move in memory
|
||||||
|
// after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
|
||||||
|
// name strings. Otherwise, we'd have to hand out copies.
|
||||||
|
typedef GrTAllocator<BuilderUniform> BuilderUniformArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the GrGLShaderBuilder to get GL locations for all uniforms.
|
* Called by the GrGLShaderBuilder to get GL locations for all uniforms.
|
||||||
|
Loading…
Reference in New Issue
Block a user