Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TFrameBuffer2D.h
Go to the documentation of this file.
1#pragma once
2
4#include "Frame/TFrame.h"
6
7#include <cstddef>
8#include <utility>
9#include <type_traits>
10
11namespace ph
12{
13
14template<typename T, std::size_t N>
16{
17 static_assert(N <= pixel_buffer::MAX_PIXEL_ELEMENTS,
18 "Number of pixel components exceeded allowed number");
19
20public:
21 explicit TFrameBuffer2D(TFrame<T, N> frame);
22
23 pixel_buffer::TPixel<float64> fetchPixel(math::TVector2<uint32> xy, std::size_t mipLevel) const override;
24 std::size_t estimateMemoryUsageBytes() const override;
25
30 auto getFramePixel(math::TVector2<uint32> xy, std::size_t mipLevel) const;
31
32private:
33 TFrame<T, N> m_frame;
34};
35
36// In-header Implementations:
37
38template<typename T, std::size_t N>
40
42 frame.getSizePx(),
43 N),
44
45 m_frame(std::move(frame))
46{}
47
48template<typename T, std::size_t N>
50{
51 // Directly cast all value types to float64
52 return typename TFrame<float64, N>::PixelType(getFramePixel(xy, mipLevel)).toArray();
53}
54
55template<typename T, std::size_t N>
56inline auto TFrameBuffer2D<T, N>::getFramePixel(const math::TVector2<uint32> xy, const std::size_t mipLevel) const
57{
58 const typename TFrame<T, N>::PixelType framePixel = m_frame.getPixel(xy);
59
60 // TODO: this should be a configurable option for each type; or some fixed policy
61 // Convert from [0, 255] to [0, 1] for LDR values
62 if constexpr(std::is_same_v<T, uint8>)
63 {
64 return typename TFrame<float32, N>::PixelType(framePixel) / 255.0f;
65 }
66 // For rest of the types, no conversion is made
67 else
68 {
69 return framePixel;
70 }
71}
72
73template<typename T, std::size_t N>
75{
76 const auto baseUsage = PixelBuffer2D::estimateMemoryUsageBytes();
77 const auto frameUsage = sizeof(TFrame<T, N>);
78
79 // Estimate usage of frame internal buffer
80 const auto numPixels = math::Vector2S(m_frame.getSizePx()).product();
81 const auto bufferUsage = numPixels * (sizeof(T) * N);
82
83 return baseUsage + frameUsage + bufferUsage;
84}
85
86}// end namespace ph
Definition PixelBuffer2D.h:153
virtual std::size_t estimateMemoryUsageBytes() const
Definition PixelBuffer2D.h:232
Definition TFrameBuffer2D.h:16
pixel_buffer::TPixel< float64 > fetchPixel(math::TVector2< uint32 > xy, std::size_t mipLevel) const override
Definition TFrameBuffer2D.h:49
auto getFramePixel(math::TVector2< uint32 > xy, std::size_t mipLevel) const
Directly get pixel value stored in the frame.
Definition TFrameBuffer2D.h:56
std::size_t estimateMemoryUsageBytes() const override
Definition TFrameBuffer2D.h:74
TFrameBuffer2D(TFrame< T, N > frame)
Definition TFrameBuffer2D.h:39
Definition TFrame.h:21
TPixelType< T > PixelType
Definition TFrame.h:28
Definition TArithmeticArray.h:13
Represents a 2-D vector.
Definition TVector2.h:19
T product() const
Definition TArithmeticArrayBase.ipp:358
Represent a pixel from pixel buffer.
Definition PixelBuffer2D.h:27
TVector2< std::size_t > Vector2S
Definition math_fwd.h:48
constexpr uint8 MAX_PIXEL_ELEMENTS
Definition PixelBuffer2D.h:21
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96