• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/InstancedOp.h"
14 #include "instanced/InstancedRendering.h"
15 
16 class GrGLCaps;
17 class GrGLGpu;
18 
19 #define GR_GL_LOG_INSTANCED_OPS 0
20 
21 namespace gr_instanced {
22 
23 class GLOpAllocator final : public OpAllocator {
24 public:
GLOpAllocator(const GrCaps * caps)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 
33 class GLInstancedRendering final : public InstancedRendering {
34 public:
35     GLInstancedRendering(GrGLGpu*);
36     ~GLInstancedRendering() override;
37 
38 private:
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&);
44 
45     GrGLGpu* glGpu() const;
46 
47     void onBeginFlush(GrResourceProvider*) override;
48     void onDraw(const GrPipeline&, const InstanceProcessor&, const InstancedOp*) override;
49     void onEndFlush() override;
50     void onResetGpuResources(ResetType) override;
51 
52     void flushInstanceAttribs(int baseInstance);
53 
54     struct GLDrawCmdInfo {
55         IndexRange fGeometry;
56         int fInstanceCount;
57     };
58 
59     GrGLuint                              fVertexArrayID;
60     sk_sp<GrBuffer>                       fInstanceBuffer;
61     sk_sp<GrBuffer>                       fDrawIndirectBuffer;
62     SkAutoSTMalloc<1024, GLDrawCmdInfo>   fGLDrawCmdsInfo;
63     GrGpuResource::UniqueID               fInstanceAttribsBufferUniqueId;
64     int                                   fInstanceAttribsBaseInstance;
65 
66     friend class ::GrGLCaps; // For CheckSupport.
67 
68     typedef InstancedRendering INHERITED;
69 };
70 
71 }
72 
73 #endif
74