コード例 #1
0
        public void Initialize()
        {
            _pMonitor = (Monitor *)Marshal.AllocHGlobal(sizeof(Monitor));

            Interop.Kernel32.InitializeCriticalSection(&_pMonitor->_criticalSection);
            Interop.Kernel32.InitializeConditionVariable(&_pMonitor->_conditionVariable);
        }
コード例 #2
0
        private bool InitWindow()
        {
            var width  = _configurationManager.GetCVar(CVars.DisplayWidth);
            var height = _configurationManager.GetCVar(CVars.DisplayHeight);

            Monitor *monitor = null;

            if (WindowMode == WindowMode.Fullscreen)
            {
                monitor = GLFW.GetPrimaryMonitor();
                var mode = GLFW.GetVideoMode(monitor);
                width  = mode->Width;
                height = mode->Height;
            }

#if DEBUG
            GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true);
#endif
            GLFW.WindowHint(WindowHintString.X11ClassName, "SS14");
            GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14");

            var renderer = (Renderer)_configurationManager.GetCVar <int>(CVars.DisplayRenderer);

            Span <Renderer> renderers = (renderer == Renderer.Default) ? stackalloc Renderer[] {
                Renderer.OpenGL33,
                Renderer.OpenGL31,
                Renderer.OpenGLES2
            } : stackalloc Renderer[] { renderer };
コード例 #3
0
        private void InitWindow()
        {
            GLFW.WindowHint(WindowHintBool.SrgbCapable, true);
            GLFW.WindowHint(WindowHintInt.ContextVersionMajor, MinimumOpenGLVersion.Major);
            GLFW.WindowHint(WindowHintInt.ContextVersionMinor, MinimumOpenGLVersion.Minor);
            GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true);
            GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);
#if DEBUG
            GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true);
#endif
            GLFW.WindowHint(WindowHintString.X11ClassName, "SS14");
            GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14");

            var width  = _configurationManager.GetCVar <int>("display.width");
            var height = _configurationManager.GetCVar <int>("display.height");

            Monitor *monitor = null;

            if (WindowMode == WindowMode.Fullscreen)
            {
                monitor = GLFW.GetPrimaryMonitor();
                var mode = GLFW.GetVideoMode(monitor);
                width  = mode->Width;
                height = mode->Height;
            }

            _glfwWindow = GLFW.CreateWindow(width, height, string.Empty, monitor, null);

            LoadWindowIcon();

            GLFW.SetCharCallback(_glfwWindow, _charCallback);
            GLFW.SetKeyCallback(_glfwWindow, _keyCallback);
            GLFW.SetWindowCloseCallback(_glfwWindow, _windowCloseCallback);
            GLFW.SetCursorPosCallback(_glfwWindow, _cursorPosCallback);
            GLFW.SetWindowSizeCallback(_glfwWindow, _windowSizeCallback);
            GLFW.SetScrollCallback(_glfwWindow, _scrollCallback);
            GLFW.SetMouseButtonCallback(_glfwWindow, _mouseButtonCallback);
            GLFW.SetWindowContentScaleCallback(_glfwWindow, _windowContentScaleCallback);

            GLFW.MakeContextCurrent(_glfwWindow);

            VSyncChanged();

            GLFW.GetFramebufferSize(_glfwWindow, out var fbW, out var fbH);
            _screenSize = (fbW, fbH);

            GLFW.GetWindowContentScale(_glfwWindow, out var scaleX, out var scaleY);
            _windowScale = (scaleX, scaleY);

            InitGLContext();

            // Initializing OTK 3 seems to mess with the current context, so ensure it's still set.
            // This took me f*****g *forever* to debug because this manifested differently on nvidia drivers vs intel mesa.
            // So I thought it was a calling convention issue with the calli OpenTK emits.
            // Because, in my tests, I had InitGLContext() AFTER the test with a delegate-based invoke of the proc.
            GLFW.MakeContextCurrent(_glfwWindow);

            InitOpenGL();
        }
コード例 #4
0
 private void OnGlfwMonitor(Monitor *monitor, ConnectedState state)
 {
     if (state == ConnectedState.Connected)
     {
         WinThreadSetupMonitor(monitor);
     }
     else
     {
         WinThreadDestroyMonitor(monitor);
     }
 }
コード例 #5
0
        private void DisposeCore()
        {
            if (_pMonitor == null)
            {
                return;
            }

            Interop.Kernel32.DeleteCriticalSection(&_pMonitor->_criticalSection);
            Marshal.FreeHGlobal((IntPtr)_pMonitor);
            _pMonitor = null;
        }
コード例 #6
0
        /// <summary>
        ///     Gets the raw dpi of the monitor pointed to.
        /// </summary>
        /// <param name="monitor">The monitor in question.</param>
        /// <param name="horizontalDpi">Horizontal dpi.</param>
        /// <param name="verticalDpi">Vertical dpi.</param>
        /// <returns><c>true</c>, if monitor's raw dpi was gotten correctly, <c>false</c> otherwise.</returns>
        /// <remarks>
        ///     This method calculates dpi by retrieving monitor dimensions and resolution.
        ///     However on certain platforms (such as Windows) these values may not
        ///     be scaled correctly.
        /// </remarks>
        public static unsafe bool TryGetMonitorDpiRaw(Monitor *monitor, out float horizontalDpi, out float verticalDpi)
        {
            if (TryGetFromCache((IntPtr)monitor, out var info))
            {
                horizontalDpi = info.HorizontalRawDpi;
                verticalDpi   = info.VerticalRawDpi;
                return(true);
            }

            horizontalDpi = verticalDpi = GetPlatformDefaultDpi();
            return(false);
        }
コード例 #7
0
ファイル: External.cs プロジェクト: OJETeam/GLFW
        public static Monitor[] GetMonitors(out int count)
        {
            int      lenght;
            Monitor *monitors = Imports.glfwGetMonitors(out lenght);

            Monitor[] result = new Monitor[lenght];
            for (int i = 0; i < lenght; i++)
            {
                result[i] = monitors[i];
            }
            count = lenght;
            return(result);
        }
コード例 #8
0
        private static void SetUpMonitorData()
        {
            ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();

            var platformMonitors = new List <ImGuiPlatformMonitor>();

            {
                Monitor *[] monitors = GLFW.GetMonitors();

                for (int i = 0; i < monitors.Length; i++)
                {
                    Monitor *            monitor = monitors[i];
                    ImGuiPlatformMonitor m       = new ImGuiPlatformMonitor();

                    var vidMode = GLFW.GetVideoMode(monitor);
                    GLFW.GetMonitorPos(monitor, out int x, out int y);
                    m.MainPos  = m.WorkPos = new Vector2(x, y);
                    m.MainSize = m.WorkSize = new Vector2(vidMode->Width, vidMode->Height);
                    GLFW.GetMonitorContentScale(monitor, out float xScale, out float yScale);
                    m.DpiScale = xScale;

                    platformMonitors.Add(m);
                }
            }

            _monitorData    = platformMonitors.ToArray();
            _monitorDataPin = GCHandle.Alloc(_monitorData, GCHandleType.Pinned);

            var platformMonitorsPtrs = new ImGuiPlatformMonitorPtr[_monitorData.Length];

            for (int i = 0; i < _monitorData.Length; i++)
            {
                fixed(ImGuiPlatformMonitor *ptr = &_monitorData[i])
                {
                    platformMonitorsPtrs[i] = new ImGuiPlatformMonitorPtr(ptr);
                }
            }

            _monitorPtrData    = platformMonitorsPtrs;
            _monitorPtrDataPin = GCHandle.Alloc(_monitorPtrData, GCHandleType.Pinned);
            _monitorsPtrVector = new ImVector <ImGuiPlatformMonitor>(_monitorPtrData.Length,
                                                                     _monitorPtrData.Length,
                                                                     _monitorDataPin.AddrOfPinnedObject());

            {
                ImGuiPlatformIO *ptr = platformIO;
                ImVector         v   = Unsafe.As <ImVector <ImGuiPlatformMonitor>, ImVector>(ref _monitorsPtrVector);
                ptr->Monitors = v;
            }
        }
コード例 #9
0
        /// <summary>
        ///     Gets the current monitor scale.
        /// </summary>
        /// <param name="monitor">The monitor in question.</param>
        /// <param name="horizontalScale">Horizontal scale.</param>
        /// <param name="verticalScale">Vertical scale.</param>
        /// <returns><c>true</c>, if current monitor scale was gotten correctly, <c>false</c> otherwise.</returns>
        public static unsafe bool TryGetMonitorScale(
            Monitor *monitor,
            out float horizontalScale,
            out float verticalScale
            )
        {
            if (TryGetFromCache((IntPtr)monitor, out var info))
            {
                horizontalScale = info.HorizontalScale;
                verticalScale   = info.VerticalScale;
                return(true);
            }

            horizontalScale = 1f;
            verticalScale   = 1f;
            return(false);
        }
コード例 #10
0
ファイル: DpiInfo.cs プロジェクト: zooid/opentk
        /// <summary>
        /// Initializes a new instance of the <see cref="DpiInfo"/> class.
        /// </summary>
        /// <remarks>
        /// <paramref pref="handle"/> must be a valid pointer to a monitor.
        /// </remarks>
        /// <param name="handle">An opaque handle to a monitor.</param>
        public DpiInfo(Monitor *handle)
        {
            if (!GLFWProvider.IsOnMainThread)
            {
                throw new NotSupportedException("Only the GLFW thread can construct this object.");
            }

            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            _handle = handle;

            GetClientArea();
            GetPhysicalSize();
            GetScale();

            // DO NOT call these methods before the above Get* methods.
            CalculateMonitorDpi();
            CalculateMonitorRawDpi();
        }
コード例 #11
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwSetGamma(Monitor *monitor, float gamma);
コード例 #12
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void *glfwGetMonitorUserPointer(Monitor *monitor);
コード例 #13
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern VideoMode *glfwGetVideoModes(Monitor *monitor, int *count);
コード例 #14
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern byte *glfwGetMonitorName(Monitor *monitor);
コード例 #15
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwSetMonitorUserPointer(Monitor *monitor, void *pointer);
コード例 #16
0
 /// <inheritdoc />
 public abstract unsafe string GetMonitorName(Monitor *monitor);
コード例 #17
0
 /// <inheritdoc />
 public abstract unsafe GammaRamp *GetGammaRamp(Monitor *monitor);
コード例 #18
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwSetWindowMonitor(Window *window, Monitor *monitor, int x, int y, int width, int height, int refreshRate);
コード例 #19
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwGetMonitorPos(Monitor *monitor, int *x, int *y);
コード例 #20
0
 /// <inheritdoc />
 public abstract unsafe void SetMonitorUserPointer(Monitor *monitor, IntPtr pointer);
コード例 #21
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern VideoMode *glfwGetVideoMode(Monitor *monitor);
コード例 #22
0
 /// <inheritdoc />
 public abstract unsafe IntPtr GetMonitorUserPointer(Monitor *monitor);
コード例 #23
0
 /// <inheritdoc />
 public abstract unsafe VideoMode *GetVideoModes(Monitor *monitor, out int count);
コード例 #24
0
 private static unsafe void DpiMonitorCallback(Monitor *monitor, ConnectedState state)
 {
     // Normally, adding or removing from the cache would be nice, but this breaks
     // getting the info from an index, thus the cache must be built from scratch.
     BuildMonitorCache();
 }
コード例 #25
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern GammaRamp *glfwGetGammaRamp(Monitor *monitor);
コード例 #26
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwGetMonitorPhysicalSize(Monitor *monitor, int *width, int *height);
コード例 #27
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwSetGammaRamp(Monitor *monitor, GammaRamp *ramp);
コード例 #28
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern void glfwGetMonitorContentScale(Monitor *monitor, float *xscale, float *yscale);
コード例 #29
0
ファイル: GLFWNative.cs プロジェクト: voltairianman/opentk
 public static extern Window *glfwCreateWindow(int width, int height, byte *title, Monitor *monitor, Window *share);
コード例 #30
0
 /// <inheritdoc />
 public abstract unsafe void SetGamma(Monitor *monitor, float gamma);