Exemple #1
0
        private void RenderContent()
        {
            if (!IsVisible)
            {
                return;
            }

            if (_operator == null || _operator.Outputs.Count <= 0)
            {
                return;
            }

            if (TimeLoggingSourceEnabled)
            {
                TimeLogger.BeginFrame(App.Current.Model.GlobalTime);
            }

            D3DDevice.BeginFrame();

            try
            {
                var context = new OperatorPartContext(_defaultContext, (float)App.Current.Model.GlobalTime);

                // FIXME: the following lines are commented out to enable different values for debugOverlay-Variable
                //if (context.Time != _previousTime)
                //{
                var invalidator = new OperatorPart.InvalidateInvalidatables();
                _operator.Outputs[_shownOutputIndex].TraverseWithFunctionUseSpecificBehavior(null, invalidator);
                //_previousTime = context.Time;
                //}

                var evaluationType = _operator.Outputs[_shownOutputIndex].Type;
                switch (evaluationType)
                {
                case FunctionType.Scene:
                case FunctionType.Mesh:
                    _renderSetup.Operator = _operator;
                    var isMeshType = evaluationType == FunctionType.Mesh;
                    _renderSetup.Render(context, _shownOutputIndex, ShowGridAndGizmos, isMeshType);
                    _D3DImageContainer.InvalidateD3DImage();
                    break;

                case FunctionType.Image:
                    _renderSetup.Operator = _operator;
                    _renderSetup.RenderImage(context, _shownOutputIndex);
                    _D3DImageContainer.InvalidateD3DImage();
                    break;
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception.ToString());
            }

            D3DDevice.EndFrame();
            if (TimeLoggingSourceEnabled)
            {
                TimeLogger.EndFrame();
            }
        }
Exemple #2
0
        private void Update()
        {
            var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES));

            if (time >= _soundLength)
            {
                if (_settings.Looped)
                {
                    Bass.BASS_ChannelSetPosition(_soundStream, 0);
                }
                else if (!_exitTimer.IsRunning)
                {
                    _exitTimer.Restart();
                }
                else if (_exitTimer.ElapsedMilliseconds >= 2000)
                {
                    _form.Close();
                }
            }

//            try {
//                _undoRedoStack.ProcessReceivedCommands();
//            }
//            catch (Exception exception) {
//                Logger.Warn("Error when excecuting remote command: {0}", exception.Message);
//            }

            //double time = (double)_globalTime.ElapsedTicks / Stopwatch.Frequency;
            TimeLogger.BeginFrame(time);
            D3DDevice.BeginFrame();

            DrawFrame((float)time);

            D3DDevice.SwapChain.Present(_settings.VSyncEnabled ? 1 : 0, PresentFlags.None);

            Int64 elapsedTicks = _stopwatch.ElapsedTicks;

            Console.Write("time: {0:000.000}, fps: {1:000.0} ({2:000.0}/{3:000.0}), resources used: {4,2}, free: {5,2}      \r",
                          time, (double)_numMeasureValues * Stopwatch.Frequency / _averagedElapsed.Sum(e => e), (double)Stopwatch.Frequency / _averagedElapsed.Max(), (double)Stopwatch.Frequency / _averagedElapsed.Min(),
                          ResourceManager.NumUsedResources, ResourceManager.NumFreeResources);
            _averagedElapsed[_currentAveragedElapsedIndex] = elapsedTicks;
            _currentAveragedElapsedIndex++;
            _currentAveragedElapsedIndex %= _numMeasureValues;
            _stopwatch.Restart();

            D3DDevice.EndFrame();
            TimeLogger.EndFrame();
        }
        public void RenderContent()
        {
            if (RenderConfig.Operator == null || RenderConfig.Operator.Outputs.Count <= 0)
            {
                return;
            }

            D3DDevice.BeginFrame();

            try
            {
                var context = new OperatorPartContext(
                    _defaultContext,
                    (float)(App.Current.Model.GlobalTime + RenderConfig.TimeScrubOffset));

                var invalidator = new OperatorPart.InvalidateInvalidatables();
                RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].TraverseWithFunctionUseSpecificBehavior(null, invalidator);

                var evaluationType = RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].Type;

                switch (evaluationType)
                {
                case FunctionType.Float:
                    RenderValuePlot(context, RenderConfig);
                    break;

                case FunctionType.Scene:
                    Action <OperatorPartContext, int> lambdaForScenes = (OperatorPartContext context2, int outputIdx) =>
                    {
                        RenderConfig.Operator.Outputs[outputIdx].Eval(context);
                    };
                    RenderGeometry(
                        context,
                        lambdaForScenes);

                    break;

                case FunctionType.Mesh:
                {
                    Action <OperatorPartContext, int> lambdaForMeshes = (OperatorPartContext context2, int outputIdx) =>
                    {
                        var mesh = RenderConfig.Operator.Outputs[outputIdx].Eval(context2).Mesh;
                        context2.Renderer.SetupEffect(context2);
                        context2.Renderer.Render(mesh, context2);
                    };
                    RenderGeometry(
                        context,
                        lambdaForMeshes);
                    break;
                }

                case FunctionType.Image:
                    SetupContextForRenderingImage(
                        context,
                        RenderConfig.RenderWithGammaCorrection);

                    var image = RenderConfig.Operator.Outputs[RenderConfig.ShownOutputIndex].Eval(new OperatorPartContext(context)).Image;
                    if (image == null)
                    {
                        break;
                    }

                    RenderedImageIsACubemap = image.Description.ArraySize > 1;
                    var cubeMapSide = RenderedImageIsACubemap ? RenderConfig.PreferredCubeMapSideIndex : -1;
                    if (cubeMapSide == 6)
                    {
                        RenderCubemapAsSphere(image, context);
                    }
                    else
                    {
                        RenderImage(image, context);
                    }
                    break;
                }
                _D3DImageContainer.InvalidateD3DImage();
            }
            catch (Exception exception)
            {
                Logger.Error(exception.ToString());
            }
            D3DDevice.EndFrame();
        }
Exemple #4
0
        private void UpdateLocalShownContent()
        {
            //if (_showSceneControl == null)
            //    return;
            //var op = _showSceneControl.Operator;
            //var d3DScene = _showSceneControl.RenderSetup;
            if (_renderConfig == null || _renderConfig.Operator == null || _renderConfig.Operator.Outputs.Count <= 0)
            {
                return;
            }

            //var op = d3DScene.RenderedOperator;
            var op = _renderConfig.Operator;

            D3DDevice.WindowSize  = new SharpDX.Size2(Size.Width, Size.Height);
            D3DDevice.TouchWidth  = Size.Width;
            D3DDevice.TouchHeight = Size.Height;

            TimeLogger.BeginFrame(CurrentTime);
            D3DDevice.BeginFrame();

            ProcessKeyEvents();

            try
            {
                var context = new OperatorPartContext(_defaultContext, (float)CurrentTime);

                if (Math.Abs(context.Time - _previousTime) > Constants.Epsilon)
                {
                    var invalidator = new OperatorPart.InvalidateInvalidatables();
                    op.Outputs[0].TraverseWithFunctionUseSpecificBehavior(null, invalidator);
                    _previousTime = context.Time;
                }

                context.D3DDevice         = D3DDevice.Device;
                context.RenderTargetView  = _renderTargetView;
                context.DepthStencilState = _renderer.DefaultDepthStencilState;
                context.BlendState        = _renderer.DefaultBlendState;
                context.RasterizerState   = _renderer.DefaultRasterizerState;
                context.SamplerState      = _renderer.DefaultSamplerState;
                context.Viewport          = _viewport;
                context.Texture0          = _shaderResourceView;

                var worldToCamera = Matrix.LookAtLH(_renderConfig.CameraSetup.Position, _renderConfig.CameraSetup.Target, _renderConfig.CameraSetup.UpDir);

                switch (op.FunctionType)
                {
                case FunctionType.Scene:
                    context.Effect           = _renderer.SceneDefaultEffect;
                    context.InputLayout      = _renderer.SceneDefaultInputLayout;
                    context.DepthStencilView = _depthStencilView;

                    D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera);

                    op.Outputs[0].Eval(context);
                    break;

                case FunctionType.Image:
                    context.Effect           = _renderer.ScreenRenderEffect;
                    context.InputLayout      = _renderer.ScreenQuadInputLayout;
                    context.DepthStencilView = null;

                    D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera);

                    var image = op.Outputs[0].Eval(new OperatorPartContext(context)).Image;
                    if (image != null)
                    {
                        _renderer.SetupBaseEffectParameters(context);
                        _renderer.RenderToScreen(image, context);
                    }
                    break;
                }

                _swapChain.Present(1, PresentFlags.None);
                D3DDevice.EndFrame();
                TimeLogger.EndFrame();
            }
            catch (Exception exception)
            {
                Logger.Error("Exception while in fullscreen:\n", exception.ToString());
            }
        }
Exemple #5
0
        private void Update()
        {
            var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES));

            if (time >= _soundLength)
            {
                if (_settings.Looped)
                {
                    Bass.BASS_ChannelSetPosition(_soundStream, 0);
                }
                else
                {
                    _form.Close();
                }
            }

//            try {
//                _undoRedoStack.ProcessReceivedCommands();
//            }
//            catch (Exception exception) {
//                Logger.Warn("Error when excecuting remote command: {0}", exception.Message);
//            }

            //double time = (double)_globalTime.ElapsedTicks / Stopwatch.Frequency;
            _model.GlobalTime = time;
            TimeLogger.BeginFrame(time);
            D3DDevice.BeginFrame();

//            ResourceManager.CheckResources();

            D3DDevice.Device.ImmediateContext.ClearDepthStencilView(_renderTargetDepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
            D3DDevice.Device.ImmediateContext.ClearRenderTargetView(_renderTargetView, new SharpDX.Color4(0.0f, 0.0f, 0.0f, 1.0f));
            D3DDevice.Device.ImmediateContext.InputAssembler.InputLayout = _renderer.SceneDefaultInputLayout;

            //invalidate all time accessors
            var invalidator = new OperatorPart.InvalidateInvalidatables();

            _model.HomeOperator.Outputs[0].TraverseWithFunctionUseSpecificBehavior(null, invalidator);

            var context = new OperatorPartContext(_defaultContext, (float)_model.GlobalTime);

            context.D3DDevice         = D3DDevice.Device;
            context.Effect            = _renderer.SceneDefaultEffect;
            context.InputLayout       = _renderer.SceneDefaultInputLayout;
            context.RenderTargetView  = _renderTargetView;
            context.DepthStencilView  = _renderTargetDepthView;
            context.DepthStencilState = _renderer.DefaultDepthStencilState;
            context.BlendState        = _renderer.DefaultBlendState;
            context.BlendFactor       = _renderer.DefaultBlendFactor;
            context.RasterizerState   = _renderer.DefaultRasterizerState;
            context.SamplerState      = _renderer.DefaultSamplerState;
            context.Viewport          = _viewport;
            context.Texture0          = _texture;

            _model.HomeOperator.Outputs[0].Eval(context);

            D3DDevice.SwapChain.Present(_settings.VSyncEnabled ? 1 : 0, PresentFlags.None);

            Int64 elapsedTicks = _stopwatch.ElapsedTicks;

            Console.Write("time: {0:000.000}, fps: {1:000.0} ({2:000.0}/{3:000.0}), resources used: {4,2}, free: {5,2}      \r",
                          time, (double)_numMeasureValues * Stopwatch.Frequency / _averagedElapsed.Sum(e => e), (double)Stopwatch.Frequency / _averagedElapsed.Max(), (double)Stopwatch.Frequency / _averagedElapsed.Min(),
                          ResourceManager.NumUsedResources, ResourceManager.NumFreeResources);
            _averagedElapsed[_currentAveragedElapsedIndex] = elapsedTicks;
            _currentAveragedElapsedIndex++;
            _currentAveragedElapsedIndex %= _numMeasureValues;
            _stopwatch.Restart();

            D3DDevice.EndFrame();
            TimeLogger.EndFrame();
        }
Exemple #6
0
        public void Precalc()
        {
            Logger.Info("Precalculating ...");

            var pv = new ProgressVisualizer(_form, D3DDevice.Device, D3DDevice.SwapChain);

            pv.Update(0.0f);

            MetaManager.InitializeCallback = progress => pv.Update(_operatorLoadEndProgress * progress);
            MetaManager.Instance.LoadMetaOperators();

            _model = new Model();

            //replace the measure operator by nop to remove render flush calls
            var script = @"using System;
                           using System.Collections.Generic;
                           namespace Framefield.Core.IDca9a3a0e_c1c7_42b6_a0e5_cdb4c61d0b18
                           {
                               public class Class_Group : OperatorPart.Function
                               {
                                   public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)
                                   {
                                       foreach (var input in inputs[0].Connections) input.Eval(context);
                                       return context;
                                   }
                               }
                           }";

            var measureMetaOp = _model.MetaOpManager.GetMetaOperator(Guid.Parse("86580803-34fe-40a8-8dbf-9197dedb889c"));

            if (measureMetaOp != null)
            {
                var measureMetaOpPart = measureMetaOp.OperatorParts[0].Item2;
                measureMetaOpPart.Version = Guid.NewGuid();
                measureMetaOpPart.Script  = script;
                measureMetaOpPart.Compile();
            }

            //replace lightswidgets op by nop
            var lightWidgetsMetaOp = _model.MetaOpManager.GetMetaOperator(Guid.Parse("86b0f0e1-5c9f-430e-8086-abadbf26866c"));

            if (lightWidgetsMetaOp != null)
            {
                var lightWidgetsMetaOpPart = lightWidgetsMetaOp.OperatorParts[0].Item2;
                lightWidgetsMetaOpPart.Version = Guid.NewGuid();
                lightWidgetsMetaOpPart.Script  = script;
                lightWidgetsMetaOpPart.Compile();
            }

            //update everything
            var context = GetNewContext();

            var statisticsCollector = new StatisticsCollector();

            _model.HomeOperator.Outputs[0].TraverseWithFunction(statisticsCollector, null);
            int totalNumOpParts     = statisticsCollector.NumTotalOpParts;
            int totalNumEvaluations = statisticsCollector.NumTotalEvaluations;

            var initialEvaluator = new InitialEvaluator(totalNumOpParts, context, pv, _operatorLoadEndProgress, _preCacheStartProgress - _operatorLoadEndProgress);

            _model.HomeOperator.Outputs[0].TraverseWithFunction(initialEvaluator, null);

            var timeClipEvaluator = new TimeClipEvaluator();

            _model.HomeOperator.Outputs[0].TraverseWithFunction(timeClipEvaluator, null);

            _model.HomeOperator.Outputs[0].MarkInvalidatables();
            OperatorPart.HasValidInvalidationMarksOnOperatorPartsForTraversing = true;

            if (_settings.PreCacheEnabled)
            {
                // draw the first, last and center frame of each TimeClip
                // in reverse order to warm up caches
                var preCacheTimes = timeClipEvaluator.GetResult();
                int i             = 0;
                foreach (double t in preCacheTimes)
                {
                    Logger.Debug("pre-rendering frame at t={0}", t);
                    D3DDevice.BeginFrame();
                    DrawFrame((float)t);
                    D3DDevice.EndFrame();
                    i++;
                    pv.Update(_preCacheStartProgress + (1.0f - _preCacheStartProgress) * i / preCacheTimes.Count);
                }
            }

            pv.Dispose();

            Logger.Info("Statistics: number of operator parts: {0}, total evaluations: {1}, number of time accessors: {2}",
                        totalNumOpParts, totalNumEvaluations, _timeAccessorOpPartFunctions.Count);

//            ResourceManager.DisposeAll();
        }