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

Side by Side Diff: src/gpu/gl/builders/GrGLFullProgramBuilder.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/GrGLFullProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrGLFullProgramBuilder.h"
9 #include "../GrGpuGL.h"
10
11 GrGLFullProgramBuilder::GrGLFullProgramBuilder(GrGpuGL* gpu,
12 const GrGLProgramDesc& desc)
13 : INHERITED(gpu, desc)
14 , fGS(this)
15 , fVS(this) {
16 }
17
18 void GrGLFullProgramBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color,
19 GrGLSLExpr4* coverage) {
20 fVS.emitCodeBeforeEffects(color, coverage);
21 }
22
23 void GrGLFullProgramBuilder::emitGeometryProcessor(const GrEffectStage* geometry Processor,
24 GrGLSLExpr4* coverage) {
25 if (geometryProcessor) {
26 GrGLProgramDesc::EffectKeyProvider geometryProcessorKeyProvider(
27 &this->desc(), GrGLProgramDesc::EffectKeyProvider::kGeometryProc essor_EffectType);
28 fGeometryProcessor.reset(this->createAndEmitEffect(
29 geometryProcessor,
30 geometryProcessorKeyProvider,
31 coverage));
32 }
33 }
34
35 void GrGLFullProgramBuilder::emitCodeAfterEffects() {
36 fVS.emitCodeAfterEffects();
37 }
38
39 void GrGLFullProgramBuilder::addVarying(GrSLType type,
40 const char* name,
41 const char** vsOutName,
42 const char** fsInName,
43 GrGLShaderVar::Precision fsPrecision) {
44 fVS.addVarying(type, name, vsOutName);
45
46 SkString* fsInputName = fVS.fOutputs.back().accessName();
47
48 #if GR_GL_EXPERIMENTAL_GS
49 if (desc().getHeader().fExperimentalGS) {
50 // TODO let the caller use these names
51 fGS.addVarying(type, fsInputName->c_str(), NULL);
52 fsInputName = fGS.fOutputs.back().accessName();
53 }
54 #endif
55 fFS.addVarying(type, fsInputName->c_str(), fsInName, fsPrecision);
56 }
57
58 GrGLFullProgramBuilder::VaryingHandle
59 GrGLFullProgramBuilder::addSeparableVarying(GrSLType type,
60 const char* name,
61 const char** vsOutName,
62 const char** fsInName) {
63 addVarying(type, name, vsOutName, fsInName);
64 SeparableVaryingInfo& varying = fSeparableVaryingInfos.push_back();
65 varying.fVariable = fFS.fInputs.back();
66 return VaryingHandle::CreateFromSeparableVaryingIndex(fSeparableVaryingInfos .count() - 1);
67 }
68
69
70 GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffects(
71 const GrEffectStage* effectStages[],
72 int effectCnt,
73 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
74 GrGLSLExpr4* inOutFSColor) {
75
76 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt);
77 this->INHERITED::createAndEmitEffects(&programEffectsBuilder,
78 effectStages,
79 effectCnt,
80 keyProvider,
81 inOutFSColor);
82 return programEffectsBuilder.finish();
83 }
84
85 void GrGLFullProgramBuilder::createAndEmitEffect(GrGLProgramEffectsBuilder* prog ramEffectsBuilder,
86 const GrEffectStage* effectStages,
87 const GrGLProgramDesc::EffectKeyPr ovider& keyProvider,
88 GrGLSLExpr4* fsInOutColor) {
89 GrGLSLExpr4 inColor = *fsInOutColor;
90 GrGLSLExpr4 outColor;
91
92 SkASSERT(effectStages && effectStages->getEffect());
93 const GrEffectStage& stage = *effectStages;
94
95 // Using scope to force ASR destructor to be triggered
96 {
97 CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
98
99 if (inColor.isZeros()) {
100 SkString inColorName;
101
102 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
103 this->nameVariable(&inColorName, '\0', "input");
104 fFS.codeAppendf("vec4 %s = %s;", inColorName.c_str(), inColor.c_str( ));
105 inColor = inColorName;
106 }
107
108 // create var to hold stage result
109 SkString outColorName;
110 this->nameVariable(&outColorName, '\0', "output");
111 fFS.codeAppendf("vec4 %s;", outColorName.c_str());
112 outColor = outColorName;
113
114
115 programEffectsBuilder->emitEffect(stage,
116 keyProvider.get(0),
117 outColor.c_str(),
118 inColor.isOnes() ? NULL : inColor.c_st r(),
119 fCodeStage.stageIndex());
120 }
121
122 *fsInOutColor = outColor;
123 }
124
125 GrGLProgramEffects* GrGLFullProgramBuilder::createAndEmitEffect(
126 const GrEffectStage* geometryProcessor,
127 const GrGLProgramDesc::EffectKeyProvider& keyProvider,
128 GrGLSLExpr4* inOutFSColor) {
129
130 GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, 1);
131 this->createAndEmitEffect(&programEffectsBuilder, geometryProcessor, keyProv ider, inOutFSColor);
132 return programEffectsBuilder.finish();
133 }
134
135 bool GrGLFullProgramBuilder::compileAndAttachShaders(GrGLuint programId,
136 SkTDArray<GrGLuint>* shader Ids) const {
137 return INHERITED::compileAndAttachShaders(programId, shaderIds)
138 && fVS.compileAndAttachShaders(programId, shaderIds)
139 #if GR_GL_EXPERIMENTAL_GS
140 && (!desc().getHeader().fExperimentalGS
141 || fGS.compileAndAttachShaders(programId, shaderIds))
142 #endif
143 ;
144 }
145
146 void GrGLFullProgramBuilder::bindProgramLocations(GrGLuint programId) {
147 fVS.bindProgramLocations(programId);
148 INHERITED::bindProgramLocations(programId);
149 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLFullProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698