aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 17:54:14 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 17:54:14 +0000
commitb41b2bc29c0411052f9f45855a98be370d586438 (patch)
treeeaa731fed5fb2f3ae8e7bb703d23eb51f6e7449f /src/gpu/gl
parent1ea01bf4cedc3067e980367e3f189a6d8642d6ce (diff)
Remove fModulate from GrGLShaderBuilder
Review URL: https://codereview.appspot.com/6495051/ git-svn-id: http://skia.googlecode.com/svn/trunk@5350 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLProgram.cpp1
-rw-r--r--src/gpu/gl/GrGLSL.cpp38
-rw-r--r--src/gpu/gl/GrGLSL.h13
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp34
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.h27
5 files changed, 80 insertions, 33 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 50e839b77c..ff29bd4028 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -987,7 +987,6 @@ void GrGLProgram::genStageCode(int stageNum,
builder->fVSCode.appendf("\t}\n");
builder->computeSwizzle(desc.fInConfigFlags);
- builder->computeModulate(fsInColor);
// Enclose custom code in a block to avoid namespace conflicts
builder->fFSCode.appendf("\t{ // stage %d %s \n",
diff --git a/src/gpu/gl/GrGLSL.cpp b/src/gpu/gl/GrGLSL.cpp
index c995a34652..079c08232f 100644
--- a/src/gpu/gl/GrGLSL.cpp
+++ b/src/gpu/gl/GrGLSL.cpp
@@ -115,6 +115,7 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend,
outAppend->append(GrGLSLZerosVecf(4));
return kZeros_GrSLConstantVec;
} else {
+ // both inputs are ones vectors
outAppend->append(GrGLSLOnesVecf(4));
return kOnes_GrSLConstantVec;
}
@@ -142,6 +143,43 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend,
}
}
+namespace {
+void append_tabs(SkString* outAppend, int tabCnt) {
+ static const char kTabs[] = "\t\t\t\t\t\t\t\t";
+ while (tabCnt) {
+ int cnt = GrMin((int)GR_ARRAY_COUNT(kTabs), tabCnt);
+ outAppend->append(kTabs, cnt);
+ tabCnt -= cnt;
+ }
+}
+}
+
+GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend,
+ int tabCnt,
+ const char* vec4VarName,
+ const char* mulFactor,
+ GrSLConstantVec mulFactorDefault) {
+ bool haveFactor = NULL != mulFactor && '\0' != *mulFactor;
+
+ GrAssert(NULL != outAppend);
+ GrAssert(NULL != vec4VarName);
+ GrAssert(kNone_GrSLConstantVec != mulFactorDefault || haveFactor);
+
+ if (!haveFactor) {
+ if (kOnes_GrSLConstantVec == mulFactorDefault) {
+ return kNone_GrSLConstantVec;
+ } else {
+ GrAssert(kZeros_GrSLConstantVec == mulFactorDefault);
+ append_tabs(outAppend, tabCnt);
+ outAppend->appendf("%s = vec4(0, 0, 0, 0);\n", vec4VarName);
+ return kZeros_GrSLConstantVec;
+ }
+ }
+ append_tabs(outAppend, tabCnt);
+ outAppend->appendf("%s *= %s;\n", vec4VarName, mulFactor);
+ return kNone_GrSLConstantVec;
+}
+
GrSLConstantVec GrGLSLAdd4f(SkString* outAppend,
const char* in0,
const char* in1,
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
index 6595608615..cbff273382 100644
--- a/src/gpu/gl/GrGLSL.h
+++ b/src/gpu/gl/GrGLSL.h
@@ -144,6 +144,19 @@ GrSLConstantVec GrGLSLModulate4f(SkString* outAppend,
GrSLConstantVec default0 = kOnes_GrSLConstantVec,
GrSLConstantVec default1 = kOnes_GrSLConstantVec);
+/**
+ * Does an inplace mul, *=, of vec4VarName by mulFactor. If mulFactorDefault is not kNone then
+ * mulFactor may be either "" or NULL. In this case either nothing will be appened (kOnes) or an
+ * assignment of vec(0,0,0,0) will be appended (kZeros). The assignment is prepended by tabCnt tabs.
+ * A semicolon and newline are added after the assignment. (TODO: Remove tabCnt when we auto-insert
+ * tabs to custom stage-generated lines.) If a zeros vec is assigned then the return value is
+ * kZeros, otherwise kNone.
+ */
+GrSLConstantVec GrGLSLMulVarBy4f(SkString* outAppend,
+ int tabCnt,
+ const char* vec4VarName,
+ const char* mulFactor,
+ GrSLConstantVec mulFactorDefault = kOnes_GrSLConstantVec);
/**
* Produces a string that is the result of adding two inputs. The inputs must be vec4 or float.
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index c0614684be..e899e416c3 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -96,14 +96,6 @@ void GrGLShaderBuilder::computeSwizzle(uint32_t configFlags) {
}
}
-void GrGLShaderBuilder::computeModulate(const char* fsInColor) {
- if (NULL != fsInColor) {
- fModulate.printf(" * %s", fsInColor);
- } else {
- fModulate.reset();
- }
-}
-
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
// projective texturing and always give the stage 2D coords. This will be fixed when custom
@@ -130,23 +122,27 @@ void GrGLShaderBuilder::setupTextureAccess(const char* varyingFSName, GrSLType v
}
}
-void GrGLShaderBuilder::emitTextureLookup(const char* samplerName,
- const char* coordName,
- GrSLType varyingType) {
+void GrGLShaderBuilder::appendTextureLookup(SkString* out,
+ const char* samplerName,
+ const char* coordName,
+ GrSLType varyingType) const {
if (NULL == coordName) {
coordName = fDefaultTexCoordsName.c_str();
varyingType = kVec2f_GrSLType;
}
- fFSCode.appendf("%s(%s, %s)", sample_function_name(varyingType), samplerName, coordName);
+ out->appendf("%s(%s, %s)", sample_function_name(varyingType), samplerName, coordName);
}
-void GrGLShaderBuilder::emitTextureLookupAndModulate(const char* outColor,
- const char* samplerName,
- const char* coordName,
- GrSLType varyingType) {
- fFSCode.appendf("\t%s = ", outColor);
- this->emitTextureLookup(samplerName, coordName, varyingType);
- fFSCode.appendf("%s%s;\n", fSwizzle.c_str(), fModulate.c_str());
+void GrGLShaderBuilder::appendTextureLookupAndModulate(SkString* out,
+ const char* modulation,
+ const char* samplerName,
+ const char* coordName,
+ GrSLType varyingType) const {
+ GrAssert(NULL != out);
+ SkString lookup;
+ this->appendTextureLookup(&lookup, samplerName, coordName, varyingType);
+ GrGLSLModulate4f(out, modulation, lookup.c_str());
+ out->append(fSwizzle.c_str());
}
void GrGLShaderBuilder::emitCustomTextureLookup(const GrTextureAccess& textureAccess,
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index 66de5abdcc..bc108923f9 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -32,7 +32,6 @@ public:
GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&);
void computeSwizzle(uint32_t configFlags);
- void computeModulate(const char* fsInColor);
/** Determines whether we should use texture2D() or texture2Dproj(), and if an explicit divide
is required for the sample coordinates, creates the new variable and emits the code to
@@ -42,17 +41,20 @@ public:
/** texture2D(samplerName, coordName), with projection if necessary; if coordName is not
specified, uses fSampleCoords. coordType must either be Vec2f or Vec3f. The latter is
interpreted as projective texture coords. */
- void emitTextureLookup(const char* samplerName,
- const char* coordName = NULL,
- GrSLType coordType = kVec2f_GrSLType);
-
- /** sets outColor to results of texture lookup, with swizzle, and/or modulate as necessary. If
- coordName is NULL then it as if defaultTexCoordsName() was passed. coordType must be either
- kVec2f or kVec3f. */
- void emitTextureLookupAndModulate(const char* outColor,
- const char* samplerName,
- const char* coordName = NULL,
- GrSLType coordType = kVec2f_GrSLType);
+ void appendTextureLookup(SkString* out,
+ const char* samplerName,
+ const char* coordName = NULL,
+ GrSLType coordType = kVec2f_GrSLType) const;
+
+ /** appends a texture lookup, with swizzle as necessary. If coordName is NULL then it as if
+ defaultTexCoordsName() was passed. coordType must be either kVec2f or kVec3f. If modulateVar
+ is not NULL or "" then the texture lookup will be modulated by it. modulation must refer to
+ be expression that evaluates to a float or vec4. */
+ void appendTextureLookupAndModulate(SkString* out,
+ const char* modulation,
+ const char* samplerName,
+ const char* coordName = NULL,
+ GrSLType varyingType = kVec2f_GrSLType) const;
/** Gets the name of the default texture coords which are always kVec2f */
const char* defaultTexCoordsName() const { return fDefaultTexCoordsName.c_str(); }
@@ -171,7 +173,6 @@ public:
//@{
SkString fSwizzle;
- SkString fModulate;
//@}