1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef gr_instanced_InstanceProcessor_DEFINED 9 #define gr_instanced_InstanceProcessor_DEFINED 10 11 #include "GrCaps.h" 12 #include "GrBufferAccess.h" 13 #include "GrGeometryProcessor.h" 14 #include "instanced/InstancedRenderingTypes.h" 15 16 namespace gr_instanced { 17 18 /** 19 * This class provides a GP implementation that uses instanced rendering. Is sends geometry in as 20 * basic, pre-baked canonical shapes, and uses instanced vertex attribs to control how these shapes 21 * are transformed and drawn. MSAA is accomplished with the sample mask rather than finely 22 * tesselated geometry. 23 */ 24 class InstanceProcessor : public GrGeometryProcessor { 25 public: 26 InstanceProcessor(BatchInfo, GrBuffer* paramsBuffer); 27 name()28 const char* name() const override { return "Instance Processor"; } batchInfo()29 BatchInfo batchInfo() const { return fBatchInfo; } 30 getGLSLProcessorKey(const GrGLSLCaps &,GrProcessorKeyBuilder * b)31 void getGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder* b) const override { 32 b->add32(fBatchInfo.fData); 33 } 34 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override; 35 36 /** 37 * Returns a buffer of ShapeVertex that defines the canonical instanced geometry. 38 */ 39 static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateVertexBuffer(GrGpu*); 40 41 /** 42 * Returns a buffer of 8-bit indices for the canonical instanced geometry. The client can call 43 * GetIndexRangeForXXX to know which indices to use for a specific shape. 44 */ 45 static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateIndex8Buffer(GrGpu*); 46 47 static IndexRange GetIndexRangeForRect(AntialiasMode); 48 static IndexRange GetIndexRangeForOval(AntialiasMode, const SkRect& devBounds); 49 static IndexRange GetIndexRangeForRRect(AntialiasMode); 50 51 static const char* GetNameOfIndexRange(IndexRange); 52 53 private: 54 /** 55 * Called by the platform-specific instanced rendering implementation to determine the level of 56 * support this class can offer on the given GLSL platform. 57 */ 58 static GrCaps::InstancedSupport CheckSupport(const GrGLSLCaps&, const GrCaps&); 59 60 const BatchInfo fBatchInfo; 61 GrBufferAccess fParamsAccess; 62 63 friend class GLInstancedRendering; // For CheckSupport. 64 65 typedef GrGeometryProcessor INHERITED; 66 }; 67 68 } 69 70 #endif 71