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

Side by Side Diff: src/gpu/glsl/GrGLSLProgramBuilder.h

Issue 1416423003: Make GrGLSLProgramBuilder base class for ProgramBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years, 1 month 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/glsl/GrGLSLCaps.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.cpp » ('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 2015 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 #ifndef GrGLSLProgramBuilder_DEFINED
9 #define GrGLSLProgramBuilder_DEFINED
10
11 #include "GrGeometryProcessor.h"
12 #include "GrGpu.h"
13 #include "gl/builders/GrGLFragmentShaderBuilder.h"
14 #include "gl/builders/GrGLGeometryShaderBuilder.h"
15 #include "gl/builders/GrGLVertexShaderBuilder.h"
16 #include "glsl/GrGLSLProgramDataManager.h"
17
18 class GrGLSLCaps;
19 class GrGLSLShaderVar;
20
21 class GrGLSLUniformBuilder {
22 public:
23 enum ShaderVisibility {
24 kVertex_Visibility = 1 << kVertex_GrShaderType,
25 kGeometry_Visibility = 1 << kGeometry_GrShaderType,
26 kFragment_Visibility = 1 << kFragment_GrShaderType,
27 };
28
29 virtual ~GrGLSLUniformBuilder() {}
30
31 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
32 typedef GrGLSLProgramDataManager::SeparableVaryingHandle SeparableVaryingHan dle;
33
34 /** Add a uniform variable to the current program, that has visibility in on e or more shaders.
35 visibility is a bitfield of ShaderVisibility values indicating from whic h shaders the
36 uniform should be accessible. At least one bit must be set. Geometry sha der uniforms are not
37 supported at this time. The actual uniform name will be mangled. If outN ame is not nullptr
38 then it will refer to the final uniform name after return. Use the addUn iformArray variant
39 to add an array of uniforms. */
40 UniformHandle addUniform(uint32_t visibility,
41 GrSLType type,
42 GrSLPrecision precision,
43 const char* name,
44 const char** outName = nullptr) {
45 return this->addUniformArray(visibility, type, precision, name, 0, outNa me);
46 }
47
48 UniformHandle addUniformArray(uint32_t visibility,
49 GrSLType type,
50 GrSLPrecision precision,
51 const char* name,
52 int arrayCount,
53 const char** outName = nullptr) {
54 return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
55 outName);
56 }
57
58 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0 ;
59
60 /**
61 * Shortcut for getUniformVariable(u).c_str()
62 */
63 virtual const char* getUniformCStr(UniformHandle u) const = 0;
64
65 virtual const GrGLSLCaps* glslCaps() const = 0;
66
67 /*
68 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
69 */
70 protected:
71 virtual UniformHandle internalAddUniformArray(
72 uint32_t visibility,
73 GrSLType type,
74 GrSLPrecision precision,
75 const char* name,
76 bool mangleName,
77 int arrayCount,
78 const char** outName) = 0;
79 };
80
81 // TODO move this into GrGLSLGPBuilder and move them both out of this file
82 class GrGLSLVarying {
83 public:
84 bool vsVarying() const { return kVertToFrag_Varying == fVarying ||
85 kVertToGeo_Varying == fVarying; }
86 bool fsVarying() const { return kVertToFrag_Varying == fVarying ||
87 kGeoToFrag_Varying == fVarying; }
88 const char* vsOut() const { return fVsOut; }
89 const char* gsIn() const { return fGsIn; }
90 const char* gsOut() const { return fGsOut; }
91 const char* fsIn() const { return fFsIn; }
92 GrSLType type() const { return fType; }
93
94 protected:
95 enum Varying {
96 kVertToFrag_Varying,
97 kVertToGeo_Varying,
98 kGeoToFrag_Varying,
99 };
100
101 GrGLSLVarying(GrSLType type, Varying varying)
102 : fVarying(varying), fType(type), fVsOut(nullptr), fGsIn(nullptr), fGsOu t(nullptr),
103 fFsIn(nullptr) {}
104
105 Varying fVarying;
106
107 private:
108 GrSLType fType;
109 const char* fVsOut;
110 const char* fGsIn;
111 const char* fGsOut;
112 const char* fFsIn;
113
114 friend class GrGLVertexBuilder;
115 friend class GrGLGeometryBuilder;
116 friend class GrGLXferBuilder;
117 friend class GrGLFragmentShaderBuilder;
118 };
119
120 struct GrGLSLVertToFrag : public GrGLSLVarying {
121 GrGLSLVertToFrag(GrSLType type)
122 : GrGLSLVarying(type, kVertToFrag_Varying) {}
123 };
124
125 struct GrGLSLVertToGeo : public GrGLSLVarying {
126 GrGLSLVertToGeo(GrSLType type)
127 : GrGLSLVarying(type, kVertToGeo_Varying) {}
128 };
129
130 struct GrGLSLGeoToFrag : public GrGLSLVarying {
131 GrGLSLGeoToFrag(GrSLType type)
132 : GrGLSLVarying(type, kGeoToFrag_Varying) {}
133 };
134
135 /* a specialization of the above for GPs. Lets the user add uniforms, varyings, and VS / FS code */
136 class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder {
137 public:
138 /*
139 * addVarying allows fine grained control for setting up varyings between st ages. If you just
140 * need to take an attribute and pass it through to an output value in a fra gment shader, use
141 * addPassThroughAttribute.
142 * TODO convert most uses of addVarying to addPassThroughAttribute
143 */
144 virtual void addVarying(const char* name,
145 GrGLSLVarying*,
146 GrSLPrecision precision = kDefault_GrSLPrecision) = 0;
147
148 /*
149 * This call can be used by GP to pass an attribute through all shaders dire ctly to 'output' in
150 * the fragment shader. Though this call effects both the vertex shader and fragment shader,
151 * it expects 'output' to be defined in the fragment shader before this call is made.
152 * TODO it might be nicer behavior to have a flag to declare output inside t his call
153 */
154 virtual void addPassThroughAttribute(const GrGeometryProcessor::Attribute*,
155 const char* output) = 0;
156
157 /*
158 * Creates a fragment shader varying that can be referred to.
159 * Comparable to GrGLSLUniformBuilder::addUniform().
160 */
161 virtual SeparableVaryingHandle addSeparableVarying(
162 const char* name, GrGLSLVertToFrag*,
163 GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
164
165 // TODO rename getFragmentBuilder
166 virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
167 virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0;
168
169 /*
170 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
171 */
172 };
173
174
175 /* a specializations for FPs. Lets the user add uniforms and FS code */
176 class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder {
177 public:
178 virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
179
180 /*
181 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
182 */
183 };
184
185 /* a specializations for XPs. Lets the user add uniforms and FS code */
186 class GrGLSLXPBuilder : public virtual GrGLSLUniformBuilder {
187 public:
188 virtual GrGLXPFragmentBuilder* getFragmentShaderBuilder() = 0;
189
190 /*
191 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
192 */
193 };
194
195 class GrGLSLProgramBuilder : public GrGLSLGPBuilder,
196 public GrGLSLFPBuilder,
197 public GrGLSLXPBuilder {
198 public:
199 typedef GrGpu::DrawArgs DrawArgs;
200
201 GrGLXPFragmentBuilder* getFragmentShaderBuilder() override { return &fFS; }
202 GrGLVertexBuilder* getVertexShaderBuilder() override { return &fVS; }
203
204 // Handles for program uniforms (other than per-effect uniforms)
205 struct BuiltinUniformHandles {
206 UniformHandle fRTAdjustmentUni;
207
208 // We use the render target height to provide a y-down frag coord when s pecifying
209 // origin_upper_left is not supported.
210 UniformHandle fRTHeightUni;
211 };
212
213 protected:
214 explicit GrGLSLProgramBuilder(const DrawArgs& args);
215
216 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim itiveProcessor; }
217 const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
218 const GrProgramDesc& desc() const { return *fArgs.fDesc; }
219 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header( ); }
220
221 void appendUniformDecls(ShaderVisibility, SkString*) const;
222
223 // Used to add a uniform for frag position without mangling the name of the uniform inside of a
224 // stage.
225 UniformHandle addFragPosUniform(uint32_t visibility,
226 GrSLType type,
227 GrSLPrecision precision,
228 const char* name,
229 const char** outName) {
230 return this->internalAddUniformArray(visibility, type, precision, name, false, 0, outName);
231 }
232
233 const char* rtAdjustment() const { return "rtAdjustment"; }
234
235 // Generates a name for a variable. The generated string will be name prefix ed by the prefix
236 // char (unless the prefix is '\0'). It also will mangle the name to be stag e-specific unless
237 // explicitly asked not to.
238 void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true);
239
240 // number of each input/output type in a single allocation block, used by ma ny builders
241 static const int kVarsPerBlock;
242
243 GrGLVertexBuilder fVS;
244 GrGLGeometryBuilder fGS;
245 GrGLFragmentShaderBuilder fFS;
246 int fStageIndex;
247
248 BuiltinUniformHandles fUniformHandles;
249
250 const DrawArgs& fArgs;
251
252 private:
253 virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out ) const = 0;
254
255 friend class GrGLShaderBuilder;
256 friend class GrGLVertexBuilder;
257 friend class GrGLFragmentShaderBuilder;
258 friend class GrGLGeometryBuilder;
259 };
260
261 #endif
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLCaps.cpp ('k') | src/gpu/glsl/GrGLSLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698