Merge branch 'MihailRis:main' into main
This commit is contained in:
@@ -361,3 +361,7 @@ void Batch2D::render(unsigned int gl_primitive) {
|
||||
void Batch2D::render() {
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
void Batch2D::lineWidth(float width) {
|
||||
glLineWidth(width);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
float r4, float g4, float b4, int sh);
|
||||
void render(unsigned int gl_primitive);
|
||||
void render();
|
||||
|
||||
void lineWidth(float width);
|
||||
};
|
||||
|
||||
#endif /* SRC_GRAPHICS_BATCH2D_H_ */
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "GfxContext.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "Batch2D.h"
|
||||
|
||||
GfxContext::GfxContext(const GfxContext* parent, Viewport& viewport, Batch2D* g2d)
|
||||
: parent(parent), viewport(viewport), g2d(g2d) {
|
||||
}
|
||||
|
||||
GfxContext::~GfxContext() {
|
||||
if (parent == nullptr)
|
||||
return;
|
||||
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);
|
||||
else glEnable(GL_CULL_FACE);
|
||||
}
|
||||
}
|
||||
|
||||
const Viewport& GfxContext::getViewport() const {
|
||||
return viewport;
|
||||
}
|
||||
|
||||
Batch2D* GfxContext::getBatch2D() const {
|
||||
return g2d;
|
||||
}
|
||||
|
||||
GfxContext GfxContext::sub() const {
|
||||
auto ctx = GfxContext(this, viewport, g2d);
|
||||
ctx.depthTest_ = depthTest_;
|
||||
ctx.cullFace_ = cullFace_;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void GfxContext::depthTest(bool flag) {
|
||||
if (depthTest_ == flag)
|
||||
return;
|
||||
depthTest_ = flag;
|
||||
if (depthTest_) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
} else {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void GfxContext::cullFace(bool flag) {
|
||||
if (cullFace_ == flag)
|
||||
return;
|
||||
cullFace_ = flag;
|
||||
if (cullFace_) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef GRAPHICS_GFX_CONTEXT_H_
|
||||
#define GRAPHICS_GFX_CONTEXT_H_
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "Viewport.h"
|
||||
|
||||
class Batch2D;
|
||||
|
||||
class GfxContext {
|
||||
const GfxContext* parent;
|
||||
Viewport& viewport;
|
||||
Batch2D* const g2d;
|
||||
bool depthTest_ = false;
|
||||
bool cullFace_ = false;
|
||||
public:
|
||||
GfxContext(const GfxContext* parent, Viewport& viewport, Batch2D* g2d);
|
||||
~GfxContext();
|
||||
|
||||
Batch2D* getBatch2D() const;
|
||||
const Viewport& getViewport() const;
|
||||
GfxContext sub() const;
|
||||
|
||||
void depthTest(bool flag);
|
||||
void cullFace(bool flag);
|
||||
};
|
||||
|
||||
#endif // GRAPHICS_GFX_CONTEXT_H_
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "Viewport.h"
|
||||
|
||||
Viewport::Viewport(uint width, uint height)
|
||||
: width(width), height(height) {
|
||||
}
|
||||
|
||||
uint Viewport::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
uint Viewport::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef GRAPHICS_VIEWPORT_H_
|
||||
#define GRAPHICS_VIEWPORT_H_
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
class Viewport {
|
||||
uint width;
|
||||
uint height;
|
||||
public:
|
||||
Viewport(uint width, uint height);
|
||||
|
||||
virtual uint getWidth() const;
|
||||
virtual uint getHeight() const;
|
||||
|
||||
glm::vec2 size() const {
|
||||
return glm::vec2(width, height);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // GRAPHICS_VIEWPORT_H_
|
||||
Reference in New Issue
Block a user