csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 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 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame^] | 11 | #include "GrCaps.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 12 | #include "gl/GrGLBuffer.h" |
| 13 | #include "instanced/InstancedRendering.h" |
| 14 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame^] | 15 | class GrGLCaps; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 16 | class GrGLGpu; |
| 17 | |
| 18 | #define GR_GL_LOG_INSTANCED_BATCHES 0 |
| 19 | |
| 20 | namespace gr_instanced { |
| 21 | |
| 22 | class GLInstancedRendering final : public InstancedRendering { |
| 23 | public: |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame^] | 24 | GLInstancedRendering(GrGLGpu*); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 25 | ~GLInstancedRendering() override; |
| 26 | |
| 27 | private: |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame^] | 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&); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 33 | |
| 34 | GrGLGpu* glGpu() const; |
| 35 | |
| 36 | Batch* createBatch() override; |
| 37 | |
| 38 | void onBeginFlush(GrResourceProvider*) override; |
| 39 | void onDraw(const GrPipeline&, const InstanceProcessor&, const Batch*) override; |
| 40 | void onEndFlush() override; |
| 41 | void onResetGpuResources(ResetType) override; |
| 42 | |
| 43 | void flushInstanceAttribs(int baseInstance); |
| 44 | |
| 45 | struct GLDrawCmdInfo { |
| 46 | int fInstanceCount; |
| 47 | #if GR_GL_LOG_INSTANCED_BATCHES |
| 48 | IndexRange fGeometry; |
| 49 | #endif |
| 50 | }; |
| 51 | |
| 52 | GrGLuint fVertexArrayID; |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 53 | SkAutoTUnref<GrBuffer> fInstanceBuffer; |
| 54 | SkAutoTUnref<GrBuffer> fDrawIndirectBuffer; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 55 | SkAutoSTMalloc<1024, GLDrawCmdInfo> fGLDrawCmdsInfo; |
| 56 | uint32_t fInstanceAttribsBufferUniqueId; |
| 57 | int fInstanceAttribsBaseInstance; |
| 58 | |
| 59 | class GLBatch; |
| 60 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame^] | 61 | friend class ::GrGLCaps; // For CheckSupport. |
| 62 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 63 | typedef InstancedRendering INHERITED; |
| 64 | }; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif |