Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Viewport.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector2.h"
5
6#include <Common/assertion.h>
7
8#include <utility>
9#include <cstddef>
10#include <string>
11
12namespace ph
13{
14
15class Viewport final
16{
17public:
20 Viewport();
21
22 explicit Viewport(math::TVector2<uint32> baseSizePx);
24
28
31 const math::TAABB2D<int64>& getWindowPx() const;
32
38
39 std::size_t numBasePixels() const;
40 std::size_t numCroppedRegionPixels() const;
41
44 bool hasView() const;
45
46 std::string toString() const;
47
48private:
49 math::TVector2<uint32> m_baseSizePx;
50 math::TAABB2D<int64> m_windowPx;
51};
52
53// In-header Implementations:
54
56 Viewport({0, 0})
57{}
58
60 Viewport(std::move(baseSizePx), math::TAABB2D<int64>({0, 0}, {baseSizePx.x(), baseSizePx.y() }))
61{}
62
64 m_baseSizePx(std::move(baseSizePx)),
65 m_windowPx (std::move(windowPx))
66{
67 PH_ASSERT(!m_windowPx.isEmpty());
68}
69
71{
72 return m_baseSizePx;
73}
74
76{
77 return m_windowPx;
78}
79
81{
82 math::TAABB2D<int64> intersectedWindowPx({0, 0}, {m_baseSizePx.x(), m_baseSizePx.y()});
83 intersectedWindowPx.intersectWith(m_windowPx);
84 return intersectedWindowPx;
85}
86
87inline std::size_t Viewport::numBasePixels() const
88{
89 return static_cast<std::size_t>(m_baseSizePx.x()) * m_baseSizePx.y();
90}
91
92inline std::size_t Viewport::numCroppedRegionPixels() const
93{
94 return static_cast<std::size_t>(getCroppedRegionPx().getArea());
95}
96
97inline bool Viewport::hasView() const
98{
99 return getCroppedRegionPx().getArea() > 0;
100}
101
102inline std::string Viewport::toString() const
103{
104 return "viewport base: " + m_baseSizePx.toString() + ", window: " + m_windowPx.toString();
105}
106
107}// end namespace ph
Definition Viewport.h:16
bool hasView() const
Whether there is any viewable area in the viewport.
Definition Viewport.h:97
std::size_t numCroppedRegionPixels() const
Definition Viewport.h:92
Viewport()
Creates empty viewport.
Definition Viewport.h:55
std::size_t numBasePixels() const
Definition Viewport.h:87
const math::TVector2< uint32 > & getBaseSizePx() const
The full size of this viewport.
Definition Viewport.h:70
const math::TAABB2D< int64 > & getWindowPx() const
The window that limits the viewing area of this viewport.
Definition Viewport.h:75
math::TAABB2D< int64 > getCroppedRegionPx() const
The viewing area of this viewport. The difference between cropped region and window is that cropped r...
Definition Viewport.h:80
std::string toString() const
Definition Viewport.h:102
A 2-D Axis-Aligned Bounding Box (AABB).
Definition TAABB2D.h:26
TAABB2D & intersectWith(const TAABB2D &other)
Definition TAABB2D.ipp:86
bool isEmpty() const
Definition TAABB2D.ipp:193
std::string toString() const
Definition TAABB2D.ipp:235
T getArea() const
Definition TAABB2D.ipp:69
Represents a 2-D vector.
Definition TVector2.h:19
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96