aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrGeometryProcessor.h
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2014-12-03 06:24:10 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-03 06:24:10 -0800
commit2dd1ae016d7f297b433c3ea3a771ef8e01657c1f (patch)
tree96aa03d4b4b1802490cb5b769627b75f3de4a470 /src/gpu/GrGeometryProcessor.h
parent960fb50a1a7ac76fd51e22983812f26bfffa6d1e (diff)
First step to moving vertex attributes to the geometryProcessor
Diffstat (limited to 'src/gpu/GrGeometryProcessor.h')
-rw-r--r--src/gpu/GrGeometryProcessor.h65
1 files changed, 50 insertions, 15 deletions
diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h
index 6d27f0b4f1..17344d2bb4 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;
};