blob: 4db2c56b240f07b17954e1a5d4b286c79750b254 [file] [log] [blame]
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -07001/*
2* Copyright (C) 2016 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17// This is almost literally
18// external/angle/src/common/mathutil.h: IndexRange +
19// external/angle/src/libANGLE/IndexRangeCache.h: IndexRangeCache,
20// with adaptations to work with goldfish opengl driver.
21// Currently, primitive restart is not supported, so there
22// is a very minimal incorporation of that.
23
24#ifndef _GL_INDEX_RANGE_CACHE_H_
25#define _GL_INDEX_RANGE_CACHE_H_
26
27#include <GLES/gl.h>
28#include <GLES/glext.h>
29#include <GLES2/gl2.h>
30#include <GLES2/gl2ext.h>
31
32#include "glUtils.h"
33
34#include <map>
35
36struct IndexRange {
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070037 // Inclusive range of indices that are not primitive restart
38 int start;
39 int end;
40
41 // Number of non-primitive restart indices
42 size_t vertexIndexCount; // TODO; not being accounted yet (GLES3 feature)
43};
44
45class IndexRangeCache {
46public:
47 void addRange(GLenum type,
48 size_t offset,
49 size_t count,
50 bool primitiveRestartEnabled,
51 int start,
52 int end);
53 bool findRange(GLenum type,
54 size_t offset,
55 size_t count,
56 bool primitiveRestartEnabled,
57 int* start_out,
58 int* end_out) const;
59 void invalidateRange(size_t offset, size_t size);
60 void clear();
61private:
62 struct IndexRangeKey {
63 IndexRangeKey() :
64 type(GL_NONE),
65 offset(0),
66 count(0),
67 primitiveRestartEnabled(false) { }
68 IndexRangeKey(GLenum _type,
69 size_t _offset,
70 size_t _count,
71 bool _primitiveRestart) :
72 type(_type),
73 offset(_offset),
74 count(_count),
75 primitiveRestartEnabled(_primitiveRestart) { }
76
77 bool operator<(const IndexRangeKey& rhs) const {
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070078 size_t end = offset + count * glSizeof(type);
Yahan Zhou0f3971d2018-11-28 12:00:13 -080079 size_t end_other = rhs.offset + rhs.count * glSizeof(rhs.type);
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070080
Yahan Zhou0f3971d2018-11-28 12:00:13 -080081 if (offset != rhs.offset) return offset < rhs.offset;
82 if (end != end_other) return end < end_other;
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070083 if (type != rhs.type) return type < rhs.type;
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070084 if (primitiveRestartEnabled != rhs.primitiveRestartEnabled)
85 return primitiveRestartEnabled;
86 return false;
87 }
88
89 GLenum type;
90 size_t offset;
91 size_t count;
92 bool primitiveRestartEnabled;
93 };
94
95 typedef std::map<IndexRangeKey, IndexRange> IndexRangeMap;
96 IndexRangeMap mIndexRangeCache;
97};
98
99#endif