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