Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: src/gpu/GrGeometryProcessor.h

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: adding test to ignore Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGeometryProcessor_DEFINED 8 #ifndef GrGeometryProcessor_DEFINED
9 #define GrGeometryProcessor_DEFINED 9 #define GrGeometryProcessor_DEFINED
10 10
11 #include "GrGeometryData.h" 11 #include "GrGeometryData.h"
12 #include "GrProcessor.h" 12 #include "GrProcessor.h"
13 #include "GrShaderVar.h" 13 #include "GrShaderVar.h"
14 14
15 /** 15 /**
16 * A GrGeomteryProcessor is used to perform computation in the vertex shader and 16 * A GrGeometryProcessor is used to perform computation in the vertex shader and
17 * add support for custom vertex attributes. A GrGemeotryProcessor is typically 17 * add support for custom vertex attributes. A GrGemeotryProcessor is typically
18 * tied to the code that does a specific type of high-level primitive rendering 18 * tied to the code that does a specific type of high-level primitive rendering
19 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is 19 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is
20 * specified using GrDrawState. There can only be one geometry processor active for 20 * specified using GrDrawState. There can only be one geometry processor active for
21 * a draw. The custom vertex attributes required by the geometry processor must be 21 * a draw. The custom vertex attributes required by the geometry processor must be
22 * added to the vertex attribute array specified on the GrDrawState. 22 * added to the vertex attribute array specified on the GrDrawState.
23 * GrGeometryProcessor subclasses should be immutable after construction. 23 * GrGeometryProcessor subclasses should be immutable after construction.
24 */ 24 */
25 class GrGeometryProcessor : public GrProcessor { 25 class GrGeometryProcessor : public GrProcessor {
26 public: 26 public:
27 GrGeometryProcessor() 27 GrGeometryProcessor()
28 : fWillUseGeoShader(false) {} 28 : fVertexStride(0)
29 , fWillUseGeoShader(false)
30 , fHasVertexColor(false)
31 , fHasVertexCoverage(false)
32 , fHasLocalCoords(false) {}
29 33
30 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; 34 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0;
31 35
32 /* 36 /*
33 * This only has a max because GLProgramsTest needs to generate test arrays, and these have to 37 * This is a safeguard to prevent GPs from going beyond platform specific at tribute limits.
34 * be static 38 * This number can almost certainly be raised if required.
35 * TODO make this truly dynamic
36 */ 39 */
37 static const int kMaxVertexAttribs = 2; 40 static const int kMaxVertexAttribs = 6;
38 typedef SkTArray<GrShaderVar, true> VertexAttribArray;
39 41
40 const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } 42 struct GrAttribute {
43 GrAttribute(const char* name, GrVertexAttribType type)
44 : fName(name)
45 , fType(type)
46 , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {}
47 const char* fName;
48 GrVertexAttribType fType;
49 size_t fOffset;
50 };
51
52 typedef SkTArray<GrAttribute, true> VertexAttribArray;
53
54 const VertexAttribArray& getAttribs() const { return fAttribs; }
55
56 // Returns the vertex stride of the GP. A common use case is to request geo metry from a
57 // drawtarget based off of the stride, and to populate this memory using an implicit array of
58 // structs. In this case, it is best to assert the vertexstride == sizeof(V ertexStruct).
59 size_t getVertexStride() const { return fVertexStride; }
41 60
42 bool willUseGeoShader() const { return fWillUseGeoShader; } 61 bool willUseGeoShader() const { return fWillUseGeoShader; }
43 62
44 /** Returns true if this and other processor conservatively draw identically . It can only return 63 /** Returns true if this and other processor conservatively draw identically . It can only return
45 true when the two prcoessors are of the same subclass (i.e. they return the same object from 64 true when the two prcoessors are of the same subclass (i.e. they return the same object from
46 from getFactory()). 65 from getFactory()).
47 A return value of true from isEqual() should not be used to test whether the processors 66 A return value of true from isEqual() should not be used to test whether the processors
48 would generate the same shader code. To test for identical code generati on use the 67 would generate the same shader code. To test for identical code generati on use the
49 processors' keys computed by the GrBackendEffectFactory. */ 68 processors' keys computed by the GrBackendEffectFactory. */
50 bool isEqual(const GrGeometryProcessor& that) const { 69 bool isEqual(const GrGeometryProcessor& that) const {
51 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc cesses(that)) { 70 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc cesses(that)) {
52 return false; 71 return false;
53 } 72 }
54 return this->onIsEqual(that); 73 return this->onIsEqual(that);
55 } 74 }
56 75
76 // TODO this is a total hack until the gp can own whether or not it uses uni form
77 // color / coverage
78 bool hasVertexColor() const { return fHasVertexColor; }
79 bool hasVertexCoverage() const { return fHasVertexCoverage; }
80 bool hasLocalCoords() const { return fHasLocalCoords; }
81
57 protected: 82 protected:
58 /** 83 /**
59 * Subclasses call this from their constructor to register vertex attributes (at most 84 * Subclasses call this from their constructor to register vertex attributes . Attributes
60 * kMaxVertexAttribs). This must only be called from the constructor because GrProcessors are 85 * will be padded to the nearest 4 bytes for performance reasons.
61 * immutable. 86 * TODO After deferred geometry, we should do all of this inline in Generate Geometry alongside
87 * the struct used to actually populate the attributes
62 */ 88 */
63 const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { 89 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) {
64 SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); 90 fVertexStride += attribute.fOffset;
65 return fVertexAttribs.push_back(var); 91 return fAttribs.push_back(attribute);
66 } 92 }
67 93
68 void setWillUseGeoShader() { fWillUseGeoShader = true; } 94 void setWillUseGeoShader() { fWillUseGeoShader = true; }
69 95
96 // TODO hack see above
97 void setHasVertexColor() { fHasVertexColor = true; }
98 void setHasVertexCoverage() { fHasVertexCoverage = true; }
99 void setHasLocalCoords() { fHasLocalCoords = true; }
100
70 private: 101 private:
71 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; 102 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0;
72 103
73 SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs; 104 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs;
105 size_t fVertexStride;
74 bool fWillUseGeoShader; 106 bool fWillUseGeoShader;
107 bool fHasVertexColor;
108 bool fHasVertexCoverage;
109 bool fHasLocalCoords;
75 110
76 typedef GrProcessor INHERITED; 111 typedef GrProcessor INHERITED;
77 }; 112 };
78 113
79 #endif 114 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698