junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "GrGLProgram.h" |
| 9 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 10 | #include "GrAllocator.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 11 | #include "GrCustomStage.h" |
| 12 | #include "GrGLProgramStage.h" |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 13 | #include "gl/GrGLShaderBuilder.h" |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 14 | #include "GrGLShaderVar.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 15 | #include "GrProgramStageFactory.h" |
tomhudson@google.com | 0c8d93a | 2011-07-01 17:08:26 +0000 | [diff] [blame] | 16 | #include "SkTrace.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 17 | #include "SkXfermode.h" |
| 18 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 19 | namespace { |
| 20 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 21 | enum { |
| 22 | /// Used to mark a StageUniLocation field that should be bound |
| 23 | /// to a uniform during getUniformLocationsAndInitCache(). |
| 24 | kUseUniform = 2000 |
| 25 | }; |
| 26 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 27 | } // namespace |
| 28 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 29 | #define PRINT_SHADERS 0 |
| 30 | |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 31 | typedef GrGLProgram::ProgramDesc::StageDesc StageDesc; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | 341767c | 2012-05-11 20:47:39 +0000 | [diff] [blame] | 33 | #define VIEW_MATRIX_NAME "uViewM" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 34 | |
| 35 | #define POS_ATTR_NAME "aPosition" |
| 36 | #define COL_ATTR_NAME "aColor" |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 37 | #define COV_ATTR_NAME "aCoverage" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 38 | #define EDGE_ATTR_NAME "aEdge" |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 39 | #define COL_UNI_NAME "uColor" |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 40 | #define COV_UNI_NAME "uCoverage" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 41 | #define COL_FILTER_UNI_NAME "uColorFilter" |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 42 | #define COL_MATRIX_UNI_NAME "uColorMatrix" |
| 43 | #define COL_MATRIX_VEC_UNI_NAME "uColorMatrixVec" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 44 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 45 | namespace { |
| 46 | inline void tex_attr_name(int coordIdx, GrStringBuilder* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 47 | *s = "aTexCoord"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 48 | s->appendS32(coordIdx); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 49 | } |
| 50 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 51 | inline const char* float_vector_type_str(int count) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 52 | return GrGLShaderVar::TypeString(GrSLFloatVectorType(count)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 53 | } |
| 54 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 55 | inline const char* vector_all_coords(int count) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 56 | static const char* ALL[] = {"ERROR", "", ".xy", ".xyz", ".xyzw"}; |
| 57 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ALL)); |
| 58 | return ALL[count]; |
| 59 | } |
| 60 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 61 | inline const char* all_ones_vec(int count) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 62 | static const char* ONESVEC[] = {"ERROR", "1.0", "vec2(1,1)", |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 63 | "vec3(1,1,1)", "vec4(1,1,1,1)"}; |
| 64 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ONESVEC)); |
| 65 | return ONESVEC[count]; |
| 66 | } |
| 67 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 68 | inline const char* all_zeros_vec(int count) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 69 | static const char* ZEROSVEC[] = {"ERROR", "0.0", "vec2(0,0)", |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 70 | "vec3(0,0,0)", "vec4(0,0,0,0)"}; |
| 71 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ZEROSVEC)); |
| 72 | return ZEROSVEC[count]; |
| 73 | } |
| 74 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 75 | inline const char* declared_color_output_name() { return "fsColorOut"; } |
| 76 | inline const char* dual_source_output_name() { return "dualSourceOut"; } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 77 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 78 | inline void tex_matrix_name(int stage, GrStringBuilder* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 79 | *s = "uTexM"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 80 | s->appendS32(stage); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 81 | } |
| 82 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 83 | inline void normalized_texel_size_name(int stage, GrStringBuilder* s) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 84 | *s = "uTexelSize"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 85 | s->appendS32(stage); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 86 | } |
| 87 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 88 | inline void sampler_name(int stage, GrStringBuilder* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 89 | *s = "uSampler"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 90 | s->appendS32(stage); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 91 | } |
| 92 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 93 | inline void radial2_param_name(int stage, GrStringBuilder* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 94 | *s = "uRadial2Params"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 95 | s->appendS32(stage); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 96 | } |
| 97 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 98 | inline void convolve_param_names(int stage, GrStringBuilder* k, GrStringBuilder* i) { |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 99 | *k = "uKernel"; |
| 100 | k->appendS32(stage); |
| 101 | *i = "uImageIncrement"; |
| 102 | i->appendS32(stage); |
| 103 | } |
| 104 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 105 | inline void image_increment_param_name(int stage, GrStringBuilder* i) { |
| 106 | *i = "uImageIncrement"; |
| 107 | i->appendS32(stage); |
| 108 | } |
| 109 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 110 | inline void tex_domain_name(int stage, GrStringBuilder* s) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 111 | *s = "uTexDom"; |
| 112 | s->appendS32(stage); |
| 113 | } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 114 | } |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 115 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 116 | GrGLProgram::GrGLProgram() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | GrGLProgram::~GrGLProgram() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 120 | } |
| 121 | |
tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 122 | void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 123 | GrBlendCoeff* dstCoeff) const { |
| 124 | switch (fProgramDesc.fDualSrcOutput) { |
| 125 | case ProgramDesc::kNone_DualSrcOutput: |
| 126 | break; |
| 127 | // the prog will write a coverage value to the secondary |
| 128 | // output and the dst is blended by one minus that value. |
| 129 | case ProgramDesc::kCoverage_DualSrcOutput: |
| 130 | case ProgramDesc::kCoverageISA_DualSrcOutput: |
| 131 | case ProgramDesc::kCoverageISC_DualSrcOutput: |
| 132 | *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_BlendCoeff; |
| 133 | break; |
| 134 | default: |
| 135 | GrCrash("Unexpected dual source blend output"); |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 140 | // assigns modulation of two vars to an output var |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 141 | // vars can be vec4s or floats (or one of each) |
| 142 | // result is always vec4 |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 143 | // if either var is "" then assign to the other var |
| 144 | // if both are "" then assign all ones |
| 145 | static inline void modulate_helper(const char* outputVar, |
| 146 | const char* var0, |
| 147 | const char* var1, |
| 148 | GrStringBuilder* code) { |
| 149 | GrAssert(NULL != outputVar); |
| 150 | GrAssert(NULL != var0); |
| 151 | GrAssert(NULL != var1); |
| 152 | GrAssert(NULL != code); |
| 153 | |
| 154 | bool has0 = '\0' != *var0; |
| 155 | bool has1 = '\0' != *var1; |
| 156 | |
| 157 | if (!has0 && !has1) { |
| 158 | code->appendf("\t%s = %s;\n", outputVar, all_ones_vec(4)); |
| 159 | } else if (!has0) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 160 | code->appendf("\t%s = vec4(%s);\n", outputVar, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 161 | } else if (!has1) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 162 | code->appendf("\t%s = vec4(%s);\n", outputVar, var0); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 163 | } else { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 164 | code->appendf("\t%s = vec4(%s * %s);\n", outputVar, var0, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | // assigns addition of two vars to an output var |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 169 | // vars can be vec4s or floats (or one of each) |
| 170 | // result is always vec4 |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 171 | // if either var is "" then assign to the other var |
| 172 | // if both are "" then assign all zeros |
| 173 | static inline void add_helper(const char* outputVar, |
| 174 | const char* var0, |
| 175 | const char* var1, |
| 176 | GrStringBuilder* code) { |
| 177 | GrAssert(NULL != outputVar); |
| 178 | GrAssert(NULL != var0); |
| 179 | GrAssert(NULL != var1); |
| 180 | GrAssert(NULL != code); |
| 181 | |
| 182 | bool has0 = '\0' != *var0; |
| 183 | bool has1 = '\0' != *var1; |
| 184 | |
| 185 | if (!has0 && !has1) { |
| 186 | code->appendf("\t%s = %s;\n", outputVar, all_zeros_vec(4)); |
| 187 | } else if (!has0) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 188 | code->appendf("\t%s = vec4(%s);\n", outputVar, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 189 | } else if (!has1) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 190 | code->appendf("\t%s = vec4(%s);\n", outputVar, var0); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 191 | } else { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 192 | code->appendf("\t%s = vec4(%s + %s);\n", outputVar, var0, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | // given two blend coeffecients determine whether the src |
| 197 | // and/or dst computation can be omitted. |
| 198 | static inline void needBlendInputs(SkXfermode::Coeff srcCoeff, |
| 199 | SkXfermode::Coeff dstCoeff, |
| 200 | bool* needSrcValue, |
| 201 | bool* needDstValue) { |
| 202 | if (SkXfermode::kZero_Coeff == srcCoeff) { |
| 203 | switch (dstCoeff) { |
| 204 | // these all read the src |
| 205 | case SkXfermode::kSC_Coeff: |
| 206 | case SkXfermode::kISC_Coeff: |
| 207 | case SkXfermode::kSA_Coeff: |
| 208 | case SkXfermode::kISA_Coeff: |
| 209 | *needSrcValue = true; |
| 210 | break; |
| 211 | default: |
| 212 | *needSrcValue = false; |
| 213 | break; |
| 214 | } |
| 215 | } else { |
| 216 | *needSrcValue = true; |
| 217 | } |
| 218 | if (SkXfermode::kZero_Coeff == dstCoeff) { |
| 219 | switch (srcCoeff) { |
| 220 | // these all read the dst |
| 221 | case SkXfermode::kDC_Coeff: |
| 222 | case SkXfermode::kIDC_Coeff: |
| 223 | case SkXfermode::kDA_Coeff: |
| 224 | case SkXfermode::kIDA_Coeff: |
| 225 | *needDstValue = true; |
| 226 | break; |
| 227 | default: |
| 228 | *needDstValue = false; |
| 229 | break; |
| 230 | } |
| 231 | } else { |
| 232 | *needDstValue = true; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 237 | * Create a blend_coeff * value string to be used in shader code. Sets empty |
| 238 | * string if result is trivially zero. |
| 239 | */ |
| 240 | static void blendTermString(GrStringBuilder* str, SkXfermode::Coeff coeff, |
| 241 | const char* src, const char* dst, |
| 242 | const char* value) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 243 | switch (coeff) { |
| 244 | case SkXfermode::kZero_Coeff: /** 0 */ |
| 245 | *str = ""; |
| 246 | break; |
| 247 | case SkXfermode::kOne_Coeff: /** 1 */ |
| 248 | *str = value; |
| 249 | break; |
| 250 | case SkXfermode::kSC_Coeff: |
| 251 | str->printf("(%s * %s)", src, value); |
| 252 | break; |
| 253 | case SkXfermode::kISC_Coeff: |
| 254 | str->printf("((%s - %s) * %s)", all_ones_vec(4), src, value); |
| 255 | break; |
| 256 | case SkXfermode::kDC_Coeff: |
| 257 | str->printf("(%s * %s)", dst, value); |
| 258 | break; |
| 259 | case SkXfermode::kIDC_Coeff: |
| 260 | str->printf("((%s - %s) * %s)", all_ones_vec(4), dst, value); |
| 261 | break; |
| 262 | case SkXfermode::kSA_Coeff: /** src alpha */ |
| 263 | str->printf("(%s.a * %s)", src, value); |
| 264 | break; |
| 265 | case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */ |
| 266 | str->printf("((1.0 - %s.a) * %s)", src, value); |
| 267 | break; |
| 268 | case SkXfermode::kDA_Coeff: /** dst alpha */ |
| 269 | str->printf("(%s.a * %s)", dst, value); |
| 270 | break; |
| 271 | case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */ |
| 272 | str->printf("((1.0 - %s.a) * %s)", dst, value); |
| 273 | break; |
| 274 | default: |
| 275 | GrCrash("Unexpected xfer coeff."); |
| 276 | break; |
| 277 | } |
| 278 | } |
| 279 | /** |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 280 | * Adds a line to the fragment shader code which modifies the color by |
| 281 | * the specified color filter. |
| 282 | */ |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 283 | static void addColorFilter(GrStringBuilder* fsCode, const char * outputVar, |
tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 284 | SkXfermode::Coeff uniformCoeff, |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 285 | SkXfermode::Coeff colorCoeff, |
| 286 | const char* inColor) { |
| 287 | GrStringBuilder colorStr, constStr; |
| 288 | blendTermString(&colorStr, colorCoeff, COL_FILTER_UNI_NAME, |
| 289 | inColor, inColor); |
| 290 | blendTermString(&constStr, uniformCoeff, COL_FILTER_UNI_NAME, |
| 291 | inColor, COL_FILTER_UNI_NAME); |
| 292 | |
| 293 | add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 294 | } |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 295 | /** |
| 296 | * Adds code to the fragment shader code which modifies the color by |
| 297 | * the specified color matrix. |
| 298 | */ |
| 299 | static void addColorMatrix(GrStringBuilder* fsCode, const char * outputVar, |
| 300 | const char* inColor) { |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 301 | fsCode->appendf("\t%s = %s * vec4(%s.rgb / %s.a, %s.a) + %s;\n", outputVar, COL_MATRIX_UNI_NAME, inColor, inColor, inColor, COL_MATRIX_VEC_UNI_NAME); |
| 302 | fsCode->appendf("\t%s.rgb *= %s.a;\n", outputVar, outputVar); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 303 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 304 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 305 | void GrGLProgram::genEdgeCoverage(const GrGLContextInfo& gl, |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 306 | GrVertexLayout layout, |
| 307 | CachedData* programData, |
| 308 | GrStringBuilder* coverageVar, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 309 | GrGLShaderBuilder* segments) const { |
bsalomon@google.com | 7ffe681 | 2012-05-11 17:32:43 +0000 | [diff] [blame] | 310 | if (layout & GrDrawTarget::kEdge_VertexLayoutBit) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 311 | const char *vsName, *fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 312 | segments->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName); |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 313 | segments->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 314 | GrGLShaderVar::kAttribute_TypeModifier, EDGE_ATTR_NAME); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 315 | segments->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName); |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 316 | switch (fProgramDesc.fVertexEdgeType) { |
| 317 | case GrDrawState::kHairLine_EdgeType: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 318 | segments->fFSCode.appendf("\tfloat edgeAlpha = abs(dot(vec3(gl_FragCoord.xy,1), %s.xyz));\n", fsName); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 319 | segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 320 | break; |
| 321 | case GrDrawState::kQuad_EdgeType: |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 322 | segments->fFSCode.append("\tfloat edgeAlpha;\n"); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 323 | // keep the derivative instructions outside the conditional |
| 324 | segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 325 | segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
| 326 | segments->fFSCode.appendf("\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsName, fsName); |
| 327 | // today we know z and w are in device space. We could use derivatives |
| 328 | segments->fFSCode.appendf("\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);\n", fsName, fsName); |
| 329 | segments->fFSCode.append ("\t} else {\n"); |
| 330 | segments->fFSCode.appendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" |
| 331 | "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n", |
| 332 | fsName, fsName); |
| 333 | segments->fFSCode.appendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 334 | segments->fFSCode.append("\t\tedgeAlpha = clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n" |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 335 | "\t}\n"); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 336 | if (kES2_GrGLBinding == gl.binding()) { |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 337 | segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); |
| 338 | } |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 339 | break; |
| 340 | case GrDrawState::kHairQuad_EdgeType: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 341 | segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 342 | segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 343 | segments->fFSCode.appendf("\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" |
| 344 | "\t 2.0*%s.x*duvdy.x - duvdy.y);\n", |
| 345 | fsName, fsName); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 346 | segments->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 347 | segments->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n"); |
| 348 | segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 349 | if (kES2_GrGLBinding == gl.binding()) { |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 350 | segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); |
| 351 | } |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 352 | break; |
| 353 | case GrDrawState::kCircle_EdgeType: |
| 354 | segments->fFSCode.append("\tfloat edgeAlpha;\n"); |
| 355 | segments->fFSCode.appendf("\tfloat d = distance(gl_FragCoord.xy, %s.xy);\n", fsName); |
| 356 | segments->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName); |
| 357 | segments->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : smoothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); |
| 358 | segments->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); |
| 359 | break; |
| 360 | default: |
| 361 | GrCrash("Unknown Edge Type!"); |
| 362 | break; |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 363 | } |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 364 | *coverageVar = "edgeAlpha"; |
| 365 | } else { |
| 366 | coverageVar->reset(); |
| 367 | } |
| 368 | } |
| 369 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 370 | namespace { |
| 371 | |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 372 | void genInputColor(GrGLProgram::ProgramDesc::ColorInput colorInput, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 373 | GrGLProgram::CachedData* programData, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 374 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 375 | GrStringBuilder* inColor) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 376 | switch (colorInput) { |
| 377 | case GrGLProgram::ProgramDesc::kAttribute_ColorInput: { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 378 | segments->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 379 | GrGLShaderVar::kAttribute_TypeModifier, |
| 380 | COL_ATTR_NAME); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 381 | const char *vsName, *fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 382 | segments->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 383 | segments->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
| 384 | *inColor = fsName; |
| 385 | } break; |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 386 | case GrGLProgram::ProgramDesc::kUniform_ColorInput: |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 387 | segments->addUniform(GrGLShaderBuilder::kFragment_VariableLifetime, |
| 388 | kVec4f_GrSLType, COL_UNI_NAME); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 389 | programData->fUniLocations.fColorUni = kUseUniform; |
| 390 | *inColor = COL_UNI_NAME; |
| 391 | break; |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 392 | case GrGLProgram::ProgramDesc::kTransBlack_ColorInput: |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 393 | GrAssert(!"needComputedColor should be false."); |
| 394 | break; |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 395 | case GrGLProgram::ProgramDesc::kSolidWhite_ColorInput: |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 396 | break; |
| 397 | default: |
| 398 | GrCrash("Unknown color type."); |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 403 | void genAttributeCoverage(GrGLShaderBuilder* segments, |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 404 | GrStringBuilder* inOutCoverage) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 405 | segments->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 406 | GrGLShaderVar::kAttribute_TypeModifier, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 407 | COV_ATTR_NAME); |
| 408 | const char *vsName, *fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 409 | segments->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 410 | segments->fVSCode.appendf("\t%s = " COV_ATTR_NAME ";\n", vsName); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 411 | if (inOutCoverage->size()) { |
| 412 | segments->fFSCode.appendf("\tvec4 attrCoverage = %s * %s;\n", |
| 413 | fsName, inOutCoverage->c_str()); |
| 414 | *inOutCoverage = "attrCoverage"; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 415 | } else { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 416 | *inOutCoverage = fsName; |
| 417 | } |
| 418 | } |
| 419 | |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 420 | void genUniformCoverage(GrGLShaderBuilder* segments, |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 421 | GrGLProgram::CachedData* programData, |
| 422 | GrStringBuilder* inOutCoverage) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 423 | segments->addUniform(GrGLShaderBuilder::kFragment_VariableLifetime, |
| 424 | kVec4f_GrSLType, COV_UNI_NAME); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 425 | programData->fUniLocations.fCoverageUni = kUseUniform; |
| 426 | if (inOutCoverage->size()) { |
| 427 | segments->fFSCode.appendf("\tvec4 uniCoverage = %s * %s;\n", |
| 428 | COV_UNI_NAME, inOutCoverage->c_str()); |
| 429 | *inOutCoverage = "uniCoverage"; |
| 430 | } else { |
| 431 | *inOutCoverage = COV_UNI_NAME; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 435 | } |
| 436 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 437 | void GrGLProgram::genGeometryShader(const GrGLContextInfo& gl, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 438 | GrGLShaderBuilder* segments) const { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 439 | #if GR_GL_EXPERIMENTAL_GS |
| 440 | if (fProgramDesc.fExperimentalGS) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 441 | GrAssert(gl.glslGeneration() >= k150_GrGLSLGeneration); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 442 | segments->fGSHeader.append("layout(triangles) in;\n" |
| 443 | "layout(triangle_strip, max_vertices = 6) out;\n"); |
| 444 | segments->fGSCode.append("void main() {\n" |
| 445 | "\tfor (int i = 0; i < 3; ++i) {\n" |
| 446 | "\t\tgl_Position = gl_in[i].gl_Position;\n"); |
| 447 | if (this->fProgramDesc.fEmitsPointSize) { |
| 448 | segments->fGSCode.append("\t\tgl_PointSize = 1.0;\n"); |
| 449 | } |
| 450 | GrAssert(segments->fGSInputs.count() == segments->fGSOutputs.count()); |
| 451 | int count = segments->fGSInputs.count(); |
| 452 | for (int i = 0; i < count; ++i) { |
| 453 | segments->fGSCode.appendf("\t\t%s = %s[i];\n", |
| 454 | segments->fGSOutputs[i].getName().c_str(), |
| 455 | segments->fGSInputs[i].getName().c_str()); |
| 456 | } |
| 457 | segments->fGSCode.append("\t\tEmitVertex();\n" |
| 458 | "\t}\n" |
| 459 | "\tEndPrimitive();\n" |
| 460 | "}\n"); |
| 461 | } |
| 462 | #endif |
| 463 | } |
| 464 | |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 465 | const char* GrGLProgram::adjustInColor(const GrStringBuilder& inColor) const { |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 466 | if (inColor.size()) { |
| 467 | return inColor.c_str(); |
| 468 | } else { |
| 469 | if (ProgramDesc::kSolidWhite_ColorInput == fProgramDesc.fColorInput) { |
| 470 | return all_ones_vec(4); |
| 471 | } else { |
| 472 | return all_zeros_vec(4); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 477 | // If this destructor is in the header file, we must include GrGLProgramStage |
| 478 | // instead of just forward-declaring it. |
| 479 | GrGLProgram::CachedData::~CachedData() { |
| 480 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| 481 | delete fCustomStage[i]; |
| 482 | } |
| 483 | } |
| 484 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 485 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 486 | bool GrGLProgram::genProgram(const GrGLContextInfo& gl, |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 487 | GrCustomStage** customStages, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 488 | GrGLProgram::CachedData* programData) const { |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 489 | GrGLShaderBuilder segments; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 490 | const uint32_t& layout = fProgramDesc.fVertexLayout; |
| 491 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 492 | programData->fUniLocations.reset(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 493 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 494 | #if GR_GL_EXPERIMENTAL_GS |
| 495 | segments.fUsesGS = fProgramDesc.fExperimentalGS; |
| 496 | #endif |
| 497 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 498 | SkXfermode::Coeff colorCoeff, uniformCoeff; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 499 | bool applyColorMatrix = SkToBool(fProgramDesc.fColorMatrixEnabled); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 500 | // The rest of transfer mode color filters have not been implemented |
| 501 | if (fProgramDesc.fColorFilterXfermode < SkXfermode::kCoeffModesCnt) { |
| 502 | GR_DEBUGCODE(bool success =) |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 503 | SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode> |
| 504 | (fProgramDesc.fColorFilterXfermode), |
| 505 | &uniformCoeff, &colorCoeff); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 506 | GR_DEBUGASSERT(success); |
| 507 | } else { |
| 508 | colorCoeff = SkXfermode::kOne_Coeff; |
| 509 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 510 | } |
| 511 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 512 | // no need to do the color filter / matrix at all if coverage is 0. The |
| 513 | // output color is scaled by the coverage. All the dual source outputs are |
| 514 | // scaled by the coverage as well. |
| 515 | if (ProgramDesc::kTransBlack_ColorInput == fProgramDesc.fCoverageInput) { |
| 516 | colorCoeff = SkXfermode::kZero_Coeff; |
| 517 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 518 | applyColorMatrix = false; |
| 519 | } |
| 520 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 521 | // If we know the final color is going to be all zeros then we can |
| 522 | // simplify the color filter coeffecients. needComputedColor will then |
| 523 | // come out false below. |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 524 | if (ProgramDesc::kTransBlack_ColorInput == fProgramDesc.fColorInput) { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 525 | colorCoeff = SkXfermode::kZero_Coeff; |
| 526 | if (SkXfermode::kDC_Coeff == uniformCoeff || |
| 527 | SkXfermode::kDA_Coeff == uniformCoeff) { |
| 528 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 529 | } else if (SkXfermode::kIDC_Coeff == uniformCoeff || |
| 530 | SkXfermode::kIDA_Coeff == uniformCoeff) { |
| 531 | uniformCoeff = SkXfermode::kOne_Coeff; |
| 532 | } |
| 533 | } |
| 534 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 535 | bool needColorFilterUniform; |
| 536 | bool needComputedColor; |
| 537 | needBlendInputs(uniformCoeff, colorCoeff, |
| 538 | &needColorFilterUniform, &needComputedColor); |
| 539 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 540 | // the dual source output has no canonical var name, have to |
| 541 | // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 542 | bool dualSourceOutputWritten = false; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 543 | segments.fHeader.printf(GrGetGLSLVersionDecl(gl.binding(), |
| 544 | gl.glslGeneration())); |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 545 | |
| 546 | GrGLShaderVar colorOutput; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 547 | bool isColorDeclared = GrGLSLSetupFSColorOuput(gl.glslGeneration(), |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 548 | declared_color_output_name(), |
| 549 | &colorOutput); |
| 550 | if (isColorDeclared) { |
| 551 | segments.fFSOutputs.push_back(colorOutput); |
| 552 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 553 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 554 | segments.addUniform(GrGLShaderBuilder::kVertex_VariableLifetime, |
| 555 | kMat33f_GrSLType, VIEW_MATRIX_NAME); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 556 | programData->fUniLocations.fViewMatrixUni = kUseUniform; |
bsalomon@google.com | 341767c | 2012-05-11 20:47:39 +0000 | [diff] [blame] | 557 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 558 | segments.fVSAttrs.push_back().set(kVec2f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 559 | GrGLShaderVar::kAttribute_TypeModifier, POS_ATTR_NAME); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 560 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 561 | segments.fVSCode.append( |
| 562 | "void main() {\n" |
| 563 | "\tvec3 pos3 = " VIEW_MATRIX_NAME " * vec3("POS_ATTR_NAME", 1);\n" |
| 564 | "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n"); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 565 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 566 | // incoming color to current stage being processed. |
| 567 | GrStringBuilder inColor; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 568 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 569 | if (needComputedColor) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 570 | genInputColor((ProgramDesc::ColorInput) fProgramDesc.fColorInput, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 571 | programData, &segments, &inColor); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 572 | } |
| 573 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 574 | // we output point size in the GS if present |
| 575 | if (fProgramDesc.fEmitsPointSize && !segments.fUsesGS){ |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 576 | segments.fVSCode.append("\tgl_PointSize = 1.0;\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 577 | } |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 578 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 579 | segments.fFSCode.append("void main() {\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 580 | |
| 581 | // add texture coordinates that are used to the list of vertex attr decls |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 582 | GrStringBuilder texCoordAttrs[GrDrawState::kMaxTexCoords]; |
| 583 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 584 | if (GrDrawTarget::VertexUsesTexCoordIdx(t, layout)) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 585 | tex_attr_name(t, texCoordAttrs + t); |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 586 | segments.fVSAttrs.push_back().set(kVec2f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 587 | GrGLShaderVar::kAttribute_TypeModifier, |
| 588 | texCoordAttrs[t].c_str()); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 592 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 593 | // We need to convert generic effect representations to GL-specific |
| 594 | // backends so they can be accesseed in genStageCode() and in subsequent, |
| 595 | // uses of programData, but it's safest to do so below when we're *sure* |
| 596 | // we need them. |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 597 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 598 | programData->fCustomStage[s] = NULL; |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 602 | // compute the final color |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 603 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 604 | // if we have color stages string them together, feeding the output color |
| 605 | // of each to the next and generating code for each stage. |
| 606 | if (needComputedColor) { |
| 607 | GrStringBuilder outColor; |
| 608 | for (int s = 0; s < fProgramDesc.fFirstCoverageStage; ++s) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 609 | if (fProgramDesc.fStages[s].isEnabled()) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 610 | // create var to hold stage result |
| 611 | outColor = "color"; |
| 612 | outColor.appendS32(s); |
| 613 | segments.fFSCode.appendf("\tvec4 %s;\n", outColor.c_str()); |
| 614 | |
| 615 | const char* inCoords; |
| 616 | // figure out what our input coords are |
| 617 | if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) & |
| 618 | layout) { |
| 619 | inCoords = POS_ATTR_NAME; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 620 | } else { |
| 621 | int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout); |
| 622 | // we better have input tex coordinates if stage is enabled. |
| 623 | GrAssert(tcIdx >= 0); |
| 624 | GrAssert(texCoordAttrs[tcIdx].size()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 625 | inCoords = texCoordAttrs[tcIdx].c_str(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 626 | } |
| 627 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 628 | if (NULL != customStages[s]) { |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 629 | const GrProgramStageFactory& factory = |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 630 | customStages[s]->getFactory(); |
| 631 | programData->fCustomStage[s] = |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 632 | factory.createGLInstance(customStages[s]); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 633 | } |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 634 | this->genStageCode(gl, |
| 635 | s, |
| 636 | fProgramDesc.fStages[s], |
| 637 | inColor.size() ? inColor.c_str() : NULL, |
| 638 | outColor.c_str(), |
| 639 | inCoords, |
| 640 | &segments, |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 641 | &programData->fUniLocations.fStages[s], |
| 642 | programData->fCustomStage[s]); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 643 | inColor = outColor; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 646 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 647 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 648 | // if have all ones or zeros for the "dst" input to the color filter then we |
| 649 | // may be able to make additional optimizations. |
| 650 | if (needColorFilterUniform && needComputedColor && !inColor.size()) { |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 651 | GrAssert(ProgramDesc::kSolidWhite_ColorInput == fProgramDesc.fColorInput); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 652 | bool uniformCoeffIsZero = SkXfermode::kIDC_Coeff == uniformCoeff || |
| 653 | SkXfermode::kIDA_Coeff == uniformCoeff; |
| 654 | if (uniformCoeffIsZero) { |
| 655 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 656 | bool bogus; |
| 657 | needBlendInputs(SkXfermode::kZero_Coeff, colorCoeff, |
| 658 | &needColorFilterUniform, &bogus); |
| 659 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 660 | } |
| 661 | if (needColorFilterUniform) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 662 | segments.addUniform(GrGLShaderBuilder::kFragment_VariableLifetime, |
| 663 | kVec4f_GrSLType, COL_FILTER_UNI_NAME); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 664 | programData->fUniLocations.fColorFilterUni = kUseUniform; |
| 665 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 666 | bool wroteFragColorZero = false; |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 667 | if (SkXfermode::kZero_Coeff == uniformCoeff && |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 668 | SkXfermode::kZero_Coeff == colorCoeff && |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 669 | !applyColorMatrix) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 670 | segments.fFSCode.appendf("\t%s = %s;\n", |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 671 | colorOutput.getName().c_str(), |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 672 | all_zeros_vec(4)); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 673 | wroteFragColorZero = true; |
| 674 | } else if (SkXfermode::kDst_Mode != fProgramDesc.fColorFilterXfermode) { |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 675 | segments.fFSCode.append("\tvec4 filteredColor;\n"); |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 676 | const char* color = adjustInColor(inColor); |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 677 | addColorFilter(&segments.fFSCode, "filteredColor", uniformCoeff, |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 678 | colorCoeff, color); |
| 679 | inColor = "filteredColor"; |
| 680 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 681 | if (applyColorMatrix) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 682 | segments.addUniform(GrGLShaderBuilder::kFragment_VariableLifetime, |
| 683 | kMat44f_GrSLType, COL_MATRIX_UNI_NAME); |
| 684 | segments.addUniform(GrGLShaderBuilder::kFragment_VariableLifetime, |
| 685 | kVec4f_GrSLType, COL_MATRIX_VEC_UNI_NAME); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 686 | programData->fUniLocations.fColorMatrixUni = kUseUniform; |
| 687 | programData->fUniLocations.fColorMatrixVecUni = kUseUniform; |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 688 | segments.fFSCode.append("\tvec4 matrixedColor;\n"); |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 689 | const char* color = adjustInColor(inColor); |
| 690 | addColorMatrix(&segments.fFSCode, "matrixedColor", color); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 691 | inColor = "matrixedColor"; |
| 692 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 693 | |
| 694 | /////////////////////////////////////////////////////////////////////////// |
| 695 | // compute the partial coverage (coverage stages and edge aa) |
| 696 | |
| 697 | GrStringBuilder inCoverage; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 698 | bool coverageIsZero = ProgramDesc::kTransBlack_ColorInput == |
| 699 | fProgramDesc.fCoverageInput; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 700 | // we don't need to compute coverage at all if we know the final shader |
| 701 | // output will be zero and we don't have a dual src blend output. |
| 702 | if (!wroteFragColorZero || |
| 703 | ProgramDesc::kNone_DualSrcOutput != fProgramDesc.fDualSrcOutput) { |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 704 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 705 | if (!coverageIsZero) { |
| 706 | this->genEdgeCoverage(gl, |
| 707 | layout, |
| 708 | programData, |
| 709 | &inCoverage, |
| 710 | &segments); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 711 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 712 | switch (fProgramDesc.fCoverageInput) { |
| 713 | case ProgramDesc::kSolidWhite_ColorInput: |
| 714 | // empty string implies solid white |
| 715 | break; |
| 716 | case ProgramDesc::kAttribute_ColorInput: |
| 717 | genAttributeCoverage(&segments, &inCoverage); |
| 718 | break; |
| 719 | case ProgramDesc::kUniform_ColorInput: |
| 720 | genUniformCoverage(&segments, programData, &inCoverage); |
| 721 | break; |
| 722 | default: |
| 723 | GrCrash("Unexpected input coverage."); |
| 724 | } |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 725 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 726 | GrStringBuilder outCoverage; |
| 727 | const int& startStage = fProgramDesc.fFirstCoverageStage; |
| 728 | for (int s = startStage; s < GrDrawState::kNumStages; ++s) { |
| 729 | if (fProgramDesc.fStages[s].isEnabled()) { |
| 730 | // create var to hold stage output |
| 731 | outCoverage = "coverage"; |
| 732 | outCoverage.appendS32(s); |
| 733 | segments.fFSCode.appendf("\tvec4 %s;\n", |
| 734 | outCoverage.c_str()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 735 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 736 | const char* inCoords; |
| 737 | // figure out what our input coords are |
| 738 | if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) & |
| 739 | layout) { |
| 740 | inCoords = POS_ATTR_NAME; |
| 741 | } else { |
| 742 | int tcIdx = |
| 743 | GrDrawTarget::VertexTexCoordsForStage(s, layout); |
| 744 | // we better have input tex coordinates if stage is |
| 745 | // enabled. |
| 746 | GrAssert(tcIdx >= 0); |
| 747 | GrAssert(texCoordAttrs[tcIdx].size()); |
| 748 | inCoords = texCoordAttrs[tcIdx].c_str(); |
| 749 | } |
| 750 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 751 | if (NULL != customStages[s]) { |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 752 | const GrProgramStageFactory& factory = |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 753 | customStages[s]->getFactory(); |
| 754 | programData->fCustomStage[s] = |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame] | 755 | factory.createGLInstance(customStages[s]); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 756 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 757 | this->genStageCode(gl, s, |
| 758 | fProgramDesc.fStages[s], |
| 759 | inCoverage.size() ? inCoverage.c_str() : NULL, |
| 760 | outCoverage.c_str(), |
| 761 | inCoords, |
| 762 | &segments, |
| 763 | &programData->fUniLocations.fStages[s], |
| 764 | programData->fCustomStage[s]); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 765 | inCoverage = outCoverage; |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 766 | } |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 767 | } |
| 768 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 769 | if (ProgramDesc::kNone_DualSrcOutput != fProgramDesc.fDualSrcOutput) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 770 | segments.fFSOutputs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 771 | GrGLShaderVar::kOut_TypeModifier, |
| 772 | dual_source_output_name()); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 773 | bool outputIsZero = coverageIsZero; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 774 | GrStringBuilder coeff; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 775 | if (!outputIsZero && |
| 776 | ProgramDesc::kCoverage_DualSrcOutput != |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 777 | fProgramDesc.fDualSrcOutput && !wroteFragColorZero) { |
| 778 | if (!inColor.size()) { |
| 779 | outputIsZero = true; |
| 780 | } else { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 781 | if (fProgramDesc.fDualSrcOutput == |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 782 | ProgramDesc::kCoverageISA_DualSrcOutput) { |
| 783 | coeff.printf("(1 - %s.a)", inColor.c_str()); |
| 784 | } else { |
| 785 | coeff.printf("(vec4(1,1,1,1) - %s)", inColor.c_str()); |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | if (outputIsZero) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 790 | segments.fFSCode.appendf("\t%s = %s;\n", |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 791 | dual_source_output_name(), |
| 792 | all_zeros_vec(4)); |
| 793 | } else { |
| 794 | modulate_helper(dual_source_output_name(), |
| 795 | coeff.c_str(), |
| 796 | inCoverage.c_str(), |
| 797 | &segments.fFSCode); |
| 798 | } |
| 799 | dualSourceOutputWritten = true; |
| 800 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 801 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 802 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 803 | /////////////////////////////////////////////////////////////////////////// |
| 804 | // combine color and coverage as frag color |
| 805 | |
| 806 | if (!wroteFragColorZero) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 807 | if (coverageIsZero) { |
| 808 | segments.fFSCode.appendf("\t%s = %s;\n", |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 809 | colorOutput.getName().c_str(), |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 810 | all_zeros_vec(4)); |
| 811 | } else { |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 812 | modulate_helper(colorOutput.getName().c_str(), |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 813 | inColor.c_str(), |
| 814 | inCoverage.c_str(), |
| 815 | &segments.fFSCode); |
| 816 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 817 | if (ProgramDesc::kUnpremultiplied_RoundDown_OutputConfig == |
| 818 | fProgramDesc.fOutputConfig) { |
| 819 | segments.fFSCode.appendf("\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.rgb / %s.a * 255.0)/255.0, %s.a);\n", |
| 820 | colorOutput.getName().c_str(), |
| 821 | colorOutput.getName().c_str(), |
| 822 | colorOutput.getName().c_str(), |
| 823 | colorOutput.getName().c_str(), |
| 824 | colorOutput.getName().c_str()); |
| 825 | } else if (ProgramDesc::kUnpremultiplied_RoundUp_OutputConfig == |
| 826 | fProgramDesc.fOutputConfig) { |
| 827 | segments.fFSCode.appendf("\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.rgb / %s.a * 255.0)/255.0, %s.a);\n", |
| 828 | colorOutput.getName().c_str(), |
| 829 | colorOutput.getName().c_str(), |
| 830 | colorOutput.getName().c_str(), |
| 831 | colorOutput.getName().c_str(), |
| 832 | colorOutput.getName().c_str()); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 833 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 834 | } |
| 835 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 836 | segments.fVSCode.append("}\n"); |
| 837 | segments.fFSCode.append("}\n"); |
| 838 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 839 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 840 | // insert GS |
| 841 | #if GR_DEBUG |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 842 | this->genGeometryShader(gl, &segments); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 843 | #endif |
| 844 | |
| 845 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 846 | // compile and setup attribs and unis |
| 847 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 848 | if (!CompileShaders(gl, segments, programData)) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 849 | return false; |
| 850 | } |
| 851 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 852 | if (!this->bindOutputsAttribsAndLinkProgram(gl, texCoordAttrs, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 853 | isColorDeclared, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 854 | dualSourceOutputWritten, |
| 855 | programData)) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 856 | return false; |
| 857 | } |
| 858 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 859 | this->getUniformLocationsAndInitCache(gl, programData); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 860 | |
| 861 | return true; |
| 862 | } |
| 863 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 864 | namespace { |
| 865 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 866 | inline void expand_decls(const VarArray& vars, |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 867 | const GrGLContextInfo& gl, |
| 868 | GrStringBuilder* string) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 869 | const int count = vars.count(); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 870 | for (int i = 0; i < count; ++i) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 871 | vars[i].appendDecl(gl, string); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 875 | inline void print_shader(int stringCnt, |
| 876 | const char** strings, |
| 877 | int* stringLengths) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 878 | for (int i = 0; i < stringCnt; ++i) { |
| 879 | if (NULL == stringLengths || stringLengths[i] < 0) { |
| 880 | GrPrintf(strings[i]); |
| 881 | } else { |
| 882 | GrPrintf("%.*s", stringLengths[i], strings[i]); |
| 883 | } |
| 884 | } |
| 885 | } |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 886 | |
| 887 | typedef SkTArray<const char*, true> StrArray; |
| 888 | #define PREALLOC_STR_ARRAY(N) SkSTArray<(N), const char*, true> |
| 889 | |
| 890 | typedef SkTArray<int, true> LengthArray; |
| 891 | #define PREALLOC_LENGTH_ARRAY(N) SkSTArray<(N), int, true> |
| 892 | |
| 893 | // these shouldn't relocate |
| 894 | typedef GrTAllocator<GrStringBuilder> TempArray; |
| 895 | #define PREALLOC_TEMP_ARRAY(N) GrSTAllocator<(N), GrStringBuilder> |
| 896 | |
| 897 | inline void append_string(const GrStringBuilder& str, |
| 898 | StrArray* strings, |
| 899 | LengthArray* lengths) { |
| 900 | int length = (int) str.size(); |
| 901 | if (length) { |
| 902 | strings->push_back(str.c_str()); |
| 903 | lengths->push_back(length); |
| 904 | } |
| 905 | GrAssert(strings->count() == lengths->count()); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 906 | } |
| 907 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 908 | inline void append_decls(const VarArray& vars, |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 909 | const GrGLContextInfo& gl, |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 910 | StrArray* strings, |
| 911 | LengthArray* lengths, |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 912 | TempArray* temp) { |
| 913 | expand_decls(vars, gl, &temp->push_back()); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 914 | append_string(temp->back(), strings, lengths); |
| 915 | } |
| 916 | |
| 917 | } |
| 918 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 919 | bool GrGLProgram::CompileShaders(const GrGLContextInfo& gl, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 920 | const GrGLShaderBuilder& segments, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 921 | CachedData* programData) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 922 | enum { kPreAllocStringCnt = 8 }; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 923 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 924 | PREALLOC_STR_ARRAY(kPreAllocStringCnt) strs; |
| 925 | PREALLOC_LENGTH_ARRAY(kPreAllocStringCnt) lengths; |
| 926 | PREALLOC_TEMP_ARRAY(kPreAllocStringCnt) temps; |
| 927 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 928 | GrStringBuilder unis; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 929 | GrStringBuilder inputs; |
| 930 | GrStringBuilder outputs; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 931 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 932 | append_string(segments.fHeader, &strs, &lengths); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 933 | append_decls(segments.fVSUnis, gl, &strs, &lengths, &temps); |
| 934 | append_decls(segments.fVSAttrs, gl, &strs, &lengths, &temps); |
| 935 | append_decls(segments.fVSOutputs, gl, &strs, &lengths, &temps); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 936 | append_string(segments.fVSCode, &strs, &lengths); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 937 | |
| 938 | #if PRINT_SHADERS |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 939 | print_shader(strs.count(), &strs[0], &lengths[0]); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 940 | GrPrintf("\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 941 | #endif |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 942 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 943 | programData->fVShaderID = |
| 944 | CompileShader(gl, GR_GL_VERTEX_SHADER, strs.count(), |
| 945 | &strs[0], &lengths[0]); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 946 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 947 | if (!programData->fVShaderID) { |
| 948 | return false; |
| 949 | } |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 950 | if (segments.fUsesGS) { |
| 951 | strs.reset(); |
| 952 | lengths.reset(); |
| 953 | temps.reset(); |
| 954 | append_string(segments.fHeader, &strs, &lengths); |
| 955 | append_string(segments.fGSHeader, &strs, &lengths); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 956 | append_decls(segments.fGSInputs, gl, &strs, &lengths, &temps); |
| 957 | append_decls(segments.fGSOutputs, gl, &strs, &lengths, &temps); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 958 | append_string(segments.fGSCode, &strs, &lengths); |
| 959 | #if PRINT_SHADERS |
| 960 | print_shader(strs.count(), &strs[0], &lengths[0]); |
| 961 | GrPrintf("\n"); |
| 962 | #endif |
| 963 | programData->fGShaderID = |
| 964 | CompileShader(gl, GR_GL_GEOMETRY_SHADER, strs.count(), |
| 965 | &strs[0], &lengths[0]); |
| 966 | } else { |
| 967 | programData->fGShaderID = 0; |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 968 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 969 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 970 | strs.reset(); |
| 971 | lengths.reset(); |
| 972 | temps.reset(); |
| 973 | |
| 974 | append_string(segments.fHeader, &strs, &lengths); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 975 | GrStringBuilder precisionStr(GrGetGLSLShaderPrecisionDecl(gl.binding())); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 976 | append_string(precisionStr, &strs, &lengths); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 977 | append_decls(segments.fFSUnis, gl, &strs, &lengths, &temps); |
| 978 | append_decls(segments.fFSInputs, gl, &strs, &lengths, &temps); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 979 | // We shouldn't have declared outputs on 1.10 |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 980 | GrAssert(k110_GrGLSLGeneration != gl.glslGeneration() || |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 981 | segments.fFSOutputs.empty()); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 982 | append_decls(segments.fFSOutputs, gl, &strs, &lengths, &temps); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 983 | append_string(segments.fFSFunctions, &strs, &lengths); |
| 984 | append_string(segments.fFSCode, &strs, &lengths); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 985 | |
| 986 | #if PRINT_SHADERS |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 987 | print_shader(strs.count(), &strs[0], &lengths[0]); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 988 | GrPrintf("\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 989 | #endif |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 990 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 991 | programData->fFShaderID = |
| 992 | CompileShader(gl, GR_GL_FRAGMENT_SHADER, strs.count(), |
| 993 | &strs[0], &lengths[0]); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 994 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 995 | if (!programData->fFShaderID) { |
| 996 | return false; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 997 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 998 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 999 | return true; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1002 | #define GL_CALL(X) GR_GL_CALL(gl.interface(), X) |
| 1003 | #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gl.interface(), R, X) |
| 1004 | |
| 1005 | GrGLuint GrGLProgram::CompileShader(const GrGLContextInfo& gl, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1006 | GrGLenum type, |
| 1007 | int stringCnt, |
| 1008 | const char** strings, |
| 1009 | int* stringLengths) { |
tomhudson@google.com | 278cbb4 | 2011-06-30 19:37:01 +0000 | [diff] [blame] | 1010 | SK_TRACE_EVENT1("GrGLProgram::CompileShader", |
| 1011 | "stringCount", SkStringPrintf("%i", stringCnt).c_str()); |
| 1012 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1013 | GrGLuint shader; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1014 | GL_CALL_RET(shader, CreateShader(type)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1015 | if (0 == shader) { |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | GrGLint compiled = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1020 | GL_CALL(ShaderSource(shader, stringCnt, strings, stringLengths)); |
| 1021 | GL_CALL(CompileShader(shader)); |
| 1022 | GL_CALL(GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1023 | |
| 1024 | if (!compiled) { |
| 1025 | GrGLint infoLen = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1026 | GL_CALL(GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 1027 | SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1028 | if (infoLen > 0) { |
bsalomon@google.com | 79afcaa | 2011-09-14 14:29:18 +0000 | [diff] [blame] | 1029 | // retrieve length even though we don't need it to workaround |
| 1030 | // bug in chrome cmd buffer param validation. |
| 1031 | GrGLsizei length = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1032 | GL_CALL(GetShaderInfoLog(shader, infoLen+1, |
| 1033 | &length, (char*)log.get())); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1034 | print_shader(stringCnt, strings, stringLengths); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1035 | GrPrintf("\n%s", log.get()); |
| 1036 | } |
| 1037 | GrAssert(!"Shader compilation failed!"); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1038 | GL_CALL(DeleteShader(shader)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1039 | return 0; |
| 1040 | } |
| 1041 | return shader; |
| 1042 | } |
| 1043 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1044 | bool GrGLProgram::bindOutputsAttribsAndLinkProgram( |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1045 | const GrGLContextInfo& gl, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1046 | GrStringBuilder texCoordAttrNames[], |
| 1047 | bool bindColorOut, |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 1048 | bool bindDualSrcOut, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1049 | CachedData* programData) const { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1050 | GL_CALL_RET(programData->fProgramID, CreateProgram()); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1051 | if (!programData->fProgramID) { |
| 1052 | return false; |
| 1053 | } |
| 1054 | const GrGLint& progID = programData->fProgramID; |
| 1055 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1056 | GL_CALL(AttachShader(progID, programData->fVShaderID)); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1057 | if (programData->fGShaderID) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1058 | GL_CALL(AttachShader(progID, programData->fGShaderID)); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1059 | } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1060 | GL_CALL(AttachShader(progID, programData->fFShaderID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1061 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1062 | if (bindColorOut) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1063 | GL_CALL(BindFragDataLocation(programData->fProgramID, |
| 1064 | 0, declared_color_output_name())); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1065 | } |
| 1066 | if (bindDualSrcOut) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1067 | GL_CALL(BindFragDataLocationIndexed(programData->fProgramID, |
| 1068 | 0, 1, dual_source_output_name())); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1071 | // Bind the attrib locations to same values for all shaders |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1072 | GL_CALL(BindAttribLocation(progID, PositionAttributeIdx(), POS_ATTR_NAME)); |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1073 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1074 | if (texCoordAttrNames[t].size()) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1075 | GL_CALL(BindAttribLocation(progID, |
| 1076 | TexCoordAttributeIdx(t), |
| 1077 | texCoordAttrNames[t].c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1081 | GL_CALL(BindAttribLocation(progID, ColorAttributeIdx(), COL_ATTR_NAME)); |
| 1082 | GL_CALL(BindAttribLocation(progID, CoverageAttributeIdx(), COV_ATTR_NAME)); |
| 1083 | GL_CALL(BindAttribLocation(progID, EdgeAttributeIdx(), EDGE_ATTR_NAME)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1084 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1085 | GL_CALL(LinkProgram(progID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1086 | |
| 1087 | GrGLint linked = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1088 | GL_CALL(GetProgramiv(progID, GR_GL_LINK_STATUS, &linked)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1089 | if (!linked) { |
| 1090 | GrGLint infoLen = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1091 | GL_CALL(GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 1092 | SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1093 | if (infoLen > 0) { |
bsalomon@google.com | 79afcaa | 2011-09-14 14:29:18 +0000 | [diff] [blame] | 1094 | // retrieve length even though we don't need it to workaround |
| 1095 | // bug in chrome cmd buffer param validation. |
| 1096 | GrGLsizei length = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1097 | GL_CALL(GetProgramInfoLog(progID, |
| 1098 | infoLen+1, |
| 1099 | &length, |
| 1100 | (char*)log.get())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1101 | GrPrintf((char*)log.get()); |
| 1102 | } |
| 1103 | GrAssert(!"Error linking program"); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1104 | GL_CALL(DeleteProgram(progID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1105 | programData->fProgramID = 0; |
| 1106 | return false; |
| 1107 | } |
| 1108 | return true; |
| 1109 | } |
| 1110 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1111 | void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1112 | CachedData* programData) const { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1113 | const GrGLint& progID = programData->fProgramID; |
| 1114 | |
| 1115 | if (kUseUniform == programData->fUniLocations.fViewMatrixUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1116 | GL_CALL_RET(programData->fUniLocations.fViewMatrixUni, |
| 1117 | GetUniformLocation(progID, VIEW_MATRIX_NAME)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1118 | GrAssert(kUnusedUniform != programData->fUniLocations.fViewMatrixUni); |
| 1119 | } |
| 1120 | if (kUseUniform == programData->fUniLocations.fColorUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1121 | GL_CALL_RET(programData->fUniLocations.fColorUni, |
| 1122 | GetUniformLocation(progID, COL_UNI_NAME)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1123 | GrAssert(kUnusedUniform != programData->fUniLocations.fColorUni); |
| 1124 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 1125 | if (kUseUniform == programData->fUniLocations.fColorFilterUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1126 | GL_CALL_RET(programData->fUniLocations.fColorFilterUni, |
| 1127 | GetUniformLocation(progID, COL_FILTER_UNI_NAME)); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 1128 | GrAssert(kUnusedUniform != programData->fUniLocations.fColorFilterUni); |
| 1129 | } |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1130 | |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1131 | if (kUseUniform == programData->fUniLocations.fColorMatrixUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1132 | GL_CALL_RET(programData->fUniLocations.fColorMatrixUni, |
| 1133 | GetUniformLocation(progID, COL_MATRIX_UNI_NAME)); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | if (kUseUniform == programData->fUniLocations.fColorMatrixVecUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1137 | GL_CALL_RET(programData->fUniLocations.fColorMatrixVecUni, |
| 1138 | GetUniformLocation(progID, COL_MATRIX_VEC_UNI_NAME)); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1139 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1140 | if (kUseUniform == programData->fUniLocations.fCoverageUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1141 | GL_CALL_RET(programData->fUniLocations.fCoverageUni, |
| 1142 | GetUniformLocation(progID, COV_UNI_NAME)); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1143 | GrAssert(kUnusedUniform != programData->fUniLocations.fCoverageUni); |
| 1144 | } |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1145 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1146 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1147 | StageUniLocations& locations = programData->fUniLocations.fStages[s]; |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 1148 | if (fProgramDesc.fStages[s].isEnabled()) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1149 | if (kUseUniform == locations.fTextureMatrixUni) { |
| 1150 | GrStringBuilder texMName; |
| 1151 | tex_matrix_name(s, &texMName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1152 | GL_CALL_RET(locations.fTextureMatrixUni, |
| 1153 | GetUniformLocation(progID, texMName.c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1154 | GrAssert(kUnusedUniform != locations.fTextureMatrixUni); |
| 1155 | } |
| 1156 | |
| 1157 | if (kUseUniform == locations.fSamplerUni) { |
| 1158 | GrStringBuilder samplerName; |
| 1159 | sampler_name(s, &samplerName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1160 | GL_CALL_RET(locations.fSamplerUni, |
| 1161 | GetUniformLocation(progID,samplerName.c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1162 | GrAssert(kUnusedUniform != locations.fSamplerUni); |
| 1163 | } |
| 1164 | |
| 1165 | if (kUseUniform == locations.fNormalizedTexelSizeUni) { |
| 1166 | GrStringBuilder texelSizeName; |
| 1167 | normalized_texel_size_name(s, &texelSizeName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1168 | GL_CALL_RET(locations.fNormalizedTexelSizeUni, |
| 1169 | GetUniformLocation(progID, texelSizeName.c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1170 | GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni); |
| 1171 | } |
| 1172 | |
| 1173 | if (kUseUniform == locations.fRadial2Uni) { |
| 1174 | GrStringBuilder radial2ParamName; |
| 1175 | radial2_param_name(s, &radial2ParamName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1176 | GL_CALL_RET(locations.fRadial2Uni, |
| 1177 | GetUniformLocation(progID, radial2ParamName.c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1178 | GrAssert(kUnusedUniform != locations.fRadial2Uni); |
| 1179 | } |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1180 | |
| 1181 | if (kUseUniform == locations.fTexDomUni) { |
| 1182 | GrStringBuilder texDomName; |
| 1183 | tex_domain_name(s, &texDomName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1184 | GL_CALL_RET(locations.fTexDomUni, |
| 1185 | GetUniformLocation(progID, texDomName.c_str())); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1186 | GrAssert(kUnusedUniform != locations.fTexDomUni); |
| 1187 | } |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1188 | |
| 1189 | GrStringBuilder kernelName, imageIncrementName; |
| 1190 | convolve_param_names(s, &kernelName, &imageIncrementName); |
| 1191 | if (kUseUniform == locations.fKernelUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1192 | GL_CALL_RET(locations.fKernelUni, |
| 1193 | GetUniformLocation(progID, kernelName.c_str())); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1194 | GrAssert(kUnusedUniform != locations.fKernelUni); |
| 1195 | } |
| 1196 | |
| 1197 | if (kUseUniform == locations.fImageIncrementUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1198 | GL_CALL_RET(locations.fImageIncrementUni, |
| 1199 | GetUniformLocation(progID, |
| 1200 | imageIncrementName.c_str())); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1201 | GrAssert(kUnusedUniform != locations.fImageIncrementUni); |
| 1202 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1203 | |
| 1204 | if (NULL != programData->fCustomStage[s]) { |
| 1205 | programData->fCustomStage[s]-> |
| 1206 | initUniforms(gl.interface(), progID); |
| 1207 | } |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1208 | } |
| 1209 | } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1210 | GL_CALL(UseProgram(progID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1211 | |
| 1212 | // init sampler unis and set bogus values for state tracking |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1213 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1214 | if (kUnusedUniform != programData->fUniLocations.fStages[s].fSamplerUni) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1215 | GL_CALL(Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1216 | } |
| 1217 | programData->fTextureMatrices[s] = GrMatrix::InvalidMatrix(); |
| 1218 | programData->fRadial2CenterX1[s] = GR_ScalarMax; |
| 1219 | programData->fRadial2Radius0[s] = -GR_ScalarMax; |
| 1220 | programData->fTextureWidth[s] = -1; |
| 1221 | programData->fTextureHeight[s] = -1; |
tomhudson@google.com | 24878f7 | 2012-03-22 14:44:46 +0000 | [diff] [blame] | 1222 | programData->fTextureDomain[s].setEmpty(); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1223 | // Must not reset fStageOverride[] here. |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1224 | } |
| 1225 | programData->fViewMatrix = GrMatrix::InvalidMatrix(); |
| 1226 | programData->fColor = GrColor_ILLEGAL; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 1227 | programData->fColorFilterColor = GrColor_ILLEGAL; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1230 | //============================================================================ |
| 1231 | // Stage code generation |
| 1232 | //============================================================================ |
| 1233 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1234 | namespace { |
| 1235 | |
| 1236 | bool isRadialMapping(GrGLProgram::StageDesc::CoordMapping mapping) { |
| 1237 | return |
| 1238 | (GrGLProgram::StageDesc::kRadial2Gradient_CoordMapping == mapping || |
| 1239 | GrGLProgram::StageDesc::kRadial2GradientDegenerate_CoordMapping == mapping); |
| 1240 | } |
| 1241 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1242 | const GrGLShaderVar* genRadialVS(int stageNum, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1243 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1244 | GrGLProgram::StageUniLocations* locations, |
| 1245 | const char** radial2VaryingVSName, |
| 1246 | const char** radial2VaryingFSName, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1247 | const char* varyingVSName) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1248 | GrStringBuilder r2ParamsName; |
| 1249 | radial2_param_name(stageNum, &r2ParamsName); |
| 1250 | const GrGLShaderVar* radial2FSParams = |
| 1251 | &segments->addUniform(GrGLShaderBuilder::kBoth_VariableLifetime, |
| 1252 | kFloat_GrSLType, r2ParamsName.c_str(), -1, 6); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1253 | locations->fRadial2Uni = kUseUniform; |
| 1254 | |
| 1255 | // for radial grads without perspective we can pass the linear |
| 1256 | // part of the quadratic as a varying. |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1257 | if (segments->fVaryingDims == segments->fCoordDims) { |
| 1258 | GrAssert(2 == segments->fCoordDims); |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 1259 | segments->addVarying(kFloat_GrSLType, |
| 1260 | "Radial2BCoeff", |
| 1261 | stageNum, |
| 1262 | radial2VaryingVSName, |
| 1263 | radial2VaryingFSName); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1264 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1265 | GrStringBuilder radial2p2; |
| 1266 | GrStringBuilder radial2p3; |
| 1267 | radial2FSParams->appendArrayAccess(2, &radial2p2); |
| 1268 | radial2FSParams->appendArrayAccess(3, &radial2p3); |
| 1269 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1270 | // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3]) |
| 1271 | const char* r2ParamName = radial2FSParams->getName().c_str(); |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1272 | segments->fVSCode.appendf("\t%s = 2.0 *(%s * %s.x - %s);\n", |
| 1273 | *radial2VaryingVSName, radial2p2.c_str(), |
| 1274 | varyingVSName, radial2p3.c_str()); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1277 | return radial2FSParams; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1280 | void genRadial2GradientCoordMapping(int stageNum, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1281 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1282 | const char* radial2VaryingFSName, |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1283 | const GrGLShaderVar* radial2Params) { |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1284 | GrStringBuilder cName("c"); |
| 1285 | GrStringBuilder ac4Name("ac4"); |
| 1286 | GrStringBuilder rootName("root"); |
| 1287 | |
| 1288 | cName.appendS32(stageNum); |
| 1289 | ac4Name.appendS32(stageNum); |
| 1290 | rootName.appendS32(stageNum); |
| 1291 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1292 | GrStringBuilder radial2p0; |
| 1293 | GrStringBuilder radial2p1; |
| 1294 | GrStringBuilder radial2p2; |
| 1295 | GrStringBuilder radial2p3; |
| 1296 | GrStringBuilder radial2p4; |
| 1297 | GrStringBuilder radial2p5; |
| 1298 | radial2Params->appendArrayAccess(0, &radial2p0); |
| 1299 | radial2Params->appendArrayAccess(1, &radial2p1); |
| 1300 | radial2Params->appendArrayAccess(2, &radial2p2); |
| 1301 | radial2Params->appendArrayAccess(3, &radial2p3); |
| 1302 | radial2Params->appendArrayAccess(4, &radial2p4); |
| 1303 | radial2Params->appendArrayAccess(5, &radial2p5); |
| 1304 | |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1305 | // if we were able to interpolate the linear component bVar is the varying |
| 1306 | // otherwise compute it |
| 1307 | GrStringBuilder bVar; |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1308 | if (segments->fCoordDims == segments->fVaryingDims) { |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1309 | bVar = radial2VaryingFSName; |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1310 | GrAssert(2 == segments->fVaryingDims); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1311 | } else { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1312 | GrAssert(3 == segments->fVaryingDims); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1313 | bVar = "b"; |
| 1314 | bVar.appendS32(stageNum); |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1315 | segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", |
| 1316 | bVar.c_str(), radial2p2.c_str(), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1317 | segments->fSampleCoords.c_str(), radial2p3.c_str()); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | // c = (x^2)+(y^2) - params[4] |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1321 | segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s;\n", |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1322 | cName.c_str(), segments->fSampleCoords.c_str(), |
| 1323 | segments->fSampleCoords.c_str(), |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1324 | radial2p4.c_str()); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1325 | // ac4 = 4.0 * params[0] * c |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1326 | segments->fFSCode.appendf("\tfloat %s = %s * 4.0 * %s;\n", |
| 1327 | ac4Name.c_str(), radial2p0.c_str(), |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1328 | cName.c_str()); |
| 1329 | |
| 1330 | // root = sqrt(b^2-4ac) |
| 1331 | // (abs to avoid exception due to fp precision) |
| 1332 | segments->fFSCode.appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", |
| 1333 | rootName.c_str(), bVar.c_str(), bVar.c_str(), |
| 1334 | ac4Name.c_str()); |
| 1335 | |
| 1336 | // x coord is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] |
| 1337 | // y coord is 0.5 (texture is effectively 1D) |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1338 | segments->fSampleCoords.printf("vec2((-%s + %s * %s) * %s, 0.5)", |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1339 | bVar.c_str(), radial2p5.c_str(), |
| 1340 | rootName.c_str(), radial2p1.c_str()); |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1341 | segments->fComplexCoord = true; |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1344 | void genRadial2GradientDegenerateCoordMapping(int stageNum, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1345 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1346 | const char* radial2VaryingFSName, |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1347 | const GrGLShaderVar* radial2Params) { |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1348 | GrStringBuilder cName("c"); |
| 1349 | |
| 1350 | cName.appendS32(stageNum); |
| 1351 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1352 | GrStringBuilder radial2p2; |
| 1353 | GrStringBuilder radial2p3; |
| 1354 | GrStringBuilder radial2p4; |
| 1355 | radial2Params->appendArrayAccess(2, &radial2p2); |
| 1356 | radial2Params->appendArrayAccess(3, &radial2p3); |
| 1357 | radial2Params->appendArrayAccess(4, &radial2p4); |
| 1358 | |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1359 | // if we were able to interpolate the linear component bVar is the varying |
| 1360 | // otherwise compute it |
| 1361 | GrStringBuilder bVar; |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1362 | if (segments->fCoordDims == segments->fVaryingDims) { |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1363 | bVar = radial2VaryingFSName; |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1364 | GrAssert(2 == segments->fVaryingDims); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1365 | } else { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1366 | GrAssert(3 == segments->fVaryingDims); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1367 | bVar = "b"; |
| 1368 | bVar.appendS32(stageNum); |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1369 | segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", |
| 1370 | bVar.c_str(), radial2p2.c_str(), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1371 | segments->fSampleCoords.c_str(), radial2p3.c_str()); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // c = (x^2)+(y^2) - params[4] |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1375 | segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s;\n", |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1376 | cName.c_str(), segments->fSampleCoords.c_str(), |
| 1377 | segments->fSampleCoords.c_str(), |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1378 | radial2p4.c_str()); |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1379 | |
| 1380 | // x coord is: -c/b |
| 1381 | // y coord is 0.5 (texture is effectively 1D) |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1382 | segments->fSampleCoords.printf("vec2((-%s / %s), 0.5)", cName.c_str(), bVar.c_str()); |
| 1383 | segments->fComplexCoord = true; |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1386 | void gen2x2FS(int stageNum, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1387 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1388 | GrGLProgram::StageUniLocations* locations, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1389 | const char* samplerName, |
| 1390 | const char* texelSizeName, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1391 | const char* fsOutColor, |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1392 | GrStringBuilder& texFunc) { |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1393 | locations->fNormalizedTexelSizeUni = kUseUniform; |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1394 | if (segments->fComplexCoord) { |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1395 | // assign the coord to a var rather than compute 4x. |
| 1396 | GrStringBuilder coordVar("tCoord"); |
| 1397 | coordVar.appendS32(stageNum); |
| 1398 | segments->fFSCode.appendf("\t%s %s = %s;\n", |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1399 | float_vector_type_str(segments->fCoordDims), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1400 | coordVar.c_str(), segments->fSampleCoords.c_str()); |
| 1401 | segments->fSampleCoords = coordVar; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1402 | } |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1403 | GrAssert(2 == segments->fCoordDims); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1404 | GrStringBuilder accumVar("accum"); |
| 1405 | accumVar.appendS32(stageNum); |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1406 | segments->fFSCode.appendf("\tvec4 %s = %s(%s, %s + vec2(-%s.x,-%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str()); |
| 1407 | segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(+%s.x,-%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str()); |
| 1408 | segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(-%s.x,+%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str()); |
| 1409 | segments->fFSCode.appendf("\t%s += %s(%s, %s + vec2(+%s.x,+%s.y))%s;\n", accumVar.c_str(), texFunc.c_str(), samplerName, segments->fSampleCoords.c_str(), texelSizeName, texelSizeName, segments->fSwizzle.c_str()); |
| 1410 | segments->fFSCode.appendf("\t%s = .25 * %s%s;\n", fsOutColor, accumVar.c_str(), segments->fModulate.c_str()); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1411 | |
| 1412 | } |
| 1413 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1414 | void genMorphologyVS(int stageNum, |
| 1415 | const StageDesc& desc, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1416 | GrGLShaderBuilder* segments, |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1417 | GrGLProgram::StageUniLocations* locations, |
| 1418 | const char** imageIncrementName, |
| 1419 | const char* varyingVSName) { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1420 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1421 | GrStringBuilder iiName; |
| 1422 | image_increment_param_name(stageNum, &iiName); |
| 1423 | const GrGLShaderVar* imgInc = |
| 1424 | &segments->addUniform( |
| 1425 | GrGLShaderBuilder::kBoth_VariableLifetime, kVec2f_GrSLType, |
| 1426 | iiName.c_str()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1427 | *imageIncrementName = imgInc->getName().c_str(); |
| 1428 | |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1429 | locations->fImageIncrementUni = kUseUniform; |
| 1430 | segments->fVSCode.appendf("\t%s -= vec2(%d, %d) * %s;\n", |
| 1431 | varyingVSName, desc.fKernelWidth, |
| 1432 | desc.fKernelWidth, *imageIncrementName); |
| 1433 | } |
| 1434 | |
| 1435 | void genMorphologyFS(int stageNum, |
| 1436 | const StageDesc& desc, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1437 | GrGLShaderBuilder* segments, |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1438 | const char* samplerName, |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1439 | const char* imageIncrementName, |
| 1440 | const char* fsOutColor, |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1441 | GrStringBuilder& texFunc) { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1442 | GrStringBuilder valueVar("value"); |
| 1443 | valueVar.appendS32(stageNum); |
| 1444 | GrStringBuilder coordVar("coord"); |
| 1445 | coordVar.appendS32(stageNum); |
| 1446 | bool isDilate = StageDesc::kDilate_FetchMode == desc.fFetchMode; |
| 1447 | |
| 1448 | if (isDilate) { |
| 1449 | segments->fFSCode.appendf("\tvec4 %s = vec4(0, 0, 0, 0);\n", |
| 1450 | valueVar.c_str()); |
| 1451 | } else { |
| 1452 | segments->fFSCode.appendf("\tvec4 %s = vec4(1, 1, 1, 1);\n", |
| 1453 | valueVar.c_str()); |
| 1454 | } |
| 1455 | segments->fFSCode.appendf("\tvec2 %s = %s;\n", |
| 1456 | coordVar.c_str(), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1457 | segments->fSampleCoords.c_str()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1458 | segments->fFSCode.appendf("\tfor (int i = 0; i < %d; i++) {\n", |
| 1459 | desc.fKernelWidth * 2 + 1); |
| 1460 | segments->fFSCode.appendf("\t\t%s = %s(%s, %s(%s, %s)%s);\n", |
| 1461 | valueVar.c_str(), isDilate ? "max" : "min", |
| 1462 | valueVar.c_str(), texFunc.c_str(), |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1463 | samplerName, coordVar.c_str(), |
| 1464 | segments->fSwizzle.c_str()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1465 | segments->fFSCode.appendf("\t\t%s += %s;\n", |
| 1466 | coordVar.c_str(), |
| 1467 | imageIncrementName); |
| 1468 | segments->fFSCode.appendf("\t}\n"); |
| 1469 | segments->fFSCode.appendf("\t%s = %s%s;\n", fsOutColor, |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1470 | valueVar.c_str(), segments->fModulate.c_str()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1471 | } |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1472 | |
| 1473 | } |
| 1474 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1475 | void GrGLProgram::genStageCode(const GrGLContextInfo& gl, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1476 | int stageNum, |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1477 | const GrGLProgram::StageDesc& desc, |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 1478 | const char* fsInColor, // NULL means no incoming color |
| 1479 | const char* fsOutColor, |
| 1480 | const char* vsInCoord, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1481 | GrGLShaderBuilder* segments, |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1482 | StageUniLocations* locations, |
| 1483 | GrGLProgramStage* customStage) const { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1484 | |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1485 | GrAssert(stageNum >= 0 && stageNum <= GrDrawState::kNumStages); |
| 1486 | GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) == |
| 1487 | desc.fInConfigFlags); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1488 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1489 | if (NULL != customStage) { |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 1490 | customStage->setupVariables(segments, stageNum); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 1493 | /// Vertex Shader Stuff |
| 1494 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1495 | // decide whether we need a matrix to transform texture coords |
| 1496 | // and whether the varying needs a perspective coord. |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1497 | const char* matName = NULL; |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1498 | if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1499 | segments->fVaryingDims = segments->fCoordDims; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1500 | } else { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1501 | GrStringBuilder texMatName; |
| 1502 | tex_matrix_name(stageNum, &texMatName); |
| 1503 | const GrGLShaderVar* mat = &segments->addUniform( |
| 1504 | GrGLShaderBuilder::kVertex_VariableLifetime, kMat33f_GrSLType, |
| 1505 | texMatName.c_str()); |
| 1506 | // Can't use texMatName.c_str() because it's on the stack! |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1507 | matName = mat->getName().c_str(); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1508 | locations->fTextureMatrixUni = kUseUniform; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1509 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1510 | if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1511 | segments->fVaryingDims = segments->fCoordDims; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1512 | } else { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1513 | segments->fVaryingDims = segments->fCoordDims + 1; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1514 | } |
| 1515 | } |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1516 | GrAssert(segments->fVaryingDims > 0); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1517 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1518 | GrStringBuilder samplerName; |
| 1519 | sampler_name(stageNum, &samplerName); |
| 1520 | const GrGLShaderVar* sampler = &segments->addUniform( |
| 1521 | GrGLShaderBuilder::kFragment_VariableLifetime, kSampler2D_GrSLType, |
| 1522 | samplerName.c_str()); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1523 | locations->fSamplerUni = kUseUniform; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1524 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1525 | const char* texelSizeName = NULL; |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1526 | if (StageDesc::k2x2_FetchMode == desc.fFetchMode) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1527 | GrStringBuilder ntsName; |
| 1528 | normalized_texel_size_name(stageNum, &ntsName); |
| 1529 | texelSizeName = segments->addUniform( |
| 1530 | GrGLShaderBuilder::kFragment_VariableLifetime, |
| 1531 | kVec2f_GrSLType, ntsName.c_str()).getName().c_str(); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1534 | const char *varyingVSName, *varyingFSName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame^] | 1535 | segments->addVarying(GrSLFloatVectorType(segments->fVaryingDims), |
| 1536 | "Stage", |
| 1537 | stageNum, |
| 1538 | &varyingVSName, |
| 1539 | &varyingFSName); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1540 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1541 | if (!matName) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1542 | GrAssert(segments->fVaryingDims == segments->fCoordDims); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1543 | segments->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1544 | } else { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1545 | // varying = texMatrix * texCoord |
| 1546 | segments->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n", |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1547 | varyingVSName, matName, vsInCoord, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1548 | vector_all_coords(segments->fVaryingDims)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1551 | const GrGLShaderVar* radial2Params = NULL; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1552 | const char* radial2VaryingVSName = NULL; |
| 1553 | const char* radial2VaryingFSName = NULL; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1554 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 1555 | if (isRadialMapping((StageDesc::CoordMapping) desc.fCoordMapping)) { |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1556 | radial2Params = genRadialVS(stageNum, segments, |
| 1557 | locations, |
| 1558 | &radial2VaryingVSName, |
| 1559 | &radial2VaryingFSName, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1560 | varyingVSName); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 1563 | GrGLShaderVar* kernel = NULL; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1564 | const char* imageIncrementName = NULL; |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1565 | if (StageDesc::kDilate_FetchMode == desc.fFetchMode || |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1566 | StageDesc::kErode_FetchMode == desc.fFetchMode) { |
| 1567 | genMorphologyVS(stageNum, desc, segments, locations, |
| 1568 | &imageIncrementName, varyingVSName); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 1569 | } |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 1570 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1571 | if (NULL != customStage) { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1572 | segments->fVSCode.appendf("\t{ // stage %d %s\n", |
| 1573 | stageNum, customStage->name()); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1574 | customStage->emitVS(segments, varyingVSName); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1575 | segments->fVSCode.appendf("\t}\n"); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1578 | /// Fragment Shader Stuff |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1579 | |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1580 | // Function used to access the shader, may be made projective. |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1581 | GrStringBuilder texFunc("texture2D"); |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1582 | if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit | |
| 1583 | StageDesc::kNoPerspective_OptFlagBit)) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1584 | GrAssert(segments->fVaryingDims == segments->fCoordDims); |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1585 | segments->fSampleCoords = varyingFSName; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1586 | } else { |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1587 | // If we have to do some special op on the varyings to get |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1588 | // our final tex coords then when in perspective we have to |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1589 | // do an explicit divide. Otherwise, we can use a Proj func. |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1590 | if (StageDesc::kIdentity_CoordMapping == desc.fCoordMapping && |
| 1591 | StageDesc::kSingle_FetchMode == desc.fFetchMode) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1592 | texFunc.append("Proj"); |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1593 | segments->fSampleCoords = varyingFSName; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1594 | } else { |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1595 | // This block is replicated in GrGLProgramStage::emitTextureLookup() |
| 1596 | segments->fSampleCoords = "inCoord"; |
| 1597 | segments->fSampleCoords.appendS32(stageNum); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1598 | segments->fFSCode.appendf("\t%s %s = %s%s / %s%s;\n", |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1599 | GrGLShaderVar::TypeString(GrSLFloatVectorType(segments->fCoordDims)), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1600 | segments->fSampleCoords.c_str(), |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1601 | varyingFSName, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1602 | GrGLSLVectorNonhomogCoords(segments->fVaryingDims), |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1603 | varyingFSName, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1604 | GrGLSLVectorHomogCoord(segments->fVaryingDims)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1608 | segments->fComplexCoord = false; |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1609 | // NOTE: GrGLProgramStages will soon responsible for mapping |
| 1610 | //if (NULL == customStage) { |
| 1611 | switch (desc.fCoordMapping) { |
| 1612 | case StageDesc::kIdentity_CoordMapping: |
| 1613 | // Do nothing |
| 1614 | break; |
| 1615 | case StageDesc::kSweepGradient_CoordMapping: |
| 1616 | segments->fSampleCoords.printf("vec2(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5, 0.5)", segments->fSampleCoords.c_str(), segments->fSampleCoords.c_str()); |
| 1617 | segments->fComplexCoord = true; |
| 1618 | break; |
| 1619 | case StageDesc::kRadialGradient_CoordMapping: |
| 1620 | segments->fSampleCoords.printf("vec2(length(%s.xy), 0.5)", segments->fSampleCoords.c_str()); |
| 1621 | segments->fComplexCoord = true; |
| 1622 | break; |
| 1623 | case StageDesc::kRadial2Gradient_CoordMapping: |
| 1624 | genRadial2GradientCoordMapping( |
| 1625 | stageNum, segments, |
| 1626 | radial2VaryingFSName, radial2Params); |
| 1627 | break; |
| 1628 | case StageDesc::kRadial2GradientDegenerate_CoordMapping: |
| 1629 | genRadial2GradientDegenerateCoordMapping( |
| 1630 | stageNum, segments, |
| 1631 | radial2VaryingFSName, radial2Params); |
| 1632 | break; |
| 1633 | } |
| 1634 | //} |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1635 | |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1636 | static const uint32_t kMulByAlphaMask = |
| 1637 | (StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag | |
| 1638 | StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag); |
| 1639 | |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1640 | segments->computeSwizzle(desc.fInConfigFlags); |
| 1641 | segments->computeModulate(fsInColor); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1642 | |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1643 | if (desc.fOptFlags & StageDesc::kCustomTextureDomain_OptFlagBit) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1644 | GrStringBuilder texDomainName; |
| 1645 | tex_domain_name(stageNum, &texDomainName); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1646 | const GrGLShaderVar* texDomain = |
| 1647 | &segments->addUniform( |
| 1648 | GrGLShaderBuilder::kFragment_VariableLifetime, |
| 1649 | kVec4f_GrSLType, texDomainName.c_str()); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1650 | GrStringBuilder coordVar("clampCoord"); |
| 1651 | segments->fFSCode.appendf("\t%s %s = clamp(%s, %s.xy, %s.zw);\n", |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1652 | float_vector_type_str(segments->fCoordDims), |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1653 | coordVar.c_str(), |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1654 | segments->fSampleCoords.c_str(), |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1655 | texDomainName.c_str(), |
| 1656 | texDomainName.c_str()); |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 1657 | segments->fSampleCoords = coordVar; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1658 | locations->fTexDomUni = kUseUniform; |
| 1659 | } |
| 1660 | |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1661 | if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit | |
| 1662 | StageDesc::kNoPerspective_OptFlagBit)) { |
| 1663 | segments->setSamplerMode(GrGLShaderBuilder::kDefault_SamplerMode); |
| 1664 | } else if (StageDesc::kIdentity_CoordMapping == desc.fCoordMapping && |
| 1665 | StageDesc::kSingle_FetchMode == desc.fFetchMode) { |
| 1666 | segments->setSamplerMode(GrGLShaderBuilder::kProj_SamplerMode); |
| 1667 | } else { |
| 1668 | segments->setSamplerMode( |
| 1669 | GrGLShaderBuilder::kExplicitDivide_SamplerMode); |
| 1670 | } |
| 1671 | |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1672 | // NOTE: GrGLProgramStages are now responsible for fetching |
| 1673 | if (NULL == customStage) { |
| 1674 | switch (desc.fFetchMode) { |
| 1675 | case StageDesc::k2x2_FetchMode: |
| 1676 | GrAssert(!(desc.fInConfigFlags & kMulByAlphaMask)); |
| 1677 | gen2x2FS(stageNum, segments, locations, |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1678 | samplerName.c_str(), texelSizeName, fsOutColor, texFunc); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | case StageDesc::kConvolution_FetchMode: |
| 1681 | GrAssert(!(desc.fInConfigFlags & kMulByAlphaMask)); |
| 1682 | break; |
| 1683 | case StageDesc::kDilate_FetchMode: |
| 1684 | case StageDesc::kErode_FetchMode: |
| 1685 | GrAssert(!(desc.fInConfigFlags & kMulByAlphaMask)); |
| 1686 | genMorphologyFS(stageNum, desc, segments, |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1687 | samplerName.c_str(), imageIncrementName, fsOutColor, texFunc); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | default: |
| 1690 | if (desc.fInConfigFlags & kMulByAlphaMask) { |
| 1691 | // only one of the mul by alpha flags should be set |
| 1692 | GrAssert(GrIsPow2(kMulByAlphaMask & desc.fInConfigFlags)); |
| 1693 | GrAssert(!(desc.fInConfigFlags & |
| 1694 | StageDesc::kSmearAlpha_InConfigFlag)); |
| 1695 | GrAssert(!(desc.fInConfigFlags & |
| 1696 | StageDesc::kSmearRed_InConfigFlag)); |
| 1697 | segments->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n", |
| 1698 | fsOutColor, texFunc.c_str(), |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1699 | samplerName.c_str(), |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1700 | segments->fSampleCoords.c_str(), |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1701 | segments->fSwizzle.c_str()); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1702 | if (desc.fInConfigFlags & |
| 1703 | StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) { |
| 1704 | segments->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n", |
| 1705 | fsOutColor, fsOutColor, fsOutColor, |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1706 | fsOutColor, segments->fModulate.c_str()); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1707 | } else { |
| 1708 | segments->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n", |
| 1709 | fsOutColor, fsOutColor, fsOutColor, |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1710 | fsOutColor, segments->fModulate.c_str()); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1711 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1712 | } else { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1713 | segments->emitDefaultFetch(fsOutColor, samplerName.c_str()); |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1714 | } |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1715 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1716 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1717 | |
| 1718 | if (NULL != customStage) { |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1719 | // Enclose custom code in a block to avoid namespace conflicts |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1720 | segments->fFSCode.appendf("\t{ // stage %d %s \n", |
| 1721 | stageNum, customStage->name()); |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 1722 | segments->emitTextureSetup(); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1723 | customStage->emitFS(segments, fsOutColor, fsInColor, |
| 1724 | samplerName.c_str()); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1725 | segments->fFSCode.appendf("\t}\n"); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1726 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1727 | } |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1728 | |
tomhudson@google.com | 5960d00 | 2011-10-19 20:21:48 +0000 | [diff] [blame] | 1729 | |