| Index: src/gpu/GrGeometryProcessor.h
|
| diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h
|
| index 6d27f0b4f123788f9eb29ae7c0334f972731268f..17344d2bb4c251df6469aff20512bb4ba98fdf13 100644
|
| --- a/src/gpu/GrGeometryProcessor.h
|
| +++ b/src/gpu/GrGeometryProcessor.h
|
| @@ -13,7 +13,7 @@
|
| #include "GrShaderVar.h"
|
|
|
| /**
|
| - * A GrGeomteryProcessor is used to perform computation in the vertex shader and
|
| + * A GrGeometryProcessor is used to perform computation in the vertex shader and
|
| * add support for custom vertex attributes. A GrGemeotryProcessor is typically
|
| * tied to the code that does a specific type of high-level primitive rendering
|
| * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is
|
| @@ -25,19 +25,38 @@
|
| class GrGeometryProcessor : public GrProcessor {
|
| public:
|
| GrGeometryProcessor()
|
| - : fWillUseGeoShader(false) {}
|
| + : fVertexStride(0)
|
| + , fWillUseGeoShader(false)
|
| + , fHasVertexColor(false)
|
| + , fHasVertexCoverage(false)
|
| + , fHasLocalCoords(false) {}
|
|
|
| virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0;
|
|
|
| /*
|
| - * This only has a max because GLProgramsTest needs to generate test arrays, and these have to
|
| - * be static
|
| - * TODO make this truly dynamic
|
| + * This is a safeguard to prevent GPs from going beyond platform specific attribute limits.
|
| + * This number can almost certainly be raised if required.
|
| */
|
| - static const int kMaxVertexAttribs = 2;
|
| - typedef SkTArray<GrShaderVar, true> VertexAttribArray;
|
| + static const int kMaxVertexAttribs = 6;
|
|
|
| - const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; }
|
| + struct GrAttribute {
|
| + GrAttribute(const char* name, GrVertexAttribType type)
|
| + : fName(name)
|
| + , fType(type)
|
| + , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {}
|
| + const char* fName;
|
| + GrVertexAttribType fType;
|
| + size_t fOffset;
|
| + };
|
| +
|
| + typedef SkTArray<GrAttribute, true> VertexAttribArray;
|
| +
|
| + const VertexAttribArray& getAttribs() const { return fAttribs; }
|
| +
|
| + // Returns the vertex stride of the GP. A common use case is to request geometry from a
|
| + // drawtarget based off of the stride, and to populate this memory using an implicit array of
|
| + // structs. In this case, it is best to assert the vertexstride == sizeof(VertexStruct).
|
| + size_t getVertexStride() const { return fVertexStride; }
|
|
|
| bool willUseGeoShader() const { return fWillUseGeoShader; }
|
|
|
| @@ -54,24 +73,40 @@ public:
|
| return this->onIsEqual(that);
|
| }
|
|
|
| + // TODO this is a total hack until the gp can own whether or not it uses uniform
|
| + // color / coverage
|
| + bool hasVertexColor() const { return fHasVertexColor; }
|
| + bool hasVertexCoverage() const { return fHasVertexCoverage; }
|
| + bool hasLocalCoords() const { return fHasLocalCoords; }
|
| +
|
| protected:
|
| /**
|
| - * Subclasses call this from their constructor to register vertex attributes (at most
|
| - * kMaxVertexAttribs). This must only be called from the constructor because GrProcessors are
|
| - * immutable.
|
| + * Subclasses call this from their constructor to register vertex attributes. Attributes
|
| + * will be padded to the nearest 4 bytes for performance reasons.
|
| + * TODO After deferred geometry, we should do all of this inline in GenerateGeometry alongside
|
| + * the struct used to actually populate the attributes
|
| */
|
| - const GrShaderVar& addVertexAttrib(const GrShaderVar& var) {
|
| - SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs);
|
| - return fVertexAttribs.push_back(var);
|
| + const GrAttribute& addVertexAttrib(const GrAttribute& attribute) {
|
| + fVertexStride += attribute.fOffset;
|
| + return fAttribs.push_back(attribute);
|
| }
|
|
|
| void setWillUseGeoShader() { fWillUseGeoShader = true; }
|
|
|
| + // TODO hack see above
|
| + void setHasVertexColor() { fHasVertexColor = true; }
|
| + void setHasVertexCoverage() { fHasVertexCoverage = true; }
|
| + void setHasLocalCoords() { fHasLocalCoords = true; }
|
| +
|
| private:
|
| virtual bool onIsEqual(const GrGeometryProcessor&) const = 0;
|
|
|
| - SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs;
|
| + SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs;
|
| + size_t fVertexStride;
|
| bool fWillUseGeoShader;
|
| + bool fHasVertexColor;
|
| + bool fHasVertexCoverage;
|
| + bool fHasLocalCoords;
|
|
|
| typedef GrProcessor INHERITED;
|
| };
|
|
|