blob: 27eb3674569a31d742252b2afe1817350fd378f2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
junov@google.comf93e7172011-03-31 21:26:24 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comf93e7172011-03-31 21:26:24 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
junov@google.comf93e7172011-03-31 21:26:24 +000010#include "GrGLProgram.h"
11
bsalomon@google.com4fa66942011-09-20 19:06:12 +000012#include "GrAllocator.h"
13#include "GrGLShaderVar.h"
tomhudson@google.com0c8d93a2011-07-01 17:08:26 +000014#include "SkTrace.h"
Scroggo97c88c22011-05-11 14:05:25 +000015#include "SkXfermode.h"
16
junov@google.comf93e7172011-03-31 21:26:24 +000017namespace {
18
bsalomon@google.com0b77d682011-08-19 13:28:54 +000019const char* GrPrecision(const GrGLInterface* gl) {
20 if (gl->supportsES()) {
junov@google.comf93e7172011-03-31 21:26:24 +000021 return "mediump";
22 } else {
bsalomon@google.com91961302011-05-09 18:39:58 +000023 return " ";
junov@google.comf93e7172011-03-31 21:26:24 +000024 }
25}
26
bsalomon@google.com0b77d682011-08-19 13:28:54 +000027const char* GrShaderPrecision(const GrGLInterface* gl) {
28 if (gl->supportsES()) {
junov@google.comf93e7172011-03-31 21:26:24 +000029 return "precision mediump float;\n";
30 } else {
31 return "";
32 }
33}
34
35} // namespace
36
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +000037#define PRINT_SHADERS 0
38
bsalomon@google.com4fa66942011-09-20 19:06:12 +000039typedef GrTAllocator<GrGLShaderVar> VarArray;
40
41// number of each input/output type in a single allocation block
42static const int gVarsPerBlock = 8;
43// except FS outputs where we expect 2 at most.
44static const int gMaxFSOutputs = 2;
45
46struct ShaderCodeSegments {
47 ShaderCodeSegments()
48 : fVSUnis(gVarsPerBlock)
49 , fVSAttrs(gVarsPerBlock)
50 , fVaryings(gVarsPerBlock)
51 , fFSUnis(gVarsPerBlock)
52 , fFSOutputs(gMaxFSOutputs) {}
53 GrStringBuilder fHeader; // VS+FS, GLSL version, etc
54 VarArray fVSUnis;
55 VarArray fVSAttrs;
56 VarArray fVaryings;
57 VarArray fFSUnis;
58 VarArray fFSOutputs;
59 GrStringBuilder fFSFunctions;
60 GrStringBuilder fVSCode;
61 GrStringBuilder fFSCode;
62};
63
64
bsalomon@google.com4be283f2011-04-19 21:15:09 +000065#if GR_GL_ATTRIBUTE_MATRICES
junov@google.comf93e7172011-03-31 21:26:24 +000066 #define VIEW_MATRIX_NAME "aViewM"
67#else
68 #define VIEW_MATRIX_NAME "uViewM"
69#endif
70
71#define POS_ATTR_NAME "aPosition"
72#define COL_ATTR_NAME "aColor"
bsalomon@google.comaeb21602011-08-30 18:13:44 +000073#define EDGE_ATTR_NAME "aEdge"
bsalomon@google.com4be283f2011-04-19 21:15:09 +000074#define COL_UNI_NAME "uColor"
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +000075#define EDGES_UNI_NAME "uEdges"
Scroggo97c88c22011-05-11 14:05:25 +000076#define COL_FILTER_UNI_NAME "uColorFilter"
junov@google.comf93e7172011-03-31 21:26:24 +000077
bsalomon@google.com4fa66942011-09-20 19:06:12 +000078namespace {
79inline void tex_attr_name(int coordIdx, GrStringBuilder* s) {
junov@google.comf93e7172011-03-31 21:26:24 +000080 *s = "aTexCoord";
bsalomon@google.comfc296292011-05-06 13:53:47 +000081 s->appendS32(coordIdx);
junov@google.comf93e7172011-03-31 21:26:24 +000082}
83
bsalomon@google.com4fa66942011-09-20 19:06:12 +000084inline GrGLShaderVar::Type float_vector_type(int count) {
85 GR_STATIC_ASSERT(GrGLShaderVar::kFloat_Type == 0);
86 GR_STATIC_ASSERT(GrGLShaderVar::kVec2f_Type == 1);
87 GR_STATIC_ASSERT(GrGLShaderVar::kVec3f_Type == 2);
88 GR_STATIC_ASSERT(GrGLShaderVar::kVec4f_Type == 3);
89 GrAssert(count > 0 && count <= 4);
90 return (GrGLShaderVar::Type)(count - 1);
junov@google.comf93e7172011-03-31 21:26:24 +000091}
92
bsalomon@google.com4fa66942011-09-20 19:06:12 +000093inline const char* float_vector_type_str(int count) {
94 return GrGLShaderVar::TypeString(float_vector_type(count));
95}
96
97inline const char* vector_homog_coord(int count) {
junov@google.comf93e7172011-03-31 21:26:24 +000098 static const char* HOMOGS[] = {"ERROR", "", ".y", ".z", ".w"};
99 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(HOMOGS));
100 return HOMOGS[count];
101}
102
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000103inline const char* vector_nonhomog_coords(int count) {
junov@google.comf93e7172011-03-31 21:26:24 +0000104 static const char* NONHOMOGS[] = {"ERROR", "", ".x", ".xy", ".xyz"};
105 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(NONHOMOGS));
106 return NONHOMOGS[count];
107}
108
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000109inline const char* vector_all_coords(int count) {
junov@google.comf93e7172011-03-31 21:26:24 +0000110 static const char* ALL[] = {"ERROR", "", ".xy", ".xyz", ".xyzw"};
111 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ALL));
112 return ALL[count];
113}
114
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000115inline const char* all_ones_vec(int count) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000116 static const char* ONESVEC[] = {"ERROR", "1.0", "vec2(1,1)",
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000117 "vec3(1,1,1)", "vec4(1,1,1,1)"};
118 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ONESVEC));
119 return ONESVEC[count];
120}
121
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000122inline const char* all_zeros_vec(int count) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000123 static const char* ZEROSVEC[] = {"ERROR", "0.0", "vec2(0,0)",
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000124 "vec3(0,0,0)", "vec4(0,0,0,0)"};
125 GrAssert(count >= 1 && count < (int)GR_ARRAY_COUNT(ZEROSVEC));
126 return ZEROSVEC[count];
127}
128
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000129inline const char* declared_color_output_name() { return "fsColorOut"; }
130inline const char* dual_source_output_name() { return "dualSourceOut"; }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000131
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000132inline void tex_matrix_name(int stage, GrStringBuilder* s) {
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000133#if GR_GL_ATTRIBUTE_MATRICES
junov@google.comf93e7172011-03-31 21:26:24 +0000134 *s = "aTexM";
135#else
136 *s = "uTexM";
137#endif
bsalomon@google.comfc296292011-05-06 13:53:47 +0000138 s->appendS32(stage);
junov@google.comf93e7172011-03-31 21:26:24 +0000139}
140
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000141inline void normalized_texel_size_name(int stage, GrStringBuilder* s) {
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000142 *s = "uTexelSize";
bsalomon@google.comfc296292011-05-06 13:53:47 +0000143 s->appendS32(stage);
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000144}
145
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000146inline void sampler_name(int stage, GrStringBuilder* s) {
junov@google.comf93e7172011-03-31 21:26:24 +0000147 *s = "uSampler";
bsalomon@google.comfc296292011-05-06 13:53:47 +0000148 s->appendS32(stage);
junov@google.comf93e7172011-03-31 21:26:24 +0000149}
150
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000151inline void stage_varying_name(int stage, GrStringBuilder* s) {
junov@google.comf93e7172011-03-31 21:26:24 +0000152 *s = "vStage";
bsalomon@google.comfc296292011-05-06 13:53:47 +0000153 s->appendS32(stage);
junov@google.comf93e7172011-03-31 21:26:24 +0000154}
155
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000156inline void radial2_param_name(int stage, GrStringBuilder* s) {
junov@google.comf93e7172011-03-31 21:26:24 +0000157 *s = "uRadial2Params";
bsalomon@google.comfc296292011-05-06 13:53:47 +0000158 s->appendS32(stage);
junov@google.comf93e7172011-03-31 21:26:24 +0000159}
160
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000161inline void radial2_varying_name(int stage, GrStringBuilder* s) {
junov@google.comf93e7172011-03-31 21:26:24 +0000162 *s = "vB";
bsalomon@google.comfc296292011-05-06 13:53:47 +0000163 s->appendS32(stage);
junov@google.comf93e7172011-03-31 21:26:24 +0000164}
165
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000166inline void convolve_param_names(int stage, GrStringBuilder* k, GrStringBuilder* i) {
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000167 *k = "uKernel";
168 k->appendS32(stage);
169 *i = "uImageIncrement";
170 i->appendS32(stage);
171}
172
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000173inline void tex_domain_name(int stage, GrStringBuilder* s) {
junov@google.com6acc9b32011-05-16 18:32:07 +0000174 *s = "uTexDom";
175 s->appendS32(stage);
176}
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000177}
junov@google.com6acc9b32011-05-16 18:32:07 +0000178
junov@google.comf93e7172011-03-31 21:26:24 +0000179GrGLProgram::GrGLProgram() {
junov@google.comf93e7172011-03-31 21:26:24 +0000180}
181
182GrGLProgram::~GrGLProgram() {
junov@google.comf93e7172011-03-31 21:26:24 +0000183}
184
tomhudson@google.com0d3f1fb2011-06-01 19:27:31 +0000185void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000186 GrBlendCoeff* dstCoeff) const {
187 switch (fProgramDesc.fDualSrcOutput) {
188 case ProgramDesc::kNone_DualSrcOutput:
189 break;
190 // the prog will write a coverage value to the secondary
191 // output and the dst is blended by one minus that value.
192 case ProgramDesc::kCoverage_DualSrcOutput:
193 case ProgramDesc::kCoverageISA_DualSrcOutput:
194 case ProgramDesc::kCoverageISC_DualSrcOutput:
195 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_BlendCoeff;
196 break;
197 default:
198 GrCrash("Unexpected dual source blend output");
199 break;
200 }
201}
202
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000203// assigns modulation of two vars to an output var
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000204// vars can be vec4s or floats (or one of each)
205// result is always vec4
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000206// if either var is "" then assign to the other var
207// if both are "" then assign all ones
208static inline void modulate_helper(const char* outputVar,
209 const char* var0,
210 const char* var1,
211 GrStringBuilder* code) {
212 GrAssert(NULL != outputVar);
213 GrAssert(NULL != var0);
214 GrAssert(NULL != var1);
215 GrAssert(NULL != code);
216
217 bool has0 = '\0' != *var0;
218 bool has1 = '\0' != *var1;
219
220 if (!has0 && !has1) {
221 code->appendf("\t%s = %s;\n", outputVar, all_ones_vec(4));
222 } else if (!has0) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000223 code->appendf("\t%s = vec4(%s);\n", outputVar, var1);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000224 } else if (!has1) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000225 code->appendf("\t%s = vec4(%s);\n", outputVar, var0);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000226 } else {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000227 code->appendf("\t%s = vec4(%s * %s);\n", outputVar, var0, var1);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000228 }
229}
230
231// assigns addition of two vars to an output var
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000232// vars can be vec4s or floats (or one of each)
233// result is always vec4
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000234// if either var is "" then assign to the other var
235// if both are "" then assign all zeros
236static inline void add_helper(const char* outputVar,
237 const char* var0,
238 const char* var1,
239 GrStringBuilder* code) {
240 GrAssert(NULL != outputVar);
241 GrAssert(NULL != var0);
242 GrAssert(NULL != var1);
243 GrAssert(NULL != code);
244
245 bool has0 = '\0' != *var0;
246 bool has1 = '\0' != *var1;
247
248 if (!has0 && !has1) {
249 code->appendf("\t%s = %s;\n", outputVar, all_zeros_vec(4));
250 } else if (!has0) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000251 code->appendf("\t%s = vec4(%s);\n", outputVar, var1);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000252 } else if (!has1) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000253 code->appendf("\t%s = vec4(%s);\n", outputVar, var0);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000254 } else {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000255 code->appendf("\t%s = vec4(%s + %s);\n", outputVar, var0, var1);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000256 }
257}
258
259// given two blend coeffecients determine whether the src
260// and/or dst computation can be omitted.
261static inline void needBlendInputs(SkXfermode::Coeff srcCoeff,
262 SkXfermode::Coeff dstCoeff,
263 bool* needSrcValue,
264 bool* needDstValue) {
265 if (SkXfermode::kZero_Coeff == srcCoeff) {
266 switch (dstCoeff) {
267 // these all read the src
268 case SkXfermode::kSC_Coeff:
269 case SkXfermode::kISC_Coeff:
270 case SkXfermode::kSA_Coeff:
271 case SkXfermode::kISA_Coeff:
272 *needSrcValue = true;
273 break;
274 default:
275 *needSrcValue = false;
276 break;
277 }
278 } else {
279 *needSrcValue = true;
280 }
281 if (SkXfermode::kZero_Coeff == dstCoeff) {
282 switch (srcCoeff) {
283 // these all read the dst
284 case SkXfermode::kDC_Coeff:
285 case SkXfermode::kIDC_Coeff:
286 case SkXfermode::kDA_Coeff:
287 case SkXfermode::kIDA_Coeff:
288 *needDstValue = true;
289 break;
290 default:
291 *needDstValue = false;
292 break;
293 }
294 } else {
295 *needDstValue = true;
Scroggo97c88c22011-05-11 14:05:25 +0000296 }
297}
298
299/**
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000300 * Create a blend_coeff * value string to be used in shader code. Sets empty
301 * string if result is trivially zero.
302 */
303static void blendTermString(GrStringBuilder* str, SkXfermode::Coeff coeff,
304 const char* src, const char* dst,
305 const char* value) {
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000306 switch (coeff) {
307 case SkXfermode::kZero_Coeff: /** 0 */
308 *str = "";
309 break;
310 case SkXfermode::kOne_Coeff: /** 1 */
311 *str = value;
312 break;
313 case SkXfermode::kSC_Coeff:
314 str->printf("(%s * %s)", src, value);
315 break;
316 case SkXfermode::kISC_Coeff:
317 str->printf("((%s - %s) * %s)", all_ones_vec(4), src, value);
318 break;
319 case SkXfermode::kDC_Coeff:
320 str->printf("(%s * %s)", dst, value);
321 break;
322 case SkXfermode::kIDC_Coeff:
323 str->printf("((%s - %s) * %s)", all_ones_vec(4), dst, value);
324 break;
325 case SkXfermode::kSA_Coeff: /** src alpha */
326 str->printf("(%s.a * %s)", src, value);
327 break;
328 case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */
329 str->printf("((1.0 - %s.a) * %s)", src, value);
330 break;
331 case SkXfermode::kDA_Coeff: /** dst alpha */
332 str->printf("(%s.a * %s)", dst, value);
333 break;
334 case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */
335 str->printf("((1.0 - %s.a) * %s)", dst, value);
336 break;
337 default:
338 GrCrash("Unexpected xfer coeff.");
339 break;
340 }
341}
342/**
Scroggo97c88c22011-05-11 14:05:25 +0000343 * Adds a line to the fragment shader code which modifies the color by
344 * the specified color filter.
345 */
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000346static void addColorFilter(GrStringBuilder* fsCode, const char * outputVar,
tomhudson@google.com0d3f1fb2011-06-01 19:27:31 +0000347 SkXfermode::Coeff uniformCoeff,
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000348 SkXfermode::Coeff colorCoeff,
349 const char* inColor) {
350 GrStringBuilder colorStr, constStr;
351 blendTermString(&colorStr, colorCoeff, COL_FILTER_UNI_NAME,
352 inColor, inColor);
353 blendTermString(&constStr, uniformCoeff, COL_FILTER_UNI_NAME,
354 inColor, COL_FILTER_UNI_NAME);
355
356 add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode);
Scroggo97c88c22011-05-11 14:05:25 +0000357}
358
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000359namespace {
360
361const char* glsl_version_string(const GrGLInterface* gl,
362 GrGLProgram::GLSLVersion v) {
363 switch (v) {
364 case GrGLProgram::k120_GLSLVersion:
365 if (gl->supportsES()) {
366 // ES2s shader language is based on version 1.20 but is version
367 // 1.00 of the ES language.
368 return "#version 100\n";
369 } else {
370 return "#version 120\n";
371 }
372 case GrGLProgram::k130_GLSLVersion:
373 GrAssert(!gl->supportsES());
374 return "#version 130\n";
375 default:
376 GrCrash("Unknown GL version.");
377 return ""; // suppress warning
378 }
379}
380
381}
382
bsalomon@google.com66105672011-09-15 15:12:00 +0000383void GrGLProgram::genEdgeCoverage(const GrGLInterface* gl,
384 GrVertexLayout layout,
385 CachedData* programData,
386 GrStringBuilder* coverageVar,
387 ShaderCodeSegments* segments) const {
388 if (fProgramDesc.fEdgeAANumEdges > 0) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000389 segments->fFSUnis.push_back().set(GrGLShaderVar::kVec3f_Type,
390 EDGES_UNI_NAME,
391 fProgramDesc.fEdgeAANumEdges);
bsalomon@google.com66105672011-09-15 15:12:00 +0000392 programData->fUniLocations.fEdgesUni = kUseUniform;
393 int count = fProgramDesc.fEdgeAANumEdges;
394 segments->fFSCode.append(
395 "\tvec3 pos = vec3(gl_FragCoord.xy, 1);\n");
396 for (int i = 0; i < count; i++) {
397 segments->fFSCode.append("\tfloat a");
398 segments->fFSCode.appendS32(i);
399 segments->fFSCode.append(" = clamp(dot(" EDGES_UNI_NAME "[");
400 segments->fFSCode.appendS32(i);
401 segments->fFSCode.append("], pos), 0.0, 1.0);\n");
402 }
403 if (fProgramDesc.fEdgeAAConcave && (count & 0x01) == 0) {
404 // For concave polys, we consider the edges in pairs.
405 segments->fFSFunctions.append("float cross2(vec2 a, vec2 b) {\n");
406 segments->fFSFunctions.append("\treturn dot(a, vec2(b.y, -b.x));\n");
407 segments->fFSFunctions.append("}\n");
408 for (int i = 0; i < count; i += 2) {
409 segments->fFSCode.appendf("\tfloat eb%d;\n", i / 2);
410 segments->fFSCode.appendf("\tif (cross2(" EDGES_UNI_NAME "[%d].xy, " EDGES_UNI_NAME "[%d].xy) < 0.0) {\n", i, i + 1);
411 segments->fFSCode.appendf("\t\teb%d = a%d * a%d;\n", i / 2, i, i + 1);
412 segments->fFSCode.append("\t} else {\n");
413 segments->fFSCode.appendf("\t\teb%d = a%d + a%d - a%d * a%d;\n", i / 2, i, i + 1, i, i + 1);
414 segments->fFSCode.append("\t}\n");
415 }
416 segments->fFSCode.append("\tfloat edgeAlpha = ");
417 for (int i = 0; i < count / 2 - 1; i++) {
418 segments->fFSCode.appendf("min(eb%d, ", i);
419 }
420 segments->fFSCode.appendf("eb%d", count / 2 - 1);
421 for (int i = 0; i < count / 2 - 1; i++) {
422 segments->fFSCode.append(")");
423 }
424 segments->fFSCode.append(";\n");
425 } else {
426 segments->fFSCode.append("\tfloat edgeAlpha = ");
427 for (int i = 0; i < count - 1; i++) {
428 segments->fFSCode.appendf("min(a%d * a%d, ", i, i + 1);
429 }
430 segments->fFSCode.appendf("a%d * a0", count - 1);
431 for (int i = 0; i < count - 1; i++) {
432 segments->fFSCode.append(")");
433 }
434 segments->fFSCode.append(";\n");
435 }
436 *coverageVar = "edgeAlpha";
437 } else if (layout & GrDrawTarget::kEdge_VertexLayoutBit) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000438 segments->fVaryings.push_back().set(GrGLShaderVar::kVec4f_Type, "vEdge");
439 segments->fVSAttrs.push_back().set(GrGLShaderVar::kVec4f_Type, EDGE_ATTR_NAME);
bsalomon@google.com66105672011-09-15 15:12:00 +0000440 segments->fVSCode.append("\tvEdge = " EDGE_ATTR_NAME ";\n");
441 if (GrDrawTarget::kHairLine_EdgeType == fProgramDesc.fVertexEdgeType) {
442 segments->fFSCode.append("\tfloat edgeAlpha = abs(dot(vec3(gl_FragCoord.xy,1), vEdge.xyz));\n");
443 } else {
444 GrAssert(GrDrawTarget::kHairQuad_EdgeType == fProgramDesc.fVertexEdgeType);
445 // for now we know we're not in perspective, so we could compute this
446 // per-quadratic rather than per pixel
447 segments->fFSCode.append("\tvec2 duvdx = dFdx(vEdge.xy);\n");
448 segments->fFSCode.append("\tvec2 duvdy = dFdy(vEdge.xy);\n");
449 segments->fFSCode.append("\tfloat dfdx = 2.0*vEdge.x*duvdx.x - duvdx.y;\n");
450 segments->fFSCode.append("\tfloat dfdy = 2.0*vEdge.x*duvdy.x - duvdy.y;\n");
451 segments->fFSCode.append("\tfloat edgeAlpha = (vEdge.x*vEdge.x - vEdge.y);\n");
452 segments->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / (dfdx*dfdx + dfdy*dfdy));\n");
453 if (gl->supportsES()) {
454 segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
455 }
456 }
457 segments->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
458 *coverageVar = "edgeAlpha";
459 } else {
460 coverageVar->reset();
461 }
462}
463
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000464namespace {
465
466// returns true if the color output was explicitly declared or not.
467bool decl_and_get_fs_color_output(GrGLProgram::GLSLVersion v,
468 VarArray* fsOutputs,
469 const char** name) {
470 switch (v) {
471 case GrGLProgram::k120_GLSLVersion:
472 *name = "gl_FragColor";
473 return false;
474 break;
475 case GrGLProgram::k130_GLSLVersion:
476 *name = declared_color_output_name();
477 fsOutputs->push_back().set(GrGLShaderVar::kVec4f_Type,
478 declared_color_output_name());
479 return true;
480 break;
481 default:
482 GrCrash("Unknown GLSL version.");
483 return false; // suppress warning
484 }
485}
486
487}
488
489bool GrGLProgram::genProgram(const GrGLInterface* gl,
490 GLSLVersion glslVersion,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000491 GrGLProgram::CachedData* programData) const {
junov@google.comf93e7172011-03-31 21:26:24 +0000492
493 ShaderCodeSegments segments;
494 const uint32_t& layout = fProgramDesc.fVertexLayout;
495
bsalomon@google.com91961302011-05-09 18:39:58 +0000496 programData->fUniLocations.reset();
junov@google.comf93e7172011-03-31 21:26:24 +0000497
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000498 SkXfermode::Coeff colorCoeff, uniformCoeff;
499 // The rest of transfer mode color filters have not been implemented
500 if (fProgramDesc.fColorFilterXfermode < SkXfermode::kCoeffModesCnt) {
501 GR_DEBUGCODE(bool success =)
tomhudson@google.com0d831722011-06-02 15:37:14 +0000502 SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>
503 (fProgramDesc.fColorFilterXfermode),
504 &uniformCoeff, &colorCoeff);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000505 GR_DEBUGASSERT(success);
506 } else {
507 colorCoeff = SkXfermode::kOne_Coeff;
508 uniformCoeff = SkXfermode::kZero_Coeff;
509 }
510
511 bool needColorFilterUniform;
512 bool needComputedColor;
513 needBlendInputs(uniformCoeff, colorCoeff,
514 &needColorFilterUniform, &needComputedColor);
515
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000516 // the dual source output has no canonical var name, have to
517 // declare an output, which is incompatible with gl_FragColor/gl_FragData.
518 const char* fsColorOutput;
519 bool dualSourceOutputWritten = false;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000520 segments.fHeader.printf(glsl_version_string(gl, glslVersion));
521 bool isColorDeclared = decl_and_get_fs_color_output(glslVersion,
522 &segments.fFSOutputs,
523 &fsColorOutput);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000524
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000525#if GR_GL_ATTRIBUTE_MATRICES
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000526 segments.fVSAttrs.push_back().set(GrGLShaderVar::kMat33f_Type, VIEW_MATRIX_NAME);
bsalomon@google.com91961302011-05-09 18:39:58 +0000527 programData->fUniLocations.fViewMatrixUni = kSetAsAttribute;
junov@google.comf93e7172011-03-31 21:26:24 +0000528#else
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000529 segments.fVSUnis.push_back().set(GrGLShaderVar::kMat33f_Type, VIEW_MATRIX_NAME);
bsalomon@google.com91961302011-05-09 18:39:58 +0000530 programData->fUniLocations.fViewMatrixUni = kUseUniform;
junov@google.comf93e7172011-03-31 21:26:24 +0000531#endif
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000532 segments.fVSAttrs.push_back().set(GrGLShaderVar::kVec2f_Type, POS_ATTR_NAME);
junov@google.comf93e7172011-03-31 21:26:24 +0000533
bsalomon@google.com91961302011-05-09 18:39:58 +0000534 segments.fVSCode.append(
535 "void main() {\n"
536 "\tvec3 pos3 = " VIEW_MATRIX_NAME " * vec3("POS_ATTR_NAME", 1);\n"
537 "\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n");
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000538
bsalomon@google.com91961302011-05-09 18:39:58 +0000539 // incoming color to current stage being processed.
540 GrStringBuilder inColor;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000541
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000542 if (needComputedColor) {
543 switch (fProgramDesc.fColorType) {
544 case ProgramDesc::kAttribute_ColorType:
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000545 segments.fVSAttrs.push_back().set(GrGLShaderVar::kVec4f_Type,
546 COL_ATTR_NAME);
547 segments.fVaryings.push_back().set(GrGLShaderVar::kVec4f_Type,
548 "vColor");
549 segments.fVSCode.append("\tvColor = " COL_ATTR_NAME ";\n");
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000550 inColor = "vColor";
551 break;
552 case ProgramDesc::kUniform_ColorType:
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000553 segments.fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
554 COL_UNI_NAME);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000555 programData->fUniLocations.fColorUni = kUseUniform;
556 inColor = COL_UNI_NAME;
557 break;
558 default:
559 GrAssert(ProgramDesc::kNone_ColorType == fProgramDesc.fColorType);
560 break;
561 }
junov@google.comf93e7172011-03-31 21:26:24 +0000562 }
563
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000564 if (fProgramDesc.fEmitsPointSize){
bsalomon@google.com91961302011-05-09 18:39:58 +0000565 segments.fVSCode.append("\tgl_PointSize = 1.0;\n");
junov@google.comf93e7172011-03-31 21:26:24 +0000566 }
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000567
bsalomon@google.com91961302011-05-09 18:39:58 +0000568 segments.fFSCode.append("void main() {\n");
junov@google.comf93e7172011-03-31 21:26:24 +0000569
570 // add texture coordinates that are used to the list of vertex attr decls
bsalomon@google.com91961302011-05-09 18:39:58 +0000571 GrStringBuilder texCoordAttrs[GrDrawTarget::kMaxTexCoords];
junov@google.comf93e7172011-03-31 21:26:24 +0000572 for (int t = 0; t < GrDrawTarget::kMaxTexCoords; ++t) {
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000573 if (GrDrawTarget::VertexUsesTexCoordIdx(t, layout)) {
junov@google.comf93e7172011-03-31 21:26:24 +0000574 tex_attr_name(t, texCoordAttrs + t);
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000575 segments.fVSAttrs.push_back().set(GrGLShaderVar::kVec2f_Type,
576 texCoordAttrs[t].c_str());
junov@google.comf93e7172011-03-31 21:26:24 +0000577 }
578 }
579
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000580 ///////////////////////////////////////////////////////////////////////////
581 // compute the final color
Scroggo97c88c22011-05-11 14:05:25 +0000582
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000583 // if we have color stages string them together, feeding the output color
584 // of each to the next and generating code for each stage.
585 if (needComputedColor) {
586 GrStringBuilder outColor;
587 for (int s = 0; s < fProgramDesc.fFirstCoverageStage; ++s) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000588 if (fProgramDesc.fStages[s].isEnabled()) {
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000589 // create var to hold stage result
590 outColor = "color";
591 outColor.appendS32(s);
592 segments.fFSCode.appendf("\tvec4 %s;\n", outColor.c_str());
593
594 const char* inCoords;
595 // figure out what our input coords are
596 if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) &
597 layout) {
598 inCoords = POS_ATTR_NAME;
Scroggo97c88c22011-05-11 14:05:25 +0000599 } else {
600 int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout);
601 // we better have input tex coordinates if stage is enabled.
602 GrAssert(tcIdx >= 0);
603 GrAssert(texCoordAttrs[tcIdx].size());
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000604 inCoords = texCoordAttrs[tcIdx].c_str();
junov@google.comf93e7172011-03-31 21:26:24 +0000605 }
606
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000607 genStageCode(gl,
608 s,
junov@google.comf93e7172011-03-31 21:26:24 +0000609 fProgramDesc.fStages[s],
bsalomon@google.comfc296292011-05-06 13:53:47 +0000610 inColor.size() ? inColor.c_str() : NULL,
611 outColor.c_str(),
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000612 inCoords,
junov@google.comf93e7172011-03-31 21:26:24 +0000613 &segments,
614 &programData->fUniLocations.fStages[s]);
junov@google.comf93e7172011-03-31 21:26:24 +0000615 inColor = outColor;
junov@google.comf93e7172011-03-31 21:26:24 +0000616 }
617 }
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000618 }
Scroggo97c88c22011-05-11 14:05:25 +0000619
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000620 // if have all ones for the "dst" input to the color filter then we can make
621 // additional optimizations.
tomhudson@google.com0d831722011-06-02 15:37:14 +0000622 if (needColorFilterUniform && !inColor.size() &&
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000623 (SkXfermode::kIDC_Coeff == uniformCoeff ||
624 SkXfermode::kIDA_Coeff == uniformCoeff)) {
625 uniformCoeff = SkXfermode::kZero_Coeff;
626 bool bogus;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000627 needBlendInputs(SkXfermode::kZero_Coeff, colorCoeff,
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000628 &needColorFilterUniform, &bogus);
629 }
630 if (needColorFilterUniform) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000631 segments.fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type,
632 COL_FILTER_UNI_NAME);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000633 programData->fUniLocations.fColorFilterUni = kUseUniform;
634 }
635
636 bool wroteFragColorZero = false;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000637 if (SkXfermode::kZero_Coeff == uniformCoeff &&
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000638 SkXfermode::kZero_Coeff == colorCoeff) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000639 segments.fFSCode.appendf("\t%s = %s;\n",
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000640 fsColorOutput,
641 all_zeros_vec(4));
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000642 wroteFragColorZero = true;
643 } else if (SkXfermode::kDst_Mode != fProgramDesc.fColorFilterXfermode) {
644 segments.fFSCode.appendf("\tvec4 filteredColor;\n");
645 const char* color = inColor.size() ? inColor.c_str() : all_ones_vec(4);
tomhudson@google.com0d831722011-06-02 15:37:14 +0000646 addColorFilter(&segments.fFSCode, "filteredColor", uniformCoeff,
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000647 colorCoeff, color);
648 inColor = "filteredColor";
649 }
650
651 ///////////////////////////////////////////////////////////////////////////
652 // compute the partial coverage (coverage stages and edge aa)
653
654 GrStringBuilder inCoverage;
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000655
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000656 // we don't need to compute coverage at all if we know the final shader
657 // output will be zero and we don't have a dual src blend output.
658 if (!wroteFragColorZero ||
659 ProgramDesc::kNone_DualSrcOutput != fProgramDesc.fDualSrcOutput) {
bsalomon@google.com66105672011-09-15 15:12:00 +0000660
661 // get edge AA coverage and use it as inCoverage to first coverage stage
662 this->genEdgeCoverage(gl, layout, programData, &inCoverage, &segments);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000663
664 GrStringBuilder outCoverage;
665 const int& startStage = fProgramDesc.fFirstCoverageStage;
666 for (int s = startStage; s < GrDrawTarget::kNumStages; ++s) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000667 if (fProgramDesc.fStages[s].isEnabled()) {
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000668 // create var to hold stage output
669 outCoverage = "coverage";
670 outCoverage.appendS32(s);
671 segments.fFSCode.appendf("\tvec4 %s;\n", outCoverage.c_str());
672
673 const char* inCoords;
674 // figure out what our input coords are
675 if (GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s) & layout) {
676 inCoords = POS_ATTR_NAME;
677 } else {
678 int tcIdx = GrDrawTarget::VertexTexCoordsForStage(s, layout);
679 // we better have input tex coordinates if stage is enabled.
680 GrAssert(tcIdx >= 0);
681 GrAssert(texCoordAttrs[tcIdx].size());
682 inCoords = texCoordAttrs[tcIdx].c_str();
683 }
684
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000685 genStageCode(gl, s,
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000686 fProgramDesc.fStages[s],
687 inCoverage.size() ? inCoverage.c_str() : NULL,
688 outCoverage.c_str(),
689 inCoords,
690 &segments,
691 &programData->fUniLocations.fStages[s]);
692 inCoverage = outCoverage;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000693 }
694 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000695 if (ProgramDesc::kNone_DualSrcOutput != fProgramDesc.fDualSrcOutput) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000696 segments.fFSOutputs.push_back().set(GrGLShaderVar::kVec4f_Type,
697 dual_source_output_name());
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000698 bool outputIsZero = false;
699 GrStringBuilder coeff;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000700 if (ProgramDesc::kCoverage_DualSrcOutput !=
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000701 fProgramDesc.fDualSrcOutput && !wroteFragColorZero) {
702 if (!inColor.size()) {
703 outputIsZero = true;
704 } else {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000705 if (fProgramDesc.fDualSrcOutput ==
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000706 ProgramDesc::kCoverageISA_DualSrcOutput) {
707 coeff.printf("(1 - %s.a)", inColor.c_str());
708 } else {
709 coeff.printf("(vec4(1,1,1,1) - %s)", inColor.c_str());
710 }
711 }
712 }
713 if (outputIsZero) {
tomhudson@google.com0d831722011-06-02 15:37:14 +0000714 segments.fFSCode.appendf("\t%s = %s;\n",
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000715 dual_source_output_name(),
716 all_zeros_vec(4));
717 } else {
718 modulate_helper(dual_source_output_name(),
719 coeff.c_str(),
720 inCoverage.c_str(),
721 &segments.fFSCode);
722 }
723 dualSourceOutputWritten = true;
724 }
junov@google.comf93e7172011-03-31 21:26:24 +0000725 }
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000726
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000727 ///////////////////////////////////////////////////////////////////////////
728 // combine color and coverage as frag color
729
730 if (!wroteFragColorZero) {
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000731 modulate_helper(fsColorOutput,
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000732 inColor.c_str(),
733 inCoverage.c_str(),
734 &segments.fFSCode);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000735 }
736
bsalomon@google.com91961302011-05-09 18:39:58 +0000737 segments.fVSCode.append("}\n");
738 segments.fFSCode.append("}\n");
739
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000740 ///////////////////////////////////////////////////////////////////////////
741 // compile and setup attribs and unis
742
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000743 if (!CompileFSAndVS(gl, glslVersion, segments, programData)) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000744 return false;
745 }
746
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000747 if (!this->bindOutputsAttribsAndLinkProgram(gl, texCoordAttrs,
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000748 isColorDeclared,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000749 dualSourceOutputWritten,
750 programData)) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000751 return false;
752 }
753
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000754 this->getUniformLocationsAndInitCache(gl, programData);
bsalomon@google.com91961302011-05-09 18:39:58 +0000755
756 return true;
757}
758
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000759namespace {
760
761void expand_decls(const VarArray& unis,
762 const GrGLInterface* gl,
763 const char* prefix,
764 GrStringBuilder* string) {
765 const int count = unis.count();
766 for (int i = 0; i < count; ++i) {
767 string->append(prefix);
768 string->append(" ");
769 unis[i].appendDecl(gl, string);
770 string->append(";\n");
771 }
772}
773
774void print_shader(int stringCnt,
775 const char** strings,
776 int* stringLengths) {
777 for (int i = 0; i < stringCnt; ++i) {
778 if (NULL == stringLengths || stringLengths[i] < 0) {
779 GrPrintf(strings[i]);
780 } else {
781 GrPrintf("%.*s", stringLengths[i], strings[i]);
782 }
783 }
784}
785}
786
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000787bool GrGLProgram::CompileFSAndVS(const GrGLInterface* gl,
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000788 GLSLVersion glslVersion,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000789 const ShaderCodeSegments& segments,
bsalomon@google.com91961302011-05-09 18:39:58 +0000790 CachedData* programData) {
junov@google.comf93e7172011-03-31 21:26:24 +0000791
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000792 static const int MAX_STRINGS = 6;
793 const char* strings[MAX_STRINGS];
794 int lengths[MAX_STRINGS];
junov@google.comf93e7172011-03-31 21:26:24 +0000795 int stringCnt = 0;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000796 GrStringBuilder attrs;
797 GrStringBuilder varyings;
798 GrStringBuilder unis;
799 GrStringBuilder fsOutputs;
800
801 static const char* gVaryingPrefixes[2][2] = {{"varying", "varying"},
802 {"out", "in"}};
803 const char** varyingPrefixes = glslVersion == k120_GLSLVersion ?
804 gVaryingPrefixes[0] :
805 gVaryingPrefixes[1];
806 const char* attributePrefix = glslVersion == k120_GLSLVersion ?
807 "attribute" :
808 "in";
junov@google.comf93e7172011-03-31 21:26:24 +0000809
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000810 if (segments.fHeader.size()) {
811 strings[stringCnt] = segments.fHeader.c_str();
812 lengths[stringCnt] = segments.fHeader.size();
813 ++stringCnt;
814 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000815 expand_decls(segments.fVSUnis, gl, "uniform", &unis);
816 if (unis.size()) {
817 strings[stringCnt] = unis.c_str();
818 lengths[stringCnt] = unis.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000819 ++stringCnt;
820 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000821 expand_decls(segments.fVSAttrs, gl, attributePrefix, &attrs);
822 if (attrs.size()) {
823 strings[stringCnt] = attrs.c_str();
824 lengths[stringCnt] = attrs.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000825 ++stringCnt;
826 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000827 expand_decls(segments.fVaryings, gl, varyingPrefixes[0], &varyings);
828 if (varyings.size()) {
829 strings[stringCnt] = varyings.c_str();
830 lengths[stringCnt] = varyings.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000831 ++stringCnt;
832 }
833
bsalomon@google.comfc296292011-05-06 13:53:47 +0000834 GrAssert(segments.fVSCode.size());
835 strings[stringCnt] = segments.fVSCode.c_str();
836 lengths[stringCnt] = segments.fVSCode.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000837 ++stringCnt;
838
839#if PRINT_SHADERS
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000840 print_shader(stringCnt, strings, lengths);
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000841 GrPrintf("\n");
junov@google.comf93e7172011-03-31 21:26:24 +0000842#endif
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000843
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000844 GrAssert(stringCnt <= MAX_STRINGS);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000845 programData->fVShaderID = CompileShader(gl, GR_GL_VERTEX_SHADER,
846 stringCnt, strings, lengths);
junov@google.comf93e7172011-03-31 21:26:24 +0000847
bsalomon@google.com91961302011-05-09 18:39:58 +0000848 if (!programData->fVShaderID) {
849 return false;
850 }
851
junov@google.comf93e7172011-03-31 21:26:24 +0000852 stringCnt = 0;
853
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000854 if (segments.fHeader.size()) {
855 strings[stringCnt] = segments.fHeader.c_str();
856 lengths[stringCnt] = segments.fHeader.size();
857 ++stringCnt;
858 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000859 if (strlen(GrShaderPrecision(gl)) > 1) {
860 strings[stringCnt] = GrShaderPrecision(gl);
861 lengths[stringCnt] = strlen(GrShaderPrecision(gl));
junov@google.comf93e7172011-03-31 21:26:24 +0000862 ++stringCnt;
863 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000864 unis.reset();
865 expand_decls(segments.fFSUnis, gl, "uniform", &unis);
866 if (unis.size()) {
867 strings[stringCnt] = unis.c_str();
868 lengths[stringCnt] = unis.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000869 ++stringCnt;
870 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000871 varyings.reset();
872 expand_decls(segments.fVaryings, gl, varyingPrefixes[1], &varyings);
873 if (varyings.size()) {
874 strings[stringCnt] = varyings.c_str();
875 lengths[stringCnt] = varyings.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000876 ++stringCnt;
877 }
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000878 expand_decls(segments.fFSOutputs, gl, "out", &fsOutputs);
879 if (fsOutputs.size()) {
880 // We shouldn't have declared outputs on 1.2
881 GrAssert(k120_GLSLVersion != glslVersion);
882 strings[stringCnt] = fsOutputs.c_str();
883 lengths[stringCnt] = fsOutputs.size();
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000884 ++stringCnt;
885 }
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000886 if (segments.fFSFunctions.size()) {
887 strings[stringCnt] = segments.fFSFunctions.c_str();
888 lengths[stringCnt] = segments.fFSFunctions.size();
889 ++stringCnt;
890 }
junov@google.comf93e7172011-03-31 21:26:24 +0000891
bsalomon@google.comfc296292011-05-06 13:53:47 +0000892 GrAssert(segments.fFSCode.size());
893 strings[stringCnt] = segments.fFSCode.c_str();
894 lengths[stringCnt] = segments.fFSCode.size();
junov@google.comf93e7172011-03-31 21:26:24 +0000895 ++stringCnt;
896
897#if PRINT_SHADERS
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000898 print_shader(stringCnt, strings, lengths);
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000899 GrPrintf("\n");
junov@google.comf93e7172011-03-31 21:26:24 +0000900#endif
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000901
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000902 GrAssert(stringCnt <= MAX_STRINGS);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000903 programData->fFShaderID = CompileShader(gl, GR_GL_FRAGMENT_SHADER,
904 stringCnt, strings, lengths);
junov@google.comf93e7172011-03-31 21:26:24 +0000905
bsalomon@google.com91961302011-05-09 18:39:58 +0000906 if (!programData->fFShaderID) {
907 return false;
junov@google.comf93e7172011-03-31 21:26:24 +0000908 }
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000909
bsalomon@google.com91961302011-05-09 18:39:58 +0000910 return true;
junov@google.comf93e7172011-03-31 21:26:24 +0000911}
912
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000913GrGLuint GrGLProgram::CompileShader(const GrGLInterface* gl,
914 GrGLenum type,
915 int stringCnt,
916 const char** strings,
917 int* stringLengths) {
tomhudson@google.com278cbb42011-06-30 19:37:01 +0000918 SK_TRACE_EVENT1("GrGLProgram::CompileShader",
919 "stringCount", SkStringPrintf("%i", stringCnt).c_str());
920
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000921 GrGLuint shader;
922 GR_GL_CALL_RET(gl, shader, CreateShader(type));
junov@google.comf93e7172011-03-31 21:26:24 +0000923 if (0 == shader) {
924 return 0;
925 }
926
927 GrGLint compiled = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000928 GR_GL_CALL(gl, ShaderSource(shader, stringCnt, strings, stringLengths));
929 GR_GL_CALL(gl, CompileShader(shader));
930 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled));
junov@google.comf93e7172011-03-31 21:26:24 +0000931
932 if (!compiled) {
933 GrGLint infoLen = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000934 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
bsalomon@google.com3582bf92011-06-30 21:32:31 +0000935 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
junov@google.comf93e7172011-03-31 21:26:24 +0000936 if (infoLen > 0) {
bsalomon@google.com79afcaa2011-09-14 14:29:18 +0000937 // retrieve length even though we don't need it to workaround
938 // bug in chrome cmd buffer param validation.
939 GrGLsizei length = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000940 GR_GL_CALL(gl, GetShaderInfoLog(shader, infoLen+1,
bsalomon@google.com79afcaa2011-09-14 14:29:18 +0000941 &length, (char*)log.get()));
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000942 print_shader(stringCnt, strings, stringLengths);
junov@google.comf93e7172011-03-31 21:26:24 +0000943 GrPrintf("\n%s", log.get());
944 }
945 GrAssert(!"Shader compilation failed!");
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000946 GR_GL_CALL(gl, DeleteShader(shader));
junov@google.comf93e7172011-03-31 21:26:24 +0000947 return 0;
948 }
949 return shader;
950}
951
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000952bool GrGLProgram::bindOutputsAttribsAndLinkProgram(
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000953 const GrGLInterface* gl,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000954 GrStringBuilder texCoordAttrNames[],
955 bool bindColorOut,
tomhudson@google.com0d831722011-06-02 15:37:14 +0000956 bool bindDualSrcOut,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000957 CachedData* programData) const {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +0000958 GR_GL_CALL_RET(gl, programData->fProgramID, CreateProgram());
bsalomon@google.com91961302011-05-09 18:39:58 +0000959 if (!programData->fProgramID) {
960 return false;
961 }
962 const GrGLint& progID = programData->fProgramID;
963
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000964 GR_GL_CALL(gl, AttachShader(progID, programData->fVShaderID));
965 GR_GL_CALL(gl, AttachShader(progID, programData->fFShaderID));
bsalomon@google.com91961302011-05-09 18:39:58 +0000966
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000967 if (bindColorOut) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000968 GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000969 0, 0, declared_color_output_name()));
970 }
971 if (bindDualSrcOut) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000972 GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000973 0, 1, dual_source_output_name()));
974 }
975
bsalomon@google.com91961302011-05-09 18:39:58 +0000976 // Bind the attrib locations to same values for all shaders
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000977 GR_GL_CALL(gl, BindAttribLocation(progID, PositionAttributeIdx(),
978 POS_ATTR_NAME));
bsalomon@google.com91961302011-05-09 18:39:58 +0000979 for (int t = 0; t < GrDrawTarget::kMaxTexCoords; ++t) {
980 if (texCoordAttrNames[t].size()) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000981 GR_GL_CALL(gl, BindAttribLocation(progID,
982 TexCoordAttributeIdx(t),
983 texCoordAttrNames[t].c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +0000984 }
985 }
986
bsalomon@google.com91961302011-05-09 18:39:58 +0000987 if (kSetAsAttribute == programData->fUniLocations.fViewMatrixUni) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000988 GR_GL_CALL(gl, BindAttribLocation(progID,
989 ViewMatrixAttributeIdx(),
990 VIEW_MATRIX_NAME));
bsalomon@google.com91961302011-05-09 18:39:58 +0000991 }
992
993 for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
bsalomon@google.com72b4fcb2011-05-09 20:47:34 +0000994 const StageUniLocations& unis = programData->fUniLocations.fStages[s];
995 if (kSetAsAttribute == unis.fTextureMatrixUni) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000996 GrStringBuilder matName;
997 tex_matrix_name(s, &matName);
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000998 GR_GL_CALL(gl, BindAttribLocation(progID,
999 TextureMatrixAttributeIdx(s),
1000 matName.c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001001 }
1002 }
1003
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001004 GR_GL_CALL(gl, BindAttribLocation(progID, ColorAttributeIdx(),
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001005 COL_ATTR_NAME));
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001006 GR_GL_CALL(gl, BindAttribLocation(progID, EdgeAttributeIdx(),
1007 EDGE_ATTR_NAME));
bsalomon@google.com91961302011-05-09 18:39:58 +00001008
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001009 GR_GL_CALL(gl, LinkProgram(progID));
bsalomon@google.com91961302011-05-09 18:39:58 +00001010
1011 GrGLint linked = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001012 GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_LINK_STATUS, &linked));
bsalomon@google.com91961302011-05-09 18:39:58 +00001013 if (!linked) {
1014 GrGLint infoLen = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001015 GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
bsalomon@google.com3582bf92011-06-30 21:32:31 +00001016 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
bsalomon@google.com91961302011-05-09 18:39:58 +00001017 if (infoLen > 0) {
bsalomon@google.com79afcaa2011-09-14 14:29:18 +00001018 // retrieve length even though we don't need it to workaround
1019 // bug in chrome cmd buffer param validation.
1020 GrGLsizei length = GR_GL_INIT_ZERO;
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001021 GR_GL_CALL(gl, GetProgramInfoLog(progID, infoLen+1,
bsalomon@google.com79afcaa2011-09-14 14:29:18 +00001022 &length, (char*)log.get()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001023 GrPrintf((char*)log.get());
1024 }
1025 GrAssert(!"Error linking program");
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001026 GR_GL_CALL(gl, DeleteProgram(progID));
bsalomon@google.com91961302011-05-09 18:39:58 +00001027 programData->fProgramID = 0;
1028 return false;
1029 }
1030 return true;
1031}
1032
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001033void GrGLProgram::getUniformLocationsAndInitCache(const GrGLInterface* gl,
1034 CachedData* programData) const {
bsalomon@google.com91961302011-05-09 18:39:58 +00001035 const GrGLint& progID = programData->fProgramID;
1036
1037 if (kUseUniform == programData->fUniLocations.fViewMatrixUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001038 GR_GL_CALL_RET(gl, programData->fUniLocations.fViewMatrixUni,
1039 GetUniformLocation(progID, VIEW_MATRIX_NAME));
bsalomon@google.com91961302011-05-09 18:39:58 +00001040 GrAssert(kUnusedUniform != programData->fUniLocations.fViewMatrixUni);
1041 }
1042 if (kUseUniform == programData->fUniLocations.fColorUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001043 GR_GL_CALL_RET(gl, programData->fUniLocations.fColorUni,
1044 GetUniformLocation(progID, COL_UNI_NAME));
bsalomon@google.com91961302011-05-09 18:39:58 +00001045 GrAssert(kUnusedUniform != programData->fUniLocations.fColorUni);
1046 }
Scroggo97c88c22011-05-11 14:05:25 +00001047 if (kUseUniform == programData->fUniLocations.fColorFilterUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001048 GR_GL_CALL_RET(gl, programData->fUniLocations.fColorFilterUni,
1049 GetUniformLocation(progID, COL_FILTER_UNI_NAME));
Scroggo97c88c22011-05-11 14:05:25 +00001050 GrAssert(kUnusedUniform != programData->fUniLocations.fColorFilterUni);
1051 }
bsalomon@google.com91961302011-05-09 18:39:58 +00001052
bsalomon@google.comf2d91552011-05-16 20:56:06 +00001053 if (kUseUniform == programData->fUniLocations.fEdgesUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001054 GR_GL_CALL_RET(gl, programData->fUniLocations.fEdgesUni,
1055 GetUniformLocation(progID, EDGES_UNI_NAME));
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +00001056 GrAssert(kUnusedUniform != programData->fUniLocations.fEdgesUni);
1057 } else {
1058 programData->fUniLocations.fEdgesUni = kUnusedUniform;
1059 }
1060
bsalomon@google.com91961302011-05-09 18:39:58 +00001061 for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
1062 StageUniLocations& locations = programData->fUniLocations.fStages[s];
tomhudson@google.com0d831722011-06-02 15:37:14 +00001063 if (fProgramDesc.fStages[s].isEnabled()) {
bsalomon@google.com91961302011-05-09 18:39:58 +00001064 if (kUseUniform == locations.fTextureMatrixUni) {
1065 GrStringBuilder texMName;
1066 tex_matrix_name(s, &texMName);
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001067 GR_GL_CALL_RET(gl, locations.fTextureMatrixUni,
1068 GetUniformLocation(progID, texMName.c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001069 GrAssert(kUnusedUniform != locations.fTextureMatrixUni);
1070 }
1071
1072 if (kUseUniform == locations.fSamplerUni) {
1073 GrStringBuilder samplerName;
1074 sampler_name(s, &samplerName);
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001075 GR_GL_CALL_RET(gl, locations.fSamplerUni,
1076 GetUniformLocation(progID,samplerName.c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001077 GrAssert(kUnusedUniform != locations.fSamplerUni);
1078 }
1079
1080 if (kUseUniform == locations.fNormalizedTexelSizeUni) {
1081 GrStringBuilder texelSizeName;
1082 normalized_texel_size_name(s, &texelSizeName);
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001083 GR_GL_CALL_RET(gl, locations.fNormalizedTexelSizeUni,
1084 GetUniformLocation(progID, texelSizeName.c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001085 GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni);
1086 }
1087
1088 if (kUseUniform == locations.fRadial2Uni) {
1089 GrStringBuilder radial2ParamName;
1090 radial2_param_name(s, &radial2ParamName);
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001091 GR_GL_CALL_RET(gl, locations.fRadial2Uni,
1092 GetUniformLocation(progID, radial2ParamName.c_str()));
bsalomon@google.com91961302011-05-09 18:39:58 +00001093 GrAssert(kUnusedUniform != locations.fRadial2Uni);
1094 }
junov@google.com6acc9b32011-05-16 18:32:07 +00001095
1096 if (kUseUniform == locations.fTexDomUni) {
1097 GrStringBuilder texDomName;
1098 tex_domain_name(s, &texDomName);
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001099 GR_GL_CALL_RET(gl, locations.fTexDomUni,
1100 GetUniformLocation(progID, texDomName.c_str()));
junov@google.com6acc9b32011-05-16 18:32:07 +00001101 GrAssert(kUnusedUniform != locations.fTexDomUni);
1102 }
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001103
1104 GrStringBuilder kernelName, imageIncrementName;
1105 convolve_param_names(s, &kernelName, &imageIncrementName);
1106 if (kUseUniform == locations.fKernelUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001107 GR_GL_CALL_RET(gl, locations.fKernelUni,
1108 GetUniformLocation(progID, kernelName.c_str()));
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001109 GrAssert(kUnusedUniform != locations.fKernelUni);
1110 }
1111
1112 if (kUseUniform == locations.fImageIncrementUni) {
bsalomon@google.com56bfc5a2011-09-01 13:28:16 +00001113 GR_GL_CALL_RET(gl, locations.fImageIncrementUni,
1114 GetUniformLocation(progID,
1115 imageIncrementName.c_str()));
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001116 GrAssert(kUnusedUniform != locations.fImageIncrementUni);
1117 }
bsalomon@google.com91961302011-05-09 18:39:58 +00001118 }
1119 }
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001120 GR_GL_CALL(gl, UseProgram(progID));
bsalomon@google.com91961302011-05-09 18:39:58 +00001121
1122 // init sampler unis and set bogus values for state tracking
1123 for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
1124 if (kUnusedUniform != programData->fUniLocations.fStages[s].fSamplerUni) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001125 GR_GL_CALL(gl, Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
bsalomon@google.com91961302011-05-09 18:39:58 +00001126 }
1127 programData->fTextureMatrices[s] = GrMatrix::InvalidMatrix();
1128 programData->fRadial2CenterX1[s] = GR_ScalarMax;
1129 programData->fRadial2Radius0[s] = -GR_ScalarMax;
1130 programData->fTextureWidth[s] = -1;
1131 programData->fTextureHeight[s] = -1;
1132 }
1133 programData->fViewMatrix = GrMatrix::InvalidMatrix();
1134 programData->fColor = GrColor_ILLEGAL;
Scroggo97c88c22011-05-11 14:05:25 +00001135 programData->fColorFilterColor = GrColor_ILLEGAL;
bsalomon@google.com91961302011-05-09 18:39:58 +00001136}
1137
junov@google.comf93e7172011-03-31 21:26:24 +00001138//============================================================================
1139// Stage code generation
1140//============================================================================
1141
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001142void GrGLProgram::genStageCode(const GrGLInterface* gl,
1143 int stageNum,
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001144 const GrGLProgram::StageDesc& desc,
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001145 const char* fsInColor, // NULL means no incoming color
1146 const char* fsOutColor,
1147 const char* vsInCoord,
1148 ShaderCodeSegments* segments,
1149 StageUniLocations* locations) const {
junov@google.comf93e7172011-03-31 21:26:24 +00001150
1151 GrAssert(stageNum >= 0 && stageNum <= 9);
1152
junov@google.comf93e7172011-03-31 21:26:24 +00001153 // First decide how many coords are needed to access the texture
1154 // Right now it's always 2 but we could start using 1D textures for
1155 // gradients.
1156 static const int coordDims = 2;
1157 int varyingDims;
1158 /// Vertex Shader Stuff
1159
1160 // decide whether we need a matrix to transform texture coords
1161 // and whether the varying needs a perspective coord.
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001162 const char* matName = NULL;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001163 if (desc.fOptFlags & StageDesc::kIdentityMatrix_OptFlagBit) {
junov@google.comf93e7172011-03-31 21:26:24 +00001164 varyingDims = coordDims;
1165 } else {
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001166 GrGLShaderVar* mat;
bsalomon@google.com4be283f2011-04-19 21:15:09 +00001167 #if GR_GL_ATTRIBUTE_MATRICES
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001168 mat = &segments->fVSAttrs.push_back();
bsalomon@google.com91961302011-05-09 18:39:58 +00001169 locations->fTextureMatrixUni = kSetAsAttribute;
junov@google.comf93e7172011-03-31 21:26:24 +00001170 #else
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001171 mat = &segments->fVSUnis.push_back();
bsalomon@google.com91961302011-05-09 18:39:58 +00001172 locations->fTextureMatrixUni = kUseUniform;
junov@google.comf93e7172011-03-31 21:26:24 +00001173 #endif
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001174 tex_matrix_name(stageNum, mat->accessName());
1175 mat->setType(GrGLShaderVar::kMat33f_Type);
1176 matName = mat->getName().c_str();
1177
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001178 if (desc.fOptFlags & StageDesc::kNoPerspective_OptFlagBit) {
junov@google.comf93e7172011-03-31 21:26:24 +00001179 varyingDims = coordDims;
1180 } else {
1181 varyingDims = coordDims + 1;
1182 }
1183 }
1184
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001185 segments->fFSUnis.push_back().setType(GrGLShaderVar::kSampler2D_Type);
1186 sampler_name(stageNum, segments->fFSUnis.back().accessName());
bsalomon@google.com91961302011-05-09 18:39:58 +00001187 locations->fSamplerUni = kUseUniform;
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001188 const char* samplerName = segments->fFSUnis.back().getName().c_str();
junov@google.comf93e7172011-03-31 21:26:24 +00001189
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001190 const char* texelSizeName = NULL;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001191 if (StageDesc::k2x2_FetchMode == desc.fFetchMode) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001192 segments->fFSUnis.push_back().setType(GrGLShaderVar::kVec2f_Type);
1193 normalized_texel_size_name(stageNum, segments->fFSUnis.back().accessName());
1194 texelSizeName = segments->fFSUnis.back().getName().c_str();
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001195 }
1196
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001197 const char* varyingName;
1198 GrGLShaderVar* varying = &segments->fVaryings.push_back();
1199 stage_varying_name(stageNum, varying->accessName());
1200 varying->setType(float_vector_type(varyingDims));
1201 varyingName = varying->getName().c_str();
junov@google.comf93e7172011-03-31 21:26:24 +00001202
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001203 if (!matName) {
junov@google.comf93e7172011-03-31 21:26:24 +00001204 GrAssert(varyingDims == coordDims);
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001205 segments->fVSCode.appendf("\t%s = %s;\n", varyingName, vsInCoord);
junov@google.comf93e7172011-03-31 21:26:24 +00001206 } else {
bsalomon@google.com91961302011-05-09 18:39:58 +00001207 // varying = texMatrix * texCoord
1208 segments->fVSCode.appendf("\t%s = (%s * vec3(%s, 1))%s;\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001209 varyingName, matName, vsInCoord,
1210 vector_all_coords(varyingDims));
junov@google.comf93e7172011-03-31 21:26:24 +00001211 }
1212
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001213 const char* radial2ParamsName = NULL;
1214 const char* radial2VaryingName = NULL;
junov@google.comf93e7172011-03-31 21:26:24 +00001215
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001216 if (StageDesc::kRadial2Gradient_CoordMapping == desc.fCoordMapping ||
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001217 StageDesc::kRadial2GradientDegenerate_CoordMapping == desc.fCoordMapping) {
junov@google.comf93e7172011-03-31 21:26:24 +00001218
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001219 GrGLShaderVar* radial2FSParams = &segments->fFSUnis.push_back();
1220 radial2FSParams->setType(GrGLShaderVar::kFloat_Type);
1221 radial2FSParams->setArrayCount(6);
1222 radial2_param_name(stageNum, radial2FSParams->accessName());
1223 segments->fVSUnis.push_back(*radial2FSParams).setEmitPrecision(true);
1224 radial2ParamsName = radial2FSParams->getName().c_str();
1225
bsalomon@google.com91961302011-05-09 18:39:58 +00001226 locations->fRadial2Uni = kUseUniform;
junov@google.comf93e7172011-03-31 21:26:24 +00001227
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001228 // for radial grads without perspective we can pass the linear
1229 // part of the quadratic as a varying.
junov@google.comf93e7172011-03-31 21:26:24 +00001230 if (varyingDims == coordDims) {
1231 GrAssert(2 == coordDims);
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001232
1233 GrGLShaderVar* radial2Varying = &segments->fVaryings.push_back();
1234 radial2Varying->setType(GrGLShaderVar::kFloat_Type);
1235 radial2_varying_name(stageNum, radial2Varying->accessName());
1236 radial2VaryingName = radial2Varying->getName().c_str();
junov@google.comf93e7172011-03-31 21:26:24 +00001237
bsalomon@google.com91961302011-05-09 18:39:58 +00001238 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001239 const char* r2ParamName = radial2FSParams->getName().c_str();
1240 const char* r2VarName = radial2Varying->getName().c_str();
bsalomon@google.com91961302011-05-09 18:39:58 +00001241 segments->fVSCode.appendf("\t%s = 2.0 *(%s[2] * %s.x - %s[3]);\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001242 r2VarName, r2ParamName, varyingName,
1243 r2ParamName);
junov@google.comf93e7172011-03-31 21:26:24 +00001244 }
1245 }
1246
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001247 const char* kernelName = NULL;
1248 const char* imageIncrementName = NULL;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001249 if (ProgramDesc::StageDesc::kConvolution_FetchMode == desc.fFetchMode) {
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001250
1251 GrGLShaderVar* kernel = &segments->fFSUnis.push_back();
1252 kernel->setType(GrGLShaderVar::kFloat_Type);
1253 kernel->setArrayCount(desc.fKernelWidth);
1254 GrGLShaderVar* imgInc = &segments->fFSUnis.push_back();
1255 imgInc->setType(GrGLShaderVar::kVec2f_Type);
1256
1257 convolve_param_names(stageNum,
1258 kernel->accessName(),
1259 imgInc->accessName());
1260 kernelName = kernel->getName().c_str();
1261 imageIncrementName = imgInc->getName().c_str();
1262
1263 // need image increment in both VS and FS
1264 segments->fVSUnis.push_back(*imgInc).setEmitPrecision(true);
1265
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001266 locations->fKernelUni = kUseUniform;
1267 locations->fImageIncrementUni = kUseUniform;
1268 float scale = (desc.fKernelWidth - 1) * 0.5f;
1269 segments->fVSCode.appendf("\t%s -= vec2(%g, %g) * %s;\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001270 varyingName, scale, scale,
1271 imageIncrementName);
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001272 }
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001273
junov@google.comf93e7172011-03-31 21:26:24 +00001274 /// Fragment Shader Stuff
bsalomon@google.com91961302011-05-09 18:39:58 +00001275 GrStringBuilder fsCoordName;
junov@google.comf93e7172011-03-31 21:26:24 +00001276 // function used to access the shader, may be made projective
bsalomon@google.com91961302011-05-09 18:39:58 +00001277 GrStringBuilder texFunc("texture2D");
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001278 if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit |
1279 StageDesc::kNoPerspective_OptFlagBit)) {
junov@google.comf93e7172011-03-31 21:26:24 +00001280 GrAssert(varyingDims == coordDims);
1281 fsCoordName = varyingName;
1282 } else {
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001283 // if we have to do some special op on the varyings to get
junov@google.comf93e7172011-03-31 21:26:24 +00001284 // our final tex coords then when in perspective we have to
bsalomon@google.com91961302011-05-09 18:39:58 +00001285 // do an explicit divide. Otherwise, we can use a Proj func.
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001286 if (StageDesc::kIdentity_CoordMapping == desc.fCoordMapping &&
1287 StageDesc::kSingle_FetchMode == desc.fFetchMode) {
bsalomon@google.com91961302011-05-09 18:39:58 +00001288 texFunc.append("Proj");
junov@google.comf93e7172011-03-31 21:26:24 +00001289 fsCoordName = varyingName;
1290 } else {
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001291 fsCoordName = "inCoord";
bsalomon@google.comfc296292011-05-06 13:53:47 +00001292 fsCoordName.appendS32(stageNum);
bsalomon@google.com91961302011-05-09 18:39:58 +00001293 segments->fFSCode.appendf("\t%s %s = %s%s / %s%s;\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001294 GrGLShaderVar::TypeString(float_vector_type(coordDims)),
1295 fsCoordName.c_str(),
1296 varyingName,
1297 vector_nonhomog_coords(varyingDims),
1298 varyingName,
1299 vector_homog_coord(varyingDims));
junov@google.comf93e7172011-03-31 21:26:24 +00001300 }
1301 }
1302
bsalomon@google.comfc296292011-05-06 13:53:47 +00001303 GrStringBuilder sampleCoords;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001304 bool complexCoord = false;
junov@google.comf93e7172011-03-31 21:26:24 +00001305 switch (desc.fCoordMapping) {
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001306 case StageDesc::kIdentity_CoordMapping:
junov@google.comf93e7172011-03-31 21:26:24 +00001307 sampleCoords = fsCoordName;
1308 break;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001309 case StageDesc::kSweepGradient_CoordMapping:
bsalomon@google.com91961302011-05-09 18:39:58 +00001310 sampleCoords.printf("vec2(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5, 0.5)", fsCoordName.c_str(), fsCoordName.c_str());
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001311 complexCoord = true;
junov@google.comf93e7172011-03-31 21:26:24 +00001312 break;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001313 case StageDesc::kRadialGradient_CoordMapping:
bsalomon@google.com91961302011-05-09 18:39:58 +00001314 sampleCoords.printf("vec2(length(%s.xy), 0.5)", fsCoordName.c_str());
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001315 complexCoord = true;
junov@google.comf93e7172011-03-31 21:26:24 +00001316 break;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001317 case StageDesc::kRadial2Gradient_CoordMapping: {
bsalomon@google.com91961302011-05-09 18:39:58 +00001318 GrStringBuilder cName("c");
1319 GrStringBuilder ac4Name("ac4");
1320 GrStringBuilder rootName("root");
junov@google.comf93e7172011-03-31 21:26:24 +00001321
bsalomon@google.comfc296292011-05-06 13:53:47 +00001322 cName.appendS32(stageNum);
1323 ac4Name.appendS32(stageNum);
1324 rootName.appendS32(stageNum);
junov@google.comf93e7172011-03-31 21:26:24 +00001325
bsalomon@google.com91961302011-05-09 18:39:58 +00001326 // if we were able to interpolate the linear component bVar is the varying
1327 // otherwise compute it
1328 GrStringBuilder bVar;
junov@google.comf93e7172011-03-31 21:26:24 +00001329 if (coordDims == varyingDims) {
1330 bVar = radial2VaryingName;
1331 GrAssert(2 == varyingDims);
1332 } else {
1333 GrAssert(3 == varyingDims);
1334 bVar = "b";
bsalomon@google.comfc296292011-05-06 13:53:47 +00001335 bVar.appendS32(stageNum);
bsalomon@google.com91961302011-05-09 18:39:58 +00001336 segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s[2] * %s.x - %s[3]);\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001337 bVar.c_str(), radial2ParamsName,
1338 fsCoordName.c_str(), radial2ParamsName);
junov@google.comf93e7172011-03-31 21:26:24 +00001339 }
1340
bsalomon@google.com91961302011-05-09 18:39:58 +00001341 // c = (x^2)+(y^2) - params[4]
1342 segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s[4];\n",
1343 cName.c_str(), fsCoordName.c_str(),
1344 fsCoordName.c_str(),
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001345 radial2ParamsName);
bsalomon@google.com91961302011-05-09 18:39:58 +00001346 // ac4 = 4.0 * params[0] * c
1347 segments->fFSCode.appendf("\tfloat %s = %s[0] * 4.0 * %s;\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001348 ac4Name.c_str(), radial2ParamsName,
bsalomon@google.com91961302011-05-09 18:39:58 +00001349 cName.c_str());
junov@google.comf93e7172011-03-31 21:26:24 +00001350
bsalomon@google.com91961302011-05-09 18:39:58 +00001351 // root = sqrt(b^2-4ac)
1352 // (abs to avoid exception due to fp precision)
1353 segments->fFSCode.appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
1354 rootName.c_str(), bVar.c_str(), bVar.c_str(),
1355 ac4Name.c_str());
junov@google.comf93e7172011-03-31 21:26:24 +00001356
bsalomon@google.com91961302011-05-09 18:39:58 +00001357 // x coord is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
1358 // y coord is 0.5 (texture is effectively 1D)
1359 sampleCoords.printf("vec2((-%s + %s[5] * %s) * %s[1], 0.5)",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001360 bVar.c_str(), radial2ParamsName,
1361 rootName.c_str(), radial2ParamsName);
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001362 complexCoord = true;
junov@google.comf93e7172011-03-31 21:26:24 +00001363 break;}
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001364 case StageDesc::kRadial2GradientDegenerate_CoordMapping: {
1365 GrStringBuilder cName("c");
1366
1367 cName.appendS32(stageNum);
1368
1369 // if we were able to interpolate the linear component bVar is the varying
1370 // otherwise compute it
1371 GrStringBuilder bVar;
1372 if (coordDims == varyingDims) {
1373 bVar = radial2VaryingName;
1374 GrAssert(2 == varyingDims);
1375 } else {
1376 GrAssert(3 == varyingDims);
1377 bVar = "b";
1378 bVar.appendS32(stageNum);
1379 segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s[2] * %s.x - %s[3]);\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001380 bVar.c_str(), radial2ParamsName,
1381 fsCoordName.c_str(), radial2ParamsName);
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001382 }
1383
1384 // c = (x^2)+(y^2) - params[4]
1385 segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s[4];\n",
1386 cName.c_str(), fsCoordName.c_str(),
1387 fsCoordName.c_str(),
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001388 radial2ParamsName);
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001389
1390 // x coord is: -c/b
1391 // y coord is 0.5 (texture is effectively 1D)
1392 sampleCoords.printf("vec2((-%s / %s), 0.5)", cName.c_str(), bVar.c_str());
1393 complexCoord = true;
1394 break;}
junov@google.comf93e7172011-03-31 21:26:24 +00001395 };
1396
bsalomon@google.com91961302011-05-09 18:39:58 +00001397 const char* smear;
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001398 if (desc.fModulation == StageDesc::kAlpha_Modulation) {
bsalomon@google.com91961302011-05-09 18:39:58 +00001399 smear = ".aaaa";
1400 } else {
1401 smear = "";
1402 }
1403 GrStringBuilder modulate;
1404 if (NULL != fsInColor) {
1405 modulate.printf(" * %s", fsInColor);
1406 }
1407
tomhudson@google.com0d831722011-06-02 15:37:14 +00001408 if (desc.fOptFlags &
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001409 StageDesc::kCustomTextureDomain_OptFlagBit) {
junov@google.com6acc9b32011-05-16 18:32:07 +00001410 GrStringBuilder texDomainName;
1411 tex_domain_name(stageNum, &texDomainName);
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001412 segments->fFSUnis.push_back().set(GrGLShaderVar::kVec4f_Type, texDomainName);
junov@google.com6acc9b32011-05-16 18:32:07 +00001413 GrStringBuilder coordVar("clampCoord");
1414 segments->fFSCode.appendf("\t%s %s = clamp(%s, %s.xy, %s.zw);\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001415 float_vector_type_str(coordDims),
junov@google.com6acc9b32011-05-16 18:32:07 +00001416 coordVar.c_str(),
1417 sampleCoords.c_str(),
1418 texDomainName.c_str(),
1419 texDomainName.c_str());
1420 sampleCoords = coordVar;
1421 locations->fTexDomUni = kUseUniform;
1422 }
1423
bsalomon@google.com22c5dea2011-07-07 14:38:03 +00001424 if (StageDesc::k2x2_FetchMode == desc.fFetchMode) {
bsalomon@google.com91961302011-05-09 18:39:58 +00001425 locations->fNormalizedTexelSizeUni = kUseUniform;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001426 if (complexCoord) {
bsalomon@google.com91961302011-05-09 18:39:58 +00001427 // assign the coord to a var rather than compute 4x.
1428 GrStringBuilder coordVar("tCoord");
bsalomon@google.comfc296292011-05-06 13:53:47 +00001429 coordVar.appendS32(stageNum);
bsalomon@google.com91961302011-05-09 18:39:58 +00001430 segments->fFSCode.appendf("\t%s %s = %s;\n",
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001431 float_vector_type_str(coordDims),
1432 coordVar.c_str(), sampleCoords.c_str());
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001433 sampleCoords = coordVar;
1434 }
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001435 GrAssert(2 == coordDims);
bsalomon@google.com91961302011-05-09 18:39:58 +00001436 GrStringBuilder accumVar("accum");
1437 accumVar.appendS32(stageNum);
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001438 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, smear);
1439 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, smear);
1440 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, smear);
1441 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, smear);
bsalomon@google.com91961302011-05-09 18:39:58 +00001442 segments->fFSCode.appendf("\t%s = .25 * %s%s;\n", fsOutColor, accumVar.c_str(), modulate.c_str());
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001443 } else if (ProgramDesc::StageDesc::kConvolution_FetchMode == desc.fFetchMode) {
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001444 GrStringBuilder sumVar("sum");
1445 sumVar.appendS32(stageNum);
1446 GrStringBuilder coordVar("coord");
1447 coordVar.appendS32(stageNum);
1448
1449 segments->fFSCode.appendf("\tvec4 %s = vec4(0, 0, 0, 0);\n",
1450 sumVar.c_str());
1451 segments->fFSCode.appendf("\tvec2 %s = %s;\n",
1452 coordVar.c_str(),
1453 sampleCoords.c_str());
1454 segments->fFSCode.appendf("\tfor (int i = 0; i < %d; i++) {\n",
1455 desc.fKernelWidth);
1456 segments->fFSCode.appendf("\t\t%s += %s(%s, %s)%s * %s[i];\n",
1457 sumVar.c_str(), texFunc.c_str(),
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001458 samplerName, coordVar.c_str(), smear,
1459 kernelName);
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001460 segments->fFSCode.appendf("\t\t%s += %s;\n",
1461 coordVar.c_str(),
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001462 imageIncrementName);
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +00001463 segments->fFSCode.appendf("\t}\n");
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001464 segments->fFSCode.appendf("\t%s = %s%s;\n", fsOutColor,
1465 sumVar.c_str(), modulate.c_str());
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +00001466 } else {
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001467 segments->fFSCode.appendf("\t%s = %s(%s, %s)%s%s;\n",
1468 fsOutColor, texFunc.c_str(),
bsalomon@google.com4fa66942011-09-20 19:06:12 +00001469 samplerName, sampleCoords.c_str(),
bsalomon@google.coma8e686e2011-08-16 15:45:58 +00001470 smear, modulate.c_str());
junov@google.comf93e7172011-03-31 21:26:24 +00001471 }
junov@google.comf93e7172011-03-31 21:26:24 +00001472}