// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; namespace FlaxEngine { partial class Render2D { /// /// Pushes transformation layer. /// /// The transformation to apply. public static void PushTransform(Matrix3x3 transform) { Internal_PushTransform(ref transform); } /// /// Pushes clipping rectangle mask. /// /// The axis aligned clipping mask rectangle. public static void PushClip(Rectangle clipRect) { Internal_PushClip(ref clipRect); } /// /// Draws the render target. /// /// The render target handle to draw. /// The rectangle to draw. public static void DrawTexture(GPUTextureView rt, Rectangle rect) { var color = Color.White; Internal_DrawTexture(FlaxEngine.Object.GetUnmanagedPtr(rt), ref rect, ref color); } /// /// Draws the texture. /// /// The texture to draw. /// The rectangle to draw. public static void DrawTexture(GPUTexture t, Rectangle rect) { var color = Color.White; Internal_DrawTexture1(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color); } /// /// Draws the texture. /// /// The texture to draw. /// The rectangle to draw. public static void DrawTexture(TextureBase t, Rectangle rect) { var color = Color.White; Internal_DrawTexture2(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color); } /// /// Draws a sprite. /// /// The sprite to draw. /// The rectangle to draw. public static void DrawSprite(SpriteHandle spriteHandle, Rectangle rect) { DrawSprite(spriteHandle, rect, Color.White); } /// /// Draws the texture (uses point sampler). /// /// The texture to draw. /// The rectangle to draw. public static void DrawTexturePoint(GPUTexture t, Rectangle rect) { var color = Color.White; Internal_DrawTexturePoint(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color); } /// /// Draws a sprite (uses point sampler). /// /// The sprite to draw. /// The rectangle to draw. public static void DrawSpritePoint(SpriteHandle spriteHandle, Rectangle rect) { DrawSpritePoint(spriteHandle, rect, Color.White); } /// /// Draws the GUI material. /// /// The material to render. Must be a GUI material type. /// The target rectangle to draw. public static void DrawMaterial(MaterialBase material, Rectangle rect) { var color = Color.White; Internal_DrawMaterial(FlaxEngine.Object.GetUnmanagedPtr(material), ref rect, ref color); } /// /// Draws a text. /// /// The font to use. /// The text to render. /// The size and position of the area in which the text is drawn. /// The text color. /// The horizontal alignment of the text in a layout rectangle. /// The vertical alignment of the text in a layout rectangle. /// Describes how wrap text inside a layout rectangle. /// The scale for distance one baseline from another. Default is 1. /// The text drawing scale. Default is 1. public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f) { var layout = new TextLayoutOptions { Bounds = layoutRect, HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment, TextWrapping = textWrapping, Scale = scale, BaseLinesGapScale = baseLinesGapScale, }; DrawText(font, text, color, ref layout); } /// /// Draws a text using a custom material shader. Given material must have GUI domain and a public parameter named Font (texture parameter used for a font atlas sampling). /// /// The font to use. /// Custom material for font characters rendering. It must contain texture parameter named Font used to sample font texture. /// The text to render. /// The size and position of the area in which the text is drawn. /// The text color. /// The horizontal alignment of the text in a layout rectangle. /// The vertical alignment of the text in a layout rectangle. /// Describes how wrap text inside a layout rectangle. /// The scale for distance one baseline from another. Default is 1. /// The text drawing scale. Default is 1. public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f) { var layout = new TextLayoutOptions { Bounds = layoutRect, HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment, TextWrapping = textWrapping, Scale = scale, BaseLinesGapScale = baseLinesGapScale, }; DrawText(font, text, color, ref layout, customMaterial); } /// /// Calls drawing GUI to the texture. /// /// The root container for Draw methods. /// The GPU context to handle graphics commands. /// The output render target. public static void CallDrawing(IDrawable drawableElement, GPUContext context, GPUTexture output) { if (context == null || output == null || drawableElement == null) throw new ArgumentNullException(); Begin(context, output); try { drawableElement.Draw(); } finally { End(); } } /// /// Calls drawing GUI to the texture using custom View*Projection matrix. /// If depth buffer texture is provided there will be depth test performed during rendering. /// /// The root container for Draw methods. /// The GPU context to handle graphics commands. /// The output render target. /// The depth buffer render target. It's optional parameter but if provided must match output texture. /// The View*Projection matrix used to transform all rendered vertices. public static void CallDrawing(IDrawable drawableElement, GPUContext context, GPUTexture output, GPUTexture depthBuffer, ref Matrix viewProjection) { if (context == null || output == null || drawableElement == null) throw new ArgumentNullException(); if (depthBuffer != null) { if (!depthBuffer.IsAllocated) throw new InvalidOperationException("Depth buffer is not allocated. Use GPUTexture.Init before rendering."); if (output.Size != depthBuffer.Size) throw new InvalidOperationException("Output buffer and depth buffer dimensions must be equal."); } Begin(context, output, depthBuffer, ref viewProjection); try { drawableElement.Draw(); } finally { End(); } } } }