5#include <Common/assertion.h>
6#include <Common/primitive_type.h>
34 template<std::
size_t N>
35 TPixel(
const std::array<T, N>& values);
40 template<std::
size_t N>
41 TPixel(
const std::array<T, N>& valueBuffer, std::size_t numUsedValues);
46 template<std::
size_t N>
58 using ValueArrayType = std::array<T, MAX_PIXEL_ELEMENTS>;
60 ValueArrayType m_valueBuffer;
61 std::size_t m_numValues;
73template<std::
size_t N>
79template<std::
size_t N>
80inline TPixel<T>::TPixel(
const std::array<T, N>& valueBuffer,
const std::size_t numUsedValues) :
83 constexpr auto MIN_BUFFER_SIZE = std::min(N, std::tuple_size_v<ValueArrayType>);
85 if(numUsedValues > MIN_BUFFER_SIZE)
87 throw std::out_of_range(std::format(
88 "Buffer of size {} cannot hold {} input values.", MIN_BUFFER_SIZE, numUsedValues));
91 for(std::size_t i = 0; i < numUsedValues; ++i)
93 m_valueBuffer[i] = valueBuffer[i];
96 m_numValues = numUsedValues;
104 for(std::size_t i = 0; i < other.
numValues(); ++i)
106 m_valueBuffer[i] =
static_cast<T
>(other[i]);
113template<std::
size_t N>
118 throw std::out_of_range(std::format(
119 "Attepmting to get {} input values from an internal buffer of size {}.", N, m_numValues));
122 std::array<T, N> values;
123 for(std::size_t i = 0; i < N; ++i)
125 values[i] = m_valueBuffer[i];
133 return m_valueBuffer;
145 PH_ASSERT_LT(index, m_numValues);
147 return m_valueBuffer[index];
177 uint8 m_numPixelElements;
178 uint8 m_numMipLevels;
185 const std::size_t numPixelElements) :
195 const std::size_t numPixelElements,
196 const std::size_t numMipLevels) :
199 m_numPixelElements(static_cast<uint8>(numPixelElements)),
200 m_numMipLevels (static_cast<uint8>(numMipLevels))
203 PH_ASSERT_GT(size.
product(), 0);
205 PH_ASSERT_GE(m_numMipLevels, 1);
209 PH_ASSERT_LE(
numMipLevels, std::numeric_limits<
decltype(m_numMipLevels)>::max());
219 return m_numMipLevels > 1;
224 return m_numPixelElements;
229 return m_numMipLevels;
Definition PixelBuffer2D.h:153
virtual std::size_t estimateMemoryUsageBytes() const
Definition PixelBuffer2D.h:232
std::size_t numMipLevels() const
Definition PixelBuffer2D.h:227
math::TVector2< uint32 > getSize() const
Definition PixelBuffer2D.h:212
virtual ~PixelBuffer2D()=default
PixelBuffer2D(math::TVector2< uint32 > size, std::size_t numPixelElements)
Definition PixelBuffer2D.h:183
std::size_t numPixelElements() const
Definition PixelBuffer2D.h:222
virtual pixel_buffer::TPixel< float64 > fetchPixel(math::TVector2< uint32 > xy, std::size_t mipLevel) const =0
bool hasMipmap() const
Definition PixelBuffer2D.h:217
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
TPixel()
Definition PixelBuffer2D.h:67
T operator[](std::size_t index) const
Definition PixelBuffer2D.h:143
std::size_t numValues() const
Definition PixelBuffer2D.h:137
std::array< T, MAX_PIXEL_ELEMENTS > getAllValues() const
Definition PixelBuffer2D.h:131
std::array< T, N > getValues() const
Definition PixelBuffer2D.h:114
constexpr uint8 MAX_PIXEL_ELEMENTS
Definition PixelBuffer2D.h:21
The root for all renderer implementations.
Definition EEngineProject.h:6