Reland r6330 thru r6333 but do without enabling GL_ARB_fragment_coord_conventions on Intel GPUs.

git-svn-id: http://skia.googlecode.com/svn/trunk@6048 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-10-23 14:53:55 +00:00
Родитель 281c726c76
Коммит 706f66831a
22 изменённых файлов: 174 добавлений и 200 удалений

Просмотреть файл

@ -383,9 +383,7 @@ public:
} }
virtual void setData(const GrGLUniformManager& uniManager, virtual void setData(const GrGLUniformManager& uniManager,
const GrCustomStage& stage, const GrCustomStage& stage) SK_OVERRIDE {
const GrRenderTarget*,
int /* stageNum */) SK_OVERRIDE {
const ColorMatrixEffect& cme = static_cast<const ColorMatrixEffect&>(stage); const ColorMatrixEffect& cme = static_cast<const ColorMatrixEffect&>(stage);
const float* m = cme.fMatrix.fMat; const float* m = cme.fMatrix.fMat;
// The GL matrix is transposed from SkColorMatrix. // The GL matrix is transposed from SkColorMatrix.

Просмотреть файл

@ -42,14 +42,7 @@ void setUniformPoint3(const GrGLUniformManager& uman, UniformHandle uni, const S
} }
void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const SkPoint3& point) { void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const SkPoint3& point) {
setUniformPoint3(uman, uni, SkPoint3(point.fX, -point.fY, point.fZ)); setUniformPoint3(uman, uni, SkPoint3(point.fX, point.fY, point.fZ));
}
void setUniformPoint3FlipY(const GrGLUniformManager& uman,
UniformHandle uni,
const SkPoint3& point,
int height) {
setUniformPoint3(uman, uni, SkPoint3(point.fX, height-point.fY, point.fZ));
} }
#endif #endif
@ -376,12 +369,12 @@ public:
virtual void setupVariables(GrGLShaderBuilder* builder); virtual void setupVariables(GrGLShaderBuilder* builder);
virtual void emitVS(SkString* out) const {} virtual void emitVS(SkString* out) const {}
virtual void emitFuncs(GrGLShaderBuilder* builder) {} virtual void emitFuncs(GrGLShaderBuilder* builder) {}
virtual void emitSurfaceToLight(const GrGLShaderBuilder*, virtual void emitSurfaceToLight(GrGLShaderBuilder*,
SkString* out, SkString* out,
const char* z) const = 0; const char* z) const = 0;
virtual void emitLightColor(GrGLShaderBuilder*, virtual void emitLightColor(GrGLShaderBuilder*,
const char *surfaceToLight) const; const char *surfaceToLight) const;
virtual void setData(const GrGLUniformManager&, const GrRenderTarget* rt, const SkLight* light) const; virtual void setData(const GrGLUniformManager&, const SkLight* light) const;
private: private:
typedef SkRefCnt INHERITED; typedef SkRefCnt INHERITED;
@ -396,8 +389,8 @@ class GrGLDistantLight : public GrGLLight {
public: public:
virtual ~GrGLDistantLight() {} virtual ~GrGLDistantLight() {}
virtual void setupVariables(GrGLShaderBuilder* builder) 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 SkLight* light) const SK_OVERRIDE;
virtual void emitSurfaceToLight(const GrGLShaderBuilder*, virtual void emitSurfaceToLight(GrGLShaderBuilder*,
SkString* out, SkString* out,
const char* z) const SK_OVERRIDE; const char* z) const SK_OVERRIDE;
private: private:
@ -411,9 +404,9 @@ class GrGLPointLight : public GrGLLight {
public: public:
virtual ~GrGLPointLight() {} virtual ~GrGLPointLight() {}
virtual void setupVariables(GrGLShaderBuilder* builder) 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 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(GrGLShaderBuilder*,
SkString* out, SkString* out,
const char* z) const SK_OVERRIDE; const char* z) const SK_OVERRIDE;
private: private:
@ -428,10 +421,10 @@ class GrGLSpotLight : public GrGLLight {
public: public:
virtual ~GrGLSpotLight() {} virtual ~GrGLSpotLight() {}
virtual void setupVariables(GrGLShaderBuilder* builder) 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 SkLight* light) const SK_OVERRIDE;
virtual void emitVS(SkString* out) const SK_OVERRIDE; virtual void emitVS(SkString* out) const SK_OVERRIDE;
virtual void emitFuncs(GrGLShaderBuilder* builder); virtual void emitFuncs(GrGLShaderBuilder* builder);
virtual void emitSurfaceToLight(const GrGLShaderBuilder* builder, virtual void emitSurfaceToLight(GrGLShaderBuilder* builder,
SkString* out, SkString* out,
const char* z) const SK_OVERRIDE; const char* z) const SK_OVERRIDE;
virtual void emitLightColor(GrGLShaderBuilder*, virtual void emitLightColor(GrGLShaderBuilder*,
@ -964,10 +957,7 @@ public:
static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps); static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
private: private:
typedef GrGLProgramStage INHERITED; typedef GrGLProgramStage INHERITED;
@ -985,10 +975,7 @@ public:
const GrCustomStage& stage); const GrCustomStage& stage);
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE; virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE; virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
private: private:
typedef GrGLLightingEffect INHERITED; typedef GrGLLightingEffect INHERITED;
@ -1004,10 +991,7 @@ public:
const GrCustomStage& stage); const GrCustomStage& stage);
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE; virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE; virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
private: private:
typedef GrGLLightingEffect INHERITED; typedef GrGLLightingEffect INHERITED;
@ -1133,7 +1117,7 @@ void GrGLLightingEffect::emitFS(GrGLShaderBuilder* builder,
"pointToNormal", "pointToNormal",
SK_ARRAY_COUNT(gPointToNormalArgs), SK_ARRAY_COUNT(gPointToNormalArgs),
gPointToNormalArgs, gPointToNormalArgs,
"\treturn normalize(vec3(-x * scale, -y * scale, 1));\n", "\treturn normalize(vec3(-x * scale, y * scale, 1));\n",
&pointToNormalName); &pointToNormalName);
static const GrGLShaderVar gInteriorNormalArgs[] = { static const GrGLShaderVar gInteriorNormalArgs[] = {
@ -1189,17 +1173,14 @@ GrGLProgramStage::StageKey GrGLLightingEffect::GenKey(const GrCustomStage& s,
return static_cast<const GrLightingEffect&>(s).light()->type(); return static_cast<const GrLightingEffect&>(s).light()->type();
} }
void GrGLLightingEffect::setData(const GrGLUniformManager& uman, void GrGLLightingEffect::setData(const GrGLUniformManager& uman, const GrCustomStage& data) {
const GrCustomStage& data,
const GrRenderTarget* rt,
int stageNum) {
const GrLightingEffect& effect = const GrLightingEffect& effect =
static_cast<const GrLightingEffect&>(data); static_cast<const GrLightingEffect&>(data);
GrGLTexture* texture = static_cast<GrGLTexture*>(data.texture(0)); GrGLTexture* texture = static_cast<GrGLTexture*>(data.texture(0));
float ySign = texture->orientation() == GrGLTexture::kTopDown_Orientation ? -1.0f : 1.0f; float ySign = texture->orientation() == GrGLTexture::kTopDown_Orientation ? -1.0f : 1.0f;
uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height()); uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
uman.set1f(fSurfaceScaleUni, effect.surfaceScale()); uman.set1f(fSurfaceScaleUni, effect.surfaceScale());
fLight->setData(uman, rt, effect.light()); fLight->setData(uman, effect.light());
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1236,11 +1217,8 @@ void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStri
funcName); funcName);
} }
void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, const GrCustomStage& data) {
const GrCustomStage& data, INHERITED::setData(uman, data);
const GrRenderTarget* rt,
int stageNum) {
INHERITED::setData(uman, data, rt, stageNum);
const GrDiffuseLightingEffect& effect = const GrDiffuseLightingEffect& effect =
static_cast<const GrDiffuseLightingEffect&>(data); static_cast<const GrDiffuseLightingEffect&>(data);
uman.set1f(fKDUni, effect.kd()); uman.set1f(fKDUni, effect.kd());
@ -1319,10 +1297,8 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr
} }
void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman, void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman,
const GrCustomStage& data, const GrCustomStage& data) {
const GrRenderTarget* rt, INHERITED::setData(uman, data);
int stageNum) {
INHERITED::setData(uman, data, rt, stageNum);
const GrSpecularLightingEffect& effect = static_cast<const GrSpecularLightingEffect&>(data); const GrSpecularLightingEffect& effect = static_cast<const GrSpecularLightingEffect&>(data);
uman.set1f(fKSUni, effect.ks()); uman.set1f(fKSUni, effect.ks());
uman.set1f(fShininessUni, effect.shininess()); uman.set1f(fShininessUni, effect.shininess());
@ -1342,7 +1318,6 @@ void GrGLLight::setupVariables(GrGLShaderBuilder* builder) {
} }
void GrGLLight::setData(const GrGLUniformManager& uman, void GrGLLight::setData(const GrGLUniformManager& uman,
const GrRenderTarget* rt,
const SkLight* light) const { const SkLight* light) const {
setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToScalar(255))); setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToScalar(255)));
} }
@ -1355,16 +1330,14 @@ void GrGLDistantLight::setupVariables(GrGLShaderBuilder* builder) {
"LightDirection"); "LightDirection");
} }
void GrGLDistantLight::setData(const GrGLUniformManager& uman, void GrGLDistantLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
const GrRenderTarget* rt, INHERITED::setData(uman, light);
const SkLight* light) const {
INHERITED::setData(uman, rt, light);
SkASSERT(light->type() == SkLight::kDistant_LightType); SkASSERT(light->type() == SkLight::kDistant_LightType);
const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(light); const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(light);
setUniformNormal3(uman, fDirectionUni, distantLight->direction()); setUniformNormal3(uman, fDirectionUni, distantLight->direction());
} }
void GrGLDistantLight::emitSurfaceToLight(const GrGLShaderBuilder* builder, void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
SkString* out, SkString* out,
const char* z) const { const char* z) const {
const char* dir = builder->getUniformCStr(fDirectionUni); const char* dir = builder->getUniformCStr(fDirectionUni);
@ -1380,22 +1353,21 @@ void GrGLPointLight::setupVariables(GrGLShaderBuilder* builder) {
} }
void GrGLPointLight::setData(const GrGLUniformManager& uman, void GrGLPointLight::setData(const GrGLUniformManager& uman,
const GrRenderTarget* rt,
const SkLight* light) const { const SkLight* light) const {
INHERITED::setData(uman, rt, light); INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kPoint_LightType); SkASSERT(light->type() == SkLight::kPoint_LightType);
const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
setUniformPoint3FlipY(uman, fLocationUni, pointLight->location(), rt->height()); setUniformPoint3(uman, fLocationUni, pointLight->location());
} }
void GrGLPointLight::emitVS(SkString* out) const { void GrGLPointLight::emitVS(SkString* out) const {
} }
void GrGLPointLight::emitSurfaceToLight(const GrGLShaderBuilder* builder, void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
SkString* out, SkString* out,
const char* z) const { const char* z) const {
const char* loc = builder->getUniformCStr(fLocationUni); const char* loc = builder->getUniformCStr(fLocationUni);
out->appendf("normalize(%s - vec3(gl_FragCoord.xy, %s))", loc, z); out->appendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->fragmentPosition(), z);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -1417,12 +1389,11 @@ void GrGLSpotLight::setupVariables(GrGLShaderBuilder* builder) {
} }
void GrGLSpotLight::setData(const GrGLUniformManager& uman, void GrGLSpotLight::setData(const GrGLUniformManager& uman,
const GrRenderTarget* rt,
const SkLight* light) const { const SkLight* light) const {
INHERITED::setData(uman, rt, light); INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kSpot_LightType); SkASSERT(light->type() == SkLight::kSpot_LightType);
const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
setUniformPoint3FlipY(uman, fLocationUni, spotLight->location(), rt->height()); setUniformPoint3(uman, fLocationUni, spotLight->location());
uman.set1f(fExponentUni, spotLight->specularExponent()); uman.set1f(fExponentUni, spotLight->specularExponent());
uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle());
uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle());
@ -1463,11 +1434,11 @@ void GrGLSpotLight::emitFuncs(GrGLShaderBuilder* builder) {
&fLightColorFunc); &fLightColorFunc);
} }
void GrGLSpotLight::emitSurfaceToLight(const GrGLShaderBuilder* builder, void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
SkString* out, SkString* out,
const char* z) const { const char* z) const {
const char* location= builder->getUniformCStr(fLocationUni); const char* location= builder->getUniformCStr(fLocationUni);
out->appendf("normalize(%s - vec3(gl_FragCoord.xy, %s))", location, z); out->appendf("normalize(%s - vec3(%s.xy, %s))", location, builder->fragmentPosition(), z);
} }
void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder, void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,

Просмотреть файл

@ -86,9 +86,7 @@ public:
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, virtual void setData(const GrGLUniformManager& uman,
const GrCustomStage& data, const GrCustomStage& data) SK_OVERRIDE;
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&); static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&);
@ -167,9 +165,7 @@ void GrGLMagnifierEffect::emitFS(GrGLShaderBuilder* state,
} }
void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman, void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman,
const GrCustomStage& data, const GrCustomStage& data) {
const GrRenderTarget*,
int stageNum) {
const GrMagnifierEffect& zoom = const GrMagnifierEffect& zoom =
static_cast<const GrMagnifierEffect&>(data); static_cast<const GrMagnifierEffect&>(data);

Просмотреть файл

@ -293,10 +293,7 @@ public:
static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps); static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
private: private:
typedef GrGLUniformManager::UniformHandle UniformHandle; typedef GrGLUniformManager::UniformHandle UniformHandle;
@ -426,9 +423,7 @@ GrGLProgramStage::StageKey GrGLMatrixConvolutionEffect::GenKey(const GrCustomSta
} }
void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
const GrCustomStage& data, const GrCustomStage& data) {
const GrRenderTarget*,
int stageNum) {
const GrMatrixConvolutionEffect& effect = const GrMatrixConvolutionEffect& effect =
static_cast<const GrMatrixConvolutionEffect&>(data); static_cast<const GrMatrixConvolutionEffect&>(data);
GrGLTexture& texture = GrGLTexture& texture =

Просмотреть файл

@ -281,10 +281,7 @@ public:
static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps); static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
private: private:
int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); }
@ -352,10 +349,7 @@ GrGLProgramStage::StageKey GrGLMorphologyEffect::GenKey(const GrCustomStage& s,
return key; return key;
} }
void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, const GrCustomStage& data) {
const GrCustomStage& data,
const GrRenderTarget*,
int stageNum) {
const Gr1DKernelEffect& kern = const Gr1DKernelEffect& kern =
static_cast<const Gr1DKernelEffect&>(data); static_cast<const Gr1DKernelEffect&>(data);
GrGLTexture& texture = GrGLTexture& texture =

Просмотреть файл

@ -257,10 +257,7 @@ public:
const char* inputColor, const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE {}
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE {}
static StageKey GenKey(const GrCustomStage&, const GrGLCaps&); static StageKey GenKey(const GrCustomStage&, const GrGLCaps&);

Просмотреть файл

@ -687,10 +687,7 @@ void GrGLGradientStage::setupVariables(GrGLShaderBuilder* builder) {
kFloat_GrSLType, "GradientYCoordFS"); kFloat_GrSLType, "GradientYCoordFS");
} }
void GrGLGradientStage::setData(const GrGLUniformManager& uman, void GrGLGradientStage::setData(const GrGLUniformManager& uman, const GrCustomStage& stage) {
const GrCustomStage& stage,
const GrRenderTarget*,
int stageNum) {
GrScalar yCoord = static_cast<const GrGradientEffect&>(stage).getYCoord(); GrScalar yCoord = static_cast<const GrGradientEffect&>(stage).getYCoord();
if (yCoord != fCachedYCoord) { if (yCoord != fCachedYCoord) {
uman.set1f(fFSYUni, yCoord); uman.set1f(fFSYUni, yCoord);

Просмотреть файл

@ -278,10 +278,7 @@ public:
virtual ~GrGLGradientStage(); virtual ~GrGLGradientStage();
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE; virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
// emit code that gets a fragment's color from an expression for t; for now // emit code that gets a fragment's color from an expression for t; for now
// this always uses the texture, but for simpler cases we'll be able to lerp // this always uses the texture, but for simpler cases we'll be able to lerp

Просмотреть файл

@ -333,10 +333,7 @@ public:
const char* outputColor, const char* outputColor,
const char* inputColor, const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps); static StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
@ -629,11 +626,8 @@ void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder,
} }
} }
void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrCustomStage& baseData) {
const GrCustomStage& baseData, INHERITED::setData(uman, baseData);
const GrRenderTarget* target,
int stageNum) {
INHERITED::setData(uman, baseData, target, stageNum);
const GrConical2Gradient& data = const GrConical2Gradient& data =
static_cast<const GrConical2Gradient&>(baseData); static_cast<const GrConical2Gradient&>(baseData);
GrAssert(data.isDegenerate() == fIsDegenerate); GrAssert(data.isDegenerate() == fIsDegenerate);

Просмотреть файл

@ -368,10 +368,7 @@ public:
const char* outputColor, const char* outputColor,
const char* inputColor, const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
static StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps); static StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
@ -566,7 +563,6 @@ void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder,
bVar = fFSVaryingName; bVar = fFSVaryingName;
} else { } else {
bVar = "b"; bVar = "b";
//bVar.appendS32(stageNum);
code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
bVar.c_str(), p2.c_str(), bVar.c_str(), p2.c_str(),
builder->defaultTexCoordsName(), p3.c_str()); builder->defaultTexCoordsName(), p3.c_str());
@ -605,11 +601,8 @@ void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder,
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]); this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
} }
void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrCustomStage& baseData) {
const GrCustomStage& baseData, INHERITED::setData(uman, baseData);
const GrRenderTarget* target,
int stageNum) {
INHERITED::setData(uman, baseData, target, stageNum);
const GrRadial2Gradient& data = const GrRadial2Gradient& data =
static_cast<const GrRadial2Gradient&>(baseData); static_cast<const GrRadial2Gradient&>(baseData);
GrAssert(data.isDegenerate() == fIsDegenerate); GrAssert(data.isDegenerate() == fIsDegenerate);

Просмотреть файл

@ -458,16 +458,7 @@ void add_line(const SkPoint p[2],
if (orthVec.setLength(SK_Scalar1)) { if (orthVec.setLength(SK_Scalar1)) {
orthVec.setOrthog(orthVec); orthVec.setOrthog(orthVec);
// the values we pass down to the frag shader SkScalar lineC = -(a.dot(orthVec));
// have to be in y-points-up space;
SkVector normal;
normal.fX = orthVec.fX;
normal.fY = -orthVec.fY;
SkPoint aYDown;
aYDown.fX = a.fX;
aYDown.fY = rtHeight - a.fY;
SkScalar lineC = -(aYDown.dot(normal));
for (int i = 0; i < kVertsPerLineSeg; ++i) { for (int i = 0; i < kVertsPerLineSeg; ++i) {
(*vert)[i].fPos = (i < 2) ? a : b; (*vert)[i].fPos = (i < 2) ? a : b;
if (0 == i || 3 == i) { if (0 == i || 3 == i) {
@ -475,8 +466,8 @@ void add_line(const SkPoint p[2],
} else { } else {
(*vert)[i].fPos += orthVec; (*vert)[i].fPos += orthVec;
} }
(*vert)[i].fLine.fA = normal.fX; (*vert)[i].fLine.fA = orthVec.fX;
(*vert)[i].fLine.fB = normal.fY; (*vert)[i].fLine.fB = orthVec.fY;
(*vert)[i].fLine.fC = lineC; (*vert)[i].fLine.fC = lineC;
} }
if (NULL != toSrc) { if (NULL != toSrc) {

Просмотреть файл

@ -1061,9 +1061,7 @@ void GrContext::drawOval(const GrPaint& paint,
verts[3].fPos = SkPoint::Make(R, B); verts[3].fPos = SkPoint::Make(R, B);
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
// this goes to fragment shader, it should be in y-points-up space. verts[i].fCenter = center;
verts[i].fCenter = SkPoint::Make(center.fX, rt->height() - center.fY);
verts[i].fOuterRadius = outerRadius; verts[i].fOuterRadius = outerRadius;
verts[i].fInnerRadius = innerRadius; verts[i].fInnerRadius = innerRadius;
} }

Просмотреть файл

@ -28,10 +28,7 @@ public:
const char* inputColor, const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, virtual void setData(const GrGLUniformManager& uman, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&); static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&);
@ -91,10 +88,7 @@ void GrGLConvolutionEffect::emitFS(GrGLShaderBuilder* builder,
GrGLSLMulVarBy4f(&builder->fFSCode, 2, outputColor, inputColor); GrGLSLMulVarBy4f(&builder->fFSCode, 2, outputColor, inputColor);
} }
void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, const GrCustomStage& data) {
const GrCustomStage& data,
const GrRenderTarget*,
int stageNum) {
const GrConvolutionEffect& conv = const GrConvolutionEffect& conv =
static_cast<const GrConvolutionEffect&>(data); static_cast<const GrConvolutionEffect&>(data);
GrTexture& texture = *data.texture(0); GrTexture& texture = *data.texture(0);

Просмотреть файл

@ -22,10 +22,7 @@ public:
const char* inputColor, const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE; const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; } static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; }
@ -63,10 +60,7 @@ void GrGLTextureDomainEffect::emitFS(GrGLShaderBuilder* builder,
builder->fFSCode.append(";\n"); builder->fFSCode.append(";\n");
} }
void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrCustomStage& data) {
const GrCustomStage& data,
const GrRenderTarget*,
int stageNum) {
const GrTextureDomainEffect& effect = static_cast<const GrTextureDomainEffect&>(data); const GrTextureDomainEffect& effect = static_cast<const GrTextureDomainEffect&>(data);
const GrRect& domain = effect.domain(); const GrRect& domain = effect.domain();

Просмотреть файл

@ -36,6 +36,7 @@ void GrGLCaps::reset() {
fTextureRedSupport = false; fTextureRedSupport = false;
fImagingSupport = false; fImagingSupport = false;
fTwoFormatLimit = false; fTwoFormatLimit = false;
fFragCoordsConventionSupport = false;
} }
GrGLCaps::GrGLCaps(const GrGLCaps& caps) { GrGLCaps::GrGLCaps(const GrGLCaps& caps) {
@ -65,6 +66,7 @@ GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
fTextureRedSupport = caps.fTextureRedSupport; fTextureRedSupport = caps.fTextureRedSupport;
fImagingSupport = caps.fImagingSupport; fImagingSupport = caps.fImagingSupport;
fTwoFormatLimit = caps.fTwoFormatLimit; fTwoFormatLimit = caps.fTwoFormatLimit;
fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
return *this; return *this;
} }
@ -158,6 +160,13 @@ void GrGLCaps::init(const GrGLContextInfo& ctxInfo) {
// can change based on which render target is bound // can change based on which render target is bound
fTwoFormatLimit = kES2_GrGLBinding == binding; fTwoFormatLimit = kES2_GrGLBinding == binding;
// Known issue on at least some Intel platforms:
// http://code.google.com/p/skia/issues/detail?id=946
if (kIntel_GrGLVendor != ctxInfo.vendor()) {
fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
}
this->initFSAASupport(ctxInfo); this->initFSAASupport(ctxInfo);
this->initStencilFormats(ctxInfo); this->initStencilFormats(ctxInfo);
} }
@ -415,5 +424,6 @@ void GrGLCaps::print() const {
GrPrintf("Pack Flip Y support: %s\n", GrPrintf("Pack Flip Y support: %s\n",
(fPackFlipYSupport ? "YES": "NO")); (fPackFlipYSupport ? "YES": "NO"));
GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
GrPrintf("Fragment coord conventions support: %s\n", (fFragCoordsConventionSupport ? "YES": "NO"));
} }

Просмотреть файл

@ -216,6 +216,9 @@ public:
/// Is GL_ARB_IMAGING supported /// Is GL_ARB_IMAGING supported
bool imagingSupport() const { return fImagingSupport; } bool imagingSupport() const { return fImagingSupport; }
/// Is GL_ARB_fragment_coord_conventions supported?
bool fragCoordConventionsSupport() const { return fFragCoordsConventionSupport; }
// Does ReadPixels support the provided format/type combo? // Does ReadPixels support the provided format/type combo?
bool readPixelsSupported(const GrGLInterface* intf, bool readPixelsSupported(const GrGLInterface* intf,
GrGLenum format, GrGLenum format,
@ -293,6 +296,7 @@ private:
bool fTextureRedSupport : 1; bool fTextureRedSupport : 1;
bool fImagingSupport : 1; bool fImagingSupport : 1;
bool fTwoFormatLimit : 1; bool fTwoFormatLimit : 1;
bool fFragCoordsConventionSupport : 1;
}; };
#endif #endif

Просмотреть файл

@ -77,6 +77,7 @@ GrGLProgram::GrGLProgram(const GrGLContextInfo& gl,
fViewportSize.set(-1, -1); fViewportSize.set(-1, -1);
fColor = GrColor_ILLEGAL; fColor = GrColor_ILLEGAL;
fColorFilterColor = GrColor_ILLEGAL; fColorFilterColor = GrColor_ILLEGAL;
fRTHeight = -1;
for (int s = 0; s < GrDrawState::kNumStages; ++s) { for (int s = 0; s < GrDrawState::kNumStages; ++s) {
fProgramStage[s] = NULL; fProgramStage[s] = NULL;
@ -234,56 +235,57 @@ static void addColorFilter(SkString* fsCode, const char * outputVar,
} }
bool GrGLProgram::genEdgeCoverage(SkString* coverageVar, bool GrGLProgram::genEdgeCoverage(SkString* coverageVar,
GrGLShaderBuilder* segments) const { GrGLShaderBuilder* builder) const {
if (fDesc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit) { if (fDesc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit) {
const char *vsName, *fsName; const char *vsName, *fsName;
segments->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName); builder->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName);
segments->fVSAttrs.push_back().set(kVec4f_GrSLType, builder->fVSAttrs.push_back().set(kVec4f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier, EDGE_ATTR_NAME); GrGLShaderVar::kAttribute_TypeModifier,
segments->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName); EDGE_ATTR_NAME);
builder->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName);
switch (fDesc.fVertexEdgeType) { switch (fDesc.fVertexEdgeType) {
case GrDrawState::kHairLine_EdgeType: case GrDrawState::kHairLine_EdgeType:
segments->fFSCode.appendf("\tfloat edgeAlpha = abs(dot(vec3(gl_FragCoord.xy,1), %s.xyz));\n", fsName); builder->fFSCode.appendf("\tfloat edgeAlpha = abs(dot(vec3(%s.xy,1), %s.xyz));\n", builder->fragmentPosition(), fsName);
segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); builder->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
break; break;
case GrDrawState::kQuad_EdgeType: case GrDrawState::kQuad_EdgeType:
segments->fFSCode.append("\tfloat edgeAlpha;\n"); builder->fFSCode.append("\tfloat edgeAlpha;\n");
// keep the derivative instructions outside the conditional // keep the derivative instructions outside the conditional
segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); builder->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName);
segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); builder->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName);
segments->fFSCode.appendf("\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsName, fsName); builder->fFSCode.appendf("\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsName, fsName);
// today we know z and w are in device space. We could use derivatives // today we know z and w are in device space. We could use derivatives
segments->fFSCode.appendf("\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);\n", fsName, fsName); builder->fFSCode.appendf("\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);\n", fsName, fsName);
segments->fFSCode.append ("\t} else {\n"); builder->fFSCode.append ("\t} else {\n");
segments->fFSCode.appendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" builder->fFSCode.appendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n"
"\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n", "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n",
fsName, fsName); fsName, fsName);
segments->fFSCode.appendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); builder->fFSCode.appendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName);
segments->fFSCode.append("\t\tedgeAlpha = clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n" builder->fFSCode.append("\t\tedgeAlpha = clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n"
"\t}\n"); "\t}\n");
if (kES2_GrGLBinding == fContextInfo.binding()) { if (kES2_GrGLBinding == fContextInfo.binding()) {
segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); builder->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
} }
break; break;
case GrDrawState::kHairQuad_EdgeType: case GrDrawState::kHairQuad_EdgeType:
segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); builder->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName);
segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); builder->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName);
segments->fFSCode.appendf("\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" builder->fFSCode.appendf("\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n"
"\t 2.0*%s.x*duvdy.x - duvdy.y);\n", "\t 2.0*%s.x*duvdy.x - duvdy.y);\n",
fsName, fsName); fsName, fsName);
segments->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); builder->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName);
segments->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n"); builder->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n");
segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); builder->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
if (kES2_GrGLBinding == fContextInfo.binding()) { if (kES2_GrGLBinding == fContextInfo.binding()) {
segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); builder->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
} }
break; break;
case GrDrawState::kCircle_EdgeType: case GrDrawState::kCircle_EdgeType:
segments->fFSCode.append("\tfloat edgeAlpha;\n"); builder->fFSCode.append("\tfloat edgeAlpha;\n");
segments->fFSCode.appendf("\tfloat d = distance(gl_FragCoord.xy, %s.xy);\n", fsName); builder->fFSCode.appendf("\tfloat d = distance(%s.xy, %s.xy);\n", builder->fragmentPosition(), fsName);
segments->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName); builder->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName);
segments->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : smoothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); builder->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : smoothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName);
segments->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); builder->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n");
break; break;
default: default:
GrCrash("Unknown Edge Type!"); GrCrash("Unknown Edge Type!");
@ -807,6 +809,7 @@ bool GrGLProgram::genProgram(const GrCustomStage** customStages) {
builder.finished(fProgramID); builder.finished(fProgramID);
this->initSamplerUniforms(); this->initSamplerUniforms();
fUniforms.fRTHeight = builder.getRTHeightUniform();
return true; return true;
} }
@ -964,15 +967,17 @@ GrGLProgramStage* GrGLProgram::GenStageCode(const GrCustomStage* stage,
return glStage; return glStage;
} }
void GrGLProgram::setData(const GrDrawState& drawState) const { void GrGLProgram::setData(const GrDrawState& drawState) {
int rtHeight = drawState.getRenderTarget()->height();
if (GrGLUniformManager::kInvalidUniformHandle != fUniforms.fRTHeight && fRTHeight != rtHeight) {
fUniformManager.set1f(fUniforms.fRTHeight, GrIntToScalar(rtHeight));
fRTHeight = rtHeight;
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) { for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (NULL != fProgramStage[s]) { if (NULL != fProgramStage[s]) {
const GrSamplerState& sampler = drawState.getSampler(s); const GrSamplerState& sampler = drawState.getSampler(s);
GrAssert(NULL != sampler.getCustomStage()); GrAssert(NULL != sampler.getCustomStage());
fProgramStage[s]->setData(fUniformManager, fProgramStage[s]->setData(fUniformManager, *sampler.getCustomStage());
*sampler.getCustomStage(),
drawState.getRenderTarget(),
s);
} }
} }
} }

Просмотреть файл

@ -70,7 +70,7 @@ public:
* This function uploads uniforms and calls each GrCustomStage's setData. It is called before a * This function uploads uniforms and calls each GrCustomStage's setData. It is called before a
* draw occurs using the program after the program has already been bound. * draw occurs using the program after the program has already been bound.
*/ */
void setData(const GrDrawState& drawState) const; void setData(const GrDrawState& drawState);
// Parameters that affect code generation // Parameters that affect code generation
// These structs should be kept compact; they are the input to an // These structs should be kept compact; they are the input to an
@ -219,12 +219,16 @@ private:
UniformHandle fColorUni; UniformHandle fColorUni;
UniformHandle fCoverageUni; UniformHandle fCoverageUni;
UniformHandle fColorFilterUni; UniformHandle fColorFilterUni;
// We use the render target height to provide a y-down frag coord when specifying
// origin_upper_left is not supported.
UniformHandle fRTHeight;
StageUniforms fStages[GrDrawState::kNumStages]; StageUniforms fStages[GrDrawState::kNumStages];
Uniforms() { Uniforms() {
fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle; fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle;
fColorUni = GrGLUniformManager::kInvalidUniformHandle; fColorUni = GrGLUniformManager::kInvalidUniformHandle;
fCoverageUni = GrGLUniformManager::kInvalidUniformHandle; fCoverageUni = GrGLUniformManager::kInvalidUniformHandle;
fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle; fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle;
fRTHeight = GrGLUniformManager::kInvalidUniformHandle;
} }
}; };
@ -244,6 +248,7 @@ private:
GrColor fColor; GrColor fColor;
GrColor fCoverage; GrColor fCoverage;
GrColor fColorFilterColor; GrColor fColorFilterColor;
int fRTHeight;
/// When it is sent to GL, the texture matrix will be flipped if the texture orientation /// When it is sent to GL, the texture matrix will be flipped if the texture orientation
/// (below) requires. /// (below) requires.
GrMatrix fTextureMatrices[GrDrawState::kNumStages]; GrMatrix fTextureMatrices[GrDrawState::kNumStages];

Просмотреть файл

@ -21,10 +21,7 @@ void GrGLProgramStage::setupVariables(GrGLShaderBuilder*) {
} }
void GrGLProgramStage::setData(const GrGLUniformManager&, void GrGLProgramStage::setData(const GrGLUniformManager&, const GrCustomStage&) {
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) {
} }
GrGLProgramStage::StageKey GrGLProgramStage::GenTextureKey(const GrCustomStage& stage, GrGLProgramStage::StageKey GrGLProgramStage::GenTextureKey(const GrCustomStage& stage,

Просмотреть файл

@ -73,10 +73,7 @@ public:
that produces the same stage key; this function reads data from that produces the same stage key; this function reads data from
a stage and uploads any uniform variables required by the shaders a stage and uploads any uniform variables required by the shaders
created in emit*(). */ created in emit*(). */
virtual void setData(const GrGLUniformManager&, virtual void setData(const GrGLUniformManager&, const GrCustomStage& stage);
const GrCustomStage& stage,
const GrRenderTarget* renderTarget,
int stageNum);
const char* name() const { return fFactory.name(); } const char* name() const { return fFactory.name(); }

Просмотреть файл

@ -93,13 +93,15 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctx, GrGLUniformMana
, fContext(ctx) , fContext(ctx)
, fUniformManager(uniformManager) , fUniformManager(uniformManager)
, fCurrentStage(kNonStageIdx) , fCurrentStage(kNonStageIdx)
, fSetupFragPosition(false)
, fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
, fTexCoordVaryingType(kVoid_GrSLType) { , fTexCoordVaryingType(kVoid_GrSLType) {
} }
void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType varyingType) { void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType varyingType) {
// FIXME: We don't know how the custom stage will manipulate the coords. So we give up on using // FIXME: We don't know how the custom stage will manipulate the coords. So we give up on using
// projective texturing and always give the stage 2D coords. This will be fixed when custom // projective texturing and always give the stage 2D coords. This will be fixed when custom
// stages are repsonsible for setting up their own tex coords / tex matrices. // stages are responsible for setting up their own tex coords / tex matrices.
switch (varyingType) { switch (varyingType) {
case kVec2f_GrSLType: case kVec2f_GrSLType:
fDefaultTexCoordsName = varyingFSName; fDefaultTexCoordsName = varyingFSName;
@ -283,6 +285,40 @@ void GrGLShaderBuilder::addVarying(GrSLType type,
} }
} }
const char* GrGLShaderBuilder::fragmentPosition() {
if (fContext.caps().fragCoordConventionsSupport()) {
if (!fSetupFragPosition) {
fFSHeader.append("#extension GL_ARB_fragment_coord_conventions: require\n");
fFSHeader.append("layout(origin_upper_left) in vec4 gl_FragCoord;\n");
fSetupFragPosition = true;
}
return "gl_FragCoord";
} else {
static const char* kCoordName = "fragCoordYDown";
if (!fSetupFragPosition) {
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fRTHeightUniform);
const char* rtHeightName;
// temporarily change the stage index because we're inserting a uniform whose name
// shouldn't be mangled to be stage-specific.
int oldStageIdx = fCurrentStage;
fCurrentStage = kNonStageIdx;
fRTHeightUniform = this->addUniform(kFragment_ShaderType,
kFloat_GrSLType,
"RTHeight",
&rtHeightName);
fCurrentStage = oldStageIdx;
this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_FragCoord.y, gl_FragCoord.zw);\n",
kCoordName, rtHeightName);
fSetupFragPosition = true;
}
GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform);
return kCoordName;
}
}
void GrGLShaderBuilder::emitFunction(ShaderType shader, void GrGLShaderBuilder::emitFunction(ShaderType shader,
GrSLType returnType, GrSLType returnType,
const char* name, const char* name,
@ -381,6 +417,7 @@ void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const {
append_default_precision_qualifier(kDefaultFragmentPrecision, append_default_precision_qualifier(kDefaultFragmentPrecision,
fContext.binding(), fContext.binding(),
shaderStr); shaderStr);
shaderStr->append(fFSHeader);
this->appendUniformDecls(kFragment_ShaderType, shaderStr); this->appendUniformDecls(kFragment_ShaderType, shaderStr);
this->appendDecls(fFSInputs, shaderStr); this->appendDecls(fFSInputs, shaderStr);
// We shouldn't have declared outputs on 1.10 // We shouldn't have declared outputs on 1.10

Просмотреть файл

@ -129,7 +129,7 @@ public:
the generated shader code. This potentially allows greater reuse of cached shaders. */ the generated shader code. This potentially allows greater reuse of cached shaders. */
static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps); static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps);
/** 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 visibility in one or more shaders.
visibility is a bitfield of ShaderType values indicating from which shaders the uniform visibility is a bitfield of ShaderType values indicating from which shaders the uniform
should be accessible. At least one bit must be set. Geometry shader uniforms are not should be accessible. At least one bit must be set. Geometry shader uniforms are not
supported at this time. The actual uniform name will be mangled. If outName is not NULL then supported at this time. The actual uniform name will be mangled. If outName is not NULL then
@ -151,7 +151,7 @@ public:
const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const; const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const;
/** /**
* Shorcut for getUniformVariable(u).c_str() * Shortcut for getUniformVariable(u).c_str()
*/ */
const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const { const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const {
return this->getUniformVariable(u).c_str(); return this->getUniformVariable(u).c_str();
@ -165,6 +165,10 @@ public:
const char** vsOutName = NULL, const char** vsOutName = NULL,
const char** fsInName = NULL); const char** fsInName = NULL);
/** Returns a variable name that represents the position of the fragment in the FS. The position
is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
const char* fragmentPosition();
/** 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;
@ -180,6 +184,8 @@ public:
void setCurrentStage(int stage) { fCurrentStage = stage; } void setCurrentStage(int stage) { fCurrentStage = stage; }
void setNonStage() { fCurrentStage = kNonStageIdx; } void setNonStage() { fCurrentStage = kNonStageIdx; }
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
private: private:
typedef GrTAllocator<GrGLShaderVar> VarArray; typedef GrTAllocator<GrGLShaderVar> VarArray;
@ -215,6 +221,10 @@ private:
GrGLUniformManager& fUniformManager; GrGLUniformManager& fUniformManager;
int fCurrentStage; int fCurrentStage;
SkString fFSFunctions; SkString fFSFunctions;
SkString fFSHeader;
bool fSetupFragPosition;
GrGLUniformManager::UniformHandle fRTHeightUniform;
/// Per-stage settings - only valid while we're inside GrGLProgram::genStageCode(). /// Per-stage settings - only valid while we're inside GrGLProgram::genStageCode().
//@{ //@{