update example to latest moonworks

main
cosmonaut 2022-03-08 10:47:51 -08:00
parent d8708818cb
commit 929800bc3c
4 changed files with 40 additions and 98 deletions

@ -1 +1 @@
Subproject commit 9028a8b1a02d1f73be3d8006f72a8a68acccacdf
Subproject commit 8f9aaf6d612b97d77ff5013e758846894777089a

View File

@ -1,32 +0,0 @@
using MoonWorks.Graphics;
namespace MoonWorksMultiWindow.Graphics
{
public class RenderTargets
{
public RenderTarget ExampleRenderTarget { get; }
public RenderTarget ExtraWindowRenderTarget { get; }
public RenderTargets(
GraphicsDevice graphicsDevice,
uint renderDimensionsX,
uint renderDimensionsY
) {
ExampleRenderTarget = RenderTarget.CreateBackedRenderTarget(
graphicsDevice,
renderDimensionsX,
renderDimensionsY,
TextureFormat.R8G8B8A8,
false
);
ExtraWindowRenderTarget = RenderTarget.CreateBackedRenderTarget(
graphicsDevice,
renderDimensionsX,
renderDimensionsY,
TextureFormat.R8G8B8A8,
false
);
}
}
}

View File

@ -1,22 +0,0 @@
using MoonWorks.Graphics;
namespace MoonWorksMultiWindow.Graphics
{
public class GraphicsObjects
{
public RenderTargets RenderTargets { get; }
public GraphicsObjects(
GraphicsDevice graphicsDevice,
uint renderDimensionsX,
uint renderDimensionsY
)
{
RenderTargets = new RenderTargets(
graphicsDevice,
renderDimensionsX,
renderDimensionsY
);
}
}
}

View File

@ -1,14 +1,11 @@
using MoonWorks.Graphics;
using MoonWorks;
using MoonWorksMultiWindow.Graphics;
using System.Threading.Tasks;
namespace MoonWorksMultiWindow
{
class MoonWorksMultiWindowGame : Game
{
private GraphicsObjects GraphicsObjects { get; }
private Window ExtraWindow { get; }
public MoonWorksMultiWindowGame(
@ -17,13 +14,6 @@ namespace MoonWorksMultiWindow
bool debugMode
) : base(windowCreateInfo, presentMode, 60, debugMode)
{
// Insert your game initialization logic here.
GraphicsObjects = new GraphicsObjects(
GraphicsDevice,
windowCreateInfo.WindowWidth,
windowCreateInfo.WindowHeight
);
var extraWindowCreateInfo = new WindowCreateInfo
{
WindowTitle = "Extra Window",
@ -37,7 +27,25 @@ namespace MoonWorksMultiWindow
protected override void Update(System.TimeSpan dt)
{
// Insert your game update logic here.
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.Keycode.Up))
{
Window.SetWindowSize(Window.Width + 50, Window.Height + 50);
}
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.Keycode.Down))
{
Window.SetWindowSize(Window.Width - 50, Window.Height - 50);
}
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.Keycode.Right))
{
ExtraWindow.SetWindowSize(ExtraWindow.Width + 50, ExtraWindow.Height + 50);
}
if (Inputs.Keyboard.IsPressed(MoonWorks.Input.Keycode.Left))
{
ExtraWindow.SetWindowSize(ExtraWindow.Width - 50, ExtraWindow.Height - 50);
}
}
protected override void Draw(System.TimeSpan dt, double alpha)
@ -52,24 +60,18 @@ namespace MoonWorksMultiWindow
private void MainDraw()
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window);
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo
{
RenderTarget = GraphicsObjects.RenderTargets.ExampleRenderTarget,
ClearColor = Color.CornflowerBlue,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.DontCare
}
);
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.CornflowerBlue
)
);
commandBuffer.EndRenderPass();
commandBuffer.QueuePresent(
GraphicsObjects.RenderTargets.ExampleRenderTarget.TextureSlice,
Filter.Nearest,
Window
);
commandBuffer.EndRenderPass();
}
GraphicsDevice.Submit(commandBuffer);
}
@ -77,24 +79,18 @@ namespace MoonWorksMultiWindow
private void ExtraWindowDraw()
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(ExtraWindow);
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo
{
RenderTarget = GraphicsObjects.RenderTargets.ExtraWindowRenderTarget,
ClearColor = Color.OrangeRed,
LoadOp = LoadOp.Clear,
StoreOp = StoreOp.DontCare
}
);
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.OrangeRed
)
);
commandBuffer.EndRenderPass();
commandBuffer.QueuePresent(
GraphicsObjects.RenderTargets.ExtraWindowRenderTarget.TextureSlice,
Filter.Nearest,
ExtraWindow
);
commandBuffer.EndRenderPass();
}
GraphicsDevice.Submit(commandBuffer);
}