OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrGLGeometryProcessor_DEFINED | 8 #ifndef GrGLPrimitiveProcessor_DEFINED |
9 #define GrGLGeometryProcessor_DEFINED | 9 #define GrGLPrimitiveProcessor_DEFINED |
10 | 10 |
| 11 #include "GrPrimitiveProcessor.h" |
11 #include "GrGLProcessor.h" | 12 #include "GrGLProcessor.h" |
12 | 13 |
13 class GrBatchTracker; | 14 class GrBatchTracker; |
14 class GrFragmentProcessor; | 15 class GrPrimitiveProcessor; |
15 class GrGLGPBuilder; | 16 class GrGLGPBuilder; |
16 | 17 |
17 class GrGLPrimitiveProcessor { | 18 class GrGLPrimitiveProcessor { |
18 public: | 19 public: |
19 GrGLPrimitiveProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::I
nvalidMatrix(); } | 20 GrGLPrimitiveProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::I
nvalidMatrix(); } |
20 virtual ~GrGLPrimitiveProcessor() {} | 21 virtual ~GrGLPrimitiveProcessor() {} |
21 | 22 |
22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 23 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
23 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; | 24 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
24 | 25 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 protected: | 76 protected: |
76 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. | 77 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. |
77 * This function will only do the minimum required to emit the correct shad
er code. If | 78 * This function will only do the minimum required to emit the correct shad
er code. If |
78 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform | 79 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform |
79 * then colorUniform must not be NULL. | 80 * then colorUniform must not be NULL. |
80 */ | 81 */ |
81 void setupColorPassThrough(GrGLGPBuilder* pb, | 82 void setupColorPassThrough(GrGLGPBuilder* pb, |
82 GrGPInput inputType, | 83 GrGPInput inputType, |
83 const char* inputName, | 84 const char* inputName, |
84 const GrGeometryProcessor::Attribute* colorAttr, | 85 const GrPrimitiveProcessor::Attribute* colorAttr, |
85 UniformHandle* colorUniform); | 86 UniformHandle* colorUniform); |
86 | 87 |
87 const char* uViewM() const { return fViewMatrixName; } | 88 const char* uViewM() const { return fViewMatrixName; } |
88 | 89 |
89 /** a helper function to setup the uniform handle for the uniform view matri
x */ | 90 /** a helper function to setup the uniform handle for the uniform view matri
x */ |
90 void addUniformViewMatrix(GrGLGPBuilder*); | 91 void addUniformViewMatrix(GrGLGPBuilder*); |
91 | 92 |
92 | 93 |
93 /** a helper function to upload a uniform viewmatrix. | 94 /** a helper function to upload a uniform viewmatrix. |
94 * TODO we can remove this function when we have deferred geometry in place | 95 * TODO we can remove this function when we have deferred geometry in place |
(...skipping 24 matching lines...) Expand all Loading... |
119 }; | 120 }; |
120 | 121 |
121 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; | 122 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
122 | 123 |
123 private: | 124 private: |
124 UniformHandle fViewMatrixUniform; | 125 UniformHandle fViewMatrixUniform; |
125 SkMatrix fViewMatrix; | 126 SkMatrix fViewMatrix; |
126 const char* fViewMatrixName; | 127 const char* fViewMatrixName; |
127 }; | 128 }; |
128 | 129 |
129 class GrGLPathRendering; | |
130 class GrGLVertexBuilder; | |
131 /** | |
132 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit | |
133 * from this class. Since paths don't have vertices, this class is only meant to
be used internally | |
134 * by skia, for special cases. | |
135 */ | |
136 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { | |
137 public: | |
138 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ | |
139 void emitCode(EmitArgs&) SK_OVERRIDE; | |
140 | |
141 void setTransformData(const GrPrimitiveProcessor&, | |
142 const GrGLProgramDataManager&, | |
143 int index, | |
144 const SkTArray<const GrCoordTransform*, true>& transfo
rms); | |
145 | |
146 protected: | |
147 // Many GrGeometryProcessors do not need explicit local coords | |
148 void emitTransforms(GrGLGPBuilder* gp, | |
149 const GrShaderVar& posVar, | |
150 const SkMatrix& localMatrix, | |
151 const TransformsIn& tin, | |
152 TransformsOut* tout) { | |
153 this->emitTransforms(gp, posVar, posVar.c_str(), localMatrix, tin, tout)
; | |
154 } | |
155 | |
156 void emitTransforms(GrGLGPBuilder*, | |
157 const GrShaderVar& posVar, | |
158 const char* localCoords, | |
159 const SkMatrix& localMatrix, | |
160 const TransformsIn&, | |
161 TransformsOut*); | |
162 | |
163 struct GrGPArgs { | |
164 // The variable used by a GP to store its position. It can be | |
165 // either a vec2 or a vec3 depending on the presence of perspective. | |
166 GrShaderVar fPositionVar; | |
167 }; | |
168 | |
169 // Create the correct type of position variable given the CTM | |
170 static void SetupPosition(GrGLVertexBuilder* vsBuilder, | |
171 GrGPArgs* gpArgs, | |
172 const char* posName, | |
173 const SkMatrix& mat, | |
174 const char* matName); | |
175 | |
176 static uint32_t ComputePosKey(const SkMatrix& mat) { | |
177 if (mat.isIdentity()) { | |
178 return 0x0; | |
179 } else if (!mat.hasPerspective()) { | |
180 return 0x01; | |
181 } else { | |
182 return 0x02; | |
183 } | |
184 } | |
185 | |
186 private: | |
187 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; | |
188 | |
189 typedef GrGLPrimitiveProcessor INHERITED; | |
190 }; | |
191 | |
192 class GrGLGpu; | |
193 | |
194 class GrGLPathProcessor : public GrGLPrimitiveProcessor { | |
195 public: | |
196 GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracker&); | |
197 | |
198 static void GenKey(const GrPathProcessor&, | |
199 const GrBatchTracker& bt, | |
200 const GrGLCaps&, | |
201 GrProcessorKeyBuilder* b); | |
202 | |
203 void emitCode(EmitArgs&) SK_OVERRIDE; | |
204 | |
205 virtual void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsO
ut*) = 0; | |
206 | |
207 virtual void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId) {} | |
208 | |
209 void setData(const GrGLProgramDataManager&, | |
210 const GrPrimitiveProcessor&, | |
211 const GrBatchTracker&) SK_OVERRIDE; | |
212 | |
213 virtual void setTransformData(const GrPrimitiveProcessor&, | |
214 int index, | |
215 const SkTArray<const GrCoordTransform*, true>&
transforms, | |
216 GrGLPathRendering*, | |
217 GrGLuint programID) = 0; | |
218 | |
219 virtual void didSetData(GrGLPathRendering*) {} | |
220 | |
221 private: | |
222 UniformHandle fColorUniform; | |
223 GrColor fColor; | |
224 | |
225 typedef GrGLPrimitiveProcessor INHERITED; | |
226 }; | |
227 | |
228 #endif | 130 #endif |
OLD | NEW |