summaryrefslogtreecommitdiff
path: root/engine/src/renderer/opengl.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-04-18 16:17:03 +0200
committerHampusM <hampus@hampusmat.com>2026-04-18 16:17:03 +0200
commit250cb67defcdfc789bfc0b4fa26fce194e3f67cd (patch)
tree77c15aa87c36016fd2e25ebf166948a3bdb20435 /engine/src/renderer/opengl.rs
parent7d578207c76a9fd51c370cd06839410675f28e03 (diff)
feat(engine): add blending to renderer draw properties
Diffstat (limited to 'engine/src/renderer/opengl.rs')
-rw-r--r--engine/src/renderer/opengl.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs
index f80237a..c4d335c 100644
--- a/engine/src/renderer/opengl.rs
+++ b/engine/src/renderer/opengl.rs
@@ -20,6 +20,12 @@ use glutin::surface::{
Surface as GlutinSurface,
WindowSurface as GlutinWindowSurface,
};
+use opengl_bindings::blending::{
+ Configuration as GlBlendingConfig,
+ Equation as GlBlendingEquation,
+ Factor as GlBlendingFactor,
+ configure as gl_blending_configure,
+};
use opengl_bindings::debug::{
MessageIdsAction,
MessageSeverity,
@@ -66,6 +72,7 @@ use crate::data_types::dimens::Dimens;
use crate::image::{ColorType as ImageColorType, Image};
use crate::matrix::Matrix;
use crate::model::Model;
+use crate::renderer::blending::{Equation as BlendingEquation, Factor as BlendingFactor};
use crate::renderer::object::{
Id as RendererObjectId,
Kind as RendererObjectKind,
@@ -1158,6 +1165,34 @@ fn handle_commands(
draw_props.polygon_mode_config.mode,
);
}
+
+ if draw_props_update_flags
+ .contains(DrawPropertiesUpdateFlags::BLENDING_ENABLED)
+ {
+ set_enabled(
+ curr_gl_ctx,
+ Capability::Blend,
+ draw_props.blending_enabled,
+ );
+ }
+
+ if draw_props_update_flags
+ .contains(DrawPropertiesUpdateFlags::BLENDING_CONFIG)
+ {
+ gl_blending_configure(
+ curr_gl_ctx,
+ GlBlendingConfig::default()
+ .with_source_factor(blending_factor_to_gl(
+ draw_props.blending_config.source_factor,
+ ))
+ .with_destination_factor(blending_factor_to_gl(
+ draw_props.blending_config.destination_factor,
+ ))
+ .with_equation(blending_equation_to_gl(
+ draw_props.blending_config.equation,
+ )),
+ );
+ }
}
}
}
@@ -1554,3 +1589,34 @@ impl From<Vec3<f32>> for CF32Vec3
Self { x: src.x, y: src.y, z: src.z }
}
}
+
+fn blending_factor_to_gl(blending_factor: BlendingFactor) -> GlBlendingFactor
+{
+ match blending_factor {
+ BlendingFactor::Zero => GlBlendingFactor::Zero,
+ BlendingFactor::One => GlBlendingFactor::One,
+ BlendingFactor::SrcColor => GlBlendingFactor::SrcColor,
+ BlendingFactor::OneMinusSrcColor => GlBlendingFactor::OneMinusSrcColor,
+ BlendingFactor::DstColor => GlBlendingFactor::DstColor,
+ BlendingFactor::OneMinusDstColor => GlBlendingFactor::OneMinusDstColor,
+ BlendingFactor::SrcAlpha => GlBlendingFactor::SrcAlpha,
+ BlendingFactor::OneMinusSrcAlpha => GlBlendingFactor::OneMinusSrcAlpha,
+ BlendingFactor::DstAlpha => GlBlendingFactor::DstAlpha,
+ BlendingFactor::OneMinusDstAlpha => GlBlendingFactor::OneMinusDstAlpha,
+ BlendingFactor::ConstantColor => GlBlendingFactor::ConstantColor,
+ BlendingFactor::OneMinusConstantColor => GlBlendingFactor::OneMinusConstantColor,
+ BlendingFactor::ConstantAlpha => GlBlendingFactor::ConstantAlpha,
+ BlendingFactor::OneMinusConstantAlpha => GlBlendingFactor::OneMinusConstantAlpha,
+ }
+}
+
+fn blending_equation_to_gl(blending_equation: BlendingEquation) -> GlBlendingEquation
+{
+ match blending_equation {
+ BlendingEquation::Add => GlBlendingEquation::Add,
+ BlendingEquation::Subtract => GlBlendingEquation::Subtract,
+ BlendingEquation::ReverseSubtract => GlBlendingEquation::ReverseSubtract,
+ BlendingEquation::Min => GlBlendingEquation::Min,
+ BlendingEquation::Max => GlBlendingEquation::Max,
+ }
+}