update DrawContext

This commit is contained in:
MihailRis
2024-07-21 16:06:40 +03:00
parent cf12338a32
commit 3590bd14cd
9 changed files with 67 additions and 45 deletions
+16 -7
View File
@@ -29,12 +29,13 @@ DrawContext::DrawContext(
Batch2D* g2d
) : parent(parent),
viewport(std::move(viewport)),
g2d(g2d)
g2d(g2d),
flushable(g2d)
{}
DrawContext::~DrawContext() {
if (g2d) {
g2d->flush();
if (flushable) {
flushable->flush();
}
while (scissorsCount--) {
@@ -73,6 +74,9 @@ DrawContext::~DrawContext() {
if (blendMode != parent->blendMode) {
set_blend_mode(parent->blendMode);
}
if (lineWidth != parent->lineWidth) {
glLineWidth(parent->lineWidth);
}
}
const Viewport& DrawContext::getViewport() const {
@@ -83,10 +87,10 @@ Batch2D* DrawContext::getBatch2D() const {
return g2d;
}
DrawContext DrawContext::sub() const {
auto ctx = DrawContext(this, viewport, g2d);
ctx.depthTest = depthTest;
ctx.cullFace = cullFace;
DrawContext DrawContext::sub(Flushable* flushable) const {
auto ctx = DrawContext(*this);
ctx.parent = this;
ctx.flushable = flushable;
return ctx;
}
@@ -148,3 +152,8 @@ void DrawContext::setScissors(glm::vec4 area) {
Window::pushScissor(area);
scissorsCount++;
}
void DrawContext::setLineWidth(float width) {
lineWidth = width;
glLineWidth(width);
}