blob: 4e17cb4535c7c9b1a509b93582dc5670199730b0 [file] [log] [blame]
csmartdaltona7f29642016-07-07 08:49:11 -07001/*
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
csmartdaltone0d36292016-07-29 08:14:20 -070011#include "GrCaps.h"
csmartdaltona7f29642016-07-07 08:49:11 -070012#include "gl/GrGLBuffer.h"
13#include "instanced/InstancedRendering.h"
14
csmartdaltone0d36292016-07-29 08:14:20 -070015class GrGLCaps;
csmartdaltona7f29642016-07-07 08:49:11 -070016class GrGLGpu;
17
18#define GR_GL_LOG_INSTANCED_BATCHES 0
19
20namespace gr_instanced {
21
22class GLInstancedRendering final : public InstancedRendering {
23public:
csmartdaltone0d36292016-07-29 08:14:20 -070024 GLInstancedRendering(GrGLGpu*);
csmartdaltona7f29642016-07-07 08:49:11 -070025 ~GLInstancedRendering() override;
26
27private:
csmartdaltone0d36292016-07-29 08:14:20 -070028 /**
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&);
csmartdaltona7f29642016-07-07 08:49:11 -070033
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;
csmartdalton485a1202016-07-13 10:16:32 -070053 SkAutoTUnref<GrBuffer> fInstanceBuffer;
54 SkAutoTUnref<GrBuffer> fDrawIndirectBuffer;
csmartdaltona7f29642016-07-07 08:49:11 -070055 SkAutoSTMalloc<1024, GLDrawCmdInfo> fGLDrawCmdsInfo;
56 uint32_t fInstanceAttribsBufferUniqueId;
57 int fInstanceAttribsBaseInstance;
58
59 class GLBatch;
60
csmartdaltone0d36292016-07-29 08:14:20 -070061 friend class ::GrGLCaps; // For CheckSupport.
62
csmartdaltona7f29642016-07-07 08:49:11 -070063 typedef InstancedRendering INHERITED;
64};
65
66}
67
68#endif