blob: d68bc86cde477cc2e3dd94f2cc76a99bc33f53c4 [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"
Robert Phillipse3302df2017-04-24 07:31:02 -040013#include "instanced/InstancedOp.h"
csmartdaltona7f29642016-07-07 08:49:11 -070014#include "instanced/InstancedRendering.h"
15
csmartdaltone0d36292016-07-29 08:14:20 -070016class GrGLCaps;
csmartdaltona7f29642016-07-07 08:49:11 -070017class GrGLGpu;
18
Brian Salomon99ad1642016-12-16 09:50:45 -050019#define GR_GL_LOG_INSTANCED_OPS 0
csmartdaltona7f29642016-07-07 08:49:11 -070020
21namespace gr_instanced {
22
Robert Phillipse3302df2017-04-24 07:31:02 -040023class GLOpAllocator final : public OpAllocator {
24public:
25 GLOpAllocator(const GrCaps* caps) : INHERITED(caps) {}
26
27private:
28 std::unique_ptr<InstancedOp> makeOp(GrPaint&& paint) override;
29
30 typedef OpAllocator INHERITED;
31};
32
csmartdaltona7f29642016-07-07 08:49:11 -070033class GLInstancedRendering final : public InstancedRendering {
34public:
csmartdaltone0d36292016-07-29 08:14:20 -070035 GLInstancedRendering(GrGLGpu*);
csmartdaltona7f29642016-07-07 08:49:11 -070036 ~GLInstancedRendering() override;
37
38private:
csmartdaltone0d36292016-07-29 08:14:20 -070039 /**
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&);
csmartdaltona7f29642016-07-07 08:49:11 -070044
45 GrGLGpu* glGpu() const;
46
csmartdaltona7f29642016-07-07 08:49:11 -070047 void onBeginFlush(GrResourceProvider*) override;
Robert Phillipse3302df2017-04-24 07:31:02 -040048 void onDraw(const GrPipeline&, const InstanceProcessor&, const InstancedOp*) override;
csmartdaltona7f29642016-07-07 08:49:11 -070049 void onEndFlush() override;
50 void onResetGpuResources(ResetType) override;
51
52 void flushInstanceAttribs(int baseInstance);
53
54 struct GLDrawCmdInfo {
csmartdaltona7f29642016-07-07 08:49:11 -070055 IndexRange fGeometry;
csmartdalton4c18b622016-07-29 12:19:28 -070056 int fInstanceCount;
csmartdaltona7f29642016-07-07 08:49:11 -070057 };
58
59 GrGLuint fVertexArrayID;
Hal Canary144caf52016-11-07 17:57:18 -050060 sk_sp<GrBuffer> fInstanceBuffer;
61 sk_sp<GrBuffer> fDrawIndirectBuffer;
csmartdaltona7f29642016-07-07 08:49:11 -070062 SkAutoSTMalloc<1024, GLDrawCmdInfo> fGLDrawCmdsInfo;
Robert Phillips294870f2016-11-11 12:38:40 -050063 GrGpuResource::UniqueID fInstanceAttribsBufferUniqueId;
csmartdaltona7f29642016-07-07 08:49:11 -070064 int fInstanceAttribsBaseInstance;
65
csmartdaltone0d36292016-07-29 08:14:20 -070066 friend class ::GrGLCaps; // For CheckSupport.
67
csmartdaltona7f29642016-07-07 08:49:11 -070068 typedef InstancedRendering INHERITED;
69};
70
71}
72
73#endif