Repository: godotengine/godot (language: cpp)

Issue:
Scaled popups use bilinear filtering when the project is configured to use nearest texture filtering
### Tested versions

v4.4.stable.official [4c311cbee] (broken)

v4.4.dev7.official [46c8f8c5c] (working)

### System information

Godot v4.4.stable - Arch Linux #1 SMP PREEMPT_DYNAMIC Thu, 27 Feb 2025 18:09:44 +0000 on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3090 (nvidia; 570.124.04) - AMD Ryzen 7 5800X 8-Core Processor (16 threads)

### Issue description

StyleBoxTexture suddenly tiling and appears blurred. See examples below.

edit: Forgot to mention, the Panel with the style renders correctly in the editor in both versions. The rendering issues only surface in-game.

### Steps to reproduce

I have a `StyleboxTexture` that uses a 16x16px sprite representing a border for tooltips.
Here are the settings.
![Image](https://github.com/user-attachments/assets/08e7a116-2cd9-4fe3-8a55-bb230be5b2e1)

Opening the project in 4.4.0-dev7, here is a screenshot of the tooltip in game.

![Image](https://github.com/user-attachments/assets/2f4f8ed9-985e-41f3-83d6-7c281f13090a)

Here is the exact same commit of my project, running in 4.4.0-stable

![Image](https://github.com/user-attachments/assets/7cbf298e-69d5-4cad-802e-26d573970e4e)

As you can see there are white lines where the edge of the border is tiling. The texture also appears blurrier in 4.4 stable. Increasing the TextureMargin from 5->6px gets rid of the tiling (while adding an extra pixel of empty space around the content) but the texture still looks blurry compared to the SS from dev7.

My guess is there is some AA happening but I have all texture filtering / AA turned off as this is a pixel art game. Unless there is a new setting somewhere that is defaulting to filter/compress/etc

### Minimal reproduction project (MRP)

[repro.zip](https://github.com/user-attachments/files/19080465/repro.zip)


Discussion / hints:
> ### Minimal reproduction project (MRP)
> 
> LMK if the above is not enough and I can provide a MRP

Please do provide an MRP so the issue could be properly investigated (without any guessing about your setup).
Having a similar issue with our pixel-art game, but instead of tooltips its our PopupMenu / PopupPanel. 

It looks awful with similar effects to what you described. Seems like some AA was applied, making everything blurry and messing up our bitmap font. The texture margin is messed up exactly as you described. 
![Image](https://github.com/user-attachments/assets/230e40e8-5341-496e-968f-ddcc2f4cd899)

Can't find a setting or a way to fix this. I really hope this gets a workaround or fix found ASAP, it is really horrible for 2D pixel game UI. 

Edit: Tinkered with some stuff, it seems like setting the window to scale by viewport instead of canvas_items works as a temporary fix. I'll miss stretching the window around though, so I hope a fix for canvas_items scaling is found.

![Image](https://github.com/user-attachments/assets/31017026-9e61-41c6-9e87-0f36710bc539)

![Image](https://github.com/user-attachments/assets/5b51d22a-44a2-4991-8911-23cd955fd08d)
https://github.com/godotengine/godot/issues/54030 was resolved in 4.4 by https://github.com/godotengine/godot/pull/97745, which means popups are now drawn at native resolution when using the `canvas_items` stretch mode as it did in 3.x.

However, popups in 4.x still use their own viewport, which means textures displayed within the popup will use bilinear filtering if their default texture filter is not configured accordingly. The Canvas Texture default filter project setting should be set to one of the **Nearest** options. It's possible that this isn't being consistently applied to popups though, which could be an engine issue.

Also, check if this occurs with the **Embed Subwindows** project setting disabled.

> Edit: Tinkered with some stuff, it seems like setting the window to scale by viewport instead of canvas_items works as a temporary fix. I'll miss stretching the window around though, so I hope a fix for canvas_items scaling is found.

You should set the scale mode project setting to `integer` for pixel art (regardless of the stretch mode). [Pixel art will look bad at non-integer scale factors.](https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html#stretch-scale-mode)
> [#54030](https://github.com/godotengine/godot/issues/54030) was resolved in 4.4 by [#97745](https://github.com/godotengine/godot/pull/97745), which means popups are now drawn at native resolution when using the `canvas_items` stretch mode as it did in 3.x.
> 
> However, popups in 4.x still use their own viewport, which means textures displayed within the popup will use bilinear filtering if their default texture filter is not configured correctly. The Canvas Texture default filter project setting should be set to one of the **Nearest** options. It's possible that this isn't being consistently applied to popups though, which could be an engine issue.
> 
> > Edit: Tinkered with some stuff, it seems like setting the window to scale by viewport instead of canvas_items works as a temporary fix. I'll miss stretching the window around though, so I hope a fix for canvas_items scaling is found.
> 
> You should set the scale mode project setting to `integer` for pixel art (regardless of the stretch mode). [Pixel art will look bad at non-integer scale factors.](https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html#stretch-scale-mode)

Yeah, my Canvas Texture default filter is set to Nearest, yet I still face this issue when using `canvas_items` scaling. I actually found that using `viewport` scaling messes up our camera movement during cutscenes in our game, so it's actually more imperative that the issue gets fixed for `canvas_items` scaling. Seems like you already have that figured out though.

Also, for the last point, our plan is to set it to `integer` for the final release of our project, but right now it's `fractional` just because we like to stretch the window around for comfort purposes. 

![Image](https://github.com/user-attachments/assets/67b53cbb-e459-4d3b-ae52-f8841e8d6385)

Edit: 

> Also, check if this occurs with the Embed Subwindows project setting disabled.

I usually have this setting enabled. Disabling it seems to fix the issue but produces an undesirable result for a pixel art game (super tiny dropdown menu)

![Image](https://github.com/user-attachments/assets/5cb8b511-00d7-4667-ab52-2665ff5d7c7d)

Enabling it produces the behavior shown in previous posts.
Just uploaded a repro project. It's not exactly the same setup as my main project as the margin isn't clipping the same way but you can see the blurriness in game vs in the editor.

For reference, here are my display settings from my game's `project.godot`
```
[display]

window/size/viewport_width=640
window/size/viewport_height=360
window/size/always_on_top=true
window/size/window_width_override=1920
window/size/window_height_override=1080
window/stretch/mode="canvas_items"
window/stretch/aspect="expand"
window/stretch/scale_mode="integer"
display_server/driver.linuxbsd="x11"
```

>Also, check if this occurs with the Embed Subwindows project setting disabled.

This causes a different issue. The tooltips are appearing way too small.

![Image](https://github.com/user-attachments/assets/4b5f5565-52ef-4e41-bdc5-4d95f25e3158)

I am guessing that this is because they are rendering at physical pixel sizes instead of scaled to the game window. eg 100px tall on my 1440px tall screen, rather than 100px of the 360px render height.

Changing the stretch mode to viewport does fix the issue but I am not exactly sure what the other consequences will be.

edit: side note
@Professor-Moof that final screenshot of your project settings is heinous. I thought I had a dead pixel for a second.
@Jack-023 
> Changing the stretch mode to viewport does fix the issue but I am not exactly sure what the other consequences will be.

Like I said, it completely messed up the smoothness of our camera during cutscenes of our game, so there definitely is consequences to switching to `viewport` if you have developed a game entirely with `canvas_items` scaling in mind. I am personally just waiting for a fix. 

> edit: side note
@Professor-Moof that final screenshot of your project settings is heinous. I thought I had a dead pixel for a second.

this is what happens when you use W11's built in screenshot tool and accidentally use the marker tool because I accidentally clicked slightly on the photo before saving it. It is heinous, I agree. I apologize for these grave misdeeds. 


> [repro.zip](https://github.com/user-attachments/files/19080465/repro.zip)

As a workaround it's of course enough to change `texture_filter` of your to-be-added-to-tooltip-custom-Control from `Inherited` to `Nearest` (so it won't inherit incorrect filter from the tooltip-PopupPanel):
![Image](https://github.com/user-attachments/assets/e30378cf-4dde-4c41-8eed-e331099359d6)

Alternative workaround would be e.g. to propagate the viewport's default filter (and repeat) to the tooltip-PopupPanel, adding such autoload would do:
```gdscript
extends Node

func _enter_tree() -> void:
	get_tree().node_added.connect(on_node_added)

func on_node_added(node: Node) -> void:
	var pp := node as PopupPanel
	if pp and pp.theme_type_variation == "TooltipPanel":
		var parent_viewport := pp.get_parent().get_viewport()
		pp.canvas_item_default_texture_filter = parent_viewport.canvas_item_default_texture_filter
		pp.canvas_item_default_texture_repeat = parent_viewport.canvas_item_default_texture_repeat
```

Fix patch:
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index d0054baeff25..43c42882fb55 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1546,6 +1546,8 @@ void Viewport::_gui_show_tooltip() {
 	panel->set_flag(Window::FLAG_POPUP, false);
 	panel->set_flag(Window::FLAG_MOUSE_PASSTHROUGH, true);
 	panel->set_wrap_controls(true);
+	panel->set_default_canvas_item_texture_filter(get_default_canvas_item_texture_filter());
+	panel->set_default_canvas_item_texture_repeat(get_default_canvas_item_texture_repeat());
 	panel->add_child(base_tooltip);
 	panel->gui_parent = this;
 


Test patch: