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

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

Issue 1462123003: Create GrGLSLVaryingHandler class for program building (Closed) Base URL: https://skia.googlesource.com/skia.git@putCapsOnArgs
Patch Set: add files 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
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 GrGLSLVarying_DEFINED
9 #define GrGLSLVarying_DEFINED
10
11 #include "GrAllocator.h"
12 #include "GrGeometryProcessor.h"
13 #include "GrTypesPriv.h"
14 #include "glsl/GrGLSLProgramDataManager.h"
15 #include "glsl/GrGLSLShaderVar.h"
16
17 class GrGLSLProgramBuilder;
18
19 class GrGLSLVarying {
20 public:
21 bool vsVarying() const { return kVertToFrag_Varying == fVarying ||
22 kVertToGeo_Varying == fVarying; }
23 bool fsVarying() const { return kVertToFrag_Varying == fVarying ||
24 kGeoToFrag_Varying == fVarying; }
25 const char* vsOut() const { return fVsOut; }
26 const char* gsIn() const { return fGsIn; }
27 const char* gsOut() const { return fGsOut; }
28 const char* fsIn() const { return fFsIn; }
29 GrSLType type() const { return fType; }
30
31 protected:
32 enum Varying {
33 kVertToFrag_Varying,
34 kVertToGeo_Varying,
35 kGeoToFrag_Varying,
36 };
37
38 GrGLSLVarying(GrSLType type, Varying varying)
39 : fVarying(varying), fType(type), fVsOut(nullptr), fGsIn(nullptr), fGsOu t(nullptr),
40 fFsIn(nullptr) {}
41
42 Varying fVarying;
43
44 private:
45 GrSLType fType;
46 const char* fVsOut;
47 const char* fGsIn;
48 const char* fGsOut;
49 const char* fFsIn;
50
51 friend class GrGLSLVaryingHandler;
52 };
53
54 struct GrGLSLVertToFrag : public GrGLSLVarying {
55 GrGLSLVertToFrag(GrSLType type)
56 : GrGLSLVarying(type, kVertToFrag_Varying) {}
57 };
58
59 struct GrGLSLVertToGeo : public GrGLSLVarying {
60 GrGLSLVertToGeo(GrSLType type)
61 : GrGLSLVarying(type, kVertToGeo_Varying) {}
62 };
63
64 struct GrGLSLGeoToFrag : public GrGLSLVarying {
65 GrGLSLGeoToFrag(GrSLType type)
66 : GrGLSLVarying(type, kGeoToFrag_Varying) {}
67 };
68
69 static const int kVaryingsPerBlock = 8;
70
71 class GrGLSLVaryingHandler {
72 public:
73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program)
joshualitt 2015/11/20 17:51:58 not that it matters, but why is this explicit?
bsalomon 2015/11/20 18:20:36 We strive to make all single arg constructors expl
74 : fVertexInputs(kVaryingsPerBlock)
75 , fVertexOutputs(kVaryingsPerBlock)
76 , fGeomInputs(kVaryingsPerBlock)
77 , fGeomOutputs(kVaryingsPerBlock)
78 , fFragInputs(kVaryingsPerBlock)
79 , fFragOutputs(kVaryingsPerBlock)
80 , fProgramBuilder(program) {}
81
82 virtual ~GrGLSLVaryingHandler() {}
83
84 typedef GrTAllocator<GrGLSLShaderVar> VarArray;
85 typedef GrGLSLProgramDataManager::SeparableVaryingHandle SeparableVaryingHan dle;
86
87 /*
88 * addVarying allows fine grained control for setting up varyings between st ages. Calling this
89 * functions will make sure all necessary decls are setup for the client. Th e client however is
90 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus t need to take an
91 * attribute and pass it through to an output value in a fragment shader, us e
92 * addPassThroughAttribute.
93 * TODO convert most uses of addVarying to addPassThroughAttribute
94 */
95 void addVarying(const char* name,
96 GrGLSLVarying*,
97 GrSLPrecision precision = kDefault_GrSLPrecision);
98
99 /*
100 * This call can be used by GP to pass an attribute through all shaders dire ctly to 'output' in
101 * the fragment shader. Though this call effects both the vertex shader and fragment shader,
102 * it expects 'output' to be defined in the fragment shader before this call is made. If there
103 * is a geometry shader, we will simply take the value of the varying from t he first vertex and
104 * that will be set as the output varying for all emitted vertices.
105 * TODO it might be nicer behavior to have a flag to declare output inside t his call
106 */
107 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch ar* output);
108
109 void emitAttributes(const GrGeometryProcessor& gp);
110
111 /*
112 * Creates a fragment shader varying that can be referred to.
113 * Comparable to GrGLSLUniformBuilder::addUniform().
114 */
115 virtual SeparableVaryingHandle addSeparableVarying(
116 const char* name, GrGLSLVertToFrag*,
117 GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
118
119 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const;
120 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const;
121 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const;
122 protected:
123 VarArray fVertexInputs;
124 VarArray fVertexOutputs;
125 VarArray fGeomInputs;
126 VarArray fGeomOutputs;
127 VarArray fFragInputs;
128 VarArray fFragOutputs;
129
130 // This is not owned by the class
131 GrGLSLProgramBuilder* fProgramBuilder;
132
133 private:
134 void addVertexVarying(const char* name, GrSLPrecision precision, GrGLSLVaryi ng* v);
135 void addGeomVarying(const char* name, GrSLPrecision precision, GrGLSLVarying * v);
136 void addFragVarying(GrSLPrecision precision, GrGLSLVarying* v);
137
138 void addAttribute(const GrShaderVar& var);
139
140 // helper function for get*Decls
141 void appendDecls(const VarArray& vars, SkString* out) const;
142
143 friend class GrGLSLProgramBuilder;
144 };
145
146 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698