Пример #1
0
 public override void ChangedWorldConfig(GraphicsDevice gd)
 {
     base.ChangedWorldConfig(gd);
     PPXDepthEngine.SSAA = (WorldConfig.Current.AA ? 2 : 1);
     PPXDepthEngine.InitScreenTargets();
     UseBackbuffer = WorldConfig.Current.AA;
 }
Пример #2
0
        public void RenderCache(List <_2DDrawBuffer> cache)
        {
            var effect = this.Effect;

            Device.BlendState = BlendState.AlphaBlend;
            //  set the only parameter this effect takes.
            var frontDir = FrontDirForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation);

            effect.Parameters["dirToFront"].SetValue(frontDir);
            effect.Parameters["offToBack"].SetValue(BackOffForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation));
            //frontDir /= 3;
            //WorldContent._2DWorldBatchEffect.Parameters["LightOffset"].SetValue(new Vector2(frontDir.X / (6 * 75), frontDir.Z / (6 * 75)));
            var mat = this.WorldCamera.View * this.WorldCamera.Projection;

            effect.Parameters["worldViewProjection"].SetValue(mat);
            effect.Parameters["iWVP"].SetValue(Matrix.Invert(mat));
            //effect.Parameters["depthOutMode"].SetValue(OutputDepth && (!FSOEnvironment.UseMRT));

            foreach (var buffer in cache)
            {
                PPXDepthEngine.RenderPPXDepth(effect, false, (depth) =>
                {
                    foreach (var group in buffer.Groups)
                    {
                        RenderDrawGroup(group);
                    }
                });
            }
        }
Пример #3
0
        public override bool NextPass()
        {
            if (Pass == 0)
            {
                Batch.Pause();
                PPXDepthEngine.SetPPXTarget(Target, DepthTarget, true);

                Batch.OutputDepth = true; //depth surface always uses depth techniques
                Batch.Resume();

                Pass++;
                return(true);
            }
            return(false);

            /*else if (Pass == 1)
             * {
             *  if (FSOEnvironment.UseMRT) return false;
             *  else
             *  {
             *      Batch.Pause();
             *      GD.SetRenderTarget(DepthTarget);
             *      Batch.OutputDepth = true;
             *      Batch.Resume();
             *      Pass++;
             *      return true;
             *  }
             * }
             * return false;*/
        }
Пример #4
0
        public void RenderCache(List <_2DDrawBuffer> cache)
        {
            var effect = this.Effect;

            Device.BlendState = BlendState.AlphaBlend;
            //  set the only parameter this effect takes.
            effect.Parameters["dirToFront"].SetValue(FrontDirForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation));
            effect.Parameters["offToBack"].SetValue(BackOffForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation));
            effect.Parameters["viewProjection"].SetValue(this.View * this.Projection);
            var mat = this.WorldCamera.View * this.WorldCamera.Projection;

            effect.Parameters["worldViewProjection"].SetValue(this.WorldCamera.View * this.WorldCamera.Projection);
            effect.Parameters["ambientLight"].SetValue(AmbientLight);
            //effect.Parameters["depthOutMode"].SetValue(OutputDepth && (!FSOEnvironment.UseMRT));

            foreach (var buffer in cache)
            {
                PPXDepthEngine.RenderPPXDepth(effect, false, (depth) =>
                {
                    foreach (var group in buffer.Groups)
                    {
                        RenderDrawGroup(group);
                    }
                });
            }
        }
Пример #5
0
 public virtual void Dispose()
 {
     Batch.Pause();
     PPXDepthEngine.SetPPXTarget(null, null, false);
     ExtractPixelTexture();
     Batch.Resume();
 }
Пример #6
0
        /// <summary>
        /// Setup anything that needs a GraphicsDevice
        /// </summary>
        /// <param name="layer"></param>
        public override void Initialize(_3DLayer layer)
        {
            base.Initialize(layer);

            /**
             * Setup world state, this object acts as a facade
             * to world objects as well as providing various
             * state settings for the world and helper functions
             */
            State = new WorldState(layer.Device, layer.Device.Viewport.Width, layer.Device.Viewport.Height, this);

            State._2D = new _2DWorldBatch(layer.Device, _2DWorldBatch.NUM_2D_BUFFERS,
                                          _2DWorldBatch.BUFFER_SURFACE_FORMATS, _2DWorldBatch.FORMAT_ALWAYS_DEPTHSTENCIL, _2DWorldBatch.SCROLL_BUFFER);

            Static = new WorldStatic(this);

            State.OutsidePx = new Texture2D(layer.Device, 1, 1);

            ChangedWorldConfig(layer.Device);

            PPXDepthEngine.InitGD(layer.Device);
            PPXDepthEngine.InitScreenTargets();

            base.Camera = State.Camera;

            HasInitGPU = true;
            HasInit    = HasInitGPU & HasInitBlueprint;
            GraphicsModeControl.ModeChanged += SetGraphicsMode;
        }
Пример #7
0
        /// <summary>
        /// Setup anything that needs a GraphicsDevice
        /// </summary>
        /// <param name="layer"></param>
        public override void Initialize(_3DLayer layer)
        {
            base.Initialize(layer);

            /**
             * Setup world state, this object acts as a facade
             * to world objects as well as providing various
             * state settings for the world and helper functions
             */
            State = new WorldState(layer.Device, layer.Device.Viewport.Width / FSOEnvironment.DPIScaleFactor, layer.Device.Viewport.Height / FSOEnvironment.DPIScaleFactor, this);

            State._3D = new FSO.LotView.Utils._3DWorldBatch(State);
            State._2D = new FSO.LotView.Utils._2DWorldBatch(layer.Device, World2D.NUM_2D_BUFFERS,
                                                            World2D.BUFFER_SURFACE_FORMATS, World2D.FORMAT_ALWAYS_DEPTHSTENCIL, World2D.SCROLL_BUFFER);

            ChangedWorldConfig(layer.Device);

            PPXDepthEngine.InitGD(layer.Device);
            PPXDepthEngine.InitScreenTargets();

            base.Camera = State.Camera;

            HasInitGPU = true;
            HasInit    = HasInitGPU & HasInitBlueprint;
        }
Пример #8
0
        public void ChangeAAMode(GraphicsDevice gd)
        {
            var lastm = PPXDepthEngine.MSAA;
            var lasts = PPXDepthEngine.SSAA;

            PPXDepthEngine.SSAAFunc = SSAADownsample.Draw;
            switch (WorldConfig.Current.AA)
            {
            case 0:
                PPXDepthEngine.MSAA = 0;
                PPXDepthEngine.SSAA = 1;
                break;

            case 1:
                PPXDepthEngine.MSAA = 4;
                PPXDepthEngine.SSAA = 1;
                break;

            case 2:
                PPXDepthEngine.MSAA = 0;
                PPXDepthEngine.SSAA = 2;
                break;
            }

            if (PPXDepthEngine.SSAA > 1 && State.CameraMode < CameraRenderMode._3D)
            {
                PPXDepthEngine.MSAA = 8;
                PPXDepthEngine.SSAA = 1;
            }
            if (lastm != PPXDepthEngine.MSAA || lasts != PPXDepthEngine.SSAA)
            {
                PPXDepthEngine.InitScreenTargets();
            }
        }
Пример #9
0
        public void DrawImmediate(_2DStandaloneSprite sprite)
        {
            var effect = this.Effect;

            if (!FSOEnvironment.DirectX)
            {
                Device.Indices = null; //monogame why
                Device.Indices = SpriteIndices;
            }
            PPXDepthEngine.RenderPPXDepth(effect, false, (depth) =>
            {
                effect.pixelTexture = sprite.Pixel;
                if (sprite.Depth != null)
                {
                    effect.depthTexture = sprite.Depth;
                }
                if (sprite.Mask != null)
                {
                    effect.maskTexture = sprite.Mask;
                }

                EffectPassCollection passes = effect.CurrentTechnique.Passes;

                EffectPass pass = passes[Math.Min(passes.Count - 1, WorldConfig.Current.DirPassOffset)];
                pass.Apply();
                if (sprite.GPUVertices != null)
                {
                    Device.SetVertexBuffer(sprite.GPUVertices);
                    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2);
                }
            });
        }
Пример #10
0
        /// <summary>
        /// Ends rendering, should always be called after DrawMesh()!
        /// </summary>
        public void End()
        {
            if (Sprites.Count == 0)
            {
                return;
            }
            //Device.RasterizerState.CullMode = CullMode.CullCounterClockwiseFace;

            var character = Sprites.Where(x => x.Effect == _3DSpriteEffect.CHARACTER).ToList();
            var pass      = WorldConfig.Current.PassOffset * 2;

            PPXDepthEngine.RenderPPXDepth(Avatar.Effect, true, (depth) =>
            {
                RenderSpriteList(character, Avatar.Effect, Avatar.Effect.Techniques[OBJIDMode ? 1 : pass]);
            });

            /*
             * ApplyCamera(Effect);
             * Effect.World = world;
             * Effect.TextureEnabled = true;
             * Effect.Texture = binding.Texture;
             * Effect.CommitChanges();
             *
             * Effect.Begin();
             * foreach (var pass in Effect.CurrentTechnique.Passes)
             * {
             *  pass.Begin();
             *  binding.Mesh.Draw(Device);
             *  pass.End();
             * }
             * Effect.End();*/
        }
Пример #11
0
        public override void PreDraw(GraphicsDevice device)
        {
            if (HasInit == false)
            {
                return;
            }

            var boundfactor = 0.5f;

            boundfactor *= Blueprint?.Width ?? 64;
            var off  = 0.5f * (Blueprint?.Width ?? 64);
            var tile = State.CenterTile;

            tile = new Vector2(Math.Min(boundfactor + off, Math.Max(off - boundfactor, tile.X)), Math.Min(boundfactor + off, Math.Max(off - boundfactor, tile.Y)));
            if (tile != State.CenterTile)
            {
                State.CenterTile = tile;
            }

            State._2D.PreciseZoom = State.PreciseZoom;
            State.OutsideColor    = Blueprint.OutsideColor;
            FSO.Common.Rendering.Framework.GameScreen.ClearColor = new Color(State.OutsideColor.ToVector4()); //new Color(0x72, 0x72, 0x72).ToVector4() *

            var frustrum = new BoundingFrustum(State.Camera.View * State.Camera.Projection);

            foreach (var sub in Blueprint.SubWorlds)
            {
                var bounds = ((SubWorldComponentRC)sub).Bounds;
                if (bounds.Intersects(frustrum))
                {
                    sub.PreDraw(device, State);
                }
            }
            State.UpdateInterpolation();
            if (Blueprint != null)
            {
                foreach (var ent in Blueprint.Objects)
                {
                    ent.Update(null, State);
                }
            }

            //For all the tiles in the dirty list, re-render them
            State.PrepareLighting();
            _2DWorld.PreDraw(device, State);
            device.SetRenderTarget(null);

            State._3D.Begin(device);
            _3DWorld.PreDraw(device, State);
            State._3D.End();

            if (UseBackbuffer)
            {
                PPXDepthEngine.SetPPXTarget(null, null, true, State.OutsideColor);
                InternalDraw(device);
                device.SetRenderTarget(null);
            }
            return;
        }
Пример #12
0
        /// <summary>
        /// Processes the accumulated draw commands and paints the screen. Optionally outputs to a vertex cache.
        /// </summary>
        public void End(List <_2DDrawBuffer> cache, bool outputDepth)
        {
            if (WorldCamera == null)
            {
                return;
            }
            var effect = this.Effect;

            if (cache == null)
            {
                Device.BlendState = BlendState.AlphaBlend;
                //  set the only parameter this effect takes.
                var frontDir = FrontDirForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation);
                effect.Parameters["dirToFront"].SetValue(frontDir);
                effect.Parameters["offToBack"].SetValue(BackOffForRot(((FSO.LotView.Utils.WorldCamera)WorldCamera).Rotation));
                //frontDir /= 3;
                //WorldContent._2DWorldBatchEffect.Parameters["LightOffset"].SetValue(new Vector2(frontDir.X / (6 * 75), frontDir.Z / (6 * 75)));
                var mat = this.WorldCamera.View * this.WorldCamera.Projection;
                effect.Parameters["worldViewProjection"].SetValue(mat);
                var inv = Matrix.Invert(mat);
                effect.Parameters["iWVP"].SetValue(inv);
                effect.Parameters["rotProjection"].SetValue(((WorldCamera)this.WorldCamera).GetRotationMatrix() * this.WorldCamera.Projection);
                //effect.Parameters["depthOutMode"].SetValue(outputDepth && (!FSOEnvironment.UseMRT));
            }

            if (Sprites.Count == 0)
            {
                return;
            }
            int i = 0;

            foreach (var sprites in Sprites)
            {
                if (cache != null)
                {
                    if (i >= cache.Count)
                    {
                        cache.Add(new _2DDrawBuffer());
                    }
                    EndDrawSprites(sprites, cache[i].Groups, outputDepth);
                }
                else
                {
                    var temp = new _2DDrawBuffer();
                    EndDrawSprites(sprites, temp.Groups, OutputDepth);
                    PPXDepthEngine.RenderPPXDepth(effect, false, (depth) =>
                    {
                        RenderCache(new List <_2DDrawBuffer> {
                            temp
                        });
                        //EndDrawSprites(sprites, null, OutputDepth);
                    });
                    temp.Dispose();
                }
                i++;
            }
        }
Пример #13
0
 public override void Dispose()
 {
     Batch.Pause();
     Batch.OutputDepth = false;
     PPXDepthEngine.SetPPXTarget(null, null, false); //need to unbind both before we can extract their textures.
     ExtractPixelTexture();
     ExtractDepthTexture();
     Batch.Resume();
 }
Пример #14
0
        public void GameResized()
        {
            PPXDepthEngine.InitScreenTargets();
            var newSize = PPXDepthEngine.GetWidthHeight();

            State._2D.GenBuffers(newSize.X, newSize.Y);
            State.SetDimensions(newSize.ToVector2());

            Blueprint?.Damage.Add(new BlueprintDamage(BlueprintDamageType.ZOOM));
        }
Пример #15
0
        public void ResizeBuffer(int bufferIndex, int width, int height)
        {
            var buffer = Buffers[bufferIndex];

            if (buffer.Width != width || buffer.Height != height)
            {
                Buffers[bufferIndex] = PPXDepthEngine.CreateRenderTarget(Device, 1, 0, buffer.Format, width, height, buffer.DepthStencilFormat);
                buffer.Dispose();
            }
        }
Пример #16
0
        public void GameResized()
        {
            PPXDepthEngine.InitScreenTargets();
            var newSize = PPXDepthEngine.GetWidthHeight();
            var ssaa    = new Point(newSize.X / PPXDepthEngine.SSAA, newSize.Y / PPXDepthEngine.SSAA);

            State._2D.GenBuffers(ssaa.X, ssaa.Y);
            State.SetDimensions(ssaa.ToVector2());

            Blueprint?.Changes?.SetFlag(BlueprintGlobalChanges.ZOOM);
        }
Пример #17
0
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            device.RasterizerState = RasterizerState.CullNone;
            if (ShapeDirty)
            {
                RegenRoof(device);
                ShapeDirty = false;
                StyleDirty = false;
            }
            else if (StyleDirty)
            {
                RemeshRoof(device);
                StyleDirty = false;
            }

            for (int i = 0; i < Drawgroups.Length; i++)
            {
                if (i > world.Level - 1)
                {
                    return;
                }
                Effect.Parameters["Level"].SetValue((float)i + 1.0001f);
                if (Drawgroups[i] != null)
                {
                    var dg = Drawgroups[i];
                    if (dg.NumPrimitives == 0)
                    {
                        continue;
                    }
                    PPXDepthEngine.RenderPPXDepth(Effect, true, (depthMode) =>
                    {
                        world._3D.ApplyCamera(Effect);
                        Effect.Parameters["World"].SetValue(Matrix.Identity);
                        Effect.Parameters["DiffuseColor"].SetValue(new Vector4(world.OutsideColor.R / 255f, world.OutsideColor.G / 255f, world.OutsideColor.B / 255f, 1.0f));
                        Effect.Parameters["UseTexture"].SetValue(true);
                        Effect.Parameters["BaseTex"].SetValue(Texture);
                        Effect.Parameters["Alpha"].SetValue(1f);
                        Effect.Parameters["IgnoreColor"].SetValue(false);
                        Effect.Parameters["TexOffset"].SetValue(Vector2.Zero);
                        Effect.Parameters["TexMatrix"].SetValue(new Vector4(1, 0, 0, 1));

                        device.SetVertexBuffer(dg.VertexBuffer);
                        device.Indices = dg.IndexBuffer;

                        Effect.CurrentTechnique = Effect.Techniques["DrawBase"];
                        var pass = Effect.CurrentTechnique.Passes[(Common.FSOEnvironment.Enable3D && (world as RC.WorldStateRC)?.Use2DCam == false)?2:WorldConfig.Current.PassOffset];
                        pass.Apply();
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, dg.NumPrimitives);
                    });
                }
            }
        }
Пример #18
0
        public virtual bool NextPass()
        {
            if (Pass == 0)
            {
                Batch.Pause();
                PPXDepthEngine.SetPPXTarget(Target, null, true);
                Batch.Resume();

                Pass++;
                return(true);
            }
            return(false);
        }
Пример #19
0
        public override Vector2 GetScreenPos(WorldState world)
        {
            var projected = Vector4.Transform(new Vector4(0, 0, 0, 1f), this.World * world.Camera.View * world.Camera.Projection);

            if (world.Camera is WorldCamera)
            {
                projected.Z = 1;
            }
            var res1 = new Vector2(projected.X / projected.Z, -projected.Y / projected.Z);
            var size = PPXDepthEngine.GetWidthHeight();

            return(new Vector2((size.X / PPXDepthEngine.SSAA) * 0.5f * (res1.X + 1f), (size.Y / PPXDepthEngine.SSAA) * 0.5f * (res1.Y + 1f))); //world.WorldSpace.GetScreenFromTile(transhead) + world.WorldSpace.GetScreenOffset() + PosCenterOffsets[(int)world.Zoom - 1];
        }
Пример #20
0
        public override Vector2 GetScreenPos(WorldState world)
        {
            var headpos   = Avatar.Skeleton.GetBone("HEAD").AbsolutePosition;
            var projected = Vector4.Transform(new Vector4(headpos, 1), Matrix.CreateRotationY((float)(Math.PI - RadianDirection)) * this.World * world.View * world.Projection);

            if (world.CameraMode < CameraRenderMode._3D)
            {
                projected.Z = 1;
            }
            var res1 = new Vector2(projected.X / projected.Z, -projected.Y / projected.Z);
            var size = PPXDepthEngine.GetWidthHeight();

            return(new Vector2((size.X / PPXDepthEngine.SSAA) * 0.5f * (res1.X + 1f), (size.Y / PPXDepthEngine.SSAA) * 0.5f * (res1.Y + 1f))); //world.WorldSpace.GetScreenFromTile(transhead) + world.WorldSpace.GetScreenOffset() + PosCenterOffsets[(int)world.Zoom - 1];
        }
Пример #21
0
        public override void Draw(GraphicsDevice device, WorldState world)
        {
            if (ShapeDirty)
            {
                RegenRoof(device);
                ShapeDirty = false;
                StyleDirty = false;
            }
            else if (StyleDirty)
            {
                RemeshRoof(device);
                StyleDirty = false;
            }

            for (int i = 0; i < Drawgroups.Length; i++)
            {
                if (i > world.Level - 1)
                {
                    return;
                }
                Effect.Parameters["Level"].SetValue((float)i + 1);
                if (Drawgroups[i] != null)
                {
                    var dg = Drawgroups[i];
                    if (dg.NumPrimitives == 0)
                    {
                        continue;
                    }
                    PPXDepthEngine.RenderPPXDepth(Effect, true, (depthMode) =>
                    {
                        world._3D.ApplyCamera(Effect);
                        Effect.Parameters["World"].SetValue(Matrix.Identity);
                        Effect.Parameters["DiffuseColor"].SetValue(new Vector4(world.OutsideColor.R / 255f, world.OutsideColor.G / 255f, world.OutsideColor.B / 255f, 1.0f));
                        Effect.Parameters["UseTexture"].SetValue(true);
                        Effect.Parameters["BaseTex"].SetValue(Texture);

                        device.SetVertexBuffer(dg.VertexBuffer);
                        device.Indices = dg.IndexBuffer;

                        Effect.CurrentTechnique = Effect.Techniques["DrawBase"];
                        foreach (var pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, dg.NumPrimitives);
                        }
                    });
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Creates a UISpriteBatch. Same as spritebatch with some extra functionality
        /// required by the UI system of this game.
        ///
        /// NumBuffers refers to a number of RenderTarget2D objects to create up front.
        /// These should be used for temp rendering for special effects. E.g. rendering
        /// part of the GUI to a texture and then painting it with opacity onto the main
        /// target.
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="numBuffers">The number of rendering buffers to pre-alloc</param>
        public UISpriteBatch(GraphicsDevice gd, int numBuffers, int width, int height, int multisample)
            : base(gd)
        {
            _Width  = width;
            _Height = height;

            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(gd, 1, multisample, SurfaceFormat.Color, width, height, DepthFormat.None)
                    );
            }

            base.GraphicsDevice.DeviceReset += new EventHandler <EventArgs>(gd_DeviceReset);
        }
Пример #23
0
        private void gd_DeviceReset(object sender, EventArgs e)
        {
            Invalidated = true;

            Buffers.Clear();
            for (var i = 0; i < 3; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(base.GraphicsDevice, 1, 0, SurfaceFormat.Color,
                                                      Width, Height, DepthFormat.None)
                    );
            }

            Invalidated = false;
        }
Пример #24
0
        /// <summary>
        /// We will just take over the whole rendering of this scene :)
        /// </summary>
        /// <param name="device"></param>
        public override void Draw(GraphicsDevice device)
        {
            if (HasInit == false)
            {
                return;
            }

            if (FSOEnvironment.SoftwareDepth)
            {
                PPXDepthEngine.DrawBackbuffer();
                return;
            }

            InternalDraw(device);
        }
Пример #25
0
        public void GenBuffers(int bwidth, int bheight)
        {
            foreach (var buffer in Buffers)
            {
                buffer.Dispose();
            }
            Buffers.Clear();

            ResetMatrices(bwidth, bheight);

            ScreenWidth  = bwidth;
            ScreenHeight = bheight;

            for (var i = 0; i < NumBuffers; i++)
            {
                int width  = bwidth + ScrollBuffer;
                int height = bheight + ScrollBuffer;

                switch (i)
                {
                case 2:     //World2D.BUFFER_OBJID
                    width  = 1;
                    height = 1;
                    break;

                case 3:     //World2D.BUFFER_THUMB
                case 4:
                    width  = 1024;
                    height = 1024;
                    break;

                case 5:
                    width  = 576;
                    height = 576;
                    break;
                }

                if (NumBuffers == 2)
                {
                    width = height = 1024;                                                                          //special case, thumb only.
                }
                var depthformat = FSOEnvironment.SoftwareDepth ? DepthFormat.Depth24Stencil8 : DepthFormat.Depth24; //stencil is used for software depth
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(Device, 1, 0, SurfaceFormats[i], width, height,
                                                      (AlwaysDS[i] || (!FSOEnvironment.UseMRT && !FSOEnvironment.SoftwareDepth)) ? depthformat : DepthFormat.None)
                    );
            }
        }
Пример #26
0
        public _2DWorldBatch(GraphicsDevice device, int numBuffers, SurfaceFormat[] surfaceFormats, bool[] alwaysDS, int scrollBuffer)
        {
            this.Device = device;
            this.Effect = WorldContent._2DWorldBatchEffect;
            //TODO: World size
            Sprites = new List <_2DSpriteGroup>();

            ScrollBuffer = scrollBuffer;

            ResetMatrices(device.Viewport.Width, device.Viewport.Height);

            ScreenWidth  = device.Viewport.Width;
            ScreenHeight = device.Viewport.Height;

            for (var i = 0; i < numBuffers; i++)
            {
                int width  = device.Viewport.Width + scrollBuffer;
                int height = device.Viewport.Height + scrollBuffer;

                switch (i)
                {
                case 4:     //World2D.BUFFER_OBJID
                    width  = 1;
                    height = 1;
                    break;

                case 0:     //World2D.BUFFER_THUMB
                case 10:
                    width  = 1024;
                    height = 1024;
                    break;

                case 11:
                    width  = 1024;
                    height = 1024;
                    break;
                }
                if (numBuffers == 2 && i == 1)
                {
                    width = height = 1024;                            //special case, thumb only.
                }
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(device, 1, 0, surfaceFormats[i], width, height,
                                                      (alwaysDS[i] || (!FSOEnvironment.UseMRT && !FSOEnvironment.SoftwareDepth))?DepthFormat.Depth24Stencil8:DepthFormat.None)
                    );
            }
        }
Пример #27
0
        /// <summary>
        /// Pre-Draw
        /// </summary>
        /// <param name="device"></param>
        public override void PreDraw(GraphicsDevice device)
        {
            base.PreDraw(device);
            if (HasInit == false)
            {
                return;
            }
            BoundView();
            State._2D.PreciseZoom = State.PreciseZoom;
            State.OutsideColor    = Blueprint.OutsideColor;
            FSO.Common.Rendering.Framework.GameScreen.ClearColor = new Color(new Color(0x72, 0x72, 0x72).ToVector4() * State.OutsideColor.ToVector4());
            foreach (var sub in Blueprint.SubWorlds)
            {
                sub.PreDraw(device, State);
            }
            State.UpdateInterpolation();
            if (Blueprint != null)
            {
                foreach (var ent in Blueprint.Objects)
                {
                    ent.Update(null, State);
                }
            }

            //For all the tiles in the dirty list, re-render them
            //PPXDepthEngine.SetPPXTarget(null, null, true);
            State.PrepareLighting();
            State._2D.Begin(this.State.Camera);
            _2DWorld.PreDraw(device, State);
            device.SetRenderTarget(null);
            State._2D.End();

            State._3D.Begin(device);
            _3DWorld.PreDraw(device, State);
            State._3D.End();

            if (UseBackbuffer)
            {
                PPXDepthEngine.SetPPXTarget(null, null, true);
                InternalDraw(device);
                device.SetRenderTarget(null);
            }

            return;
        }
Пример #28
0
        /// <summary>
        /// We will just take over the whole rendering of this scene :)
        /// </summary>
        /// <param name="device"></param>
        public override void Draw(GraphicsDevice device)
        {
            if (HasInit == false)
            {
                return;
            }

            FrameCounter++;
            if (FrameCounter < LastCacheClear + 60 * 60)
            {
                State._2D.ClearTextureCache();
            }
            if (!UseBackbuffer)
            {
                InternalDraw(device);
            }
            else
            {
                PPXDepthEngine.DrawBackbuffer(Opacity);
            }
            return;
        }
Пример #29
0
        public void ResizeBuffer(int width, int height)
        {
            _Width  = width;
            _Height = height;

            var numBuffers = AllBuffers.Count;

            foreach (var buf in AllBuffers)
            {
                buf.Dispose();
            }

            Buffers.Clear();
            AllBuffers.Clear();
            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(base.GraphicsDevice, 1, 0, SurfaceFormat.Color,
                                                      Width, Height, DepthFormat.None)
                    );
            }
            AllBuffers = new List <RenderTarget2D>(Buffers);
        }
Пример #30
0
        public override void ChangedWorldConfig(GraphicsDevice gd)
        {
            base.ChangedWorldConfig(gd);
            switch (WorldConfig.Current.AA)
            {
            case 1:
                PPXDepthEngine.MSAA = 4;
                PPXDepthEngine.SSAA = 1;
                break;

            case 2:
                PPXDepthEngine.SSAA = 2;
                PPXDepthEngine.MSAA = 0;
                break;

            default:
                PPXDepthEngine.MSAA = 0;
                PPXDepthEngine.SSAA = 1;
                break;
            }
            PPXDepthEngine.InitScreenTargets();
            UseBackbuffer = WorldConfig.Current.AA > 0;
        }