84 lines
3.7 KiB
C++
Executable File
84 lines
3.7 KiB
C++
Executable File
// =====================================================================================================================
|
|
// glw, an open-source library that wraps OpenGL structures into classes.
|
|
// Copyright (C) 2024 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 GLW_TEXTURE_ARRAY_H
|
|
#define GLW_TEXTURE_ARRAY_H
|
|
|
|
#include "common.h"
|
|
#include "texture.h"
|
|
|
|
namespace glw
|
|
{
|
|
|
|
template<enum_t T_, enum_t...Fs_>
|
|
class texarray
|
|
{
|
|
// Constants ===========================================================================================================
|
|
|
|
public:
|
|
inline static constexpr enum_t type = T_;
|
|
inline static constexpr size_t length = sizeof...(Fs_);
|
|
|
|
private:
|
|
using array_type = std::tuple<texture<T_, Fs_>...>;
|
|
|
|
|
|
// Functions ===========================================================================================================
|
|
|
|
// Helpers
|
|
template<int I = 0> void resize_(size_t size) { get<I>().resize(size); if constexpr (I < length - 1) resize_<I + 1>(size); }
|
|
template<int I = 0> void resize_(glm::ivec2 size) { get<I>().resize(size); if constexpr (I < length - 1) resize_<I + 1>(size); }
|
|
template<int I = 0> void resize_(glm::ivec2 size, size_t samples) { get<I>().resize(size); if constexpr (I < length - 1) resize_<I + 1>(size, samples); }
|
|
template<int I = 0> void resize_(glm::ivec3 size) { get<I>().resize(size); if constexpr (I < length - 1) resize_<I + 1>(size); }
|
|
template<int I = 0> void resize_(glm::ivec3 size, size_t samples) { get<I>().resize(size); if constexpr (I < length - 1) resize_<I + 1>(size, samples); }
|
|
|
|
public:
|
|
texarray(size_t size) : array_(texture<T_, Fs_>{ size }...) { }
|
|
texarray(glm::ivec2 size) : array_(texture<T_, Fs_>{ size }...) { }
|
|
texarray(glm::ivec2 size, size_t samples) : array_(texture<T_, Fs_>{ size, samples }...) { }
|
|
texarray(glm::ivec3 size) : array_(texture<T_, Fs_>{ size }...) { }
|
|
texarray(glm::ivec3 size, size_t samples) : array_(texture<T_, Fs_>{ size, samples }...) { }
|
|
|
|
void resize(size_t size) { resize_(size); }
|
|
void resize(glm::ivec2 size) { resize_(size); }
|
|
void resize(glm::ivec2 size, size_t samples) { resize_(size, samples); }
|
|
void resize(glm::ivec3 size) { resize_(size); }
|
|
void resize(glm::ivec3 size, size_t samples) { resize_(size, samples); }
|
|
|
|
// Variables ===========================================================================================================
|
|
|
|
template <size_t _Index>
|
|
constexpr std::tuple_element_t<_Index, array_type>& get() noexcept
|
|
{
|
|
return std::get<_Index>(array_);
|
|
}
|
|
|
|
template <size_t _Index>
|
|
constexpr const std::tuple_element_t<_Index, array_type>& get() const noexcept
|
|
{
|
|
return std::get<_Index>(array_);
|
|
}
|
|
|
|
private:
|
|
array_type array_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //TEXTURE_ARRAY_H
|