Skip to content

Commit

Permalink
Fixes #401
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Oct 23, 2023
1 parent 647f0f7 commit e510985
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
53 changes: 32 additions & 21 deletions src/Myra/Graphics2D/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Myra.Utility;
using FontStashSharp.RichText;
using FontStashSharp.Interfaces;
using info.lundin.math;

#if MONOGAME || FNA
using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -76,6 +77,35 @@ static RenderContext()
private TextureFiltering _textureFiltering = TextureFiltering.Nearest;
public Transform Transform;

internal Rectangle DeviceScissor
{
get
{
#if MONOGAME || FNA
var device = _renderer.GraphicsDevice;
return device.ScissorRectangle;
#elif STRIDE
return MyraEnvironment.Game.GraphicsContext.CommandList.Scissor;
#else
return _renderer.Scissor;
#endif
}

set
{
#if MONOGAME || FNA
var device = _renderer.GraphicsDevice;
device.ScissorRectangle = value;
#elif STRIDE
Flush();
MyraEnvironment.Game.GraphicsContext.CommandList.SetScissorRectangle(value);
#else
_renderer.Scissor = value;
#endif
}
}


public Rectangle Scissor
{
get
Expand All @@ -97,13 +127,12 @@ public Rectangle Scissor
var device = _renderer.GraphicsDevice;
value.X += device.Viewport.X;
value.Y += device.Viewport.Y;
device.ScissorRectangle = value;
#elif STRIDE
Flush();
MyraEnvironment.Game.GraphicsContext.CommandList.SetScissorRectangle(value);
#else
_renderer.Scissor = value;
#endif

DeviceScissor = value;
}
}

Expand All @@ -127,7 +156,6 @@ public RenderContext()
_fontStashRenderer2 = new FontStashRenderer2(_renderer);
}
#endif
_scissor = GetDeviceScissor();
}

/// <summary>
Expand All @@ -139,23 +167,6 @@ public void AddOpacity(float opacity)
Opacity *= opacity;
}

private Rectangle GetDeviceScissor()
{
#if MONOGAME || FNA
var device = _renderer.GraphicsDevice;
var rect = device.ScissorRectangle;

rect.X -= device.Viewport.X;
rect.Y -= device.Viewport.Y;

return rect;
#elif STRIDE
return MyraEnvironment.Game.GraphicsContext.CommandList.Scissor;
#else
return _renderer.Scissor;
#endif
}

private void SetTextureFiltering(TextureFiltering value)
{
if (_textureFiltering == value)
Expand Down
4 changes: 2 additions & 2 deletions src/Myra/Graphics2D/UI/Desktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ private void WidgetsOnCollectionChanged(object sender, NotifyCollectionChangedEv

public void RenderVisual()
{
var oldScissorRectangle = _renderContext.Scissor;
var oldDeviceScissor = _renderContext.DeviceScissor;

_renderContext.Begin();

Expand All @@ -732,7 +732,7 @@ public void RenderVisual()

_renderContext.End();

_renderContext.Scissor = oldScissorRectangle;
_renderContext.DeviceScissor = oldDeviceScissor;
}

public void Render()
Expand Down

0 comments on commit e510985

Please sign in to comment.