| Index: src/gpu/gl/GrGLSL.h
|
| diff --git a/src/gpu/gl/GrGLSL.h b/src/gpu/gl/GrGLSL.h
|
| index 8c5da51bde097386f73da9a8df1f0053755459fe..e63d1e9e5c3a35b0604b3560f0e38dc989ccaec6 100644
|
| --- a/src/gpu/gl/GrGLSL.h
|
| +++ b/src/gpu/gl/GrGLSL.h
|
| @@ -123,28 +123,18 @@ protected:
|
|
|
| /** Constructs an expression from a string.
|
| * Argument expr is a simple expression or a parenthesized expression. */
|
| - // TODO: make explicit once effects input Exprs.
|
| - GrGLSLExpr(const char expr[]) {
|
| - if (NULL == expr) { // TODO: remove this once effects input Exprs.
|
| - fType = kOnes_ExprType;
|
| - } else {
|
| - fType = kFullExpr_ExprType;
|
| - fExpr = expr;
|
| - }
|
| - SkASSERT(this->isValid());
|
| + explicit GrGLSLExpr(const char expr[]) {
|
| + fType = kFullExpr_ExprType;
|
| + fExpr = expr;
|
| + SkASSERT(NULL != expr);
|
| }
|
|
|
| /** Constructs an expression from a string.
|
| * Argument expr is a simple expression or a parenthesized expression. */
|
| - // TODO: make explicit once effects input Exprs.
|
| - GrGLSLExpr(const SkString& expr) {
|
| - if (expr.isEmpty()) { // TODO: remove this once effects input Exprs.
|
| - fType = kOnes_ExprType;
|
| - } else {
|
| - fType = kFullExpr_ExprType;
|
| - fExpr = expr;
|
| - }
|
| - SkASSERT(this->isValid());
|
| + explicit GrGLSLExpr(const SkString& expr) {
|
| + fType = kFullExpr_ExprType;
|
| + fExpr = expr;
|
| + SkASSERT(!expr.isEmpty());
|
| }
|
|
|
| /** Constructs an expression from a string with one substitution. */
|
| @@ -212,8 +202,19 @@ private:
|
| };
|
|
|
| class GrGLSLExpr1;
|
| +class GrGLSLExpr3;
|
| class GrGLSLExpr4;
|
|
|
| +namespace GrGLSL {
|
| +GrGLSLExpr1 max(const GrGLSLExpr1& a, float b);
|
| +
|
| +template<typename T>
|
| +T min(const T& a, const T& b);
|
| +
|
| +template<typename T>
|
| +T max(const T& a, const T& b);
|
| +}
|
| +
|
| /** Class representing a float GLSL expression. */
|
| class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> {
|
| public:
|
| @@ -223,10 +224,10 @@ public:
|
| explicit GrGLSLExpr1(int v)
|
| : INHERITED(v) {
|
| }
|
| - GrGLSLExpr1(const char* expr)
|
| + explicit GrGLSLExpr1(const char* expr)
|
| : INHERITED(expr) {
|
| }
|
| - GrGLSLExpr1(const SkString& expr)
|
| + explicit GrGLSLExpr1(const SkString& expr)
|
| : INHERITED(expr) {
|
| }
|
|
|
| @@ -249,12 +250,72 @@ private:
|
| friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
|
| friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
|
|
|
| + template<typename T> friend T GrGLSL::min(const T& a, const T& b);
|
| + template<typename T> friend T GrGLSL::max(const T& a, const T& b);
|
| +
|
| friend class GrGLSLExpr<GrGLSLExpr1>;
|
| + friend class GrGLSLExpr<GrGLSLExpr3>;
|
| friend class GrGLSLExpr<GrGLSLExpr4>;
|
| -
|
| typedef GrGLSLExpr<GrGLSLExpr1> INHERITED;
|
| };
|
|
|
| +class GrGLSLExpr3 : public GrGLSLExpr<GrGLSLExpr3> {
|
| +public:
|
| + GrGLSLExpr3()
|
| + : INHERITED() {
|
| + }
|
| + explicit GrGLSLExpr3(int v)
|
| + : INHERITED(v) {
|
| + }
|
| + explicit GrGLSLExpr3(const char* expr)
|
| + : INHERITED(expr) {
|
| + }
|
| + explicit GrGLSLExpr3(const SkString& expr)
|
| + : INHERITED(expr) {
|
| + }
|
| +
|
| + /** GLSL vec3 cast / constructor, eg vec3(floatv) -> vec3(floatv, floatv, floatv) */
|
| + static GrGLSLExpr3 VectorCast(const GrGLSLExpr1& expr);
|
| + static GrGLSLExpr3 VectorCast(const GrGLSLExpr3& expr);
|
| +
|
| + GrGLSLExpr1 x() const;
|
| + GrGLSLExpr1 y() const;
|
| + GrGLSLExpr1 z() const;
|
| + GrGLSLExpr1 r() const;
|
| + GrGLSLExpr1 g() const;
|
| + GrGLSLExpr1 b() const;
|
| +
|
| +private:
|
| + GrGLSLExpr3(const char format[], const char in0[]) : INHERITED(format, in0) { }
|
| + GrGLSLExpr3(const char format[], const char in0[], const char in1[]): INHERITED(format, in0, in1) { }
|
| +
|
| + static const char* ZerosStr();
|
| + static const char* OnesStr();
|
| + static const char* CastStr();
|
| + static const char* CastIntStr();
|
| +
|
| + // The vector-by-scalar and scalar-by-vector binary operations.
|
| + friend GrGLSLExpr3 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
|
| + friend GrGLSLExpr3 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
|
| + friend GrGLSLExpr3 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
|
| + friend GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
|
| + friend GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
|
| + friend GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
|
| +
|
| + // The vector-by-vector, i.e. component-wise, binary operations.
|
| + friend GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
|
| + friend GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
|
| + friend GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
|
| +
|
| + template<typename T> friend T GrGLSL::min(const T& a, const T& b);
|
| + template<typename T> friend T GrGLSL::max(const T& a, const T& b);
|
| +
|
| + friend class GrGLSLExpr<GrGLSLExpr3>;
|
| + friend class GrGLSLExpr<GrGLSLExpr4>;
|
| +
|
| + typedef GrGLSLExpr<GrGLSLExpr3> INHERITED;
|
| +};
|
| +
|
| /** Class representing a float vector (vec4) GLSL expression. */
|
| class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> {
|
| public:
|
| @@ -264,16 +325,26 @@ public:
|
| explicit GrGLSLExpr4(int v)
|
| : INHERITED(v) {
|
| }
|
| - GrGLSLExpr4(const char* expr)
|
| + explicit GrGLSLExpr4(const char* expr)
|
| : INHERITED(expr) {
|
| }
|
| - GrGLSLExpr4(const SkString& expr)
|
| + explicit GrGLSLExpr4(const SkString& expr)
|
| : INHERITED(expr) {
|
| }
|
|
|
| + GrGLSLExpr1 x() const;
|
| + GrGLSLExpr1 y() const;
|
| + GrGLSLExpr1 z() const;
|
| + GrGLSLExpr1 w() const;
|
| + GrGLSLExpr1 r() const;
|
| + GrGLSLExpr1 g() const;
|
| + GrGLSLExpr1 b() const;
|
| typedef GrGLSLExpr1 AExpr;
|
| AExpr a() const;
|
|
|
| + GrGLSLExpr3 xyz() const;
|
| + GrGLSLExpr3 rgb() const;
|
| +
|
| /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */
|
| static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr);
|
| static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr);
|
| @@ -304,11 +375,14 @@ private:
|
| friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
|
| friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
|
|
|
| - friend class GrGLSLExpr<GrGLSLExpr4>;
|
| + template<typename T> friend T GrGLSL::min(const T& a, const T& b);
|
| + template<typename T> friend T GrGLSL::max(const T& a, const T& b);
|
|
|
| + friend class GrGLSLExpr<GrGLSLExpr4>;
|
| typedef GrGLSLExpr<GrGLSLExpr4> INHERITED;
|
| };
|
|
|
| +
|
| /**
|
| * Does an inplace mul, *=, of vec4VarName by mulFactor.
|
| * A semicolon and newline are added after the assignment.
|
|
|