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