summaryrefslogtreecommitdiffstats
path: root/src/GalOgl.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-12-05 01:42:15 +0100
committerLaG1924 <lag1924@gmail.com>2021-12-05 01:42:15 +0100
commitda66c30a110233f7c8b71b5e6aa8dd804879c1b6 (patch)
treebe229b509f08c6a0f851d5c4fdf3e322bac6402a /src/GalOgl.cpp
parentAdded Ambient occlusion options parameter (diff)
downloadAltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar.gz
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar.bz2
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar.lz
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar.xz
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.tar.zst
AltCraft-da66c30a110233f7c8b71b5e6aa8dd804879c1b6.zip
Diffstat (limited to '')
-rw-r--r--src/GalOgl.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp
index c7344fe..4ac6c84 100644
--- a/src/GalOgl.cpp
+++ b/src/GalOgl.cpp
@@ -89,6 +89,7 @@ class OglState {
GLuint activeTextureUnit = 0;
GLint vpX = 0, vpY = 0;
GLsizei vpW = 0, vpH = 0;
+ bool blending = false;
public:
@@ -162,6 +163,16 @@ public:
glCheckError();
}
+ void EnableBlending(bool enable) {
+ if (enable != blending) {
+ blending = enable;
+ if (blending)
+ glEnable(GL_BLEND);
+ else
+ glDisable(GL_BLEND);
+ }
+ }
+
} oglState;
std::unique_ptr<ImplOgl> impl;
@@ -791,6 +802,7 @@ struct PipelineConfigOgl : public PipelineConfig {
std::shared_ptr<FramebufferOgl> targetFb;
std::vector<std::vector<VertexAttribute>> vertexBuffers;
Primitive vertexPrimitive = Primitive::Triangle;
+ Blending blending = Blending::Opaque;
virtual void SetVertexShader(std::shared_ptr<Shader> shader) override {
vertexShader = std::static_pointer_cast<ShaderOgl,Shader>(shader);
@@ -818,6 +830,10 @@ struct PipelineConfigOgl : public PipelineConfig {
vertexPrimitive = primitive;
}
+ virtual void SetBlending(Blending blendingMode) override {
+ blending = blendingMode;
+ }
+
virtual std::shared_ptr<BufferBinding> BindVertexBuffer(std::vector<VertexAttribute> &&bufferLayout) override {
auto binding = std::make_shared<BufferBindingOgl>(vertexBuffers.size());
vertexBuffers.push_back(bufferLayout);
@@ -901,12 +917,14 @@ struct PipelineOgl : public Pipeline {
};
std::vector<VertexBindingCommand> vertexBindCmds;
Primitive primitive;
+ Blending blending;
std::shared_ptr<FramebufferOgl> target;
virtual void Activate() override {
oglState.UseProgram(program);
oglState.BindFbo(target->fbo);
oglState.SetViewport(target->vpX, target->vpY, target->vpW, target->vpH);
+ oglState.EnableBlending(blending == Blending::Additive);
if (target->fbo)
glDrawBuffers(target->attachments.size(), target->attachments.data());
@@ -1076,7 +1094,7 @@ struct ImplOgl : public Impl {
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
- glEnable(GL_BLEND);
+ oglState.EnableBlending(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glCheckError();
if (glActiveTexture == nullptr) {
@@ -1201,6 +1219,7 @@ struct ImplOgl : public Impl {
auto config = std::static_pointer_cast<PipelineConfigOgl, PipelineConfig>(pipelineConfig);
pipeline->primitive = config->vertexPrimitive;
+ pipeline->blending = config->blending;
pipeline->target = config->targetFb;
if (!pipeline->target)