Index: src/gpu/gl/GrGLSL.cpp |
=================================================================== |
--- src/gpu/gl/GrGLSL.cpp (revision 8735) |
+++ src/gpu/gl/GrGLSL.cpp (working copy) |
@@ -87,76 +87,28 @@ |
return GrGLSLVectorNonhomogCoords(GrSLTypeToVecLength(type)); |
} |
-GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, |
- const char* in0, |
- const char* in1, |
- GrSLConstantVec default0, |
- GrSLConstantVec default1) { |
- GrAssert(NULL != outAppend); |
- |
- bool has0 = NULL != in0 && '\0' != *in0; |
- bool has1 = NULL != in1 && '\0' != *in1; |
- |
- GrAssert(has0 || kNone_GrSLConstantVec != default0); |
- GrAssert(has1 || kNone_GrSLConstantVec != default1); |
- |
- if (!has0 && !has1) { |
- GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0); |
- GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1); |
- if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == default1) { |
- outAppend->append(GrGLSLZerosVecf(4)); |
- return kZeros_GrSLConstantVec; |
- } else { |
- // both inputs are ones vectors |
- outAppend->append(GrGLSLOnesVecf(4)); |
- return kOnes_GrSLConstantVec; |
+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; |
} |
- } else if (!has0) { |
- GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec == default0); |
- if (kZeros_GrSLConstantVec == default0) { |
- outAppend->append(GrGLSLZerosVecf(4)); |
- return kZeros_GrSLConstantVec; |
- } else { |
- outAppend->appendf("vec4(%s)", in1); |
- return kNone_GrSLConstantVec; |
- } |
- } else if (!has1) { |
- GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec == default1); |
- if (kZeros_GrSLConstantVec == default1) { |
- outAppend->append(GrGLSLZerosVecf(4)); |
- return kZeros_GrSLConstantVec; |
- } else { |
- outAppend->appendf("vec4(%s)", in0); |
- return kNone_GrSLConstantVec; |
- } |
- } else { |
- outAppend->appendf("vec4(%s * %s)", in0, in1); |
- return kNone_GrSLConstantVec; |
} |
} |
-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; |
@@ -172,31 +124,24 @@ |
return kNone_GrSLConstantVec; |
} |
-GrSLConstantVec GrGLSLAdd4f(SkString* outAppend, |
- const char* in0, |
- const char* in1, |
- GrSLConstantVec default0, |
- GrSLConstantVec default1) { |
- GrAssert(NULL != outAppend); |
- |
- bool has0 = NULL != in0 && '\0' != *in0; |
- bool has1 = NULL != in1 && '\0' != *in1; |
- |
- if (!has0 && !has1) { |
- GrAssert(kZeros_GrSLConstantVec == default0); |
- GrAssert(kZeros_GrSLConstantVec == default1); |
- outAppend->append(GrGLSLZerosVecf(4)); |
- return kZeros_GrSLConstantVec; |
- } else if (!has0) { |
- GrAssert(kZeros_GrSLConstantVec == default0); |
- outAppend->appendf("vec4(%s)", in1); |
- return kNone_GrSLConstantVec; |
- } else if (!has1) { |
- GrAssert(kZeros_GrSLConstantVec == default1); |
- outAppend->appendf("vec4(%s)", in0); |
- return kNone_GrSLConstantVec; |
+GrSLConstantVec GrGLSLGetComponent4f(SkString* outAppend, |
+ const char* expr, |
+ GrColorComponentFlags component, |
+ GrSLConstantVec defaultExpr, |
+ bool omitIfConst) { |
+ if (NULL == expr || '\0' == *expr) { |
+ GrAssert(defaultExpr != kNone_GrSLConstantVec); |
+ if (!omitIfConst) { |
+ if (kOnes_GrSLConstantVec == defaultExpr) { |
+ outAppend->append("1.0"); |
+ } else { |
+ GrAssert(kZeros_GrSLConstantVec == defaultExpr); |
+ outAppend->append("0.0"); |
+ } |
+ } |
+ return defaultExpr; |
} else { |
- outAppend->appendf("(vec4(%s) + vec4(%s))", in0, in1); |
+ outAppend->appendf("(%s).%c", expr, GrColorComponentFlagToChar(component)); |
return kNone_GrSLConstantVec; |
} |
} |