static TextureBuilder CreateRenderTarget()

Summary

Begins creation of a ['a']. Finish by calling M:Sandbox.TextureBuilder.Create(System.String,System.Boolean,System.ReadOnlySpan{System.Byte},System.Int32).

static Texture CreateRenderTarget( string name, ImageFormat format, Vector2 size )

Summary

A convenience function to quickly create a ['a'].

static Texture CreateRenderTarget( string name, ImageFormat format, Vector2 size, Texture oldTexture )

Summary

This will create a ['a'] texture if ['paramref'] is null or doesn't match what you've passed in. This is designed to be called regularly to resize your texture in response to other things changing (like the screen size, panel size etc).
trophy 1421
Jul 2022 1 post
Michael 19 days ago edited 19 days ago
Here's a simple implementation of a viewport using this, inheriting from Image:
using Sandbox;
using Sandbox.UI;

/// <summary>
/// A box that will display what a Camera sees.
/// </summary>
public partial class ViewPort : Image
{
    /// <summary>The camera that will render to our texture.</summary>
    public CameraComponent Camera { get; set; }

    /// <summary>The image format that the texture will use.</summary>
    public ImageFormat TextureFormat { get; set; } = ImageFormat.RGBA8888;

    protected override void OnAfterTreeRender( bool firstTime )
    {
        Vector2 textureSize = (Box.Rect.Size.Length != 0) ? Box.Rect.Size : new( 200, 200 );
        Camera.RenderTarget = Texture.CreateRenderTarget( "camerapanel", TextureFormat, textureSize, Camera.RenderTarget );
        Texture = Camera.RenderTarget;
    }

    protected override int BuildHash() => Box.Rect.Size.LengthSquared.FloorToInt();
}

You can then implement it inside a Razor PanelComponent like this:
<ViewPort [email protected] />
trophy 115
Aug 2024 2 posts
MichaelI need yuou....
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.