From 92be2f74db81f0ed480b55c58cbde39270f9b772 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 19 Jun 2018 14:33:47 -0400 Subject: Revert "Revert "Change how vertex/instance attributes are handled in geometry processors."" This reverts commit 5045e501d2aec23e5f1e4b46346033ac3202c6b0. TBR=csmartdalton@google.com Change-Id: Ifbf5f1d8f8ef340fdc69653e931b6d68d4bf0854 Reviewed-on: https://skia-review.googlesource.com/135862 Reviewed-by: Brian Salomon Commit-Queue: Brian Salomon --- tests/GrMeshTest.cpp | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'tests/GrMeshTest.cpp') diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp index 4d9773b1a9..f95dbc8603 100644 --- a/tests/GrMeshTest.cpp +++ b/tests/GrMeshTest.cpp @@ -294,35 +294,46 @@ private: class GrMeshTestProcessor : public GrGeometryProcessor { public: GrMeshTestProcessor(bool instanced, bool hasVertexBuffer) - : INHERITED(kGrMeshTestProcessor_ClassID) - , fInstanceLocation(nullptr) - , fVertex(nullptr) - , fColor(nullptr) { + : INHERITED(kGrMeshTestProcessor_ClassID) { if (instanced) { - fInstanceLocation = &this->addInstanceAttrib("location", kHalf2_GrVertexAttribType); + fInstanceLocation = {"location", kHalf2_GrVertexAttribType}; + fColor = {"color", kUByte4_norm_GrVertexAttribType}; + this->setInstanceAttributeCnt(2); if (hasVertexBuffer) { - fVertex = &this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType); + fVertex = {"vertex", kHalf2_GrVertexAttribType}; + this->setVertexAttributeCnt(1); } - fColor = &this->addInstanceAttrib("color", kUByte4_norm_GrVertexAttribType); } else { - fVertex = &this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType); - fColor = &this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType); + fVertex = {"vertex", kHalf2_GrVertexAttribType}; + fColor = {"color", kUByte4_norm_GrVertexAttribType}; + this->setVertexAttributeCnt(2); } } const char* name() const override { return "GrMeshTest Processor"; } void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final { - b->add32(SkToBool(fInstanceLocation)); - b->add32(SkToBool(fVertex)); + b->add32(fInstanceLocation.isInitialized()); + b->add32(fVertex.isInitialized()); } GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final; -protected: - const Attribute* fInstanceLocation; - const Attribute* fVertex; - const Attribute* fColor; +private: + const Attribute& onVertexAttribute(int i) const override { + if (fInstanceLocation.isInitialized()) { + return fVertex; + } + return IthAttribute(i, fVertex, fColor); + } + + const Attribute& onInstanceAttribute(int i) const override { + return IthAttribute(i, fInstanceLocation, fColor); + } + + Attribute fInstanceLocation; + Attribute fVertex; + Attribute fColor; friend class GLSLMeshTestProcessor; typedef GrGeometryProcessor INHERITED; @@ -340,15 +351,15 @@ class GLSLMeshTestProcessor : public GrGLSLGeometryProcessor { varyingHandler->addPassThroughAttribute(mp.fColor, args.fOutputColor); GrGLSLVertexBuilder* v = args.fVertBuilder; - if (!mp.fInstanceLocation) { - v->codeAppendf("float2 vertex = %s;", mp.fVertex->name()); + if (!mp.fInstanceLocation.isInitialized()) { + v->codeAppendf("float2 vertex = %s;", mp.fVertex.name()); } else { - if (mp.fVertex) { - v->codeAppendf("float2 offset = %s;", mp.fVertex->name()); + if (mp.fVertex.isInitialized()) { + v->codeAppendf("float2 offset = %s;", mp.fVertex.name()); } else { v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);"); } - v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation->name(), + v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation.name(), kBoxSize); } gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex"); -- cgit v1.2.3