Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 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.cpp: Defines the gl::IndexRangeCache class which stores information about |
| 8 | // ranges of indices. |
| 9 | |
| 10 | #include "libANGLE/IndexRangeCache.h" |
| 11 | |
| 12 | #include "common/debug.h" |
| 13 | #include "libANGLE/formatutils.h" |
| 14 | |
| 15 | namespace gl |
| 16 | { |
| 17 | |
| 18 | void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, const RangeUI &range) |
| 19 | { |
| 20 | mIndexRangeCache[IndexRange(type, offset, count)] = range; |
| 21 | } |
| 22 | |
| 23 | void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) |
| 24 | { |
| 25 | unsigned int invalidateStart = offset; |
| 26 | unsigned int invalidateEnd = offset + size; |
| 27 | |
| 28 | IndexRangeMap::iterator i = mIndexRangeCache.begin(); |
| 29 | while (i != mIndexRangeCache.end()) |
| 30 | { |
| 31 | unsigned int rangeStart = i->first.offset; |
| 32 | unsigned int rangeEnd = i->first.offset + (GetTypeInfo(i->first.type).bytes * i->first.count); |
| 33 | |
| 34 | if (invalidateEnd < rangeStart || invalidateStart > rangeEnd) |
| 35 | { |
| 36 | ++i; |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | mIndexRangeCache.erase(i++); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, |
| 46 | RangeUI *outRange) const |
| 47 | { |
| 48 | IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count)); |
| 49 | if (i != mIndexRangeCache.end()) |
| 50 | { |
| 51 | if (outRange) |
| 52 | { |
| 53 | *outRange = i->second; |
| 54 | } |
| 55 | return true; |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | if (outRange) |
| 60 | { |
| 61 | *outRange = RangeUI(0, 0); |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void IndexRangeCache::clear() |
| 68 | { |
| 69 | mIndexRangeCache.clear(); |
| 70 | } |
| 71 | |
| 72 | IndexRangeCache::IndexRange::IndexRange() |
| 73 | : IndexRangeCache::IndexRange(GL_NONE, 0, 0) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | IndexRangeCache::IndexRange::IndexRange(GLenum typ, intptr_t off, GLsizei c) |
| 78 | : type(typ), |
| 79 | offset(static_cast<unsigned int>(off)), |
| 80 | count(c) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const |
| 85 | { |
| 86 | if (type != rhs.type) return type < rhs.type; |
| 87 | if (offset != rhs.offset) return offset < rhs.offset; |
| 88 | return count < rhs.count; |
| 89 | } |
| 90 | |
| 91 | } |