Index: include/gpu/GrGeometryProcessor.h |
diff --git a/include/gpu/GrGeometryProcessor.h b/include/gpu/GrGeometryProcessor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b8e44bb3f1ed3000380171ccdf2892d89e041360 |
--- /dev/null |
+++ b/include/gpu/GrGeometryProcessor.h |
@@ -0,0 +1,56 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrGeometryProcessor_DEFINED |
+#define GrGeometryProcessor_DEFINED |
+ |
+#include "GrProcessor.h" |
+class GrBackendGeometryProcessorFactory; |
bsalomon
2014/09/22 14:56:38
Can this file live in src/gpu?
joshua.litt
2014/09/22 18:14:44
I will move it in a future CL, along with the fact
|
+ |
+/** |
+ * If an effect needs specialized vertex shader code, then it must inherit from this class. |
bsalomon
2014/09/22 14:56:38
How about something like:
A GrGeomteryProcessor i
|
+ * Otherwise it won't be able to add vertex attribs, and it might be given a vertexless shader |
+ * program in emitCode. |
+ */ |
+class GrGeometryProcessor : public GrProcessor { |
+public: |
+ GrGeometryProcessor() {} |
+ |
+ virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; |
+ |
+ static const int kMaxVertexAttribs = 2; |
+ typedef SkSTArray<kMaxVertexAttribs, GrShaderVar, true> VertexAttribArray; |
bsalomon
2014/09/22 14:56:38
Is it really a max of two? Why use a dynamic array
joshua.litt
2014/09/22 18:14:44
This is just because of GLProgramsTest. Eventuall
|
+ |
+ const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } |
+ |
+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. |
+ */ |
+ const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { |
+ SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); |
+ return fVertexAttribs.push_back(var); |
+ } |
+ |
+private: |
+ VertexAttribArray fVertexAttribs; |
+ |
+ typedef GrProcessor INHERITED; |
+}; |
+ |
+/** |
+ * This creates an effect outside of the effect memory pool. The effect's destructor will be called |
+ * at global destruction time. NAME will be the name of the created GrProcessor. |
+ */ |
+#define GR_CREATE_STATIC_GEOMETRY_PROCESSOR(NAME, GP_CLASS, ARGS) \ |
+static SkAlignedSStorage<sizeof(GP_CLASS)> g_##NAME##_Storage; \ |
+static GrGeometryProcessor* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), GP_CLASS, ARGS); \ |
+static SkAutoTDestroy<GrGeometryProcessor> NAME##_ad(NAME); |
+ |
+#endif |