Browse Source

Vk: functions for translating generic enums to Vulkan values.

Because I don't yet have any source file that's assert-independent, the
MagnumVkObjects library is commented out, as it is completely empty
right now.
pull/297/head
Vladimír Vondruš 8 years ago
parent
commit
b0a1719eb4
  1. 13
      doc/changelog.dox
  2. 4
      src/Magnum/GL/Test/PixelFormatTest.cpp
  3. 40
      src/Magnum/Mesh.h
  4. 166
      src/Magnum/PixelFormat.h
  5. 45
      src/Magnum/Sampler.h
  6. 60
      src/Magnum/Vk/CMakeLists.txt
  7. 192
      src/Magnum/Vk/Enums.cpp
  8. 195
      src/Magnum/Vk/Enums.h
  9. 32
      src/Magnum/Vk/Implementation/compressedFormatMapping.hpp
  10. 76
      src/Magnum/Vk/Implementation/formatMapping.hpp
  11. 2
      src/Magnum/Vk/Test/CMakeLists.txt
  12. 406
      src/Magnum/Vk/Test/EnumsTest.cpp

13
doc/changelog.dox

@ -230,6 +230,19 @@ See also:
- @ref Trade::AnySceneImporter "AnySceneImporter" gained support for
animation import
@subsubsection changelog-latest-new-vk Vk library
- New @ref Vk library that'll be the home of a Vulkan graphics backend in the
future
- New functions @ref Vk::hasVkPrimitiveTopology(),
@ref Vk::vkPrimitiveTopology(), @ref Vk::hasVkIndexType(),
@ref Vk::vkIndexType(), @ref Vk::hasVkFormat(), @ref Vk::vkFormat(),
@ref Vk::vkFilter(), @ref Vk::vkSamplerMipmapMode(),
@ref Vk::hasVkSamplerAddressMode(), @ref Vk::vkSamplerAddressMode() for
converting generic @ref MeshPrimitive, @ref MeshIndexType,
@ref PixelFormat, @ref CompressedPixelFormat, @ref SamplerFilter,
@ref SamplerMipmap and @ref SamplerWrapping enums to Vulkan-specific values
@subsection changelog-latest-changes Changes and improvements
@subsubsection changelog-latest-changes-audio Audio library

4
src/Magnum/GL/Test/PixelFormatTest.cpp

@ -237,7 +237,7 @@ void PixelFormatTest::mapFormatDeprecated() {
void PixelFormatTest::mapFormatUnsupported() {
#ifndef MAGNUM_TARGET_GLES2
CORRADE_SKIP("All pixel formats are supported on ES3+");
CORRADE_SKIP("All pixel formats are supported on ES3+.");
#else
std::ostringstream out;
Error redirectError{&out};
@ -480,7 +480,7 @@ void PixelFormatTest::mapCompressedFormatDeprecated() {
void PixelFormatTest::mapCompressedFormatUnsupported() {
#if 1
CORRADE_SKIP("All compressed pixel formats are currently supported everywhere");
CORRADE_SKIP("All compressed pixel formats are currently supported everywhere.");
#else
CORRADE_VERIFY(!hasCompressedPixelFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm));

40
src/Magnum/Mesh.h

@ -46,12 +46,18 @@ namespace Magnum {
In case of OpenGL, corresponds to @ref GL::MeshPrimitive and is convertible to
it using @ref GL::meshPrimitive(). See documentation of each value for more
information about the mapping.
In case of Vulkan, corresponds to @type_vk_keyword{PrimitiveTopology} and is
convertible to it using @ref Vk::vkPrimitiveTopology(). See documentation of
each value for more information about the mapping. Note that not every mode is available there, use @ref Vk::hasVkPrimitiveTopology() to check for its
presence.
*/
enum class MeshPrimitive: UnsignedInt {
/**
* Single points.
*
* Corresponds to @ref GL::MeshPrimitive::Points.
* Corresponds to @ref GL::MeshPrimitive::Points /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_POINT_LIST,PrimitiveTopology}.
*/
Points,
@ -59,14 +65,16 @@ enum class MeshPrimitive: UnsignedInt {
* Each pair of vertices defines a single line, lines aren't
* connected together.
*
* Corresponds to @ref GL::MeshPrimitive::Lines.
* Corresponds to @ref GL::MeshPrimitive::Lines /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_LINE_LIST,PrimitiveTopology}.
*/
Lines,
/**
* Line strip, last and first vertex are connected together.
*
* Corresponds to @ref GL::MeshPrimitive::LineLoop.
* Corresponds to @ref GL::MeshPrimitive::LineLoop. Not supported on
* Vulkan.
*/
LineLoop,
@ -74,14 +82,16 @@ enum class MeshPrimitive: UnsignedInt {
* First two vertices define first line segment, each following
* vertex defines another segment.
*
* Corresponds to @ref GL::MeshPrimitive::LineStrip.
* Corresponds to @ref GL::MeshPrimitive::LineStrip /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_LINE_STRIP,PrimitiveTopology}.
*/
LineStrip,
/**
* Each three vertices define one triangle.
*
* Corresponds to @ref GL::MeshPrimitive::Triangles.
* Corresponds to @ref GL::MeshPrimitive::Triangles /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,PrimitiveTopology}.
*/
Triangles,
@ -89,7 +99,8 @@ enum class MeshPrimitive: UnsignedInt {
* First three vertices define first triangle, each following
* vertex defines another triangle.
*
* Corresponds to @ref GL::MeshPrimitive::TriangleStrip.
* Corresponds to @ref GL::MeshPrimitive::TriangleStrip /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,PrimitiveTopology}.
*/
TriangleStrip,
@ -97,7 +108,8 @@ enum class MeshPrimitive: UnsignedInt {
* First vertex is center, each following vertex is connected to
* previous and center vertex.
*
* Corresponds to @ref GL::MeshPrimitive::TriangleFan.
* Corresponds to @ref GL::MeshPrimitive::TriangleFan /
* @def_vk_keyword{PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,PrimitiveTopology}.
*/
TriangleFan,
@ -143,27 +155,35 @@ MAGNUM_EXPORT Debug& operator<<(Debug& debug, MeshPrimitive value);
In case of OpenGL, corresponds to @ref GL::MeshIndexType and is convertible to
it using @ref GL::meshIndexType(). See documentation of each value for more
information about the mapping.
In case of Vulkan, corresponds to @type_vk_keyword{IndexType} and is
convertible to it using @ref Vk::vkIndexType(). See documentation of each value
for more information about the mapping. Note that not every type is available
there, use @ref Vk::hasVkIndexType() to check for its presence.
@see @ref meshIndexTypeSize()
*/
enum class MeshIndexType: UnsignedInt {
/**
* Unsigned byte
*
* Corresponds to @ref GL::MeshIndexType::UnsignedByte.
* Corresponds to @ref GL::MeshIndexType::UnsignedByte. Not available on
* Vulkan.
*/
UnsignedByte,
/**
* Unsigned short
*
* Corresponds to @ref GL::MeshIndexType::UnsignedShort.
* Corresponds to @ref GL::MeshIndexType::UnsignedShort /
* @def_vk_keyword{INDEX_TYPE_UINT16,IndexType}.
*/
UnsignedShort,
/**
* Unsigned int
*
* Corresponds to @ref GL::MeshIndexType::UnsignedInt.
* Corresponds to @ref GL::MeshIndexType::UnsignedInt /
* @def_vk_keyword{INDEX_TYPE_UINT32,IndexType}.
*/
UnsignedInt
};

166
src/Magnum/PixelFormat.h

@ -54,6 +54,11 @@ and is convertible to them using @ref GL::pixelFormat() and
about the mapping. Note that not every format is available on all targets, use
@ref GL::hasPixelFormat() to check for its presence.
In case of Vulkan, corresponds to @type_vk_keyword{Format} and is convertible
to it using @ref Vk::vkFormat(Magnum::PixelFormat). See documentation of each
value for more information about the mapping. Note that not every format may be
available, use @ref Vk::hasVkFormat(Magnum::PixelFormat) to check for its
presence.
@see @ref pixelSize(), @ref CompressedPixelFormat, @ref Image, @ref ImageView
*/
enum class PixelFormat: UnsignedInt {
@ -61,7 +66,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, normalized unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::R8.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::R8 /
* @def_vk_keyword{FORMAT_R8_UNORM,Format}.
*/
R8Unorm,
@ -69,7 +75,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, normalized unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RG8.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RG8 /
* @def_vk_keyword{FORMAT_R8G8_UNORM,Format}.
*/
RG8Unorm,
@ -77,7 +84,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, normalized unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGB8.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGB8 /
* @def_vk_keyword{FORMAT_R8G8B8_UNORM,Format}.
*/
RGB8Unorm,
@ -85,7 +93,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, normalized unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGBA8.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGBA8 /
* @def_vk_keyword{FORMAT_R8G8B8A8_UNORM,Format}.
*/
RGBA8Unorm,
@ -93,7 +102,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, normalized signed byte.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::R8Snorm.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::R8Snorm /
* @def_vk_keyword{FORMAT_R8_SNORM,Format}.
*/
R8Snorm,
@ -101,7 +111,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, normalized signed byte.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RG8Snorm.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RG8Snorm /
* @def_vk_keyword{FORMAT_R8G8_SNORM,Format}.
*/
RG8Snorm,
@ -109,7 +120,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, normalized signed byte.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGB8Snorm.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGB8Snorm /
* @def_vk_keyword{FORMAT_R8G8B8_SNORM,Format}.
*/
RGB8Snorm,
@ -117,7 +129,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, normalized signed byte.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGBA8Snorm.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGBA8Snorm /
* @def_vk_keyword{FORMAT_R8G8B8A8_SNORM,Format}.
*/
RGBA8Snorm,
@ -125,7 +138,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::R8UI.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::R8UI /
* @def_vk_keyword{FORMAT_R8_UINT,Format}.
*/
R8UI,
@ -133,7 +147,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RG8UI.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RG8UI /
* @def_vk_keyword{FORMAT_R8G8_UINT,Format}.
*/
RG8UI,
@ -141,7 +156,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGB8UI.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGB8UI /
* @def_vk_keyword{FORMAT_R8G8B8_UINT,Format}.
*/
RGB8UI,
@ -149,7 +165,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral unsigned byte.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGBA8UI.
* @ref GL::PixelType::UnsignedByte, @ref GL::TextureFormat::RGBA8UI /
* @def_vk_keyword{FORMAT_R8G8B8A8_UINT,Format}.
*/
RGBA8UI,
@ -157,7 +174,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral signed byte.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::R8I.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::R8I /
* @def_vk_keyword{FORMAT_R8_SINT,Format}.
*/
R8I,
@ -165,7 +183,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral signed byte.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RG8I.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RG8I /
* @def_vk_keyword{FORMAT_R8G8_SINT,Format}.
*/
RG8I,
@ -173,7 +192,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral signed byte.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGB8I.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGB8I /
* @def_vk_keyword{FORMAT_R8G8B8_SINT,Format}.
*/
RGB8I,
@ -181,7 +201,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral signed byte.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGBA8I.
* @ref GL::PixelType::Byte, @ref GL::TextureFormat::RGBA8I /
* @def_vk_keyword{FORMAT_R8G8B8A8_SINT,Format}.
*/
RGBA8I,
@ -189,7 +210,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, normalized unsigned short.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::R16.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::R16 /
* @def_vk_keyword{FORMAT_R16_UNORM,Format}.
*/
R16Unorm,
@ -197,7 +219,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, normalized unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RG16.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RG16 /
* @def_vk_keyword{FORMAT_R16G16_UNORM,Format}.
*/
RG16Unorm,
@ -205,7 +228,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, normalized unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGB16.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGB16 /
* @def_vk_keyword{FORMAT_R16G16B16_UNORM,Format}.
*/
RGB16Unorm,
@ -213,7 +237,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, normalized unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGBA16.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGBA16 /
* @def_vk_keyword{FORMAT_R16G16B16A16_UNORM,Format}.
*/
RGBA16Unorm,
@ -221,7 +246,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, normalized signed short.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::R16Snorm.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::R16Snorm /
* @def_vk_keyword{FORMAT_R16_SNORM,Format}.
*/
R16Snorm,
@ -229,7 +255,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, normalized signed short.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RG16Snorm.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RG16Snorm /
* @def_vk_keyword{FORMAT_R16G16_SNORM,Format}.
*/
RG16Snorm,
@ -237,7 +264,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, normalized signed short.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGB16Snorm.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGB16Snorm /
* @def_vk_keyword{FORMAT_R16G16B16_SNORM,Format}.
*/
RGB16Snorm,
@ -245,7 +273,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, normalized signed short.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGBA16Snorm.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGBA16Snorm /
* @def_vk_keyword{FORMAT_R16G16B16A16_SNORM,Format}.
*/
RGBA16Snorm,
@ -253,7 +282,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::R16UI.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::R16UI /
* @def_vk_keyword{FORMAT_R16_UINT,Format}.
*/
R16UI,
@ -261,7 +291,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RG16UI.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RG16UI /
* @def_vk_keyword{FORMAT_R16G16_UINT,Format}.
*/
RG16UI,
@ -269,7 +300,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGB16UI.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGB16UI /
* @def_vk_keyword{FORMAT_R16G16B16_UINT,Format}.
*/
RGB16UI,
@ -277,7 +309,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral unsigned short.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGBA16UI.
* @ref GL::PixelType::UnsignedShort, @ref GL::TextureFormat::RGBA16UI /
* @def_vk_keyword{FORMAT_R16G16B16A16_UINT,Format}.
*/
RGBA16UI,
@ -285,7 +318,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral signed short.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::R16I.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::R16I /
* @def_vk_keyword{FORMAT_R16_SINT,Format}.
*/
R16I,
@ -293,7 +327,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral signed short.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RG16I.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RG16I /
* @def_vk_keyword{FORMAT_R16G16_SINT,Format}.
*/
RG16I,
@ -301,7 +336,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral signed short.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGB16I.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGB16I /
* @def_vk_keyword{FORMAT_R16G16B16_SINT,Format}.
*/
RGB16I,
@ -309,7 +345,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral signed short.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGBA16I.
* @ref GL::PixelType::Short, @ref GL::TextureFormat::RGBA16I /
* @def_vk_keyword{FORMAT_R16G16B16A16_SINT,Format}.
*/
RGBA16I,
@ -317,7 +354,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral unsigned int.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::R32UI.
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::R32UI /
* @def_vk_keyword{FORMAT_R32_UINT,Format}.
*/
R32UI,
@ -325,7 +363,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral unsigned int.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RG32UI.
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RG32UI /
* @def_vk_keyword{FORMAT_R32G32_UINT,Format}.
*/
RG32UI,
@ -333,7 +372,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral unsigned int.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RGB32UI.
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RGB32UI /
* @def_vk_keyword{FORMAT_R32G32B32_UINT,Format}.
*/
RGB32UI,
@ -341,7 +381,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral unsigned int.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RGBA32UI.
* @ref GL::PixelType::UnsignedInt, @ref GL::TextureFormat::RGBA32UI /
* @def_vk_keyword{FORMAT_R32G32B32A32_UINT,Format}.
*/
RGBA32UI,
@ -349,7 +390,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, integral signed int.
*
* Corresponds to @ref GL::PixelFormat::RedInteger and
* @ref GL::PixelType::Int, @ref GL::TextureFormat::R32I.
* @ref GL::PixelType::Int, @ref GL::TextureFormat::R32I /
* @def_vk_keyword{FORMAT_R32_SINT,Format}.
*/
R32I,
@ -357,7 +399,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, integral signed int.
*
* Corresponds to @ref GL::PixelFormat::RGInteger and
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RG32I.
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RG32I /
* @def_vk_keyword{FORMAT_R32G32_SINT,Format}.
*/
RG32I,
@ -365,7 +408,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, integral signed int.
*
* Corresponds to @ref GL::PixelFormat::RGBInteger and
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RGB32I.
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RGB32I /
* @def_vk_keyword{FORMAT_R32G32B32_SINT,Format}.
*/
RGB32I,
@ -373,7 +417,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, integral signed int.
*
* Corresponds to @ref GL::PixelFormat::RGBAInteger and
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RGBA32I.
* @ref GL::PixelType::Int, @ref GL::TextureFormat::RGBA32I /
* @def_vk_keyword{FORMAT_R32G32B32A32_SINT,Format}.
*/
RGBA32I,
@ -381,7 +426,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, half float.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::R16F.
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::R16F /
* @def_vk_keyword{FORMAT_R16_SFLOAT,Format}.
* @see @ref Half, @ref Math::packHalf(), @ref Math::unpackHalf()
*/
R16F,
@ -390,7 +436,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, half float.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RG16F.
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RG16F /
* @def_vk_keyword{FORMAT_R16G16_SFLOAT,Format}.
* @see @ref Half, @ref Math::packHalf(), @ref Math::unpackHalf()
*/
RG16F,
@ -399,7 +446,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, half float.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RGB16F.
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RGB16F /
* @def_vk_keyword{FORMAT_R16G16B16_SFLOAT,Format}.
* @see @ref Half, @ref Math::packHalf(), @ref Math::unpackHalf()
*/
RGB16F,
@ -408,7 +456,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, half float.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RGBA16F.
* @ref GL::PixelType::HalfFloat, @ref GL::TextureFormat::RGBA16F /
* @def_vk_keyword{FORMAT_R16G16B16A16_SFLOAT,Format}.
* @see @ref Half, @ref Math::packHalf(), @ref Math::unpackHalf()
*/
RGBA16F,
@ -417,7 +466,8 @@ enum class PixelFormat: UnsignedInt {
* Red component, half float.
*
* Corresponds to @ref GL::PixelFormat::Red and
* @ref GL::PixelType::Float, @ref GL::TextureFormat::R32F.
* @ref GL::PixelType::Float, @ref GL::TextureFormat::R32F /
* @def_vk_keyword{FORMAT_R32_SFLOAT,Format}.
*/
R32F,
@ -425,7 +475,8 @@ enum class PixelFormat: UnsignedInt {
* Red and green component, half float.
*
* Corresponds to @ref GL::PixelFormat::RG and
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RG32F.
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RG32F /
* @def_vk_keyword{FORMAT_R32G32_SFLOAT,Format}.
*/
RG32F,
@ -433,7 +484,8 @@ enum class PixelFormat: UnsignedInt {
* RGB, half float.
*
* Corresponds to @ref GL::PixelFormat::RGB and
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RGB32F.
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RGB32F /
* @def_vk_keyword{FORMAT_R32G32B32_SFLOAT,Format}.
*/
RGB32F,
@ -441,7 +493,8 @@ enum class PixelFormat: UnsignedInt {
* RGBA, half float.
*
* Corresponds to @ref GL::PixelFormat::RGBA and
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RGBA32F.
* @ref GL::PixelType::Float, @ref GL::TextureFormat::RGBA32F /
* @def_vk_keyword{FORMAT_R32G32B32A32_SFLOAT,Format}.
*/
RGBA32F,
@ -709,6 +762,11 @@ each value for more information about the mapping. Note that not every format
is available on all targets, use @ref GL::hasCompressedPixelFormat() to check
for its presence.
In case of Vulkan, corresponds to @type_vk_keyword{Format} and is convertible
to it using @ref Vk::vkFormat(Magnum::CompressedPixelFormat). See documentation
of each value for more information about the mapping. Note that not every
format may be available, use @ref Vk::hasVkFormat(Magnum::CompressedPixelFormat)
to check for its presence.
@see @ref PixelFormat, @ref CompressedImage, @ref CompressedImageView
*/
enum class CompressedPixelFormat: UnsignedInt {
@ -716,7 +774,8 @@ enum class CompressedPixelFormat: UnsignedInt {
* S3TC BC1 compressed RGB (DXT1).
*
* Corresponds to @ref GL::CompressedPixelFormat::RGBS3tcDxt1,
* @ref GL::TextureFormat::RGBS3tcDxt1.
* @ref GL::TextureFormat::RGBS3tcDxt1 /
* @def_vk_keyword{FORMAT_BC1_RGB_UNORM_BLOCK,Format}.
*/
Bc1RGBUnorm,
@ -724,7 +783,8 @@ enum class CompressedPixelFormat: UnsignedInt {
* S3TC BC1 compressed RGBA (DXT1).
*
* Corresponds to @ref GL::CompressedPixelFormat::RGBAS3tcDxt1,
* @ref GL::TextureFormat::RGBAS3tcDxt1.
* @ref GL::TextureFormat::RGBAS3tcDxt1 /
* @def_vk_keyword{FORMAT_BC1_RGBA_UNORM_BLOCK,Format}.
*/
Bc1RGBAUnorm,
@ -732,7 +792,8 @@ enum class CompressedPixelFormat: UnsignedInt {
* S3TC BC2 compressed RGBA (DXT3).
*
* Corresponds to @ref GL::CompressedPixelFormat::RGBAS3tcDxt3,
* @ref GL::TextureFormat::RGBAS3tcDxt3.
* @ref GL::TextureFormat::RGBAS3tcDxt3 /
* @def_vk_keyword{FORMAT_BC2_UNORM_BLOCK,Format}.
*/
Bc2RGBAUnorm,
@ -740,7 +801,8 @@ enum class CompressedPixelFormat: UnsignedInt {
* S3TC BC3 compressed RGBA (DXT5).
*
* Corresponds to @ref GL::CompressedPixelFormat::RGBAS3tcDxt5,
* @ref GL::TextureFormat::RGBAS3tcDxt5.
* @ref GL::TextureFormat::RGBAS3tcDxt5 /
* @def_vk_keyword{FORMAT_BC3_UNORM_BLOCK,Format}.
*/
Bc3RGBAUnorm,

45
src/Magnum/Sampler.h

@ -44,20 +44,26 @@ namespace Magnum {
In case of OpenGL, corresponds to @ref GL::SamplerFilter and is convertible to
it using @ref GL::samplerFilter(). See documentation of each value for more
information about the mapping.
In case of Vulkan, corresponds to @type_vk_keyword{Filter} and is convertible
to it using @ref Vk::vkFilter(). See documentation of each value for more
information about the mapping.
@see @ref SamplerMipmap, @ref SamplerWrapping
*/
enum class SamplerFilter: UnsignedInt {
/**
* Nearest neighbor filtering.
*
* Corresponds to @ref GL::SamplerFilter::Nearest.
* Corresponds to @ref GL::SamplerFilter::Nearest /
* @def_vk_keyword{FILTER_NEAREST,Filter}.
*/
Nearest,
/**
* Linear interpolation filtering.
*
* Corresponds to @ref GL::SamplerFilter::Linear.
* Corresponds to @ref GL::SamplerFilter::Linear /
* @def_vk_keyword{FILTER_LINEAR,Filter}.
*/
Linear
};
@ -68,27 +74,36 @@ enum class SamplerFilter: UnsignedInt {
In case of OpenGL, corresponds to @ref GL::SamplerMipmap and is convertible to
it using @ref GL::samplerMipmap(). See documentation of each value for more
information about the mapping.
In case of Vulkan, corresponds to @type_vk_keyword{SamplerMipmapMode} and is
convertible to it using @ref Vk::vkSamplerMipmapMode(). See documentation of
each value for more information about the mapping.
@see @ref SamplerFilter, @ref SamplerWrapping
*/
enum class SamplerMipmap: UnsignedInt {
/**
* Select base mip level
*
* Corresponds to @ref GL::SamplerMipmap::Base.
* Corresponds to @ref GL::SamplerMipmap::Base. On Vulkan, the
* corresponding mode is
* @def_vk_keyword{SAMPLER_MIPMAP_MODE_NEAREST,SamplerMipmapMode} and you
* have to configure the sampler to use just a single mipmap level.
*/
Base,
/**
* Select nearest mip level.
*
* Corresponds to @ref GL::SamplerMipmap::Nearest.
* Corresponds to @ref GL::SamplerMipmap::Nearest /
* @def_vk_keyword{SAMPLER_MIPMAP_MODE_NEAREST,SamplerMipmapMode}.
*/
Nearest,
/**
* Linear interpolation of nearest mip levels.
*
* Corresponds to @ref GL::SamplerMipmap::Linear.
* Corresponds to @ref GL::SamplerMipmap::Linear /
* @def_vk_keyword{SAMPLER_MIPMAP_MODE_LINEAR,SamplerMipmapMode}.
*/
Linear
};
@ -100,20 +115,27 @@ In case of OpenGL, corresponds to @ref GL::SamplerWrapping and is convertible
to it using @ref GL::samplerWrapping(). See documentation of each value for
more information about the mapping. Note that not every mode is available on
all targets, use @ref GL::hasSamplerWrapping() to check for its presence.
In case of Vulkan, corresponds to @type_vk_keyword{SamplerAddressMode} and is
convertible to it using @ref Vk::vkSamplerAddressMode(). See documentation of
each value for more information about the mapping. Note that not every mode is available there, use @ref Vk::hasVkSamplerAddressMode() to check for its
presence.
@see @ref SamplerFilter, @ref SamplerMipmap
*/
enum class SamplerWrapping: UnsignedInt {
/**
* Repeat texture.
*
* Corresponds to @ref GL::SamplerWrapping::Repeat.
* Corresponds to @ref GL::SamplerWrapping::Repeat /
* @def_vk_keyword{SAMPLER_ADDRESS_MODE_REPEAT,SamplerAddressMode}.
*/
Repeat,
/**
* Repeat mirrored texture.
*
* Corresponds to @ref GL::SamplerWrapping::MirroredRepeat.
* Corresponds to @ref GL::SamplerWrapping::MirroredRepeat /
* @def_vk_keyword{SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,SamplerAddressMode}.
*/
MirroredRepeat,
@ -121,7 +143,8 @@ enum class SamplerWrapping: UnsignedInt {
* Clamp to edge. Coordinates out of the range will be clamped to
* first / last column / row in given direction.
*
* Corresponds to @ref GL::SamplerWrapping::ClampToEdge.
* Corresponds to @ref GL::SamplerWrapping::ClampToEdge /
* @def_vk_keyword{SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,SamplerAddressMode}.
*/
ClampToEdge,
@ -129,7 +152,8 @@ enum class SamplerWrapping: UnsignedInt {
* Clamp to border color. Coordinates out of range will be clamped
* to border color.
*
* Corresponds to @ref GL::SamplerWrapping::ClampToBorder.
* Corresponds to @ref GL::SamplerWrapping::ClampToBorder /
* @def_vk_keyword{SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,SamplerAddressMode}.
*/
ClampToBorder,
@ -137,7 +161,8 @@ enum class SamplerWrapping: UnsignedInt {
* Mirror the texture once in negative coordinates and clamp to
* edge after that.
*
* Corresponds to @ref GL::SamplerWrapping::MirrorClampToEdge.
* Corresponds to @ref GL::SamplerWrapping::MirrorClampToEdge. Not
* available on Vulkan.
*/
MirrorClampToEdge
};

60
src/Magnum/Vk/CMakeLists.txt

@ -32,19 +32,37 @@ set(Vulkan_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/MagnumExternal/Vulkan)
find_package(Vulkan REQUIRED)
set(MagnumVk_SRCS )
set(MagnumVk_GracefulAssert_SRCS
Enums.cpp)
set(MagnumVk_HEADERS
Enums.h
Vk.h
Vulkan.h
visibility.h)
set(MagnumVk_PRIVATE_HEADERS )
set(MagnumVk_PRIVATE_HEADERS
Implementation/FormatMapping.hpp)
# Objects shared between main and test library
# add_library(MagnumVkObjects OBJECT
# ${MagnumVk_SRCS}
# ${MagnumVk_HEADERS}
# ${MagnumVk_PRIVATE_HEADERS})
# target_include_directories(MagnumVkObjects PUBLIC
# $<TARGET_PROPERTY:Magnum,INTERFACE_INCLUDE_DIRECTORIES>)
# if(NOT BUILD_STATIC)
# target_compile_definitions(MagnumVkObjects PRIVATE "MagnumVkObjects_EXPORTS" "FlextVk_EXPORTS")
# endif()
# if(NOT BUILD_STATIC OR BUILD_STATIC_PIC)
# set_target_properties(MagnumVkObjects PROPERTIES POSITION_INDEPENDENT_CODE ON)
# endif()
# set_target_properties(MagnumVkObjects PROPERTIES FOLDER "Magnum/Vk")
# Vk library
add_library(MagnumVk ${SHARED_OR_STATIC}
${MagnumVk_SRCS}
${MagnumVk_HEADERS}
${MagnumVk_PRIVATE_HEADERS}
$<TARGET_OBJECTS:MagnumFlextVkObjects>)
# $<TARGET_OBJECTS:MagnumVkObjects>
$<TARGET_OBJECTS:MagnumFlextVkObjects>
${MagnumVk_GracefulAssert_SRCS})
set_target_properties(MagnumVk PROPERTIES
DEBUG_POSTFIX "-d"
FOLDER "Magnum/Vk")
@ -67,9 +85,35 @@ install(TARGETS MagnumVk
ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumVk_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Vk)
# Magnum Vk library target alias for superprojects
add_library(Magnum::Vk ALIAS MagnumVk)
if(BUILD_TESTS)
# Library with graceful assert for testing
add_library(MagnumVkTestLib ${SHARED_OR_STATIC}
# $<TARGET_OBJECTS:MagnumVkObjects>
$<TARGET_OBJECTS:MagnumFlextVkObjects>
${MagnumVk_GracefulAssert_SRCS})
set_target_properties(MagnumVkTestLib PROPERTIES
DEBUG_POSTFIX "-d"
FOLDER "Magnum/Vk")
target_compile_definitions(MagnumVkTestLib PRIVATE
"CORRADE_GRACEFUL_ASSERT" "MagnumVk_EXPORTS" "FlextVk_EXPORTS")
if(BUILD_STATIC_PIC)
set_target_properties(MagnumVkTestLib PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(MagnumVkTestLib PUBLIC
Magnum
Vulkan::Vulkan)
# On Windows we need to install first and then run the tests to avoid "DLL
# not found" hell, thus we need to install this too
if(CORRADE_TARGET_WINDOWS AND NOT CMAKE_CROSSCOMPILING AND NOT BUILD_STATIC)
install(TARGETS MagnumVkTestLib
RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()
add_subdirectory(Test)
endif()
# Magnum Vk library target alias for superprojects
add_library(Magnum::Vk ALIAS MagnumVk)

192
src/Magnum/Vk/Enums.cpp

@ -0,0 +1,192 @@
/*
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 "Enums.h"
#include <Corrade/Containers/ArrayView.h>
#include "Magnum/Mesh.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/Sampler.h"
namespace Magnum { namespace Vk {
namespace {
constexpr VkPrimitiveTopology PrimitiveTopologyMapping[]{
VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
VkPrimitiveTopology(~UnsignedInt{}),
VK_PRIMITIVE_TOPOLOGY_LINE_STRIP,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN
};
constexpr VkIndexType IndexTypeMapping[]{
VkIndexType(~UnsignedInt{}),
VK_INDEX_TYPE_UINT16,
VK_INDEX_TYPE_UINT32
};
#ifndef DOXYGEN_GENERATING_OUTPUT /* It gets *really* confused */
constexpr VkFormat FormatMapping[] {
#define _c(input, format) VK_FORMAT_ ## format,
#define _s(input) VkFormat(~UnsignedInt{}),
#include "Magnum/Vk/Implementation/formatMapping.hpp"
#undef _s
#undef _c
};
constexpr VkFormat CompressedFormatMapping[] {
#define _c(input, format) VK_FORMAT_ ## format,
#define _s(input) VkFormat(~UnsignedInt{}),
#include "Magnum/Vk/Implementation/compressedFormatMapping.hpp"
#undef _s
#undef _c
};
#endif
constexpr VkFilter FilterMapping[]{
VK_FILTER_NEAREST,
VK_FILTER_LINEAR
};
constexpr VkSamplerMipmapMode SamplerMipmapModeMapping[]{
VK_SAMPLER_MIPMAP_MODE_NEAREST, /* See vkSamplerMipmapMode() for details */
VK_SAMPLER_MIPMAP_MODE_NEAREST,
VK_SAMPLER_MIPMAP_MODE_LINEAR
};
constexpr VkSamplerAddressMode SamplerAddressModeMapping[]{
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
VkSamplerAddressMode(~UnsignedInt{}),
};
}
bool hasVkPrimitiveTopology(const Magnum::MeshPrimitive primitive) {
CORRADE_ASSERT(UnsignedInt(primitive) < Containers::arraySize(PrimitiveTopologyMapping),
"Vk::hasVkPrimitiveTopology(): invalid primitive" << primitive, {});
return UnsignedInt(PrimitiveTopologyMapping[UnsignedInt(primitive)]) != ~UnsignedInt{};
}
VkPrimitiveTopology vkPrimitiveTopology(const Magnum::MeshPrimitive primitive) {
CORRADE_ASSERT(UnsignedInt(primitive) < Containers::arraySize(PrimitiveTopologyMapping),
"Vk::vkPrimitiveTopology(): invalid primitive" << primitive, {});
const VkPrimitiveTopology out = PrimitiveTopologyMapping[UnsignedInt(primitive)];
CORRADE_ASSERT(out != VkPrimitiveTopology(~UnsignedInt{}),
"Vk::vkPrimitiveTopology(): unsupported primitive" << primitive, {});
return out;
}
bool hasVkIndexType(const Magnum::MeshIndexType type) {
CORRADE_ASSERT(UnsignedInt(type) < Containers::arraySize(IndexTypeMapping),
"Vk::hasVkIndexType(): invalid type" << type, {});
return UnsignedInt(IndexTypeMapping[UnsignedInt(type)]) != ~UnsignedInt{};
}
VkIndexType vkIndexType(const Magnum::MeshIndexType type) {
CORRADE_ASSERT(UnsignedInt(type) < Containers::arraySize(IndexTypeMapping),
"Vk::vkIndexType(): invalid type" << type, {});
const VkIndexType out = IndexTypeMapping[UnsignedInt(type)];
CORRADE_ASSERT(out != VkIndexType(~UnsignedInt{}),
"Vk::vkIndexType(): unsupported type" << type, {});
return out;
}
bool hasVkFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format))
return true;
CORRADE_ASSERT(UnsignedInt(format) < Containers::arraySize(FormatMapping),
"Vk::hasVkFormat(): invalid format" << format, {});
return UnsignedInt(FormatMapping[UnsignedInt(format)]);
}
bool hasVkFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format))
return true;
CORRADE_ASSERT(UnsignedInt(format) < Containers::arraySize(CompressedFormatMapping),
"Vk::hasVkFormat(): invalid format" << format, {});
return UnsignedInt(CompressedFormatMapping[UnsignedInt(format)]);
}
VkFormat vkFormat(const Magnum::PixelFormat format) {
if(isPixelFormatImplementationSpecific(format))
return pixelFormatUnwrap<VkFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) < Containers::arraySize(FormatMapping),
"Vk::vkFormat(): invalid format" << format, {});
const VkFormat out = FormatMapping[UnsignedInt(format)];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::vkFormat(): unsupported format" << format, {});
return out;
}
VkFormat vkFormat(const Magnum::CompressedPixelFormat format) {
if(isCompressedPixelFormatImplementationSpecific(format))
return compressedPixelFormatUnwrap<VkFormat>(format);
CORRADE_ASSERT(UnsignedInt(format) < Containers::arraySize(CompressedFormatMapping),
"Vk::vkFormat(): invalid format" << format, {});
const VkFormat out = CompressedFormatMapping[UnsignedInt(format)];
CORRADE_ASSERT(UnsignedInt(out),
"Vk::vkFormat(): unsupported format" << format, {});
return out;
}
VkFilter vkFilter(const Magnum::SamplerFilter filter) {
CORRADE_ASSERT(UnsignedInt(filter) < Containers::arraySize(FilterMapping),
"Vk::vkFilter(): invalid filter" << filter, {});
return FilterMapping[UnsignedInt(filter)];
}
VkSamplerMipmapMode vkSamplerMipmapMode(const Magnum::SamplerMipmap mipmap) {
CORRADE_ASSERT(UnsignedInt(mipmap) < Containers::arraySize(SamplerMipmapModeMapping),
"Vk::vkSamplerMipmapMode(): invalid mode" << mipmap, {});
return SamplerMipmapModeMapping[UnsignedInt(mipmap)];
}
bool hasVkSamplerAddressMode(const Magnum::SamplerWrapping wrapping) {
CORRADE_ASSERT(UnsignedInt(wrapping) < Containers::arraySize(SamplerAddressModeMapping),
"Vk::hasVkSamplerAddressMode(): invalid wrapping" << wrapping, {});
return UnsignedInt(SamplerAddressModeMapping[UnsignedInt(wrapping)]) != ~UnsignedInt{};
}
VkSamplerAddressMode vkSamplerAddressMode(const Magnum::SamplerWrapping wrapping) {
CORRADE_ASSERT(UnsignedInt(wrapping) < Containers::arraySize(SamplerAddressModeMapping),
"Vk::vkSamplerAddressMode(): invalid wrapping" << wrapping, {});
const VkSamplerAddressMode out = SamplerAddressModeMapping[UnsignedInt(wrapping)];
CORRADE_ASSERT(out != VkSamplerAddressMode(~UnsignedInt{}),
"Vk::vkSamplerAddressMode(): unsupported wrapping" << wrapping, {});
return out;
}
}}

195
src/Magnum/Vk/Enums.h

@ -0,0 +1,195 @@
#ifndef Magnum_GL_Enums_h
#define Magnum_GL_Enums_h
/*
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.
*/
/** @file
* @brief Function @ref Magnum::Vk::hasVkPrimitiveTopology(), @ref Magnum::Vk::vkPrimitiveTopology(), @ref Magnum::Vk::hasVkIndexType(), @ref Magnum::Vk::vkIndexType(), @ref Magnum::Vk::hasVkFormat(), @ref Magnum::Vk::vkFormat(), @ref Magnum::Vk::vkFilter(), @ref Magnum::Vk::vkSamplerMipmapMode(), @ref Magnum::Vk::hasVkSamplerAddressMode(), @ref Magnum::Vk::vkSamplerAddressMode()
*/
#include "Magnum/Array.h"
#include "Magnum/Vk/Vulkan.h"
#include "Magnum/Vk/visibility.h"
namespace Magnum { namespace Vk {
/**
@brief Check availability of a generic mesh primitive
In particular, Vulkan doesn't support the @ref MeshPrimitive::LineLoop
primitive. Returns @cpp false @ce if Vulkan doesn't support such primitive,
@cpp true @ce otherwise. The @p primitive value is expected to be valid.
@see @ref vkPrimitiveTopology()
*/
MAGNUM_VK_EXPORT bool hasVkPrimitiveTopology(Magnum::MeshPrimitive primitive);
/**
@brief Convert generic mesh primitive to Vulkan primitive topology
Not all generic mesh primitives are available in Vulkan and this function
expects that given primitive is available. Use @ref hasVkPrimitiveTopology() to
query availability of given primitive.
@see @ref vkIndexType()
*/
MAGNUM_VK_EXPORT VkPrimitiveTopology vkPrimitiveTopology(Magnum::MeshPrimitive primitive);
/**
@brief Check availability of a generic index type
In particular, Vulkan doesn't support the @ref MeshIndexType::UnsignedByte
type. Returns @cpp false @ce if Vulkan doesn't support such type, @cpp true @ce
otherwise. The @p type value is expected to be valid.
@see @ref vkIndexType()
*/
MAGNUM_VK_EXPORT bool hasVkIndexType(Magnum::MeshIndexType type);
/**
@brief Convert generic mesh index type to Vulkan mesh index type
Not all generic index types are available in Vulkan and this function expects
that given type is available. Use @ref hasVkIndexType() to query availability
of given index type.
@see @ref vkPrimitiveTopology()
*/
MAGNUM_VK_EXPORT VkIndexType vkIndexType(Magnum::MeshIndexType type);
/**
@brief Check availability of a generic pixel format
Some Vulkan targets don't support all generic formats. Returns @cpp false @ce
if current target can't support such format, @cpp true @ce otherwise. Moreover,
returns @cpp true @ce also for all formats that are
@ref isPixelFormatImplementationSpecific(). The @p format value is expected to
be valid.
@note Support of some formats depends on presence of a particular Vulkan
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
@see @ref vkFormat()
*/
MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::PixelFormat format);
/**
@brief Check availability of a generic compressed pixel format
Some Vulkan targets don't support all generic formats. Returns @cpp false @ce
if current target can't support such format, @cpp true @ce otherwise. Moreover,
returns @cpp true @ce also for all formats that are
@ref isCompressedPixelFormatImplementationSpecific(). The @p format value is
expected to be valid.
@note Support of some formats depends on presence of a particular Vulkan
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
@see @ref vkFormat()
*/
MAGNUM_VK_EXPORT bool hasVkFormat(Magnum::CompressedPixelFormat format);
/**
@brief Convert a generic pixel format to Vulkan format
In case @ref isPixelFormatImplementationSpecific() returns @cpp false @ce for
@p format, maps it to a corresponding Vulkan format. In case
@ref isPixelFormatImplementationSpecific() returns @cpp true @ce, assumes
@p format stores Vulkan-specific format and returns @ref pixelFormatUnwrap()
cast to @type_vk{Format}.
Not all generic pixel formats may be available on all targets and this function
expects that given format is available on the target. Use @ref hasVkFormat() to
query availability of given format.
*/
MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::PixelFormat format);
/**
@brief Convert a generic pixel format to Vulkan format
In case @ref isCompressedPixelFormatImplementationSpecific() returns
@cpp false @ce for @p format, maps it to a corresponding Vulkan format. In case
@ref isCompressedPixelFormatImplementationSpecific() returns @cpp true @ce,
assumes @p format stores Vulkan-specific format and returns
@ref compressedPixelFormatUnwrap() cast to @type_vk{Format}.
Not all generic pixel formats may be available on all targets and this function
expects that given format is available on the target. Use @ref hasVkFormat() to
query availability of given format.
*/
MAGNUM_VK_EXPORT VkFormat vkFormat(Magnum::CompressedPixelFormat format);
/**
@brief Convert generic sampler filter to Vulkan filter
@see @ref vkSamplerMipmapMode(), @ref vkSamplerAddressMode()
*/
MAGNUM_VK_EXPORT VkFilter vkFilter(Magnum::SamplerFilter filter);
/**
@brief Convert generic sampler mipomap mode to Vulkan sampler mipmap mode
Vulkan doesn't support the @ref SamplerMipmap::Base value directly, instead
@def_vk{SAMPLER_MIPMAP_MODE_NEAREST,SamplerMipmapMode} is used and you have to
configure the sampler to use just a single mipmap level.
@see @ref vkFilter(), @ref vkSamplerAddressMode()
*/
MAGNUM_VK_EXPORT VkSamplerMipmapMode vkSamplerMipmapMode(Magnum::SamplerMipmap mipmap);
/**
@brief Check availability of a generic sampler wrapping mode
Some Vulkan targets don't support all generic sampler wrapping modes (for
example the @ref SamplerWrapping::MirrorClampToEdge). Returns @cpp false @ce if
current target can't support such format, @cpp true @ce otherwise. The
@p wrapping value is expected to be valid.
@note Support of some formats depends on presence of a particular Vulkan
extension. Such check is outside of the scope of this function and you are
expected to verify extension availability before using such format.
@see @ref vkSamplerAddressMode(), @ref vkFilter(), @ref vkSamplerMipmapMode()
*/
MAGNUM_VK_EXPORT bool hasVkSamplerAddressMode(Magnum::SamplerWrapping wrapping);
/**
@brief Convert generic sampler filter mode to Vulkan sampler address mode
Not all generic sampler wrapping modes may be available on all targets and this
function expects that given format is available on the target. Use
@ref hasVkSamplerAddressMode() to query availability of given mode.
@see @ref vkFilter(), @ref vkSamplerAddressMode()
*/
MAGNUM_VK_EXPORT VkSamplerAddressMode vkSamplerAddressMode(Magnum::SamplerWrapping wrapping);
/** @overload */
template<UnsignedInt dimensions> Array<dimensions, VkSamplerAddressMode> vkSamplerAddressMode(const Array<dimensions, Magnum::SamplerWrapping>& wrapping) {
Array<dimensions, VkSamplerAddressMode> out; /** @todo NoInit */
for(std::size_t i = 0; i != dimensions; ++i)
out[i] = vkSamplerAddressMode(wrapping[i]);
return out;
}
}}
#endif

32
src/Magnum/Vk/Implementation/compressedFormatMapping.hpp

@ -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/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */
#ifdef _c
_c(Bc1RGBUnorm, BC1_RGB_UNORM_BLOCK)
_c(Bc1RGBAUnorm, BC1_RGBA_UNORM_BLOCK)
_c(Bc2RGBAUnorm, BC2_UNORM_BLOCK)
_c(Bc3RGBAUnorm, BC3_UNORM_BLOCK)
#endif

76
src/Magnum/Vk/Implementation/formatMapping.hpp

@ -0,0 +1,76 @@
/*
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/Vk/Enums.cpp and Magnum/Vk/Test/EnumsTest.cpp */
#ifdef _c
_c(R8Unorm, R8_UNORM)
_c(RG8Unorm, R8G8_UNORM)
_c(RGB8Unorm, R8G8B8_UNORM)
_c(RGBA8Unorm, R8G8B8A8_UNORM)
_c(R8Snorm, R8_SNORM)
_c(RG8Snorm, R8G8_SNORM)
_c(RGB8Snorm, R8G8B8_SNORM)
_c(RGBA8Snorm, R8G8B8A8_SNORM)
_c(R8UI, R8_UINT)
_c(RG8UI, R8G8_UINT)
_c(RGB8UI, R8G8B8_UINT)
_c(RGBA8UI, R8G8B8A8_UINT)
_c(R8I, R8_SINT)
_c(RG8I, R8G8_SINT)
_c(RGB8I, R8G8B8_SINT)
_c(RGBA8I, R8G8B8A8_SINT)
_c(R16Unorm, R16_UNORM)
_c(RG16Unorm, R16G16_UNORM)
_c(RGB16Unorm, R16G16B16_UNORM)
_c(RGBA16Unorm, R16G16B16A16_UNORM)
_c(R16Snorm, R16_SNORM)
_c(RG16Snorm, R16G16_SNORM)
_c(RGB16Snorm, R16G16B16_SNORM)
_c(RGBA16Snorm, R16G16B16A16_SNORM)
_c(R16UI, R16_UINT)
_c(RG16UI, R16G16_UINT)
_c(RGB16UI, R16G16B16_UINT)
_c(RGBA16UI, R16G16B16A16_UINT)
_c(R16I, R16_SINT)
_c(RG16I, R16G16_SINT)
_c(RGB16I, R16G16B16_SINT)
_c(RGBA16I, R16G16B16A16_SINT)
_c(R32UI, R32_UINT)
_c(RG32UI, R32G32_UINT)
_c(RGB32UI, R32G32B32_UINT)
_c(RGBA32UI, R32G32B32A32_UINT)
_c(R32I, R32_SINT)
_c(RG32I, R32G32_SINT)
_c(RGB32I, R32G32B32_SINT)
_c(RGBA32I, R32G32B32A32_SINT)
_c(R16F, R16_SFLOAT)
_c(RG16F, R16G16_SFLOAT)
_c(RGB16F, R16G16B16_SFLOAT)
_c(RGBA16F, R16G16B16A16_SFLOAT)
_c(R32F, R32_SFLOAT)
_c(RG32F, R32G32_SFLOAT)
_c(RGB32F, R32G32B32_SFLOAT)
_c(RGBA32F, R32G32B32A32_SFLOAT)
#endif

2
src/Magnum/Vk/Test/CMakeLists.txt

@ -23,3 +23,5 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
corrade_add_test(VkEnumsTest EnumsTest.cpp LIBRARIES MagnumVkTestLib)

406
src/Magnum/Vk/Test/EnumsTest.cpp

@ -0,0 +1,406 @@
/*
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/configure.h"
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL)
/* So we don't need to care about the deprecated (Compressed)PixelFormat values */
#undef MAGNUM_TARGET_GL
#endif
#include "Magnum/Mesh.h"
#include "Magnum/PixelFormat.h"
#include "Magnum/Sampler.h"
#include "Magnum/Vk/Enums.h"
namespace Magnum { namespace Vk { namespace Test {
/* Tests MeshView as well */
struct EnumsTest: TestSuite::Tester {
explicit EnumsTest();
void mapVkPrimitiveTopology();
void mapVkPrimitiveTopologyUnsupported();
void mapVkPrimitiveTopologyInvalid();
void mapVkIndexType();
void mapVkIndexTypeUnsupported();
void mapVkIndexTypeInvalid();
void mapVkFormat();
void mapVkFormatImplementationSpecific();
void mapVkFormatUnsupported();
void mapVkFormatInvalid();
void mapVkFormatCompressed();
void mapVkFormatCompressedImplementationSpecific();
void mapVkFormatCompressedUnsupported();
void mapVkFormatCompressedInvalid();
void mapVkFilter();
void mapVkFilterInvalid();
void mapVkSamplerMipmapMode();
void mapVkSamplerMipmapModeInvalid();
void mapVkSamplerAddressMode();
void mapVkSamplerAddressModeArray();
void mapVkSamplerAddressModeUnsupported();
void mapVkSamplerAddressModeInvalid();
};
EnumsTest::EnumsTest() {
addTests({&EnumsTest::mapVkPrimitiveTopology,
&EnumsTest::mapVkPrimitiveTopologyUnsupported,
&EnumsTest::mapVkPrimitiveTopologyInvalid,
&EnumsTest::mapVkIndexType,
&EnumsTest::mapVkIndexTypeUnsupported,
&EnumsTest::mapVkIndexTypeInvalid,
&EnumsTest::mapVkFormat,
&EnumsTest::mapVkFormatImplementationSpecific,
&EnumsTest::mapVkFormatUnsupported,
&EnumsTest::mapVkFormatInvalid,
&EnumsTest::mapVkFormatCompressed,
&EnumsTest::mapVkFormatCompressedImplementationSpecific,
&EnumsTest::mapVkFormatCompressedUnsupported,
&EnumsTest::mapVkFormatCompressedInvalid,
&EnumsTest::mapVkFilter,
&EnumsTest::mapVkFilterInvalid,
&EnumsTest::mapVkSamplerMipmapMode,
&EnumsTest::mapVkSamplerMipmapModeInvalid,
&EnumsTest::mapVkSamplerAddressMode,
&EnumsTest::mapVkSamplerAddressModeArray,
&EnumsTest::mapVkSamplerAddressModeUnsupported,
&EnumsTest::mapVkSamplerAddressModeInvalid});
}
void EnumsTest::mapVkPrimitiveTopology() {
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::Points));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::Points), VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::Lines));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::Lines), VK_PRIMITIVE_TOPOLOGY_LINE_LIST);
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::LineStrip));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::LineStrip), VK_PRIMITIVE_TOPOLOGY_LINE_STRIP);
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::Triangles));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::Triangles), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::TriangleStrip));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::TriangleStrip), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP);
CORRADE_VERIFY(hasVkPrimitiveTopology(Magnum::MeshPrimitive::TriangleFan));
CORRADE_COMPARE(vkPrimitiveTopology(Magnum::MeshPrimitive::TriangleFan), VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN);
}
void EnumsTest::mapVkPrimitiveTopologyUnsupported() {
CORRADE_VERIFY(!hasVkPrimitiveTopology(Magnum::MeshPrimitive::LineLoop));
std::ostringstream out;
{
Error redirectError{&out};
vkPrimitiveTopology(Magnum::MeshPrimitive::LineLoop);
}
CORRADE_COMPARE(out.str(),
"Vk::vkPrimitiveTopology(): unsupported primitive MeshPrimitive::LineLoop\n");
}
void EnumsTest::mapVkPrimitiveTopologyInvalid() {
std::ostringstream out;
Error redirectError{&out};
hasVkPrimitiveTopology(Magnum::MeshPrimitive(0x123));
vkPrimitiveTopology(Magnum::MeshPrimitive(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkPrimitiveTopology(): invalid primitive MeshPrimitive(0x123)\n"
"Vk::vkPrimitiveTopology(): invalid primitive MeshPrimitive(0x123)\n");
}
void EnumsTest::mapVkIndexType() {
CORRADE_VERIFY(hasVkIndexType(Magnum::MeshIndexType::UnsignedShort));
CORRADE_COMPARE(vkIndexType(Magnum::MeshIndexType::UnsignedShort), VK_INDEX_TYPE_UINT16);
CORRADE_VERIFY(hasVkIndexType(Magnum::MeshIndexType::UnsignedInt));
CORRADE_COMPARE(vkIndexType(Magnum::MeshIndexType::UnsignedInt), VK_INDEX_TYPE_UINT32);
}
void EnumsTest::mapVkIndexTypeUnsupported() {
CORRADE_VERIFY(!hasVkIndexType(Magnum::MeshIndexType::UnsignedByte));
std::ostringstream out;
{
Error redirectError{&out};
vkIndexType(Magnum::MeshIndexType::UnsignedByte);
}
CORRADE_COMPARE(out.str(),
"Vk::vkIndexType(): unsupported type MeshIndexType::UnsignedByte\n");
}
void EnumsTest::mapVkIndexTypeInvalid() {
std::ostringstream out;
Error redirectError{&out};
hasVkIndexType(Magnum::MeshIndexType(0x123));
vkIndexType(Magnum::MeshIndexType(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkIndexType(): invalid type MeshIndexType(0x123)\n"
"Vk::vkIndexType(): invalid type MeshIndexType(0x123)\n");
}
void EnumsTest::mapVkFormat() {
/* Touchstone verification */
CORRADE_VERIFY(hasVkFormat(Magnum::PixelFormat::RGBA8Unorm));
CORRADE_COMPARE(vkFormat(Magnum::PixelFormat::RGBA8Unorm), VK_FORMAT_R8G8B8A8_UNORM);
/* 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) \
case Magnum::PixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(hasVkFormat(Magnum::PixelFormat::format)); \
CORRADE_COMPARE(vkFormat(Magnum::PixelFormat::format), VK_FORMAT_ ## expectedFormat); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::PixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasVkFormat(Magnum::PixelFormat::format)); \
vkFormat(Magnum::PixelFormat::format); \
++nextHandled; \
continue;
#include "Magnum/Vk/Implementation/formatMapping.hpp"
#undef _s
#undef _c
}
/* 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 EnumsTest::mapVkFormatImplementationSpecific() {
CORRADE_VERIFY(hasVkFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)));
CORRADE_COMPARE(vkFormat(Magnum::pixelFormatWrap(VK_FORMAT_A8B8G8R8_SINT_PACK32)),
VK_FORMAT_A8B8G8R8_SINT_PACK32);
}
void EnumsTest::mapVkFormatUnsupported() {
#if 1
CORRADE_SKIP("All pixel formats are supported.");
#else
std::ostringstream out;
Error redirectError{&out};
vkFormat(Magnum::PixelFormat::RGB16UI);
CORRADE_COMPARE(out.str(), "Vk::vkFormat(): unsupported format PixelFormat::RGB16UI\n");
#endif
}
void EnumsTest::mapVkFormatInvalid() {
std::ostringstream out;
Error redirectError{&out};
hasVkFormat(Magnum::PixelFormat(0x123));
vkFormat(Magnum::PixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkFormat(): invalid format PixelFormat(0x123)\n"
"Vk::vkFormat(): invalid format PixelFormat(0x123)\n");
}
void EnumsTest::mapVkFormatCompressed() {
/* Touchstone verification */
CORRADE_VERIFY(hasVkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm));
CORRADE_COMPARE(vkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm), VK_FORMAT_BC1_RGBA_UNORM_BLOCK);
/* 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(hasVkFormat(Magnum::CompressedPixelFormat::format)); \
CORRADE_COMPARE(vkFormat(Magnum::CompressedPixelFormat::format), VK_FORMAT_ ## expectedFormat); \
++nextHandled; \
continue;
#define _s(format) \
case Magnum::CompressedPixelFormat::format: \
CORRADE_COMPARE(nextHandled, i); \
CORRADE_COMPARE(firstUnhandled, 0xffff); \
CORRADE_VERIFY(!hasVkFormat(Magnum::CompressedPixelFormat::format)); \
vkFormat(Magnum::CompressedPixelFormat::format); \
++nextHandled; \
continue;
#include "Magnum/Vk/Implementation/compressedFormatMapping.hpp"
#undef _s
#undef _c
}
/* 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 EnumsTest::mapVkFormatCompressedImplementationSpecific() {
CORRADE_VERIFY(hasVkFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)));
CORRADE_COMPARE(vkFormat(Magnum::compressedPixelFormatWrap(VK_FORMAT_ASTC_10x6_UNORM_BLOCK)),
VK_FORMAT_ASTC_10x6_UNORM_BLOCK);
}
void EnumsTest::mapVkFormatCompressedUnsupported() {
#if 1
CORRADE_SKIP("All compressed pixel formats are currently supported.");
#else
CORRADE_VERIFY(!hasVkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm));
std::ostringstream out;
Error redirectError{&out};
vkFormat(Magnum::CompressedPixelFormat::Bc1RGBAUnorm);
CORRADE_COMPARE(out.str(), "Vk::vkFormat(): unsupported format CompressedPixelFormat::Bc1RGBAUnorm\n");
#endif
}
void EnumsTest::mapVkFormatCompressedInvalid() {
std::ostringstream out;
Error redirectError{&out};
hasVkFormat(Magnum::CompressedPixelFormat(0x123));
vkFormat(Magnum::CompressedPixelFormat(0x123));
CORRADE_COMPARE(out.str(),
"Vk::hasVkFormat(): invalid format CompressedPixelFormat(0x123)\n"
"Vk::vkFormat(): invalid format CompressedPixelFormat(0x123)\n");
}
void EnumsTest::mapVkFilter() {
CORRADE_COMPARE(vkFilter(SamplerFilter::Nearest), VK_FILTER_NEAREST);
CORRADE_COMPARE(vkFilter(SamplerFilter::Linear), VK_FILTER_LINEAR);
}
void EnumsTest::mapVkFilterInvalid() {
std::ostringstream out;
Error redirectError{&out};
vkFilter(Magnum::SamplerFilter(0x123));
CORRADE_COMPARE(out.str(),
"Vk::vkFilter(): invalid filter SamplerFilter(0x123)\n");
}
void EnumsTest::mapVkSamplerMipmapMode() {
CORRADE_COMPARE(vkSamplerMipmapMode(SamplerMipmap::Base), VK_SAMPLER_MIPMAP_MODE_NEAREST); /* deliberate */
CORRADE_COMPARE(vkSamplerMipmapMode(SamplerMipmap::Nearest), VK_SAMPLER_MIPMAP_MODE_NEAREST);
CORRADE_COMPARE(vkSamplerMipmapMode(SamplerMipmap::Linear), VK_SAMPLER_MIPMAP_MODE_LINEAR);
}
void EnumsTest::mapVkSamplerMipmapModeInvalid() {
std::ostringstream out;
Error redirectError{&out};
vkSamplerMipmapMode(Magnum::SamplerMipmap(0x123));
CORRADE_COMPARE(out.str(),
"Vk::vkSamplerMipmapMode(): invalid mode SamplerMipmap(0x123)\n");
}
void EnumsTest::mapVkSamplerAddressMode() {
CORRADE_VERIFY(hasVkSamplerAddressMode(SamplerWrapping::Repeat));
CORRADE_COMPARE(vkSamplerAddressMode(SamplerWrapping::Repeat), VK_SAMPLER_ADDRESS_MODE_REPEAT);
CORRADE_VERIFY(hasVkSamplerAddressMode(SamplerWrapping::MirroredRepeat));
CORRADE_COMPARE(vkSamplerAddressMode(SamplerWrapping::MirroredRepeat), VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT);
CORRADE_VERIFY(hasVkSamplerAddressMode(SamplerWrapping::ClampToEdge));
CORRADE_COMPARE(vkSamplerAddressMode(SamplerWrapping::ClampToEdge), VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE);
CORRADE_VERIFY(hasVkSamplerAddressMode(SamplerWrapping::ClampToBorder));
CORRADE_COMPARE(vkSamplerAddressMode(SamplerWrapping::ClampToBorder), VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
}
void EnumsTest::mapVkSamplerAddressModeArray() {
CORRADE_COMPARE(vkSamplerAddressMode<2>({SamplerWrapping::Repeat, SamplerWrapping::ClampToBorder}), (Array2D<VkSamplerAddressMode>{VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER}));
}
void EnumsTest::mapVkSamplerAddressModeUnsupported() {
CORRADE_VERIFY(!hasVkSamplerAddressMode(Magnum::SamplerWrapping::MirrorClampToEdge));
std::ostringstream out;
{
Error redirectError{&out};
vkSamplerAddressMode(Magnum::SamplerWrapping::MirrorClampToEdge);
}
CORRADE_COMPARE(out.str(),
"Vk::vkSamplerAddressMode(): unsupported wrapping SamplerWrapping::MirrorClampToEdge\n");
}
void EnumsTest::mapVkSamplerAddressModeInvalid() {
std::ostringstream out;
Error redirectError{&out};
vkSamplerAddressMode(Magnum::SamplerWrapping(0x123));
CORRADE_COMPARE(out.str(),
"Vk::vkSamplerAddressMode(): invalid wrapping SamplerWrapping(0x123)\n");
}
}}}
CORRADE_TEST_MAIN(Magnum::Vk::Test::EnumsTest)
Loading…
Cancel
Save