OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "glsl/GrGLSLProgramBuilder.h" | 8 #include "glsl/GrGLSLProgramBuilder.h" |
9 | 9 |
10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
oc, | 82 void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
oc, |
83 GrGLSLExpr4* outputColor, | 83 GrGLSLExpr4* outputColor, |
84 GrGLSLExpr4* outputCoverage) { | 84 GrGLSLExpr4* outputCoverage) { |
85 // Program builders have a bit of state we need to clear with each effect | 85 // Program builders have a bit of state we need to clear with each effect |
86 AutoStageAdvance adv(this); | 86 AutoStageAdvance adv(this); |
87 this->nameExpression(outputColor, "outputColor"); | 87 this->nameExpression(outputColor, "outputColor"); |
88 this->nameExpression(outputCoverage, "outputCoverage"); | 88 this->nameExpression(outputCoverage, "outputCoverage"); |
89 | 89 |
| 90 const char* distanceVectorName = nullptr; |
| 91 if (this->fPipeline.usesDistanceVectorField() && proc.implementsDistanceVect
or()) { |
| 92 distanceVectorName = fFS.distanceVectorName(); |
| 93 fFS.codeAppend( "// Un-normalized vector to the closed geometric edge (i
n source space)\n"); |
| 94 fFS.codeAppendf("vec2 %s;", distanceVectorName); |
| 95 } |
| 96 |
90 // Enclose custom code in a block to avoid namespace conflicts | 97 // Enclose custom code in a block to avoid namespace conflicts |
91 SkString openBrace; | 98 SkString openBrace; |
92 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); | 99 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); |
93 fFS.codeAppend(openBrace.c_str()); | 100 fFS.codeAppend(openBrace.c_str()); |
94 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); | 101 fVS.codeAppendf("// Primitive Processor %s\n", proc.name()); |
95 | 102 |
96 SkASSERT(!fGeometryProcessor); | 103 SkASSERT(!fGeometryProcessor); |
97 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); | 104 fGeometryProcessor = proc.createGLSLInstance(*this->glslCaps()); |
98 | 105 |
99 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures()); | 106 SkSTArray<4, SamplerHandle> texSamplers(proc.numTextures()); |
100 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); | 107 SkSTArray<2, SamplerHandle> bufferSamplers(proc.numBuffers()); |
101 this->emitSamplers(proc, &texSamplers, &bufferSamplers); | 108 this->emitSamplers(proc, &texSamplers, &bufferSamplers); |
102 | 109 |
103 GrGLSLGeometryProcessor::EmitArgs args(&fVS, | 110 GrGLSLGeometryProcessor::EmitArgs args(&fVS, |
104 &fFS, | 111 &fFS, |
105 this->varyingHandler(), | 112 this->varyingHandler(), |
106 this->uniformHandler(), | 113 this->uniformHandler(), |
107 this->glslCaps(), | 114 this->glslCaps(), |
108 proc, | 115 proc, |
109 outputColor->c_str(), | 116 outputColor->c_str(), |
110 outputCoverage->c_str(), | 117 outputCoverage->c_str(), |
| 118 distanceVectorName, |
111 texSamplers.begin(), | 119 texSamplers.begin(), |
112 bufferSamplers.begin(), | 120 bufferSamplers.begin(), |
113 fCoordTransforms, | 121 fCoordTransforms, |
114 &fOutCoords); | 122 &fOutCoords); |
115 fGeometryProcessor->emitCode(args); | 123 fGeometryProcessor->emitCode(args); |
116 | 124 |
117 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 125 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
118 // asks for dst color, then the emit code needs to follow suit | 126 // asks for dst color, then the emit code needs to follow suit |
119 SkDEBUGCODE(verify(proc);) | 127 SkDEBUGCODE(verify(proc);) |
120 | 128 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 this->emitSamplers(fp, &texSamplers, &bufferSamplers); | 162 this->emitSamplers(fp, &texSamplers, &bufferSamplers); |
155 | 163 |
156 GrGLSLFragmentProcessor::EmitArgs args(&fFS, | 164 GrGLSLFragmentProcessor::EmitArgs args(&fFS, |
157 this->uniformHandler(), | 165 this->uniformHandler(), |
158 this->glslCaps(), | 166 this->glslCaps(), |
159 fp, | 167 fp, |
160 output->c_str(), | 168 output->c_str(), |
161 input.isOnes() ? nullptr : input.c_st
r(), | 169 input.isOnes() ? nullptr : input.c_st
r(), |
162 fOutCoords[index], | 170 fOutCoords[index], |
163 texSamplers.begin(), | 171 texSamplers.begin(), |
164 bufferSamplers.begin()); | 172 bufferSamplers.begin(), |
| 173 this->primitiveProcessor().implements
DistanceVector()); |
| 174 |
165 fragProc->emitCode(args); | 175 fragProc->emitCode(args); |
166 | 176 |
167 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 177 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
168 // asks for dst color, then the emit code needs to follow suit | 178 // asks for dst color, then the emit code needs to follow suit |
169 SkDEBUGCODE(verify(fp);) | 179 SkDEBUGCODE(verify(fp);) |
170 fFragmentProcessors.push_back(fragProc); | 180 fFragmentProcessors.push_back(fragProc); |
171 | 181 |
172 fFS.codeAppend("}"); | 182 fFS.codeAppend("}"); |
173 } | 183 } |
174 | 184 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 delete fFragmentProcessors[i]; | 411 delete fFragmentProcessors[i]; |
402 } | 412 } |
403 } | 413 } |
404 | 414 |
405 void GrGLSLProgramBuilder::finalizeShaders() { | 415 void GrGLSLProgramBuilder::finalizeShaders() { |
406 this->varyingHandler()->finalize(); | 416 this->varyingHandler()->finalize(); |
407 fVS.finalize(kVertex_GrShaderFlag); | 417 fVS.finalize(kVertex_GrShaderFlag); |
408 fFS.finalize(kFragment_GrShaderFlag); | 418 fFS.finalize(kFragment_GrShaderFlag); |
409 | 419 |
410 } | 420 } |
OLD | NEW |