76 lines
1.6 KiB
C++
76 lines
1.6 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Scene/DataFormat.hpp"
|
|
#include <magic_enum/magic_enum.hpp>
|
|
#include <cinttypes>
|
|
#include <string_view>
|
|
|
|
namespace OpenVulkano
|
|
{
|
|
class SubpixelLayout
|
|
{
|
|
public:
|
|
enum Layout : uint16_t
|
|
{
|
|
RGB,
|
|
BGR,
|
|
RGBV,
|
|
BGRV,
|
|
// unknown and auto must be last two
|
|
UNKNOWN,
|
|
NONE = UNKNOWN,
|
|
AUTO = UNKNOWN
|
|
};
|
|
|
|
constexpr SubpixelLayout() = default;
|
|
|
|
constexpr SubpixelLayout(Layout layout) : m_layout(layout) {}
|
|
|
|
[[nodiscard]] DataFormat GetTextureDataFormat() const
|
|
{
|
|
if (m_layout >= SubpixelLayout::UNKNOWN)
|
|
{
|
|
return DataFormat::R8_UINT;
|
|
}
|
|
if (m_layout == SubpixelLayout::BGR || m_layout == SubpixelLayout::BGRV)
|
|
{
|
|
return DataFormat::B8G8R8A8_UINT;
|
|
}
|
|
return DataFormat::R8G8B8A8_UINT;
|
|
}
|
|
|
|
[[nodiscard]] std::string_view GetName() const { return magic_enum::enum_name(m_layout); }
|
|
|
|
[[nodiscard]] constexpr bool operator==(Layout rhs) const
|
|
{
|
|
return m_layout == rhs;
|
|
}
|
|
|
|
[[nodiscard]] constexpr bool operator!=(Layout rhs) const
|
|
{
|
|
return m_layout != rhs;
|
|
}
|
|
|
|
[[nodiscard]] constexpr operator uint32_t() const
|
|
{
|
|
return m_layout;
|
|
}
|
|
|
|
[[nodiscard]] bool IsHorizontalSubpixelLayout() const
|
|
{
|
|
return m_layout == SubpixelLayout::RGB || m_layout == SubpixelLayout::BGR;
|
|
}
|
|
|
|
explicit operator bool() const { return m_layout < Layout::UNKNOWN; }
|
|
|
|
private:
|
|
Layout m_layout = Layout::UNKNOWN;
|
|
};
|
|
}
|