forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLFW.cs
5564 lines (5367 loc) · 253 KB
/
GLFW.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// GLFW.cs
//
// Copyright (C) 2018 OpenTK
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//
using System;
using System.Runtime.InteropServices;
using static OpenToolkit.GraphicsLibraryFramework.GLFWNative;
namespace OpenToolkit.GraphicsLibraryFramework
{
/// <summary>
/// Provides access to the GLFW API.
/// </summary>
public static class GLFW
{
// XML-documentation is from https://www.glfw.org/docs/latest/
// Still missing in documentation
/// <summary>
/// Gets an integer equal to GLFW_DONT_CARE. This can be used for several window hints to use the platform default.
/// </summary>
public const int DontCare = -1;
/// <summary>
/// <para>
/// This function initialwizes the GLFW library. Before most GLFW functions can be used,
/// GLFW must be initialized, and before an application terminates GLFW should be terminated in order to
/// free any resources allocated during or after initialization.
/// </para>
/// <para>
/// If this function fails, it calls <see cref="Terminate"/> before returning.
/// </para>
/// <para>
/// If it succeeds, you should call <see cref="Terminate"/> before the application exits.
/// </para>
/// <para>
/// Additional calls to this function after successful initialization
/// but before termination will return <c>true</c> immediately.
/// </para>
/// </summary>
/// <returns><c>true</c> if successful, or <c>false</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// OS X: This function will change the current directory of the application
/// to the Contents/Resources subdirectory of the application's bundle, if present.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static bool Init() => glfwInit() == GLFW_TRUE;
/// <summary>
/// <para>
/// This function destroys all remaining windows and cursors, restores any modified gamma ramps
/// and frees any other allocated resources. Once this function is called,
/// you must again call <see cref="Init"/> successfully before you will be able to use most GLFW functions.
/// </para>
/// <para>
/// If GLFW has been successfully initialized, this function should be called before the application exits.
/// </para>
/// <para>
/// If initialization fails, there is no need to call this function,
/// as it is called by <see cref="Init"/> before it returns failure.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// The contexts of any remaining windows must not be current on any other thread when this function is called.
/// </para>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function must not be called from a callback.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static void Terminate() => glfwTerminate();
/// <summary>
/// <para>
/// This function sets hints for the next initialization of GLFW.
/// </para>
/// <para>
/// The values you set hints to are never reset by GLFW, but they only take effect during initialization.
/// </para>
/// <para>
/// Once GLFW has been initialized,
/// any values you set will be ignored until the library is terminated and initialized again.
/// </para>
/// <para>Some hints are platform specific.
/// These may be set on any platform but they will only affect their specific platform.
/// Other platforms will ignore them. Setting these hints requires no platform specific headers or functions.
/// </para>
/// </summary>
/// <param name="hintBool">The <see cref="InitHintBool"/> to set.</param>
/// <param name="value">The new value of the <see cref="InitHintBool"/>.</param>
/// <remarks>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.InvalidEnum"/> and <see cref="ErrorCode.InvalidValue"/>.
/// </para>
/// </remarks>
public static void InitHint(InitHintBool hintBool, bool value) =>
glfwInitHint((int)hintBool, value ? GLFW_TRUE : GLFW_FALSE);
/// <summary>
/// <para>
/// This function sets hints for the next initialization of GLFW.
/// </para>
/// <para>
/// The values you set hints to are never reset by GLFW, but they only take effect during initialization.
/// </para>
/// <para>
/// Once GLFW has been initialized,
/// any values you set will be ignored until the library is terminated and initialized again.
/// </para>
/// <para>Some hints are platform specific.
/// These may be set on any platform but they will only affect their specific platform.
/// Other platforms will ignore them. Setting these hints requires no platform specific headers or functions.
/// </para>
/// </summary>
/// <param name="hintInt">The <see cref="InitHintInt"/> to set.</param>
/// <param name="value">The new value of the <see cref="InitHintBool"/>.</param>
/// <remarks>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.InvalidEnum"/> and <see cref="ErrorCode.InvalidValue"/>.
/// </para>
/// </remarks>
public static void InitHint(InitHintInt hintInt, int value) => glfwInitHint((int)hintInt, value);
/// <summary>
/// <para>
/// This function retrieves the major, minor and revision numbers of the GLFW library.
/// It is intended for when you are using GLFW
/// as a shared library and want to ensure that you are using the minimum required version.
/// </para>
/// <para>
/// Any or all of the version arguments may be <c>out _</c>.
/// </para>
/// </summary>
/// <param name="major">Where to store the major version number, or <c>out _</c>.</param>
/// <param name="minor">Where to store the minor version number, or <c>out _</c>.</param>
/// <param name="revision">Where to store the revision number, or <c>out _</c>.</param>
/// <remarks>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function may be called from any thread.
/// </para>
/// </remarks>
public static unsafe void GetVersion(out int major, out int minor, out int revision)
{
int localMajor, localMinor, localRevision;
glfwGetVersion(&localMajor, &localMinor, &localRevision);
major = localMajor;
minor = localMinor;
revision = localRevision;
}
/// <summary>
/// <para>
/// This function returns the compile-time generated version string of the GLFW library binary.
/// It describes the version, platform, compiler and any platform-specific compile-time options.
/// It should not be confused with the OpenGL or OpenGL ES version string, queried with <c>glGetString</c>.
/// </para>
/// <para>
/// Do not use the version string to parse the GLFW library version.
/// The <see cref="GetVersion"/> function provides the version of the running library binary in numerical format.
/// </para>
/// </summary>
/// <returns>The ASCII-encoded GLFW version string.</returns>
/// <remarks>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// The returned string is static and compile-time generated.
/// </para>
/// <para>
/// This function may be called from any thread.
/// </para>
/// </remarks>
/// <seealso cref="GetVersion"/>
public static unsafe string GetVersionString()
{
return Marshal.PtrToStringUTF8((IntPtr) glfwGetVersionString());
}
/// <summary>
/// <para>
/// This function returns the compile-time generated version string of the GLFW library binary.
/// It describes the version, platform, compiler and any platform-specific compile-time options.
/// It should not be confused with the OpenGL or OpenGL ES version string, queried with <c>glGetString</c>.
/// </para>
/// <para>
/// Do not use the version string to parse the GLFW library version.
/// The <see cref="GetVersion"/> function provides the version of the running library binary in numerical format.
/// </para>
/// </summary>
/// <returns>The ASCII-encoded GLFW version string.</returns>
/// <remarks>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// The returned string is static and compile-time generated.
/// </para>
/// <para>
/// This function may be called from any thread.
/// </para>
/// </remarks>
/// <seealso cref="GetVersion"/>
public static unsafe byte* GetVersionStringRaw()
{
return glfwGetVersionString();
}
/// <summary>
/// <para>
/// This function returns and clears the error code of the last error that occurred on the calling thread,
/// and optionally a UTF-8 encoded human-readable description of it.
/// </para>
/// <para>
/// If no error has occurred since the last call,
/// it returns <see cref="ErrorCode.NoError"/> (zero) and the description pointer is set to <c>null</c>.
/// </para>
/// </summary>
/// <param name="description">Where to store the error description pointer, or <c>out _</c>"/>.</param>
/// <returns>The last error code for the calling thread, or <see cref="ErrorCode.NoError"/> (zero).</returns>
/// <remarks>
/// <para>
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the next error occurs or the library is terminated.
/// </para>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function may be called from any thread.
/// </para>
/// </remarks>
/// <seealso cref="SetErrorCallback"/>
public static unsafe ErrorCode GetError(out string description)
{
byte* desc;
var code = glfwGetError(&desc);
description = Marshal.PtrToStringUTF8((IntPtr) desc);
return code;
}
/// <summary>
/// <para>
/// This function returns and clears the error code of the last error that occurred on the calling thread,
/// and optionally a UTF-8 encoded human-readable description of it.
/// </para>
/// <para>
/// If no error has occurred since the last call,
/// it returns <see cref="ErrorCode.NoError"/> (zero) and the description pointer is set to <c>null</c>.
/// </para>
/// </summary>
/// <param name="description">Where to store the error description pointer, or <c>out _</c>"/>.</param>
/// <returns>The last error code for the calling thread, or <see cref="ErrorCode.NoError"/> (zero).</returns>
/// <remarks>
/// <para>
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the next error occurs or the library is terminated.
/// </para>
/// <para>
/// This function may be called before <see cref="Init"/>.
/// </para>
/// <para>
/// This function may be called from any thread.
/// </para>
/// </remarks>
/// <seealso cref="SetErrorCallback"/>
public static unsafe ErrorCode GetErrorRaw(out byte* description)
{
byte* desc;
var code = glfwGetError(&desc);
description = desc;
return code;
}
/// <summary>
/// <para>
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
/// </para>
/// <para>
/// If no monitors were found, this function returns <c>null</c>.
/// </para>
/// </summary>
/// <param name="count">
/// Where to store the number of monitors in the returned array. This is set to zero if an error occurred.
/// </param>
/// <returns>
/// An array of monitor handles, or <c>null</c> if no monitors were found or if an error occurred.
/// </returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetPrimaryMonitor"/>
public static unsafe Monitor** GetMonitorsRaw(out int count)
{
fixed (int* ptr = &count)
{
return glfwGetMonitors(ptr);
}
}
/// <summary>
/// <para>
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
/// </para>
/// <para>
/// If no monitors were found, this function returns <c>null</c>.
/// </para>
/// </summary>
/// <param name="count">
/// Where to store the number of monitors in the returned array. This is set to zero if an error occurred.
/// </param>
/// <returns>
/// An array of monitor handles, or <c>null</c> if no monitors were found or if an error occurred.
/// </returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetPrimaryMonitor"/>
public static unsafe Monitor** GetMonitorsRaw(int* count)
{
return glfwGetMonitors(count);
}
/// <summary>
/// <para>
/// This function returns an array of handles for all currently connected monitors.
/// The primary monitor is always first in the returned array.
/// </para>
/// <para>
/// If no monitors were found, this function returns <c>null</c>.
/// </para>
/// </summary>
/// <returns>
/// An array of monitor handles, or <c>null</c> if no monitors were found or if an error occurred.
/// </returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is only guaranteed to be valid until the monitor configuration changes or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetPrimaryMonitor"/>
public static unsafe Monitor*[] GetMonitors()
{
var ptr = GetMonitorsRaw(out var count);
if (ptr == null)
{
return null;
}
var array = new Monitor*[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
/// <summary>
/// <para>
/// This function returns the position, in screen coordinates, of the upper-left corner of the specified monitor.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="x">Where to store the monitor x-coordinate, or <c>out _</c>.</param>
/// <param name="y">Where to store the monitor y-coordinate, or <c>out _</c>.</param>
/// <remarks>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe void GetMonitorPos(Monitor* monitor, out int x, out int y)
{
int localX, localY;
glfwGetMonitorPos(monitor, &localX, &localY);
x = localX;
y = localY;
}
/// <summary>
/// <para>
/// This function returns the position, in screen coordinates, of the upper-left corner of the specified monitor.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="x">Where to store the monitor x-coordinate.</param>
/// <param name="y">Where to store the monitor y-coordinate.</param>
/// <remarks>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe void GetMonitorPos(Monitor* monitor, int* x, int* y)
{
glfwGetMonitorPos(monitor, x, y);
}
/// <summary>
/// <para>
/// This function returns the size, in millimetres, of the display area of the specified monitor.
/// </para>
/// <para>
/// Some systems do not provide accurate monitor size information,
/// either because the monitor EDID(Extended Display Identification Data) data is incorrect
/// or because the driver does not report it accurately.
/// </para>
/// <para>
/// Any or all of the size arguments may be <c>out _</c>.
/// If an error occurs, all non-<c>out _</c> size arguments will be set to zero.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="width">
/// Where to store the width, in millimetres, of the monitor's display area, or <c>out _</c>.
/// </param>
/// <param name="height">
/// Where to store the height, in millimetres, of the monitor's display area, or <c>out _</c>.
/// </param>
/// <remarks>
/// <para>
/// Windows: calculates the returned physical size from the current resolution
/// and system DPI instead of querying the monitor EDID data.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
public static unsafe void GetMonitorPhysicalSize(Monitor* monitor, out int width, out int height)
{
int localWidth, localHeight;
glfwGetMonitorPhysicalSize(monitor, &localWidth, &localHeight);
width = localWidth;
height = localHeight;
}
/// <summary>
/// <para>
/// This function retrieves the content scale for the specified monitor.
/// </para>
/// <para>
/// The content scale is the ratio between the current DPI and the platform's default DPI.
/// </para>
/// <para>
/// If you scale all pixel dimensions by this scale then your content should appear at an appropriate size.
/// This is especially important for text and any UI elements.
/// </para>
///
/// <para>
/// The content scale may depend on both the monitor resolution and pixel density and on user settings.
/// It may be very different from the raw DPI calculated from the physical size and current resolution.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="xScale">Where to store the x-axis content scale, or <c>out _</c>.</param>
/// <param name="yScale">Where to store the y-axis content scale, or <c>out _</c>.</param>
public static unsafe void GetMonitorContentScale(Monitor* monitor, out float xScale, out float yScale)
{
float localX, localY;
glfwGetMonitorContentScale(monitor, &localX, &localY);
xScale = localX;
yScale = localY;
}
/// <summary>
/// <para>
/// This function retrieves the content scale for the specified monitor.
/// </para>
/// <para>
/// The content scale is the ratio between the current DPI and the platform's default DPI.
/// </para>
/// <para>
/// If you scale all pixel dimensions by this scale then your content should appear at an appropriate size.
/// This is especially important for text and any UI elements.
/// </para>
///
/// <para>
/// The content scale may depend on both the monitor resolution and pixel density and on user settings.
/// It may be very different from the raw DPI calculated from the physical size and current resolution.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="xScale">Where to store the x-axis content scale, or <c>out _</c>.</param>
/// <param name="yScale">Where to store the y-axis content scale, or <c>out _</c>.</param>
public static unsafe void GetMonitorContentScaleRaw(Monitor* monitor, float* xScale, float* yScale)
{
glfwGetMonitorContentScale(monitor, xScale, yScale);
}
/// <summary>
/// <para>
/// This function returns a human-readable name, encoded as UTF-8, of the specified monitor.
/// The name typically reflects the make and model of the monitor
/// and is not guaranteed to be unique among the connected monitors.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <returns>The UTF-8 encoded name of the monitor, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
public static unsafe string GetMonitorName(Monitor* monitor)
{
return Marshal.PtrToStringUTF8((IntPtr) glfwGetMonitorName(monitor));
}
/// <summary>
/// <para>
/// This function returns a human-readable name, encoded as UTF-8, of the specified monitor.
/// The name typically reflects the make and model of the monitor
/// and is not guaranteed to be unique among the connected monitors.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <returns>The UTF-8 encoded name of the monitor, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned string is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
public static unsafe byte* GetMonitorNameRaw(Monitor* monitor)
{
return glfwGetMonitorName(monitor);
}
/// <summary>
/// <para>
/// This function sets the user-defined pointer of the specified monitor.
/// The current value is retained until the monitor is disconnected.
/// The initial value is <see cref="IntPtr.Zero"/>.
/// </para>
/// <para>
/// This function may be called from the monitor callback, even for a monitor that is being disconnected.
/// </para>
/// </summary>
/// <param name="monitor">The monitor whose pointer to set.</param>
/// <param name="pointer">The new value.</param>
/// <remarks>
/// <para>
/// This function may be called from any thread. Access is not synchronized.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
public static unsafe void SetMonitorUserPointer(Monitor* monitor, void* pointer)
{
glfwSetMonitorUserPointer(monitor, pointer);
}
/// <summary>
/// <para>
/// This function returns the current value of the user-defined pointer of the specified monitor.
/// The initial value is <see cref="IntPtr.Zero"/>.
/// </para>
/// <para>
/// This function may be called from the monitor callback, even for a monitor that is being disconnected.
/// </para>
/// </summary>
/// <param name="monitor">The monitor whose pointer to return.</param>
/// <returns>The user-defined pointer of the given <paramref name="monitor"/>.</returns>
/// <remarks>
/// <para>
/// This function may be called from any thread. Access is not synchronized.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>.
/// </para>
/// </remarks>
public static unsafe void* GetMonitorUserPointer(Monitor* monitor)
{
return glfwGetMonitorUserPointer(monitor);
}
/// <summary>
/// <para>
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="count">
/// Where to store the number of video modes in the returned array.
/// This is set to zero if an error occurred.
/// </param>
/// <returns>An array of video modes, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetVideoMode"/>
public static unsafe VideoMode* GetVideoModesRaw(Monitor* monitor, out int count)
{
fixed (int* ptr = &count)
{
return glfwGetVideoModes(monitor, ptr);
}
}
/// <summary>
/// <para>
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <param name="count">
/// Where to store the number of video modes in the returned array.
/// This is set to zero if an error occurred.
/// </param>
/// <returns>An array of video modes, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetVideoMode"/>
public static unsafe VideoMode* GetVideoModesRaw(Monitor* monitor, int* count)
{
return glfwGetVideoModes(monitor, count);
}
/// <summary>
/// <para>
/// This function returns an array of all video modes supported by the specified monitor.
/// The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths)
/// and then by resolution area (the product of width and height).
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <returns>An array of video modes, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned array is allocated and freed by GLFW. You should not free it yourself.
/// It is valid until the specified monitor is disconnected,
/// this function is called again for that monitor, or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
/// <seealso cref="GetVideoMode"/>
public static unsafe VideoMode[] GetVideoModes(Monitor* monitor)
{
var ptr = GetVideoModesRaw(monitor, out var count);
if (ptr == null)
{
return null;
}
var array = new VideoMode[count];
for (var i = 0; i < count; i++)
{
array[i] = ptr[i];
}
return array;
}
/// <summary>
/// <para>
/// This function generates a 256-element gamma ramp from the specified exponent and then calls
/// <see cref="SetGamma"/> with it. The value must be a finite number greater than zero.
/// </para>
/// </summary>
/// <param name="monitor">The monitor whose gamma ramp to set.</param>
/// <param name="gamma">The desired exponent.</param>
/// <remarks>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>, <see cref="ErrorCode.InvalidValue"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe void SetGamma(Monitor* monitor, float gamma)
{
glfwSetGamma(monitor, gamma);
}
/// <summary>
/// <para>
/// This function returns the current gamma ramp of the specified monitor.
/// </para>
/// </summary>
/// <param name="monitor">The monitor to query.</param>
/// <returns>The current gamma ramp, or <c>null</c> if an error occurred.</returns>
/// <remarks>
/// <para>
/// The returned structure and its arrays are allocated and freed by GLFW.
/// You should not free them yourself. They are valid until the specified monitor is disconnected,
/// this function is called again for that monitor or the library is terminated.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe GammaRamp* GetGammaRamp(Monitor* monitor)
{
return glfwGetGammaRamp(monitor);
}
/// <summary>
/// <para>
/// This function sets the current gamma ramp for the specified monitor.
/// </para>
/// <para>
/// The original gamma ramp for that monitor
/// is saved by GLFW the first time this function is called and is restored by <see cref="Terminate"/>.
/// </para>
/// </summary>
/// <param name="monitor">The monitor whose gamma ramp to set.</param>
/// <param name="ramp">The gamma ramp to use.</param>
/// <remarks>
/// <para>
/// Gamma ramp sizes other than 256 are not supported by all platforms or graphics hardware.
/// </para>
/// <para>
/// Windows: The gamma ramp size must be 256.
/// </para>
/// <para>
/// The specified gamma ramp is copied before this function returns.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe void SetGammaRamp(Monitor* monitor, GammaRamp* ramp)
{
glfwSetGammaRamp(monitor, ramp);
}
/// <summary>
/// <para>
/// This function resets all window hints to their default values.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// </remarks>
public static void DefaultWindowHints() => glfwDefaultWindowHints();
/// <summary>
/// <para>
/// Sets the specified window hint to the desired value.
/// </para>
/// <para>
/// This function sets hints for the next call to @ref glfwCreateWindow. The
/// hints, once set, retain their values until changed by a call to this
/// function or <see cref="DefaultWindowHints"/>, or until the library is terminated.
/// </para>
/// <para>
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported by the next
/// call to <see cref="CreateWindow"/>.
/// </para>
/// <para>
/// Some hints are platform specific. These may be set on any platform but they
/// will only affect their specific platform. Other platforms will ignore them.
/// Setting these hints requires no platform specific headers or functions.
/// </para>
/// </summary>
/// <param name="hint">The window hint to set.</param>
/// <param name="value">The new value of the set hint.</param>
/// <remarks>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> <see cref="ErrorCode.InvalidEnum"/>.
/// </para>
/// <para>
/// The string is copied before this function returns.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// </remarks>
public static unsafe void WindowHint(WindowHintString hint, string value)
{
var ptr = Marshal.StringToCoTaskMemUTF8(value);
try
{
glfwWindowHintString((int)hint, (byte*)ptr);
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
/// <summary>
/// <para>
/// Sets the specified window hint to the desired value.
/// </para>
/// <para>
/// This function sets hints for the next call to @ref glfwCreateWindow. The
/// hints, once set, retain their values until changed by a call to this
/// function or <see cref="DefaultWindowHints"/>, or until the library is terminated.
/// </para>
/// <para>
/// This function does not check whether the specified hint values are valid.
/// If you set hints to invalid values this will instead be reported by the next
/// call to <see cref="CreateWindow"/>.
/// </para>
/// <para>
/// Some hints are platform specific. These may be set on any platform but they
/// will only affect their specific platform. Other platforms will ignore them.
/// Setting these hints requires no platform specific headers or functions.
/// </para>
/// </summary>
/// <param name="hint">The window hint to set.</param>
/// <param name="value">The new value of the set hint.</param>
/// <remarks>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/> <see cref="ErrorCode.InvalidEnum"/>.
/// </para>
/// <para>
/// The string is copied before this function returns.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// </remarks>
public static unsafe void WindowHintRaw(WindowHintString hint, byte* value)
{
glfwWindowHintString((int)hint, value);
}
/// <summary>
/// <para>
/// This function sets the size limits of the client area of the specified window.
/// </para>
/// <para>
/// If the window is full screen, the size limits only take effect once it is made windowed.
/// </para>
/// <para>
/// If the window is not resizable, this function does nothing.
/// </para>
/// <para>
/// The size limits are applied immediately to a windowed mode window and may cause it to be resized.
/// </para>
/// <para>
/// The maximum dimensions must be greater than or equal to the minimum dimensions
/// and all must be greater than or equal to zero.
/// </para>
/// </summary>
/// <param name="window">The window to set limits for.</param>
/// <param name="minWidth">
/// The minimum width, in screen coordinates, of the client area, or <see cref="GLFW.DontCare"/>.
/// </param>
/// <param name="minHeight">
/// The minimum height, in screen coordinates, of the client area, or <see cref="GLFW.DontCare"/>.
/// </param>
/// <param name="maxWidth">
/// The maximum width, in screen coordinates, of the client area, or <see cref="GLFW.DontCare"/>.
/// </param>
/// <param name="maxHeight">
/// The maximum height, in screen coordinates, of the client area, or <see cref="GLFW.DontCare"/>.
/// </param>
/// <remarks>
/// <para>
/// If you set size limits and an aspect ratio that conflict, the results are undefined.
/// </para>
/// <para>
/// This function must only be called from the main thread.
/// </para>
/// <para>
/// Possible errors include <see cref="ErrorCode.NotInitialized"/>, <see cref="ErrorCode.InvalidValue"/> and <see cref="ErrorCode.PlatformError"/>.
/// </para>
/// </remarks>
public static unsafe void SetWindowSizeLimits(
Window* window,
int minWidth,
int minHeight,
int maxWidth,