summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/Gal.hpp7
-rw-r--r--src/GalOgl.cpp21
-rw-r--r--src/Rml.cpp2
3 files changed, 29 insertions, 1 deletions
diff --git a/src/Gal.hpp b/src/Gal.hpp
index 76db560..fe99dc7 100644
--- a/src/Gal.hpp
+++ b/src/Gal.hpp
@@ -86,6 +86,11 @@ namespace Gal {
TriangleFan,
};
+ enum class Blending {
+ Opaque,
+ Additive,
+ };
+
struct VertexAttribute {
std::string name;
Type type;
@@ -186,6 +191,8 @@ namespace Gal {
virtual void SetPrimitive(Primitive primitive) = 0;
+ virtual void SetBlending(Blending blendingMode) = 0;
+
virtual std::shared_ptr<BufferBinding> BindVertexBuffer(std::vector<VertexAttribute> &&bufferLayout) = 0;
virtual std::shared_ptr<BufferBinding> BindIndexBuffer() = 0;
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)
diff --git a/src/Rml.cpp b/src/Rml.cpp
index 746f6a4..f6fff44 100644
--- a/src/Rml.cpp
+++ b/src/Rml.cpp
@@ -68,6 +68,7 @@ RmlRenderInterface::RmlRenderInterface() {
pipelineConfig->SetTarget(gal->GetDefaultFramebuffer());
pipelineConfig->SetVertexShader(gal->LoadVertexShader(vertexSource));
pipelineConfig->SetPixelShader(gal->LoadPixelShader(pixelSource));
+ pipelineConfig->SetBlending(Gal::Blending::Additive);
auto vertBuffBind = pipelineConfig->BindVertexBuffer({
{"pos", Gal::Type::Vec2},
@@ -92,6 +93,7 @@ RmlRenderInterface::RmlRenderInterface() {
texPipelineConfig->SetTarget(gal->GetDefaultFramebuffer());
texPipelineConfig->SetVertexShader(gal->LoadVertexShader(vertexSource));
texPipelineConfig->SetPixelShader(gal->LoadPixelShader(texPixelSource));
+ texPipelineConfig->SetBlending(Gal::Blending::Additive);
auto texVertBuffBind = texPipelineConfig->BindVertexBuffer({
{"pos", Gal::Type::Vec2},