Separate GraphicsContext from Window, prepare for windows and swap chain for multi window

This commit is contained in:
Simon Lübeß
2024-09-10 19:07:58 +02:00
parent 65992126c0
commit 352073869f
16 changed files with 99 additions and 130 deletions
+15 -1
View File
@@ -8,11 +8,25 @@ namespace GlitchyEngine.Renderer
{
private static GraphicsContext s_GraphicsContext;
public static GraphicsContext Get() => s_GraphicsContext;
private Window _currentWindow;
public extern SwapChain SwapChain {get;}
private bool _immediateContext;
public Window CurrentWindow
{
get => _currentWindow;
set => _currentWindow = value;
}
protected extern void PlatformConstruct();
public this(Window currentWindow, bool immediateContext = false)
{
_currentWindow = currentWindow;
_immediateContext = immediateContext;
}
/**
* The maximum number of simultaneous rendertargets supported.
*/
+4 -3
View File
@@ -17,10 +17,11 @@ namespace GlitchyEngine.Renderer
public uint32 SampleCount;
public uint32 SampleQuality;
public DepthStencilFormat DepthStencilFormat;
public bool IsSwapchainTarget;
/// If not null, the render target will represent the specified swap chains back buffer.
public SwapChain SwapChain;
public this(Format pixelFormat, uint32 width, uint32 height, uint32 arraySize = 1, uint32 mipLevels = 1,
DepthStencilFormat depthStencilFormat = .Unknown, CPUAccessFlags cpuAccess = .None, uint32 sampleCount = 1, uint32 sampleQuality = 0, bool isSwapchainTarget = false)
DepthStencilFormat depthStencilFormat = .Unknown, CPUAccessFlags cpuAccess = .None, uint32 sampleCount = 1, uint32 sampleQuality = 0, SwapChain swapChain = null)
{
PixelFormat = pixelFormat;
Width = width;
@@ -33,7 +34,7 @@ namespace GlitchyEngine.Renderer
SampleCount = sampleCount;
SampleQuality = sampleQuality;
IsSwapchainTarget = isSwapchainTarget;
SwapChain = swapChain;
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ namespace GlitchyEngine.Renderer
{
Debug.Profiler.ProfileRendererFunction!();
var actualRt = (renderTarget ?? GraphicsContext.Get().SwapChain.BackBuffer);
var actualRt = (renderTarget ?? GraphicsContext.Get().CurrentWindow.SwapChain.BackBuffer);
if(options.HasFlag(.Color))
Clear(actualRt, color);
+9 -1
View File
@@ -3,8 +3,9 @@ namespace GlitchyEngine.Renderer
public class SwapChain
{
private GraphicsContext _context;
private Window _window;
private bool _changed;
private bool _changed = true;
private uint32 _width, _height;
@@ -16,6 +17,8 @@ namespace GlitchyEngine.Renderer
public GraphicsContext Context => _context;
public Window Window => _window;
/**
* Gets or Sets the backbuffers width.
* @remarks @ApplyChanges() needs to be called in order to apply the changes.
@@ -77,6 +80,11 @@ namespace GlitchyEngine.Renderer
public RenderTarget2D BackBuffer => _backBuffer;
public this(Window window)
{
_window = window;
}
public extern void Init();
/**