junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "GrGLProgram.h" |
| 9 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 10 | #include "GrAllocator.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 11 | #include "GrCustomStage.h" |
| 12 | #include "GrGLProgramStage.h" |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 13 | #include "gl/GrGLShaderBuilder.h" |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 14 | #include "GrGLShaderVar.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 15 | #include "GrProgramStageFactory.h" |
tomhudson@google.com | 0c8d93a | 2011-07-01 17:08:26 +0000 | [diff] [blame] | 16 | #include "SkTrace.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 17 | #include "SkXfermode.h" |
| 18 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 19 | SK_DEFINE_INST_COUNT(GrGLProgram) |
| 20 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 21 | #define GL_CALL(X) GR_GL_CALL(fContextInfo.interface(), X) |
| 22 | #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContextInfo.interface(), R, X) |
| 23 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 26 | enum { |
| 27 | /// Used to mark a StageUniLocation field that should be bound |
| 28 | /// to a uniform during getUniformLocationsAndInitCache(). |
| 29 | kUseUniform = 2000 |
| 30 | }; |
| 31 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 32 | } // namespace |
| 33 | |
rileya@google.com | e38160c | 2012-07-03 18:03:04 +0000 | [diff] [blame] | 34 | #define PRINT_SHADERS 0 |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 35 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 36 | typedef GrGLProgram::Desc::StageDesc StageDesc; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 37 | |
bsalomon@google.com | 341767c | 2012-05-11 20:47:39 +0000 | [diff] [blame] | 38 | #define VIEW_MATRIX_NAME "uViewM" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 39 | |
| 40 | #define POS_ATTR_NAME "aPosition" |
| 41 | #define COL_ATTR_NAME "aColor" |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 42 | #define COV_ATTR_NAME "aCoverage" |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 43 | #define EDGE_ATTR_NAME "aEdge" |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 44 | #define COL_UNI_NAME "uColor" |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 45 | #define COV_UNI_NAME "uCoverage" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 46 | #define COL_FILTER_UNI_NAME "uColorFilter" |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 47 | #define COL_MATRIX_UNI_NAME "uColorMatrix" |
| 48 | #define COL_MATRIX_VEC_UNI_NAME "uColorMatrixVec" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 50 | namespace { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 51 | inline void tex_attr_name(int coordIdx, SkString* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 52 | *s = "aTexCoord"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 53 | s->appendS32(coordIdx); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 56 | inline const char* float_vector_type_str(int count) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 57 | return GrGLShaderVar::TypeString(GrSLFloatVectorType(count)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 58 | } |
| 59 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 60 | inline const char* vector_all_coords(int count) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 61 | static const char* ALL[] = {"ERROR", "", ".xy", ".xyz", ".xyzw"}; |
| 62 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ALL)); |
| 63 | return ALL[count]; |
| 64 | } |
| 65 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 66 | inline const char* all_ones_vec(int count) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 67 | static const char* ONESVEC[] = {"ERROR", "1.0", "vec2(1,1)", |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 68 | "vec3(1,1,1)", "vec4(1,1,1,1)"}; |
| 69 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ONESVEC)); |
| 70 | return ONESVEC[count]; |
| 71 | } |
| 72 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 73 | inline const char* all_zeros_vec(int count) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 74 | static const char* ZEROSVEC[] = {"ERROR", "0.0", "vec2(0,0)", |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 75 | "vec3(0,0,0)", "vec4(0,0,0,0)"}; |
| 76 | GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ZEROSVEC)); |
| 77 | return ZEROSVEC[count]; |
| 78 | } |
| 79 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 80 | inline const char* declared_color_output_name() { return "fsColorOut"; } |
| 81 | inline const char* dual_source_output_name() { return "dualSourceOut"; } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 82 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 83 | inline void tex_matrix_name(int stage, SkString* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 84 | *s = "uTexM"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 85 | s->appendS32(stage); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 86 | } |
| 87 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 88 | inline void sampler_name(int stage, SkString* s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 89 | *s = "uSampler"; |
bsalomon@google.com | fc29629 | 2011-05-06 13:53:47 +0000 | [diff] [blame] | 90 | s->appendS32(stage); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 91 | } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 92 | } |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 93 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 94 | GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, |
| 95 | const Desc& desc, |
| 96 | GrCustomStage** customStages) { |
| 97 | GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, customStages)); |
| 98 | if (!program->succeeded()) { |
| 99 | delete program; |
| 100 | program = NULL; |
| 101 | } |
| 102 | return program; |
| 103 | } |
| 104 | |
| 105 | GrGLProgram::GrGLProgram(const GrGLContextInfo& gl, |
| 106 | const Desc& desc, |
| 107 | GrCustomStage** customStages) : fContextInfo(gl) { |
| 108 | fDesc = desc; |
| 109 | fVShaderID = 0; |
| 110 | fGShaderID = 0; |
| 111 | fFShaderID = 0; |
| 112 | fProgramID = 0; |
| 113 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 114 | fProgramStage[s] = NULL; |
| 115 | } |
| 116 | this->genProgram(customStages); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | GrGLProgram::~GrGLProgram() { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 120 | if (fVShaderID) { |
| 121 | GL_CALL(DeleteShader(fVShaderID)); |
| 122 | } |
| 123 | if (fGShaderID) { |
| 124 | GL_CALL(DeleteShader(fGShaderID)); |
| 125 | } |
| 126 | if (fFShaderID) { |
| 127 | GL_CALL(DeleteShader(fFShaderID)); |
| 128 | } |
| 129 | if (fProgramID) { |
| 130 | GL_CALL(DeleteProgram(fProgramID)); |
| 131 | } |
| 132 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 133 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| 134 | delete fProgramStage[i]; |
| 135 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 138 | void GrGLProgram::abandon() { |
| 139 | fVShaderID = 0; |
| 140 | fGShaderID = 0; |
| 141 | fFShaderID = 0; |
| 142 | fProgramID = 0; |
| 143 | } |
| 144 | |
tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 145 | void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 146 | GrBlendCoeff* dstCoeff) const { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 147 | switch (fDesc.fDualSrcOutput) { |
| 148 | case Desc::kNone_DualSrcOutput: |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 149 | break; |
| 150 | // the prog will write a coverage value to the secondary |
| 151 | // output and the dst is blended by one minus that value. |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 152 | case Desc::kCoverage_DualSrcOutput: |
| 153 | case Desc::kCoverageISA_DualSrcOutput: |
| 154 | case Desc::kCoverageISC_DualSrcOutput: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 155 | *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 156 | break; |
| 157 | default: |
| 158 | GrCrash("Unexpected dual source blend output"); |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 163 | // assigns modulation of two vars to an output var |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 164 | // vars can be vec4s or floats (or one of each) |
| 165 | // result is always vec4 |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 166 | // if either var is "" then assign to the other var |
| 167 | // if both are "" then assign all ones |
| 168 | static inline void modulate_helper(const char* outputVar, |
| 169 | const char* var0, |
| 170 | const char* var1, |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 171 | SkString* code) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 172 | GrAssert(NULL != outputVar); |
| 173 | GrAssert(NULL != var0); |
| 174 | GrAssert(NULL != var1); |
| 175 | GrAssert(NULL != code); |
| 176 | |
| 177 | bool has0 = '\0' != *var0; |
| 178 | bool has1 = '\0' != *var1; |
| 179 | |
| 180 | if (!has0 && !has1) { |
| 181 | code->appendf("\t%s = %s;\n", outputVar, all_ones_vec(4)); |
| 182 | } else if (!has0) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 183 | code->appendf("\t%s = vec4(%s);\n", outputVar, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 184 | } else if (!has1) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 185 | code->appendf("\t%s = vec4(%s);\n", outputVar, var0); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 186 | } else { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 187 | code->appendf("\t%s = vec4(%s * %s);\n", outputVar, var0, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | // assigns addition of two vars to an output var |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 192 | // vars can be vec4s or floats (or one of each) |
| 193 | // result is always vec4 |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 194 | // if either var is "" then assign to the other var |
| 195 | // if both are "" then assign all zeros |
| 196 | static inline void add_helper(const char* outputVar, |
| 197 | const char* var0, |
| 198 | const char* var1, |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 199 | SkString* code) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 200 | GrAssert(NULL != outputVar); |
| 201 | GrAssert(NULL != var0); |
| 202 | GrAssert(NULL != var1); |
| 203 | GrAssert(NULL != code); |
| 204 | |
| 205 | bool has0 = '\0' != *var0; |
| 206 | bool has1 = '\0' != *var1; |
| 207 | |
| 208 | if (!has0 && !has1) { |
| 209 | code->appendf("\t%s = %s;\n", outputVar, all_zeros_vec(4)); |
| 210 | } else if (!has0) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 211 | code->appendf("\t%s = vec4(%s);\n", outputVar, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 212 | } else if (!has1) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 213 | code->appendf("\t%s = vec4(%s);\n", outputVar, var0); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 214 | } else { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 215 | code->appendf("\t%s = vec4(%s + %s);\n", outputVar, var0, var1); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | // given two blend coeffecients determine whether the src |
| 220 | // and/or dst computation can be omitted. |
| 221 | static inline void needBlendInputs(SkXfermode::Coeff srcCoeff, |
| 222 | SkXfermode::Coeff dstCoeff, |
| 223 | bool* needSrcValue, |
| 224 | bool* needDstValue) { |
| 225 | if (SkXfermode::kZero_Coeff == srcCoeff) { |
| 226 | switch (dstCoeff) { |
| 227 | // these all read the src |
| 228 | case SkXfermode::kSC_Coeff: |
| 229 | case SkXfermode::kISC_Coeff: |
| 230 | case SkXfermode::kSA_Coeff: |
| 231 | case SkXfermode::kISA_Coeff: |
| 232 | *needSrcValue = true; |
| 233 | break; |
| 234 | default: |
| 235 | *needSrcValue = false; |
| 236 | break; |
| 237 | } |
| 238 | } else { |
| 239 | *needSrcValue = true; |
| 240 | } |
| 241 | if (SkXfermode::kZero_Coeff == dstCoeff) { |
| 242 | switch (srcCoeff) { |
| 243 | // these all read the dst |
| 244 | case SkXfermode::kDC_Coeff: |
| 245 | case SkXfermode::kIDC_Coeff: |
| 246 | case SkXfermode::kDA_Coeff: |
| 247 | case SkXfermode::kIDA_Coeff: |
| 248 | *needDstValue = true; |
| 249 | break; |
| 250 | default: |
| 251 | *needDstValue = false; |
| 252 | break; |
| 253 | } |
| 254 | } else { |
| 255 | *needDstValue = true; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| 259 | /** |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 260 | * Create a blend_coeff * value string to be used in shader code. Sets empty |
| 261 | * string if result is trivially zero. |
| 262 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 263 | static void blendTermString(SkString* str, SkXfermode::Coeff coeff, |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 264 | const char* src, const char* dst, |
| 265 | const char* value) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 266 | switch (coeff) { |
| 267 | case SkXfermode::kZero_Coeff: /** 0 */ |
| 268 | *str = ""; |
| 269 | break; |
| 270 | case SkXfermode::kOne_Coeff: /** 1 */ |
| 271 | *str = value; |
| 272 | break; |
| 273 | case SkXfermode::kSC_Coeff: |
| 274 | str->printf("(%s * %s)", src, value); |
| 275 | break; |
| 276 | case SkXfermode::kISC_Coeff: |
| 277 | str->printf("((%s - %s) * %s)", all_ones_vec(4), src, value); |
| 278 | break; |
| 279 | case SkXfermode::kDC_Coeff: |
| 280 | str->printf("(%s * %s)", dst, value); |
| 281 | break; |
| 282 | case SkXfermode::kIDC_Coeff: |
| 283 | str->printf("((%s - %s) * %s)", all_ones_vec(4), dst, value); |
| 284 | break; |
| 285 | case SkXfermode::kSA_Coeff: /** src alpha */ |
| 286 | str->printf("(%s.a * %s)", src, value); |
| 287 | break; |
| 288 | case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */ |
| 289 | str->printf("((1.0 - %s.a) * %s)", src, value); |
| 290 | break; |
| 291 | case SkXfermode::kDA_Coeff: /** dst alpha */ |
| 292 | str->printf("(%s.a * %s)", dst, value); |
| 293 | break; |
| 294 | case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */ |
| 295 | str->printf("((1.0 - %s.a) * %s)", dst, value); |
| 296 | break; |
| 297 | default: |
| 298 | GrCrash("Unexpected xfer coeff."); |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | /** |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 303 | * Adds a line to the fragment shader code which modifies the color by |
| 304 | * the specified color filter. |
| 305 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 306 | static void addColorFilter(SkString* fsCode, const char * outputVar, |
tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 307 | SkXfermode::Coeff uniformCoeff, |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 308 | SkXfermode::Coeff colorCoeff, |
| 309 | const char* inColor) { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 310 | SkString colorStr, constStr; |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 311 | blendTermString(&colorStr, colorCoeff, COL_FILTER_UNI_NAME, |
| 312 | inColor, inColor); |
| 313 | blendTermString(&constStr, uniformCoeff, COL_FILTER_UNI_NAME, |
| 314 | inColor, COL_FILTER_UNI_NAME); |
| 315 | |
| 316 | add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 317 | } |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 318 | /** |
| 319 | * Adds code to the fragment shader code which modifies the color by |
| 320 | * the specified color matrix. |
| 321 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 322 | static void addColorMatrix(SkString* fsCode, const char * outputVar, |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 323 | const char* inColor) { |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 324 | fsCode->appendf("\t%s = %s * vec4(%s.rgb / %s.a, %s.a) + %s;\n", outputVar, COL_MATRIX_UNI_NAME, inColor, inColor, inColor, COL_MATRIX_VEC_UNI_NAME); |
| 325 | fsCode->appendf("\t%s.rgb *= %s.a;\n", outputVar, outputVar); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 326 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 327 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 328 | void GrGLProgram::genEdgeCoverage(SkString* coverageVar, |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 329 | GrGLShaderBuilder* segments) const { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 330 | if (fDesc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 331 | const char *vsName, *fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 332 | segments->addVarying(kVec4f_GrSLType, "Edge", &vsName, &fsName); |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 333 | segments->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 334 | GrGLShaderVar::kAttribute_TypeModifier, EDGE_ATTR_NAME); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 335 | segments->fVSCode.appendf("\t%s = " EDGE_ATTR_NAME ";\n", vsName); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 336 | switch (fDesc.fVertexEdgeType) { |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 337 | case GrDrawState::kHairLine_EdgeType: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 338 | segments->fFSCode.appendf("\tfloat edgeAlpha = abs(dot(vec3(gl_FragCoord.xy,1), %s.xyz));\n", fsName); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 339 | segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 340 | break; |
| 341 | case GrDrawState::kQuad_EdgeType: |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 342 | segments->fFSCode.append("\tfloat edgeAlpha;\n"); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 343 | // keep the derivative instructions outside the conditional |
| 344 | segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 345 | segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
| 346 | segments->fFSCode.appendf("\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsName, fsName); |
| 347 | // today we know z and w are in device space. We could use derivatives |
| 348 | segments->fFSCode.appendf("\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);\n", fsName, fsName); |
| 349 | segments->fFSCode.append ("\t} else {\n"); |
| 350 | segments->fFSCode.appendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" |
| 351 | "\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n", |
| 352 | fsName, fsName); |
| 353 | segments->fFSCode.appendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); |
vandebo@chromium.org | b9682d3 | 2012-02-21 18:53:39 +0000 | [diff] [blame] | 354 | segments->fFSCode.append("\t\tedgeAlpha = clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n" |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 355 | "\t}\n"); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 356 | if (kES2_GrGLBinding == fContextInfo.binding()) { |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 357 | segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); |
| 358 | } |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 359 | break; |
| 360 | case GrDrawState::kHairQuad_EdgeType: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 361 | segments->fFSCode.appendf("\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
| 362 | segments->fFSCode.appendf("\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 363 | segments->fFSCode.appendf("\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" |
| 364 | "\t 2.0*%s.x*duvdy.x - duvdy.y);\n", |
| 365 | fsName, fsName); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 366 | segments->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName); |
bsalomon@google.com | 9aed114 | 2012-01-30 14:28:39 +0000 | [diff] [blame] | 367 | segments->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n"); |
| 368 | segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n"); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 369 | if (kES2_GrGLBinding == fContextInfo.binding()) { |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 370 | segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n"); |
| 371 | } |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 372 | break; |
| 373 | case GrDrawState::kCircle_EdgeType: |
| 374 | segments->fFSCode.append("\tfloat edgeAlpha;\n"); |
| 375 | segments->fFSCode.appendf("\tfloat d = distance(gl_FragCoord.xy, %s.xy);\n", fsName); |
| 376 | segments->fFSCode.appendf("\tfloat outerAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName); |
| 377 | segments->fFSCode.appendf("\tfloat innerAlpha = %s.w == 0.0 ? 1.0 : smoothstep(%s.w - 0.5, %s.w + 0.5, d);\n", fsName, fsName, fsName); |
| 378 | segments->fFSCode.append("\tedgeAlpha = outerAlpha * innerAlpha;\n"); |
| 379 | break; |
| 380 | default: |
| 381 | GrCrash("Unknown Edge Type!"); |
| 382 | break; |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 383 | } |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 384 | *coverageVar = "edgeAlpha"; |
| 385 | } else { |
| 386 | coverageVar->reset(); |
| 387 | } |
| 388 | } |
| 389 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 390 | void GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString* inColor) { |
| 391 | switch (fDesc.fColorInput) { |
| 392 | case GrGLProgram::Desc::kAttribute_ColorInput: { |
| 393 | builder->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 394 | GrGLShaderVar::kAttribute_TypeModifier, |
| 395 | COL_ATTR_NAME); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 396 | const char *vsName, *fsName; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 397 | builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); |
| 398 | builder->fVSCode.appendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 399 | *inColor = fsName; |
| 400 | } break; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 401 | case GrGLProgram::Desc::kUniform_ColorInput: |
| 402 | builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 403 | kVec4f_GrSLType, COL_UNI_NAME); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 404 | fUniLocations.fColorUni = kUseUniform; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 405 | *inColor = COL_UNI_NAME; |
| 406 | break; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 407 | case GrGLProgram::Desc::kTransBlack_ColorInput: |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 408 | GrAssert(!"needComputedColor should be false."); |
| 409 | break; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 410 | case GrGLProgram::Desc::kSolidWhite_ColorInput: |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 411 | break; |
| 412 | default: |
| 413 | GrCrash("Unknown color type."); |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 418 | void GrGLProgram::genUniformCoverage(GrGLShaderBuilder* builder, SkString* inOutCoverage) { |
| 419 | builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 420 | kVec4f_GrSLType, COV_UNI_NAME); |
| 421 | fUniLocations.fCoverageUni = kUseUniform; |
| 422 | if (inOutCoverage->size()) { |
| 423 | builder->fFSCode.appendf("\tvec4 uniCoverage = %s * %s;\n", |
| 424 | COV_UNI_NAME, inOutCoverage->c_str()); |
| 425 | *inOutCoverage = "uniCoverage"; |
| 426 | } else { |
| 427 | *inOutCoverage = COV_UNI_NAME; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | namespace { |
| 432 | void gen_attribute_coverage(GrGLShaderBuilder* segments, |
| 433 | SkString* inOutCoverage) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 434 | segments->fVSAttrs.push_back().set(kVec4f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 435 | GrGLShaderVar::kAttribute_TypeModifier, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 436 | COV_ATTR_NAME); |
| 437 | const char *vsName, *fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 438 | segments->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &fsName); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 439 | segments->fVSCode.appendf("\t%s = " COV_ATTR_NAME ";\n", vsName); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 440 | if (inOutCoverage->size()) { |
| 441 | segments->fFSCode.appendf("\tvec4 attrCoverage = %s * %s;\n", |
| 442 | fsName, inOutCoverage->c_str()); |
| 443 | *inOutCoverage = "attrCoverage"; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 444 | } else { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 445 | *inOutCoverage = fsName; |
| 446 | } |
| 447 | } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 448 | } |
| 449 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 450 | void GrGLProgram::genGeometryShader(GrGLShaderBuilder* segments) const { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 451 | #if GR_GL_EXPERIMENTAL_GS |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 452 | if (fDesc.fExperimentalGS) { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 453 | GrAssert(fContextInfo.glslGeneration() >= k150_GrGLSLGeneration); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 454 | segments->fGSHeader.append("layout(triangles) in;\n" |
| 455 | "layout(triangle_strip, max_vertices = 6) out;\n"); |
| 456 | segments->fGSCode.append("void main() {\n" |
| 457 | "\tfor (int i = 0; i < 3; ++i) {\n" |
| 458 | "\t\tgl_Position = gl_in[i].gl_Position;\n"); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 459 | if (fDesc.fEmitsPointSize) { |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 460 | segments->fGSCode.append("\t\tgl_PointSize = 1.0;\n"); |
| 461 | } |
| 462 | GrAssert(segments->fGSInputs.count() == segments->fGSOutputs.count()); |
| 463 | int count = segments->fGSInputs.count(); |
| 464 | for (int i = 0; i < count; ++i) { |
| 465 | segments->fGSCode.appendf("\t\t%s = %s[i];\n", |
| 466 | segments->fGSOutputs[i].getName().c_str(), |
| 467 | segments->fGSInputs[i].getName().c_str()); |
| 468 | } |
| 469 | segments->fGSCode.append("\t\tEmitVertex();\n" |
| 470 | "\t}\n" |
| 471 | "\tEndPrimitive();\n" |
| 472 | "}\n"); |
| 473 | } |
| 474 | #endif |
| 475 | } |
| 476 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 477 | const char* GrGLProgram::adjustInColor(const SkString& inColor) const { |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 478 | if (inColor.size()) { |
| 479 | return inColor.c_str(); |
| 480 | } else { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 481 | if (Desc::kSolidWhite_ColorInput == fDesc.fColorInput) { |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 482 | return all_ones_vec(4); |
| 483 | } else { |
| 484 | return all_zeros_vec(4); |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 489 | namespace { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 490 | // prints a shader using params similar to glShaderSource |
| 491 | void print_shader(GrGLint stringCnt, |
| 492 | const GrGLchar** strings, |
| 493 | GrGLint* stringLengths) { |
| 494 | for (int i = 0; i < stringCnt; ++i) { |
| 495 | if (NULL == stringLengths || stringLengths[i] < 0) { |
| 496 | GrPrintf(strings[i]); |
| 497 | } else { |
| 498 | GrPrintf("%.*s", stringLengths[i], strings[i]); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | // Compiles a GL shader, returns shader ID or 0 if failed params have same meaning as glShaderSource |
| 504 | GrGLuint compile_shader(const GrGLContextInfo& gl, |
| 505 | GrGLenum type, |
| 506 | int stringCnt, |
| 507 | const char** strings, |
| 508 | int* stringLengths) { |
| 509 | SK_TRACE_EVENT1("GrGLProgram::CompileShader", |
| 510 | "stringCount", SkStringPrintf("%i", stringCnt).c_str()); |
| 511 | |
| 512 | GrGLuint shader; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 513 | GR_GL_CALL_RET(gl.interface(), shader, CreateShader(type)); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 514 | if (0 == shader) { |
| 515 | return 0; |
| 516 | } |
| 517 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 518 | const GrGLInterface* gli = gl.interface(); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 519 | GrGLint compiled = GR_GL_INIT_ZERO; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 520 | GR_GL_CALL(gli, ShaderSource(shader, stringCnt, strings, stringLengths)); |
| 521 | GR_GL_CALL(gli, CompileShader(shader)); |
| 522 | GR_GL_CALL(gli, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled)); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 523 | |
| 524 | if (!compiled) { |
| 525 | GrGLint infoLen = GR_GL_INIT_ZERO; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 526 | GR_GL_CALL(gli, GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 527 | SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
| 528 | if (infoLen > 0) { |
| 529 | // retrieve length even though we don't need it to workaround bug in chrome cmd buffer |
| 530 | // param validation. |
| 531 | GrGLsizei length = GR_GL_INIT_ZERO; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 532 | GR_GL_CALL(gli, GetShaderInfoLog(shader, infoLen+1, |
| 533 | &length, (char*)log.get())); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 534 | print_shader(stringCnt, strings, stringLengths); |
| 535 | GrPrintf("\n%s", log.get()); |
| 536 | } |
| 537 | GrAssert(!"Shader compilation failed!"); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 538 | GR_GL_CALL(gli, DeleteShader(shader)); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | return shader; |
| 542 | } |
| 543 | |
| 544 | // helper version of above for when shader is already flattened into a single SkString |
| 545 | GrGLuint compile_shader(const GrGLContextInfo& gl, GrGLenum type, const SkString& shader) { |
| 546 | const GrGLchar* str = shader.c_str(); |
| 547 | int length = shader.size(); |
| 548 | return compile_shader(gl, type, 1, &str, &length); |
| 549 | } |
| 550 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // compiles all the shaders from builder and stores the shader IDs |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 554 | bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 555 | |
| 556 | SkString shader; |
| 557 | |
| 558 | builder.getShader(GrGLShaderBuilder::kVertex_ShaderType, &shader); |
| 559 | #if PRINT_SHADERS |
| 560 | GrPrintf(shader.c_str()); |
| 561 | GrPrintf("\n"); |
| 562 | #endif |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 563 | if (!(fVShaderID = compile_shader(fContextInfo, GR_GL_VERTEX_SHADER, shader))) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 564 | return false; |
| 565 | } |
| 566 | |
| 567 | if (builder.fUsesGS) { |
| 568 | builder.getShader(GrGLShaderBuilder::kGeometry_ShaderType, &shader); |
| 569 | #if PRINT_SHADERS |
| 570 | GrPrintf(shader.c_str()); |
| 571 | GrPrintf("\n"); |
| 572 | #endif |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 573 | if (!(fGShaderID = compile_shader(fContextInfo, GR_GL_GEOMETRY_SHADER, shader))) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 574 | return false; |
| 575 | } |
| 576 | } else { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 577 | fGShaderID = 0; |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | builder.getShader(GrGLShaderBuilder::kFragment_ShaderType, &shader); |
| 581 | #if PRINT_SHADERS |
| 582 | GrPrintf(shader.c_str()); |
| 583 | GrPrintf("\n"); |
| 584 | #endif |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 585 | if (!(fFShaderID = compile_shader(fContextInfo, GR_GL_FRAGMENT_SHADER, shader))) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 586 | return false; |
| 587 | } |
| 588 | |
| 589 | return true; |
| 590 | } |
| 591 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 592 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 593 | bool GrGLProgram::genProgram(GrCustomStage** customStages) { |
| 594 | GrAssert(0 == fProgramID); |
| 595 | |
| 596 | GrGLShaderBuilder builder(fContextInfo); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 597 | const uint32_t& layout = fDesc.fVertexLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 598 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 599 | fUniLocations.reset(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 600 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 601 | #if GR_GL_EXPERIMENTAL_GS |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 602 | builder.fUsesGS = fDesc.fExperimentalGS; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 603 | #endif |
| 604 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 605 | SkXfermode::Coeff colorCoeff, uniformCoeff; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 606 | bool applyColorMatrix = SkToBool(fDesc.fColorMatrixEnabled); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 607 | // The rest of transfer mode color filters have not been implemented |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 608 | if (fDesc.fColorFilterXfermode < SkXfermode::kCoeffModesCnt) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 609 | GR_DEBUGCODE(bool success =) |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 610 | SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode> |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 611 | (fDesc.fColorFilterXfermode), |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 612 | &uniformCoeff, &colorCoeff); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 613 | GR_DEBUGASSERT(success); |
| 614 | } else { |
| 615 | colorCoeff = SkXfermode::kOne_Coeff; |
| 616 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 617 | } |
| 618 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 619 | // no need to do the color filter / matrix at all if coverage is 0. The |
| 620 | // output color is scaled by the coverage. All the dual source outputs are |
| 621 | // scaled by the coverage as well. |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 622 | if (Desc::kTransBlack_ColorInput == fDesc.fCoverageInput) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 623 | colorCoeff = SkXfermode::kZero_Coeff; |
| 624 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 625 | applyColorMatrix = false; |
| 626 | } |
| 627 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 628 | // If we know the final color is going to be all zeros then we can |
| 629 | // simplify the color filter coeffecients. needComputedColor will then |
| 630 | // come out false below. |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 631 | if (Desc::kTransBlack_ColorInput == fDesc.fColorInput) { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 632 | colorCoeff = SkXfermode::kZero_Coeff; |
| 633 | if (SkXfermode::kDC_Coeff == uniformCoeff || |
| 634 | SkXfermode::kDA_Coeff == uniformCoeff) { |
| 635 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 636 | } else if (SkXfermode::kIDC_Coeff == uniformCoeff || |
| 637 | SkXfermode::kIDA_Coeff == uniformCoeff) { |
| 638 | uniformCoeff = SkXfermode::kOne_Coeff; |
| 639 | } |
| 640 | } |
| 641 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 642 | bool needColorFilterUniform; |
| 643 | bool needComputedColor; |
| 644 | needBlendInputs(uniformCoeff, colorCoeff, |
| 645 | &needColorFilterUniform, &needComputedColor); |
| 646 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 647 | // the dual source output has no canonical var name, have to |
| 648 | // declare an output, which is incompatible with gl_FragColor/gl_FragData. |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 649 | bool dualSourceOutputWritten = false; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 650 | builder.fHeader.append(GrGetGLSLVersionDecl(fContextInfo.binding(), |
| 651 | fContextInfo.glslGeneration())); |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 652 | |
| 653 | GrGLShaderVar colorOutput; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 654 | bool isColorDeclared = GrGLSLSetupFSColorOuput(fContextInfo.glslGeneration(), |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 655 | declared_color_output_name(), |
| 656 | &colorOutput); |
| 657 | if (isColorDeclared) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 658 | builder.fFSOutputs.push_back(colorOutput); |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 659 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 660 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 661 | builder.addUniform(GrGLShaderBuilder::kVertex_ShaderType, |
| 662 | kMat33f_GrSLType, VIEW_MATRIX_NAME); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 663 | fUniLocations.fViewMatrixUni = kUseUniform; |
bsalomon@google.com | 341767c | 2012-05-11 20:47:39 +0000 | [diff] [blame] | 664 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 665 | builder.fVSAttrs.push_back().set(kVec2f_GrSLType, |
| 666 | GrGLShaderVar::kAttribute_TypeModifier, |
| 667 | POS_ATTR_NAME); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 668 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 669 | builder.fVSCode.append("void main() {\n" |
| 670 | "\tvec3 pos3 = " VIEW_MATRIX_NAME " * vec3("POS_ATTR_NAME", 1);\n" |
| 671 | "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n"); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 672 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 673 | // incoming color to current stage being processed. |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 674 | SkString inColor; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 675 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 676 | if (needComputedColor) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 677 | this->genInputColor(&builder, &inColor); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 678 | } |
| 679 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 680 | // we output point size in the GS if present |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 681 | if (fDesc.fEmitsPointSize && !builder.fUsesGS){ |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 682 | builder.fVSCode.append("\tgl_PointSize = 1.0;\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 683 | } |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 684 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 685 | builder.fFSCode.append("void main() {\n"); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 686 | |
| 687 | // add texture coordinates that are used to the list of vertex attr decls |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 688 | SkString texCoordAttrs[GrDrawState::kMaxTexCoords]; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 689 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 690 | if (GrDrawTarget::VertexUsesTexCoordIdx(t, layout)) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 691 | tex_attr_name(t, texCoordAttrs + t); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 692 | builder.fVSAttrs.push_back().set(kVec2f_GrSLType, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 693 | GrGLShaderVar::kAttribute_TypeModifier, |
| 694 | texCoordAttrs[t].c_str()); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 698 | /////////////////////////////////////////////////////////////////////////// |
| 699 | // compute the final color |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 700 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 701 | // if we have color stages string them together, feeding the output color |
| 702 | // of each to the next and generating code for each stage. |
| 703 | if (needComputedColor) { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 704 | SkString outColor; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 705 | for (int s = 0; s < fDesc.fFirstCoverageStage; ++s) { |
| 706 | if (fDesc.fStages[s].isEnabled()) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 707 | // create var to hold stage result |
| 708 | outColor = "color"; |
| 709 | outColor.appendS32(s); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 710 | builder.fFSCode.appendf("\tvec4 %s;\n", outColor.c_str()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 711 | |
| 712 | const char* inCoords; |
| 713 | // figure out what our input coords are |
tomhudson@google.com | b213ed8 | 2012-06-25 15:22:12 +0000 | [diff] [blame] | 714 | int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout); |
| 715 | if (tcIdx < 0) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 716 | inCoords = POS_ATTR_NAME; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 717 | } else { |
tomhudson@google.com | b213ed8 | 2012-06-25 15:22:12 +0000 | [diff] [blame] | 718 | // must have input tex coordinates if stage is enabled. |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 719 | GrAssert(texCoordAttrs[tcIdx].size()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 720 | inCoords = texCoordAttrs[tcIdx].c_str(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 721 | } |
| 722 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 723 | if (NULL != customStages[s]) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 724 | const GrProgramStageFactory& factory = customStages[s]->getFactory(); |
| 725 | fProgramStage[s] = factory.createGLInstance(*customStages[s]); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 726 | } |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 727 | this->genStageCode(s, |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 728 | inColor.size() ? inColor.c_str() : NULL, |
| 729 | outColor.c_str(), |
| 730 | inCoords, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 731 | &builder); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 732 | inColor = outColor; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 733 | } |
| 734 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 735 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 736 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 737 | // if have all ones or zeros for the "dst" input to the color filter then we |
| 738 | // may be able to make additional optimizations. |
| 739 | if (needColorFilterUniform && needComputedColor && !inColor.size()) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 740 | GrAssert(Desc::kSolidWhite_ColorInput == fDesc.fColorInput); |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 741 | bool uniformCoeffIsZero = SkXfermode::kIDC_Coeff == uniformCoeff || |
| 742 | SkXfermode::kIDA_Coeff == uniformCoeff; |
| 743 | if (uniformCoeffIsZero) { |
| 744 | uniformCoeff = SkXfermode::kZero_Coeff; |
| 745 | bool bogus; |
| 746 | needBlendInputs(SkXfermode::kZero_Coeff, colorCoeff, |
| 747 | &needColorFilterUniform, &bogus); |
| 748 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 749 | } |
| 750 | if (needColorFilterUniform) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 751 | builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 752 | kVec4f_GrSLType, COL_FILTER_UNI_NAME); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 753 | fUniLocations.fColorFilterUni = kUseUniform; |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 754 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 755 | bool wroteFragColorZero = false; |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 756 | if (SkXfermode::kZero_Coeff == uniformCoeff && |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 757 | SkXfermode::kZero_Coeff == colorCoeff && |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 758 | !applyColorMatrix) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 759 | builder.fFSCode.appendf("\t%s = %s;\n", |
| 760 | colorOutput.getName().c_str(), |
| 761 | all_zeros_vec(4)); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 762 | wroteFragColorZero = true; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 763 | } else if (SkXfermode::kDst_Mode != fDesc.fColorFilterXfermode) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 764 | builder.fFSCode.append("\tvec4 filteredColor;\n"); |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 765 | const char* color = adjustInColor(inColor); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 766 | addColorFilter(&builder.fFSCode, "filteredColor", uniformCoeff, |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 767 | colorCoeff, color); |
| 768 | inColor = "filteredColor"; |
| 769 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 770 | if (applyColorMatrix) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 771 | builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 772 | kMat44f_GrSLType, COL_MATRIX_UNI_NAME); |
| 773 | builder.addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 774 | kVec4f_GrSLType, COL_MATRIX_VEC_UNI_NAME); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 775 | fUniLocations.fColorMatrixUni = kUseUniform; |
| 776 | fUniLocations.fColorMatrixVecUni = kUseUniform; |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 777 | builder.fFSCode.append("\tvec4 matrixedColor;\n"); |
senorblanco@chromium.org | b3a39b5 | 2012-01-05 18:28:56 +0000 | [diff] [blame] | 778 | const char* color = adjustInColor(inColor); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 779 | addColorMatrix(&builder.fFSCode, "matrixedColor", color); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 780 | inColor = "matrixedColor"; |
| 781 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 782 | |
| 783 | /////////////////////////////////////////////////////////////////////////// |
| 784 | // compute the partial coverage (coverage stages and edge aa) |
| 785 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 786 | SkString inCoverage; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 787 | bool coverageIsZero = Desc::kTransBlack_ColorInput == fDesc.fCoverageInput; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 788 | // we don't need to compute coverage at all if we know the final shader |
| 789 | // output will be zero and we don't have a dual src blend output. |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 790 | if (!wroteFragColorZero || Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 791 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 792 | if (!coverageIsZero) { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 793 | this->genEdgeCoverage(&inCoverage, &builder); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 794 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 795 | switch (fDesc.fCoverageInput) { |
| 796 | case Desc::kSolidWhite_ColorInput: |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 797 | // empty string implies solid white |
| 798 | break; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 799 | case Desc::kAttribute_ColorInput: |
| 800 | gen_attribute_coverage(&builder, &inCoverage); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 801 | break; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 802 | case Desc::kUniform_ColorInput: |
| 803 | this->genUniformCoverage(&builder, &inCoverage); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 804 | break; |
| 805 | default: |
| 806 | GrCrash("Unexpected input coverage."); |
| 807 | } |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 808 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 809 | SkString outCoverage; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 810 | const int& startStage = fDesc.fFirstCoverageStage; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 811 | for (int s = startStage; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 812 | if (fDesc.fStages[s].isEnabled()) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 813 | // create var to hold stage output |
| 814 | outCoverage = "coverage"; |
| 815 | outCoverage.appendS32(s); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 816 | builder.fFSCode.appendf("\tvec4 %s;\n", |
| 817 | outCoverage.c_str()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 818 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 819 | const char* inCoords; |
| 820 | // figure out what our input coords are |
tomhudson@google.com | b213ed8 | 2012-06-25 15:22:12 +0000 | [diff] [blame] | 821 | int tcIdx = |
| 822 | GrDrawTarget::VertexTexCoordsForStage(s, layout); |
| 823 | if (tcIdx < 0) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 824 | inCoords = POS_ATTR_NAME; |
| 825 | } else { |
tomhudson@google.com | b213ed8 | 2012-06-25 15:22:12 +0000 | [diff] [blame] | 826 | // must have input tex coordinates if stage is |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 827 | // enabled. |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 828 | GrAssert(texCoordAttrs[tcIdx].size()); |
| 829 | inCoords = texCoordAttrs[tcIdx].c_str(); |
| 830 | } |
| 831 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 832 | if (NULL != customStages[s]) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 833 | const GrProgramStageFactory& factory = customStages[s]->getFactory(); |
| 834 | fProgramStage[s] = factory.createGLInstance(*customStages[s]); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 835 | } |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 836 | this->genStageCode(s, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 837 | inCoverage.size() ? inCoverage.c_str() : NULL, |
| 838 | outCoverage.c_str(), |
| 839 | inCoords, |
| 840 | &builder); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 841 | inCoverage = outCoverage; |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 842 | } |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 843 | } |
| 844 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 845 | if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 846 | builder.fFSOutputs.push_back().set(kVec4f_GrSLType, |
| 847 | GrGLShaderVar::kOut_TypeModifier, |
| 848 | dual_source_output_name()); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 849 | bool outputIsZero = coverageIsZero; |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 850 | SkString coeff; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 851 | if (!outputIsZero && |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 852 | Desc::kCoverage_DualSrcOutput != fDesc.fDualSrcOutput && !wroteFragColorZero) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 853 | if (!inColor.size()) { |
| 854 | outputIsZero = true; |
| 855 | } else { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 856 | if (Desc::kCoverageISA_DualSrcOutput == fDesc.fDualSrcOutput) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 857 | coeff.printf("(1 - %s.a)", inColor.c_str()); |
| 858 | } else { |
| 859 | coeff.printf("(vec4(1,1,1,1) - %s)", inColor.c_str()); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | if (outputIsZero) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 864 | builder.fFSCode.appendf("\t%s = %s;\n", |
| 865 | dual_source_output_name(), |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 866 | all_zeros_vec(4)); |
| 867 | } else { |
| 868 | modulate_helper(dual_source_output_name(), |
| 869 | coeff.c_str(), |
| 870 | inCoverage.c_str(), |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 871 | &builder.fFSCode); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 872 | } |
| 873 | dualSourceOutputWritten = true; |
| 874 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 875 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 876 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 877 | /////////////////////////////////////////////////////////////////////////// |
| 878 | // combine color and coverage as frag color |
| 879 | |
| 880 | if (!wroteFragColorZero) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 881 | if (coverageIsZero) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 882 | builder.fFSCode.appendf("\t%s = %s;\n", |
| 883 | colorOutput.getName().c_str(), |
| 884 | all_zeros_vec(4)); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 885 | } else { |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 886 | modulate_helper(colorOutput.getName().c_str(), |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 887 | inColor.c_str(), |
| 888 | inCoverage.c_str(), |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 889 | &builder.fFSCode); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 890 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 891 | if (Desc::kUnpremultiplied_RoundDown_OutputConfig == fDesc.fOutputConfig) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 892 | builder.fFSCode.appendf("\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.rgb / %s.a * 255.0)/255.0, %s.a);\n", |
| 893 | colorOutput.getName().c_str(), |
| 894 | colorOutput.getName().c_str(), |
| 895 | colorOutput.getName().c_str(), |
| 896 | colorOutput.getName().c_str(), |
| 897 | colorOutput.getName().c_str()); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 898 | } else if (Desc::kUnpremultiplied_RoundUp_OutputConfig == fDesc.fOutputConfig) { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 899 | builder.fFSCode.appendf("\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.rgb / %s.a * 255.0)/255.0, %s.a);\n", |
| 900 | colorOutput.getName().c_str(), |
| 901 | colorOutput.getName().c_str(), |
| 902 | colorOutput.getName().c_str(), |
| 903 | colorOutput.getName().c_str(), |
| 904 | colorOutput.getName().c_str()); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 905 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 906 | } |
| 907 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 908 | builder.fVSCode.append("}\n"); |
| 909 | builder.fFSCode.append("}\n"); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 910 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 911 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 912 | // insert GS |
| 913 | #if GR_DEBUG |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 914 | this->genGeometryShader(&builder); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 915 | #endif |
| 916 | |
| 917 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 918 | // compile and setup attribs and unis |
| 919 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 920 | if (!this->compileShaders(builder)) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 921 | return false; |
| 922 | } |
| 923 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 924 | if (!this->bindOutputsAttribsAndLinkProgram(texCoordAttrs, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 925 | isColorDeclared, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 926 | dualSourceOutputWritten)) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 927 | return false; |
| 928 | } |
| 929 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 930 | this->getUniformLocationsAndInitCache(builder); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 931 | |
| 932 | return true; |
| 933 | } |
| 934 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 935 | bool GrGLProgram::bindOutputsAttribsAndLinkProgram(SkString texCoordAttrNames[], |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 936 | bool bindColorOut, |
| 937 | bool bindDualSrcOut) { |
| 938 | GL_CALL_RET(fProgramID, CreateProgram()); |
| 939 | if (!fProgramID) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 940 | return false; |
| 941 | } |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 942 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 943 | GL_CALL(AttachShader(fProgramID, fVShaderID)); |
| 944 | if (fGShaderID) { |
| 945 | GL_CALL(AttachShader(fProgramID, fGShaderID)); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 946 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 947 | GL_CALL(AttachShader(fProgramID, fFShaderID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 948 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 949 | if (bindColorOut) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 950 | GL_CALL(BindFragDataLocation(fProgramID, 0, declared_color_output_name())); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 951 | } |
| 952 | if (bindDualSrcOut) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 953 | GL_CALL(BindFragDataLocationIndexed(fProgramID, 0, 1, dual_source_output_name())); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 954 | } |
| 955 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 956 | // Bind the attrib locations to same values for all shaders |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 957 | GL_CALL(BindAttribLocation(fProgramID, PositionAttributeIdx(), POS_ATTR_NAME)); |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 958 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 959 | if (texCoordAttrNames[t].size()) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 960 | GL_CALL(BindAttribLocation(fProgramID, |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 961 | TexCoordAttributeIdx(t), |
| 962 | texCoordAttrNames[t].c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 966 | GL_CALL(BindAttribLocation(fProgramID, ColorAttributeIdx(), COL_ATTR_NAME)); |
| 967 | GL_CALL(BindAttribLocation(fProgramID, CoverageAttributeIdx(), COV_ATTR_NAME)); |
| 968 | GL_CALL(BindAttribLocation(fProgramID, EdgeAttributeIdx(), EDGE_ATTR_NAME)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 969 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 970 | GL_CALL(LinkProgram(fProgramID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 971 | |
| 972 | GrGLint linked = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 973 | GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 974 | if (!linked) { |
| 975 | GrGLint infoLen = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 976 | GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 977 | SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 978 | if (infoLen > 0) { |
bsalomon@google.com | 79afcaa | 2011-09-14 14:29:18 +0000 | [diff] [blame] | 979 | // retrieve length even though we don't need it to workaround |
| 980 | // bug in chrome cmd buffer param validation. |
| 981 | GrGLsizei length = GR_GL_INIT_ZERO; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 982 | GL_CALL(GetProgramInfoLog(fProgramID, |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 983 | infoLen+1, |
| 984 | &length, |
| 985 | (char*)log.get())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 986 | GrPrintf((char*)log.get()); |
| 987 | } |
| 988 | GrAssert(!"Error linking program"); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 989 | GL_CALL(DeleteProgram(fProgramID)); |
| 990 | fProgramID = 0; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 991 | return false; |
| 992 | } |
| 993 | return true; |
| 994 | } |
| 995 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 996 | void GrGLProgram::getUniformLocationsAndInitCache(const GrGLShaderBuilder& builder) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 997 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 998 | if (kUseUniform == fUniLocations.fViewMatrixUni) { |
| 999 | GL_CALL_RET(fUniLocations.fViewMatrixUni, GetUniformLocation(fProgramID, VIEW_MATRIX_NAME)); |
| 1000 | GrAssert(kUnusedUniform != fUniLocations.fViewMatrixUni); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1001 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1002 | if (kUseUniform == fUniLocations.fColorUni) { |
| 1003 | GL_CALL_RET(fUniLocations.fColorUni, GetUniformLocation(fProgramID, COL_UNI_NAME)); |
| 1004 | GrAssert(kUnusedUniform != fUniLocations.fColorUni); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1005 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1006 | if (kUseUniform == fUniLocations.fColorFilterUni) { |
| 1007 | GL_CALL_RET(fUniLocations.fColorFilterUni, |
| 1008 | GetUniformLocation(fProgramID, COL_FILTER_UNI_NAME)); |
| 1009 | GrAssert(kUnusedUniform != fUniLocations.fColorFilterUni); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 1010 | } |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1011 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1012 | if (kUseUniform == fUniLocations.fColorMatrixUni) { |
| 1013 | GL_CALL_RET(fUniLocations.fColorMatrixUni, |
| 1014 | GetUniformLocation(fProgramID, COL_MATRIX_UNI_NAME)); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1017 | if (kUseUniform == fUniLocations.fColorMatrixVecUni) { |
| 1018 | GL_CALL_RET(fUniLocations.fColorMatrixVecUni, |
| 1019 | GetUniformLocation(fProgramID, COL_MATRIX_VEC_UNI_NAME)); |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1020 | } |
bsalomon@google.com | 33c1f6b | 2012-07-16 17:54:26 +0000 | [diff] [blame] | 1021 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1022 | if (kUseUniform == fUniLocations.fCoverageUni) { |
bsalomon@google.com | 33c1f6b | 2012-07-16 17:54:26 +0000 | [diff] [blame] | 1023 | GL_CALL_RET(fUniLocations.fCoverageUni,GetUniformLocation(fProgramID, COV_UNI_NAME)); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1024 | GrAssert(kUnusedUniform != fUniLocations.fCoverageUni); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 1025 | } |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 1026 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1027 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1028 | StageUniLocations& locations = fUniLocations.fStages[s]; |
| 1029 | if (fDesc.fStages[s].isEnabled()) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1030 | if (kUseUniform == locations.fTextureMatrixUni) { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 1031 | SkString texMName; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1032 | tex_matrix_name(s, &texMName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1033 | GL_CALL_RET(locations.fTextureMatrixUni, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1034 | GetUniformLocation(fProgramID, texMName.c_str())); |
bsalomon@google.com | 96291df | 2012-07-20 16:17:03 +0000 | [diff] [blame] | 1035 | //color filter table effect does not consumer coords gen'ed by matrix. |
| 1036 | //GrAssert(kUnusedUniform != locations.fTextureMatrixUni); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | if (kUseUniform == locations.fSamplerUni) { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 1040 | SkString samplerName; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1041 | sampler_name(s, &samplerName); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 1042 | GL_CALL_RET(locations.fSamplerUni, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1043 | GetUniformLocation(fProgramID,samplerName.c_str())); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1044 | GrAssert(kUnusedUniform != locations.fSamplerUni); |
| 1045 | } |
| 1046 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1047 | if (NULL != fProgramStage[s]) { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 1048 | fProgramStage[s]->initUniforms(&builder, fContextInfo.interface(), fProgramID); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1049 | } |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1050 | } |
| 1051 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1052 | GL_CALL(UseProgram(fProgramID)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1053 | |
| 1054 | // init sampler unis and set bogus values for state tracking |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1055 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1056 | if (kUnusedUniform != fUniLocations.fStages[s].fSamplerUni) { |
| 1057 | GL_CALL(Uniform1i(fUniLocations.fStages[s].fSamplerUni, s)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1058 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1059 | fTextureMatrices[s] = GrMatrix::InvalidMatrix(); |
bsalomon@google.com | 890e3b5 | 2012-06-01 19:01:37 +0000 | [diff] [blame] | 1060 | // this is arbitrary, just initialize to something |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1061 | fTextureOrientation[s] = GrGLTexture::kBottomUp_Orientation; |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1062 | // Must not reset fStageOverride[] here. |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1063 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1064 | fViewMatrix = GrMatrix::InvalidMatrix(); |
| 1065 | fViewportSize.set(-1, -1); |
| 1066 | fColor = GrColor_ILLEGAL; |
| 1067 | fColorFilterColor = GrColor_ILLEGAL; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 1070 | /////////////////////////////////////////////////////////////////////////////// |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1071 | // Stage code generation |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1072 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 1073 | void GrGLProgram::genStageCode(int stageNum, |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 1074 | const char* fsInColor, // NULL means no incoming color |
| 1075 | const char* fsOutColor, |
| 1076 | const char* vsInCoord, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1077 | GrGLShaderBuilder* segments) { |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1078 | GrAssert(stageNum >= 0 && stageNum <= GrDrawState::kNumStages); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1079 | |
| 1080 | const GrGLProgram::StageDesc& desc = fDesc.fStages[stageNum]; |
| 1081 | StageUniLocations& locations = fUniLocations.fStages[stageNum]; |
| 1082 | GrGLProgramStage* customStage = fProgramStage[stageNum]; |
| 1083 | |
| 1084 | GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) == desc.fInConfigFlags); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1085 | |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 1086 | /// Vertex Shader Stuff |
| 1087 | |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 1088 | // decide whether we need a matrix to transform texture coords and whether the varying needs a |
| 1089 | // perspective coord. |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1090 | const char* matName = NULL; |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1091 | if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1092 | segments->fVaryingDims = segments->fCoordDims; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1093 | } else { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 1094 | SkString texMatName; |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1095 | tex_matrix_name(stageNum, &texMatName); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 1096 | GrGLShaderBuilder::UniformHandle m = |
| 1097 | segments->addUniform(GrGLShaderBuilder::kVertex_ShaderType, |
| 1098 | kMat33f_GrSLType, texMatName.c_str()); |
| 1099 | const GrGLShaderVar& mat = segments->getUniformVariable(m); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1100 | // Can't use texMatName.c_str() because it's on the stack! |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 1101 | matName = mat.getName().c_str(); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1102 | locations.fTextureMatrixUni = kUseUniform; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1103 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1104 | if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1105 | segments->fVaryingDims = segments->fCoordDims; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1106 | } else { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1107 | segments->fVaryingDims = segments->fCoordDims + 1; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1110 | GrAssert(segments->fVaryingDims > 0); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1111 | |
tomhudson@google.com | 898e7b5 | 2012-06-01 20:42:15 +0000 | [diff] [blame] | 1112 | // Must setup variables after computing segments->fVaryingDims |
| 1113 | if (NULL != customStage) { |
| 1114 | customStage->setupVariables(segments, stageNum); |
| 1115 | } |
| 1116 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 1117 | SkString samplerName; |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1118 | sampler_name(stageNum, &samplerName); |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 1119 | segments->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 1120 | kSampler2D_GrSLType, samplerName.c_str()); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1121 | locations.fSamplerUni = kUseUniform; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1122 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1123 | const char *varyingVSName, *varyingFSName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 1124 | segments->addVarying(GrSLFloatVectorType(segments->fVaryingDims), |
| 1125 | "Stage", |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 1126 | stageNum, |
| 1127 | &varyingVSName, |
| 1128 | &varyingFSName); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1129 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1130 | if (!matName) { |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1131 | GrAssert(segments->fVaryingDims == segments->fCoordDims); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1132 | segments->fVSCode.appendf("\t%s = %s;\n", varyingVSName, vsInCoord); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1133 | } else { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 1134 | // varying = texMatrix * texCoord |
| 1135 | segments->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n", |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1136 | varyingVSName, matName, vsInCoord, |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 1137 | vector_all_coords(segments->fVaryingDims)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1140 | if (NULL != customStage) { |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1141 | segments->fVSCode.appendf("\t{ // stage %d %s\n", |
| 1142 | stageNum, customStage->name()); |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1143 | customStage->emitVS(segments, varyingVSName); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1144 | segments->fVSCode.appendf("\t}\n"); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1147 | /// Fragment Shader Stuff |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1148 | |
tomhudson@google.com | 5440f06 | 2012-06-01 15:55:50 +0000 | [diff] [blame] | 1149 | segments->fSampleCoords = varyingFSName; |
| 1150 | |
| 1151 | GrGLShaderBuilder::SamplerMode sampleMode = |
| 1152 | GrGLShaderBuilder::kExplicitDivide_SamplerMode; |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 1153 | if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit | |
| 1154 | StageDesc::kNoPerspective_OptFlagBit)) { |
tomhudson@google.com | 5440f06 | 2012-06-01 15:55:50 +0000 | [diff] [blame] | 1155 | sampleMode = GrGLShaderBuilder::kDefault_SamplerMode; |
bsalomon@google.com | d2ae1fa | 2012-06-04 20:06:02 +0000 | [diff] [blame] | 1156 | } else if (NULL == customStage) { |
tomhudson@google.com | 5440f06 | 2012-06-01 15:55:50 +0000 | [diff] [blame] | 1157 | sampleMode = GrGLShaderBuilder::kProj_SamplerMode; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1158 | } |
tomhudson@google.com | 5440f06 | 2012-06-01 15:55:50 +0000 | [diff] [blame] | 1159 | segments->setupTextureAccess(sampleMode, stageNum); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1160 | |
tomhudson@google.com | 898e7b5 | 2012-06-01 20:42:15 +0000 | [diff] [blame] | 1161 | segments->computeSwizzle(desc.fInConfigFlags); |
| 1162 | segments->computeModulate(fsInColor); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1163 | |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1164 | static const uint32_t kMulByAlphaMask = |
| 1165 | (StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag | |
| 1166 | StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag); |
| 1167 | |
tomhudson@google.com | 6a820b6 | 2012-05-24 15:10:14 +0000 | [diff] [blame] | 1168 | // NOTE: GrGLProgramStages are now responsible for fetching |
| 1169 | if (NULL == customStage) { |
bsalomon@google.com | d2ae1fa | 2012-06-04 20:06:02 +0000 | [diff] [blame] | 1170 | if (desc.fInConfigFlags & kMulByAlphaMask) { |
| 1171 | // only one of the mul by alpha flags should be set |
| 1172 | GrAssert(GrIsPow2(kMulByAlphaMask & desc.fInConfigFlags)); |
| 1173 | GrAssert(!(desc.fInConfigFlags & |
| 1174 | StageDesc::kSmearAlpha_InConfigFlag)); |
| 1175 | GrAssert(!(desc.fInConfigFlags & |
| 1176 | StageDesc::kSmearRed_InConfigFlag)); |
| 1177 | segments->fFSCode.appendf("\t%s = %s(%s, %s)%s;\n", |
| 1178 | fsOutColor, |
| 1179 | segments->fTexFunc.c_str(), |
| 1180 | samplerName.c_str(), |
| 1181 | segments->fSampleCoords.c_str(), |
| 1182 | segments->fSwizzle.c_str()); |
| 1183 | if (desc.fInConfigFlags & |
| 1184 | StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag) { |
| 1185 | segments->fFSCode.appendf("\t%s = vec4(ceil(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n", |
| 1186 | fsOutColor, fsOutColor, fsOutColor, |
| 1187 | fsOutColor, segments->fModulate.c_str()); |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1188 | } else { |
bsalomon@google.com | d2ae1fa | 2012-06-04 20:06:02 +0000 | [diff] [blame] | 1189 | segments->fFSCode.appendf("\t%s = vec4(floor(%s.rgb*%s.a*255.0)/255.0,%s.a)%s;\n", |
| 1190 | fsOutColor, fsOutColor, fsOutColor, |
| 1191 | fsOutColor, segments->fModulate.c_str()); |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1192 | } |
bsalomon@google.com | d2ae1fa | 2012-06-04 20:06:02 +0000 | [diff] [blame] | 1193 | } else { |
| 1194 | segments->emitDefaultFetch(fsOutColor, samplerName.c_str()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1195 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1196 | } |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1197 | |
| 1198 | if (NULL != customStage) { |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1199 | // Enclose custom code in a block to avoid namespace conflicts |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1200 | segments->fFSCode.appendf("\t{ // stage %d %s \n", |
| 1201 | stageNum, customStage->name()); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 1202 | customStage->emitFS(segments, fsOutColor, fsInColor, |
| 1203 | samplerName.c_str()); |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 1204 | segments->fFSCode.appendf("\t}\n"); |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 1205 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1206 | } |