Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSwizzledTexture.h
Go to the documentation of this file.
1#pragma once
2
5#include "Utility/traits.h"
6
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9
10#include <cstddef>
11#include <array>
12#include <memory>
13#include <utility>
14#include <type_traits>
15
16namespace ph
17{
18
25template<typename InputT, typename OutputT, std::size_t OUTPUT_N>
26class TSwizzledTexture : public TTexture<OutputT>
27{
28 static_assert(CSubscriptable<InputT>,
29 "Input type must be subscriptable.");
30
31 static_assert(CSubscriptable<OutputT>,
32 "Output type must be subscriptable.");
33
34public:
35 using InputTexRes = std::shared_ptr<TTexture<InputT>>;
36 using InputElement = std::remove_cvref_t<decltype(std::declval<InputT>()[std::declval<std::size_t>()])>;
37 using OutputElement = std::remove_cvref_t<decltype(std::declval<OutputT>()[std::declval<std::size_t>()])>;
38
39 static_assert(std::is_convertible_v<InputElement, OutputElement>,
40 "Array element of input type is not convertible to the array element of output type.");
41
47 InputTexRes inputTexture,
48 std::array<uint8, OUTPUT_N> swizzleMap) :
49
50 TTexture<OutputT>(),
51
52 m_inputTexture(std::move(inputTexture)),
53 m_swizzleMap (std::move(swizzleMap))
54 {}
55
56 void sample(const SampleLocation& sampleLocation, OutputT* const out_value) const override
57 {
58 PH_ASSERT(m_inputTexture);
59 PH_ASSERT(out_value);
60
61 InputT inputValue;
62 m_inputTexture->sample(sampleLocation, &inputValue);
63
64 *out_value = OutputT{};
65 for(std::size_t oi = 0; oi < OUTPUT_N; ++oi)
66 {
67 const std::size_t mappedIndex = m_swizzleMap[oi];
68 (*out_value)[oi] = static_cast<OutputElement>(inputValue[mappedIndex]);
69 }
70 }
71
72private:
73 InputTexRes m_inputTexture;
74 std::array<uint8, OUTPUT_N> m_swizzleMap;
75};
76
77}// end namespace ph
Definition SampleLocation.h:22
Swizzle an array-like input type to the other array-like output type. Output type OutputT can have an...
Definition TSwizzledTexture.h:27
TSwizzledTexture(InputTexRes inputTexture, std::array< uint8, OUTPUT_N > swizzleMap)
Definition TSwizzledTexture.h:46
std::remove_cvref_t< decltype(std::declval< OutputT >()[std::declval< std::size_t >()])> OutputElement
Definition TSwizzledTexture.h:37
std::remove_cvref_t< decltype(std::declval< InputT >()[std::declval< std::size_t >()])> InputElement
Definition TSwizzledTexture.h:36
std::shared_ptr< TTexture< InputT > > InputTexRes
Definition TSwizzledTexture.h:35
void sample(const SampleLocation &sampleLocation, OutputT *const out_value) const override
Definition TSwizzledTexture.h:56
Definition TTexture.h:12
Definition traits.h:87
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96