159 lines
3.8 KiB
C++
159 lines
3.8 KiB
C++
#ifndef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
|
|
# error Never include this file directly include 'dynamic_texture_buffer.hpp'
|
|
#endif
|
|
|
|
|
|
inline assets::texture_data::texture_data(
|
|
std::unique_ptr<value_type[]>&& data,
|
|
const dim_type width,
|
|
const dim_type height,
|
|
const texture_components::flags components
|
|
) :
|
|
m_data{ std::move(data) },
|
|
m_width{ width },
|
|
m_height{ height },
|
|
m_components{ components }
|
|
{};
|
|
|
|
inline assets::texture_data::texture_data(const assets::texture_data& other) :
|
|
m_data{ new value_type[other.component_count()] },
|
|
m_width{ other.m_width },
|
|
m_height{ other.m_height },
|
|
m_components{ other.m_components }
|
|
{
|
|
std::copy_n(other.m_data.get(), other.m_width * other.m_height, this->m_data.get());
|
|
}
|
|
|
|
inline assets::texture_data::texture_data(texture_data&& other) noexcept :
|
|
m_data{ std::move(other.m_data) },
|
|
m_width{ other.m_width },
|
|
m_height{ other.m_height },
|
|
m_components{ other.m_components }
|
|
{
|
|
other.m_width = 0;
|
|
other.m_height = 0;
|
|
other.m_components = texture_components::flags::none;
|
|
}
|
|
|
|
inline assets::texture_data& assets::texture_data::operator=(const assets::texture_data& other)
|
|
{
|
|
if (this != &other) [[likely]]
|
|
{
|
|
|
|
const auto m_size = this->component_count();
|
|
const auto o_size = other.component_count();
|
|
|
|
if (o_size > m_size) {
|
|
this->~texture_data();
|
|
this->m_data.reset(new value_type[o_size]);
|
|
}
|
|
|
|
std::copy_n(other.m_data.get(), o_size, this->m_data.get());
|
|
|
|
this->m_width = other.m_width;
|
|
this->m_height = other.m_height;
|
|
this->m_components = other.m_components;
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
inline assets::texture_data& assets::texture_data::operator=(texture_data&& other) noexcept
|
|
{
|
|
if (this != &other) [[likely]]
|
|
{
|
|
this->~texture_data();
|
|
|
|
this->m_data = std::move(other.m_data);
|
|
this->m_width = other.m_width;
|
|
this->m_height = other.m_height;
|
|
|
|
other.m_width = 0;
|
|
other.m_height = 0;
|
|
other.m_components = texture_components::flags::none;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
inline assets::texture_components::flags assets::texture_data::components() const
|
|
{
|
|
return m_components;
|
|
}
|
|
|
|
inline assets::texture_data::dim_type assets::texture_data::width() const
|
|
{
|
|
return m_width;
|
|
}
|
|
|
|
inline assets::texture_data::dim_type assets::texture_data::height() const
|
|
{
|
|
return m_height;
|
|
}
|
|
|
|
inline std::pair<assets::texture_data::dim_type, assets::texture_data::dim_type> assets::texture_data::dimensions() const
|
|
{
|
|
return { m_width, m_height };
|
|
}
|
|
|
|
inline assets::texture_data::size_type assets::texture_data::pixel_count() const
|
|
{
|
|
return static_cast<size_type>(m_width) * static_cast<size_type>(m_height);
|
|
}
|
|
|
|
inline assets::texture_data::size_type assets::texture_data::component_count() const
|
|
{
|
|
return std::popcount(static_cast<std::underlying_type_t<texture_components::flags>>(m_components));
|
|
}
|
|
|
|
inline assets::texture_data::size_type assets::texture_data::size() const
|
|
{
|
|
return pixel_count() * component_count();
|
|
}
|
|
|
|
inline assets::texture_data::const_pointer assets::texture_data::data() const
|
|
{
|
|
return m_data.get();
|
|
}
|
|
|
|
inline assets::texture_data::pointer assets::texture_data::data()
|
|
{
|
|
return m_data.get();
|
|
}
|
|
|
|
inline assets::texture_data::const_iterator assets::texture_data::begin() const
|
|
{
|
|
return data();
|
|
}
|
|
|
|
inline assets::texture_data::iterator assets::texture_data::begin()
|
|
{
|
|
return data();
|
|
}
|
|
|
|
inline assets::texture_data::const_iterator assets::texture_data::end() const
|
|
{
|
|
return begin() + component_count();
|
|
}
|
|
|
|
inline assets::texture_data::iterator assets::texture_data::end()
|
|
{
|
|
return begin() + component_count();
|
|
}
|
|
|
|
inline assets::texture_data::const_iterator assets::texture_data::cbegin() const
|
|
{
|
|
return const_cast<const_iterator>(begin());
|
|
}
|
|
|
|
inline assets::texture_data::const_iterator assets::texture_data::cend() const
|
|
{
|
|
return const_cast<const_iterator>(begin());
|
|
}
|
|
|
|
inline void assets::texture_data::clear()
|
|
{
|
|
m_data.reset();
|
|
m_width = 0;
|
|
m_height = 0;
|
|
m_components = {};
|
|
} |