libdonut 2.3.6
Application framework for cross-platform game development in C++20
Loading...
Searching...
No Matches
Viewport.hpp
Go to the documentation of this file.
1#ifndef DONUT_GRAPHICS_VIEWPORT_HPP
2#define DONUT_GRAPHICS_VIEWPORT_HPP
3
4#include <donut/math.hpp>
5
6#include <utility> // std::pair
7
8namespace donut::graphics {
9
13struct Viewport {
32 [[nodiscard]] static constexpr std::pair<Viewport, int> createIntegerScaled(ivec2 framebufferSize, ivec2 renderResolution) noexcept {
33 Viewport result{.position{}, .size = renderResolution};
34 int scale = 1;
35 while (true) {
36 const ivec2 nextViewportSize = renderResolution * (scale + 1);
37 if (nextViewportSize.x > framebufferSize.x || nextViewportSize.y > framebufferSize.y) {
38 break;
39 }
40 result.size = nextViewportSize;
41 ++scale;
42 }
43 result.position = (framebufferSize - result.size) / 2;
44 return {result, scale};
45 }
46
51 ivec2 position;
52
56 ivec2 size;
57};
58
59} // namespace donut::graphics
60
61#endif
Definition Buffer.hpp:7
Rectangular region of a framebuffer.
Definition Viewport.hpp:13
ivec2 size
The width and height of the viewport, in pixels.
Definition Viewport.hpp:56
ivec2 position
The offset of the viewport, in pixels, from the bottom left of the framebuffer.
Definition Viewport.hpp:51
static constexpr std::pair< Viewport, int > createIntegerScaled(ivec2 framebufferSize, ivec2 renderResolution) noexcept
Create an integer-scaled viewport that fits into the middle of a framebuffer at the largest positive ...
Definition Viewport.hpp:32