OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLSLPrettyPrint.h" | 10 #include "gl/GrGLSLPrettyPrint.h" |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 259 } |
260 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo
verage); | 260 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo
verage); |
261 } | 261 } |
262 | 262 |
263 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G
rGLSLExpr4* inOut) { | 263 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G
rGLSLExpr4* inOut) { |
264 ProcKeyProvider keyProvider(&fDesc, | 264 ProcKeyProvider keyProvider(&fDesc, |
265 ProcKeyProvider::kFragment_ProcessorType, | 265 ProcKeyProvider::kFragment_ProcessorType, |
266 GrGLProgramDescBuilder::kProcessorKeyOffsetsAndL
engthOffset); | 266 GrGLProgramDescBuilder::kProcessorKeyOffsetsAndL
engthOffset); |
267 for (int e = procOffset; e < numProcs; ++e) { | 267 for (int e = procOffset; e < numProcs; ++e) { |
268 GrGLSLExpr4 output; | 268 GrGLSLExpr4 output; |
269 const GrFragmentStage& stage = fOptState.getFragmentStage(e); | 269 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); |
270 this->emitAndInstallProc<GrFragmentStage>(stage, e, keyProvider, *inOut,
&output); | 270 this->emitAndInstallProc<GrPendingFragmentStage>(stage, e, keyProvider,
*inOut, &output); |
271 *inOut = output; | 271 *inOut = output; |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 // TODO Processors cannot output zeros because an empty string is all 1s | 275 // TODO Processors cannot output zeros because an empty string is all 1s |
276 // the fix is to allow effects to take the GrGLSLExpr4 directly | 276 // the fix is to allow effects to take the GrGLSLExpr4 directly |
277 template <class Proc> | 277 template <class Proc> |
278 void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc, | 278 void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc, |
279 int index, | 279 int index, |
280 const ProcKeyProvider& keyProvider, | 280 const ProcKeyProvider& keyProvider, |
(...skipping 17 matching lines...) Expand all Loading... |
298 SkString openBrace; | 298 SkString openBrace; |
299 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); | 299 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); |
300 fFS.codeAppend(openBrace.c_str()); | 300 fFS.codeAppend(openBrace.c_str()); |
301 | 301 |
302 this->emitAndInstallProc(proc, keyProvider.get(index), output->c_str(), | 302 this->emitAndInstallProc(proc, keyProvider.get(index), output->c_str(), |
303 input.isOnes() ? NULL : input.c_str()); | 303 input.isOnes() ? NULL : input.c_str()); |
304 | 304 |
305 fFS.codeAppend("}"); | 305 fFS.codeAppend("}"); |
306 } | 306 } |
307 | 307 |
308 void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentStage& fs, | 308 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, |
309 const GrProcessorKey& key, | 309 const GrProcessorKey& key, |
310 const char* outColor, | 310 const char* outColor, |
311 const char* inColor) { | 311 const char* inColor) { |
312 GrGLInstalledFragProc* ifp = SkNEW_ARGS(GrGLInstalledFragProc, (fVS.hasLocal
Coords())); | 312 GrGLInstalledFragProc* ifp = SkNEW_ARGS(GrGLInstalledFragProc, (fVS.hasLocal
Coords())); |
313 | 313 |
314 const GrFragmentProcessor& fp = *fs.getProcessor(); | 314 const GrFragmentProcessor& fp = *fs.getProcessor(); |
315 ifp->fGLProc.reset(fp.getFactory().createGLInstance(fp)); | 315 ifp->fGLProc.reset(fp.getFactory().createGLInstance(fp)); |
316 | 316 |
317 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); | 317 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); |
318 this->emitSamplers(fp, &samplers, ifp); | 318 this->emitSamplers(fp, &samplers, ifp); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 351 |
352 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { | 352 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { |
353 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); | 353 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); |
354 } | 354 } |
355 | 355 |
356 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 356 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
357 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 357 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
358 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); | 358 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); |
359 } | 359 } |
360 | 360 |
361 void GrGLProgramBuilder::emitTransforms(const GrFragmentStage& effectStage, | 361 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, |
362 GrGLProcessor::TransformedCoordsArray* o
utCoords, | 362 GrGLProcessor::TransformedCoordsArray* o
utCoords, |
363 GrGLInstalledFragProc* ifp) { | 363 GrGLInstalledFragProc* ifp) { |
364 const GrFragmentProcessor* effect = effectStage.getProcessor(); | 364 const GrFragmentProcessor* processor = stage.getProcessor(); |
365 int numTransforms = effect->numTransforms(); | 365 int numTransforms = processor->numTransforms(); |
366 ifp->fTransforms.push_back_n(numTransforms); | 366 ifp->fTransforms.push_back_n(numTransforms); |
367 | 367 |
368 for (int t = 0; t < numTransforms; t++) { | 368 for (int t = 0; t < numTransforms; t++) { |
369 const char* uniName = "StageMatrix"; | 369 const char* uniName = "StageMatrix"; |
370 GrSLType varyingType = | 370 GrSLType varyingType = stage.isPerspectiveCoordTransform(t) ? kVec3f_GrS
LType : |
371 effectStage.isPerspectiveCoordTransform(t, fVS.hasLocalCoords())
? | 371 kVec2f_GrS
LType; |
372 kVec3f_GrSLType : | |
373 kVec2f_GrSLType; | |
374 | |
375 SkString suffixedUniName; | 372 SkString suffixedUniName; |
376 if (0 != t) { | 373 if (0 != t) { |
377 suffixedUniName.append(uniName); | 374 suffixedUniName.append(uniName); |
378 suffixedUniName.appendf("_%i", t); | 375 suffixedUniName.appendf("_%i", t); |
379 uniName = suffixedUniName.c_str(); | 376 uniName = suffixedUniName.c_str(); |
380 } | 377 } |
381 ifp->fTransforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVert
ex_Visibility, | 378 ifp->fTransforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVert
ex_Visibility, |
382 kMat33f_GrSLType, | 379 kMat33f_GrSLType, |
383 uniName, | 380 uniName, |
384 &uniName).toShaderBuilder
Index(); | 381 &uniName).toShaderBuilder
Index(); |
385 | 382 |
386 const char* varyingName = "MatrixCoord"; | 383 const char* varyingName = "MatrixCoord"; |
387 SkString suffixedVaryingName; | 384 SkString suffixedVaryingName; |
388 if (0 != t) { | 385 if (0 != t) { |
389 suffixedVaryingName.append(varyingName); | 386 suffixedVaryingName.append(varyingName); |
390 suffixedVaryingName.appendf("_%i", t); | 387 suffixedVaryingName.appendf("_%i", t); |
391 varyingName = suffixedVaryingName.c_str(); | 388 varyingName = suffixedVaryingName.c_str(); |
392 } | 389 } |
393 const char* coords = kPosition_GrCoordSet == effect->coordTransform(t).s
ourceCoords() ? | 390 const char* coords = kPosition_GrCoordSet == processor->coordTransform(t
).sourceCoords() ? |
394 fVS.positionAttribute().c_s
tr() : | 391 fVS.positionAttribute().c_s
tr() : |
395 fVS.localCoordsAttribute().
c_str(); | 392 fVS.localCoordsAttribute().
c_str(); |
396 GrGLVertToFrag v(varyingType); | 393 GrGLVertToFrag v(varyingType); |
397 this->addCoordVarying(varyingName, &v, uniName, coords); | 394 this->addCoordVarying(varyingName, &v, uniName, coords); |
398 | 395 |
399 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); | 396 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp
e); |
400 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, | 397 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, |
401 (SkString(v.fsIn()), varyingType)); | 398 (SkString(v.fsIn()), varyingType)); |
402 } | 399 } |
403 } | 400 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 519 } |
523 | 520 |
524 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 521 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
525 | 522 |
526 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 523 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
527 int numProcs = fProcs.count(); | 524 int numProcs = fProcs.count(); |
528 for (int e = 0; e < numProcs; ++e) { | 525 for (int e = 0; e < numProcs; ++e) { |
529 SkDELETE(fProcs[e]); | 526 SkDELETE(fProcs[e]); |
530 } | 527 } |
531 } | 528 } |
OLD | NEW |