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