|
|
|
|
/*
|
|
|
|
|
This file is part of Magnum.
|
|
|
|
|
|
|
|
|
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
|
|
|
|
Vladimír Vondruš <mosra@centrum.cz>
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <Corrade/Containers/Array.h>
|
|
|
|
|
#include <Corrade/TestSuite/Compare/Container.h>
|
|
|
|
|
|
|
|
|
|
#include "Magnum/BufferImage.h"
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
#include "Magnum/PixelFormat.h"
|
|
|
|
|
#include "Magnum/OpenGLTester.h"
|
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Test {
|
|
|
|
|
|
|
|
|
|
struct BufferImageGLTest: OpenGLTester {
|
|
|
|
|
explicit BufferImageGLTest();
|
|
|
|
|
|
|
|
|
|
void construct();
|
|
|
|
|
void constructGeneric();
|
|
|
|
|
void constructCompressed();
|
|
|
|
|
void constructCompressedGeneric();
|
|
|
|
|
void constructBuffer();
|
|
|
|
|
void constructBufferGeneric();
|
|
|
|
|
void constructBufferCompressed();
|
|
|
|
|
void constructBufferCompressedGeneric();
|
|
|
|
|
|
|
|
|
|
void constructInvalidSize();
|
|
|
|
|
void constructCompressedInvalidSize();
|
|
|
|
|
|
|
|
|
|
void constructCopy();
|
|
|
|
|
void constructCopyCompressed();
|
|
|
|
|
void constructMove();
|
|
|
|
|
void constructMoveCompressed();
|
|
|
|
|
|
|
|
|
|
void dataProperties();
|
|
|
|
|
void dataPropertiesCompressed();
|
|
|
|
|
|
|
|
|
|
void setData();
|
|
|
|
|
void setDataGeneric();
|
|
|
|
|
void setDataCompressed();
|
|
|
|
|
void setDataCompressedGeneric();
|
|
|
|
|
|
|
|
|
|
void release();
|
|
|
|
|
void releaseCompressed();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BufferImageGLTest::BufferImageGLTest() {
|
|
|
|
|
addTests({&BufferImageGLTest::construct,
|
|
|
|
|
&BufferImageGLTest::constructGeneric,
|
|
|
|
|
&BufferImageGLTest::constructCompressed,
|
|
|
|
|
&BufferImageGLTest::constructCompressedGeneric,
|
|
|
|
|
&BufferImageGLTest::constructBuffer,
|
|
|
|
|
&BufferImageGLTest::constructBufferGeneric,
|
|
|
|
|
&BufferImageGLTest::constructBufferCompressed,
|
|
|
|
|
&BufferImageGLTest::constructBufferCompressedGeneric,
|
|
|
|
|
|
|
|
|
|
&BufferImageGLTest::constructInvalidSize,
|
|
|
|
|
&BufferImageGLTest::constructCompressedInvalidSize,
|
|
|
|
|
|
|
|
|
|
&BufferImageGLTest::constructCopy,
|
|
|
|
|
&BufferImageGLTest::constructCopyCompressed,
|
|
|
|
|
&BufferImageGLTest::constructMove,
|
|
|
|
|
&BufferImageGLTest::constructMoveCompressed,
|
|
|
|
|
|
|
|
|
|
&BufferImageGLTest::dataProperties,
|
|
|
|
|
&BufferImageGLTest::dataPropertiesCompressed,
|
|
|
|
|
|
|
|
|
|
&BufferImageGLTest::setData,
|
|
|
|
|
&BufferImageGLTest::setDataGeneric,
|
|
|
|
|
&BufferImageGLTest::setDataCompressed,
|
|
|
|
|
&BufferImageGLTest::setDataCompressedGeneric,
|
|
|
|
|
|
|
|
|
|
&BufferImageGLTest::release,
|
|
|
|
|
&BufferImageGLTest::releaseCompressed});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::construct() {
|
|
|
|
|
const char data[] = { 'a', 'b', 'c' };
|
|
|
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
|
|
|
|
PixelFormat::Red, PixelType::UnsignedByte, {1, 3}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
const auto imageData = a.buffer().data();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_ERROR();
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(a.storage().alignment(), 1);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::PixelFormat::Red);
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructGeneric() {
|
|
|
|
|
const char data[] = { 'a', 'b', 'c' };
|
|
|
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
|
|
|
|
Magnum::PixelFormat::R8Unorm, {1, 3}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
const auto imageData = a.buffer().data();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_ERROR();
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(a.storage().alignment(), 1);
|
|
|
|
|
CORRADE_COMPARE(a.format(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructCompressed() {
|
|
|
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
|
|
|
|
CompressedBufferImage2D a{
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
|
|
|
|
#endif
|
|
|
|
|
CompressedPixelFormat::RGBAS3tcDxt1,
|
|
|
|
|
{4, 4}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
#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
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructCompressedGeneric() {
|
|
|
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
|
|
|
|
CompressedBufferImage2D a{
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
|
|
|
|
#endif
|
|
|
|
|
Magnum::CompressedPixelFormat::Bc1RGBAUnorm,
|
|
|
|
|
{4, 4}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
#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_COMPARE(a.format(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructBufferGeneric() {
|
|
|
|
|
const char data[] = { 'a', 'b', 'c' };
|
|
|
|
|
Buffer buffer;
|
|
|
|
|
buffer.setData(data, BufferUsage::StaticDraw);
|
|
|
|
|
const UnsignedInt id = buffer.id();
|
|
|
|
|
|
|
|
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
|
|
|
|
Magnum::PixelFormat::R8Unorm, {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(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#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);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructBufferCompressedGeneric() {
|
|
|
|
|
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
|
|
|
|
|
Magnum::CompressedPixelFormat::Bc1RGBAUnorm,
|
|
|
|
|
{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(), GL::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
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructInvalidSize() {
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
|
|
|
|
|
|
|
|
|
/* Doesn't consider alignment */
|
|
|
|
|
BufferImage2D{PixelFormat::RGB8Unorm, {1, 3}, Containers::Array<char>{3*3}, BufferUsage::StaticDraw};
|
|
|
|
|
CORRADE_COMPARE(out.str(), "GL::BufferImage::BufferImage(): data too small, got 9 but expected at least 12 bytes\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructCompressedInvalidSize() {
|
|
|
|
|
CORRADE_EXPECT_FAIL("Size checking for compressed image data is not implemented yet.");
|
|
|
|
|
|
|
|
|
|
/* Too small for given format */
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
|
|
|
|
CompressedBufferImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {4, 4}, Containers::Array<char>{2}, BufferUsage::StaticDraw};
|
|
|
|
|
CORRADE_COMPARE(out.str(), "GL::CompressedBufferImage::CompressedBufferImage(): data too small, got 2 but expected at least 4 bytes\n");
|
|
|
|
|
|
|
|
|
|
/* Size should be rounded up even if the image size is not full block */
|
|
|
|
|
} {
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
Error redirectError{&out};
|
|
|
|
|
CompressedBufferImage2D{CompressedPixelFormat::Bc2RGBAUnorm, {2, 2}, Containers::Array<char>{2}, BufferUsage::StaticDraw};
|
|
|
|
|
CORRADE_COMPARE(out.str(), "GL::CompressedBufferImage::CompressedBufferImage(): data too small, got 2 but expected at least 4 bytes\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructCopy() {
|
|
|
|
|
CORRADE_VERIFY(!(std::is_constructible<BufferImage2D, const BufferImage2D&>{}));
|
|
|
|
|
CORRADE_VERIFY(!(std::is_assignable<BufferImage2D, const BufferImage2D&>{}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructCopyCompressed() {
|
|
|
|
|
CORRADE_VERIFY(!(std::is_constructible<CompressedBufferImage2D, const CompressedBufferImage2D&>{}));
|
|
|
|
|
CORRADE_VERIFY(!(std::is_assignable<CompressedBufferImage2D, const CompressedBufferImage2D&>{}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructMove() {
|
|
|
|
|
const char data[4] = { 'a', 'b', 'c', 'd' };
|
|
|
|
|
BufferImage2D a{PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(b.storage().alignment(), 4);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(b.format(), GL::PixelFormat::Red);
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
CORRADE_COMPARE(b.type(), PixelType::UnsignedByte);
|
|
|
|
|
CORRADE_COMPARE(b.size(), Vector2i(4, 1));
|
|
|
|
|
CORRADE_COMPARE(b.buffer().id(), id);
|
|
|
|
|
|
|
|
|
|
const unsigned short data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
|
|
|
|
BufferImage2D c{PixelStorage{}.setAlignment(1),
|
|
|
|
|
PixelFormat::RGBA, PixelType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw};
|
|
|
|
|
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(1, 2));
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(c.storage().alignment(), 4);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(c.format(), GL::PixelFormat::Red);
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
CORRADE_COMPARE(c.type(), PixelType::UnsignedByte);
|
|
|
|
|
CORRADE_COMPARE(c.size(), Vector2i(4, 1));
|
|
|
|
|
CORRADE_COMPARE(c.buffer().id(), id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::constructMoveCompressed() {
|
|
|
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, data, BufferUsage::StaticDraw};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE(b.storage().compressedBlockSize(), Vector3i{0});
|
|
|
|
|
#endif
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(b.format(), GL::CompressedPixelFormat::RGBAS3tcDxt1);
|
|
|
|
|
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 };
|
|
|
|
|
CompressedBufferImage2D c{
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
|
|
|
|
#endif
|
|
|
|
|
CompressedPixelFormat::RGBAS3tcDxt1, {8, 4}, data2, BufferUsage::StaticDraw};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE(c.storage().compressedBlockSize(), Vector3i{0});
|
|
|
|
|
#endif
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(c.format(), GL::CompressedPixelFormat::RGBAS3tcDxt1);
|
|
|
|
|
CORRADE_COMPARE(c.size(), Vector2i(4, 4));
|
|
|
|
|
CORRADE_COMPARE(c.dataSize(), 8);
|
|
|
|
|
CORRADE_COMPARE(c.buffer().id(), id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::dataProperties() {
|
|
|
|
|
const char data[224]{};
|
|
|
|
|
BufferImage3D image{
|
|
|
|
|
PixelStorage{}
|
|
|
|
|
.setAlignment(8)
|
|
|
|
|
.setSkip({3, 2, 1}),
|
|
|
|
|
Magnum::PixelFormat::R8Unorm, {2, 4, 6}, data, BufferUsage::StaticDraw};
|
|
|
|
|
CORRADE_COMPARE(image.dataProperties(),
|
|
|
|
|
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{3, 16, 32}, {8, 4, 6}}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::dataPropertiesCompressed() {
|
|
|
|
|
/* Yes, I know, this is totally bogus and doesn't match the BC1 format */
|
|
|
|
|
const char data[1]{};
|
|
|
|
|
CompressedBufferImage3D image{
|
|
|
|
|
CompressedPixelStorage{}
|
|
|
|
|
.setCompressedBlockSize({3, 4, 5})
|
|
|
|
|
.setCompressedBlockDataSize(16)
|
|
|
|
|
.setImageHeight(12)
|
|
|
|
|
.setSkip({5, 8, 11}),
|
|
|
|
|
CompressedPixelFormat::Bc1RGBAUnorm, {2, 8, 11}, data, BufferUsage::StaticDraw};
|
|
|
|
|
CORRADE_COMPARE(image.dataProperties(),
|
|
|
|
|
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{2*16, 2*16, 9*16}, {1, 3, 3}}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::setData() {
|
|
|
|
|
const char data[4] = { 'a', 'b', 'c', 'd' };
|
|
|
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
|
|
|
|
PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
const UnsignedShort data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
a.setData(PixelFormat::RGBA, PixelType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw);
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
const auto imageData = a.buffer().data();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_ERROR();
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(a.storage().alignment(), 4);
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::PixelFormat::RGBA);
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
CORRADE_COMPARE(a.type(), PixelType::UnsignedShort);
|
|
|
|
|
CORRADE_COMPARE(a.size(), Vector2i(1, 2));
|
|
|
|
|
|
|
|
|
|
/** @todo How to verify the contents in ES? */
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE_AS(Containers::arrayCast<UnsignedShort>(imageData),
|
|
|
|
|
Containers::arrayView(data2),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::setDataGeneric() {
|
|
|
|
|
const char data[4] = { 'a', 'b', 'c', 'd' };
|
|
|
|
|
BufferImage2D a{PixelStorage{}.setAlignment(1),
|
|
|
|
|
PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
const UnsignedShort data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
|
|
|
|
a.setData(Magnum::PixelFormat::RGBA16Unorm, {1, 2}, data2, BufferUsage::StaticDraw);
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
const auto imageData = a.buffer().data();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MAGNUM_VERIFY_NO_ERROR();
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(a.storage().alignment(), 4);
|
|
|
|
|
CORRADE_COMPARE(a.format(), GL::PixelFormat::RGBA);
|
|
|
|
|
CORRADE_COMPARE(a.type(), PixelType::UnsignedShort);
|
|
|
|
|
CORRADE_COMPARE(a.size(), Vector2i(1, 2));
|
|
|
|
|
|
|
|
|
|
/** @todo How to verify the contents in ES? */
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE_AS(Containers::arrayCast<UnsignedShort>(imageData),
|
|
|
|
|
Containers::arrayView(data2),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::setDataCompressed() {
|
|
|
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
Pixel storage support, part 2: renamed ColorFormat to PixelFormat etc.
Yeah, sorry, I know, the enums are renamed for second or third time in a
row, first they were Image::Format, then ImageFormat, then ColorFormat
and now PixelFormat. But this time it's final and last time they are
renamed and now everything is finally consistent:
* ColorFormat::DepthComponent -- depth is not a color, thus
PixelFormat::DepthComponent makes a lot more sense.
* There will be PixelStorage classes, which will be stored in images
alonside PixelFormat/PixelType enums, making everything nicely
aligned.
* The GL documentation about glTexImage2D() etc. denotes the <format>
and <type> parameters as format and type of *pixel* data, so now we
are _finally_ consistent with the official naming.
I wonder why did I not choose PixelFormat originally. Anyway, the old
<Magnum/ColorFormat.h> header, ColorFormat, ColorType and
CompressedColorFormat types are now aliases to the new ones, are marked
as deprecated and will be removed in some future release (as always, I'm
waiting at least six months before removing the deprecated
functionality).
11 years ago
|
|
|
CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
const char data2[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0, 'd', 0, 0, 0 };
|
|
|
|
|
a.setData(
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
|
|
|
|
#endif
|
|
|
|
|
CompressedPixelFormat::RGBAS3tcDxt3, {8, 4}, data2, BufferUsage::StaticDraw);
|
|
|
|
|
|
|
|
|
|
#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_COMPARE(a.format(), GL::CompressedPixelFormat::RGBAS3tcDxt3);
|
|
|
|
|
CORRADE_COMPARE(a.size(), Vector2i(8, 4));
|
|
|
|
|
CORRADE_COMPARE(a.dataSize(), 16);
|
|
|
|
|
|
|
|
|
|
/** @todo How to verify the contents in ES? */
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data2),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BufferImageGLTest::setDataCompressedGeneric() {
|
|
|
|
|
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0 };
|
|
|
|
|
CompressedBufferImage2D a{CompressedPixelFormat::RGBAS3tcDxt1, {4, 4}, data, BufferUsage::StaticDraw};
|
|
|
|
|
|
|
|
|
|
const char data2[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0, 'd', 0, 0, 0 };
|
|
|
|
|
a.setData(
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CompressedPixelStorage{}.setCompressedBlockSize(Vector3i{4}),
|
|
|
|
|
#endif
|
|
|
|
|
Magnum::CompressedPixelFormat::Bc2RGBAUnorm, {8, 4}, data2, BufferUsage::StaticDraw);
|
|
|
|
|
|
|
|
|
|
#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
|
Split the OpenGL layer out, pt 9: generic pixel formats.
This is quite big, so:
* There are new Magnum::PixelFormat and Magnum::CompressedPixelFormat
enums, which contain generic API-independent formats. In particular,
PixelFormat replaces GL::PixelFormat and GL::PixelType with a single
value.
* There's GL::pixelFormat(), GL::pixelType(),
GL::compressedPixelFormat() to convert the generic enums to
GL-specific. The mapping is only in one direction, done with a lookup
table (generic enums are indices to that table).
* GL classes taking the formats directly (such as GL::BufferImage) have
overloads that take both the GL-specific and generic format.
* The generic Image, CompressedImage, ImageView, CompressedImageView,
and Trade::ImageData classes now accept the generic formats
first-class. However, it's also possible to store an
implementation-specific value to cover cases where a generic format
enum doesn't have support for a particular format. This is done by
wrapping the value using pixelFormatWrap() or
compressedPixelFormatWrap(). Particular GPU APIs then assume it's
their implementation-specific value and extract the value back using
pixelFormatUnwrap() or compressedPixelFormatUnwrap(). There's also an
isPixelFormatImplementationSpecific() and
isCompressedPixelFormatImplementationSpecific() that distinguishes
these values.
* Many operations need pixel size and in order to have it even for
implementation-specific formats, a corresponding pixelSize()
overload is found via ADL on construction and the calculated size
stored along the format. Previously the pixel size was only
calculated on demand, but that's not possible now. In case such
overload is not available, it's possible to pass pixel size manually
as well.
* In order to support the GL format+type pair, Image, ImageView and
Trade::ImageData, there's now an additional untyped formatExtra()
field that holds the second value.
* The CompressedPixelStorage class is now unconditionally available on
all targets, including OpenGL ES and WebGL. However, on OpenGL ES the
GL APIs expect that it's all at default values.
I attempted to preserve backwards compatibility as much as possible:
* The PixelFormat and CompressedPixelFormat enum now contains generic
API-independent values. The GL-specific formats are present there,
but marked as deprecated. Use either the generic values or
GL::PixelFormat (togehter with GL::PixelType) and
GL::CompressedPixelFormat instead. There's a lot of ugliness caused
by this, but seems to work well.
* *Image::type() functions are deprecated as they were too
GL-specific. Use formatExtra() and cast it to GL::PixelType instead.
* Image constructors take templated format or format+extra arguments,
so passing GL-specific values to them should still work.
8 years ago
|
|
|
CORRADE_COMPARE(a.format(), GL::CompressedPixelFormat::RGBAS3tcDxt3);
|
|
|
|
|
CORRADE_COMPARE(a.size(), Vector2i(8, 4));
|
|
|
|
|
CORRADE_COMPARE(a.dataSize(), 16);
|
|
|
|
|
|
|
|
|
|
/** @todo How to verify the contents in ES? */
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES
|
|
|
|
|
CORRADE_COMPARE_AS(imageData, Containers::arrayView(data2),
|
|
|
|
|
TestSuite::Compare::Container);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::Test::BufferImageGLTest)
|