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