OLD | NEW |
---|---|
(Empty) | |
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 "GrProcessor.h" | |
12 class GrBackendGeometryProcessorFactory; | |
13 | |
14 /** | |
15 * A GrGeomteryProcessor is used to perform computation in the vertex shader and | |
16 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | |
17 * tied to the code that does a specific type of high-level primitive rendering | |
18 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is | |
19 * specified using GrDrawState. There can only be one geometry processor active for | |
20 * a draw. The custom vertex attributes required by the geometry processor must be | |
21 * added to the vertex attribute array specified on the GrDrawState. | |
22 * GrGeometryProcessor subclasses should be immutable after construction. | |
23 */ | |
24 class GrGeometryProcessor : public GrProcessor { | |
25 public: | |
26 GrGeometryProcessor() {} | |
27 | |
28 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; | |
29 | |
30 /* | |
31 * This only has a max because GLProgramsTest needs to generate test arrays, and these have to | |
32 * be static | |
33 * TODO make this truly dynamic | |
34 */ | |
35 static const int kMaxVertexAttribs = 2; | |
36 typedef SkTArray<GrShaderVar, true> VertexAttribArray; | |
37 | |
38 const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } | |
39 | |
40 protected: | |
41 /** | |
42 * Subclasses call this from their constructor to register vertex attributes (at most | |
43 * kMaxVertexAttribs). This must only be called from the constructor because GrProcessors are | |
44 * immutable. | |
45 */ | |
46 const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { | |
47 SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); | |
48 return fVertexAttribs.push_back(var); | |
49 } | |
50 | |
51 private: | |
52 VertexAttribArray fVertexAttribs; | |
bsalomon
2014/09/22 19:15:37
Might still make sense to use an SkSTArray<2 or 4,
| |
53 | |
54 typedef GrProcessor INHERITED; | |
55 }; | |
56 | |
57 /** | |
58 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called | |
59 * at global destruction time. NAME will be the name of the created GrProcessor. | |
60 */ | |
61 #define GR_CREATE_STATIC_GEOMETRY_PROCESSOR(NAME, GP_CLASS, ARGS) \ | |
62 static SkAlignedSStorage<sizeof(GP_CLASS)> g_##NAME##_Storage; \ | |
63 static GrGeometryProcessor* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), GP_CLASS, ARGS); \ | |
64 static SkAutoTDestroy<GrGeometryProcessor> NAME##_ad(NAME); | |
65 | |
66 #endif | |
OLD | NEW |