mirror of https://github.com/mosra/magnum.git
Browse Source
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.pull/233/head
34 changed files with 4761 additions and 662 deletions
@ -0,0 +1,179 @@ |
|||||||
|
/*
|
||||||
|
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 "Magnum/Image.h" |
||||||
|
#include "Magnum/PixelFormat.h" |
||||||
|
#ifdef MAGNUM_TARGET_GL |
||||||
|
#include "Magnum/GL/PixelFormat.h" |
||||||
|
#include "Magnum/GL/Texture.h" |
||||||
|
#endif |
||||||
|
|
||||||
|
using namespace Magnum; |
||||||
|
using namespace Magnum::Math::Literals; |
||||||
|
|
||||||
|
int main() { |
||||||
|
|
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [ImageView-usage] */ |
||||||
|
ImageView2D image{PixelFormat::RGBA8Unorm, {512, 256}, data}; |
||||||
|
/* [ImageView-usage] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
char evenFrameData[3], oddFrameData[3]; |
||||||
|
/* [ImageView-usage-streaming] */ |
||||||
|
ImageView2D frame{PixelFormat::RGBA8Unorm, {512, 256}}; |
||||||
|
|
||||||
|
frame.setData(evenFrameData); |
||||||
|
// Use even frame data ...
|
||||||
|
|
||||||
|
frame.setData(oddFrameData); |
||||||
|
// Use odd frame data ...
|
||||||
|
/* [ImageView-usage-streaming] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [ImageView-usage-storage] */ |
||||||
|
ImageView2D image{ |
||||||
|
PixelStorage{} |
||||||
|
.setRowLength(75) |
||||||
|
.setAlignment(4) |
||||||
|
.setSkip({25, 25, 0}), |
||||||
|
PixelFormat::RGBA8Unorm, {25, 25}, data}; |
||||||
|
/* [ImageView-usage-storage] */ |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef MAGNUM_TARGET_GL |
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [ImageView-usage-gl] */ |
||||||
|
ImageView2D image{GL::PixelFormat::DepthComponent, |
||||||
|
GL::PixelType::UnsignedInt, {512, 256}, data}; |
||||||
|
/* [ImageView-usage-gl] */ |
||||||
|
|
||||||
|
/* [ImageView-usage-gl-extract] */ |
||||||
|
auto format = pixelFormatUnwrap<GLenum>(image.format()); |
||||||
|
auto type = GLenum(image.formatExtra()); |
||||||
|
/* [ImageView-usage-gl-extract] */ |
||||||
|
static_cast<void>(format); |
||||||
|
static_cast<void>(type); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
#define MTLPixelFormatRGBA8Unorm_sRGB 71 |
||||||
|
/* [ImageView-usage-metal] */ |
||||||
|
/* Default pixel storage, 8-bit sRGB + alpha, four bytes per pixel */ |
||||||
|
ImageView2D view{{}, MTLPixelFormatRGBA8Unorm_sRGB, {}, 4, {256, 256}, data}; |
||||||
|
/* [ImageView-usage-metal] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [CompressedImageView-usage] */ |
||||||
|
CompressedImageView2D image{CompressedPixelFormat::Bc1RGBUnorm, |
||||||
|
{512, 256}, data}; |
||||||
|
/* [CompressedImageView-usage] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
char evenFrameData[3], oddFrameData[3]; |
||||||
|
/* [CompressedImageView-usage-streaming] */ |
||||||
|
CompressedImageView2D frame{CompressedPixelFormat::Bc1RGBUnorm, {512, 256}}; |
||||||
|
|
||||||
|
frame.setData(evenFrameData); |
||||||
|
// Use even frame data ...
|
||||||
|
|
||||||
|
frame.setData(oddFrameData); |
||||||
|
// Use odd frame data ...
|
||||||
|
/* [CompressedImageView-usage-streaming] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [CompressedImageView-usage-storage] */ |
||||||
|
CompressedImageView2D image{ |
||||||
|
CompressedPixelStorage{} |
||||||
|
.setRowLength(64) |
||||||
|
.setCompressedBlockSize({4, 4, 1}) |
||||||
|
.setCompressedBlockDataSize(8) |
||||||
|
.setSkip({32, 32, 0}), |
||||||
|
CompressedPixelFormat::Bc1RGBUnorm, {32, 32}, data}; |
||||||
|
/* [CompressedImageView-usage-storage] */ |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_GLES) |
||||||
|
{ |
||||||
|
char data[3]; |
||||||
|
/* [CompressedImageView-usage-gl] */ |
||||||
|
CompressedImageView2D image{GL::CompressedPixelFormat::SignedRGRgtc2, |
||||||
|
{512, 256}, data}; |
||||||
|
/* [CompressedImageView-usage-gl] */ |
||||||
|
|
||||||
|
/* [CompressedImageView-usage-gl-extract] */ |
||||||
|
auto format = compressedPixelFormatUnwrap<GLenum>(image.format()); |
||||||
|
/* [CompressedImageView-usage-gl-extract] */ |
||||||
|
static_cast<void>(format); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
{ |
||||||
|
/* [Image-usage] */ |
||||||
|
Containers::Array<char> data; |
||||||
|
Image2D image{PixelFormat::RGBA8Unorm, {512, 256}, std::move(data)}; |
||||||
|
/* [Image-usage] */ |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_GLES) |
||||||
|
{ |
||||||
|
/* [Image-usage-query] */ |
||||||
|
GL::Texture2D texture; |
||||||
|
Image2D image = texture.image(0, {GL::PixelFormat::DepthComponent, |
||||||
|
GL::PixelType::UnsignedInt}); |
||||||
|
/* [Image-usage-query] */ |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
{ |
||||||
|
/* [CompressedImage-usage] */ |
||||||
|
Containers::Array<char> data; |
||||||
|
CompressedImage2D image{CompressedPixelFormat::Bc1RGBUnorm, |
||||||
|
{512, 256}, std::move(data)}; |
||||||
|
/* [CompressedImage-usage] */ |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_TARGET_GL) && !defined(MAGNUM_TARGET_GLES) |
||||||
|
{ |
||||||
|
/* [CompressedImage-usage-query] */ |
||||||
|
GL::Texture2D texture; |
||||||
|
CompressedImage2D image = texture.compressedImage(0, {}); |
||||||
|
/* [CompressedImage-usage-query] */ |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,70 @@ |
|||||||
|
/*
|
||||||
|
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 "Magnum/PixelFormat.h" |
||||||
|
#include "Magnum/Trade/AbstractImporter.h" |
||||||
|
#include "Magnum/Trade/ImageData.h" |
||||||
|
#ifdef MAGNUM_TARGET_GL |
||||||
|
#include "Magnum/GL/Texture.h" |
||||||
|
#endif |
||||||
|
|
||||||
|
using namespace Magnum; |
||||||
|
using namespace Magnum::Math::Literals; |
||||||
|
|
||||||
|
int main() { |
||||||
|
|
||||||
|
{ |
||||||
|
/* [ImageData-construction] */ |
||||||
|
Containers::Array<char> data; |
||||||
|
Trade::ImageData2D image{PixelFormat::RGB8Unorm, {32, 32}, std::move(data)}; |
||||||
|
/* [ImageData-construction] */ |
||||||
|
} |
||||||
|
|
||||||
|
{ |
||||||
|
/* [ImageData-construction-compressed] */ |
||||||
|
Containers::Array<char> data; |
||||||
|
Trade::ImageData2D image{CompressedPixelFormat::Bc1RGBUnorm, |
||||||
|
{32, 32}, std::move(data)}; |
||||||
|
/* [ImageData-construction-compressed] */ |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef MAGNUM_TARGET_GL |
||||||
|
{ |
||||||
|
/* [ImageData-usage] */ |
||||||
|
std::unique_ptr<Trade::AbstractImporter> importer; |
||||||
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0); |
||||||
|
if(!image) Fatal{} << "Oopsie!"; |
||||||
|
|
||||||
|
GL::Texture2D texture; |
||||||
|
// ...
|
||||||
|
if(!image->isCompressed()) |
||||||
|
texture.setSubImage(0, {}, *image); |
||||||
|
else |
||||||
|
texture.setCompressedSubImage(0, {}, *image); |
||||||
|
/* [ImageData-usage] */ |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/* See Magnum/GL/PixelFormat.cpp and Magnum/GL/Test/PixelFormatTest.cpp */ |
||||||
|
#ifdef _c |
||||||
|
_c(Bc1RGBUnorm, RGBS3tcDxt1) |
||||||
|
_c(Bc1RGBAUnorm, RGBAS3tcDxt1) |
||||||
|
_c(Bc2RGBAUnorm, RGBAS3tcDxt3) |
||||||
|
_c(Bc3RGBAUnorm, RGBAS3tcDxt5) |
||||||
|
#endif |
||||||
@ -0,0 +1,140 @@ |
|||||||
|
/*
|
||||||
|
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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/* See Magnum/GL/PixelFormat.cpp and Magnum/GL/Test/PixelFormatTest.cpp */ |
||||||
|
#ifdef _c |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R8Unorm, Red, UnsignedByte) |
||||||
|
_c(RG8Unorm, RG, UnsignedByte) |
||||||
|
#else |
||||||
|
_c(R8Unorm, Luminance, UnsignedByte) |
||||||
|
_c(RG8Unorm, LuminanceAlpha, UnsignedByte) |
||||||
|
#endif |
||||||
|
_c(RGB8Unorm, RGB, UnsignedByte) |
||||||
|
_c(RGBA8Unorm, RGBA, UnsignedByte) |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R8Snorm, Red, Byte) |
||||||
|
_c(RG8Snorm, RG, Byte) |
||||||
|
_c(RGB8Snorm, RGB, Byte) |
||||||
|
_c(RGBA8Snorm, RGBA, Byte) |
||||||
|
#else |
||||||
|
_s(R8Snorm) |
||||||
|
_s(RG8Snorm) |
||||||
|
_s(RGB8Snorm) |
||||||
|
_s(RGBA8Snorm) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R8UI, RedInteger, UnsignedByte) |
||||||
|
_c(RG8UI, RGInteger, UnsignedByte) |
||||||
|
_c(RGB8UI, RGBInteger, UnsignedByte) |
||||||
|
_c(RGBA8UI, RGBAInteger, UnsignedByte) |
||||||
|
_c(R8I, RedInteger, Byte) |
||||||
|
_c(RG8I, RGInteger, Byte) |
||||||
|
_c(RGB8I, RGBInteger, Byte) |
||||||
|
_c(RGBA8I, RGBAInteger, Byte) |
||||||
|
#else |
||||||
|
_s(R8UI) |
||||||
|
_s(RG8UI) |
||||||
|
_s(RGB8UI) |
||||||
|
_s(RGBA8UI) |
||||||
|
_s(R8I) |
||||||
|
_s(RG8I) |
||||||
|
_s(RGB8I) |
||||||
|
_s(RGBA8I) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R16Unorm, Red, UnsignedShort) |
||||||
|
_c(RG16Unorm, RG, UnsignedShort) |
||||||
|
#else |
||||||
|
_c(R16Unorm, Luminance, UnsignedShort) |
||||||
|
_c(RG16Unorm, LuminanceAlpha, UnsignedShort) |
||||||
|
#endif |
||||||
|
_c(RGB16Unorm, RGB, UnsignedShort) |
||||||
|
_c(RGBA16Unorm, RGBA, UnsignedShort) |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R16Snorm, Red, Short) |
||||||
|
_c(RG16Snorm, RG, Short) |
||||||
|
_c(RGB16Snorm, RGB, Short) |
||||||
|
_c(RGBA16Snorm, RGBA, Short) |
||||||
|
#else |
||||||
|
_s(R16Snorm) |
||||||
|
_s(RG16Snorm) |
||||||
|
_s(RGB16Snorm) |
||||||
|
_s(RGBA16Snorm) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R16UI, RedInteger, UnsignedShort) |
||||||
|
_c(RG16UI, RGInteger, UnsignedShort) |
||||||
|
_c(RGB16UI, RGBInteger, UnsignedShort) |
||||||
|
_c(RGBA16UI, RGBAInteger, UnsignedShort) |
||||||
|
_c(R16I, RedInteger, Short) |
||||||
|
_c(RG16I, RGInteger, Short) |
||||||
|
_c(RGB16I, RGBInteger, Short) |
||||||
|
_c(RGBA16I, RGBAInteger, Short) |
||||||
|
_c(R32UI, RedInteger, UnsignedInt) |
||||||
|
_c(RG32UI, RGInteger, UnsignedInt) |
||||||
|
_c(RGB32UI, RGBInteger, UnsignedInt) |
||||||
|
_c(RGBA32UI, RGBAInteger, UnsignedInt) |
||||||
|
_c(R32I, RedInteger, Int) |
||||||
|
_c(RG32I, RGInteger, Int) |
||||||
|
_c(RGB32I, RGBInteger, Int) |
||||||
|
_c(RGBA32I, RGBAInteger, Int) |
||||||
|
#else |
||||||
|
_s(R16UI) |
||||||
|
_s(RG16UI) |
||||||
|
_s(RGB16UI) |
||||||
|
_s(RGBA16UI) |
||||||
|
_s(R16I) |
||||||
|
_s(RG16I) |
||||||
|
_s(RGB16I) |
||||||
|
_s(RGBA16I) |
||||||
|
_s(R32UI) |
||||||
|
_s(RG32UI) |
||||||
|
_s(RGB32UI) |
||||||
|
_s(RGBA32UI) |
||||||
|
_s(R32I) |
||||||
|
_s(RG32I) |
||||||
|
_s(RGB32I) |
||||||
|
_s(RGBA32I) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R16F, Red, HalfFloat) |
||||||
|
_c(RG16F, RG, HalfFloat) |
||||||
|
#else |
||||||
|
_c(R16F, Luminance, HalfFloat) |
||||||
|
_c(RG16F, LuminanceAlpha, HalfFloat) |
||||||
|
#endif |
||||||
|
_c(RGB16F, RGB, HalfFloat) |
||||||
|
_c(RGBA16F, RGBA, HalfFloat) |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(R32F, Red, Float) |
||||||
|
_c(RG32F, RG, Float) |
||||||
|
#else |
||||||
|
_c(R32F, Luminance, Float) |
||||||
|
_c(RG32F, LuminanceAlpha, Float) |
||||||
|
#endif |
||||||
|
_c(RGB32F, RGB, Float) |
||||||
|
_c(RGBA32F, RGBA, Float) |
||||||
|
#endif |
||||||
@ -1,74 +0,0 @@ |
|||||||
/*
|
|
||||||
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/TestSuite/Tester.h> |
|
||||||
|
|
||||||
#include "Magnum/PixelFormat.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Test { |
|
||||||
|
|
||||||
struct FormatTest: TestSuite::Tester { |
|
||||||
explicit FormatTest(); |
|
||||||
|
|
||||||
void debugPixelFormat(); |
|
||||||
void debugPixelType(); |
|
||||||
void debugCompressedPixelFormat(); |
|
||||||
}; |
|
||||||
|
|
||||||
FormatTest::FormatTest() { |
|
||||||
addTests({&FormatTest::debugPixelFormat, |
|
||||||
&FormatTest::debugPixelType, |
|
||||||
&FormatTest::debugCompressedPixelFormat}); |
|
||||||
} |
|
||||||
|
|
||||||
void FormatTest::debugPixelFormat() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug(&out) << PixelFormat::RGBA << PixelFormat(0xdead); |
|
||||||
CORRADE_COMPARE(out.str(), "GL::PixelFormat::RGBA GL::PixelFormat(0xdead)\n"); |
|
||||||
} |
|
||||||
|
|
||||||
void FormatTest::debugPixelType() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug(&out) << PixelType::UnsignedByte << PixelType(0xdead); |
|
||||||
CORRADE_COMPARE(out.str(), "GL::PixelType::UnsignedByte GL::PixelType(0xdead)\n"); |
|
||||||
} |
|
||||||
|
|
||||||
void FormatTest::debugCompressedPixelFormat() { |
|
||||||
#ifdef MAGNUM_TARGET_GLES |
|
||||||
CORRADE_SKIP("No enum value available"); |
|
||||||
#else |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug(&out) << CompressedPixelFormat::RGBBptcUnsignedFloat << CompressedPixelFormat(0xdead); |
|
||||||
CORRADE_COMPARE(out.str(), "GL::CompressedPixelFormat::RGBBptcUnsignedFloat GL::CompressedPixelFormat(0xdead)\n"); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::Test::FormatTest) |
|
||||||
@ -0,0 +1,548 @@ |
|||||||
|
/*
|
||||||
|
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/TestSuite/Tester.h> |
||||||
|
|
||||||
|
#include "Magnum/PixelFormat.h" |
||||||
|
#include "Magnum/GL/PixelFormat.h" |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
#include "Magnum/PixelStorage.h" |
||||||
|
#endif |
||||||
|
|
||||||
|
namespace Magnum { namespace GL { namespace Test { |
||||||
|
|
||||||
|
struct PixelFormatTest: TestSuite::Tester { |
||||||
|
explicit PixelFormatTest(); |
||||||
|
|
||||||
|
void mapFormatType(); |
||||||
|
void mapFormatImplementationSpecific(); |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void mapFormatDeprecated(); |
||||||
|
#endif |
||||||
|
void mapFormatUnsupported(); |
||||||
|
void mapFormatInvalid(); |
||||||
|
void mapTypeImplementationSpecific(); |
||||||
|
void mapTypeImplementationSpecificZero(); |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void mapTypeDeprecated(); |
||||||
|
#endif |
||||||
|
void mapTypeUnsupported(); |
||||||
|
void mapTypeInvalid(); |
||||||
|
|
||||||
|
void size(); |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void sizeDataPropertiesDeprecated(); |
||||||
|
#endif |
||||||
|
void sizeInvalid(); |
||||||
|
|
||||||
|
void mapCompressedFormat(); |
||||||
|
void mapCompressedFormatImplementationSpecific(); |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void mapCompressedFormatDeprecated(); |
||||||
|
#endif |
||||||
|
void mapCompressedFormatUnsupported(); |
||||||
|
void mapCompressedFormatInvalid(); |
||||||
|
|
||||||
|
void debugPixelFormat(); |
||||||
|
void debugPixelType(); |
||||||
|
|
||||||
|
void debugCompressedPixelFormat(); |
||||||
|
}; |
||||||
|
|
||||||
|
PixelFormatTest::PixelFormatTest() { |
||||||
|
addTests({&PixelFormatTest::mapFormatType, |
||||||
|
&PixelFormatTest::mapFormatImplementationSpecific, |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
&PixelFormatTest::mapFormatDeprecated, |
||||||
|
#endif |
||||||
|
&PixelFormatTest::mapFormatUnsupported, |
||||||
|
&PixelFormatTest::mapFormatInvalid, |
||||||
|
&PixelFormatTest::mapTypeImplementationSpecific, |
||||||
|
&PixelFormatTest::mapTypeImplementationSpecificZero, |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
&PixelFormatTest::mapTypeDeprecated, |
||||||
|
#endif |
||||||
|
&PixelFormatTest::mapTypeUnsupported, |
||||||
|
&PixelFormatTest::mapTypeInvalid, |
||||||
|
|
||||||
|
&PixelFormatTest::size, |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
&PixelFormatTest::sizeDataPropertiesDeprecated, |
||||||
|
#endif |
||||||
|
&PixelFormatTest::sizeInvalid, |
||||||
|
|
||||||
|
&PixelFormatTest::mapCompressedFormat, |
||||||
|
&PixelFormatTest::mapCompressedFormatImplementationSpecific, |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
&PixelFormatTest::mapCompressedFormatDeprecated, |
||||||
|
#endif |
||||||
|
&PixelFormatTest::mapCompressedFormatUnsupported, |
||||||
|
&PixelFormatTest::mapCompressedFormatInvalid, |
||||||
|
|
||||||
|
&PixelFormatTest::debugPixelFormat, |
||||||
|
&PixelFormatTest::debugPixelType, |
||||||
|
&PixelFormatTest::debugCompressedPixelFormat}); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapFormatType() { |
||||||
|
/* Touchstone verification */ |
||||||
|
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::RGBA8Unorm)); |
||||||
|
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::RGBA8Unorm), PixelFormat::RGBA); |
||||||
|
CORRADE_COMPARE(pixelType(Magnum::PixelFormat::RGBA8Unorm), PixelType::UnsignedByte); |
||||||
|
|
||||||
|
/* This goes through the first 16 bits, which should be enough. Going
|
||||||
|
through 32 bits takes 8 seconds, too much. */ |
||||||
|
UnsignedInt firstUnhandled = 0xffff; |
||||||
|
UnsignedInt nextHandled = 0; |
||||||
|
for(UnsignedInt i = 0; i <= 0xffff; ++i) { |
||||||
|
const auto format = Magnum::PixelFormat(i); |
||||||
|
/* Each case verifies:
|
||||||
|
- that the cases are ordered by number (so insertion here is done in |
||||||
|
proper place) |
||||||
|
- that there was no gap (unhandled value inside the range) |
||||||
|
- that a particular pixel format maps to a particular GL format |
||||||
|
- that a particular pixel type maps to a particular GL type */ |
||||||
|
switch(format) { |
||||||
|
#define _c(format, expectedFormat, expectedType) \ |
||||||
|
case Magnum::PixelFormat::format: \
|
||||||
|
CORRADE_COMPARE(nextHandled, i); \
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||||
|
CORRADE_VERIFY(hasPixelFormat(Magnum::PixelFormat::format)); \
|
||||||
|
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::format), Magnum::GL::PixelFormat::expectedFormat); \
|
||||||
|
CORRADE_COMPARE(pixelType(Magnum::PixelFormat::format), Magnum::GL::PixelType::expectedType); \
|
||||||
|
++nextHandled; \
|
||||||
|
continue; |
||||||
|
#define _s(format) \ |
||||||
|
case Magnum::PixelFormat::format: \
|
||||||
|
CORRADE_COMPARE(nextHandled, i); \
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||||
|
CORRADE_VERIFY(!hasPixelFormat(Magnum::PixelFormat::format)); \
|
||||||
|
pixelFormat(Magnum::PixelFormat::format); \
|
||||||
|
pixelType(Magnum::PixelFormat::format); \
|
||||||
|
++nextHandled; \
|
||||||
|
continue; |
||||||
|
#include "Magnum/GL/Implementation/pixelFormatMapping.hpp" |
||||||
|
#undef _s |
||||||
|
#undef _c |
||||||
|
|
||||||
|
/* Here to silence unhandled value warnings and to verify that all
|
||||||
|
GL-specific formats are larger than a particular value. This |
||||||
|
value is used in pixelFormat() and pixelType() to detect |
||||||
|
deprecated GL-specific values and convert them properly. */ |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
#define _c(value) \ |
||||||
|
case Magnum::PixelFormat::value: \
|
||||||
|
CORRADE_VERIFY(UnsignedInt(Magnum::PixelFormat::value) >= 0x1000); \
|
||||||
|
continue; |
||||||
|
#ifdef __GNUC__ |
||||||
|
#pragma GCC diagnostic push |
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
||||||
|
#elif defined(_MSC_VER) |
||||||
|
#pragma warning(push) |
||||||
|
#pragma warning(disable: 4996) |
||||||
|
#endif |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
_c(Red) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Green) |
||||||
|
_c(Blue) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(Luminance) |
||||||
|
#endif |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
_c(RG) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(LuminanceAlpha) |
||||||
|
#endif |
||||||
|
_c(RGB) |
||||||
|
_c(RGBA) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(BGR) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(BGRA) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(SRGB) |
||||||
|
_c(SRGBAlpha) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(RedInteger) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(GreenInteger) |
||||||
|
_c(BlueInteger) |
||||||
|
#endif |
||||||
|
_c(RGInteger) |
||||||
|
_c(RGBInteger) |
||||||
|
_c(RGBAInteger) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(BGRInteger) |
||||||
|
_c(BGRAInteger) |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
_c(DepthComponent) |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(StencilIndex) |
||||||
|
#endif |
||||||
|
_c(DepthStencil) |
||||||
|
#undef _c |
||||||
|
#ifdef __GNUC__ |
||||||
|
#pragma GCC diagnostic pop |
||||||
|
#elif defined(_MSC_VER) |
||||||
|
#pragma warning(pop) |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
/* Not handled by any value, remember -- we might either be at the end
|
||||||
|
of the enum range (which is okay) or some value might be unhandled |
||||||
|
here */ |
||||||
|
firstUnhandled = i; |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapFormatImplementationSpecific() { |
||||||
|
CORRADE_VERIFY(hasPixelFormat(Magnum::pixelFormatWrap(PixelFormat::RGBA))); |
||||||
|
CORRADE_COMPARE(pixelFormat(Magnum::pixelFormatWrap(PixelFormat::RGBA)), |
||||||
|
PixelFormat::RGBA); |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void PixelFormatTest::mapFormatDeprecated() { |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
CORRADE_COMPARE(pixelFormat(Magnum::PixelFormat::RGBA), |
||||||
|
PixelFormat::RGBA); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
void PixelFormatTest::mapFormatUnsupported() { |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_SKIP("All pixel formats are supported on ES3+"); |
||||||
|
#else |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
pixelFormat(Magnum::PixelFormat::RGB16UI); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::pixelFormat(): format PixelFormat::RGB16UI is not supported on this target\n"); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapFormatInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
hasPixelFormat(Magnum::PixelFormat(0x123)); |
||||||
|
pixelFormat(Magnum::PixelFormat(0x123)); |
||||||
|
CORRADE_COMPARE(out.str(), |
||||||
|
"GL::hasPixelFormat(): invalid format PixelFormat(0x123)\n" |
||||||
|
"GL::pixelFormat(): invalid format PixelFormat(0x123)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapTypeImplementationSpecific() { |
||||||
|
CORRADE_COMPARE(pixelType(Magnum::pixelFormatWrap(PixelFormat::RGBA), GL_UNSIGNED_BYTE), |
||||||
|
PixelType::UnsignedByte); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapTypeImplementationSpecificZero() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
pixelType(Magnum::pixelFormatWrap(PixelFormat::RGBA)); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::pixelType(): format is implementation-specific, but no additional type specifier was passed\n"); |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void PixelFormatTest::mapTypeDeprecated() { |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
CORRADE_COMPARE(pixelType(Magnum::PixelFormat::RGBA, GL_UNSIGNED_BYTE), |
||||||
|
PixelType::UnsignedByte); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
void PixelFormatTest::mapTypeUnsupported() { |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_SKIP("All pixel formats are supported on ES3+"); |
||||||
|
#else |
||||||
|
CORRADE_VERIFY(!hasPixelFormat(Magnum::PixelFormat::RGBA16UI)); |
||||||
|
|
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
pixelType(Magnum::PixelFormat::RGB16UI); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::pixelType(): format PixelFormat::RGB16UI is not supported on this target\n"); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapTypeInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
pixelType(Magnum::PixelFormat(0x123)); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::pixelType(): invalid format PixelFormat(0x123)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::size() { |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGB, PixelType::UnsignedByte332), 1); |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::StencilIndex, PixelType::UnsignedByte), 1); |
||||||
|
#endif |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::DepthComponent, PixelType::UnsignedShort), 2); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGBA, PixelType::UnsignedShort4444), 2); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::DepthStencil, PixelType::UnsignedInt248), 4); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGBA, PixelType::UnsignedInt), 4*4); |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::DepthStencil, PixelType::Float32UnsignedInt248Rev), 8); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void PixelFormatTest::sizeDataPropertiesDeprecated() { |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::RGBA, PixelType::UnsignedShort4444), 2); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
|
||||||
|
PixelStorage storage; |
||||||
|
storage.setAlignment(4) |
||||||
|
.setRowLength(15) |
||||||
|
.setSkip({3, 7, 0}); |
||||||
|
|
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
CORRADE_COMPARE(storage.dataProperties(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i{1}), |
||||||
|
(std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::size_t>{{3*4, 7*15*4, 0}, {60, 1, 1}, 4})); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
void PixelFormatTest::sizeInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
pixelSize(PixelFormat::DepthStencil, PixelType::Float); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::pixelSize(): invalid GL::PixelType::Float specified for GL::PixelFormat::DepthStencil\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapCompressedFormat() { |
||||||
|
/* Touchstone verification */ |
||||||
|
CORRADE_VERIFY(hasCompressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm)); |
||||||
|
CORRADE_COMPARE(compressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm), CompressedPixelFormat::RGBAS3tcDxt1); |
||||||
|
|
||||||
|
/* This goes through the first 16 bits, which should be enough. Going
|
||||||
|
through 32 bits takes 8 seconds, too much. */ |
||||||
|
UnsignedInt firstUnhandled = 0xffff; |
||||||
|
UnsignedInt nextHandled = 0; |
||||||
|
for(UnsignedInt i = 0; i <= 0xffff; ++i) { |
||||||
|
const auto format = Magnum::CompressedPixelFormat(i); |
||||||
|
/* Each case verifies:
|
||||||
|
- that the cases are ordered by number (so insertion here is done in |
||||||
|
proper place) |
||||||
|
- that there was no gap (unhandled value inside the range) |
||||||
|
- that a particular pixel format maps to a particular GL format |
||||||
|
- that a particular pixel type maps to a particular GL type */ |
||||||
|
switch(format) { |
||||||
|
#define _c(format, expectedFormat) \ |
||||||
|
case Magnum::CompressedPixelFormat::format: \
|
||||||
|
CORRADE_COMPARE(nextHandled, i); \
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||||
|
CORRADE_VERIFY(hasCompressedPixelFormat(Magnum::CompressedPixelFormat::format)); \
|
||||||
|
CORRADE_COMPARE(compressedPixelFormat(Magnum::CompressedPixelFormat::format), Magnum::GL::CompressedPixelFormat::expectedFormat); \
|
||||||
|
++nextHandled; \
|
||||||
|
continue; |
||||||
|
#define _s(format) \ |
||||||
|
case Magnum::CompressedPixelFormat::format: \
|
||||||
|
CORRADE_COMPARE(nextHandled, i); \
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); \
|
||||||
|
CORRADE_VERIFY(!hasCompressedPixelFormat(Magnum::CompressedPixelFormat::format)); \
|
||||||
|
compressedPixelFormat(Magnum::CompressedPixelFormat::format); \
|
||||||
|
++nextHandled; \
|
||||||
|
continue; |
||||||
|
#include "Magnum/GL/Implementation/compressedPixelFormatMapping.hpp" |
||||||
|
#undef _s |
||||||
|
#undef _c |
||||||
|
|
||||||
|
/* Here to silence unhandled value warnings and to verify that all
|
||||||
|
GL-specific formats are larger than a particular value. This |
||||||
|
value is used in compressedPixelFormat() to detect deprecated |
||||||
|
GL-specific values and convert them properly. */ |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
#define _c(value) \ |
||||||
|
case Magnum::CompressedPixelFormat::value: \
|
||||||
|
CORRADE_VERIFY(UnsignedInt(Magnum::CompressedPixelFormat::value) >= 0x1000); \
|
||||||
|
continue; |
||||||
|
#ifdef __GNUC__ |
||||||
|
#pragma GCC diagnostic push |
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
||||||
|
#elif defined(_MSC_VER) |
||||||
|
#pragma warning(push) |
||||||
|
#pragma warning(disable: 4996) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Red) |
||||||
|
_c(RG) |
||||||
|
_c(RGB) |
||||||
|
_c(RGBA) |
||||||
|
_c(RedRgtc1) |
||||||
|
_c(RGRgtc2) |
||||||
|
_c(SignedRedRgtc1) |
||||||
|
_c(SignedRGRgtc2) |
||||||
|
_c(RGBBptcUnsignedFloat) |
||||||
|
_c(RGBBptcSignedFloat) |
||||||
|
_c(RGBABptcUnorm) |
||||||
|
_c(SRGBAlphaBptcUnorm) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(RGB8Etc2) |
||||||
|
_c(SRGB8Etc2) |
||||||
|
_c(RGB8PunchthroughAlpha1Etc2) |
||||||
|
_c(SRGB8PunchthroughAlpha1Etc2) |
||||||
|
_c(RGBA8Etc2Eac) |
||||||
|
_c(SRGB8Alpha8Etc2Eac) |
||||||
|
_c(R11Eac) |
||||||
|
_c(SignedR11Eac) |
||||||
|
_c(RG11Eac) |
||||||
|
_c(SignedRG11Eac) |
||||||
|
#endif |
||||||
|
_c(RGBS3tcDxt1) |
||||||
|
_c(RGBAS3tcDxt1) |
||||||
|
_c(RGBAS3tcDxt3) |
||||||
|
_c(RGBAS3tcDxt5) |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(RGBAAstc4x4) |
||||||
|
_c(SRGB8Alpha8Astc4x4) |
||||||
|
_c(RGBAAstc5x4) |
||||||
|
_c(SRGB8Alpha8Astc5x4) |
||||||
|
_c(RGBAAstc5x5) |
||||||
|
_c(SRGB8Alpha8Astc5x5) |
||||||
|
_c(RGBAAstc6x5) |
||||||
|
_c(SRGB8Alpha8Astc6x5) |
||||||
|
_c(RGBAAstc6x6) |
||||||
|
_c(SRGB8Alpha8Astc6x6) |
||||||
|
_c(RGBAAstc8x5) |
||||||
|
_c(SRGB8Alpha8Astc8x5) |
||||||
|
_c(RGBAAstc8x6) |
||||||
|
_c(SRGB8Alpha8Astc8x6) |
||||||
|
_c(RGBAAstc8x8) |
||||||
|
_c(SRGB8Alpha8Astc8x8) |
||||||
|
_c(RGBAAstc10x5) |
||||||
|
_c(SRGB8Alpha8Astc10x5) |
||||||
|
_c(RGBAAstc10x6) |
||||||
|
_c(SRGB8Alpha8Astc10x6) |
||||||
|
_c(RGBAAstc10x8) |
||||||
|
_c(SRGB8Alpha8Astc10x8) |
||||||
|
_c(RGBAAstc10x10) |
||||||
|
_c(SRGB8Alpha8Astc10x10) |
||||||
|
_c(RGBAAstc12x10) |
||||||
|
_c(SRGB8Alpha8Astc12x10) |
||||||
|
_c(RGBAAstc12x12) |
||||||
|
_c(SRGB8Alpha8Astc12x12) |
||||||
|
#endif |
||||||
|
#undef _c |
||||||
|
#ifdef __GNUC__ |
||||||
|
#pragma GCC diagnostic pop |
||||||
|
#elif defined(_MSC_VER) |
||||||
|
#pragma warning(pop) |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
/* Not handled by any value, remember -- we might either be at the end
|
||||||
|
of the enum range (which is okay) or some value might be unhandled |
||||||
|
here */ |
||||||
|
firstUnhandled = i; |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_COMPARE(firstUnhandled, 0xffff); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapCompressedFormatImplementationSpecific() { |
||||||
|
CORRADE_VERIFY(hasCompressedPixelFormat(Magnum::compressedPixelFormatWrap(CompressedPixelFormat::RGBAS3tcDxt1))); |
||||||
|
CORRADE_COMPARE(compressedPixelFormat(Magnum::compressedPixelFormatWrap(CompressedPixelFormat::RGBAS3tcDxt1)), |
||||||
|
CompressedPixelFormat::RGBAS3tcDxt1); |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void PixelFormatTest::mapCompressedFormatDeprecated() { |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
CORRADE_COMPARE(compressedPixelFormat(Magnum::CompressedPixelFormat::RGBAS3tcDxt1), |
||||||
|
CompressedPixelFormat::RGBAS3tcDxt1); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
void PixelFormatTest::mapCompressedFormatUnsupported() { |
||||||
|
#if 1 |
||||||
|
CORRADE_SKIP("All compressed pixel formats are currently supported everywhere"); |
||||||
|
#else |
||||||
|
CORRADE_VERIFY(!hasCompressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm)); |
||||||
|
|
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
compressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::compressedPixelFormat(): format CompressedPixelFormat::Bc1RGBAUnorm is not supported on this target\n"); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::mapCompressedFormatInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
hasCompressedPixelFormat(Magnum::CompressedPixelFormat(0x123)); |
||||||
|
compressedPixelFormat(Magnum::CompressedPixelFormat(0x123)); |
||||||
|
CORRADE_COMPARE(out.str(), |
||||||
|
"GL::hasCompressedPixelFormat(): invalid format CompressedPixelFormat(0x123)\n" |
||||||
|
"GL::compressedPixelFormat(): invalid format CompressedPixelFormat(0x123)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::debugPixelFormat() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug(&out) << PixelFormat::RGBA << PixelFormat(0xdead); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::PixelFormat::RGBA GL::PixelFormat(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::debugPixelType() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug(&out) << PixelType::UnsignedByte << PixelType(0xdead); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::PixelType::UnsignedByte GL::PixelType(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::debugCompressedPixelFormat() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug{&out} << CompressedPixelFormat::RGBS3tcDxt1 << CompressedPixelFormat(0xdead); |
||||||
|
CORRADE_COMPARE(out.str(), "GL::CompressedPixelFormat::RGBS3tcDxt1 GL::CompressedPixelFormat(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::GL::Test::PixelFormatTest) |
||||||
@ -0,0 +1,369 @@ |
|||||||
|
/*
|
||||||
|
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 "Magnum/PixelFormat.h" |
||||||
|
|
||||||
|
#include <Corrade/Utility/Assert.h> |
||||||
|
#include <Corrade/Utility/Debug.h> |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
|
||||||
|
UnsignedInt pixelSize(const PixelFormat format) { |
||||||
|
CORRADE_ASSERT(!(UnsignedInt(format) & (1 << 31)), |
||||||
|
"pixelSize(): can't determine pixel size of an implementation-specific format", {}); |
||||||
|
|
||||||
|
switch(format) { |
||||||
|
case PixelFormat::R8Unorm: |
||||||
|
case PixelFormat::R8Snorm: |
||||||
|
case PixelFormat::R8UI: |
||||||
|
case PixelFormat::R8I: |
||||||
|
return 1; |
||||||
|
case PixelFormat::RG8Unorm: |
||||||
|
case PixelFormat::RG8Snorm: |
||||||
|
case PixelFormat::RG8UI: |
||||||
|
case PixelFormat::RG8I: |
||||||
|
case PixelFormat::R16Unorm: |
||||||
|
case PixelFormat::R16Snorm: |
||||||
|
case PixelFormat::R16UI: |
||||||
|
case PixelFormat::R16I: |
||||||
|
case PixelFormat::R16F: |
||||||
|
return 2; |
||||||
|
case PixelFormat::RGB8Unorm: |
||||||
|
case PixelFormat::RGB8Snorm: |
||||||
|
case PixelFormat::RGB8UI: |
||||||
|
case PixelFormat::RGB8I: |
||||||
|
return 3; |
||||||
|
case PixelFormat::RGBA8Unorm: |
||||||
|
case PixelFormat::RGBA8Snorm: |
||||||
|
case PixelFormat::RGBA8UI: |
||||||
|
case PixelFormat::RGBA8I: |
||||||
|
case PixelFormat::RG16Unorm: |
||||||
|
case PixelFormat::RG16Snorm: |
||||||
|
case PixelFormat::RG16UI: |
||||||
|
case PixelFormat::RG16I: |
||||||
|
case PixelFormat::RG16F: |
||||||
|
case PixelFormat::R32UI: |
||||||
|
case PixelFormat::R32I: |
||||||
|
case PixelFormat::R32F: |
||||||
|
return 4; |
||||||
|
case PixelFormat::RGB16Unorm: |
||||||
|
case PixelFormat::RGB16Snorm: |
||||||
|
case PixelFormat::RGB16UI: |
||||||
|
case PixelFormat::RGB16I: |
||||||
|
case PixelFormat::RGB16F: |
||||||
|
return 6; |
||||||
|
case PixelFormat::RGBA16Unorm: |
||||||
|
case PixelFormat::RGBA16Snorm: |
||||||
|
case PixelFormat::RGBA16UI: |
||||||
|
case PixelFormat::RGBA16I: |
||||||
|
case PixelFormat::RGBA16F: |
||||||
|
case PixelFormat::RG32UI: |
||||||
|
case PixelFormat::RG32I: |
||||||
|
case PixelFormat::RG32F: |
||||||
|
return 8; |
||||||
|
case PixelFormat::RGB32UI: |
||||||
|
case PixelFormat::RGB32I: |
||||||
|
case PixelFormat::RGB32F: |
||||||
|
return 12; |
||||||
|
case PixelFormat::RGBA32UI: |
||||||
|
case PixelFormat::RGBA32I: |
||||||
|
case PixelFormat::RGBA32F: |
||||||
|
return 16; |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
case PixelFormat::Red: |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case PixelFormat::Green: |
||||||
|
case PixelFormat::Blue: |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
case PixelFormat::Luminance: |
||||||
|
#endif |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
case PixelFormat::RG: |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
case PixelFormat::LuminanceAlpha: |
||||||
|
#endif |
||||||
|
case PixelFormat::RGB: |
||||||
|
case PixelFormat::RGBA: |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case PixelFormat::BGR: |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
case PixelFormat::BGRA: |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
case PixelFormat::SRGB: |
||||||
|
case PixelFormat::SRGBAlpha: |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
case PixelFormat::RedInteger: |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case PixelFormat::GreenInteger: |
||||||
|
case PixelFormat::BlueInteger: |
||||||
|
#endif |
||||||
|
case PixelFormat::RGInteger: |
||||||
|
case PixelFormat::RGBInteger: |
||||||
|
case PixelFormat::RGBAInteger: |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
case PixelFormat::BGRInteger: |
||||||
|
case PixelFormat::BGRAInteger: |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
case PixelFormat::DepthComponent: |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
case PixelFormat::StencilIndex: |
||||||
|
#endif |
||||||
|
case PixelFormat::DepthStencil: |
||||||
|
/** @todo CORRADE_ASSERT_UNREACHABLE() with message here */ |
||||||
|
CORRADE_ASSERT(false, |
||||||
|
"pixelSize(): called with deprecated GL-specific format, use GL::pixelSize() instead", {}); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ |
||||||
|
} |
||||||
|
|
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
Debug& operator<<(Debug& debug, const PixelFormat value) { |
||||||
|
if(isPixelFormatImplementationSpecific(value)) { |
||||||
|
return debug << "PixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(pixelFormatUnwrap(value)) << Debug::nospace << ")"; |
||||||
|
} |
||||||
|
|
||||||
|
switch(value) { |
||||||
|
/* LCOV_EXCL_START */ |
||||||
|
#define _c(value) case PixelFormat::value: return debug << "PixelFormat::" #value; |
||||||
|
_c(R8Unorm) |
||||||
|
_c(RG8Unorm) |
||||||
|
_c(RGB8Unorm) |
||||||
|
_c(RGBA8Unorm) |
||||||
|
_c(R8Snorm) |
||||||
|
_c(RG8Snorm) |
||||||
|
_c(RGB8Snorm) |
||||||
|
_c(RGBA8Snorm) |
||||||
|
_c(R8UI) |
||||||
|
_c(RG8UI) |
||||||
|
_c(RGB8UI) |
||||||
|
_c(RGBA8UI) |
||||||
|
_c(R8I) |
||||||
|
_c(RG8I) |
||||||
|
_c(RGB8I) |
||||||
|
_c(RGBA8I) |
||||||
|
_c(R16Unorm) |
||||||
|
_c(RG16Unorm) |
||||||
|
_c(RGB16Unorm) |
||||||
|
_c(RGBA16Unorm) |
||||||
|
_c(R16Snorm) |
||||||
|
_c(RG16Snorm) |
||||||
|
_c(RGB16Snorm) |
||||||
|
_c(RGBA16Snorm) |
||||||
|
_c(R16UI) |
||||||
|
_c(RG16UI) |
||||||
|
_c(RGB16UI) |
||||||
|
_c(RGBA16UI) |
||||||
|
_c(R16I) |
||||||
|
_c(RG16I) |
||||||
|
_c(RGB16I) |
||||||
|
_c(RGBA16I) |
||||||
|
_c(R32UI) |
||||||
|
_c(RG32UI) |
||||||
|
_c(RGB32UI) |
||||||
|
_c(RGBA32UI) |
||||||
|
_c(R32I) |
||||||
|
_c(RG32I) |
||||||
|
_c(RGB32I) |
||||||
|
_c(RGBA32I) |
||||||
|
_c(R16F) |
||||||
|
_c(RG16F) |
||||||
|
_c(RGB16F) |
||||||
|
_c(RGBA16F) |
||||||
|
_c(R32F) |
||||||
|
_c(RG32F) |
||||||
|
_c(RGB32F) |
||||||
|
_c(RGBA32F) |
||||||
|
#undef _c |
||||||
|
|
||||||
|
/* Verbatim copy from GL/PixelFormat.cpp. Here mainly to suppress
|
||||||
|
compiler warnings about unhandled cases, to check that all values |
||||||
|
from the original enum are present and also to check that there are |
||||||
|
no accidentally conflicting values. */ |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
#define _c(value) case PixelFormat::value: return debug << "GL::PixelFormat::" #value; |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
_c(Red) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Green) |
||||||
|
_c(Blue) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(Luminance) |
||||||
|
#endif |
||||||
|
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
||||||
|
_c(RG) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(LuminanceAlpha) |
||||||
|
#endif |
||||||
|
_c(RGB) |
||||||
|
_c(RGBA) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(BGR) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(BGRA) |
||||||
|
#endif |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
_c(SRGB) |
||||||
|
_c(SRGBAlpha) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(RedInteger) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(GreenInteger) |
||||||
|
_c(BlueInteger) |
||||||
|
#endif |
||||||
|
_c(RGInteger) |
||||||
|
_c(RGBInteger) |
||||||
|
_c(RGBAInteger) |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(BGRInteger) |
||||||
|
_c(BGRAInteger) |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
_c(DepthComponent) |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(StencilIndex) |
||||||
|
#endif |
||||||
|
_c(DepthStencil) |
||||||
|
#undef _c |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
#endif |
||||||
|
/* LCOV_EXCL_STOP */ |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "PixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")"; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
Debug& operator<<(Debug& debug, const CompressedPixelFormat value) { |
||||||
|
if(isCompressedPixelFormatImplementationSpecific(value)) { |
||||||
|
return debug << "CompressedPixelFormat::ImplementationSpecific(" << Debug::nospace << reinterpret_cast<void*>(compressedPixelFormatUnwrap(value)) << Debug::nospace << ")"; |
||||||
|
} |
||||||
|
|
||||||
|
switch(value) { |
||||||
|
/* LCOV_EXCL_START */ |
||||||
|
#define _c(value) case CompressedPixelFormat::value: return debug << "CompressedPixelFormat::" #value; |
||||||
|
_c(Bc1RGBUnorm) |
||||||
|
_c(Bc1RGBAUnorm) |
||||||
|
_c(Bc2RGBAUnorm) |
||||||
|
_c(Bc3RGBAUnorm) |
||||||
|
#undef _c |
||||||
|
|
||||||
|
/* Verbatim copy from GL/PixelFormat.cpp. Here mainly to suppress
|
||||||
|
compiler warnings about unhandled cases, to check that all values |
||||||
|
from the original enum are present and also to check that there are |
||||||
|
no accidentally conflicting values. */ |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
#define _c(value) case CompressedPixelFormat::value: return debug << "GL::CompressedPixelFormat::" #value; |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
_c(Red) |
||||||
|
_c(RG) |
||||||
|
_c(RGB) |
||||||
|
_c(RGBA) |
||||||
|
_c(RedRgtc1) |
||||||
|
_c(RGRgtc2) |
||||||
|
_c(SignedRedRgtc1) |
||||||
|
_c(SignedRGRgtc2) |
||||||
|
_c(RGBBptcUnsignedFloat) |
||||||
|
_c(RGBBptcSignedFloat) |
||||||
|
_c(RGBABptcUnorm) |
||||||
|
_c(SRGBAlphaBptcUnorm) |
||||||
|
#endif |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
_c(RGB8Etc2) |
||||||
|
_c(SRGB8Etc2) |
||||||
|
_c(RGB8PunchthroughAlpha1Etc2) |
||||||
|
_c(SRGB8PunchthroughAlpha1Etc2) |
||||||
|
_c(RGBA8Etc2Eac) |
||||||
|
_c(SRGB8Alpha8Etc2Eac) |
||||||
|
_c(R11Eac) |
||||||
|
_c(SignedR11Eac) |
||||||
|
_c(RG11Eac) |
||||||
|
_c(SignedRG11Eac) |
||||||
|
#endif |
||||||
|
_c(RGBS3tcDxt1) |
||||||
|
_c(RGBAS3tcDxt1) |
||||||
|
_c(RGBAS3tcDxt3) |
||||||
|
_c(RGBAS3tcDxt5) |
||||||
|
#ifndef MAGNUM_TARGET_WEBGL |
||||||
|
_c(RGBAAstc4x4) |
||||||
|
_c(SRGB8Alpha8Astc4x4) |
||||||
|
_c(RGBAAstc5x4) |
||||||
|
_c(SRGB8Alpha8Astc5x4) |
||||||
|
_c(RGBAAstc5x5) |
||||||
|
_c(SRGB8Alpha8Astc5x5) |
||||||
|
_c(RGBAAstc6x5) |
||||||
|
_c(SRGB8Alpha8Astc6x5) |
||||||
|
_c(RGBAAstc6x6) |
||||||
|
_c(SRGB8Alpha8Astc6x6) |
||||||
|
_c(RGBAAstc8x5) |
||||||
|
_c(SRGB8Alpha8Astc8x5) |
||||||
|
_c(RGBAAstc8x6) |
||||||
|
_c(SRGB8Alpha8Astc8x6) |
||||||
|
_c(RGBAAstc8x8) |
||||||
|
_c(SRGB8Alpha8Astc8x8) |
||||||
|
_c(RGBAAstc10x5) |
||||||
|
_c(SRGB8Alpha8Astc10x5) |
||||||
|
_c(RGBAAstc10x6) |
||||||
|
_c(SRGB8Alpha8Astc10x6) |
||||||
|
_c(RGBAAstc10x8) |
||||||
|
_c(SRGB8Alpha8Astc10x8) |
||||||
|
_c(RGBAAstc10x10) |
||||||
|
_c(SRGB8Alpha8Astc10x10) |
||||||
|
_c(RGBAAstc12x10) |
||||||
|
_c(SRGB8Alpha8Astc12x10) |
||||||
|
_c(RGBAAstc12x12) |
||||||
|
_c(SRGB8Alpha8Astc12x12) |
||||||
|
#undef _c |
||||||
|
#endif |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
#endif |
||||||
|
/* LCOV_EXCL_STOP */ |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "CompressedPixelFormat(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")"; |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,216 @@ |
|||||||
|
/*
|
||||||
|
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/TestSuite/Tester.h> |
||||||
|
|
||||||
|
#include "Magnum/PixelFormat.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Test { |
||||||
|
|
||||||
|
struct PixelFormatTest: TestSuite::Tester { |
||||||
|
explicit PixelFormatTest(); |
||||||
|
|
||||||
|
void size(); |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void sizeDeprecated(); |
||||||
|
#endif |
||||||
|
void sizeImplementationSpecific(); |
||||||
|
|
||||||
|
void isImplementationSpecific(); |
||||||
|
void wrap(); |
||||||
|
void wrapInvalid(); |
||||||
|
void unwrap(); |
||||||
|
void unwrapInvalid(); |
||||||
|
|
||||||
|
void compressedIsImplementationSpecific(); |
||||||
|
void compressedWrap(); |
||||||
|
void compressedWrapInvalid(); |
||||||
|
void compressedUnwrap(); |
||||||
|
void compressedUnwrapInvalid(); |
||||||
|
|
||||||
|
void debug(); |
||||||
|
void debugImplementationSpecific(); |
||||||
|
|
||||||
|
void compressedDebug(); |
||||||
|
void compressedDebugImplementationSpecific(); |
||||||
|
}; |
||||||
|
|
||||||
|
PixelFormatTest::PixelFormatTest() { |
||||||
|
addTests({&PixelFormatTest::size, |
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
&PixelFormatTest::sizeDeprecated, |
||||||
|
#endif |
||||||
|
&PixelFormatTest::sizeImplementationSpecific, |
||||||
|
|
||||||
|
&PixelFormatTest::isImplementationSpecific, |
||||||
|
&PixelFormatTest::wrap, |
||||||
|
&PixelFormatTest::wrapInvalid, |
||||||
|
&PixelFormatTest::unwrap, |
||||||
|
&PixelFormatTest::unwrapInvalid, |
||||||
|
|
||||||
|
&PixelFormatTest::compressedIsImplementationSpecific, |
||||||
|
&PixelFormatTest::compressedWrap, |
||||||
|
&PixelFormatTest::compressedWrapInvalid, |
||||||
|
&PixelFormatTest::compressedUnwrap, |
||||||
|
&PixelFormatTest::compressedUnwrapInvalid, |
||||||
|
|
||||||
|
&PixelFormatTest::debug, |
||||||
|
&PixelFormatTest::debugImplementationSpecific, |
||||||
|
|
||||||
|
&PixelFormatTest::compressedDebug, |
||||||
|
&PixelFormatTest::compressedDebugImplementationSpecific}); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::size() { |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::R8I), 1); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::R16UI), 2); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGB8Unorm), 3); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGBA8Snorm), 4); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGB16I), 6); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGBA16F), 8); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGB32UI), 12); |
||||||
|
CORRADE_COMPARE(pixelSize(PixelFormat::RGBA32F), 16); |
||||||
|
} |
||||||
|
|
||||||
|
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) |
||||||
|
void PixelFormatTest::sizeDeprecated() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
CORRADE_IGNORE_DEPRECATED_PUSH |
||||||
|
pixelSize(PixelFormat::RGBA); |
||||||
|
CORRADE_IGNORE_DEPRECATED_POP |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "pixelSize(): called with deprecated GL-specific format, use GL::pixelSize() instead\n"); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
void PixelFormatTest::sizeImplementationSpecific() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
pixelSize(pixelFormatWrap(0xdead)); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "pixelSize(): can't determine pixel size of an implementation-specific format\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::isImplementationSpecific() { |
||||||
|
constexpr bool a = isPixelFormatImplementationSpecific(PixelFormat::RGBA8Unorm); |
||||||
|
constexpr bool b = isPixelFormatImplementationSpecific(PixelFormat(0x8000dead)); |
||||||
|
CORRADE_VERIFY(!a); |
||||||
|
CORRADE_VERIFY(b); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::wrap() { |
||||||
|
constexpr PixelFormat a = pixelFormatWrap(0xdead); |
||||||
|
CORRADE_COMPARE(UnsignedInt(a), 0x8000dead); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::wrapInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
pixelFormatWrap(0xdeadbeef); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "pixelFormatWrap(): implementation-specific value already wrapped or too large\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::unwrap() { |
||||||
|
constexpr UnsignedInt a = pixelFormatUnwrap(PixelFormat(0x8000dead)); |
||||||
|
CORRADE_COMPARE(a, 0xdead); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::unwrapInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
pixelFormatUnwrap(PixelFormat(0xdead)); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "pixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedIsImplementationSpecific() { |
||||||
|
CORRADE_VERIFY(!isPixelFormatImplementationSpecific(PixelFormat::RGBA8Unorm)); |
||||||
|
CORRADE_VERIFY(isPixelFormatImplementationSpecific(pixelFormatWrap(0xdead))); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedWrap() { |
||||||
|
CORRADE_COMPARE(UnsignedInt(pixelFormatWrap(0xdead)), 0x8000dead); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedWrapInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
compressedPixelFormatWrap(0xdeadbeef); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "compressedPixelFormatWrap(): implementation-specific value already wrapped or too large\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedUnwrap() { |
||||||
|
CORRADE_COMPARE(UnsignedInt(compressedPixelFormatUnwrap(CompressedPixelFormat(0x8000dead))), 0xdead); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedUnwrapInvalid() { |
||||||
|
std::ostringstream out; |
||||||
|
Error redirectError{&out}; |
||||||
|
|
||||||
|
compressedPixelFormatUnwrap(CompressedPixelFormat(0xdead)); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "compressedPixelFormatUnwrap(): format doesn't contain a wrapped implementation-specific value\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::debug() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug{&out} << PixelFormat::RG16Snorm << PixelFormat(0xdead); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "PixelFormat::RG16Snorm PixelFormat(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::debugImplementationSpecific() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug{&out} << pixelFormatWrap(0xdead); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "PixelFormat::ImplementationSpecific(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedDebug() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug{&out} << CompressedPixelFormat::Bc3RGBAUnorm << CompressedPixelFormat(0xdead); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "CompressedPixelFormat::Bc3RGBAUnorm CompressedPixelFormat(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void PixelFormatTest::compressedDebugImplementationSpecific() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug{&out} << compressedPixelFormatWrap(0xdead); |
||||||
|
|
||||||
|
CORRADE_COMPARE(out.str(), "CompressedPixelFormat::ImplementationSpecific(0xdead)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Test::PixelFormatTest) |
||||||
Loading…
Reference in new issue