Index: src/gpu/gl/GrGLSL.h |
=================================================================== |
--- src/gpu/gl/GrGLSL.h (revision 8735) |
+++ src/gpu/gl/GrGLSL.h (working copy) |
@@ -9,6 +9,7 @@ |
#define GrGLSL_DEFINED |
#include "gl/GrGLInterface.h" |
+#include "GrColor.h" |
#include "GrTypesPriv.h" |
class GrGLShaderVar; |
@@ -103,10 +104,38 @@ |
bool GrGLSLSetupFSColorOuput(GrGLSLGeneration gen, |
const char* nameIfDeclared, |
GrGLShaderVar* var); |
+/** |
+ * Converts a GrSLType to a string containing the name of the equivalent GLSL type. |
+ */ |
+static const char* GrGLSLTypeString(GrSLType t) { |
+ switch (t) { |
+ case kVoid_GrSLType: |
+ return "void"; |
+ case kFloat_GrSLType: |
+ return "float"; |
+ case kVec2f_GrSLType: |
+ return "vec2"; |
+ case kVec3f_GrSLType: |
+ return "vec3"; |
+ case kVec4f_GrSLType: |
+ return "vec4"; |
+ case kMat33f_GrSLType: |
+ return "mat3"; |
+ case kMat44f_GrSLType: |
+ return "mat4"; |
+ case kSampler2D_GrSLType: |
+ return "sampler2D"; |
+ default: |
+ GrCrash("Unknown shader var type."); |
+ return ""; // suppress warning |
+ } |
+} |
-/** Convert a count of 1..n floats into the corresponding type enum, |
- e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
-GrSLType GrSLFloatVectorType(int count); |
+/** Return the type enum for a vector of floats of length n (1..4), |
+ e.g. 1 -> "float", 2 -> "vec2", ... */ |
+static inline const char* GrGLSLFloatVectorTypeString(int n) { |
+ return GrGLSLTypeString(GrSLFloatVectorType(n)); |
+} |
/** Return the GLSL swizzle operator for a homogenous component of a vector |
with the given number of coordinates, e.g. 2 -> ".y", 3 -> ".z" */ |
@@ -119,21 +148,60 @@ |
const char* GrGLSLVectorNonhomogCoords(GrSLType type); |
/** |
- * Produces a string that is the result of modulating two inputs. The inputs must be vec4 or |
- * float. The result is always a vec4. The inputs may be expressions, not just identifier names. |
- * Either can be NULL or "" in which case the default params control whether vec4(1,1,1,1) or |
- * vec4(0,0,0,0) is assumed. It is an error to pass kNone for default<i> if in<i> is NULL or "". |
- * Note that when if function determines that the result is a zeros or ones vec then any expression |
- * represented by in0 or in1 will not be emitted. The return value indicates whether a zeros, ones |
- * or neither was appended. |
+ * Produces a string that is the result of modulating two inputs. The inputs must be vecN or |
+ * float. The result is always a vecN. The inputs may be expressions, not just identifier names. |
+ * Either can be NULL or "" in which case the default params control whether a vector of ones or |
+ * zeros. It is an error to pass kNone for default<i> if in<i> is NULL or "". Note that when if |
+ * function determines that the result is a zeros or ones vec then any expression represented by |
+ * or in1 will not be emitted (side effects won't occur). The return value indicates whether a |
+ * known zeros or ones vector resulted. The output can be supressed when known vector is produced |
+ * by passing true for omitIfConstVec. |
*/ |
-GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, |
- const char* in0, |
- const char* in1, |
- GrSLConstantVec default0 = kOnes_GrSLConstantVec, |
- GrSLConstantVec default1 = kOnes_GrSLConstantVec); |
+template <int N> |
+GrSLConstantVec GrGLSLModulatef(SkString* outAppend, |
+ const char* in0, |
+ const char* in1, |
+ GrSLConstantVec default0 = kOnes_GrSLConstantVec, |
+ GrSLConstantVec default1 = kOnes_GrSLConstantVec, |
+ bool omitIfConstVec = false); |
/** |
+ * Produces a string that is the result of adding two inputs. The inputs must be vecN or |
+ * float. The result is always a vecN. The inputs may be expressions, not just identifier names. |
+ * Either can be NULL or "" in which case the default params control whether a vector of ones or |
+ * zeros. It is an error to pass kNone for default<i> if in<i> is NULL or "". Note that when if |
+ * function determines that the result is a zeros or ones vec then any expression represented by |
+ * or in1 will not be emitted (side effects won't occur). The return value indicates whether a |
+ * known zeros or ones vector resulted. The output can be supressed when known vector is produced |
+ * by passing true for omitIfConstVec. |
+ */ |
+template <int N> |
+GrSLConstantVec GrGLSLAddf(SkString* outAppend, |
+ const char* in0, |
+ const char* in1, |
+ GrSLConstantVec default0 = kZeros_GrSLConstantVec, |
+ GrSLConstantVec default1 = kZeros_GrSLConstantVec, |
+ bool omitIfConstVec = false); |
+ |
+/** |
+ * Produces a string that is the result of adding two inputs. The inputs must be vecN or |
+ * float. The result is always a vecN. The inputs may be expressions, not just identifier names. |
+ * Either can be NULL or "" in which case the default params control whether a vector of ones or |
+ * zeros. It is an error to pass kNone for default<i> if in<i> is NULL or "". Note that when if |
+ * function determines that the result is a zeros or ones vec then any expression represented by |
+ * or in1 will not be emitted (side effects won't occur). The return value indicates whether a |
+ * known zeros or ones vector resulted. The output can be supressed when known vector is produced |
+ * by passing true for omitIfConstVec. |
+ */ |
+template <int N> |
+GrSLConstantVec GrGLSLSubtractf(SkString* outAppend, |
+ const char* in0, |
+ const char* in1, |
+ GrSLConstantVec default0 = kZeros_GrSLConstantVec, |
+ GrSLConstantVec default1 = kZeros_GrSLConstantVec, |
+ bool omitIfConstVec = false); |
+ |
+/** |
* 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 appended (kOnes) or an |
* assignment of vec(0,0,0,0) will be appended (kZeros). The assignment is prepended by tabCnt tabs. |
@@ -148,18 +216,14 @@ |
GrSLConstantVec mulFactorDefault = kOnes_GrSLConstantVec); |
/** |
- * Produces a string that is the result of adding two inputs. The inputs must be vec4 or float. |
- * The result is always a vec4. The inputs may be expressions, not just identifier names. Either |
- * can be NULL or "" in which case if the default is kZeros then vec4(0,0,0,0) is assumed. It is an |
- * error to pass kOnes for either default or to pass kNone for default<i> if in<i> is NULL or "". |
- * Note that if the function determines that the result is a zeros vec any expression represented |
- * by in0 or in1 will not be emitted. The return value indicates whether a zeros vec was appended |
- * or not. |
- */ |
-GrSLConstantVec GrGLSLAdd4f(SkString* outAppend, |
- const char* in0, |
- const char* in1, |
- GrSLConstantVec default0 = kZeros_GrSLConstantVec, |
- GrSLConstantVec default1 = kZeros_GrSLConstantVec); |
+ * Given an expression that evaluates to a GLSL vec4, extract a component. If |
+ */ |
+GrSLConstantVec GrGLSLGetComponent4f(SkString* outAppend, |
+ const char* expr, |
+ GrColorComponentFlags component, |
+ GrSLConstantVec defaultExpr = kNone_GrSLConstantVec, |
+ bool omitIfConst = false); |
+#include "GrGLSL_impl.h" |
+ |
#endif |