Index: src/gpu/gl/GrGLSL_impl.h |
diff --git a/src/gpu/gl/GrGLSL_impl.h b/src/gpu/gl/GrGLSL_impl.h |
index bdd69cc76b37fc47d9747a1427d5043162ba36cf..5eb3c1b00a4a08d27414cbe4f285c85ce5c4ea3e 100644 |
--- a/src/gpu/gl/GrGLSL_impl.h |
+++ b/src/gpu/gl/GrGLSL_impl.h |
@@ -108,6 +108,66 @@ inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { |
return GrGLSLExpr1::Sub(in0, in1); |
} |
+inline GrGLSLExpr3 GrGLSLExpr3::VectorCast(const GrGLSLExpr1& expr) { |
+ return INHERITED::VectorCastImpl(expr); |
+} |
+ |
+inline GrGLSLExpr3 GrGLSLExpr3::VectorCast(const GrGLSLExpr3& expr) { |
+ return expr; |
+} |
+ |
+inline const char* GrGLSLExpr3::ZerosStr() { |
+ return "vec3(0)"; |
+} |
+ |
+inline const char* GrGLSLExpr3::OnesStr() { |
+ return "vec3(1)"; |
+} |
+ |
+inline const char* GrGLSLExpr3::CastStr() { |
+ return "vec3(%s)"; |
+} |
+ |
+inline const char* GrGLSLExpr3::CastIntStr() { |
+ return "vec3(%d)"; |
+} |
+ |
+inline GrGLSLExpr3 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Mul(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Add(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Sub(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) { |
+ return GrGLSLExpr3::Mul(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) { |
+ return GrGLSLExpr3::Add(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) { |
+ return GrGLSLExpr3::Sub(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Mul(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Add(in0, in1); |
+} |
+ |
+inline GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) { |
+ return GrGLSLExpr3::Sub(in0, in1); |
+} |
+ |
inline const char* GrGLSLExpr4::ZerosStr() { |
return "vec4(0)"; |
} |
@@ -132,10 +192,23 @@ inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) { |
return expr; |
} |
+inline GrGLSLExpr1 GrGLSLExpr4::x() const { return this->extractComponents<GrGLSLExpr1>("%s.x"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::y() const { return this->extractComponents<GrGLSLExpr1>("%s.y"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::z() const { return this->extractComponents<GrGLSLExpr1>("%s.z"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::w() const { return this->extractComponents<GrGLSLExpr1>("%s.w"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::r() const { return this->extractComponents<GrGLSLExpr1>("%s.r"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::g() const { return this->extractComponents<GrGLSLExpr1>("%s.g"); } |
+inline GrGLSLExpr1 GrGLSLExpr4::b() const { return this->extractComponents<GrGLSLExpr1>("%s.b"); } |
+ |
inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const { |
return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a"); |
} |
+inline GrGLSLExpr3 GrGLSLExpr4::xyz() const { return this->extractComponents<GrGLSLExpr3>("%s.xyz"); } |
+inline GrGLSLExpr3 GrGLSLExpr4::rgb() const { return this->extractComponents<GrGLSLExpr3>("%s.rgb"); } |
+ |
+ |
+ |
inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { |
return GrGLSLExpr4::Mul(in0, in1); |
} |
@@ -172,4 +245,65 @@ inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { |
return GrGLSLExpr4::Sub(in0, in1); |
} |
+namespace GrGLSL { |
+inline GrGLSLExpr1 max(const GrGLSLExpr1& a, float b) { |
+ if (a.isOnes()) { |
+ if (b > 1) { |
+ return GrGLSLExpr1(b); |
+ } |
+ return a; |
+ } else if (a.isZeros()) { |
+ if (b > 0) { |
+ return GrGLSLExpr1(b); |
+ } |
+ return a; |
+ } |
+ SkString r; |
+ r.printf("max(%s, %f)", a.c_str(), b); |
+ return GrGLSLExpr1(r); |
+} |
+ |
+template<typename T> |
+inline T min(const T& a, const T& b) { |
+ if (a.isOnes()) { |
+ if (b.isOnes()) { |
+ return a; |
+ } |
+ if (b.isZeros()) { |
+ return b; |
+ } |
+ } |
+ if (a.isZeros()) { |
+ if (b.isOnes()) { |
+ return a; |
+ } |
+ if (b.isZeros()) { |
+ return a; |
+ } |
+ } |
+ return T("min(%s, %s)", a.c_str(), b.c_str()); |
+} |
+ |
+template<typename T> |
+inline T max(const T& a, const T& b) { |
+ if (a.isOnes()) { |
+ if (b.isOnes()) { |
+ return a; |
+ } |
+ if (b.isZeros()) { |
+ return a; |
+ } |
+ } |
+ if (a.isZeros()) { |
+ if (b.isOnes()) { |
+ return b; |
+ } |
+ if (b.isZeros()) { |
+ return a; |
+ } |
+ } |
+ return T("max(%s, %s)", a.c_str(), b.c_str()); |
+} |
+} |
+ |
#endif |