OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLSLVarying_DEFINED | 8 #ifndef GrGLSLVarying_DEFINED |
9 #define GrGLSLVarying_DEFINED | 9 #define GrGLSLVarying_DEFINED |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 public: | 72 public: |
73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program) | 73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program) |
74 : fVertexInputs(kVaryingsPerBlock) | 74 : fVertexInputs(kVaryingsPerBlock) |
75 , fVertexOutputs(kVaryingsPerBlock) | 75 , fVertexOutputs(kVaryingsPerBlock) |
76 , fGeomInputs(kVaryingsPerBlock) | 76 , fGeomInputs(kVaryingsPerBlock) |
77 , fGeomOutputs(kVaryingsPerBlock) | 77 , fGeomOutputs(kVaryingsPerBlock) |
78 , fFragInputs(kVaryingsPerBlock) | 78 , fFragInputs(kVaryingsPerBlock) |
79 , fFragOutputs(kVaryingsPerBlock) | 79 , fFragOutputs(kVaryingsPerBlock) |
80 , fProgramBuilder(program) {} | 80 , fProgramBuilder(program) {} |
81 | 81 |
| 82 virtual ~GrGLSLVaryingHandler() {} |
| 83 |
82 typedef GrTAllocator<GrGLSLShaderVar> VarArray; | 84 typedef GrTAllocator<GrGLSLShaderVar> VarArray; |
83 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; | 85 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; |
84 | 86 |
85 /* | 87 /* |
86 * addVarying allows fine grained control for setting up varyings between st
ages. Calling this | 88 * addVarying allows fine grained control for setting up varyings between st
ages. Calling this |
87 * functions will make sure all necessary decls are setup for the client. Th
e client however is | 89 * functions will make sure all necessary decls are setup for the client. Th
e client however is |
88 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus
t need to take an | 90 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus
t need to take an |
89 * attribute and pass it through to an output value in a fragment shader, us
e | 91 * attribute and pass it through to an output value in a fragment shader, us
e |
90 * addPassThroughAttribute. | 92 * addPassThroughAttribute. |
91 * TODO convert most uses of addVarying to addPassThroughAttribute | 93 * TODO convert most uses of addVarying to addPassThroughAttribute |
92 */ | 94 */ |
93 void addVarying(const char* name, | 95 void addVarying(const char* name, |
94 GrGLSLVarying*, | 96 GrGLSLVarying*, |
95 GrSLPrecision precision = kDefault_GrSLPrecision); | 97 GrSLPrecision precision = kDefault_GrSLPrecision); |
96 | 98 |
97 /* | 99 /* |
98 * This call can be used by GP to pass an attribute through all shaders dire
ctly to 'output' in | 100 * This call can be used by GP to pass an attribute through all shaders dire
ctly to 'output' in |
99 * the fragment shader. Though this call effects both the vertex shader and
fragment shader, | 101 * the fragment shader. Though this call effects both the vertex shader and
fragment shader, |
100 * it expects 'output' to be defined in the fragment shader before this call
is made. If there | 102 * it expects 'output' to be defined in the fragment shader before this call
is made. If there |
101 * is a geometry shader, we will simply take the value of the varying from t
he first vertex and | 103 * is a geometry shader, we will simply take the value of the varying from t
he first vertex and |
102 * that will be set as the output varying for all emitted vertices. | 104 * that will be set as the output varying for all emitted vertices. |
103 * TODO it might be nicer behavior to have a flag to declare output inside t
his call | 105 * TODO it might be nicer behavior to have a flag to declare output inside t
his call |
104 */ | 106 */ |
105 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch
ar* output); | 107 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch
ar* output); |
106 | 108 |
107 void emitAttributes(const GrGeometryProcessor& gp); | 109 void emitAttributes(const GrGeometryProcessor& gp); |
108 | 110 |
| 111 // This should be called once all attributes and varyings have been added to
the |
| 112 // GrGLSLVaryingHanlder and before getting/adding any of the declarations to
the shaders. |
| 113 void finalize(); |
| 114 |
109 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; | 115 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; |
110 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; | 116 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; |
111 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; | 117 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; |
112 protected: | 118 protected: |
113 VarArray fVertexInputs; | 119 VarArray fVertexInputs; |
114 VarArray fVertexOutputs; | 120 VarArray fVertexOutputs; |
115 VarArray fGeomInputs; | 121 VarArray fGeomInputs; |
116 VarArray fGeomOutputs; | 122 VarArray fGeomOutputs; |
117 VarArray fFragInputs; | 123 VarArray fFragInputs; |
118 VarArray fFragOutputs; | 124 VarArray fFragOutputs; |
119 | 125 |
120 // This is not owned by the class | 126 // This is not owned by the class |
121 GrGLSLProgramBuilder* fProgramBuilder; | 127 GrGLSLProgramBuilder* fProgramBuilder; |
122 | 128 |
123 private: | 129 private: |
124 void addVertexVarying(const char* name, GrSLPrecision precision, GrGLSLVaryi
ng* v); | 130 void addVertexVarying(const char* name, GrSLPrecision precision, GrGLSLVaryi
ng* v); |
125 void addGeomVarying(const char* name, GrSLPrecision precision, GrGLSLVarying
* v); | 131 void addGeomVarying(const char* name, GrSLPrecision precision, GrGLSLVarying
* v); |
126 void addFragVarying(GrSLPrecision precision, GrGLSLVarying* v); | 132 void addFragVarying(GrSLPrecision precision, GrGLSLVarying* v); |
127 | 133 |
128 void addAttribute(const GrShaderVar& var); | 134 void addAttribute(const GrShaderVar& var); |
129 | 135 |
| 136 virtual void onFinalize() = 0; |
| 137 |
130 // helper function for get*Decls | 138 // helper function for get*Decls |
131 void appendDecls(const VarArray& vars, SkString* out) const; | 139 void appendDecls(const VarArray& vars, SkString* out) const; |
132 | 140 |
133 friend class GrGLSLProgramBuilder; | 141 friend class GrGLSLProgramBuilder; |
134 }; | 142 }; |
135 | 143 |
136 #endif | 144 #endif |
OLD | NEW |