• 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(ClassID classID)22     GrGeometryProcessor(ClassID classID)
23         : INHERITED(classID)
24         , fWillUseGeoShader(false)
25         , fLocalCoordsType(kUnused_LocalCoordsType)
26         , fSampleShading(0.0) {}
27 
willUseGeoShader()28     bool willUseGeoShader() const final { return fWillUseGeoShader; }
29 
hasExplicitLocalCoords()30     bool hasExplicitLocalCoords() const final {
31         return kHasExplicit_LocalCoordsType == fLocalCoordsType;
32     }
33 
34     /**
35      * Returns the minimum fraction of samples for which the fragment shader will be run. For
36      * instance, if sampleShading is 0.5 in MSAA16 mode, the fragment shader will run a minimum of
37      * 8 times per pixel. The default value is zero.
38      */
getSampleShading()39     float getSampleShading() const final { return fSampleShading; }
40 
41 protected:
setWillUseGeoShader()42     void setWillUseGeoShader() { fWillUseGeoShader = true; }
43 
44     /**
45      * If a GrFragmentProcessor in the GrPipeline needs localCoods, we will provide them in one of
46      * three ways
47      * 1) LocalCoordTransform * Position - in Shader
48      * 2) LocalCoordTransform * ExplicitLocalCoords- in Shader
49      * 3) A transformation on the CPU uploaded via vertex attribute
50      */
51     enum LocalCoordsType {
52         kUnused_LocalCoordsType,
53         kHasExplicit_LocalCoordsType,
54         kHasTransformed_LocalCoordsType
55     };
56 
setHasExplicitLocalCoords()57     void setHasExplicitLocalCoords() {
58         SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
59         fLocalCoordsType = kHasExplicit_LocalCoordsType;
60     }
setHasTransformedLocalCoords()61     void setHasTransformedLocalCoords() {
62         SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
63         fLocalCoordsType = kHasTransformed_LocalCoordsType;
64     }
65 
setSampleShading(float sampleShading)66     void setSampleShading(float sampleShading) {
67         fSampleShading = sampleShading;
68     }
69 
70 private:
71     bool fWillUseGeoShader;
72     LocalCoordsType fLocalCoordsType;
73     float fSampleShading;
74 
75     typedef GrPrimitiveProcessor INHERITED;
76 };
77 
78 #endif
79