OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
9 | 9 |
10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #define COL_ATTR_NAME "aColor" | 30 #define COL_ATTR_NAME "aColor" |
31 #define COV_ATTR_NAME "aCoverage" | 31 #define COV_ATTR_NAME "aCoverage" |
32 #define EDGE_ATTR_NAME "aEdge" | 32 #define EDGE_ATTR_NAME "aEdge" |
33 | 33 |
34 namespace { | 34 namespace { |
35 inline const char* declared_color_output_name() { return "fsColorOut"; } | 35 inline const char* declared_color_output_name() { return "fsColorOut"; } |
36 inline const char* dual_source_output_name() { return "dualSourceOut"; } | 36 inline const char* dual_source_output_name() { return "dualSourceOut"; } |
37 } | 37 } |
38 | 38 |
39 const GrGLProgram::AttribLayout GrGLProgram::kAttribLayouts[kGrVertexAttribTypeC
ount] = { | 39 void GrGLProgramDesc::Build(const GrDrawState& drawState, |
40 {1, GR_GL_FLOAT, false}, // kFloat_GrVertexAttribType | |
41 {2, GR_GL_FLOAT, false}, // kVec2f_GrVertexAttribType | |
42 {3, GR_GL_FLOAT, false}, // kVec3f_GrVertexAttribType | |
43 {4, GR_GL_FLOAT, false}, // kVec4f_GrVertexAttribType | |
44 {4, GR_GL_UNSIGNED_BYTE, true}, // kVec4ub_GrVertexAttribType | |
45 }; | |
46 | |
47 void GrGLProgram::BuildDesc(const GrDrawState& drawState, | |
48 bool isPoints, | 40 bool isPoints, |
49 GrDrawState::BlendOptFlags blendOpts, | 41 GrDrawState::BlendOptFlags blendOpts, |
50 GrBlendCoeff srcCoeff, | 42 GrBlendCoeff srcCoeff, |
51 GrBlendCoeff dstCoeff, | 43 GrBlendCoeff dstCoeff, |
52 const GrGpuGL* gpu, | 44 const GrGpuGL* gpu, |
53 Desc* desc) { | 45 GrGLProgramDesc* desc) { |
54 | 46 |
55 // This should already have been caught | 47 // This should already have been caught |
56 GrAssert(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); | 48 GrAssert(!(GrDrawState::kSkipDraw_BlendOptFlag & blendOpts)); |
57 | 49 |
58 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); | 50 bool skipCoverage = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendO
ptFlag); |
59 | 51 |
60 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | | 52 bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOpt
Flag | |
61 GrDrawState::kEmitCoverage_BlendOptFl
ag)); | 53 GrDrawState::kEmitCoverage_BlendOptFl
ag)); |
62 | 54 |
63 // The descriptor is used as a cache key. Thus when a field of the | 55 // The descriptor is used as a cache key. Thus when a field of the |
(...skipping 23 matching lines...) Expand all Loading... |
87 | 79 |
88 // no reason to do edge aa or look at per-vertex coverage if coverage is ign
ored | 80 // no reason to do edge aa or look at per-vertex coverage if coverage is ign
ored |
89 if (skipCoverage) { | 81 if (skipCoverage) { |
90 desc->fAttribBindings &= ~(GrDrawState::kCoverage_AttribBindingsBit); | 82 desc->fAttribBindings &= ~(GrDrawState::kCoverage_AttribBindingsBit); |
91 } | 83 } |
92 | 84 |
93 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); | 85 bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_B
lendOptFlag); |
94 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || | 86 bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFla
g) || |
95 (!requiresAttributeColors && 0xffffffff == drawStat
e.getColor()); | 87 (!requiresAttributeColors && 0xffffffff == drawStat
e.getColor()); |
96 if (colorIsTransBlack) { | 88 if (colorIsTransBlack) { |
97 desc->fColorInput = Desc::kTransBlack_ColorInput; | 89 desc->fColorInput = kTransBlack_ColorInput; |
98 } else if (colorIsSolidWhite) { | 90 } else if (colorIsSolidWhite) { |
99 desc->fColorInput = Desc::kSolidWhite_ColorInput; | 91 desc->fColorInput = kSolidWhite_ColorInput; |
100 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeColors) { | 92 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeColors) { |
101 desc->fColorInput = Desc::kUniform_ColorInput; | 93 desc->fColorInput = kUniform_ColorInput; |
102 } else { | 94 } else { |
103 desc->fColorInput = Desc::kAttribute_ColorInput; | 95 desc->fColorInput = kAttribute_ColorInput; |
104 } | 96 } |
105 | 97 |
106 bool covIsSolidWhite = !requiresAttributeCoverage && 0xffffffff == drawState
.getCoverage(); | 98 bool covIsSolidWhite = !requiresAttributeCoverage && 0xffffffff == drawState
.getCoverage(); |
107 | 99 |
108 if (skipCoverage) { | 100 if (skipCoverage) { |
109 desc->fCoverageInput = Desc::kTransBlack_ColorInput; | 101 desc->fCoverageInput = kTransBlack_ColorInput; |
110 } else if (covIsSolidWhite) { | 102 } else if (covIsSolidWhite) { |
111 desc->fCoverageInput = Desc::kSolidWhite_ColorInput; | 103 desc->fCoverageInput = kSolidWhite_ColorInput; |
112 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeCoverage) { | 104 } else if (GR_GL_NO_CONSTANT_ATTRIBUTES && !requiresAttributeCoverage) { |
113 desc->fCoverageInput = Desc::kUniform_ColorInput; | 105 desc->fCoverageInput = kUniform_ColorInput; |
114 } else { | 106 } else { |
115 desc->fCoverageInput = Desc::kAttribute_ColorInput; | 107 desc->fCoverageInput = kAttribute_ColorInput; |
116 } | 108 } |
117 | 109 |
118 int lastEnabledStage = -1; | 110 int lastEnabledStage = -1; |
119 | 111 |
120 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 112 for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
121 | 113 |
122 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; | 114 bool skip = s < drawState.getFirstCoverageStage() ? skipColor : skipCove
rage; |
123 if (!skip && drawState.isStageEnabled(s)) { | 115 if (!skip && drawState.isStageEnabled(s)) { |
124 lastEnabledStage = s; | 116 lastEnabledStage = s; |
125 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); | 117 const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
126 const GrBackendEffectFactory& factory = effect->getFactory(); | 118 const GrBackendEffectFactory& factory = effect->getFactory(); |
127 bool explicitLocalCoords = (drawState.getAttribBindings() & | 119 bool explicitLocalCoords = (drawState.getAttribBindings() & |
128 GrDrawState::kLocalCoords_AttribBindings
Bit); | 120 GrDrawState::kLocalCoords_AttribBindings
Bit); |
129 GrDrawEffect drawEffect(drawState.getStage(s), explicitLocalCoords); | 121 GrDrawEffect drawEffect(drawState.getStage(s), explicitLocalCoords); |
130 desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()
); | 122 desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps()
); |
131 } else { | 123 } else { |
132 desc->fEffectKeys[s] = 0; | 124 desc->fEffectKeys[s] = 0; |
133 } | 125 } |
134 } | 126 } |
135 | 127 |
136 desc->fDualSrcOutput = Desc::kNone_DualSrcOutput; | 128 desc->fDualSrcOutput = kNone_DualSrcOutput; |
137 | 129 |
138 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything | 130 // Currently the experimental GS will only work with triangle prims (and it
doesn't do anything |
139 // other than pass through values from the VS to the FS anyway). | 131 // other than pass through values from the VS to the FS anyway). |
140 #if GR_GL_EXPERIMENTAL_GS | 132 #if GR_GL_EXPERIMENTAL_GS |
141 #if 0 | 133 #if 0 |
142 desc->fExperimentalGS = gpu->caps().geometryShaderSupport(); | 134 desc->fExperimentalGS = gpu->caps().geometryShaderSupport(); |
143 #else | 135 #else |
144 desc->fExperimentalGS = false; | 136 desc->fExperimentalGS = false; |
145 #endif | 137 #endif |
146 #endif | 138 #endif |
(...skipping 27 matching lines...) Expand all Loading... |
174 if (drawState.getStencil().doesWrite()) { | 166 if (drawState.getStencil().doesWrite()) { |
175 desc->fDiscardIfZeroCoverage = true; | 167 desc->fDiscardIfZeroCoverage = true; |
176 desc->fFirstCoverageStage = firstCoverageStage; | 168 desc->fFirstCoverageStage = firstCoverageStage; |
177 } | 169 } |
178 | 170 |
179 if (gpu->caps()->dualSourceBlendingSupport() && | 171 if (gpu->caps()->dualSourceBlendingSupport() && |
180 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | | 172 !(blendOpts & (GrDrawState::kEmitCoverage_BlendOptFlag | |
181 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { | 173 GrDrawState::kCoverageAsAlpha_BlendOptFlag))) { |
182 if (kZero_GrBlendCoeff == dstCoeff) { | 174 if (kZero_GrBlendCoeff == dstCoeff) { |
183 // write the coverage value to second color | 175 // write the coverage value to second color |
184 desc->fDualSrcOutput = Desc::kCoverage_DualSrcOutput; | 176 desc->fDualSrcOutput = kCoverage_DualSrcOutput; |
185 desc->fFirstCoverageStage = firstCoverageStage; | 177 desc->fFirstCoverageStage = firstCoverageStage; |
186 } else if (kSA_GrBlendCoeff == dstCoeff) { | 178 } else if (kSA_GrBlendCoeff == dstCoeff) { |
187 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 179 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
188 desc->fDualSrcOutput = Desc::kCoverageISA_DualSrcOutput; | 180 desc->fDualSrcOutput = kCoverageISA_DualSrcOutput; |
189 desc->fFirstCoverageStage = firstCoverageStage; | 181 desc->fFirstCoverageStage = firstCoverageStage; |
190 } else if (kSC_GrBlendCoeff == dstCoeff) { | 182 } else if (kSC_GrBlendCoeff == dstCoeff) { |
191 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 183 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
192 desc->fDualSrcOutput = Desc::kCoverageISC_DualSrcOutput; | 184 desc->fDualSrcOutput = kCoverageISC_DualSrcOutput; |
193 desc->fFirstCoverageStage = firstCoverageStage; | 185 desc->fFirstCoverageStage = firstCoverageStage; |
194 } | 186 } |
195 } | 187 } |
196 } | 188 } |
197 | 189 |
198 desc->fPositionAttributeIndex = drawState.getAttribIndex(GrDrawState::kPosit
ion_AttribIndex); | 190 desc->fPositionAttributeIndex = drawState.getAttribIndex(GrDrawState::kPosit
ion_AttribIndex); |
199 if (requiresAttributeColors) { | 191 if (requiresAttributeColors) { |
200 desc->fColorAttributeIndex = drawState.getAttribIndex(GrDrawState::kColo
r_AttribIndex); | 192 desc->fColorAttributeIndex = drawState.getAttribIndex(GrDrawState::kColo
r_AttribIndex); |
201 } else { | 193 } else { |
202 desc->fColorAttributeIndex = GrDrawState::kColorOverrideAttribIndexValue
; | 194 desc->fColorAttributeIndex = GrDrawState::kColorOverrideAttribIndexValue
; |
203 } | 195 } |
204 if (requiresAttributeCoverage) { | 196 if (requiresAttributeCoverage) { |
205 desc->fCoverageAttributeIndex = drawState.getAttribIndex(GrDrawState::kC
overage_AttribIndex); | 197 desc->fCoverageAttributeIndex = drawState.getAttribIndex(GrDrawState::kC
overage_AttribIndex); |
206 } else { | 198 } else { |
207 desc->fCoverageAttributeIndex = GrDrawState::kCoverageOverrideAttribInde
xValue; | 199 desc->fCoverageAttributeIndex = GrDrawState::kCoverageOverrideAttribInde
xValue; |
208 } | 200 } |
209 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | 201 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { |
210 desc->fLocalCoordsAttributeIndex = drawState.getAttribIndex(GrDrawState:
:kLocalCoords_AttribIndex); | 202 desc->fLocalCoordsAttributeIndex = drawState.getAttribIndex(GrDrawState:
:kLocalCoords_AttribIndex); |
211 } | 203 } |
212 | 204 |
213 #if GR_DEBUG | 205 #if GR_DEBUG |
214 // verify valid vertex attribute state | 206 // Verify valid vertex attribute state. These assertions should probably be
done somewhere |
| 207 // higher up the callstack |
215 const GrVertexAttrib* vertexAttribs = drawState.getVertexAttribs(); | 208 const GrVertexAttrib* vertexAttribs = drawState.getVertexAttribs(); |
216 GrAssert(desc->fPositionAttributeIndex < GrDrawState::kVertexAttribCnt); | 209 GrAssert(desc->fPositionAttributeIndex < GrDrawState::kVertexAttribCnt); |
217 GrAssert(kAttribLayouts[vertexAttribs[desc->fPositionAttributeIndex].fType].
fCount == 2); | 210 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fPositionAttributeIndex]
.fType).fCount == 2); |
218 if (requiresAttributeColors) { | 211 if (requiresAttributeColors) { |
219 GrAssert(desc->fColorAttributeIndex < GrDrawState::kVertexAttribCnt); | 212 GrAssert(desc->fColorAttributeIndex < GrDrawState::kVertexAttribCnt); |
220 GrAssert(kAttribLayouts[vertexAttribs[desc->fColorAttributeIndex].fType]
.fCount == 4); | 213 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fColorAttributeIndex
].fType).fCount == 4); |
221 } | 214 } |
222 if (requiresAttributeCoverage) { | 215 if (requiresAttributeCoverage) { |
223 GrAssert(desc->fCoverageAttributeIndex < GrDrawState::kVertexAttribCnt); | 216 GrAssert(desc->fCoverageAttributeIndex < GrDrawState::kVertexAttribCnt); |
224 GrAssert(kAttribLayouts[vertexAttribs[desc->fCoverageAttributeIndex].fTy
pe].fCount == 4); | 217 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fCoverageAttributeIn
dex].fType).fCount == 4); |
225 } | 218 } |
226 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { | 219 if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) { |
227 GrAssert(desc->fLocalCoordsAttributeIndex < GrDrawState::kVertexAttribCn
t); | 220 GrAssert(desc->fLocalCoordsAttributeIndex < GrDrawState::kVertexAttribCn
t); |
228 GrAssert(kAttribLayouts[vertexAttribs[desc->fLocalCoordsAttributeIndex].
fType].fCount == 2); | 221 GrAssert(GrGLAttribTypeToLayout(vertexAttribs[desc->fLocalCoordsAttribut
eIndex].fType).fCount == 2); |
229 } | 222 } |
230 #endif | 223 #endif |
231 } | 224 } |
232 | 225 |
233 GrGLProgram* GrGLProgram::Create(const GrGLContext& gl, | 226 GrGLProgram* GrGLProgram::Create(const GrGLContext& gl, |
234 const Desc& desc, | 227 const GrGLProgramDesc& desc, |
235 const GrEffectStage* stages[]) { | 228 const GrEffectStage* stages[]) { |
236 GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, stages)); | 229 GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, stages)); |
237 if (!program->succeeded()) { | 230 if (!program->succeeded()) { |
238 delete program; | 231 delete program; |
239 program = NULL; | 232 program = NULL; |
240 } | 233 } |
241 return program; | 234 return program; |
242 } | 235 } |
243 | 236 |
244 GrGLProgram::GrGLProgram(const GrGLContext& gl, | 237 GrGLProgram::GrGLProgram(const GrGLContext& gl, |
245 const Desc& desc, | 238 const GrGLProgramDesc& desc, |
246 const GrEffectStage* stages[]) | 239 const GrEffectStage* stages[]) |
247 : fContext(gl) | 240 : fContext(gl) |
248 , fUniformManager(gl) { | 241 , fUniformManager(gl) { |
249 fDesc = desc; | 242 fDesc = desc; |
250 fVShaderID = 0; | 243 fVShaderID = 0; |
251 fGShaderID = 0; | 244 fGShaderID = 0; |
252 fFShaderID = 0; | 245 fFShaderID = 0; |
253 fProgramID = 0; | 246 fProgramID = 0; |
254 | 247 |
255 fColor = GrColor_ILLEGAL; | 248 fColor = GrColor_ILLEGAL; |
(...skipping 28 matching lines...) Expand all Loading... |
284 void GrGLProgram::abandon() { | 277 void GrGLProgram::abandon() { |
285 fVShaderID = 0; | 278 fVShaderID = 0; |
286 fGShaderID = 0; | 279 fGShaderID = 0; |
287 fFShaderID = 0; | 280 fFShaderID = 0; |
288 fProgramID = 0; | 281 fProgramID = 0; |
289 } | 282 } |
290 | 283 |
291 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, | 284 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
292 GrBlendCoeff* dstCoeff) const { | 285 GrBlendCoeff* dstCoeff) const { |
293 switch (fDesc.fDualSrcOutput) { | 286 switch (fDesc.fDualSrcOutput) { |
294 case Desc::kNone_DualSrcOutput: | 287 case GrGLProgramDesc::kNone_DualSrcOutput: |
295 break; | 288 break; |
296 // the prog will write a coverage value to the secondary | 289 // the prog will write a coverage value to the secondary |
297 // output and the dst is blended by one minus that value. | 290 // output and the dst is blended by one minus that value. |
298 case Desc::kCoverage_DualSrcOutput: | 291 case GrGLProgramDesc::kCoverage_DualSrcOutput: |
299 case Desc::kCoverageISA_DualSrcOutput: | 292 case GrGLProgramDesc::kCoverageISA_DualSrcOutput: |
300 case Desc::kCoverageISC_DualSrcOutput: | 293 case GrGLProgramDesc::kCoverageISC_DualSrcOutput: |
301 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 294 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
302 break; | 295 break; |
303 default: | 296 default: |
304 GrCrash("Unexpected dual source blend output"); | 297 GrCrash("Unexpected dual source blend output"); |
305 break; | 298 break; |
306 } | 299 } |
307 } | 300 } |
308 | 301 |
309 namespace { | 302 namespace { |
310 | 303 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 blend_term_string(&constStr, uniformCoeff, filterColor, inColor, filterColor
); | 399 blend_term_string(&constStr, uniformCoeff, filterColor, inColor, filterColor
); |
407 | 400 |
408 SkString sum; | 401 SkString sum; |
409 GrGLSLAdd4f(&sum, colorStr.c_str(), constStr.c_str()); | 402 GrGLSLAdd4f(&sum, colorStr.c_str(), constStr.c_str()); |
410 builder->fsCodeAppendf("\t%s = %s;\n", outputVar, sum.c_str()); | 403 builder->fsCodeAppendf("\t%s = %s;\n", outputVar, sum.c_str()); |
411 } | 404 } |
412 } | 405 } |
413 | 406 |
414 void GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString* inColor) { | 407 void GrGLProgram::genInputColor(GrGLShaderBuilder* builder, SkString* inColor) { |
415 switch (fDesc.fColorInput) { | 408 switch (fDesc.fColorInput) { |
416 case GrGLProgram::Desc::kAttribute_ColorInput: { | 409 case GrGLProgramDesc::kAttribute_ColorInput: { |
417 builder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); | 410 builder->addAttribute(kVec4f_GrSLType, COL_ATTR_NAME); |
418 const char *vsName, *fsName; | 411 const char *vsName, *fsName; |
419 builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); | 412 builder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsName); |
420 builder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); | 413 builder->vsCodeAppendf("\t%s = " COL_ATTR_NAME ";\n", vsName); |
421 *inColor = fsName; | 414 *inColor = fsName; |
422 } break; | 415 } break; |
423 case GrGLProgram::Desc::kUniform_ColorInput: { | 416 case GrGLProgramDesc::kUniform_ColorInput: { |
424 const char* name; | 417 const char* name; |
425 fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::k
Fragment_ShaderType, | 418 fUniformHandles.fColorUni = builder->addUniform(GrGLShaderBuilder::k
Fragment_ShaderType, |
426 kVec4f_GrSLType, "Co
lor", &name); | 419 kVec4f_GrSLType, "Co
lor", &name); |
427 *inColor = name; | 420 *inColor = name; |
428 break; | 421 break; |
429 } | 422 } |
430 case GrGLProgram::Desc::kTransBlack_ColorInput: | 423 case GrGLProgramDesc::kTransBlack_ColorInput: |
431 GrAssert(!"needComputedColor should be false."); | 424 GrAssert(!"needComputedColor should be false."); |
432 break; | 425 break; |
433 case GrGLProgram::Desc::kSolidWhite_ColorInput: | 426 case GrGLProgramDesc::kSolidWhite_ColorInput: |
434 break; | 427 break; |
435 default: | 428 default: |
436 GrCrash("Unknown color type."); | 429 GrCrash("Unknown color type."); |
437 break; | 430 break; |
438 } | 431 } |
439 } | 432 } |
440 | 433 |
441 void GrGLProgram::genUniformCoverage(GrGLShaderBuilder* builder, SkString* inOut
Coverage) { | 434 void GrGLProgram::genUniformCoverage(GrGLShaderBuilder* builder, SkString* inOut
Coverage) { |
442 const char* covUniName; | 435 const char* covUniName; |
443 fUniformHandles.fCoverageUni = builder->addUniform(GrGLShaderBuilder::kFragm
ent_ShaderType, | 436 fUniformHandles.fCoverageUni = builder->addUniform(GrGLShaderBuilder::kFragm
ent_ShaderType, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 "\t}\n" | 483 "\t}\n" |
491 "\tEndPrimitive();\n"); | 484 "\tEndPrimitive();\n"); |
492 } | 485 } |
493 #endif | 486 #endif |
494 } | 487 } |
495 | 488 |
496 const char* GrGLProgram::adjustInColor(const SkString& inColor) const { | 489 const char* GrGLProgram::adjustInColor(const SkString& inColor) const { |
497 if (inColor.size()) { | 490 if (inColor.size()) { |
498 return inColor.c_str(); | 491 return inColor.c_str(); |
499 } else { | 492 } else { |
500 if (Desc::kSolidWhite_ColorInput == fDesc.fColorInput) { | 493 if (GrGLProgramDesc::kSolidWhite_ColorInput == fDesc.fColorInput) { |
501 return GrGLSLOnesVecf(4); | 494 return GrGLSLOnesVecf(4); |
502 } else { | 495 } else { |
503 return GrGLSLZerosVecf(4); | 496 return GrGLSLZerosVecf(4); |
504 } | 497 } |
505 } | 498 } |
506 } | 499 } |
507 | 500 |
508 namespace { | 501 namespace { |
509 // prints a shader using params similar to glShaderSource | 502 // prints a shader using params similar to glShaderSource |
510 void print_shader(GrGLint stringCnt, | 503 void print_shader(GrGLint stringCnt, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 (fDesc.fColorFilterXfermode), | 622 (fDesc.fColorFilterXfermode), |
630 &uniformCoeff, &colorCoeff); | 623 &uniformCoeff, &colorCoeff); |
631 GR_DEBUGASSERT(success); | 624 GR_DEBUGASSERT(success); |
632 } else { | 625 } else { |
633 colorCoeff = SkXfermode::kOne_Coeff; | 626 colorCoeff = SkXfermode::kOne_Coeff; |
634 uniformCoeff = SkXfermode::kZero_Coeff; | 627 uniformCoeff = SkXfermode::kZero_Coeff; |
635 } | 628 } |
636 | 629 |
637 // no need to do the color filter if coverage is 0. The output color is scal
ed by the coverage. | 630 // no need to do the color filter if coverage is 0. The output color is scal
ed by the coverage. |
638 // All the dual source outputs are scaled by the coverage as well. | 631 // All the dual source outputs are scaled by the coverage as well. |
639 if (Desc::kTransBlack_ColorInput == fDesc.fCoverageInput) { | 632 if (GrGLProgramDesc::kTransBlack_ColorInput == fDesc.fCoverageInput) { |
640 colorCoeff = SkXfermode::kZero_Coeff; | 633 colorCoeff = SkXfermode::kZero_Coeff; |
641 uniformCoeff = SkXfermode::kZero_Coeff; | 634 uniformCoeff = SkXfermode::kZero_Coeff; |
642 } | 635 } |
643 | 636 |
644 // If we know the final color is going to be all zeros then we can | 637 // If we know the final color is going to be all zeros then we can |
645 // simplify the color filter coefficients. needComputedColor will then | 638 // simplify the color filter coefficients. needComputedColor will then |
646 // come out false below. | 639 // come out false below. |
647 if (Desc::kTransBlack_ColorInput == fDesc.fColorInput) { | 640 if (GrGLProgramDesc::kTransBlack_ColorInput == fDesc.fColorInput) { |
648 colorCoeff = SkXfermode::kZero_Coeff; | 641 colorCoeff = SkXfermode::kZero_Coeff; |
649 if (SkXfermode::kDC_Coeff == uniformCoeff || | 642 if (SkXfermode::kDC_Coeff == uniformCoeff || |
650 SkXfermode::kDA_Coeff == uniformCoeff) { | 643 SkXfermode::kDA_Coeff == uniformCoeff) { |
651 uniformCoeff = SkXfermode::kZero_Coeff; | 644 uniformCoeff = SkXfermode::kZero_Coeff; |
652 } else if (SkXfermode::kIDC_Coeff == uniformCoeff || | 645 } else if (SkXfermode::kIDC_Coeff == uniformCoeff || |
653 SkXfermode::kIDA_Coeff == uniformCoeff) { | 646 SkXfermode::kIDA_Coeff == uniformCoeff) { |
654 uniformCoeff = SkXfermode::kOne_Coeff; | 647 uniformCoeff = SkXfermode::kOne_Coeff; |
655 } | 648 } |
656 } | 649 } |
657 | 650 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 &fUniformHandles.fSa
mplerUnis[s]); | 710 &fUniformHandles.fSa
mplerUnis[s]); |
718 builder.setNonStage(); | 711 builder.setNonStage(); |
719 inColor = outColor; | 712 inColor = outColor; |
720 } | 713 } |
721 } | 714 } |
722 } | 715 } |
723 | 716 |
724 // if have all ones or zeros for the "dst" input to the color filter then we | 717 // if have all ones or zeros for the "dst" input to the color filter then we |
725 // may be able to make additional optimizations. | 718 // may be able to make additional optimizations. |
726 if (needColorFilterUniform && needComputedColor && !inColor.size()) { | 719 if (needColorFilterUniform && needComputedColor && !inColor.size()) { |
727 GrAssert(Desc::kSolidWhite_ColorInput == fDesc.fColorInput); | 720 GrAssert(GrGLProgramDesc::kSolidWhite_ColorInput == fDesc.fColorInput); |
728 bool uniformCoeffIsZero = SkXfermode::kIDC_Coeff == uniformCoeff || | 721 bool uniformCoeffIsZero = SkXfermode::kIDC_Coeff == uniformCoeff || |
729 SkXfermode::kIDA_Coeff == uniformCoeff; | 722 SkXfermode::kIDA_Coeff == uniformCoeff; |
730 if (uniformCoeffIsZero) { | 723 if (uniformCoeffIsZero) { |
731 uniformCoeff = SkXfermode::kZero_Coeff; | 724 uniformCoeff = SkXfermode::kZero_Coeff; |
732 bool bogus; | 725 bool bogus; |
733 need_blend_inputs(SkXfermode::kZero_Coeff, colorCoeff, | 726 need_blend_inputs(SkXfermode::kZero_Coeff, colorCoeff, |
734 &needColorFilterUniform, &bogus); | 727 &needColorFilterUniform, &bogus); |
735 } | 728 } |
736 } | 729 } |
737 const char* colorFilterColorUniName = NULL; | 730 const char* colorFilterColorUniName = NULL; |
(...skipping 13 matching lines...) Expand all Loading... |
751 const char* color = adjustInColor(inColor); | 744 const char* color = adjustInColor(inColor); |
752 add_color_filter(&builder, "filteredColor", uniformCoeff, | 745 add_color_filter(&builder, "filteredColor", uniformCoeff, |
753 colorCoeff, colorFilterColorUniName, color); | 746 colorCoeff, colorFilterColorUniName, color); |
754 inColor = "filteredColor"; | 747 inColor = "filteredColor"; |
755 } | 748 } |
756 | 749 |
757 /////////////////////////////////////////////////////////////////////////// | 750 /////////////////////////////////////////////////////////////////////////// |
758 // compute the partial coverage (coverage stages and edge aa) | 751 // compute the partial coverage (coverage stages and edge aa) |
759 | 752 |
760 SkString inCoverage; | 753 SkString inCoverage; |
761 bool coverageIsZero = Desc::kTransBlack_ColorInput == fDesc.fCoverageInput; | 754 bool coverageIsZero = GrGLProgramDesc::kTransBlack_ColorInput == fDesc.fCove
rageInput; |
762 // we don't need to compute coverage at all if we know the final shader | 755 // we don't need to compute coverage at all if we know the final shader |
763 // output will be zero and we don't have a dual src blend output. | 756 // output will be zero and we don't have a dual src blend output. |
764 if (!wroteFragColorZero || Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput
) { | 757 if (!wroteFragColorZero || GrGLProgramDesc::kNone_DualSrcOutput != fDesc.fDu
alSrcOutput) { |
765 | 758 |
766 if (!coverageIsZero) { | 759 if (!coverageIsZero) { |
767 switch (fDesc.fCoverageInput) { | 760 switch (fDesc.fCoverageInput) { |
768 case Desc::kSolidWhite_ColorInput: | 761 case GrGLProgramDesc::kSolidWhite_ColorInput: |
769 // empty string implies solid white | 762 // empty string implies solid white |
770 break; | 763 break; |
771 case Desc::kAttribute_ColorInput: | 764 case GrGLProgramDesc::kAttribute_ColorInput: |
772 gen_attribute_coverage(&builder, &inCoverage); | 765 gen_attribute_coverage(&builder, &inCoverage); |
773 break; | 766 break; |
774 case Desc::kUniform_ColorInput: | 767 case GrGLProgramDesc::kUniform_ColorInput: |
775 this->genUniformCoverage(&builder, &inCoverage); | 768 this->genUniformCoverage(&builder, &inCoverage); |
776 break; | 769 break; |
777 default: | 770 default: |
778 GrCrash("Unexpected input coverage."); | 771 GrCrash("Unexpected input coverage."); |
779 } | 772 } |
780 | 773 |
781 SkString outCoverage; | 774 SkString outCoverage; |
782 const int& startStage = fDesc.fFirstCoverageStage; | 775 const int& startStage = fDesc.fFirstCoverageStage; |
783 for (int s = startStage; s < GrDrawState::kNumStages; ++s) { | 776 for (int s = startStage; s < GrDrawState::kNumStages; ++s) { |
784 if (fDesc.fEffectKeys[s]) { | 777 if (fDesc.fEffectKeys[s]) { |
(...skipping 15 matching lines...) Expand all Loading... |
800 } | 793 } |
801 | 794 |
802 // discard if coverage is zero | 795 // discard if coverage is zero |
803 if (fDesc.fDiscardIfZeroCoverage && !outCoverage.isEmpty()) { | 796 if (fDesc.fDiscardIfZeroCoverage && !outCoverage.isEmpty()) { |
804 builder.fsCodeAppendf( | 797 builder.fsCodeAppendf( |
805 "\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\t\tdiscard;\n\
t}\n", | 798 "\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\t\tdiscard;\n\
t}\n", |
806 outCoverage.c_str()); | 799 outCoverage.c_str()); |
807 } | 800 } |
808 } | 801 } |
809 | 802 |
810 if (Desc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { | 803 if (GrGLProgramDesc::kNone_DualSrcOutput != fDesc.fDualSrcOutput) { |
811 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, | 804 builder.fFSOutputs.push_back().set(kVec4f_GrSLType, |
812 GrGLShaderVar::kOut_TypeModifier, | 805 GrGLShaderVar::kOut_TypeModifier, |
813 dual_source_output_name()); | 806 dual_source_output_name()); |
814 bool outputIsZero = coverageIsZero; | 807 bool outputIsZero = coverageIsZero; |
815 SkString coeff; | 808 SkString coeff; |
816 if (!outputIsZero && | 809 if (!outputIsZero && |
817 Desc::kCoverage_DualSrcOutput != fDesc.fDualSrcOutput && !wroteF
ragColorZero) { | 810 GrGLProgramDesc::kCoverage_DualSrcOutput != fDesc.fDualSrcOutput
&& !wroteFragColorZero) { |
818 if (!inColor.size()) { | 811 if (!inColor.size()) { |
819 outputIsZero = true; | 812 outputIsZero = true; |
820 } else { | 813 } else { |
821 if (Desc::kCoverageISA_DualSrcOutput == fDesc.fDualSrcOutput
) { | 814 if (GrGLProgramDesc::kCoverageISA_DualSrcOutput == fDesc.fDu
alSrcOutput) { |
822 coeff.printf("(1 - %s.a)", inColor.c_str()); | 815 coeff.printf("(1 - %s.a)", inColor.c_str()); |
823 } else { | 816 } else { |
824 coeff.printf("(vec4(1,1,1,1) - %s)", inColor.c_str()); | 817 coeff.printf("(vec4(1,1,1,1) - %s)", inColor.c_str()); |
825 } | 818 } |
826 } | 819 } |
827 } | 820 } |
828 if (outputIsZero) { | 821 if (outputIsZero) { |
829 builder.fsCodeAppendf("\t%s = %s;\n", dual_source_output_name(),
GrGLSLZerosVecf(4)); | 822 builder.fsCodeAppendf("\t%s = %s;\n", dual_source_output_name(),
GrGLSLZerosVecf(4)); |
830 } else { | 823 } else { |
831 SkString modulate; | 824 SkString modulate; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 995 } |
1003 } | 996 } |
1004 } | 997 } |
1005 } | 998 } |
1006 | 999 |
1007 void GrGLProgram::setColor(const GrDrawState& drawState, | 1000 void GrGLProgram::setColor(const GrDrawState& drawState, |
1008 GrColor color, | 1001 GrColor color, |
1009 SharedGLState* sharedState) { | 1002 SharedGLState* sharedState) { |
1010 if (!(drawState.getAttribBindings() & GrDrawState::kColor_AttribBindingsBit)
) { | 1003 if (!(drawState.getAttribBindings() & GrDrawState::kColor_AttribBindingsBit)
) { |
1011 switch (fDesc.fColorInput) { | 1004 switch (fDesc.fColorInput) { |
1012 case GrGLProgram::Desc::kAttribute_ColorInput: | 1005 case GrGLProgramDesc::kAttribute_ColorInput: |
1013 if (sharedState->fConstAttribColor != color) { | 1006 if (sharedState->fConstAttribColor != color) { |
1014 // OpenGL ES only supports the float varieties of glVertexAt
trib | 1007 // OpenGL ES only supports the float varieties of glVertexAt
trib |
1015 GrGLfloat c[4]; | 1008 GrGLfloat c[4]; |
1016 GrColorToRGBAFloat(color, c); | 1009 GrColorToRGBAFloat(color, c); |
1017 GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); | 1010 GL_CALL(VertexAttrib4fv(fDesc.fColorAttributeIndex, c)); |
1018 sharedState->fConstAttribColor = color; | 1011 sharedState->fConstAttribColor = color; |
1019 } | 1012 } |
1020 break; | 1013 break; |
1021 case GrGLProgram::Desc::kUniform_ColorInput: | 1014 case GrGLProgramDesc::kUniform_ColorInput: |
1022 if (fColor != color) { | 1015 if (fColor != color) { |
1023 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 1016 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
1024 GrGLfloat c[4]; | 1017 GrGLfloat c[4]; |
1025 GrColorToRGBAFloat(color, c); | 1018 GrColorToRGBAFloat(color, c); |
1026 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 1019 GrAssert(GrGLUniformManager::kInvalidUniformHandle != |
1027 fUniformHandles.fColorUni); | 1020 fUniformHandles.fColorUni); |
1028 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); | 1021 fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |
1029 fColor = color; | 1022 fColor = color; |
1030 } | 1023 } |
1031 break; | 1024 break; |
1032 case GrGLProgram::Desc::kSolidWhite_ColorInput: | 1025 case GrGLProgramDesc::kSolidWhite_ColorInput: |
1033 case GrGLProgram::Desc::kTransBlack_ColorInput: | 1026 case GrGLProgramDesc::kTransBlack_ColorInput: |
1034 break; | 1027 break; |
1035 default: | 1028 default: |
1036 GrCrash("Unknown color type."); | 1029 GrCrash("Unknown color type."); |
1037 } | 1030 } |
1038 } | 1031 } |
1039 } | 1032 } |
1040 | 1033 |
1041 void GrGLProgram::setCoverage(const GrDrawState& drawState, | 1034 void GrGLProgram::setCoverage(const GrDrawState& drawState, |
1042 GrColor coverage, | 1035 GrColor coverage, |
1043 SharedGLState* sharedState) { | 1036 SharedGLState* sharedState) { |
1044 if (!(drawState.getAttribBindings() & GrDrawState::kCoverage_AttribBindingsB
it)) { | 1037 if (!(drawState.getAttribBindings() & GrDrawState::kCoverage_AttribBindingsB
it)) { |
1045 switch (fDesc.fCoverageInput) { | 1038 switch (fDesc.fCoverageInput) { |
1046 case Desc::kAttribute_ColorInput: | 1039 case GrGLProgramDesc::kAttribute_ColorInput: |
1047 if (sharedState->fConstAttribCoverage != coverage) { | 1040 if (sharedState->fConstAttribCoverage != coverage) { |
1048 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 1041 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
1049 GrGLfloat c[4]; | 1042 GrGLfloat c[4]; |
1050 GrColorToRGBAFloat(coverage, c); | 1043 GrColorToRGBAFloat(coverage, c); |
1051 GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); | 1044 GL_CALL(VertexAttrib4fv(fDesc.fCoverageAttributeIndex, c)); |
1052 sharedState->fConstAttribCoverage = coverage; | 1045 sharedState->fConstAttribCoverage = coverage; |
1053 } | 1046 } |
1054 break; | 1047 break; |
1055 case Desc::kUniform_ColorInput: | 1048 case GrGLProgramDesc::kUniform_ColorInput: |
1056 if (fCoverage != coverage) { | 1049 if (fCoverage != coverage) { |
1057 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform | 1050 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
1058 GrGLfloat c[4]; | 1051 GrGLfloat c[4]; |
1059 GrColorToRGBAFloat(coverage, c); | 1052 GrColorToRGBAFloat(coverage, c); |
1060 GrAssert(GrGLUniformManager::kInvalidUniformHandle != | 1053 GrAssert(GrGLUniformManager::kInvalidUniformHandle != |
1061 fUniformHandles.fCoverageUni); | 1054 fUniformHandles.fCoverageUni); |
1062 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); | 1055 fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c
); |
1063 fCoverage = coverage; | 1056 fCoverage = coverage; |
1064 } | 1057 } |
1065 break; | 1058 break; |
1066 case Desc::kSolidWhite_ColorInput: | 1059 case GrGLProgramDesc::kSolidWhite_ColorInput: |
1067 case Desc::kTransBlack_ColorInput: | 1060 case GrGLProgramDesc::kTransBlack_ColorInput: |
1068 break; | 1061 break; |
1069 default: | 1062 default: |
1070 GrCrash("Unknown coverage type."); | 1063 GrCrash("Unknown coverage type."); |
1071 } | 1064 } |
1072 } | 1065 } |
1073 } | 1066 } |
1074 | 1067 |
1075 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { | 1068 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |
1076 const GrRenderTarget* rt = drawState.getRenderTarget(); | 1069 const GrRenderTarget* rt = drawState.getRenderTarget(); |
1077 SkISize size; | 1070 SkISize size; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 SkScalarToFloat(m[SkMatrix::kMTransX]), | 1104 SkScalarToFloat(m[SkMatrix::kMTransX]), |
1112 SkScalarToFloat(m[SkMatrix::kMTransY]), | 1105 SkScalarToFloat(m[SkMatrix::kMTransY]), |
1113 SkScalarToFloat(m[SkMatrix::kMPersp2]) | 1106 SkScalarToFloat(m[SkMatrix::kMPersp2]) |
1114 }; | 1107 }; |
1115 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); | 1108 fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, mt); |
1116 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 1109 fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
1117 fMatrixState.fRenderTargetSize = size; | 1110 fMatrixState.fRenderTargetSize = size; |
1118 fMatrixState.fRenderTargetOrigin = rt->origin(); | 1111 fMatrixState.fRenderTargetOrigin = rt->origin(); |
1119 } | 1112 } |
1120 } | 1113 } |
OLD | NEW |