MoonWorksGraphicsTests/Examples/ClearScreen_MultiWindowExam...

76 lines
2.1 KiB
C#
Raw Permalink Normal View History

2024-06-06 05:47:06 +00:00
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Input;
namespace MoonWorksGraphicsTests
{
class ClearScreen_MultiWindowExample : Example
{
private Window SecondaryWindow;
public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs)
{
Window = window;
GraphicsDevice = graphicsDevice;
2024-06-06 05:56:09 +00:00
Window.SetTitle("ClearScreen");
Window.SetPosition(SDL2.SDL.SDL_WINDOWPOS_CENTERED, SDL2.SDL.SDL_WINDOWPOS_CENTERED);
2024-06-06 05:47:06 +00:00
var (windowX, windowY) = Window.Position;
Window.SetPosition(windowX - 360, windowY);
SecondaryWindow = new Window(
2024-06-11 17:08:37 +00:00
new WindowCreateInfo("Secondary Window", 640, 480, ScreenMode.Windowed, false, false),
2024-06-06 05:47:06 +00:00
SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN
);
(windowX, windowY) = SecondaryWindow.Position;
SecondaryWindow.SetPosition(windowX + 360, windowY);
GraphicsDevice.ClaimWindow(SecondaryWindow, SwapchainComposition.SDR, PresentMode.VSync);
}
public override void Update(System.TimeSpan delta) { }
public override void Draw(double alpha)
{
CommandBuffer cmdbuf;
Texture swapchainTexture;
if (Window.Claimed)
{
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window);
if (swapchainTexture != null)
{
var renderPass = cmdbuf.BeginRenderPass(
new ColorAttachmentInfo(swapchainTexture, false, Color.CornflowerBlue)
);
cmdbuf.EndRenderPass(renderPass);
}
GraphicsDevice.Submit(cmdbuf);
}
if (SecondaryWindow.Claimed)
{
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
swapchainTexture = cmdbuf.AcquireSwapchainTexture(SecondaryWindow);
if (swapchainTexture != null)
{
var renderPass = cmdbuf.BeginRenderPass(
new ColorAttachmentInfo(swapchainTexture, false, Color.Aquamarine)
);
cmdbuf.EndRenderPass(renderPass);
}
GraphicsDevice.Submit(cmdbuf);
}
}
public override void Destroy()
{
GraphicsDevice.UnclaimWindow(SecondaryWindow);
SecondaryWindow.Dispose();
2024-06-06 05:56:09 +00:00
Window.SetPosition(SDL2.SDL.SDL_WINDOWPOS_CENTERED, SDL2.SDL.SDL_WINDOWPOS_CENTERED);
2024-06-06 05:47:06 +00:00
}
}
}