/// <inheritdoc /> public override void Setup(Vector2 renderSize) { Gl.BindAPI(s => Glfw.GetProcAddress(s)); Gl.QueryContextVersion(); // Check if context was created. if (Gl.CurrentVersion == null) { ErrorHandler.SubmitError(new Exception("Couldn't connect to OpenGL context.")); return; } // Bind current thread as the GLThread. GLThread.BindThread(); // Renderer bootstrap. Engine.Log.Info("Creating OpenGL GraphicsManager...", MessageSource.GL); Engine.Log.Info($"GL: {Gl.CurrentVersion} on {Gl.CurrentRenderer}", MessageSource.GL); Engine.Log.Info($"GLSL: {Gl.CurrentShadingVersion}", MessageSource.GL); CreateDefaultShader(); CreateDefaultIbo(); // Set default state. DefaultGLState(); ResetState(); // Clear to transparent black. Gl.ClearColor(0, 0, 0, 0); Engine.Log.Info("GraphicsManager ready.", MessageSource.GL); }
/// <summary> /// Perform engine setup. /// </summary> /// <param name="configurator">An optional engine configuration - will be passed to the light setup.</param> public static void Setup(Configurator configurator = null) { // Call light setup if needed. if (Status < EngineStatus.LightSetup) { LightSetup(configurator); } if (Status >= EngineStatus.Setup) { return; } // Mount default assets. The platform should add it's own specific sources and stores. AssetLoader = LoadDefaultAssetLoader(); // Create the platform, window, audio, and graphics context. Host = PlatformBase.GetInstanceOfDetected(configurator); if (Host == null) { SubmitError(new Exception("Platform couldn't initialize.")); return; } InputManager = Host; Audio = Host.Audio; // Errors in host initialization can cause this. if (Status == EngineStatus.Stopped) { return; } // Now that the context is created, the renderer can be created. GLThread.BindThread(); Renderer = new RenderComposer(); Renderer.Setup(); // Now "game-mode" modules can be created. SceneManager = new SceneManager(); // Setup plugins. foreach (IPlugin p in Configuration.Plugins) { p.Initialize(); } if (Status == EngineStatus.Stopped) { return; } Status = EngineStatus.Setup; }
private static void InternalSetup(Action <Settings> config = null) { // Initiate bootstrap. Debugger.Log(MessageType.Info, MessageSource.Engine, "-------------------------------"); Debugger.Log(MessageType.Info, MessageSource.Engine, $"Executed at: {Environment.CurrentDirectory}"); Debugger.Log(MessageType.Info, MessageSource.Engine, $"Debug Mode / Debugger Attached: {Debugger.DebugMode} / {System.Diagnostics.Debugger.IsAttached}"); Debugger.Log(MessageType.Info, MessageSource.Engine, $"64Bit: {Environment.Is64BitProcess}"); Debugger.Log(MessageType.Info, MessageSource.Engine, $"OS: {CurrentPlatform.OS} ({Environment.OSVersion})"); Debugger.Log(MessageType.Info, MessageSource.Engine, $"CPU: {Environment.ProcessorCount}"); // Run platform specific boot. switch (CurrentPlatform.OS) { case PlatformName.Windows: WindowsSetup(); break; case PlatformName.Linux: LinuxSetup(); break; } Debugger.Log(MessageType.Info, MessageSource.Engine, "-------------------------------"); Debugger.Log(MessageType.Info, MessageSource.Engine, "Bootstrap complete."); // Apply settings and run initial setup function. Settings initial = new Settings(); config?.Invoke(initial); Settings = initial; // Setup thread manager. GLThread.BindThread(); // Create host if not created. if (Host == null) { try { Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating host..."); if (CurrentPlatform.OS == PlatformName.Windows || CurrentPlatform.OS == PlatformName.Linux || CurrentPlatform.OS == PlatformName.Mac) { Host = new OtkWindow(); Debugger.Log(MessageType.Info, MessageSource.Engine, "Created OpenTK window host."); } else { throw new Exception("Unsupported platform."); } } catch (Exception ex) { Debugger.Log(MessageType.Error, MessageSource.Engine, "Could not create host. Is the system supported?"); Debugger.Log(MessageType.Error, MessageSource.Engine, ex.ToString()); throw; } } // Apply settings and hook. Host.ApplySettings(Settings); Host.SetHooks(LoopUpdate, LoopDraw, Resize); // Start creating modules. // Scripting engine is first to provide the other modules the ability to expose functions. Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating scripting engine..."); ScriptingEngine = new ScriptingEngine(); // Asset loader is next so other modules - especially the renderer, can access the file system. Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating asset loader..."); AssetLoader = new AssetLoader(); // The order of the next modules doesn't matter. Debugger.InitializeModule(); Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating renderer..."); Renderer = new Renderer(); Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating sound manager..."); SoundManager = new SoundManager(); Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating layer manager..."); LayerManager = new LayerManager(); Debugger.Log(MessageType.Trace, MessageSource.Engine, "Creating input manager..."); InputManager = new InputManager(); }