Browse Source

Don't use std::tie() on std::pair().

It's nice and all, but including the whole <tuple> just for that is not
worth it.
pull/332/head
Vladimír Vondruš 7 years ago
parent
commit
f8b9c69b16
  1. 4
      src/Magnum/Animation/Player.hpp
  2. 28
      src/Magnum/GL/CubeMapTexture.cpp
  3. 53
      src/Magnum/Math/Test/BezierTest.cpp
  4. 32
      src/Magnum/PixelStorage.h

4
src/Magnum/Animation/Player.hpp

@ -239,7 +239,9 @@ template<class T, class K> Containers::Optional<std::pair<UnsignedInt, K>> playe
iteration. If we exceeded play count, stop the animation and give out
value at duration end. */
} else {
std::tie(playIteration, key) = scaler(timeToUse, duration);
const std::pair<UnsignedInt, K> scaled = scaler(timeToUse, duration);
playIteration = scaled.first;
key = scaled.second;
if(playCount && playIteration >= playCount) {
if(state != State::Paused) state = State::Stopped;
/* Don't reset the startTime to disambiguate between explicitly

28
src/Magnum/GL/CubeMapTexture.cpp

@ -113,11 +113,11 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image)
/* If the user-provided pixel storage doesn't tell us all properties about
the compression, we need to ask GL for it */
std::size_t dataOffset, dataSize;
std::pair<std::size_t, std::size_t> dataOffsetSize;
if(!image.storage().compressedBlockSize().product() || !image.storage().compressedBlockDataSize()) {
dataOffset = 0;
dataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6;
} else std::tie(dataOffset, dataSize) = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size);
dataOffsetSize.first = 0;
dataOffsetSize.second = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6;
} else dataOffsetSize = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size);
/* Internal texture format */
GLint format;
@ -125,12 +125,12 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image)
/* Reallocate only if needed */
Containers::Array<char> data{image.release()};
if(data.size() < dataOffset + dataSize)
data = Containers::Array<char>{dataOffset + dataSize};
if(data.size() < dataOffsetSize.first + dataOffsetSize.second)
data = Containers::Array<char>{dataOffsetSize.first + dataOffsetSize.second};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
Context::current().state().renderer->applyPixelStoragePack(image.storage());
(this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffset, dataSize, data);
(this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffsetSize.first, dataOffsetSize.second, data);
image = CompressedImage3D{image.storage(), CompressedPixelFormat(format), size, std::move(data)};
}
@ -146,25 +146,25 @@ void CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D& i
/* If the user-provided pixel storage doesn't tell us all properties about
the compression, we need to ask GL for it */
std::size_t dataOffset, dataSize;
std::pair<std::size_t, std::size_t> dataOffsetSize;
if(!image.storage().compressedBlockSize().product() || !image.storage().compressedBlockDataSize()) {
dataOffset = 0;
dataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6;
} else std::tie(dataOffset, dataSize) = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size);
dataOffsetSize.first = 0;
dataOffsetSize.second = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6;
} else dataOffsetSize = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size);
/* Internal texture format */
GLint format;
(this->*Context::current().state().texture->getCubeLevelParameterivImplementation)(level, GL_TEXTURE_INTERNAL_FORMAT, &format);
/* Reallocate only if needed */
if(image.dataSize() < dataOffset + dataSize)
image.setData(image.storage(), CompressedPixelFormat(format), size, {nullptr, dataOffset + dataSize}, usage);
if(image.dataSize() < dataOffsetSize.first + dataOffsetSize.second)
image.setData(image.storage(), CompressedPixelFormat(format), size, {nullptr, dataOffsetSize.first + dataOffsetSize.second}, usage);
else
image.setData(image.storage(), CompressedPixelFormat(format), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
Context::current().state().renderer->applyPixelStoragePack(image.storage());
(this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffset, dataSize, nullptr);
(this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffsetSize.first, dataOffsetSize.second, nullptr);
}
CompressedBufferImage3D CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D&& image, const BufferUsage usage) {

53
src/Magnum/Math/Test/BezierTest.cpp

@ -272,46 +272,43 @@ void BezierTest::valueCubic() {
void BezierTest::subdivideLinear() {
LinearBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{20.0f, 4.0f}};
LinearBezier2D left, right;
std::tie(left, right) = bezier.subdivide(0.25f);
CORRADE_COMPARE(left[0], bezier[0]);
CORRADE_COMPARE(left[1], right[0]);
CORRADE_COMPARE(right[1], bezier[1]);
CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(left, (LinearBezier2D{Vector2{0.0f, 0.0f}, Vector2{5.0f, 1.0f}}));
CORRADE_COMPARE(right, (LinearBezier2D{Vector2{5.0f, 1.0f}, Vector2{20.0f, 4.0f}}));
std::pair<LinearBezier2D, LinearBezier2D> subdivided = bezier.subdivide(0.25f);
CORRADE_COMPARE(subdivided.first[0], bezier[0]);
CORRADE_COMPARE(subdivided.first[1], subdivided.second[0]);
CORRADE_COMPARE(subdivided.second[1], bezier[1]);
CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(subdivided.first, (LinearBezier2D{Vector2{0.0f, 0.0f}, Vector2{5.0f, 1.0f}}));
CORRADE_COMPARE(subdivided.second, (LinearBezier2D{Vector2{5.0f, 1.0f}, Vector2{20.0f, 4.0f}}));
}
void BezierTest::subdivideQuadratic() {
QuadraticBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{10.0f, 15.0f}, Vector2{20.0f, 4.0f}};
QuadraticBezier2D left, right;
std::tie(left, right) = bezier.subdivide(0.25f);
std::pair<QuadraticBezier2D, QuadraticBezier2D> subdivided = bezier.subdivide(0.25f);
CORRADE_COMPARE(left[0], bezier[0]);
CORRADE_COMPARE(left[2], right[0]);
CORRADE_COMPARE(right[2], bezier[2]);
CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(left, (QuadraticBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}}));
CORRADE_COMPARE(right, (QuadraticBezier2D{Vector2{5.0f, 5.875f}, Vector2{12.5f, 12.25f}, Vector2{20.0f, 4.0f}}));
CORRADE_COMPARE(subdivided.first[0], bezier[0]);
CORRADE_COMPARE(subdivided.first[2], subdivided.second[0]);
CORRADE_COMPARE(subdivided.second[2], bezier[2]);
CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(subdivided.first, (QuadraticBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}}));
CORRADE_COMPARE(subdivided.second, (QuadraticBezier2D{Vector2{5.0f, 5.875f}, Vector2{12.5f, 12.25f}, Vector2{20.0f, 4.0f}}));
}
void BezierTest::subdivideCubic() {
CubicBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{10.0f, 15.0f}, Vector2{20.0f, 4.0f}, Vector2{5.0f, -20.0f}};
CubicBezier2D left, right;
std::tie(left, right) = bezier.subdivide(0.25f);
std::pair<CubicBezier2D, CubicBezier2D> subdivided = bezier.subdivide(0.25f);
CORRADE_COMPARE(left[0], bezier[0]);
CORRADE_COMPARE(left[3], right[0]);
CORRADE_COMPARE(right[3], bezier[3]);
CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(left, (CubicBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}, Vector2{7.10938f, 6.57812f}}));
CORRADE_COMPARE(right, (CubicBezier2D{Vector2{7.10938f, 6.57812f}, Vector2{13.4375f, 8.6875f}, Vector2{16.25f, -2.0f}, Vector2{5.0f, -20.0f}}));
CORRADE_COMPARE(subdivided.first[0], bezier[0]);
CORRADE_COMPARE(subdivided.first[3], subdivided.second[0]);
CORRADE_COMPARE(subdivided.second[3], bezier[3]);
CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f));
CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f));
CORRADE_COMPARE(subdivided.first, (CubicBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}, Vector2{7.10938f, 6.57812f}}));
CORRADE_COMPARE(subdivided.second, (CubicBezier2D{Vector2{7.10938f, 6.57812f}, Vector2{13.4375f, 8.6875f}, Vector2{16.25f, -2.0f}, Vector2{5.0f, -20.0f}}));
}
void BezierTest::strictWeakOrdering() {

32
src/Magnum/PixelStorage.h

@ -248,35 +248,32 @@ constexpr PixelStorage::PixelStorage() noexcept: _rowLength{0}, _imageHeight{0},
namespace Implementation {
/* Used in *Image::dataProperties() */
template<std::size_t dimensions, class T> std::pair<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>> imageDataProperties(const T& image) {
Math::Vector3<std::size_t> offset, dataSize;
std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1));
return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(dataSize));
std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1));
return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(dataProperties.first), Math::Vector<dimensions, std::size_t>::pad(dataProperties.second));
}
/* Used in Compressed*Image::dataProperties() */
template<std::size_t dimensions, class T> std::pair<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>> compressedImageDataProperties(const T& image) {
Math::Vector3<std::size_t> offset, blockCount;
std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(image.size(), 1));
return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(blockCount));
std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties = image.storage().dataProperties(Vector3i::pad(image.size(), 1));
return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(dataProperties.first), Math::Vector<dimensions, std::size_t>::pad(dataProperties.second));
}
/* Used in image query functions */
template<std::size_t dimensions, class T> std::size_t imageDataSizeFor(const T& image, const Math::Vector<dimensions, Int>& size) {
Math::Vector3<std::size_t> offset, dataSize;
std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1));
std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1));
/* Smallest line/rectangle/cube that covers the area */
std::size_t dataOffset = 0;
if(offset.z())
dataOffset += offset.z();
else if(offset.y()) {
if(dataProperties.first.z())
dataOffset += dataProperties.first.z();
else if(dataProperties.first.y()) {
if(!image.storage().imageHeight())
dataOffset += offset.y();
} else if(offset.x()) {
dataOffset += dataProperties.first.y();
} else if(dataProperties.first.x()) {
if(!image.storage().rowLength())
dataOffset += offset.x();
dataOffset += dataProperties.first.x();
}
return dataOffset + dataSize.product();
return dataOffset + dataProperties.second.product();
}
/* Used in data size assertions */
@ -287,12 +284,11 @@ namespace Implementation {
template<std::size_t dimensions, class T> std::pair<std::size_t, std::size_t> compressedImageDataOffsetSizeFor(const T& image, const Math::Vector<dimensions, Int>& size) {
CORRADE_INTERNAL_ASSERT(image.storage().compressedBlockSize().product() && image.storage().compressedBlockDataSize());
Math::Vector3<std::size_t> offset, blockCount;
std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(size, 1));
std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties = image.storage().dataProperties(Vector3i::pad(size, 1));
const auto realBlockCount = Math::Vector3<std::size_t>{(Vector3i::pad(size, 1) + image.storage().compressedBlockSize() - Vector3i{1})/image.storage().compressedBlockSize()};
return {offset.sum(), (blockCount.product() - (blockCount.x() - realBlockCount.x()) - (blockCount.y() - realBlockCount.y())*blockCount.x())*image.storage().compressedBlockDataSize()};
return {dataProperties.first.sum(), (dataProperties.second.product() - (dataProperties.second.x() - realBlockCount.x()) - (dataProperties.second.y() - realBlockCount.y())*dataProperties.second.x())*image.storage().compressedBlockDataSize()};
}
/* Used in image query functions */

Loading…
Cancel
Save