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_GLInstancedRendering_DEFINED 9 #define gr_instanced_GLInstancedRendering_DEFINED 10 11 #include "GrCaps.h" 12 #include "gl/GrGLBuffer.h" 13 #include "instanced/InstancedRendering.h" 14 15 class GrGLCaps; 16 class GrGLGpu; 17 18 #define GR_GL_LOG_INSTANCED_OPS 0 19 20 namespace gr_instanced { 21 22 class GLInstancedRendering final : public InstancedRendering { 23 public: 24 GLInstancedRendering(GrGLGpu*); 25 ~GLInstancedRendering() override; 26 27 private: 28 /** 29 * Called by GrGLCaps to determine the level of support this class can offer for instanced 30 * rendering on the current platform. 31 */ 32 static GrCaps::InstancedSupport CheckSupport(const GrGLCaps&); 33 34 GrGLGpu* glGpu() const; 35 36 std::unique_ptr<Op> makeOp(GrPaint&& paint) override; 37 38 void onBeginFlush(GrResourceProvider*) override; 39 void onDraw(const GrPipeline&, const InstanceProcessor&, const Op*) override; 40 void onEndFlush() override; 41 void onResetGpuResources(ResetType) override; 42 43 void flushInstanceAttribs(int baseInstance); 44 45 struct GLDrawCmdInfo { 46 IndexRange fGeometry; 47 int fInstanceCount; 48 }; 49 50 GrGLuint fVertexArrayID; 51 sk_sp<GrBuffer> fInstanceBuffer; 52 sk_sp<GrBuffer> fDrawIndirectBuffer; 53 SkAutoSTMalloc<1024, GLDrawCmdInfo> fGLDrawCmdsInfo; 54 GrGpuResource::UniqueID fInstanceAttribsBufferUniqueId; 55 int fInstanceAttribsBaseInstance; 56 57 class GLOp; 58 59 friend class ::GrGLCaps; // For CheckSupport. 60 61 typedef InstancedRendering INHERITED; 62 }; 63 64 } 65 66 #endif 67