Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: src/gpu/gl/builders/GrGLProgramBuilder.cpp

Issue 576543005: Breaking out full program and frag only (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gl/GrGLProgram.h" 8 #include "gl/GrGLProgram.h"
9 #include "gl/GrGLSLPrettyPrint.h" 9 #include "gl/GrGLSLPrettyPrint.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 GetProgramResourceLocation(programId, 319 GetProgramResourceLocation(programId,
320 GR_GL_FRAGMENT_INPUT, 320 GR_GL_FRAGMENT_INPUT,
321 fSeparableVaryingInfos[i].fVariab le.c_str())); 321 fSeparableVaryingInfos[i].fVariab le.c_str()));
322 fSeparableVaryingInfos[i].fLocation = location; 322 fSeparableVaryingInfos[i].fLocation = location;
323 } 323 }
324 } 324 }
325 325
326 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { 326 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
327 return fGpu->ctxInfo(); 327 return fGpu->ctxInfo();
328 } 328 }
329
330 ////////////////////////////////////////////////////////////////////////////////
331
332 GrGLFullProgramBuilder::GrGLFullProgramBuilder(GrGpuGL* gpu,
333 const GrGLProgramDesc& desc)
334 : INHERITED(gpu, desc)
335 , fGS(this)
336 , fVS(this) {
337 }
338
339 void GrGLFullProgramBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color,
340 GrGLSLExpr4* coverage) {
341 fVS.emitCodeBeforeEffects(color, coverage);
342 }
343
344 void GrGLFullProgramBuilder::emitGeometryProcessor(const GrEffectStage* geometry Processor,
345 GrGLSLExpr4* coverage) {
346 if (geometryProcessor) {
347 GrGLProgramDesc::EffectKeyProvider geometryProcessorKeyProvider(
348 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kGeometryProc essor_EffectType);
349 fGeometryProcessor.reset(this->createAndEmitEffect(
350 geometryProcessor,
351 geometryProcessorKeyProvider,
352 coverage));
353 }
354 }
355
356 void GrGLFullProgramBuilder::emitCodeAfterEffects() {
357 fVS.emitCodeAfterEffects();
358 }
359
360 void GrGLFullProgramBuilder::addVarying(GrSLType type,
361 const char* name,
362 const char** vsOutName,
363 const char** fsInName,
364 GrGLShaderVar::Precision fsPrecision) {
365 fVS.addVarying(type, name, vsOutName);
366
367 SkString* fsInputName = fVS.fOutputs.back().accessName();
368
369 #if GR_GL_EXPERIMENTAL_GS
370 if (desc().getHeader().fExperimentalGS) {
371 // TODO let the caller use these names
372 fGS.addVarying(type, fsInputName->c_str(), NULL);
373 fsInputName = fGS.fOutputs.back().accessName();
374 }
375 #endif
376 fFS.addVarying(type, fsInputName->c_str(), fsInName, fsPrecision);
377 }
378
379 GrGLFullProgramBuilder::VaryingHandle
380 GrGLFullProgramBuilder::addSeparableVarying(GrSLType type,
381 const char* name,
382 const char** vsOutName,
383 const char** fsInName) {
384 addVarying(type, name, vsOutName, fsInName);
385 SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back();
386 varying.fVariable = fFS.fInputs.back();
387 return VaryingHandle::CreateFromSeparableVaryingIndex(fSeparableVaryingInfos .count() - 1);
388 }
389
390
391 GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffects(
392 const GrEffectStage* effectStages[],
393 int effectCnt,
394 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
395 GrGLSLExpr4* inOutFSColor) {
396
397 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt);
398 this->INHERITED::createAndEmitEffects(&programEffectsBuilder,
399 effectStages,
400 effectCnt,
401 keyProvider,
402 inOutFSColor);
403 return programEffectsBuilder.finish();
404 }
405
406 void GrGLFullProgramBuilder::createAndEmitEffect(GrGLProgramEffectsBuilder* prog ramEffectsBuilder,
407 const GrEffectStage* effectStages,
408 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider,
409 GrGLSLExpr4* fsInOutColor) {
410 GrGLSLExpr4 inColor = *fsInOutColor;
411 GrGLSLExpr4 outColor;
412
413 SkASSERT(effectStages && effectStages->getEffect());
414 const GrEffectStage& stage = *effectStages;
415
416 // Using scope to force ASR destructor to be triggered
417 {
418 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
419
420 if (inColor.isZeros()) {
421 SkString inColorName;
422
423 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
424 this->nameVariable(&inColorName, '\0', "input");
425 fFS.codeAppendf("vec4 %s = %s;", inColorName.c_str(), inColor.c_str( ));
426 inColor = inColorName;
427 }
428
429 // create var to hold stage result
430 SkString outColorName;
431 this->nameVariable(&outColorName, '\0', "output");
432 fFS.codeAppendf("vec4 %s;", outColorName.c_str());
433 outColor = outColorName;
434
435
436 programEffectsBuilder->emitEffect(stage,
437 keyProvider.get(0),
438 outColor.c_str(),
439 inColor.isOnes() ? NULL : inColor.c_st r(),
440 fCodeStage.stageIndex());
441 }
442
443 *fsInOutColor = outColor;
444 }
445
446 GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffect(
447 const GrEffectStage* geometryProcessor,
448 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
449 GrGLSLExpr4* inOutFSColor) {
450
451 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, 1);
452 this->createAndEmitEffect(&programEffectsBuilder, geometryProcessor, keyProv ider, inOutFSColor);
453 return programEffectsBuilder.finish();
454 }
455
456 bool GrGLFullProgramBuilder::compileAndAttachShaders(GrGLuint programId,
457 SkTDArray<GrGLuint>* shader Ids) const {
458 return INHERITED::compileAndAttachShaders(programId, shaderIds)
459 && fVS.compileAndAttachShaders(programId, shaderIds)
460 #if GR_GL_EXPERIMENTAL_GS
461 && (!desc().getHeader().fExperimentalGS
462 || fGS.compileAndAttachShaders(programId, shaderIds))
463 #endif
464 ;
465 }
466
467 void GrGLFullProgramBuilder::bindProgramLocations(GrGLuint programId) {
468 fVS.bindProgramLocations(programId);
469 INHERITED::bindProgramLocations(programId);
470 }
471
472 ////////////////////////////////////////////////////////////////////////////////
473
474 GrGLFragmentOnlyProgramBuilder::GrGLFragmentOnlyProgramBuilder(GrGpuGL* gpu,
475 const GrGLProgram Desc& desc)
476 : INHERITED(gpu, desc) {
477 SkASSERT(!desc.getHeader().fRequiresVertexShader);
478 SkASSERT(gpu->glCaps().pathRenderingSupport());
479 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorIn put);
480 SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverag eInput);
481 }
482
483 int GrGLFragmentOnlyProgramBuilder::addTexCoordSets(int count) {
484 int firstFreeCoordSet = fTexCoordSetCnt;
485 fTexCoordSetCnt += count;
486 SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt) ;
487 return firstFreeCoordSet;
488 }
489
490 GrGLProgramEffects* GrGLFragmentOnlyProgramBuilder::createAndEmitEffects(
491 const GrEffectStage* effectStages[], int effectCnt,
492 const GrGLProgramDesc::EffectKeyProvider& keyProvider, GrGLSLExpr4* inOu tFSColor) {
493
494 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this,
495 effectCnt);
496 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder,
497 effectStages,
498 effectCnt,
499 keyProvider,
500 inOutFSColor);
501 return pathTexGenEffectsBuilder.finish();
502 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698