Exemple #1
0
        protected override void Present(XnaTime time)
        {
            var milliseconds = time.ElapsedGameTime.Milliseconds;

            _dt = milliseconds / 1000.0f;
            _sun.Update(time.ElapsedGameTime);

            var device = Graphics.GraphicsDevice;

            if (_usePostProcessor)
            {
                device.SetRenderTarget(0, _tempBuffer);

                device.Clear(
                    options: ClearOptions.Target,
                    color: Color.TransparentBlack,
                    depth: 1.0f,
                    stencil: 0);

                _sun.Render();
                _postProcessor.ToneMap(_tempBuffer, BackBuffer, _dt, false, true);
                device.SetRenderTarget(0, BackBuffer);
            }
            else
            {
                device.Clear(
                    options: ClearOptions.Target,
                    color: Color.TransparentBlack,
                    depth: 1.0f,
                    stencil: 0);

                _sun.Render();
            }
        }
Exemple #2
0
        private void Present()
        {
            var time = _stopwatch.ElapsedMilliseconds;

            _dt       = (time - _lastTime) / 1000.0f;
            _lastTime = time;

            if (_lastTime != 0L)
            {
                _sun.Update(TimeSpan.FromSeconds(_dt));
            }

            if (_device.GraphicsDeviceStatus != GraphicsDeviceStatus.Normal)
            {
                while (_device.GraphicsDeviceStatus == GraphicsDeviceStatus.Lost)
                {
                    Thread.Sleep(1);
                }

                Reset();
                return;
            }

            // Do resize
            if (_needResize)
            {
                _needResize = false;

                var backupFrontBuffer = _frontBuffer;
                var backupBackBuffer  = _backBuffer;
                var backupTempBuffer  = _tempBuffer;

                CreateBuffers();

                backupFrontBuffer.Dispose();
                backupBackBuffer.Dispose();
                backupTempBuffer.Dispose();

                return;
            }

            _device.SetRenderTarget(0, _backBuffer);

            Clear();

            _sun.Render(this.StarType);

            if (_usePostProcessor)
            {
                _postProcessor.ToneMap(_backBuffer, _tempBuffer, _dt, false, true);
                _copySurfaceMethod.Invoke(_device, new object[] { _tempBufferPointer, _frontBufferPointer });
            }
            else
            {
                _copySurfaceMethod.Invoke(_device, new object[] { _backBufferPointer, _frontBufferPointer });
            }

            //_copySurfaceMethod.Invoke(_device, new object[] { _backBufferPointer, _frontBufferPointer });

            _device.SetRenderTarget(0, null);

            try { _device.Present(); }
            catch (DeviceLostException) {}
        }