/// <inheritdoc /> public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output) { if (renderContext.View.Frustum.Contains(Canvas.Bounds.GetBoundingBox()) == ContainmentType.Disjoint) { return; } Profiler.BeginEventGPU("UI Canvas"); // Calculate rendering matrix (world*view*projection) Canvas.GetWorldMatrix(out Matrix worldMatrix); Matrix.Multiply(ref worldMatrix, ref renderContext.View.View, out Matrix viewMatrix); Matrix.Multiply(ref viewMatrix, ref renderContext.View.Projection, out Matrix viewProjectionMatrix); // Pick a depth buffer GPUTexture depthBuffer = Canvas.IgnoreDepth ? null : renderContext.Buffers.DepthBuffer; // Render GUI in 3D var features = Render2D.Features; if (Canvas.RenderMode == CanvasRenderMode.WorldSpace || Canvas.RenderMode == CanvasRenderMode.WorldSpaceFaceCamera) { Render2D.Features &= ~Render2D.RenderingFeatures.VertexSnapping; } Render2D.CallDrawing(Canvas.GUI, context, input, depthBuffer, ref viewProjectionMatrix); Render2D.Features = features; Profiler.EndEventGPU(); }
public static void Release(GPUTexture rt) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_Release(FlaxEngine.Object.GetUnmanagedPtr(rt)); #endif }
public void ResolveMultisample(GPUTexture sourceMultisampleTexture, GPUTexture destTexture, int sourceSubResource = 0, int destSubResource = 0, PixelFormat format = PixelFormat.Unknown) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_ResolveMultisample(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(sourceMultisampleTexture), FlaxEngine.Object.GetUnmanagedPtr(destTexture), sourceSubResource, destSubResource, format); #endif }
public void Draw(GPUTexture dst, SpriteAtlas src) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_Draw2(unmanagedPtr, Object.GetUnmanagedPtr(dst), Object.GetUnmanagedPtr(src)); #endif }
public void ClearDepth(GPUTexture depthBuffer, float depthValue = 1.0f) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_ClearDepth(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(depthBuffer), depthValue); #endif }
public void CopyTexture(GPUTexture dstResource, uint dstSubresource, uint dstX, uint dstY, uint dstZ, GPUTexture srcResource, uint srcSubresource) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_CopyTextureRegion4(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(dstResource), dstSubresource, dstX, dstY, dstZ, FlaxEngine.Object.GetUnmanagedPtr(srcResource), srcSubresource); #endif }
public void DrawPostFxMaterial(MaterialBase material, GPUTextureView view, GPUTexture input = null) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_DrawPostFxMaterial2(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(material), view, FlaxEngine.Object.GetUnmanagedPtr(input)); #endif }
public static void Draw(RenderTask task, IntPtr[] selectedActors, GPUTexture target = null, GPUContext context = null, GPUTexture depthBuffer = null, bool enableDepthTest = false) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_Draw(FlaxEngine.Object.GetUnmanagedPtr(task), selectedActors, FlaxEngine.Object.GetUnmanagedPtr(target), FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(depthBuffer), enableDepthTest); #endif }
/// <summary> /// Draws postFx material to the render target. /// </summary> /// <param name="material">The material to render. It must be a post fx material.</param> /// <param name="output">The output texture. Must be valid and created.</param> /// <param name="input">The input texture. It's optional.</param> /// <param name="sceneRenderTask">Render task to use it's view description and the render buffers.</param> public void DrawPostFxMaterial(MaterialBase material, GPUTexture output, GPUTexture input, SceneRenderTask sceneRenderTask) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else Internal_DrawPostFxMaterial1(unmanagedPtr, GetUnmanagedPtr(material), GetUnmanagedPtr(output), GetUnmanagedPtr(input), ref sceneRenderTask.View, Object.GetUnmanagedPtr(sceneRenderTask.Buffers)); #endif }
public void DrawSceneDepth(SceneRenderTask task, GPUTexture output, List <Actor> customActors = null, ActorsSources actorsSource = ActorsSources.Scenes) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else // Get unmanaged actors var actors = GetActors(customActors, out int actorsCount); Internal_DrawSceneDepth(unmanagedPtr, GetUnmanagedPtr(task), GetUnmanagedPtr(output), actors, actorsCount, actorsSource); #endif }
public void Clear(GPUTexture texture, Color color) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else if (texture == null) { throw new ArgumentNullException(nameof(texture)); } Internal_Clear(unmanagedPtr, texture.View(), ref color); #endif }
public void DrawScene(RenderTask task, GPUTexture output, RenderBuffers buffers, ref RenderView view, List <Actor> customActors = null, ActorsSources actorsSource = ActorsSources.ScenesAndCustomActors, HashSet <PostProcessEffect> customPostFx = null) { #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else // Get unmanaged actors var actors = GetActors(customActors, out int actorsCount); // Get unmanaged postFx var postFx = GetPostFx(customPostFx, out int postFxCount); Internal_DrawScene(unmanagedPtr, GetUnmanagedPtr(task), GetUnmanagedPtr(output), GetUnmanagedPtr(buffers), ref view, actors, actorsCount, actorsSource, postFx, postFxCount); #endif }
/// <summary> /// Executes the draw calls. /// </summary> /// <param name="context">The GPU command context.</param> /// <param name="task">The render task.</param> /// <param name="output">The output texture.</param> /// <param name="outputDepth">The output depth texture.</param> /// <param name="pass">The rendering pass mode.</param> public void ExecuteDrawCalls(GPUContext context, RenderTask task, GPUTexture output, GPUTexture outputDepth, DrawPass pass) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (task == null) { throw new ArgumentNullException(nameof(task)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } GPUContext.Internal_ExecuteDrawCalls(context.unmanagedPtr, task.unmanagedPtr, output.unmanagedPtr, Object.GetUnmanagedPtr(outputDepth), DrawCalls, pass); }
/// <inheritdoc /> public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output) { // TODO: apply frustum culling to skip rendering if canvas is not in a viewport Profiler.BeginEventGPU("UI Canvas"); // Calculate rendering matrix (world*view*projection) Canvas.GetWorldMatrix(out Matrix worldMatrix); Matrix.Multiply(ref worldMatrix, ref renderContext.View.View, out Matrix viewMatrix); Matrix.Multiply(ref viewMatrix, ref renderContext.View.Projection, out Matrix viewProjectionMatrix); // Pick a depth buffer GPUTexture depthBuffer = Canvas.IgnoreDepth ? null : renderContext.Buffers.DepthBuffer; // Render GUI in 3D Render2D.CallDrawing(Canvas.GUI, context, input, depthBuffer, ref viewProjectionMatrix); Profiler.EndEventGPU(); }
/// <summary> /// Releases a temporary render target. /// </summary> /// <param name="rt">The reference to temporary target to release.</param> public static void Release(GPUTexture rt) { Internal_Release(FlaxEngine.Object.GetUnmanagedPtr(rt)); }
/// <summary> /// Draws postFx material to the render target. /// </summary> /// <param name="context">The GPU commands context to use.</param> /// <param name="renderContext">The rendering context.</param> /// <param name="material">The material to render. It must be a post fx material.</param> /// <param name="output">The output texture. Must be valid and created.</param> /// <param name="input">The input texture. It's optional.</param> public static void DrawPostFxMaterial(GPUContext context, ref RenderContext renderContext, MaterialBase material, GPUTexture output, GPUTextureView input) { Internal_DrawPostFxMaterial(FlaxEngine.Object.GetUnmanagedPtr(context), ref renderContext, FlaxEngine.Object.GetUnmanagedPtr(material), FlaxEngine.Object.GetUnmanagedPtr(output), FlaxEngine.Object.GetUnmanagedPtr(input)); }
/// <summary> /// Draws scene objects depth (to the output Z buffer). The output must be depth texture to write hardware depth to it. /// </summary> /// <param name="context">The GPU commands context to use.</param> /// <param name="task">Render task to use it's view description and the render buffers.</param> /// <param name="output">The output texture. Must be valid and created.</param> /// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param> public static void DrawSceneDepth(GPUContext context, SceneRenderTask task, GPUTexture output, Actor[] customActors) { Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), customActors); }
public static void CallDrawing(IDrawable drawableElement, GPUContext context, GPUTexture output) { if (context == null || output == null || drawableElement == null) { throw new ArgumentNullException(); } #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else if (Internal_DrawBegin1(context.unmanagedPtr, output.unmanagedPtr)) { throw new InvalidOperationException("Cannot perform GUI rendering."); } try { drawableElement.Draw(); } finally { Internal_DrawEnd(); } #endif }
/// <summary> /// Draws the texture. /// </summary> /// <param name="t">The texture to draw.</param> /// <param name="rect">The rectangle to draw.</param> public static void DrawTexture(GPUTexture t, Rectangle rect) { var color = Color.White; Internal_DrawTexture1(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color); }
/// <summary> /// Calls drawing GUI to the texture. /// </summary> /// <param name="drawableElement">The root container for Draw methods.</param> /// <param name="context">The GPU context to handle graphics commands.</param> /// <param name="output">The output render target.</param> 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(); } }
/// <summary> /// Draws scene objects depth (to the output Z buffer). The output must be depth texture to write hardware depth to it. /// </summary> /// <param name="context">The GPU commands context to use.</param> /// <param name="task">Render task to use it's view description and the render buffers.</param> /// <param name="output">The output texture. Must be valid and created.</param> /// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param> public static void DrawSceneDepth(GPUContext context, SceneRenderTask task, GPUTexture output, List <Actor> customActors) { Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), Utils.ExtractArrayFromList(customActors)); }
/// <summary> /// Draws the texture (uses point sampler). /// </summary> /// <param name="t">The texture to draw.</param> /// <param name="rect">The rectangle to draw.</param> /// <param name="color">The color to multiply all texture pixels.</param> public static void DrawTexturePoint(GPUTexture t, Rectangle rect, Color color) { Internal_DrawTexturePoint(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ref color); }
/// <summary> /// 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. /// </summary> /// <param name="drawableElement">The root container for Draw methods.</param> /// <param name="context">The GPU context to handle graphics commands.</param> /// <param name="output">The output render target.</param> /// <param name="depthBuffer">The depth buffer render target. It's optional parameter but if provided must match output texture.</param> /// <param name="viewProjection">The View*Projection matrix used to transform all rendered vertices.</param> 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(); } }
/// <summary> /// Begins the rendering phrase. /// </summary> /// <param name="context">The GPU commands context to use.</param> /// <param name="output">The output target.</param> /// <param name="depthBuffer">The depth buffer.</param> public static void Begin(GPUContext context, GPUTexture output, GPUTexture depthBuffer = null) { Internal_Begin(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(output), FlaxEngine.Object.GetUnmanagedPtr(depthBuffer)); }
/// <summary> /// Draws postFx material to the render target. /// </summary> /// <param name="material">The material to render. It must be a post fx material.</param> /// <param name="output">The output texture. Must be valid and created.</param> /// <param name="input">The input texture. It's optional.</param> public void DrawPostFxMaterial(MaterialBase material, GPUTexture output, GPUTexture input = null) { DrawPostFxMaterial(material, output.View(), input); }
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."); } } #if UNIT_TEST_COMPILANT throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set."); #else if (Internal_DrawBegin2(context.unmanagedPtr, output.unmanagedPtr, Object.GetUnmanagedPtr(depthBuffer), ref viewProjection)) { throw new InvalidOperationException("Cannot perform GUI rendering."); } try { drawableElement.Draw(); } finally { Internal_DrawEnd(); } #endif }
/// <summary> /// Performs custom rendering. /// </summary> /// <param name="t">The texture to use.</param> /// <param name="rect">The rectangle area to draw.</param> /// <param name="ps">The custom pipeline state to use (input must match default Render2D vertex shader and can use single texture).</param> /// <param name="color">The color to multiply all texture pixels.</param> public static void DrawCustom(GPUTexture t, Rectangle rect, IntPtr ps, Color color) { Internal_DrawCustom(FlaxEngine.Object.GetUnmanagedPtr(t), ref rect, ps, ref color); }
/// <summary> /// Captures the specified render target contents and saves it to the file. /// Remember that downloading data from the GPU may take a while so screenshot may be taken one or more frames later due to latency. /// </summary> /// <param name="target">The target render target to capture it's contents.</param> /// <param name="path">The custom file location. Use null or empty to use default one.</param> public static void Capture(GPUTexture target, string path = null) { Internal_Capture(FlaxEngine.Object.GetUnmanagedPtr(target), path); }
/// <summary> /// Begins the rendering phrase. /// </summary> /// <param name="context">The GPU commands context to use.</param> /// <param name="output">The output target.</param> /// <param name="depthBuffer">The depth buffer.</param> /// <param name="viewProjection">The View*Projection matrix. Allows to render GUI in 3D or with custom transformations.</param> public static void Begin(GPUContext context, GPUTexture output, GPUTexture depthBuffer, ref Matrix viewProjection) { Internal_Begin1(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(output), FlaxEngine.Object.GetUnmanagedPtr(depthBuffer), ref viewProjection); }
/// <summary> /// Updates the texture data. /// </summary> /// <param name="texture">The destination texture.</param> /// <param name="arrayIndex">The destination surface index in the texture array.</param> /// <param name="mipIndex">The absolute index of the mip map to update.</param> /// <param name="data">The pointer to the data.</param> /// <param name="rowPitch">The row pitch (in bytes) of the input data.</param> /// <param name="slicePitch">The slice pitch (in bytes) of the input data.</param> public void UpdateTexture(GPUTexture texture, int arrayIndex, int mipIndex, IntPtr data, uint rowPitch, uint slicePitch) { Internal_UpdateTexture(unmanagedPtr, FlaxEngine.Object.GetUnmanagedPtr(texture), arrayIndex, mipIndex, data, rowPitch, slicePitch); }