Ejemplo n.º 1
0
            public bool SetPosition(Vector2 position)
            {
                _checkDisposed();

                var(x, y) = position;

                if (!AreFinite(x, y))
                {
                    return(false);
                }
#if DEBUG
                // OpenAL doesn't seem to want to play stereo positionally.
                // Log a warning if people try to.
                if (_sourceStream.ChannelCount > 1 && !_didPositionWarning)
                {
                    _didPositionWarning = true;
                    Logger.WarningS("clyde.oal",
                                    "Attempting to set position on audio source with multiple audio channels! Stream: '{0}'",
                                    _sourceStream.Name);
                }
#endif

                AL.Source(SourceHandle, ALSource3f.Position, x, y, 0);
                _master._checkAlError();
                return(true);
            }
Ejemplo n.º 2
0
        private void OnGlfwWindowSize(Window *window, int width, int height)
        {
            try
            {
                var oldSize = _framebufferSize;
                GLFW.GetFramebufferSize(window, out var fbW, out var fbH);
                _framebufferSize = (fbW, fbH);
                _windowSize      = (width, height);

                if (fbW == 0 || fbH == 0 || width == 0 || height == 0)
                {
                    return;
                }

                _pixelRatio = _framebufferSize / _windowSize;

                GL.Viewport(0, 0, fbW, fbH);
                if (fbW != 0 && fbH != 0)
                {
                    RegenerateLightingRenderTargets();
                }

                OnWindowResized?.Invoke(new WindowResizedEventArgs(oldSize, _framebufferSize));
            }
            catch (Exception e)
            {
                CatchCallbackException(e);
            }
        }
Ejemplo n.º 3
0
        private void OnGlfwWindowSize(Window *window, int width, int height)
        {
            try
            {
                var oldSize = _framebufferSize;
                GLFW.GetFramebufferSize(window, out var fbW, out var fbH);
                _framebufferSize = (fbW, fbH);
                _windowSize      = (width, height);
                UpdateWindowLoadedRtSize();

                if (fbW == 0 || fbH == 0 || width == 0 || height == 0)
                {
                    return;
                }

                _pixelRatio = _framebufferSize / _windowSize;

                GL.Viewport(0, 0, fbW, fbH);
                if (fbW != 0 && fbH != 0)
                {
                    _mainViewport.Dispose();
                    CreateMainViewport();
                }

                OnWindowResized?.Invoke(new WindowResizedEventArgs(oldSize, _framebufferSize));
            }
            catch (Exception e)
            {
                CatchCallbackException(e);
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
 private void OnGlfwWindownContentScale(Window *window, float xScale, float yScale)
 {
     try
     {
         _windowScale = (xScale, yScale);
     }
     catch (Exception e)
     {
         CatchCallbackException(e);
     }
 }
        private void OnGlfwCursorPos(Window *window, double x, double y)
        {
            var newPos = ((float)x, (float)y) * _pixelRatio;
            var delta  = newPos - _lastMousePos;

            _lastMousePos = newPos;

            var ev = new MouseMoveEventArgs(delta, newPos);

            _gameController.MouseMove(ev);
        }
Ejemplo n.º 7
0
            public void SetVelocity(Vector2 velocity)
            {
                _checkDisposed();

                var(x, y) = velocity;

                if (!AreFinite(x, y))
                {
                    return;
                }

                AL.Source(SourceHandle, ALSource3f.Velocity, x, y, 0);

                _master._checkAlError();
            }
Ejemplo n.º 8
0
        private void OnGlfwCursorPos(Window *window, double x, double y)
        {
            try
            {
                var newPos = ((float)x, (float)y) * _pixelRatio;
                var delta  = newPos - _lastMousePos;
                _lastMousePos = newPos;

                var ev = new MouseMoveEventArgs(delta, newPos);
                _gameController.MouseMove(ev);
            }
            catch (Exception e)
            {
                CatchCallbackException(e);
            }
        }
Ejemplo n.º 9
0
        protected override Vector2 MeasureOverride(Vector2 availableSize)
        {
            if (List.ChildCount == 0)
            {
                return(Vector2.Zero);
            }

            List.Measure(availableSize);
            var listSize = List.DesiredSize;

            if (List.ChildCount < MaxItemsBeforeScroll)
            {
                return(listSize);
            }
            listSize.Y = MaxItemsBeforeScroll * 32 + MaxItemsBeforeScroll * MarginSizeBetweenElements;
            return(listSize);
        }
        private void OnGlfwWindowSize(Window *window, int width, int height)
        {
            var oldSize = _framebufferSize;

            GLFW.GetFramebufferSize(window, out var fbW, out var fbH);
            _framebufferSize = (fbW, fbH);

            _windowSize = (width, height);
            _pixelRatio = _framebufferSize / _windowSize;

            GL.Viewport(0, 0, fbW, fbH);
            if (fbW != 0 && fbH != 0)
            {
                _regenerateLightRenderTarget();
            }

            OnWindowResized?.Invoke(new WindowResizedEventArgs(oldSize, _framebufferSize));
        }
Ejemplo n.º 11
0
 public UniformConstants(Vector2 screenPixelSize, float time)
 {
     ScreenPixelSize = screenPixelSize;
     Time            = time;
 }
Ejemplo n.º 12
0
 public Vertex2D(Vector2 position, float u, float v)
     : this(position, new Vector2(u, v))
 {
 }
Ejemplo n.º 13
0
 public Vertex2D(Vector2 position, Vector2 textureCoordinates)
 {
     Position           = position;
     TextureCoordinates = textureCoordinates;
 }
Ejemplo n.º 14
0
        private void _initWindow()
        {
            var width  = _configurationManager.GetCVar <int>("display.width");
            var height = _configurationManager.GetCVar <int>("display.height");

            _window = new GameWindow(
                width,
                height,
                GraphicsMode.Default,
                "Space Station 14",
                GameWindowFlags.Default,
                DisplayDevice.Default,
                3, 3,
#if DEBUG
                GraphicsContextFlags.Debug | GraphicsContextFlags.ForwardCompatible
#else
                GraphicsContextFlags.ForwardCompatible
#endif
                )
            {
                Visible = true
            };

            // Actually set VSync.
            VSyncChanged();

            _windowSize = new Vector2i(_window.Width, _window.Height);

            _mainThread = Thread.CurrentThread;

            _window.KeyDown += (sender, eventArgs) =>
            {
                _gameController.KeyDown((KeyEventArgs)eventArgs);
            };

            _window.KeyUp  += (sender, eventArgs) => { _gameController.KeyUp((KeyEventArgs)eventArgs); };
            _window.Closed += _onWindowClosed;
            _window.Resize += (sender, eventArgs) =>
            {
                var oldSize = _windowSize;
                _windowSize = new Vector2i(_window.Width, _window.Height);
                GL.Viewport(0, 0, _window.Width, _window.Height);
                _regenerateLightTexture();
                OnWindowResized?.Invoke(new WindowResizedEventArgs(oldSize, _windowSize));
            };
            _window.MouseDown += (sender, eventArgs) =>
            {
                var mouseButtonEventArgs = (MouseButtonEventArgs)eventArgs;
                _gameController.MouseDown(mouseButtonEventArgs);
                if (!mouseButtonEventArgs.Handled)
                {
                    _gameController.KeyDown((KeyEventArgs)eventArgs);
                }
            };
            _window.MouseUp += (sender, eventArgs) =>
            {
                var mouseButtonEventArgs = (MouseButtonEventArgs)eventArgs;
                _gameController.MouseUp(mouseButtonEventArgs);
                if (!mouseButtonEventArgs.Handled)
                {
                    _gameController.KeyUp((KeyEventArgs)eventArgs);
                }
            };
            _window.MouseMove += (sender, eventArgs) =>
            {
                MouseScreenPosition = new Vector2(eventArgs.X, eventArgs.Y);
                _gameController.MouseMove((MouseMoveEventArgs)eventArgs);
            };
            _window.MouseWheel += (sender, eventArgs) =>
            {
                _gameController.MouseWheel((MouseWheelEventArgs)eventArgs);
            };
            _window.KeyPress += (sender, eventArgs) =>
            {
                // If this is a surrogate it has to be specifically handled and I'm not doing that yet.
                DebugTools.Assert(!char.IsSurrogate(eventArgs.KeyChar));

                _gameController.TextEntered(new TextEventArgs(eventArgs.KeyChar));
            };

            using (var iconFile = _resourceCache.ContentFileRead("/Textures/Logo/icon.ico"))
            {
                _window.Icon = new Icon(iconFile);
            }

            _initOpenGL();
        }
 private void OnGlfwWindownContentScale(Window *window, float xScale, float yScale)
 {
     _windowScale = (xScale, yScale);
 }
Ejemplo n.º 16
0
        private bool InitWindow()
        {
            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;
            }

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

            var renderer = (Renderer)_configurationManager.GetCVar <int>("display.renderer");

            if (renderer == Renderer.Default)
            {
                // Try OpenGL Core 3.3
                GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3);
                GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 3);
                GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true);
                GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);

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

                if (_glfwWindow == null)
                {
                    // Window failed to init due to error.
                    var err = GLFW.GetErrorRaw(out _);

                    if (err == ErrorCode.VersionUnavailable)
                    {
                        Logger.DebugS("clyde.win", "OpenGL Core 3.3 unsupported, trying OpenGL 3.1");

                        CreateWindowGl31();
                    }
                }
            }
            else if (renderer == Renderer.OpenGL31)
            {
                CreateWindowGl31();
            }

            if (_glfwWindow == null)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var code = GLFW.GetError(out string desc);

                    var errorContent = "Failed to create the game window. " +
                                       "This probably means your GPU is too old to play the game. " +
                                       "That or update your graphic drivers\n" +
                                       $"The exact error is: [{code}]\n {desc}";

                    MessageBoxW(null,
                                errorContent,
                                "Space Station 14: Failed to create window",
                                MB_OK | MB_ICONERROR);
                }

                Logger.FatalS("clyde.win",
                              "Failed to create GLFW window! " +
                              "This probably means your GPU is too old to run the game. " +
                              "That or update your graphics drivers.");
                return(false);
            }

            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.SetWindowIconifyCallback(_glfwWindow, _windowIconifyCallback);

            GLFW.MakeContextCurrent(_glfwWindow);

            VSyncChanged();

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

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

            GLFW.GetWindowSize(_glfwWindow, out var w, out var h);
            _prevWindowSize = _windowSize = (w, h);

            GLFW.GetWindowPos(_glfwWindow, out var x, out var y);
            _prevWindowPos = (x, y);

            _pixelRatio = _framebufferSize / _windowSize;

            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();

            return(true);

            void CreateWindowGl31()
            {
                GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3);
                GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 1);
                GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, false);
                GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any);

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