using NativeEngine; namespace Sandbox; public static partial class Graphics { /// /// Draws a single model at the given Transform immediately. /// /// The model to draw /// Transform to draw the model at /// Optional attributes to apply only for this draw call public static void DrawModel( Model model, Transform transform, RenderAttributes attributes = null ) { AssertRenderBlock(); attributes ??= Attributes; DrawModelInstanced( model, new[] { transform }, attributes ); } /// /// Draws multiple instances of a model using GPU instancing, assuming standard implemented shaders. /// /// Use `GetTransformMatrix( int instance )` in shaders to access the instance transform. /// /// There is a limit of 1,048,576 transform slots per frame when using this method. /// /// The model to draw /// Instance transform data to draw /// Optional attributes to apply only for this draw call public static unsafe void DrawModelInstanced( Model model, Span transforms, RenderAttributes attributes = null ) { AssertRenderBlock(); if ( transforms.Length <= 0 ) return; if ( !model.IsValid() ) return; attributes ??= Attributes; fixed ( Transform* pTransforms = transforms ) { RenderTools.DrawModel( Context, SceneLayer, model.native, (IntPtr)pTransforms, transforms.Length, attributes.Get() ); } } /// /// Draws multiple instances of a model using GPU instancing with the number of instances being provided by indirect draw arguments. /// Use `SV_InstanceID` semantic in shaders to access the rendered instance. /// /// The model to draw /// The GPU buffer containing the DrawIndirectArguments /// Optional offset in the GPU buffer /// Optional attributes to apply only for this draw call public static void DrawModelInstancedIndirect( Model model, GpuBuffer buffer, int bufferOffset = 0, RenderAttributes attributes = null ) { AssertRenderBlock(); if ( buffer is null ) return; attributes ??= Attributes; RenderTools.DrawModel( Context, SceneLayer, model.native, buffer.native, bufferOffset, attributes.Get() ); } /// /// Draws multiple instances of a model using GPU instancing. /// This is similar to , /// except the count is provided from the CPU rather than via a GPU buffer. /// /// Use `SV_InstanceID` semantic in shaders to access the rendered instance. /// /// The model to draw /// The number of instances to draw /// Optional attributes to apply only for this draw call public static unsafe void DrawModelInstanced( Model model, int count, RenderAttributes attributes = null ) { AssertRenderBlock(); if ( count <= 0 ) return; if ( !model.IsValid() ) return; attributes ??= Attributes; RenderTools.DrawModel( Context, SceneLayer, model.native, IntPtr.Zero, count, attributes.Get() ); } }