Line data Source code
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 0 : class GrGeometryProcessor : public GrPrimitiveProcessor {
21 : public:
22 0 : GrGeometryProcessor()
23 0 : : fWillUseGeoShader(false)
24 : , fLocalCoordsType(kUnused_LocalCoordsType)
25 0 : , fSampleShading(0.0) {}
26 :
27 0 : bool willUseGeoShader() const override { return fWillUseGeoShader; }
28 :
29 0 : bool hasExplicitLocalCoords() const override {
30 0 : 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 : */
38 0 : float getSampleShading() const override {
39 0 : return fSampleShading;
40 : }
41 :
42 : protected:
43 : /**
44 : * Subclasses call this from their constructor to register vertex attributes. Attributes
45 : * will be padded to the nearest 4 bytes for performance reasons.
46 : * TODO After deferred geometry, we should do all of this inline in GenerateGeometry alongside
47 : * the struct used to actually populate the attributes. This is all extremely fragile, vertex
48 : * attributes have to be added in the order they will appear in the struct which maps memory.
49 : * The processor key should reflect the vertex attributes, or there lack thereof in the
50 : * GrGeometryProcessor.
51 : */
52 0 : const Attribute& addVertexAttrib(const char* name, GrVertexAttribType type,
53 : GrSLPrecision precision = kDefault_GrSLPrecision) {
54 0 : precision = (kDefault_GrSLPrecision == precision) ? kMedium_GrSLPrecision : precision;
55 0 : fAttribs.emplace_back(name, type, precision);
56 0 : fVertexStride += fAttribs.back().fOffset;
57 0 : return fAttribs.back();
58 : }
59 :
60 : void setWillUseGeoShader() { fWillUseGeoShader = true; }
61 :
62 : /**
63 : * If a GrFragmentProcessor in the GrPipeline needs localCoods, we will provide them in one of
64 : * three ways
65 : * 1) LocalCoordTransform * Position - in Shader
66 : * 2) LocalCoordTransform * ExplicitLocalCoords- in Shader
67 : * 3) A transformation on the CPU uploaded via vertex attribute
68 : */
69 : enum LocalCoordsType {
70 : kUnused_LocalCoordsType,
71 : kHasExplicit_LocalCoordsType,
72 : kHasTransformed_LocalCoordsType
73 : };
74 :
75 0 : void setHasExplicitLocalCoords() {
76 0 : SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
77 0 : fLocalCoordsType = kHasExplicit_LocalCoordsType;
78 0 : }
79 : void setHasTransformedLocalCoords() {
80 : SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType);
81 : fLocalCoordsType = kHasTransformed_LocalCoordsType;
82 : }
83 :
84 0 : void setSampleShading(float sampleShading) {
85 0 : fSampleShading = sampleShading;
86 0 : }
87 :
88 : private:
89 : bool fWillUseGeoShader;
90 : LocalCoordsType fLocalCoordsType;
91 : float fSampleShading;
92 :
93 : typedef GrPrimitiveProcessor INHERITED;
94 : };
95 :
96 : #endif
|