MoonWorksMultiWindowTest/src/MoonWorksMultiWindowGame.cs

104 lines
2.3 KiB
C#

using MoonWorks.Graphics;
using MoonWorks;
using System.Threading.Tasks;
namespace MoonWorksMultiWindow
{
class MoonWorksMultiWindowGame : Game
{
private Window ExtraWindow { get; }
public MoonWorksMultiWindowGame(
WindowCreateInfo windowCreateInfo,
PresentMode presentMode,
bool debugMode
) : base(windowCreateInfo, presentMode, 60, debugMode)
{
var extraWindowCreateInfo = new WindowCreateInfo
{
WindowTitle = "Extra Window",
WindowWidth = 1280,
WindowHeight = 720,
ScreenMode = ScreenMode.Windowed
};
ExtraWindow = new Window(extraWindowCreateInfo);
}
protected override void Update(System.TimeSpan dt)
{
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)
{
var mainDraw = Task.Run(MainDraw);
var extraDraw = Task.Run(ExtraWindowDraw);
mainDraw.Wait();
extraDraw.Wait();
}
private void MainDraw()
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window);
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.CornflowerBlue
)
);
commandBuffer.EndRenderPass();
}
GraphicsDevice.Submit(commandBuffer);
}
private void ExtraWindowDraw()
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(ExtraWindow);
if (swapchainTexture != null)
{
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(
swapchainTexture, Color.OrangeRed
)
);
commandBuffer.EndRenderPass();
}
GraphicsDevice.Submit(commandBuffer);
}
protected override void OnDestroy()
{
}
}
}