public SceneRenderer(GameSettingsAsset gameSettings) { if (gameSettings == null) throw new ArgumentNullException(nameof(gameSettings)); // Initialize services Services = new ServiceRegistry(); ContentManager = new ContentManager(Services); var renderingSettings = gameSettings.Get<RenderingSettings>(); GraphicsDevice = GraphicsDevice.New(DeviceCreationFlags.None, new[] { renderingSettings.DefaultGraphicsProfile }); var graphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice); EffectSystem = new EffectSystem(Services); GraphicsContext = new GraphicsContext(GraphicsDevice); Services.AddService(typeof(GraphicsContext), GraphicsContext); SceneSystem = new SceneSystem(Services); // Create game systems GameSystems = new GameSystemCollection(Services); GameSystems.Add(new GameFontSystem(Services)); GameSystems.Add(new UISystem(Services)); GameSystems.Add(EffectSystem); GameSystems.Add(SceneSystem); GameSystems.Initialize(); // Fake presenter // TODO GRAPHICS REFACTOR: This is needed be for render stage setup GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice, Texture.New2D(GraphicsDevice, renderingSettings.DefaultBackBufferWidth, renderingSettings.DefaultBackBufferHeight, renderingSettings.ColorSpace == ColorSpace.Linear ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget), PixelFormat.D24_UNorm_S8_UInt); SceneSystem.MainRenderFrame = RenderFrame.FromTexture(GraphicsDevice.Presenter.BackBuffer, GraphicsDevice.Presenter.DepthStencilBuffer); }
public SceneRenderer(GameSettingsAsset gameSettings) { if (gameSettings == null) { throw new ArgumentNullException(nameof(gameSettings)); } // Initialize services Services = new ServiceRegistry(); ContentManager = new ContentManager(Services); Services.AddService(typeof(IContentManager), ContentManager); Services.AddService(typeof(ContentManager), ContentManager); var renderingSettings = gameSettings.GetOrCreate <RenderingSettings>(); GraphicsDevice = GraphicsDevice.New(DeviceCreationFlags.Debug, new[] { renderingSettings.DefaultGraphicsProfile }); var graphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice); Services.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); EffectSystem = new EffectSystem(Services); Services.AddService(typeof(EffectSystem), EffectSystem); GraphicsContext = new GraphicsContext(GraphicsDevice); Services.AddService(typeof(GraphicsContext), GraphicsContext); SceneSystem = new SceneSystem(Services); Services.AddService(typeof(SceneSystem), SceneSystem); // Create game systems GameSystems = new GameSystemCollection(Services); Services.AddService(typeof(IGameSystemCollection), GameSystems); var gameFontSystem = new GameFontSystem(Services); Services.AddService(typeof(FontSystem), gameFontSystem.FontSystem); Services.AddService(typeof(IFontFactory), gameFontSystem.FontSystem); GameSystems.Add(gameFontSystem); var uiSystem = new UISystem(Services); Services.AddService(typeof(UISystem), uiSystem); GameSystems.Add(uiSystem); GameSystems.Add(EffectSystem); GameSystems.Add(SceneSystem); GameSystems.Initialize(); // Fake presenter // TODO GRAPHICS REFACTOR: This is needed be for render stage setup GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice, Texture.New2D(GraphicsDevice, renderingSettings.DefaultBackBufferWidth, renderingSettings.DefaultBackBufferHeight, renderingSettings.ColorSpace == ColorSpace.Linear ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget), PixelFormat.D24_UNorm_S8_UInt); GraphicsContext.CommandList.SetRenderTarget(GraphicsDevice.Presenter.DepthStencilBuffer, GraphicsDevice.Presenter.BackBuffer); }
public static void TryAdd <T>(this GameSystemCollection gameSystems, T gameSystem) where T : GameSystemBase { for (int i = 0; i < gameSystems.Count; i++) { if (gameSystems[i] == gameSystem) { return; } } gameSystems.Add(gameSystem); }
public ThumbnailGenerator(EffectCompilerBase effectCompiler) { // create base services Services = new ServiceRegistry(); Services.AddService(MicrothreadLocalDatabases.ProviderService); ContentManager = new ContentManager(Services); Services.AddService <IContentManager>(ContentManager); Services.AddService(ContentManager); GraphicsDevice = GraphicsDevice.New(); GraphicsContext = new GraphicsContext(GraphicsDevice); GraphicsCommandList = GraphicsContext.CommandList; Services.AddService(GraphicsContext); sceneSystem = new SceneSystem(Services); Services.AddService(sceneSystem); fontSystem = new GameFontSystem(Services); Services.AddService(fontSystem.FontSystem); Services.AddService <IFontFactory>(fontSystem.FontSystem); GraphicsDeviceService = new GraphicsDeviceServiceLocal(Services, GraphicsDevice); Services.AddService(GraphicsDeviceService); var uiSystem = new UISystem(Services); Services.AddService(uiSystem); var physicsSystem = new Bullet2PhysicsSystem(Services); Services.AddService <IPhysicsSystem>(physicsSystem); gameSystems = new GameSystemCollection(Services) { fontSystem, uiSystem, physicsSystem }; Services.AddService <IGameSystemCollection>(gameSystems); Simulation.DisableSimulation = true; //make sure we do not simulate physics within the editor // initialize base services gameSystems.Initialize(); // create remaining services EffectSystem = new EffectSystem(Services); Services.AddService(EffectSystem); gameSystems.Add(EffectSystem); gameSystems.Add(sceneSystem); EffectSystem.Initialize(); // Mount the same database for the cache EffectSystem.Compiler = EffectCompilerFactory.CreateEffectCompiler(effectCompiler.FileProvider, EffectSystem); // Deactivate the asynchronous effect compilation ((EffectCompilerCache)EffectSystem.Compiler).CompileEffectAsynchronously = false; // load game system content gameSystems.LoadContent(); // create the default fonts var fontItem = OfflineRasterizedSpriteFontFactory.Create(); fontItem.FontType.Size = 22; DefaultFont = OfflineRasterizedFontCompiler.Compile(fontSystem.FontSystem, fontItem, true); // create utility members nullGameTime = new GameTime(); SpriteBatch = new SpriteBatch(GraphicsDevice); UIBatch = new UIBatch(GraphicsDevice); // create the pipeline SetUpPipeline(); }