tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrGLSL_DEFINED |
| 9 | #define GrGLSL_DEFINED |
| 10 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 11 | #include "GrTypesPriv.h" |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 13 | |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 14 | class GrGLSLCaps; |
| 15 | |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 16 | // Limited set of GLSL versions we build shaders for. Caller should round |
| 17 | // down the GLSL version to one of these enums. |
| 18 | enum GrGLSLGeneration { |
| 19 | /** |
bsalomon@google.com | 281c726 | 2012-10-23 14:31:30 +0000 | [diff] [blame] | 20 | * Desktop GLSL 1.10 and ES2 shading language (based on desktop GLSL 1.20) |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 21 | */ |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 22 | k110_GrGLSLGeneration, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Desktop GLSL 1.30 |
| 25 | */ |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 26 | k130_GrGLSLGeneration, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 27 | /** |
bsalomon@google.com | 281c726 | 2012-10-23 14:31:30 +0000 | [diff] [blame] | 28 | * Desktop GLSL 1.40 |
| 29 | */ |
| 30 | k140_GrGLSLGeneration, |
| 31 | /** |
| 32 | * Desktop GLSL 1.50 |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 33 | */ |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 34 | k150_GrGLSLGeneration, |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Desktop GLSL 3.30, and ES GLSL 3.00 |
| 37 | */ |
| 38 | k330_GrGLSLGeneration, |
| 39 | /** |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 40 | * Desktop GLSL 4.00 |
| 41 | */ |
| 42 | k400_GrGLSLGeneration, |
| 43 | /** |
Brian Salomon | d327e8c | 2016-11-15 13:26:08 -0500 | [diff] [blame] | 44 | * Desktop GLSL 4.20 |
| 45 | */ |
| 46 | k420_GrGLSLGeneration, |
| 47 | /** |
rmistry | 63a9f84 | 2014-10-17 06:07:08 -0700 | [diff] [blame] | 48 | * ES GLSL 3.10 only TODO Make GLSLCap objects to make this more granular |
| 49 | */ |
| 50 | k310es_GrGLSLGeneration, |
cdalton | 33ad701 | 2016-02-22 07:55:44 -0800 | [diff] [blame] | 51 | /** |
| 52 | * ES GLSL 3.20 |
| 53 | */ |
| 54 | k320es_GrGLSLGeneration, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
bsalomon | bc50e5c | 2015-06-04 08:49:34 -0700 | [diff] [blame] | 57 | bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration); |
| 58 | |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 59 | /** |
egdaniel | cb7ba1e | 2015-10-26 08:38:25 -0700 | [diff] [blame] | 60 | * Adds a line of GLSL code to declare the default precision for float types. |
| 61 | */ |
| 62 | void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision, |
| 63 | const GrGLSLCaps& glslCaps, |
| 64 | SkString* out); |
| 65 | |
| 66 | /** |
cdalton | 1f50acf | 2016-04-11 11:30:50 -0700 | [diff] [blame] | 67 | * Converts a GrSLPrecision to its corresponding GLSL precision qualifier. |
| 68 | */ |
| 69 | static inline const char* GrGLSLPrecisionString(GrSLPrecision p) { |
| 70 | switch (p) { |
| 71 | case kLow_GrSLPrecision: |
| 72 | return "lowp"; |
| 73 | case kMedium_GrSLPrecision: |
| 74 | return "mediump"; |
| 75 | case kHigh_GrSLPrecision: |
| 76 | return "highp"; |
| 77 | default: |
| 78 | SkFAIL("Unexpected precision type."); |
| 79 | return ""; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 84 | * Converts a GrSLType to a string containing the name of the equivalent GLSL type. |
| 85 | */ |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 86 | static inline const char* GrGLSLTypeString(GrSLType t) { |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 87 | switch (t) { |
| 88 | case kVoid_GrSLType: |
| 89 | return "void"; |
| 90 | case kFloat_GrSLType: |
| 91 | return "float"; |
| 92 | case kVec2f_GrSLType: |
| 93 | return "vec2"; |
| 94 | case kVec3f_GrSLType: |
| 95 | return "vec3"; |
| 96 | case kVec4f_GrSLType: |
| 97 | return "vec4"; |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 98 | case kMat22f_GrSLType: |
| 99 | return "mat2"; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 100 | case kMat33f_GrSLType: |
| 101 | return "mat3"; |
| 102 | case kMat44f_GrSLType: |
| 103 | return "mat4"; |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 104 | case kTexture2DSampler_GrSLType: |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 105 | return "sampler2D"; |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 106 | case kITexture2DSampler_GrSLType: |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 107 | return "isampler2D"; |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 108 | case kTextureExternalSampler_GrSLType: |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 109 | return "samplerExternalOES"; |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 110 | case kTexture2DRectSampler_GrSLType: |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 111 | return "sampler2DRect"; |
csmartdalton | 2245803 | 2016-11-16 11:28:16 -0700 | [diff] [blame] | 112 | case kBufferSampler_GrSLType: |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 113 | return "samplerBuffer"; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 114 | case kBool_GrSLType: |
| 115 | return "bool"; |
| 116 | case kInt_GrSLType: |
| 117 | return "int"; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 118 | case kUint_GrSLType: |
| 119 | return "uint"; |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 120 | case kTexture2D_GrSLType: |
| 121 | return "texture2D"; |
| 122 | case kSampler_GrSLType: |
| 123 | return "sampler"; |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame^] | 124 | case kImageStorage2D_GrSLType: |
| 125 | return "image2D"; |
| 126 | case kIImageStorage2D_GrSLType: |
| 127 | return "iimage2D"; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 128 | } |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 129 | SkFAIL("Unknown shader var type."); |
| 130 | return ""; // suppress warning |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 131 | } |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 132 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 133 | /** A generic base-class representing a GLSL expression. |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 134 | * The instance can be a variable name, expression or vecN(0) or vecN(1). Does simple constant |
| 135 | * folding with help of 1 and 0. |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 136 | * |
| 137 | * Clients should not use this class, rather the specific instantiations defined |
| 138 | * later, for example GrGLSLExpr4. |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 139 | */ |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 140 | template <typename Self> |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 141 | class GrGLSLExpr { |
| 142 | public: |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 143 | bool isOnes() const { return kOnes_ExprType == fType; } |
| 144 | bool isZeros() const { return kZeros_ExprType == fType; } |
| 145 | |
| 146 | const char* c_str() const { |
| 147 | if (kZeros_ExprType == fType) { |
| 148 | return Self::ZerosStr(); |
| 149 | } else if (kOnes_ExprType == fType) { |
| 150 | return Self::OnesStr(); |
| 151 | } |
| 152 | SkASSERT(!fExpr.isEmpty()); // Empty expressions should not be used. |
| 153 | return fExpr.c_str(); |
| 154 | } |
| 155 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 156 | bool isValid() const { |
| 157 | return kFullExpr_ExprType != fType || !fExpr.isEmpty(); |
| 158 | } |
| 159 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 160 | protected: |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 161 | /** Constructs an invalid expression. |
| 162 | * Useful only as a return value from functions that never actually return |
| 163 | * this and instances that will be assigned to later. */ |
| 164 | GrGLSLExpr() |
| 165 | : fType(kFullExpr_ExprType) { |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 166 | // The only constructor that is allowed to build an empty expression. |
| 167 | SkASSERT(!this->isValid()); |
| 168 | } |
| 169 | |
| 170 | /** Constructs an expression with all components as value v */ |
| 171 | explicit GrGLSLExpr(int v) { |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 172 | if (v == 0) { |
| 173 | fType = kZeros_ExprType; |
| 174 | } else if (v == 1) { |
| 175 | fType = kOnes_ExprType; |
| 176 | } else { |
| 177 | fType = kFullExpr_ExprType; |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 178 | fExpr.appendf(Self::CastIntStr(), v); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
| 182 | /** Constructs an expression from a string. |
| 183 | * Argument expr is a simple expression or a parenthesized expression. */ |
| 184 | // TODO: make explicit once effects input Exprs. |
| 185 | GrGLSLExpr(const char expr[]) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 186 | if (nullptr == expr) { // TODO: remove this once effects input Exprs. |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 187 | fType = kOnes_ExprType; |
| 188 | } else { |
| 189 | fType = kFullExpr_ExprType; |
| 190 | fExpr = expr; |
| 191 | } |
| 192 | SkASSERT(this->isValid()); |
| 193 | } |
| 194 | |
| 195 | /** Constructs an expression from a string. |
| 196 | * Argument expr is a simple expression or a parenthesized expression. */ |
| 197 | // TODO: make explicit once effects input Exprs. |
| 198 | GrGLSLExpr(const SkString& expr) { |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 199 | if (expr.isEmpty()) { // TODO: remove this once effects input Exprs. |
| 200 | fType = kOnes_ExprType; |
| 201 | } else { |
| 202 | fType = kFullExpr_ExprType; |
| 203 | fExpr = expr; |
| 204 | } |
| 205 | SkASSERT(this->isValid()); |
| 206 | } |
| 207 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 208 | /** Constructs an expression from a string with one substitution. */ |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 209 | GrGLSLExpr(const char format[], const char in0[]) |
| 210 | : fType(kFullExpr_ExprType) { |
| 211 | fExpr.appendf(format, in0); |
| 212 | } |
| 213 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 214 | /** Constructs an expression from a string with two substitutions. */ |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 215 | GrGLSLExpr(const char format[], const char in0[], const char in1[]) |
| 216 | : fType(kFullExpr_ExprType) { |
| 217 | fExpr.appendf(format, in0, in1); |
| 218 | } |
| 219 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 220 | /** Returns expression casted to another type. |
| 221 | * Generic implementation that is called for non-trivial cases of casts. */ |
| 222 | template <typename T> |
| 223 | static Self VectorCastImpl(const T& other); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 224 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 225 | /** Returns a GLSL multiplication: component-wise or component-by-scalar. |
| 226 | * The multiplication will be component-wise or multiply each component by a scalar. |
| 227 | * |
| 228 | * The returned expression will compute the value of: |
| 229 | * vecN(in0.x * in1.x, ...) if dim(T0) == dim(T1) (component-wise) |
| 230 | * vecN(in0.x * in1, ...) if dim(T1) == 1 (vector by scalar) |
| 231 | * vecN(in0 * in1.x, ...) if dim(T0) == 1 (scalar by vector) |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 232 | */ |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 233 | template <typename T0, typename T1> |
| 234 | static Self Mul(T0 in0, T1 in1); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 235 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 236 | /** Returns a GLSL addition: component-wise or add a scalar to each component. |
| 237 | * Return value computes: |
| 238 | * vecN(in0.x + in1.x, ...) or vecN(in0.x + in1, ...) or vecN(in0 + in1.x, ...). |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 239 | */ |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 240 | template <typename T0, typename T1> |
| 241 | static Self Add(T0 in0, T1 in1); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 242 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 243 | /** Returns a GLSL subtraction: component-wise or subtract compoments by a scalar. |
| 244 | * Return value computes |
| 245 | * vecN(in0.x - in1.x, ...) or vecN(in0.x - in1, ...) or vecN(in0 - in1.x, ...). |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 246 | */ |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 247 | template <typename T0, typename T1> |
| 248 | static Self Sub(T0 in0, T1 in1); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 249 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 250 | /** Returns expression that accesses component(s) of the expression. |
| 251 | * format should be the form "%s.x" where 'x' is the component(s) to access. |
| 252 | * Caller is responsible for making sure the amount of components in the |
| 253 | * format string is equal to dim(T). |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 254 | */ |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 255 | template <typename T> |
| 256 | T extractComponents(const char format[]) const; |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 257 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 258 | private: |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 259 | enum ExprType { |
| 260 | kZeros_ExprType, |
| 261 | kOnes_ExprType, |
| 262 | kFullExpr_ExprType, |
| 263 | }; |
| 264 | ExprType fType; |
| 265 | SkString fExpr; |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 268 | class GrGLSLExpr1; |
| 269 | class GrGLSLExpr4; |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 270 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 271 | /** Class representing a float GLSL expression. */ |
| 272 | class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> { |
| 273 | public: |
| 274 | GrGLSLExpr1() |
| 275 | : INHERITED() { |
| 276 | } |
| 277 | explicit GrGLSLExpr1(int v) |
| 278 | : INHERITED(v) { |
| 279 | } |
| 280 | GrGLSLExpr1(const char* expr) |
| 281 | : INHERITED(expr) { |
| 282 | } |
| 283 | GrGLSLExpr1(const SkString& expr) |
| 284 | : INHERITED(expr) { |
| 285 | } |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 286 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 287 | static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr); |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 288 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 289 | private: |
| 290 | GrGLSLExpr1(const char format[], const char in0[]) |
| 291 | : INHERITED(format, in0) { |
| 292 | } |
| 293 | GrGLSLExpr1(const char format[], const char in0[], const char in1[]) |
| 294 | : INHERITED(format, in0, in1) { |
| 295 | } |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 296 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 297 | static const char* ZerosStr(); |
| 298 | static const char* OnesStr(); |
| 299 | static const char* CastStr(); |
| 300 | static const char* CastIntStr(); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 302 | friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); |
| 303 | friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); |
| 304 | friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 305 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 306 | friend class GrGLSLExpr<GrGLSLExpr1>; |
| 307 | friend class GrGLSLExpr<GrGLSLExpr4>; |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 308 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 309 | typedef GrGLSLExpr<GrGLSLExpr1> INHERITED; |
| 310 | }; |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 311 | |
commit-bot@chromium.org | a34995e | 2013-10-23 05:42:03 +0000 | [diff] [blame] | 312 | /** Class representing a float vector (vec4) GLSL expression. */ |
| 313 | class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> { |
| 314 | public: |
| 315 | GrGLSLExpr4() |
| 316 | : INHERITED() { |
| 317 | } |
| 318 | explicit GrGLSLExpr4(int v) |
| 319 | : INHERITED(v) { |
| 320 | } |
| 321 | GrGLSLExpr4(const char* expr) |
| 322 | : INHERITED(expr) { |
| 323 | } |
| 324 | GrGLSLExpr4(const SkString& expr) |
| 325 | : INHERITED(expr) { |
| 326 | } |
| 327 | |
| 328 | typedef GrGLSLExpr1 AExpr; |
| 329 | AExpr a() const; |
| 330 | |
| 331 | /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */ |
| 332 | static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr); |
| 333 | static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr); |
| 334 | |
| 335 | private: |
| 336 | GrGLSLExpr4(const char format[], const char in0[]) |
| 337 | : INHERITED(format, in0) { |
| 338 | } |
| 339 | GrGLSLExpr4(const char format[], const char in0[], const char in1[]) |
| 340 | : INHERITED(format, in0, in1) { |
| 341 | } |
| 342 | |
| 343 | static const char* ZerosStr(); |
| 344 | static const char* OnesStr(); |
| 345 | static const char* CastStr(); |
| 346 | static const char* CastIntStr(); |
| 347 | |
| 348 | // The vector-by-scalar and scalar-by-vector binary operations. |
| 349 | friend GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); |
| 350 | friend GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); |
| 351 | friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); |
| 352 | friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); |
| 353 | friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); |
| 354 | friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); |
| 355 | |
| 356 | // The vector-by-vector, i.e. component-wise, binary operations. |
| 357 | friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); |
| 358 | friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); |
| 359 | friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); |
| 360 | |
| 361 | friend class GrGLSLExpr<GrGLSLExpr4>; |
| 362 | |
| 363 | typedef GrGLSLExpr<GrGLSLExpr4> INHERITED; |
| 364 | }; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 365 | |
| 366 | /** |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 367 | * Does an inplace mul, *=, of vec4VarName by mulFactor. |
egdaniel | 089f8de | 2014-10-09 10:34:58 -0700 | [diff] [blame] | 368 | * A semicolon is added after the assignment. |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 369 | */ |
egdaniel | 089f8de | 2014-10-09 10:34:58 -0700 | [diff] [blame] | 370 | void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor); |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 371 | |
| 372 | #include "GrGLSL_impl.h" |
bsalomon@google.com | 4af0af6 | 2012-08-29 12:59:57 +0000 | [diff] [blame] | 373 | |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 374 | #endif |