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

Unified Diff: src/gpu/batches/GrVertexBatch.h

Issue 1296483002: Split GrDrawBatch and GrVertexBatch into their own files (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add new files to git Created 5 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/batches/GrTestBatch.h ('k') | src/gpu/batches/GrVertexBatch.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrVertexBatch.h
diff --git a/src/gpu/batches/GrVertexBatch.h b/src/gpu/batches/GrVertexBatch.h
new file mode 100644
index 0000000000000000000000000000000000000000..882cfa0c8ddda977120f02afc8e36fa0bb04e1bf
--- /dev/null
+++ b/src/gpu/batches/GrVertexBatch.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrVertexBatch_DEFINED
+#define GrVertexBatch_DEFINED
+
+#include "GrDrawBatch.h"
+#include "GrBatchTarget.h"
+
+/**
+ * Base class for vertex-based GrBatches.
+ */
+class GrVertexBatch : public GrDrawBatch {
+public:
+ GrVertexBatch();
+
+ virtual void generateGeometry(GrBatchTarget*) = 0;
+
+ // TODO this goes away when batches are everywhere
+ void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
+ int numberOfDraws() const { return fNumberOfDraws; }
+
+protected:
+ /** Helper for rendering instances using an instanced index index buffer. This class creates the
+ space for the vertices and flushes the draws to the batch target. */
+ class InstancedHelper {
+ public:
+ InstancedHelper() {}
+ /** Returns the allocated storage for the vertices. The caller should populate the before
+ vertices before calling issueDraws(). */
+ void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStride,
+ const GrIndexBuffer*, int verticesPerInstance, int indicesPerInstance,
+ int instancesToDraw);
+
+ /** Call after init() to issue draws to the batch target.*/
+ void issueDraw(GrBatchTarget* batchTarget) {
+ SkASSERT(fVertices.instanceCount());
+ batchTarget->draw(fVertices);
+ }
+ private:
+ GrVertices fVertices;
+ };
+
+ static const int kVerticesPerQuad = 4;
+ static const int kIndicesPerQuad = 6;
+
+ /** A specialization of InstanceHelper for quad rendering. */
+ class QuadHelper : private InstancedHelper {
+ public:
+ QuadHelper() : INHERITED() {}
+ /** Finds the cached quad index buffer and reserves vertex space. Returns NULL on failure
+ and on sucess a pointer to the vertex data that the caller should populate before
+ calling issueDraws(). */
+ void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw);
+
+ using InstancedHelper::issueDraw;
+
+ private:
+ typedef InstancedHelper INHERITED;
+ };
+
+private:
+ int fNumberOfDraws;
+ typedef GrDrawBatch INHERITED;
+};
+
+#endif
« no previous file with comments | « src/gpu/batches/GrTestBatch.h ('k') | src/gpu/batches/GrVertexBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698