14
14
15
15
namespace Silk . NET . Windowing . Glfw
16
16
{
17
- internal unsafe class GlfwWindow : WindowImplementationBase , IGLContext , IVkSurface
17
+ internal unsafe class GlfwWindow : WindowImplementationBase , IVkSurface
18
18
{
19
19
internal readonly GLFW . Glfw _glfw ;
20
20
internal WindowHandle * _glfwWindow ;
21
- private string _localTitleCache ; // glfw doesn't let us get the window title.
22
- private readonly GlfwWindow ? _parent ;
23
- private readonly GlfwMonitor ? _initialMonitor ;
24
21
25
22
// Callbacks
26
23
private GlfwCallbacks . WindowPosCallback ? _onMove ;
@@ -31,8 +28,14 @@ internal unsafe class GlfwWindow : WindowImplementationBase, IGLContext, IVkSurf
31
28
private GlfwCallbacks . WindowFocusCallback ? _onFocusChanged ;
32
29
private GlfwCallbacks . WindowIconifyCallback ? _onMinimized ;
33
30
private GlfwCallbacks . WindowMaximizeCallback ? _onMaximized ;
31
+
32
+ // Other variables
33
+ private readonly GlfwWindow ? _parent ;
34
+ private readonly GlfwMonitor ? _initialMonitor ;
34
35
private Vector2D < int > _nonFullscreenPosition ;
35
36
private Vector2D < int > _nonFullscreenSize ;
37
+ private string _localTitleCache ; // glfw doesn't let us get the window title.
38
+ private GlfwContext ? _glContext ;
36
39
37
40
public GlfwWindow ( WindowOptions optionsCache , GlfwWindow ? parent , GlfwMonitor ? monitor ) : base ( optionsCache )
38
41
{
@@ -48,11 +51,11 @@ protected override Vector2D<int> CoreSize
48
51
get
49
52
{
50
53
_glfw . GetWindowSize ( _glfwWindow , out var width , out var height ) ;
51
- return new Vector2D < int > ( width , height ) ;
54
+ return new ( width , height ) ;
52
55
}
53
56
}
54
57
55
- protected override unsafe Rectangle < int > CoreBorderSize
58
+ protected override Rectangle < int > CoreBorderSize
56
59
{
57
60
get
58
61
{
@@ -84,7 +87,9 @@ protected override void CoreReset()
84
87
}
85
88
86
89
public override IGLContext ? GLContext
87
- => API . API == ContextAPI . OpenGL || API . API == ContextAPI . OpenGLES ? this : null ;
90
+ => API . API == ContextAPI . OpenGL || API . API == ContextAPI . OpenGLES
91
+ ? _glContext ??= new ( _glfw , _glfwWindow , this )
92
+ : null ;
88
93
89
94
public override IVkSurface ? VkSurface => API . API == ContextAPI . Vulkan && _glfw . VulkanSupported ( ) ? this : null ;
90
95
@@ -109,7 +114,7 @@ protected override Vector2D<int> CorePosition
109
114
get
110
115
{
111
116
_glfw . GetWindowPos ( _glfwWindow , out var x , out var y ) ;
112
- return new Vector2D < int > ( x , y ) ;
117
+ return new ( x , y ) ;
113
118
}
114
119
set => _glfw . SetWindowPos ( _glfwWindow , value . X , value . Y ) ;
115
120
}
@@ -326,7 +331,6 @@ protected override void CoreInitialize(WindowOptions opts)
326
331
{
327
332
null => null ,
328
333
_ when share is GlfwContext glfwContext => ( WindowHandle * ) glfwContext . Handle ,
329
- _ when share is GlfwWindow glfwWindow => glfwWindow . _glfwWindow ,
330
334
_ => throw new ArgumentException ( "The given shared context should be a GlfwContext or GlfwWindow" )
331
335
}
332
336
) ;
@@ -373,7 +377,7 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
373
377
var icon = icons [ i ] ;
374
378
// ReSharper disable once StackAllocInsideLoop
375
379
Span < byte > iconMemory = stackalloc byte [ icon . Pixels . Length ] ;
376
- images [ i ] = new Image
380
+ images [ i ] = new ( )
377
381
{
378
382
Width = icon . Width , Height = icon . Height ,
379
383
Pixels = ( byte * ) Unsafe . AsPointer ( ref iconMemory [ 0 ] )
@@ -390,7 +394,6 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
390
394
public override IWindow CreateWindow ( WindowOptions opts ) => new GlfwWindow ( opts , this , null ) ;
391
395
392
396
public override IWindowHost ? Parent => ( IWindowHost ? ) _parent ?? Monitor ;
393
- public IGLContextSource ? Source => ( IGLContextSource ? ) GLContext ;
394
397
public override IGLContext ? SharedContext { get ; }
395
398
396
399
@@ -486,7 +489,7 @@ private static int IndexOf<T>(T** array, T* target, int count)
486
489
return - 1 ;
487
490
}
488
491
489
- public override bool IsClosing => _glfw . WindowShouldClose ( _glfwWindow ) ;
492
+ protected override bool CoreIsClosing => _glfw . WindowShouldClose ( _glfwWindow ) ;
490
493
491
494
public override VideoMode VideoMode
492
495
=> IsInitialized ? CachedVideoMode = Monitor ? . VideoMode ?? CachedVideoMode : CachedVideoMode ;
@@ -498,7 +501,7 @@ public override Vector2D<int> FramebufferSize
498
501
get
499
502
{
500
503
_glfw . GetFramebufferSize ( _glfwWindow , out var width , out var height ) ;
501
- return new Vector2D < int > ( width , height ) ;
504
+ return new ( width , height ) ;
502
505
}
503
506
}
504
507
@@ -516,12 +519,6 @@ public override void DoEvents()
516
519
517
520
public override void ContinueEvents ( ) => _glfw . PostEmptyEvent ( ) ;
518
521
519
- public override void Dispose ( )
520
- {
521
- Reset ( ) ;
522
- GC . SuppressFinalize ( this ) ;
523
- }
524
-
525
522
public nint GetProcAddress ( string proc , int ? slot = default )
526
523
{
527
524
var ret = _glfw . GetProcAddress ( proc ) ;
@@ -567,7 +564,7 @@ protected override void RegisterCallbacks()
567
564
568
565
_onFramebufferResize = ( window , width , height ) =>
569
566
{
570
- FramebufferResize ? . Invoke ( new Vector2D < int > ( width , height ) ) ;
567
+ FramebufferResize ? . Invoke ( new ( width , height ) ) ;
571
568
} ;
572
569
573
570
_onClosing = window => Closing ? . Invoke ( ) ;
@@ -690,12 +687,6 @@ protected override void UnregisterCallbacks()
690
687
Reset ( ) ;
691
688
}
692
689
693
- public bool IsCurrent => _glfw . GetCurrentContext ( ) == _glfwWindow ;
694
- public void SwapInterval ( int interval ) => _glfw . SwapInterval ( interval ) ;
695
- public void SwapBuffers ( ) => _glfw . SwapBuffers ( _glfwWindow ) ;
696
- public void MakeCurrent ( ) => _glfw . MakeContextCurrent ( _glfwWindow ) ;
697
- public void Clear ( ) => _glfw . MakeContextCurrent ( null ) ;
698
-
699
690
public VkNonDispatchableHandle Create < T > ( VkHandle instance , T * allocator ) where T : unmanaged
700
691
{
701
692
var surface = stackalloc VkNonDispatchableHandle [ 1 ] ;
0 commit comments