1//
2// Copyright 2013 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// IndexRangeCache.h: Defines the gl::IndexRangeCache class which stores information about
8// ranges of indices.
9
10#ifndef LIBANGLE_INDEXRANGECACHE_H_
11#define LIBANGLE_INDEXRANGECACHE_H_
12
13#include "angle_gl.h"
14#include "common/PackedEnums.h"
15#include "common/angleutils.h"
16#include "common/mathutil.h"
17
18#include <map>
19
20namespace gl
21{
22
23class IndexRangeCache
24{
25  public:
26    IndexRangeCache();
27    ~IndexRangeCache();
28
29    void addRange(DrawElementsType type,
30                  size_t offset,
31                  size_t count,
32                  bool primitiveRestartEnabled,
33                  const IndexRange &range);
34    bool findRange(DrawElementsType type,
35                   size_t offset,
36                   size_t count,
37                   bool primitiveRestartEnabled,
38                   IndexRange *outRange) const;
39
40    void invalidateRange(size_t offset, size_t size);
41    void clear();
42
43  private:
44    struct IndexRangeKey
45    {
46        IndexRangeKey();
47        IndexRangeKey(DrawElementsType type, size_t offset, size_t count, bool primitiveRestart);
48
49        bool operator<(const IndexRangeKey &rhs) const;
50
51        DrawElementsType type;
52        size_t offset;
53        size_t count;
54        bool primitiveRestartEnabled;
55    };
56
57    typedef std::map<IndexRangeKey, IndexRange> IndexRangeMap;
58    IndexRangeMap mIndexRangeCache;
59};
60
61}  // namespace gl
62
63#endif  // LIBANGLE_INDEXRANGECACHE_H_
64