remove Viewport class

This commit is contained in:
MihailRis
2025-04-02 17:35:17 +03:00
parent 105561ad77
commit 9843a1fc27
17 changed files with 60 additions and 115 deletions
+5 -13
View File
@@ -29,7 +29,7 @@ DrawContext::DrawContext(
Batch2D* g2d
) : window(window),
parent(parent),
viewport({window.getSize()}),
viewport(window.getSize()),
g2d(g2d),
flushable(g2d)
{}
@@ -55,11 +55,7 @@ DrawContext::~DrawContext() {
}
}
glViewport(
0, 0,
parent->viewport.getWidth(),
parent->viewport.getHeight()
);
glViewport(0, 0, parent->viewport.x, parent->viewport.y);
if (depthMask != parent->depthMask) {
glDepthMask(parent->depthMask);
@@ -80,7 +76,7 @@ DrawContext::~DrawContext() {
}
}
const Viewport& DrawContext::getViewport() const {
const glm::uvec2& DrawContext::getViewport() const {
return viewport;
}
@@ -99,13 +95,9 @@ DrawContext DrawContext::sub(Flushable* flushable) const {
return ctx;
}
void DrawContext::setViewport(const Viewport& viewport) {
void DrawContext::setViewport(const glm::uvec2& viewport) {
this->viewport = viewport;
glViewport(
0, 0,
viewport.getWidth(),
viewport.getHeight()
);
glViewport(0, 0, viewport.x, viewport.y);
}
void DrawContext::setFramebuffer(Framebuffer* fbo) {
+6 -4
View File
@@ -1,7 +1,9 @@
#pragma once
#include <glm/vec2.hpp>
#include <glm/vec4.hpp>
#include "commons.hpp"
#include "Viewport.hpp"
#include "typedefs.hpp"
class Window;
@@ -11,7 +13,7 @@ class Framebuffer;
class DrawContext {
Window& window;
const DrawContext* parent;
Viewport viewport;
glm::uvec2 viewport;
Batch2D* g2d;
Flushable* flushable = nullptr;
Framebuffer* fbo = nullptr;
@@ -31,10 +33,10 @@ public:
Batch2D* getBatch2D() const;
const Viewport& getViewport() const;
const glm::uvec2& getViewport() const;
DrawContext sub(Flushable* flushable=nullptr) const;
void setViewport(const Viewport& viewport);
void setViewport(const glm::uvec2& viewport);
void setFramebuffer(Framebuffer* fbo);
void setDepthMask(bool flag);
void setDepthTest(bool flag);
+3 -4
View File
@@ -3,7 +3,6 @@
#include "Shader.hpp"
#include "Texture.hpp"
#include "Framebuffer.hpp"
#include "Viewport.hpp"
#include "DrawContext.hpp"
#include <stdexcept>
@@ -23,9 +22,9 @@ PostProcessing::~PostProcessing() = default;
void PostProcessing::use(DrawContext& context) {
const auto& vp = context.getViewport();
if (fbo) {
fbo->resize(vp.getWidth(), vp.getHeight());
fbo->resize(vp.x, vp.y);
} else {
fbo = std::make_unique<Framebuffer>(vp.getWidth(), vp.getHeight());
fbo = std::make_unique<Framebuffer>(vp.x, vp.y);
}
context.setFramebuffer(fbo.get());
}
@@ -37,7 +36,7 @@ void PostProcessing::render(const DrawContext& context, Shader* screenShader) {
const auto& viewport = context.getViewport();
screenShader->use();
screenShader->uniform2i("u_screenSize", viewport.size());
screenShader->uniform2i("u_screenSize", viewport);
fbo->getTexture()->bind();
quadMesh->draw();
}
-16
View File
@@ -1,16 +0,0 @@
#include "Viewport.hpp"
Viewport::Viewport(uint width, uint height)
: width(width), height(height) {
}
Viewport::Viewport(const glm::ivec2& size) : width(size.x), height(size.y) {
}
uint Viewport::getWidth() const {
return width;
}
uint Viewport::getHeight() const {
return height;
}
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include <glm/glm.hpp>
#include "typedefs.hpp"
class Viewport {
uint width;
uint height;
public:
Viewport(uint width, uint height);
Viewport(const glm::ivec2& size);
virtual uint getWidth() const;
virtual uint getHeight() const;
glm::ivec2 size() const {
return glm::ivec2(width, height);
}
float getRatio() const {
return width / static_cast<float>(height);
}
};