Exemplo n.º 1
0
        public void RenderScene(Scene scene)
        {
            _renderer2D.BeginRendering();

            _renderer2D.Clear(Color.FromArgb(255, 255, 255, 255));

            // TODO It is inefficient to traverse all entities to find a camera each time.
            var cameraEntity = scene.AllEntities.SingleOrDefault(e => e.HasComponent <CameraComponent>() && e.HasComponent <Transform2DComponent>());

            if (cameraEntity != null)
            {
                var cameraComponent = cameraEntity.GetComponent <CameraComponent>();
                cameraComponent.ScreenWidth  = _renderer2D.ScreenWidth;
                cameraComponent.ScreenHeight = _renderer2D.ScreenHeight;
                var cameraTransformationMatrix = cameraEntity.Create2DWorldToScreenMatrix();

                if (cameraComponent.AspectRatioBehavior == AspectRatioBehavior.Underscan)
                {
                    _renderer2D.Clear(Color.FromArgb(255, 0, 0, 0));

                    var clipDimension     = ComputeClipDimension(cameraComponent);
                    var clippingRectangle = new AxisAlignedRectangle(clipDimension);
                    _renderer2D.SetClippingRectangle(clippingRectangle);

                    _renderer2D.Clear(Color.FromArgb(255, 255, 255, 255));
                }

                UpdateRenderList(scene);
                RenderEntities(cameraTransformationMatrix);

                _debugRendererForRenderingSystem.DrawDebugInformation(_renderer2D, cameraTransformationMatrix);

                if (cameraComponent.AspectRatioBehavior == AspectRatioBehavior.Underscan)
                {
                    _renderer2D.ClearClipping();
                }
            }
            else
            {
                Log.Warn("No camera component found in scene.");
            }

            RenderDiagnosticInfo();

            _renderer2D.EndRendering(_renderingConfiguration.EnableVSync);
        }