aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects
diff options
context:
space:
mode:
authorGravatar twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-02 15:15:16 +0000
committerGravatar twiz@google.com <twiz@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-02 15:15:16 +0000
commita5e65ec434fed44dc616e4f64950b835b541181b (patch)
treeffe3592179c7c3ce78db8e5e485c641900042015 /src/gpu/effects
parenteb7ad4a8b9c67743d6aa4e71b82e32f4cf1c8a9f (diff)
Introduction of set of functions to manage generation of texture fetch shader code.
A new set of routines have been added to GrGLShaderBuilder to emit texture fetches, taking into consideration the format of the texture to be accessed, and the channel swizzle. Review URL: https://codereview.appspot.com/6446072 git-svn-id: http://skia.googlecode.com/svn/trunk@4919 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/GrColorTableEffect.cpp60
-rw-r--r--src/gpu/effects/GrColorTableEffect.h4
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp7
-rw-r--r--src/gpu/effects/GrMorphologyEffect.cpp6
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.cpp4
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.cpp4
6 files changed, 57 insertions, 28 deletions
diff --git a/src/gpu/effects/GrColorTableEffect.cpp b/src/gpu/effects/GrColorTableEffect.cpp
index 2075c22fbb..f1ce664826 100644
--- a/src/gpu/effects/GrColorTableEffect.cpp
+++ b/src/gpu/effects/GrColorTableEffect.cpp
@@ -30,49 +30,72 @@ public:
const GrRenderTarget*,
int stageNum) SK_OVERRIDE {}
- static inline StageKey GenKey(const GrCustomStage&);
+ static StageKey GenKey(const GrCustomStage&, const GrGLCaps&);
private:
+
+ const GrCustomStage& fCustomStage;
+
typedef GrGLProgramStage INHERITED;
};
GrGLColorTableEffect::GrGLColorTableEffect(
const GrProgramStageFactory& factory, const GrCustomStage& stage)
- : INHERITED(factory) {
+ : INHERITED(factory)
+ , fCustomStage(stage) {
}
-void GrGLColorTableEffect::emitFS(GrGLShaderBuilder* state,
+void GrGLColorTableEffect::emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
const char* samplerName) {
static const float kColorScaleFactor = 255.0f / 256.0f;
static const float kColorOffsetFactor = 1.0f / 512.0f;
- SkString* code = &state->fFSCode;
+ SkString* code = &builder->fFSCode;
code->appendf("\t\tvec4 coord = vec4(%s.rgb / %s.a, %s.a);\n",
inputColor, inputColor, inputColor);
code->appendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
kColorScaleFactor,
kColorOffsetFactor, kColorOffsetFactor, kColorOffsetFactor, kColorOffsetFactor);
- code->appendf("\t\t%s.a = texture2D(%s, vec2(coord.a, 0.125)).a;\n",
- outputColor, samplerName);
- code->appendf("\t\t%s.r = texture2D(%s, vec2(coord.r, 0.375)).a;\n",
- outputColor, samplerName);
- code->appendf("\t\t%s.g = texture2D(%s, vec2(coord.g, 0.625)).a;\n",
- outputColor, samplerName);
- code->appendf("\t\t%s.b = texture2D(%s, vec2(coord.b, 0.875)).a;\n",
- outputColor, samplerName);
+
+ const GrTextureAccess& access = *fCustomStage.textureAccess(0);
+ code->appendf("\t\t%s.a = ", outputColor);
+ builder->emitCustomTextureLookup(GrGLShaderBuilder::kDefault_SamplerMode,
+ access,
+ samplerName,
+ "vec2(coord.a, 0.125)");
+
+ code->appendf("\t\t%s.r = ", outputColor);
+ builder->emitCustomTextureLookup(GrGLShaderBuilder::kDefault_SamplerMode,
+ access,
+ samplerName,
+ "vec2(coord.r, 0.375)");
+
+ code->appendf("\t\t%s.g = ", outputColor);
+ builder->emitCustomTextureLookup(GrGLShaderBuilder::kDefault_SamplerMode,
+ access,
+ samplerName,
+ "vec2(coord.g, 0.625)");
+
+ code->appendf("\t\t%s.b = ", outputColor);
+ builder->emitCustomTextureLookup(GrGLShaderBuilder::kDefault_SamplerMode,
+ access,
+ samplerName,
+ "vec2(coord.b, 0.875)");
+
code->appendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
-GrGLProgramStage::StageKey GrGLColorTableEffect::GenKey(
- const GrCustomStage& s) {
+GrGLProgramStage::StageKey GrGLColorTableEffect::GenKey(const GrCustomStage& s,
+ const GrGLCaps& caps) {
return 0;
}
///////////////////////////////////////////////////////////////////////////////
GrColorTableEffect::GrColorTableEffect(GrTexture* texture)
- : INHERITED(texture) {
+ : INHERITED(texture)
+ , fTextureAccess(texture, SkString("a")) {
}
GrColorTableEffect::~GrColorTableEffect() {
@@ -85,3 +108,10 @@ const GrProgramStageFactory& GrColorTableEffect::getFactory() const {
bool GrColorTableEffect::isEqual(const GrCustomStage& sBase) const {
return INHERITED::isEqual(sBase);
}
+
+const GrTextureAccess* GrColorTableEffect::textureAccess(unsigned int index) const {
+ if (0 == index)
+ return &fTextureAccess;
+
+ return NULL;
+}
diff --git a/src/gpu/effects/GrColorTableEffect.h b/src/gpu/effects/GrColorTableEffect.h
index ee7a630469..16d76ade7f 100644
--- a/src/gpu/effects/GrColorTableEffect.h
+++ b/src/gpu/effects/GrColorTableEffect.h
@@ -29,10 +29,14 @@ public:
virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE;
virtual bool isEqual(const GrCustomStage&) const SK_OVERRIDE;
+ virtual const GrTextureAccess* textureAccess(unsigned int index) const SK_OVERRIDE;
+
typedef GrGLColorTableEffect GLProgramStage;
private:
+ GrTextureAccess fTextureAccess;
+
typedef GrSingleTextureEffect INHERITED;
};
#endif
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 6af891b098..5cce800b51 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -33,7 +33,7 @@ public:
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
- static inline StageKey GenKey(const GrCustomStage&);
+ static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&);
private:
int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); }
@@ -125,8 +125,8 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
}
-GrGLProgramStage::StageKey GrGLConvolutionEffect::GenKey(
- const GrCustomStage& s) {
+GrGLProgramStage::StageKey GrGLConvolutionEffect::GenKey(const GrCustomStage& s,
+ const GrGLCaps& caps) {
return static_cast<const GrConvolutionEffect&>(s).radius();
}
@@ -185,4 +185,3 @@ bool GrConvolutionEffect::isEqual(const GrCustomStage& sBase) const {
this->direction() == s.direction() &&
0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float)));
}
-
diff --git a/src/gpu/effects/GrMorphologyEffect.cpp b/src/gpu/effects/GrMorphologyEffect.cpp
index f8b268dae6..be8485e554 100644
--- a/src/gpu/effects/GrMorphologyEffect.cpp
+++ b/src/gpu/effects/GrMorphologyEffect.cpp
@@ -26,7 +26,7 @@ public:
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- static inline StageKey GenKey(const GrCustomStage& s);
+ static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps& caps);
virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
@@ -98,8 +98,8 @@ void GrGLMorphologyEffect ::emitFS(GrGLShaderBuilder* builder,
code->appendf("\t\t%s = value%s;\n", outputColor, builder->fModulate.c_str());
}
-GrGLProgramStage::StageKey GrGLMorphologyEffect::GenKey(
- const GrCustomStage& s) {
+GrGLProgramStage::StageKey GrGLMorphologyEffect::GenKey(const GrCustomStage& s,
+ const GrGLCaps& caps) {
const GrMorphologyEffect& m = static_cast<const GrMorphologyEffect&>(s);
StageKey key = static_cast<StageKey>(m.radius());
key |= (m.type() << 8);
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index 350d9e6bc5..5f66e09805 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -26,7 +26,7 @@ public:
builder->emitDefaultFetch(outputColor, samplerName);
}
- static inline StageKey GenKey(const GrCustomStage&) { return 0; }
+ static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; }
private:
@@ -56,5 +56,3 @@ GrTexture* GrSingleTextureEffect::texture(unsigned int index) const {
const GrProgramStageFactory& GrSingleTextureEffect::getFactory() const {
return GrTProgramStageFactory<GrSingleTextureEffect>::getInstance();
}
-
-
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index 1bf0512da7..e76d0c916b 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -27,7 +27,7 @@ public:
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
- static inline StageKey GenKey(const GrCustomStage&) { return 0; }
+ static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&) { return 0; }
private:
GrGLUniformManager::UniformHandle fNameUni;
@@ -107,5 +107,3 @@ bool GrTextureDomainEffect::isEqual(const GrCustomStage& sBase) const {
const GrTextureDomainEffect& s = static_cast<const GrTextureDomainEffect&>(sBase);
return (INHERITED::isEqual(sBase) && this->fTextureDomain == s.fTextureDomain);
}
-
-