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 GrGeometryProcessor_DEFINED | 8 #ifndef GrPrimitiveProcessor_DEFINED |
9 #define GrGeometryProcessor_DEFINED | 9 #define GrPrimitiveProcessor_DEFINED |
10 | 10 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrShaderVar.h" | 13 #include "GrShaderVar.h" |
14 | 14 |
15 /* | 15 /* |
16 * The GrPrimitiveProcessor represents some kind of geometric primitive. This i
ncludes the shape | 16 * The GrPrimitiveProcessor represents some kind of geometric primitive. This i
ncludes the shape |
17 * of the primitive and the inherent color of the primitive. The GrPrimitivePro
cessor is | 17 * of the primitive and the inherent color of the primitive. The GrPrimitivePro
cessor is |
18 * responsible for providing a color and coverage input into the Ganesh renderin
g pipeline. Through | 18 * responsible for providing a color and coverage input into the Ganesh renderin
g pipeline. Through |
19 * optimization, Ganesh may decide a different color, no color, and / or no cove
rage are required | 19 * optimization, Ganesh may decide a different color, no color, and / or no cove
rage are required |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 private: | 220 private: |
221 virtual bool hasExplicitLocalCoords() const = 0; | 221 virtual bool hasExplicitLocalCoords() const = 0; |
222 | 222 |
223 const SkMatrix fViewMatrix; | 223 const SkMatrix fViewMatrix; |
224 SkMatrix fLocalMatrix; | 224 SkMatrix fLocalMatrix; |
225 bool fIsPathRendering; | 225 bool fIsPathRendering; |
226 | 226 |
227 typedef GrProcessor INHERITED; | 227 typedef GrProcessor INHERITED; |
228 }; | 228 }; |
229 | 229 |
230 /** | |
231 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor | |
232 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it | |
233 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and | |
234 * coverage into the fragment shader. Where this color and coverage come from i
s completely the | |
235 * responsibility of the GrGeometryProcessor. | |
236 */ | |
237 class GrGeometryProcessor : public GrPrimitiveProcessor { | |
238 public: | |
239 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or | |
240 // atleast bundles | |
241 GrGeometryProcessor(GrColor color, | |
242 const SkMatrix& viewMatrix = SkMatrix::I(), | |
243 const SkMatrix& localMatrix = SkMatrix::I(), | |
244 bool opaqueVertexColors = false) | |
245 : INHERITED(viewMatrix, localMatrix, false) | |
246 , fColor(color) | |
247 , fOpaqueVertexColors(opaqueVertexColors) | |
248 , fWillUseGeoShader(false) | |
249 , fHasVertexColor(false) | |
250 , fHasLocalCoords(false) {} | |
251 | |
252 bool willUseGeoShader() const { return fWillUseGeoShader; } | |
253 | |
254 /* | |
255 * In an ideal world, two GrGeometryProcessors with the same class id and te
xture accesses | |
256 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are
the same then we | |
257 * will only keep one of them. The remaining GrGeometryProcessor then updat
es its | |
258 * GrBatchTracker to incorporate the draw information from the GrGeometryPro
cessor we discard. | |
259 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the | |
260 * remaining GrGeometryProcessor. | |
261 */ | |
262 bool canMakeEqual(const GrBatchTracker& mine, | |
263 const GrPrimitiveProcessor& that, | |
264 const GrBatchTracker& theirs) const SK_OVERRIDE { | |
265 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { | |
266 return false; | |
267 } | |
268 | |
269 // TODO let the GPs decide this | |
270 if (!this->viewMatrix().cheapEqualTo(that.viewMatrix())) { | |
271 return false; | |
272 } | |
273 | |
274 // TODO remove the hint | |
275 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); | |
276 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ | |
277 return false; | |
278 } | |
279 | |
280 // TODO this equality test should really be broken up, some of this can
live on the batch | |
281 // tracker test and some of this should be in bundles | |
282 if (!this->onIsEqual(other)) { | |
283 return false; | |
284 } | |
285 | |
286 return this->onCanMakeEqual(mine, other, theirs); | |
287 } | |
288 | |
289 // TODO we can remove color from the GrGeometryProcessor base class once we
have bundles of | |
290 // primitive data | |
291 GrColor color() const { return fColor; } | |
292 | |
293 // TODO this is a total hack until the gp can do deferred geometry | |
294 bool hasVertexColor() const { return fHasVertexColor; } | |
295 | |
296 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | |
297 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; | |
298 | |
299 protected: | |
300 /* | |
301 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should | |
302 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT | |
303 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported | |
304 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is | |
305 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must | |
306 * emit a color via uniform | |
307 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor | |
308 * can upload a new color via attribute if needed. | |
309 */ | |
310 static GrGPInput GetColorInputType(GrColor* color, GrColor primitiveColor, | |
311 const GrPipelineInfo& init, | |
312 bool hasVertexColor) { | |
313 if (init.fColorIgnored) { | |
314 *color = GrColor_ILLEGAL; | |
315 return kIgnored_GrGPInput; | |
316 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | |
317 *color = init.fOverrideColor; | |
318 return kUniform_GrGPInput; | |
319 } | |
320 | |
321 *color = primitiveColor; | |
322 if (hasVertexColor) { | |
323 return kAttribute_GrGPInput; | |
324 } else { | |
325 return kUniform_GrGPInput; | |
326 } | |
327 } | |
328 | |
329 /** | |
330 * Subclasses call this from their constructor to register vertex attributes
. Attributes | |
331 * will be padded to the nearest 4 bytes for performance reasons. | |
332 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | |
333 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex | |
334 * attributes have to be added in the order they will appear in the struct w
hich maps memory. | |
335 * The processor key should reflect the vertex attributes, or there lack the
reof in the | |
336 * GrGeometryProcessor. | |
337 */ | |
338 const Attribute& addVertexAttrib(const Attribute& attribute) { | |
339 SkASSERT(fNumAttribs < kMaxVertexAttribs); | |
340 fVertexStride += attribute.fOffset; | |
341 fAttribs[fNumAttribs] = attribute; | |
342 return fAttribs[fNumAttribs++]; | |
343 } | |
344 | |
345 void setWillUseGeoShader() { fWillUseGeoShader = true; } | |
346 | |
347 // TODO hack see above | |
348 void setHasVertexColor() { fHasVertexColor = true; } | |
349 void setHasLocalCoords() { fHasLocalCoords = true; } | |
350 | |
351 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} | |
352 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; | |
353 | |
354 private: | |
355 virtual bool onCanMakeEqual(const GrBatchTracker& mine, | |
356 const GrGeometryProcessor& that, | |
357 const GrBatchTracker& theirs) const = 0; | |
358 | |
359 // TODO delete this when we have more advanced equality testing via bundles
and the BT | |
360 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | |
361 | |
362 bool hasExplicitLocalCoords() const SK_OVERRIDE { return fHasLocalCoords; } | |
363 | |
364 GrColor fColor; | |
365 bool fOpaqueVertexColors; | |
366 bool fWillUseGeoShader; | |
367 bool fHasVertexColor; | |
368 bool fHasLocalCoords; | |
369 | |
370 typedef GrPrimitiveProcessor INHERITED; | |
371 }; | |
372 | |
373 /* | |
374 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on | |
375 * extending this class to handle all nvpr uniform / varying / program work. | |
376 */ | |
377 class GrPathProcessor : public GrPrimitiveProcessor { | |
378 public: | |
379 static GrPathProcessor* Create(GrColor color, | |
380 const SkMatrix& viewMatrix = SkMatrix::I(), | |
381 const SkMatrix& localMatrix = SkMatrix::I())
{ | |
382 return SkNEW_ARGS(GrPathProcessor, (color, viewMatrix, localMatrix)); | |
383 } | |
384 | |
385 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const SK_OVERR
IDE; | |
386 | |
387 bool canMakeEqual(const GrBatchTracker& mine, | |
388 const GrPrimitiveProcessor& that, | |
389 const GrBatchTracker& theirs) const SK_OVERRIDE; | |
390 | |
391 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | |
392 | |
393 GrColor color() const { return fColor; } | |
394 | |
395 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | |
396 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; | |
397 | |
398 bool willUseGeoShader() const SK_OVERRIDE { return false; } | |
399 | |
400 virtual void getGLProcessorKey(const GrBatchTracker& bt, | |
401 const GrGLCaps& caps, | |
402 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | |
403 | |
404 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | |
405 const GrGLCaps& caps) const
SK_OVERRIDE; | |
406 | |
407 protected: | |
408 GrPathProcessor(GrColor color, const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix); | |
409 | |
410 private: | |
411 bool hasExplicitLocalCoords() const SK_OVERRIDE { return false; } | |
412 | |
413 GrColor fColor; | |
414 | |
415 typedef GrPrimitiveProcessor INHERITED; | |
416 }; | |
417 | |
418 #endif | 230 #endif |
OLD | NEW |