GL-related refactor
This commit is contained in:
+70
-27
@@ -3,10 +3,16 @@
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "Batch2D.h"
|
||||
#include "Framebuffer.h"
|
||||
|
||||
GfxContext::GfxContext(const GfxContext* parent, Viewport& viewport, Batch2D* g2d)
|
||||
: parent(parent), viewport(viewport), g2d(g2d) {
|
||||
}
|
||||
GfxContext::GfxContext(
|
||||
const GfxContext* parent,
|
||||
const Viewport& viewport,
|
||||
Batch2D* g2d
|
||||
) : parent(parent),
|
||||
viewport(viewport),
|
||||
g2d(g2d)
|
||||
{}
|
||||
|
||||
GfxContext::~GfxContext() {
|
||||
while (scissorsCount--) {
|
||||
@@ -15,20 +21,39 @@ GfxContext::~GfxContext() {
|
||||
|
||||
if (parent == nullptr)
|
||||
return;
|
||||
|
||||
if (depthMask_ != parent->depthMask_) {
|
||||
glDepthMask(parent->depthMask_);
|
||||
|
||||
if (g2d) {
|
||||
g2d->flush();
|
||||
}
|
||||
if (depthTest_ != parent->depthTest_) {
|
||||
if (depthTest_) glDisable(GL_DEPTH_TEST);
|
||||
|
||||
if (fbo != parent->fbo) {
|
||||
if (fbo) {
|
||||
fbo->unbind();
|
||||
}
|
||||
if (parent->fbo) {
|
||||
fbo->bind();
|
||||
}
|
||||
}
|
||||
|
||||
Window::viewport(
|
||||
0, 0,
|
||||
parent->viewport.getWidth(),
|
||||
parent->viewport.getHeight()
|
||||
);
|
||||
|
||||
if (depthMask != parent->depthMask) {
|
||||
glDepthMask(parent->depthMask);
|
||||
}
|
||||
if (depthTest != parent->depthTest) {
|
||||
if (depthTest) glDisable(GL_DEPTH_TEST);
|
||||
else glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
if (cullFace_ != parent->cullFace_) {
|
||||
if (cullFace_) glDisable(GL_CULL_FACE);
|
||||
if (cullFace != parent->cullFace) {
|
||||
if (cullFace) glDisable(GL_CULL_FACE);
|
||||
else glEnable(GL_CULL_FACE);
|
||||
}
|
||||
if (blendMode_ != parent->blendMode_) {
|
||||
Window::setBlendMode(parent->blendMode_);
|
||||
if (blendMode != parent->blendMode) {
|
||||
Window::setBlendMode(parent->blendMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,22 +67,40 @@ Batch2D* GfxContext::getBatch2D() const {
|
||||
|
||||
GfxContext GfxContext::sub() const {
|
||||
auto ctx = GfxContext(this, viewport, g2d);
|
||||
ctx.depthTest_ = depthTest_;
|
||||
ctx.cullFace_ = cullFace_;
|
||||
ctx.depthTest = depthTest;
|
||||
ctx.cullFace = cullFace;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void GfxContext::depthMask(bool flag) {
|
||||
if (depthMask_ == flag)
|
||||
void GfxContext::setViewport(const Viewport& viewport) {
|
||||
this->viewport = viewport;
|
||||
Window::viewport(
|
||||
0, 0,
|
||||
viewport.getWidth(),
|
||||
viewport.getHeight()
|
||||
);
|
||||
}
|
||||
|
||||
void GfxContext::setFramebuffer(Framebuffer* fbo) {
|
||||
if (this->fbo == fbo)
|
||||
return;
|
||||
depthMask_ = flag;
|
||||
this->fbo = fbo;
|
||||
if (fbo) {
|
||||
fbo->bind();
|
||||
}
|
||||
}
|
||||
|
||||
void GfxContext::setDepthMask(bool flag) {
|
||||
if (depthMask == flag)
|
||||
return;
|
||||
depthMask = flag;
|
||||
glDepthMask(GL_FALSE + flag);
|
||||
}
|
||||
|
||||
void GfxContext::depthTest(bool flag) {
|
||||
if (depthTest_ == flag)
|
||||
void GfxContext::setDepthTest(bool flag) {
|
||||
if (depthTest == flag)
|
||||
return;
|
||||
depthTest_ = flag;
|
||||
depthTest = flag;
|
||||
if (flag) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
@@ -65,10 +108,10 @@ void GfxContext::depthTest(bool flag) {
|
||||
}
|
||||
}
|
||||
|
||||
void GfxContext::cullFace(bool flag) {
|
||||
if (cullFace_ == flag)
|
||||
void GfxContext::setCullFace(bool flag) {
|
||||
if (cullFace == flag)
|
||||
return;
|
||||
cullFace_ = flag;
|
||||
cullFace = flag;
|
||||
if (flag) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
} else {
|
||||
@@ -76,14 +119,14 @@ void GfxContext::cullFace(bool flag) {
|
||||
}
|
||||
}
|
||||
|
||||
void GfxContext::blendMode(blendmode mode) {
|
||||
if (blendMode_ == mode)
|
||||
void GfxContext::setBlendMode(blendmode mode) {
|
||||
if (blendMode == mode)
|
||||
return;
|
||||
blendMode_ = mode;
|
||||
blendMode = mode;
|
||||
Window::setBlendMode(mode);
|
||||
}
|
||||
|
||||
void GfxContext::scissors(glm::vec4 area) {
|
||||
void GfxContext::setScissors(glm::vec4 area) {
|
||||
Window::pushScissor(area);
|
||||
scissorsCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user