55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright © 2025 - 2026 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
|
|
#ifndef FENNEC_MATH_SWIZZLE_STORAGE_H
|
|
#define FENNEC_MATH_SWIZZLE_STORAGE_H
|
|
|
|
namespace fennec::detail
|
|
{
|
|
|
|
///
|
|
/// \brief Backing storage struct for \ref fennec::swizzle "swizzle"
|
|
/// \tparam DataT Data Type
|
|
/// \tparam ScalarT Element Types
|
|
/// \tparam IndicesV Swizzle Order
|
|
template<typename DataT, typename ScalarT, size_t...IndicesV>
|
|
struct swizzle_storage
|
|
{
|
|
///
|
|
/// \brief an array containing the indices of this swizzle
|
|
inline static constexpr size_t indices[] = { IndicesV... };
|
|
|
|
///
|
|
/// \brief an array containing the scalar values of this swizzle
|
|
DataT data;
|
|
|
|
///
|
|
/// \brief element access, returns a copy of the value at index \p i
|
|
/// \param i the index
|
|
/// \returns a copy of the scalar value at index \p i
|
|
constexpr ScalarT operator[](size_t i) const noexcept {
|
|
return data[indices[i]];
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif // FENNEC_MATH_SWIZZLE_STORAGE_H
|