Simplify formatutils.h by exposing the info structures.
Removed all the separate query functions and simply expose the internal
info structures. This reduces the number of std::map/std::set operations
that were hidden behind the API.
Moved the validation tables for ES3 format combinations and effective
internal formats into validationES3.cpp so that formatutils.h only has
generic GL format queries.
BUG=angle:658
Change-Id: Ieb60d42b8eafcdb4f21dcbec130b39478ce5f7c5
Reviewed-on: https://chromium-review.googlesource.com/206835
Reviewed-by: Nicolas Capens <capn@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
index d6de3bf..98716c1 100644
--- a/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
+++ b/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
@@ -131,7 +131,10 @@
return GL_OUT_OF_MEMORY;
}
+ const gl::Type &typeInfo = gl::GetTypeInfo(type);
+
GLenum destinationIndexType = (type == GL_UNSIGNED_INT) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT;
+
unsigned int offset = 0;
bool alignedOffset = false;
@@ -155,16 +158,14 @@
default: UNREACHABLE(); alignedOffset = false;
}
- unsigned int typeSize = gl::GetTypeBytes(type);
-
// check for integer overflows
- if (static_cast<unsigned int>(count) > (std::numeric_limits<unsigned int>::max() / typeSize) ||
- typeSize * static_cast<unsigned int>(count) + offset < offset)
+ if (static_cast<unsigned int>(count) > (std::numeric_limits<unsigned int>::max() / typeInfo.bytes) ||
+ typeInfo.bytes * static_cast<unsigned int>(count) + offset < offset)
{
return GL_OUT_OF_MEMORY;
}
- if (typeSize * static_cast<unsigned int>(count) + offset > storage->getSize())
+ if (typeInfo.bytes * static_cast<unsigned int>(count) + offset > storage->getSize())
{
return GL_INVALID_OPERATION;
}
@@ -197,7 +198,7 @@
if (!staticBuffer->getIndexRangeCache()->findRange(type, offset, count, &translated->minIndex,
&translated->maxIndex, &streamOffset))
{
- streamOffset = (offset / gl::GetTypeBytes(type)) * gl::GetTypeBytes(destinationIndexType);
+ streamOffset = (offset / typeInfo.bytes) * gl::GetTypeInfo(destinationIndexType).bytes;
computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex,
translated->maxIndex, streamOffset);
@@ -217,6 +218,8 @@
indexBuffer = NULL;
}
+ const gl::Type &destTypeInfo = gl::GetTypeInfo(destinationIndexType);
+
if (!directStorage && !indexBuffer)
{
indexBuffer = (destinationIndexType == GL_UNSIGNED_INT) ? mStreamingBufferInt : mStreamingBufferShort;
@@ -228,7 +231,7 @@
if (staticBuffer->getBufferSize() == 0 && alignedOffset)
{
indexBuffer = staticBuffer;
- convertCount = storage->getSize() / gl::GetTypeBytes(type);
+ convertCount = storage->getSize() / typeInfo.bytes;
}
else
{
@@ -243,14 +246,13 @@
return GL_INVALID_OPERATION;
}
- unsigned int indexTypeSize = gl::GetTypeBytes(destinationIndexType);
- if (convertCount > std::numeric_limits<unsigned int>::max() / indexTypeSize)
+ if (convertCount > std::numeric_limits<unsigned int>::max() / destTypeInfo.bytes)
{
- ERR("Reserving %u indicies of %u bytes each exceeds the maximum buffer size.", convertCount, indexTypeSize);
+ ERR("Reserving %u indicies of %u bytes each exceeds the maximum buffer size.", convertCount, destTypeInfo.bytes);
return GL_OUT_OF_MEMORY;
}
- unsigned int bufferSizeRequired = convertCount * indexTypeSize;
+ unsigned int bufferSizeRequired = convertCount * destTypeInfo.bytes;
if (!indexBuffer->reserveBufferSpace(bufferSizeRequired, type))
{
ERR("Failed to reserve %u bytes in an index buffer.", bufferSizeRequired);
@@ -274,7 +276,7 @@
if (staticBuffer)
{
- streamOffset = (offset / gl::GetTypeBytes(type)) * gl::GetTypeBytes(destinationIndexType);
+ streamOffset = (offset / typeInfo.bytes) * destTypeInfo.bytes;
staticBuffer->getIndexRangeCache()->addRange(type, offset, count, translated->minIndex,
translated->maxIndex, streamOffset);
}
@@ -283,13 +285,13 @@
translated->storage = directStorage ? storage : NULL;
translated->indexBuffer = indexBuffer ? indexBuffer->getIndexBuffer() : NULL;
translated->serial = directStorage ? storage->getSerial() : indexBuffer->getSerial();
- translated->startIndex = streamOffset / gl::GetTypeBytes(destinationIndexType);
+ translated->startIndex = streamOffset / destTypeInfo.bytes;
translated->startOffset = streamOffset;
translated->indexType = destinationIndexType;
if (storage)
{
- storage->promoteStaticUsage(count * gl::GetTypeBytes(type));
+ storage->promoteStaticUsage(count * typeInfo.bytes);
}
return GL_NO_ERROR;