diff options
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp')
-rw-r--r-- | src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp index e957d96270..f68ac383de 100644 --- a/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp +++ b/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp @@ -1,4 +1,3 @@ -#include "precompiled.h" // // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -10,16 +9,49 @@ #include "libGLESv2/renderer/IndexRangeCache.h" #include "libGLESv2/formatutils.h" + #include "common/debug.h" + #include <tuple> namespace rx { -void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx, +template <class IndexType> +static RangeUI ComputeTypedRange(const IndexType *indices, GLsizei count) +{ + unsigned int minIndex = indices[0]; + unsigned int maxIndex = indices[0]; + + for (GLsizei i = 1; i < count; i++) + { + if (minIndex > indices[i]) minIndex = indices[i]; + if (maxIndex < indices[i]) maxIndex = indices[i]; + } + + return RangeUI(minIndex, maxIndex); +} + +RangeUI IndexRangeCache::ComputeRange(GLenum type, const GLvoid *indices, GLsizei count) +{ + switch (type) + { + case GL_UNSIGNED_BYTE: + return ComputeTypedRange(static_cast<const GLubyte*>(indices), count); + case GL_UNSIGNED_INT: + return ComputeTypedRange(static_cast<const GLuint*>(indices), count); + case GL_UNSIGNED_SHORT: + return ComputeTypedRange(static_cast<const GLushort*>(indices), count); + default: + UNREACHABLE(); + return RangeUI(); + } +} + +void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, const RangeUI &range, unsigned int streamOffset) { - mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset); + mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(range, streamOffset); } void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) @@ -31,7 +63,7 @@ void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) while (i != mIndexRangeCache.end()) { unsigned int rangeStart = i->second.streamOffset; - unsigned int rangeEnd = i->second.streamOffset + (gl::GetTypeBytes(i->first.type) * i->first.count); + unsigned int rangeEnd = i->second.streamOffset + (gl::GetTypeInfo(i->first.type).bytes * i->first.count); if (invalidateEnd < rangeStart || invalidateStart > rangeEnd) { @@ -44,21 +76,19 @@ void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size) } } -bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex, - unsigned int *outMaxIndex, unsigned int *outStreamOffset) const +bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, + RangeUI *outRange, unsigned int *outStreamOffset) const { IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count)); if (i != mIndexRangeCache.end()) { - if (outMinIndex) *outMinIndex = i->second.minIndex; - if (outMaxIndex) *outMaxIndex = i->second.maxIndex; + if (outRange) *outRange = i->second.range; if (outStreamOffset) *outStreamOffset = i->second.streamOffset; return true; } else { - if (outMinIndex) *outMinIndex = 0; - if (outMaxIndex) *outMaxIndex = 0; + if (outRange) *outRange = RangeUI(0, 0); if (outStreamOffset) *outStreamOffset = 0; return false; } @@ -89,12 +119,13 @@ bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const } IndexRangeCache::IndexBounds::IndexBounds() - : minIndex(0), maxIndex(0), streamOffset(0) + : range(0, 0), + streamOffset(0) { } -IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset) - : minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset) +IndexRangeCache::IndexBounds::IndexBounds(const RangeUI &rangeIn, unsigned int offset) + : range(rangeIn), streamOffset(offset) { } |