MoonWorksMultiWindowTest/src/MoonWorksMultiWindowGame.cs

104 lines
2.3 KiB
C#
Raw Permalink Normal View History

2022-02-09 01:38:20 +00:00
using MoonWorks.Graphics;
using MoonWorks;
using System.Threading.Tasks;
namespace MoonWorksMultiWindow
{
2022-02-25 06:07:35 +00:00
class MoonWorksMultiWindowGame : Game
{
2022-02-25 21:27:27 +00:00
private Window ExtraWindow { get; }
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
public MoonWorksMultiWindowGame(
WindowCreateInfo windowCreateInfo,
PresentMode presentMode,
bool debugMode
) : base(windowCreateInfo, presentMode, 60, debugMode)
{
2022-02-09 01:38:20 +00:00
var extraWindowCreateInfo = new WindowCreateInfo
{
WindowTitle = "Extra Window",
WindowWidth = 1280,
WindowHeight = 720,
ScreenMode = ScreenMode.Windowed
};
2022-02-25 21:27:27 +00:00
ExtraWindow = new Window(extraWindowCreateInfo);
2022-02-25 06:07:35 +00:00
}
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
protected override void Update(System.TimeSpan dt)
{
2022-03-08 18:47:51 +00:00
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);
}
2022-02-25 06:07:35 +00:00
}
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
protected override void Draw(System.TimeSpan dt, double alpha)
{
2022-02-10 05:25:16 +00:00
var mainDraw = Task.Run(MainDraw);
var extraDraw = Task.Run(ExtraWindowDraw);
mainDraw.Wait();
extraDraw.Wait();
2022-02-25 06:07:35 +00:00
}
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
private void MainDraw()
2022-02-09 01:38:20 +00:00
{
2022-02-25 06:07:35 +00:00
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
2022-03-08 18:47:51 +00:00
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window);
2022-02-25 06:07:35 +00:00
2022-03-08 18:47:51 +00:00
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.CornflowerBlue
)
);
2022-02-09 01:38:20 +00:00
2022-03-08 18:47:51 +00:00
commandBuffer.EndRenderPass();
}
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
GraphicsDevice.Submit(commandBuffer);
2022-02-09 01:38:20 +00:00
}
2022-02-25 06:07:35 +00:00
private void ExtraWindowDraw()
2022-02-09 01:38:20 +00:00
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
2022-03-08 18:47:51 +00:00
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(ExtraWindow);
2022-02-09 01:38:20 +00:00
2022-03-08 18:47:51 +00:00
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.OrangeRed
)
);
commandBuffer.EndRenderPass();
}
2022-02-09 01:38:20 +00:00
2022-02-25 06:07:35 +00:00
GraphicsDevice.Submit(commandBuffer);
}
protected override void OnDestroy()
{
2022-02-09 01:38:20 +00:00
}
2022-02-25 06:07:35 +00:00
}
2022-02-09 01:38:20 +00:00
}