mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
12 KiB
363 lines
12 KiB
|
13 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
12 years ago
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
13 years ago
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
*/
|
||
|
|
|
||
|
9 years ago
|
#include <Corrade/Containers/Array.h>
|
||
|
12 years ago
|
#include <Corrade/TestSuite/Compare/Container.h>
|
||
|
13 years ago
|
|
||
|
12 years ago
|
#include "Magnum/BufferImage.h"
|
||
|
11 years ago
|
#include "Magnum/PixelFormat.h"
|
||
|
9 years ago
|
#include "Magnum/OpenGLTester.h"
|
||
|
13 years ago
|
|
||
|
|
namespace Magnum { namespace Test {
|
||
|
|
|
||
|
9 years ago
|
struct BufferImageGLTest: OpenGLTester {
|
||
|
11 years ago
|
explicit BufferImageGLTest();
|
||
|
13 years ago
|
|
||
|
11 years ago
|
void construct();
|
||
|
11 years ago
|
void constructCompressed();
|
||
|
9 years ago
|
void constructBuffer();
|
||
|
|
void constructBufferCompressed();
|
||
|
11 years ago
|
void constructCopy();
|
||
|
11 years ago
|
void constructCopyCompressed();
|
||
|
11 years ago
|
void constructMove();
|
||
|
11 years ago
|
void constructMoveCompressed();
|
||
|
13 years ago
|
|
||
|
11 years ago
|
void setData();
|
||
|
11 years ago
|
void setDataCompressed();
|
||
|
9 years ago
|
|
||
|
|
void release();
|
||
|
|
void releaseCompressed();
|
||
|
13 years ago
|
};
|
||
|
|
|
||
|
11 years ago
|
BufferImageGLTest::BufferImageGLTest() {
|
||
|
|
addTests({&BufferImageGLTest::construct,
|
||
|
11 years ago
|
&BufferImageGLTest::constructCompressed,
|
||
|
9 years ago
|
&BufferImageGLTest::constructBuffer,
|
||
|
|
&BufferImageGLTest::constructBufferCompressed,
|
||
|
11 years ago
|
&BufferImageGLTest::constructCopy,
|
||
|
11 years ago
|
&BufferImageGLTest::constructCopyCompressed,
|
||
|
11 years ago
|
&BufferImageGLTest::constructMove,
|
||
|
11 years ago
|
&BufferImageGLTest::constructMoveCompressed,
|
||
|
13 years ago
|
|
||
|
11 years ago
|
&BufferImageGLTest::setData,
|
||
|
9 years ago
|
&BufferImageGLTest::setDataCompressed,
|
||
|
|
|
||
|
|
&BufferImageGLTest::release,
|
||
|
|
&BufferImageGLTest::releaseCompressed});
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::construct() {
|
||
|
11 years ago
|
const char data[] = { 'a', 'b', 'c' };
|
||
|
11 years ago
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
||
|
|
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, data, BufferUsage::StaticDraw};
|
||
|
13 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
11 years ago
|
const auto imageData = a.buffer().data();
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
11 years ago
|
CORRADE_COMPARE(a.storage().alignment(), 1);
|
||
|
11 years ago
|
CORRADE_COMPARE(a.format(), PixelFormat::Red);
|
||
|
|
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
|
||
|
13 years ago
|
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
|
||
|
13 years ago
|
|
||
|
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
||
|
|
TestSuite::Compare::Container);
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::constructCompressed() {
|
||
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
||
|
11 years ago
|
CompressedBufferImage2D a{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
||
|
|
#endif
|
||
|
|
CompressedPixelFormat::RGBAS3tcDxt1,
|
||
|
|
{4, 4}, data, BufferUsage::StaticDraw};
|
||
|
11 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
const auto imageData = a.buffer().data();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(a.storage().compressedBlockSize(), Vector3i{4});
|
||
|
|
#endif
|
||
|
11 years ago
|
CORRADE_COMPARE(a.format(), CompressedPixelFormat::RGBAS3tcDxt1);
|
||
|
11 years ago
|
CORRADE_COMPARE(a.size(), Vector2i(4, 4));
|
||
|
|
CORRADE_COMPARE(a.dataSize(), 8);
|
||
|
|
|
||
|
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
||
|
|
TestSuite::Compare::Container);
|
||
|
11 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
9 years ago
|
void BufferImageGLTest::constructBuffer() {
|
||
|
|
const char data[] = { 'a', 'b', 'c' };
|
||
|
|
Buffer buffer;
|
||
|
|
buffer.setData(data, BufferUsage::StaticDraw);
|
||
|
|
const UnsignedInt id = buffer.id();
|
||
|
|
|
||
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
||
|
|
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, std::move(buffer), sizeof(data)};
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
const auto imageData = a.buffer().data();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
|
CORRADE_VERIFY(!buffer.id());
|
||
|
|
CORRADE_COMPARE(a.buffer().id(), id);
|
||
|
|
CORRADE_COMPARE(a.storage().alignment(), 1);
|
||
|
|
CORRADE_COMPARE(a.format(), PixelFormat::Red);
|
||
|
|
CORRADE_COMPARE(a.type(), PixelType::UnsignedByte);
|
||
|
|
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
|
||
|
|
|
||
|
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
||
|
|
TestSuite::Compare::Container);
|
||
|
9 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void BufferImageGLTest::constructBufferCompressed() {
|
||
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
||
|
|
Buffer buffer;
|
||
|
|
buffer.setData(data, BufferUsage::StaticDraw);
|
||
|
|
const UnsignedInt id = buffer.id();
|
||
|
|
|
||
|
|
CompressedBufferImage2D a{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
||
|
|
#endif
|
||
|
|
CompressedPixelFormat::RGBAS3tcDxt1,
|
||
|
|
{4, 4}, std::move(buffer), sizeof(data)};
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
const auto imageData = a.buffer().data();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(a.storage().compressedBlockSize(), Vector3i{4});
|
||
|
|
#endif
|
||
|
|
CORRADE_VERIFY(!buffer.id());
|
||
|
|
CORRADE_COMPARE(a.buffer().id(), id);
|
||
|
|
CORRADE_COMPARE(a.format(), CompressedPixelFormat::RGBAS3tcDxt1);
|
||
|
|
CORRADE_COMPARE(a.size(), Vector2i(4, 4));
|
||
|
|
CORRADE_COMPARE(a.dataSize(), 8);
|
||
|
|
|
||
|
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
||
|
|
TestSuite::Compare::Container);
|
||
|
9 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::constructCopy() {
|
||
|
13 years ago
|
CORRADE_VERIFY(!(std::is_constructible<BufferImage2D, const BufferImage2D&>{}));
|
||
|
|
CORRADE_VERIFY(!(std::is_assignable<BufferImage2D, const BufferImage2D&>{}));
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::constructCopyCompressed() {
|
||
|
|
CORRADE_VERIFY(!(std::is_constructible<CompressedBufferImage2D, const CompressedBufferImage2D&>{}));
|
||
|
|
CORRADE_VERIFY(!(std::is_assignable<CompressedBufferImage2D, const CompressedBufferImage2D&>{}));
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::constructMove() {
|
||
|
11 years ago
|
const char data[4] = { 'a', 'b', 'c', 'd' };
|
||
|
11 years ago
|
BufferImage2D a{PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};
|
||
|
13 years ago
|
const Int id = a.buffer().id();
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
CORRADE_VERIFY(id > 0);
|
||
|
|
|
||
|
|
BufferImage2D b(std::move(a));
|
||
|
|
|
||
|
|
CORRADE_COMPARE(a.buffer().id(), 0);
|
||
|
|
CORRADE_COMPARE(a.size(), Vector2i());
|
||
|
|
|
||
|
11 years ago
|
CORRADE_COMPARE(b.storage().alignment(), 4);
|
||
|
11 years ago
|
CORRADE_COMPARE(b.format(), PixelFormat::Red);
|
||
|
|
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
|
||
|
12 years ago
|
CORRADE_COMPARE(b.size(), Vector2i(4, 1));
|
||
|
13 years ago
|
CORRADE_COMPARE(b.buffer().id(), id);
|
||
|
|
|
||
|
|
const unsigned short data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||
|
11 years ago
|
BufferImage2D c{PixelStorage{}.setAlignment(1),
|
||
|
|
PixelFormat::RGBA, PixelType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw};
|
||
|
13 years ago
|
const Int cId = c.buffer().id();
|
||
|
|
c = std::move(b);
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
|
CORRADE_VERIFY(cId > 0);
|
||
|
|
CORRADE_COMPARE(b.buffer().id(), cId);
|
||
|
12 years ago
|
CORRADE_COMPARE(b.size(), Vector2i(1, 2));
|
||
|
13 years ago
|
|
||
|
11 years ago
|
CORRADE_COMPARE(c.storage().alignment(), 4);
|
||
|
11 years ago
|
CORRADE_COMPARE(c.format(), PixelFormat::Red);
|
||
|
|
CORRADE_COMPARE(c.type(), PixelType::UnsignedByte);
|
||
|
12 years ago
|
CORRADE_COMPARE(c.size(), Vector2i(4, 1));
|
||
|
13 years ago
|
CORRADE_COMPARE(c.buffer().id(), id);
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::constructMoveCompressed() {
|
||
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
||
|
11 years ago
|
CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, data, BufferUsage::StaticDraw};
|
||
|
11 years ago
|
const Int id = a.buffer().id();
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
CORRADE_VERIFY(id > 0);
|
||
|
|
|
||
|
|
CompressedBufferImage2D b{std::move(a)};
|
||
|
|
|
||
|
|
CORRADE_COMPARE(a.buffer().id(), 0);
|
||
|
|
CORRADE_COMPARE(a.size(), Vector2i());
|
||
|
|
CORRADE_COMPARE(a.dataSize(), 0);
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(b.storage().compressedBlockSize(), Vector3i{0});
|
||
|
|
#endif
|
||
|
11 years ago
|
CORRADE_COMPARE(b.format(), CompressedPixelFormat::RGBAS3tcDxt1);
|
||
|
11 years ago
|
CORRADE_COMPARE(b.size(), Vector2i(4, 4));
|
||
|
|
CORRADE_COMPARE(b.dataSize(), 8);
|
||
|
|
CORRADE_COMPARE(b.buffer().id(), id);
|
||
|
|
|
||
|
|
const unsigned char data2[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0, 'd', 0, 0, 0 };
|
||
|
11 years ago
|
CompressedBufferImage2D c{
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
||
|
|
#endif
|
||
|
|
CompressedPixelFormat::RGBAS3tcDxt1, {8, 4}, data2, BufferUsage::StaticDraw};
|
||
|
11 years ago
|
const Int cId = c.buffer().id();
|
||
|
|
c = std::move(b);
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
|
CORRADE_VERIFY(cId > 0);
|
||
|
|
CORRADE_COMPARE(b.buffer().id(), cId);
|
||
|
|
CORRADE_COMPARE(b.size(), Vector2i(8, 4));
|
||
|
|
CORRADE_COMPARE(b.dataSize(), 16);
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(c.storage().compressedBlockSize(), Vector3i{0});
|
||
|
|
#endif
|
||
|
11 years ago
|
CORRADE_COMPARE(c.format(), CompressedPixelFormat::RGBAS3tcDxt1);
|
||
|
11 years ago
|
CORRADE_COMPARE(c.size(), Vector2i(4, 4));
|
||
|
|
CORRADE_COMPARE(c.dataSize(), 8);
|
||
|
|
CORRADE_COMPARE(c.buffer().id(), id);
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
void BufferImageGLTest::setData() {
|
||
|
11 years ago
|
const char data[4] = { 'a', 'b', 'c', 'd' };
|
||
|
11 years ago
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
||
|
|
PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};
|
||
|
13 years ago
|
|
||
|
11 years ago
|
const UnsignedShort data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||
|
11 years ago
|
a.setData(PixelFormat::RGBA, PixelType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw);
|
||
|
13 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
const auto imageData = a.buffer().data();
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
11 years ago
|
CORRADE_COMPARE(a.storage().alignment(), 4);
|
||
|
11 years ago
|
CORRADE_COMPARE(a.format(), PixelFormat::RGBA);
|
||
|
|
CORRADE_COMPARE(a.type(), PixelType::UnsignedShort);
|
||
|
12 years ago
|
CORRADE_COMPARE(a.size(), Vector2i(1, 2));
|
||
|
13 years ago
|
|
||
|
11 years ago
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(Containers::arrayCast<UnsignedShort>(imageData),
|
||
|
|
Containers::arrayView(data2),
|
||
|
9 years ago
|
TestSuite::Compare::Container);
|
||
|
11 years ago
|
#endif
|
||
|
|
}
|
||
|
|
|
||
|
|
void BufferImageGLTest::setDataCompressed() {
|
||
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
||
|
11 years ago
|
CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, data, BufferUsage::StaticDraw};
|
||
|
11 years ago
|
|
||
|
|
const char data2[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0, 'd', 0, 0, 0 };
|
||
|
11 years ago
|
a.setData(
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
||
|
|
#endif
|
||
|
|
CompressedPixelFormat::RGBAS3tcDxt3, {8, 4}, data2, BufferUsage::StaticDraw);
|
||
|
11 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
const auto imageData = a.buffer().data();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
MAGNUM_VERIFY_NO_ERROR();
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
CORRADE_COMPARE(a.storage().compressedBlockSize(), Vector3i{4});
|
||
|
|
#endif
|
||
|
11 years ago
|
CORRADE_COMPARE(a.format(), CompressedPixelFormat::RGBAS3tcDxt3);
|
||
|
11 years ago
|
CORRADE_COMPARE(a.size(), Vector2i(8, 4));
|
||
|
|
CORRADE_COMPARE(a.dataSize(), 16);
|
||
|
|
|
||
|
13 years ago
|
/** @todo How to verify the contents in ES? */
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
9 years ago
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data2),
|
||
|
|
TestSuite::Compare::Container);
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
9 years ago
|
void BufferImageGLTest::release() {
|
||
|
|
BufferImage2D a{PixelFormat::RGBA, PixelType::UnsignedByte};
|
||
|
|
const UnsignedInt id = a.buffer().id();
|
||
|
|
|
||
|
|
CORRADE_VERIFY(a.buffer().id());
|
||
|
|
Buffer b = a.release();
|
||
|
|
CORRADE_VERIFY(!a.buffer().id());
|
||
|
|
CORRADE_COMPARE(b.id(), id);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BufferImageGLTest::releaseCompressed() {
|
||
|
|
CompressedBufferImage2D a;
|
||
|
|
const UnsignedInt id = a.buffer().id();
|
||
|
|
|
||
|
|
CORRADE_VERIFY(a.buffer().id());
|
||
|
|
Buffer b = a.release();
|
||
|
|
CORRADE_VERIFY(!a.buffer().id());
|
||
|
|
CORRADE_COMPARE(b.id(), id);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
}}
|
||
|
|
|
||
|
9 years ago
|
CORRADE_TEST_MAIN(Magnum::Test::BufferImageGLTest)
|