Skip to content

Commit

Permalink
Revert "Add sampling option to UIComponent"
Browse files Browse the repository at this point in the history
  • Loading branch information
xen2 committed Apr 14, 2021
1 parent 65ff2a3 commit 5fc826c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 45 deletions.
11 changes: 0 additions & 11 deletions sources/engine/Stride.UI/Engine/UIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ public UIComponent()
[Display("Page")]
public UIPage Page { get; set; }

/// <summary>
/// Specifies the sampling method to be used for this component
/// </summary>
/// <userdoc>
/// Specifies the sampling method to be used for this component
/// </userdoc>
[DataMember(15)]
[DefaultValue(Sampler.LinearClamp)]
[Display("Sampler")]
public Sampler Sampler { get; set; } = Sampler.LinearClamp;

/// <summary>
/// Gets or sets the value indicating whether the UI should be full screen.
/// </summary>
Expand Down
14 changes: 0 additions & 14 deletions sources/engine/Stride.UI/Rendering/UI/RenderUIElement.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Stride.Core;
using Stride.Core.Mathematics;
using Stride.Engine;
using Stride.UI;

namespace Stride.Rendering.UI
{
public enum Sampler
{
[Display("Point (Nearest)")]
PointClamp,

[Display("Linear")]
LinearClamp,

[Display("Anisotropic")]
AnisotropicClamp,
}

public class RenderUIElement : RenderObject
{
public RenderUIElement()
Expand All @@ -29,7 +16,6 @@ public RenderUIElement()

// UIComponent values
public UIPage Page;
public Sampler Sampler;
public bool IsFullScreen;
public Vector3 Resolution;
public Vector3 Size;
Expand Down
27 changes: 8 additions & 19 deletions sources/engine/Stride.UI/Rendering/UI/UIRenderFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,12 @@ private void DrawInternal(RenderDrawContext context, RenderView renderView, Rend
}
context.CommandList.SetRenderTarget(renderingContext.DepthStencilBuffer, renderingContext.RenderTarget);

var samplerState = context.GraphicsDevice.SamplerStates.LinearClamp;
if (renderObject.Sampler != Sampler.LinearClamp)
{
switch (renderObject.Sampler)
{
case Sampler.PointClamp:
samplerState = context.GraphicsDevice.SamplerStates.PointClamp;
break;
}
}

// start the image draw session
renderingContext.StencilTestReferenceValue = 0;
batch.Begin(context.GraphicsContext, ref uiElementState.WorldViewProjectionMatrix, BlendStates.AlphaBlend, samplerState, null, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
batch.Begin(context.GraphicsContext, ref uiElementState.WorldViewProjectionMatrix, BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);

// Render the UI elements in the final render target
RecursiveDrawWithClipping(context, rootElement, ref uiElementState.WorldViewProjectionMatrix, samplerState);
RecursiveDrawWithClipping(context, rootElement, ref uiElementState.WorldViewProjectionMatrix);

// end the image draw session
batch.End();
Expand All @@ -281,7 +270,7 @@ private void DrawInternal(RenderDrawContext context, RenderView renderView, Rend
}
}

private void RecursiveDrawWithClipping(RenderDrawContext context, UIElement element, ref Matrix worldViewProj, SamplerState samplerState)
private void RecursiveDrawWithClipping(RenderDrawContext context, UIElement element, ref Matrix worldViewProj)
{
// if the element is not visible, we also remove all its children
if (!element.IsVisible)
Expand All @@ -297,21 +286,21 @@ private void RecursiveDrawWithClipping(RenderDrawContext context, UIElement elem
batch.End();

// render the clipping region
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.ColorDisabled, samplerState, null, uiSystem.IncreaseStencilValueState, renderingContext.StencilTestReferenceValue);
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.ColorDisabled, uiSystem.IncreaseStencilValueState, renderingContext.StencilTestReferenceValue);
renderer.RenderClipping(element, renderingContext);
batch.End();

// update context and restart the batch
renderingContext.StencilTestReferenceValue += 1;
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.AlphaBlend, samplerState, null, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
}

// render the design of the element
renderer.RenderColor(element, renderingContext);

// render the children
foreach (var child in element.VisualChildrenCollection)
RecursiveDrawWithClipping(context, child, ref worldViewProj, samplerState);
RecursiveDrawWithClipping(context, child, ref worldViewProj);

// clear the element clipping region from the stencil buffer
if (element.ClipToBounds)
Expand All @@ -322,13 +311,13 @@ private void RecursiveDrawWithClipping(RenderDrawContext context, UIElement elem
renderingContext.DepthBias = element.MaxChildrenDepthBias;

// render the clipping region
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.ColorDisabled, samplerState, null, uiSystem.DecreaseStencilValueState, renderingContext.StencilTestReferenceValue);
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.ColorDisabled, uiSystem.DecreaseStencilValueState, renderingContext.StencilTestReferenceValue);
renderer.RenderClipping(element, renderingContext);
batch.End();

// update context and restart the batch
renderingContext.StencilTestReferenceValue -= 1;
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.AlphaBlend, samplerState, null, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
batch.Begin(context.GraphicsContext, ref worldViewProj, BlendStates.AlphaBlend, uiSystem.KeepStencilValueState, renderingContext.StencilTestReferenceValue);
}
}

Expand Down
1 change: 0 additions & 1 deletion sources/engine/Stride.UI/Rendering/UI/UIRenderProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public override void Draw(RenderContext gameTime)
renderUIElement.RenderGroup = uiComponent.RenderGroup;

renderUIElement.Page = uiComponent.Page;
renderUIElement.Sampler = uiComponent.Sampler;
renderUIElement.IsFullScreen = uiComponent.IsFullScreen;
renderUIElement.Resolution = uiComponent.Resolution;
renderUIElement.Size = uiComponent.Size;
Expand Down

0 comments on commit 5fc826c

Please sign in to comment.