refactor: add Window interface

This commit is contained in:
MihailRis
2025-04-02 14:59:53 +03:00
parent cd5c6a889c
commit 9694a59649
31 changed files with 859 additions and 923 deletions
+8 -7
View File
@@ -25,10 +25,11 @@ static void set_blend_mode(BlendMode mode) {
DrawContext::DrawContext(
const DrawContext* parent,
Viewport viewport,
Window& window,
Batch2D* g2d
) : parent(parent),
viewport(std::move(viewport)),
) : window(window),
parent(parent),
viewport({window.getSize()}),
g2d(g2d),
flushable(g2d)
{}
@@ -39,7 +40,7 @@ DrawContext::~DrawContext() {
}
while (scissorsCount--) {
Window::popScissor();
window.popScissor();
}
if (parent == nullptr)
@@ -54,7 +55,7 @@ DrawContext::~DrawContext() {
}
}
Window::viewport(
glViewport(
0, 0,
parent->viewport.getWidth(),
parent->viewport.getHeight()
@@ -100,7 +101,7 @@ DrawContext DrawContext::sub(Flushable* flushable) const {
void DrawContext::setViewport(const Viewport& viewport) {
this->viewport = viewport;
Window::viewport(
glViewport(
0, 0,
viewport.getWidth(),
viewport.getHeight()
@@ -153,7 +154,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
}
void DrawContext::setScissors(const glm::vec4& area) {
Window::pushScissor(area);
window.pushScissor(area);
scissorsCount++;
}
+7 -1
View File
@@ -4,10 +4,12 @@
#include "Viewport.hpp"
#include "typedefs.hpp"
class Window;
class Batch2D;
class Framebuffer;
class DrawContext {
Window& window;
const DrawContext* parent;
Viewport viewport;
Batch2D* g2d;
@@ -20,7 +22,11 @@ class DrawContext {
int scissorsCount = 0;
float lineWidth = 1.0f;
public:
DrawContext(const DrawContext* parent, Viewport viewport, Batch2D* g2d);
DrawContext(
const DrawContext* parent,
Window& window,
Batch2D* g2d
);
~DrawContext();
Batch2D* getBatch2D() const;
+3
View File
@@ -4,6 +4,9 @@ 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;
}
+1
View File
@@ -9,6 +9,7 @@ class Viewport {
uint height;
public:
Viewport(uint width, uint height);
Viewport(const glm::ivec2& size);
virtual uint getWidth() const;
virtual uint getHeight() const;