aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/instanced/InstanceProcessor.h
blob: 84d75a9f732cfea3a066337aebd5e750075fe8e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef gr_instanced_InstanceProcessor_DEFINED
#define gr_instanced_InstanceProcessor_DEFINED

#include "GrCaps.h"
#include "GrGeometryProcessor.h"
#include "instanced/InstancedRenderingTypes.h"

namespace gr_instanced {

/**
 * This class provides a GP implementation that uses instanced rendering. Is sends geometry in as
 * basic, pre-baked canonical shapes, and uses instanced vertex attribs to control how these shapes
 * are transformed and drawn. MSAA is accomplished with the sample mask rather than finely
 * tesselated geometry.
 */
class InstanceProcessor : public GrGeometryProcessor {
public:
    InstanceProcessor(OpInfo, GrBuffer* paramsBuffer);

    const char* name() const override { return "Instance Processor"; }
    OpInfo opInfo() const { return fOpInfo; }

    void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
        b->add32(fOpInfo.fData);
    }
    GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;

    /**
     * Returns a buffer of ShapeVertex that defines the canonical instanced geometry.
     */
    static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateVertexBuffer(GrGpu*);

    /**
     * Returns a buffer of 8-bit indices for the canonical instanced geometry. The client can call
     * GetIndexRangeForXXX to know which indices to use for a specific shape.
     */
    static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateIndex8Buffer(GrGpu*);

    static IndexRange GetIndexRangeForRect(GrAAType);
    static IndexRange GetIndexRangeForOval(GrAAType, const SkRect& devBounds);
    static IndexRange GetIndexRangeForRRect(GrAAType);

    static const char* GetNameOfIndexRange(IndexRange);

private:
    /**
     * Called by the platform-specific instanced rendering implementation to determine the level of
     * support this class can offer on the given GLSL platform.
     */
    static GrCaps::InstancedSupport CheckSupport(const GrShaderCaps&, const GrCaps&);

    const OpInfo fOpInfo;
    BufferAccess fParamsAccess;

    friend class GLInstancedRendering; // For CheckSupport.

    typedef GrGeometryProcessor INHERITED;
};

}

#endif