blob: 99d85b64d634b08ba2aa9be67ebf48ac589251fd [file] [log] [blame]
joshualitt4973d9d2014-11-08 09:24:25 -08001/*
2 * Copyright 2014 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 GrDefaultGeoProcFactory_DEFINED
9#define GrDefaultGeoProcFactory_DEFINED
10
11#include "GrGeometryProcessor.h"
12
13class GrDrawState;
14
15/*
16 * A factory for creating default Geometry Processors which simply multiply position by the uniform
17 * view matrix and wire through color, coverage, UV coords if requested. Right now this is only
18 * used in the creation of optimized draw states because adding default GPs to the drawstate can
19 * interfere with batching due to updating the drawstate.
20 * TODO When we track geometry state separately from the draw state, we should be able use a default
21 * GP with every draw call
22 */
23class GrDefaultGeoProcFactory {
24public:
25 // Structs for adding vertex attributes
26 struct PositionAttr {
27 SkPoint fPosition;
28 };
29
30 struct PositionCoverageAttr {
31 SkPoint fPosition;
32 GrColor fCoverage;
33 };
34
35 struct PositionColorAttr {
36 SkPoint fPosition;
37 SkColor fColor;
38 };
39
40 struct PositionColorCoverageAttr {
41 SkPoint fPosition;
42 SkColor fColor;
43 GrColor fCoverage;
44 };
45
46 struct PositionLocalCoordAttr {
47 SkPoint fPosition;
48 SkPoint fLocalCoord;
49 };
50
51 struct PositionLocalCoordCoverageAttr {
52 SkPoint fPosition;
53 SkPoint fLocalCoord;
54 GrColor fCoverage;
55 };
56
57 struct PositionColorLocalCoordAttr {
58 SkPoint fPosition;
59 GrColor fColor;
60 SkPoint fLocalCoord;
61 };
62
63 struct PositionColorLocalCoordCoverage {
64 SkPoint fPosition;
65 GrColor fColor;
66 SkPoint fLocalCoord;
67 GrColor fCoverage;
68 };
69
70 enum GPType {
71 kPosition_GPType = 0x0, // we ALWAYS have position
72 kColor_GPType = 0x01,
73 kLocalCoord_GPType = 0x02,
74 kCoverage_GPType= 0x04,
75 kLastGPType = kCoverage_GPType
76 };
77
joshualitt5478d422014-11-14 16:00:38 -080078 /*
79 * The following functions are used to create default GPs. If you just need to create
80 * attributes seperately from creating the default GP, use the SetAttribs function followed
81 * by the Create function. Otherwise use CreateAndSetAttribs to do both at once.
82 *
83 * You must unref the return from Create.
84 */
85 static void SetAttribs(GrDrawState*, uint32_t GPTypeFlags = 0);
86 static const GrGeometryProcessor* CreateAndSetAttribs(GrDrawState*, uint32_t GPTypeFlags = 0);
87 static const GrGeometryProcessor* Create(bool hasAttributeCoverage);
joshualitt4973d9d2014-11-08 09:24:25 -080088};
89
90#endif