Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TNumericPixelTexture2D.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9
10#include <cstddef>
11#include <algorithm>
12
13namespace ph
14{
15
16template<typename T, std::size_t N>
17class TNumericPixelTexture2D : public TPixelTexture2D<math::TArithmeticArray<T, N>>
18{
19public:
20 explicit TNumericPixelTexture2D(const std::shared_ptr<PixelBuffer2D>& pixelBuffer);
21
23 const std::shared_ptr<PixelBuffer2D>& pixelBuffer,
26 pixel_texture::EWrapMode wrapModeT);
27
29 const std::shared_ptr<PixelBuffer2D>& pixelBuffer,
33 std::size_t pixelIndexOffset);
34
35 void sample(
36 const SampleLocation& sampleLocation,
37 math::TArithmeticArray<T, N>* out_value) const override;
38
39private:
40 std::size_t m_pixelIndexOffset;
41};
42
43// In-header Implementations:
44
45template<typename T, std::size_t N>
46inline TNumericPixelTexture2D<T, N>::TNumericPixelTexture2D(const std::shared_ptr<PixelBuffer2D>& pixelBuffer) :
47
48 TPixelTexture2D<math::TArithmeticArray<T, N>>(pixelBuffer),
49
50 m_pixelIndexOffset(0)
51{}
52
53template<typename T, std::size_t N>
55 const std::shared_ptr<PixelBuffer2D>& pixelBuffer,
56 const pixel_texture::ESampleMode sampleMode,
57 const pixel_texture::EWrapMode wrapModeS,
58 const pixel_texture::EWrapMode wrapModeT) :
59
61 pixelBuffer,
62 sampleMode,
63 wrapModeS,
64 wrapModeT,
65 0)
66{}
67
68template<typename T, std::size_t N>
70 const std::shared_ptr<PixelBuffer2D>& pixelBuffer,
71 const pixel_texture::ESampleMode sampleMode,
72 const pixel_texture::EWrapMode wrapModeS,
73 const pixel_texture::EWrapMode wrapModeT,
74 const std::size_t pixelIndexOffset) :
75
77 pixelBuffer,
78 sampleMode,
79 wrapModeS,
80 wrapModeT),
81
82 m_pixelIndexOffset(pixelIndexOffset)
83{}
84
85template<typename T, std::size_t N>
87 const SampleLocation& sampleLocation,
88 math::TArithmeticArray<T, N>* const out_value) const
89{
90 PH_ASSERT(out_value);
91
92 const pixel_buffer::TPixel<float64> sampledPixel = this->samplePixelBuffer(math::Vector2D(sampleLocation.uv()));
93
94 // Number of sampled values is limited by either `N` or the dimension of sampled pixel
95 const auto minBufferSize = std::min(N, sampledPixel.numValues());
96
97 out_value->set(0);
98 for(std::size_t i = m_pixelIndexOffset; i < minBufferSize; ++i)
99 {
100 (*out_value)[i] = static_cast<T>(sampledPixel[i]);
101 }
102}
103
104}// end namespace ph
Definition SampleLocation.h:22
math::Vector2R uv() const
Definition SampleLocation.h:95
Definition TNumericPixelTexture2D.h:18
TNumericPixelTexture2D(const std::shared_ptr< PixelBuffer2D > &pixelBuffer, pixel_texture::ESampleMode sampleMode, pixel_texture::EWrapMode wrapModeS, pixel_texture::EWrapMode wrapModeT)
Definition TNumericPixelTexture2D.h:54
TNumericPixelTexture2D(const std::shared_ptr< PixelBuffer2D > &pixelBuffer, pixel_texture::ESampleMode sampleMode, pixel_texture::EWrapMode wrapModeS, pixel_texture::EWrapMode wrapModeT, std::size_t pixelIndexOffset)
Definition TNumericPixelTexture2D.h:69
void sample(const SampleLocation &sampleLocation, math::TArithmeticArray< T, N > *out_value) const override
Definition TNumericPixelTexture2D.h:86
TNumericPixelTexture2D(const std::shared_ptr< PixelBuffer2D > &pixelBuffer)
Definition TNumericPixelTexture2D.h:46
Definition TPixelTexture2D.h:16
Derived & set(T value)
Definition TArithmeticArrayBase.ipp:604
Definition TArithmeticArray.h:13
Represent a pixel from pixel buffer.
Definition PixelBuffer2D.h:27
std::size_t numValues() const
Definition PixelBuffer2D.h:137
EWrapMode
Definition pixel_texture_basics.h:21
ESampleMode
Definition pixel_texture_basics.h:28
The root for all renderer implementations.
Definition EEngineProject.h:6