Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLSLVarying.h
Go to the documentation of this file.
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
17
20
21#ifdef SK_DEBUG
22static bool is_matrix(SkSLType type) {
23 switch (type) {
30 return true;
31 default:
32 return false;
33 }
34}
35#endif
36
38public:
39 enum class Scope {
43 };
44
45 GrGLSLVarying() = default;
47 : fType(type)
48 , fScope(scope) {
49 // Metal doesn't support varying matrices, so we disallow them everywhere for consistency
50 SkASSERT(!is_matrix(type));
51 }
52
54 // Metal doesn't support varying matrices, so we disallow them everywhere for consistency
55 SkASSERT(!is_matrix(type));
56 *this = GrGLSLVarying();
57 fType = type;
58 fScope = scope;
59 }
60
61 SkSLType type() const { return fType; }
62 Scope scope() const { return fScope; }
63 bool isInVertexShader() const { return Scope::kGeoToFrag != fScope; }
64 bool isInFragmentShader() const { return Scope::kVertToGeo != fScope; }
65
66 const char* vsOut() const { SkASSERT(this->isInVertexShader()); return fVsOut; }
67 const char* fsIn() const { SkASSERT(this->isInFragmentShader()); return fFsIn; }
68
71 return GrShaderVar(this->vsOut(), fType, GrShaderVar::TypeModifier::Out);
72 }
73
76 return GrShaderVar(this->fsIn(), fType, GrShaderVar::TypeModifier::In);
77 }
78
79private:
82 const char* fVsOut = nullptr;
83 const char* fFsIn = nullptr;
84
86};
87
88static const int kVaryingsPerBlock = 8;
89
91public:
100
102
103 /**
104 * Notifies the varying handler that this shader will never emit geometry in perspective and
105 * therefore does not require perspective-correct interpolation. When supported, this allows
106 * varyings to use the "noperspective" keyword, which means the GPU can use cheaper math for
107 * interpolation.
108 */
109 void setNoPerspective();
110
111 enum class Interpolation {
113 kCanBeFlat, // Use "flat" if it will be faster.
114 kMustBeFlat // Use "flat" even if it is known to be slow.
115 };
116
117 /**
118 * addVarying allows fine grained control for setting up varyings between stages. Calling this
119 * function will make sure all necessary decls are setup for the client. The client however is
120 * responsible for setting up all shader code (e.g "vOut = vIn;") If you just need to take an
121 * attribute and pass it through to an output value in a fragment shader, use
122 * addPassThroughAttribute.
123 * TODO convert most uses of addVarying to addPassThroughAttribute
124 */
125 void addVarying(const char* name, GrGLSLVarying* varying,
127
128 /**
129 * The GP can use these calls to pass a vertex shader variable directly to 'output' in the
130 * fragment shader. Though this adds code to vertex and fragment stages, 'output' is expected to
131 * be defined in the fragment shader before the call is made.
132 * TODO it might be nicer behavior to have a flag to declare output inside these calls
133 */
134 void addPassThroughAttribute(const GrShaderVar& vsVar,
135 const char* output,
137
139
140 // This should be called once all attributes and varyings have been added to the
141 // GrGLSLVaryingHanlder and before getting/adding any of the declarations to the shaders.
142 void finalize();
143
144 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const;
145 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const;
146
147protected:
154
157
163
164 // This is not owned by the class
166
167private:
168 void addAttribute(const GrShaderVar& var);
169
170 virtual void onFinalize() = 0;
171
172 // helper function for get*Decls
173 void appendDecls(const VarArray& vars, SkString* out) const;
174
175 const char* fDefaultInterpolationModifier;
176
178};
179
180#endif
static const int kVaryingsPerBlock
GrShaderFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
SkSLType
SkTBlockList< GrShaderVar > VarArray
void emitAttributes(const GrGeometryProcessor &)
void addPassThroughAttribute(const GrShaderVar &vsVar, const char *output, Interpolation=Interpolation::kInterpolated)
void getVertexDecls(SkString *inputDecls, SkString *outputDecls) const
void getFragDecls(SkString *inputDecls, SkString *outputDecls) const
SkTBlockList< VaryingInfo > VaryingList
GrGLSLProgramBuilder * fProgramBuilder
GrGLSLVaryingHandler(GrGLSLProgramBuilder *program)
virtual void onFinalize()=0
void addVarying(const char *name, GrGLSLVarying *varying, Interpolation=Interpolation::kInterpolated)
virtual ~GrGLSLVaryingHandler()
GrGLSLVarying(SkSLType type, Scope scope=Scope::kVertToFrag)
Scope scope() const
bool isInVertexShader() const
const char * vsOut() const
bool isInFragmentShader() const
GrGLSLVarying()=default
const char * fsIn() const
GrShaderVar fsInVar() const
SkSLType type() const
void reset(SkSLType type, Scope scope=Scope::kVertToFrag)
GrShaderVar vsOutVar() const
const char * name
Definition fuchsia.cc:50