blob: 91c6f5dda7dba3dab29c3cfa7612b68155639493 [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.
joshualitt4973d9d2014-11-08 09:24:25 -080020 */
21class GrDefaultGeoProcFactory {
22public:
23 // Structs for adding vertex attributes
24 struct PositionAttr {
25 SkPoint fPosition;
26 };
27
28 struct PositionCoverageAttr {
29 SkPoint fPosition;
30 GrColor fCoverage;
31 };
32
33 struct PositionColorAttr {
34 SkPoint fPosition;
35 SkColor fColor;
36 };
37
38 struct PositionColorCoverageAttr {
39 SkPoint fPosition;
40 SkColor fColor;
41 GrColor fCoverage;
42 };
43
44 struct PositionLocalCoordAttr {
45 SkPoint fPosition;
46 SkPoint fLocalCoord;
47 };
48
49 struct PositionLocalCoordCoverageAttr {
50 SkPoint fPosition;
51 SkPoint fLocalCoord;
52 GrColor fCoverage;
53 };
54
55 struct PositionColorLocalCoordAttr {
56 SkPoint fPosition;
57 GrColor fColor;
58 SkPoint fLocalCoord;
59 };
60
61 struct PositionColorLocalCoordCoverage {
62 SkPoint fPosition;
63 GrColor fColor;
64 SkPoint fLocalCoord;
65 GrColor fCoverage;
66 };
67
68 enum GPType {
69 kPosition_GPType = 0x0, // we ALWAYS have position
70 kColor_GPType = 0x01,
71 kLocalCoord_GPType = 0x02,
72 kCoverage_GPType= 0x04,
73 kLastGPType = kCoverage_GPType
74 };
75
joshualitt5478d422014-11-14 16:00:38 -080076 /*
77 * The following functions are used to create default GPs. If you just need to create
78 * attributes seperately from creating the default GP, use the SetAttribs function followed
79 * by the Create function. Otherwise use CreateAndSetAttribs to do both at once.
80 *
81 * You must unref the return from Create.
82 */
joshualitt8059eb92014-12-29 15:10:07 -080083 // TODO clean this up
84 static const GrGeometryProcessor* Create(uint32_t gpTypeFlags,
85 GrColor,
86 const SkMatrix& viewMatrix = SkMatrix::I(),
87 const SkMatrix& localMatrix = SkMatrix::I(),
joshualitt56995b52014-12-11 15:44:02 -080088 bool opaqueVertexColors = false,
joshualitt8059eb92014-12-29 15:10:07 -080089 uint8_t coverage = 0xff);
joshualitt8fc6c2d2014-12-22 15:27:05 -080090
joshualitt2e3b3e32014-12-09 13:31:14 -080091 static size_t DefaultVertexStride() { return sizeof(PositionAttr); }
joshualitt4973d9d2014-11-08 09:24:25 -080092};
93
94#endif