Added the C# code equivalent to the note in Viewport.GetTexture()

Define 'viewport' for parity with GDScript's '$viewport'

Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
This commit is contained in:
Lurker 2025-08-14 18:53:34 -07:00
parent e67074d0ab
commit 0ea06fe446

View file

@ -122,11 +122,21 @@
<description> <description>
Returns the viewport's texture. Returns the viewport's texture.
[b]Note:[/b] When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. [method Node._ready]. To make sure the texture you get is correct, you can await [signal RenderingServer.frame_post_draw] signal. [b]Note:[/b] When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. [method Node._ready]. To make sure the texture you get is correct, you can await [signal RenderingServer.frame_post_draw] signal.
[codeblock] [codeblocks]
[gdscript]
func _ready(): func _ready():
await RenderingServer.frame_post_draw await RenderingServer.frame_post_draw
$Viewport.get_texture().get_image().save_png("user://Screenshot.png") $Viewport.get_texture().get_image().save_png("user://Screenshot.png")
[/codeblock] [/gdscript]
[csharp]
public async override void _Ready()
{
await ToSignal(RenderingServer.Singleton, RenderingServer.SignalName.FramePostDraw);
var viewport = GetNode&lt;Viewport&gt;("Viewport");
viewport.GetTexture().GetImage().SavePng("user://Screenshot.png");
}
[/csharp]
[/codeblocks]
[b]Note:[/b] When [member use_hdr_2d] is [code]true[/code] the returned texture will be an HDR image encoded in linear space. [b]Note:[/b] When [member use_hdr_2d] is [code]true[/code] the returned texture will be an HDR image encoded in linear space.
</description> </description>
</method> </method>