Exemple #1
0
        /// <summary>
        /// Executes Draw events.
        /// </summary>
        internal static void CallDrawEvents()
        {
            foreach (var scene in Scenes)
            {
                if (scene.Visible)
                {
                    CurrentScene = scene;
                    foreach (var layer in scene.Layers)
                    {
                        if (
                            layer.Visible &&
                            !layer.IsGUI &&
                            !GraphicsMgr.CurrentCamera.Filter(scene.Name, layer.Name)
                            )
                        {
                            CurrentLayer = layer;

                            bool hasPostprocessing = (
                                GraphicsMgr.CurrentCamera.PostprocessingMode == PostprocessingMode.CameraAndLayers &&
                                layer.PostprocessorEffects.Count > 0
                                );

                            if (hasPostprocessing)
                            {
                                GraphicsMgr.SetSurfaceTarget(GraphicsMgr.CurrentCamera._postprocessorLayerBuffer, GraphicsMgr.CurrentView);
                                GraphicsMgr.Device.Clear(Color.TransparentBlack);
                            }

                            foreach (var entity in layer._depthSortedEntities)
                            {
                                if (entity.Visible && !entity.Destroyed)
                                {
                                    foreach (var componentPair in entity._components)
                                    {
                                        if (componentPair.Value.Visible)
                                        {
                                            SystemMgr.Draw(componentPair.Value);
                                        }
                                    }
                                    entity.Draw();
                                }
                            }

                            if (hasPostprocessing)
                            {
                                GraphicsMgr.ResetSurfaceTarget();

                                var oldRasterizer = GraphicsMgr.Rasterizer;
                                GraphicsMgr.Rasterizer = GraphicsMgr._cameraRasterizerState;
                                GraphicsMgr.SetTransformMatrix(Matrix.CreateTranslation(Vector3.Zero));
                                layer.ApplyPostprocessing();
                                GraphicsMgr.ResetTransformMatrix();
                                GraphicsMgr.Rasterizer = oldRasterizer;
                            }
                        }
                    }
                }
            }
        }