Skip to content

Commit 234ada8

Browse files
committed
fix: premuliplied alpha blending
1 parent 1aa21c4 commit 234ada8

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

crates/gdcef/src/cef_texture/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use cef::{self, ImplBrowserHost, ImplDragData, do_message_loop_work};
1010
use godot::classes::notify::ControlNotification;
1111
use godot::classes::texture_rect::ExpandMode;
1212
use godot::classes::{
13-
ITextureRect, ImageTexture, InputEvent, InputEventKey, InputEventMagnifyGesture,
14-
InputEventMouseButton, InputEventMouseMotion, InputEventPanGesture, InputEventScreenDrag,
15-
InputEventScreenTouch, LineEdit, TextureRect,
13+
CanvasItemMaterial, ITextureRect, ImageTexture, InputEvent, InputEventKey,
14+
InputEventMagnifyGesture, InputEventMouseButton, InputEventMouseMotion, InputEventPanGesture,
15+
InputEventScreenDrag, InputEventScreenTouch, LineEdit, TextureRect,
1616
};
1717
use godot::prelude::*;
1818

@@ -181,6 +181,12 @@ impl CefTexture {
181181
position - self.base().get_global_position()
182182
}
183183

184+
fn make_browser_material() -> Gd<godot::classes::Material> {
185+
let mut material = CanvasItemMaterial::new_gd();
186+
material.set_blend_mode(godot::classes::canvas_item_material::BlendMode::PREMULT_ALPHA);
187+
material.upcast()
188+
}
189+
184190
#[signal]
185191
fn ipc_message(message: GString);
186192

@@ -270,6 +276,7 @@ impl CefTexture {
270276
self.with_app_mut(|app| app.mark_cef_retained());
271277

272278
self.base_mut().set_expand_mode(ExpandMode::IGNORE_SIZE);
279+
self.base_mut().set_material(&Self::make_browser_material());
273280
// Must explicitly enable processing when using on_notification instead of fn process()
274281
self.base_mut().set_process(true);
275282
// Enable focus so we receive FOCUS_ENTER/EXIT notifications and can forward to CEF.

crates/gdcef/src/cef_texture/rendering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl CefTexture {
154154
if self.popup_overlay.is_none() {
155155
let mut overlay = TextureRect::new_alloc();
156156
overlay.set_expand_mode(ExpandMode::IGNORE_SIZE);
157+
overlay.set_material(&Self::make_browser_material());
157158
overlay.set_mouse_filter(MouseFilter::IGNORE);
158159
let overlay_node: Gd<godot::classes::Node> = overlay.clone().upcast();
159160
self.base_mut().add_child(&overlay_node);

0 commit comments

Comments
 (0)