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" |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 13 | #include "instanced/InstancedOp.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 14 | #include "instanced/InstancedRendering.h" |
| 15 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 16 | class GrGLCaps; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 17 | class GrGLGpu; |
| 18 | |
Brian Salomon | 99ad164 | 2016-12-16 09:50:45 -0500 | [diff] [blame] | 19 | #define GR_GL_LOG_INSTANCED_OPS 0 |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 20 | |
| 21 | namespace gr_instanced { |
| 22 | |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 23 | class GLOpAllocator final : public OpAllocator { |
| 24 | public: |
| 25 | GLOpAllocator(const GrCaps* caps) : INHERITED(caps) {} |
| 26 | |
| 27 | private: |
| 28 | std::unique_ptr<InstancedOp> makeOp(GrPaint&& paint) override; |
| 29 | |
| 30 | typedef OpAllocator INHERITED; |
| 31 | }; |
| 32 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 33 | class GLInstancedRendering final : public InstancedRendering { |
| 34 | public: |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 35 | GLInstancedRendering(GrGLGpu*); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 36 | ~GLInstancedRendering() override; |
| 37 | |
| 38 | private: |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Called by GrGLCaps to determine the level of support this class can offer for instanced |
| 41 | * rendering on the current platform. |
| 42 | */ |
| 43 | static GrCaps::InstancedSupport CheckSupport(const GrGLCaps&); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 44 | |
| 45 | GrGLGpu* glGpu() const; |
| 46 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 47 | void onBeginFlush(GrResourceProvider*) override; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 48 | void onDraw(const GrPipeline&, const InstanceProcessor&, const InstancedOp*) override; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 49 | void onEndFlush() override; |
| 50 | void onResetGpuResources(ResetType) override; |
| 51 | |
| 52 | void flushInstanceAttribs(int baseInstance); |
| 53 | |
| 54 | struct GLDrawCmdInfo { |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 55 | IndexRange fGeometry; |
csmartdalton | 4c18b62 | 2016-07-29 12:19:28 -0700 | [diff] [blame] | 56 | int fInstanceCount; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | GrGLuint fVertexArrayID; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 60 | sk_sp<GrBuffer> fInstanceBuffer; |
| 61 | sk_sp<GrBuffer> fDrawIndirectBuffer; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 62 | SkAutoSTMalloc<1024, GLDrawCmdInfo> fGLDrawCmdsInfo; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 63 | GrGpuResource::UniqueID fInstanceAttribsBufferUniqueId; |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 64 | int fInstanceAttribsBaseInstance; |
| 65 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 66 | friend class ::GrGLCaps; // For CheckSupport. |
| 67 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 68 | typedef InstancedRendering INHERITED; |
| 69 | }; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | #endif |