diff options
author | 2012-08-29 12:59:57 +0000 | |
---|---|---|
committer | 2012-08-29 12:59:57 +0000 | |
commit | 4af0af612f8cfb6951feb10ffe3091821866bd44 (patch) | |
tree | 53682cd4bf4f3d0db27768493da80577b497d310 /src/gpu/gl/GrGLSL.h | |
parent | 1fcc1b80994f7bfa60bbc74e924484da09b47e3b (diff) |
Add helpers to add/modulate glsl vec4s.
Review URL: https://codereview.appspot.com/6497046/
git-svn-id: http://skia.googlecode.com/svn/trunk@5332 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl/GrGLSL.h')
-rw-r--r-- | src/gpu/gl/GrGLSL.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h index f69385f239..6595608615 100644 --- a/src/gpu/gl/GrGLSL.h +++ b/src/gpu/gl/GrGLSL.h @@ -11,6 +11,7 @@ #include "gl/GrGLInterface.h" class GrGLShaderVar; +class SkString; // Limited set of GLSL versions we build shaders for. Caller should round // down the GLSL version to one of these enums. @@ -45,6 +46,12 @@ enum GrSLType { kSampler2D_GrSLType }; +enum GrSLConstantVec { + kZeros_GrSLConstantVec, + kOnes_GrSLConstantVec, + kNone_GrSLConstantVec, +}; + namespace { inline int GrSLTypeToVecLength(GrSLType type) { static const int kVecLengths[] = { @@ -60,6 +67,20 @@ inline int GrSLTypeToVecLength(GrSLType type) { GrAssert((size_t) type < GR_ARRAY_COUNT(kVecLengths)); return kVecLengths[type]; } + +const char* GrGLSLOnesVecf(int count) { + static const char* kONESVEC[] = {"ERROR", "1.0", "vec2(1,1)", + "vec3(1,1,1)", "vec4(1,1,1,1)"}; + GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(kONESVEC)); + return kONESVEC[count]; +} + +const char* GrGLSLZerosVecf(int count) { + static const char* kZEROSVEC[] = {"ERROR", "0.0", "vec2(0,0)", + "vec3(0,0,0)", "vec4(0,0,0,0)"}; + GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(kZEROSVEC)); + return kZEROSVEC[count]; +} } /** @@ -107,4 +128,36 @@ const char* GrGLSLVectorHomogCoord(GrSLType type); with the given number of coordinates, e.g. 2 -> ".x", 3 -> ".xy" */ const char* GrGLSLVectorNonhomogCoords(int count); 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 appeneded. + */ +GrSLConstantVec GrGLSLModulate4f(SkString* outAppend, + const char* in0, + const char* in1, + GrSLConstantVec default0 = kOnes_GrSLConstantVec, + GrSLConstantVec default1 = 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); + #endif |