• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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 GrGeometryProcessor_DEFINED
9 #define GrGeometryProcessor_DEFINED
10 
11 #include "GrPrimitiveProcessor.h"
12 
13 /**
14  * A GrGeometryProcessor is a flexible method for rendering a primitive.  The GrGeometryProcessor
15  * has complete control over vertex attributes and uniforms(aside from the render target) but it
16  * must obey the same contract as any GrPrimitiveProcessor, specifically it must emit a color and
17  * coverage into the fragment shader.  Where this color and coverage come from is completely the
18  * responsibility of the GrGeometryProcessor.
19  */
20 class GrGeometryProcessor : public GrPrimitiveProcessor {
21 public:
GrGeometryProcessor()22     GrGeometryProcessor()
23         : fWillUseGeoShader(false)
24         , fLocalCoordsType(kUnused_LocalCoordsType) {}
25 
willUseGeoShader()26     bool willUseGeoShader() const override { return fWillUseGeoShader; }
27 
hasTransformedLocalCoords()28     bool hasTransformedLocalCoords() const override {
29         return kHasTransformed_LocalCoordsType == fLocalCoordsType;
30     }
31 
hasExplicitLocalCoords()32     bool hasExplicitLocalCoords() const override {
33         return kHasExplicit_LocalCoordsType == fLocalCoordsType;
34     }
35 
36 protected:
37     /**
38      * Subclasses call this from their constructor to register vertex attributes.  Attributes
39      * will be padded to the nearest 4 bytes for performance reasons.
40      * TODO After deferred geometry, we should do all of this inline in GenerateGeometry alongside
41      * the struct used to actually populate the attributes.  This is all extremely fragile, vertex
42      * attributes have to be added in the order they will appear in the struct which maps memory.
43      * The processor key should reflect the vertex attributes, or there lack thereof in the
44      * GrGeometryProcessor.
45      */
addVertexAttrib(const Attribute & attribute)46     const Attribute& addVertexAttrib(const Attribute& attribute) {
47         SkASSERT(fNumAttribs < kMaxVertexAttribs);
48         fVertexStride += attribute.fOffset;
49         fAttribs[fNumAttribs] = attribute;
50         return fAttribs[fNumAttribs++];
51     }
52 
setWillUseGeoShader()53     void setWillUseGeoShader() { fWillUseGeoShader = true; }
54 
55     /**
56      * If a GrFragmentProcessor in the GrPipeline needs localCoods, we will provide them in one of
57      * three ways
58      * 1) LocalCoordTransform * Position - in Shader
59      * 2) LocalCoordTransform * ExplicitLocalCoords- in Shader
60      * 3) A transformation on the CPU uploaded via vertex attribute
61      * TODO make this GrBatches responsibility
62      */
63     enum LocalCoordsType {
64         kUnused_LocalCoordsType,
65         kHasExplicit_LocalCoordsType,
66         kHasTransformed_LocalCoordsType
67     };
68 
setHasExplicitLocalCoords()69     void setHasExplicitLocalCoords() {
70         SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
71         fLocalCoordsType = kHasExplicit_LocalCoordsType;
72     }
setHasTransformedLocalCoords()73     void setHasTransformedLocalCoords() {
74         SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
75         fLocalCoordsType = kHasTransformed_LocalCoordsType;
76     }
77 
78 private:
79     bool fWillUseGeoShader;
80     LocalCoordsType fLocalCoordsType;
81 
82     typedef GrPrimitiveProcessor INHERITED;
83 };
84 
85 #endif
86