From 8017660ecafdc061c8dc301925b839dadf66f1c3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 4 Oct 2026 14:20:30 +0200 Subject: [PATCH] Add `ConstantInvalidate` option to `RenderToTextureControl` for no-cached image --- .../UI/GUI/Common/RenderToTextureControl.cs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs index f1a9c69a5..abaf69e21 100644 --- a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs +++ b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs @@ -9,7 +9,7 @@ namespace FlaxEngine.GUI public class RenderToTextureControl : ContainerControl { private bool _invalid, _redrawRegistered, _isDuringTextureDraw; - private bool _autoSize = true; + private bool _autoSize = true, _constantInvalidate = false; private GPUTexture _texture; private Float2 _textureSize; private MaterialBase _drawMaterial; @@ -60,6 +60,33 @@ namespace FlaxEngine.GUI [EditorOrder(30)] public bool AutomaticInvalidate { get; set; } = true; + /// + /// Gets or sets the value whether cached texture data should be invalidated every frame (eg. when UI is animated). + /// + [EditorOrder(40)] + public bool ConstantInvalidate + { + get => _constantInvalidate; + set + { + if (_constantInvalidate != value) + { + _constantInvalidate = value; + if (value) + { + // Register for constant invalidation + Invalidate(); + } + else if (_invalid && _redrawRegistered) + { + // Don't invalidate anymore + _redrawRegistered = false; + Scripting.Draw -= OnDraw; + } + } + } + } + /// /// Gets or sets the GUI material used to draw the cached texture to the screen. /// Can be used to post-process underlying GUI with a custom shader (eg. chromatic-aberration, blur or tint). If not set, simple texture copy is performed. @@ -116,13 +143,16 @@ namespace FlaxEngine.GUI private void OnDraw() { - if (_redrawRegistered) + if (!ConstantInvalidate) { - _redrawRegistered = false; - Scripting.Draw -= OnDraw; + if (_redrawRegistered) + { + _redrawRegistered = false; + Scripting.Draw -= OnDraw; + } + if (!_invalid) + return; } - if (!_invalid) - return; _invalid = false; if (!_texture)