Exemplo n.º 1
0
        public void OnSceneBackBufferSizeChanged(int newWidth, int newHeight)
        {
            // dont recreate the mosaic unless we really need to
            if (_lastMosaicScale != _scene.PixelPerfectScale)
            {
                CreateMosaicTexture(_scene.PixelPerfectScale);
                _lastMosaicScale = _scene.PixelPerfectScale;
            }

            if (_mosaicRenderTex != null)
            {
                _mosaicRenderTex.Dispose();
                _mosaicRenderTex = RenderTarget.Create(newWidth * _scene.PixelPerfectScale,
                                                       newHeight * _scene.PixelPerfectScale, DepthFormat.None);
            }
            else
            {
                _mosaicRenderTex = RenderTarget.Create(newWidth * _scene.PixelPerfectScale,
                                                       newHeight * _scene.PixelPerfectScale, DepthFormat.None);
            }

            // based on the look of games by: http://deepnight.net/games/strike-of-rage/
            // use the mosaic to render to a full sized RenderTarget repeating the mosaic
            GraphicsDeviceExt.SetRenderTarget(Core.GraphicsDevice, _mosaicRenderTex);
            Graphics.Instance.Batcher.Begin(BlendState.Opaque, SamplerState.PointWrap, DepthStencilState.None,
                                            RasterizerState.CullNone);
            Graphics.Instance.Batcher.Draw(_mosaicTexture, Vector2.Zero,
                                           new Rectangle(0, 0, _mosaicRenderTex.Width, _mosaicRenderTex.Height), Color.White);
            Graphics.Instance.Batcher.End();

            // let our Effect know about our rendered, full screen mosaic
            _effect.Parameters["_secondTexture"].SetValue(_mosaicRenderTex);
        }
Exemplo n.º 2
0
 public void HandleFinalRender(RenderTarget2D finalRenderTarget, Color letterboxColor, RenderTarget2D source,
                               Rectangle finalRenderDestinationRect, SamplerState samplerState)
 {
     GraphicsDeviceExt.SetRenderTarget(Core.GraphicsDevice, finalRenderTarget);
     Core.GraphicsDevice.Clear(letterboxColor);
     Graphics.Instance.Batcher.Begin(BlendState.Opaque, samplerState, DepthStencilState.None,
                                     RasterizerState.CullNone, _effect);
     Graphics.Instance.Batcher.Draw(source, finalRenderDestinationRect, Color.White);
     Graphics.Instance.Batcher.End();
 }
Exemplo n.º 3
0
        public override void Process(RenderTarget2D source, RenderTarget2D destination)
        {
            // first we process the rendered layer with the bloom effect
            base.Process(_layerRT, _tempRT);

            // we need to be careful here and ensure we use AlphaBlending since the layer we rendered is mostly transparent
            GraphicsDeviceExt.SetRenderTarget(Core.GraphicsDevice, destination);
            Graphics.Instance.Batcher.Begin(BlendState.AlphaBlend, SamplerState, DepthStencilState.None,
                                            RasterizerState.CullNone);

            // now we first draw the full scene (source), then draw our bloomed layer (tempRT) then draw the un-bloomed layer (layerRT)
            Graphics.Instance.Batcher.Draw(source, new Rectangle(0, 0, destination.Width, destination.Height),
                                           Color.White);
            Graphics.Instance.Batcher.Draw(_tempRT, new Rectangle(0, 0, destination.Width, destination.Height),
                                           Color.White);
            Graphics.Instance.Batcher.Draw(_layerRT, new Rectangle(0, 0, destination.Width, destination.Height),
                                           Color.White);

            Graphics.Instance.Batcher.End();
        }
Exemplo n.º 4
0
        void IFinalRenderDelegate.HandleFinalRender(RenderTarget2D finalRenderTarget, Color letterboxColor,
                                                    RenderTarget2D source, Rectangle finalRenderDestinationRect,
                                                    SamplerState samplerState)
        {
            if (ShowSeperateGameWindow)
            {
                if (_lastRenderTarget != source)
                {
                    // unbind the old texture if we had one
                    if (_lastRenderTarget != null)
                    {
                        _renderer.UnbindTexture(_renderTargetId);
                    }

                    // bind the new texture
                    _lastRenderTarget = source;
                    _renderTargetId   = _renderer.BindTexture(source);
                }

                // we cant draw the game window until we have the texture bound so we append it here
                ImGui.Begin(_gameWindowTitle, _gameWindowFlags);
                ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Num.Vector2.Zero);
                ImGui.ImageButton(_renderTargetId, ImGui.GetContentRegionAvail());
                ImGui.PopStyleVar();
                ImGui.End();

                Core.GraphicsDevice.SamplerStates[0] = samplerState;
                GraphicsDeviceExt.SetRenderTarget(Core.GraphicsDevice, finalRenderTarget);
                Core.GraphicsDevice.Clear(letterboxColor);
            }
            else
            {
                GraphicsDeviceExt.SetRenderTarget(Core.GraphicsDevice, finalRenderTarget);
                Core.GraphicsDevice.Clear(letterboxColor);
                Graphics.Instance.Batcher.Begin(BlendState.Opaque, samplerState, null, null);
                Graphics.Instance.Batcher.Draw(source, finalRenderDestinationRect, Color.White);
                Graphics.Instance.Batcher.End();
            }

            _renderer.AfterLayout();
        }