Пример #1
0
 public void RenderLoop()
 {
     while (running)
     {
         try
         {
             if (resized)
             {
                 reset();
             }
             device.Clear(ClearFlags.Target, Color.Transparent, 0, 0);
             device.SetRenderState(RenderState.AlphaBlendEnable, true);
             device.SetRenderState(RenderState.CullMode, Cull.Clockwise);
             device.BeginScene();
             fontRenderer.Begin();
             textureRenderer.Begin();
             try
             {
                 Render.SafeInvoke();
             }
             finally
             {
                 textureRenderer.End();
                 fontRenderer.End();
                 device.EndScene();
                 device.Present();
             }
         }
         catch (SharpDXException) { }
     }
     renderLocker.Set();
 }
Пример #2
0
        private void display()
        {
            stopwatch.Start();

            advectVelocity(g_dvfield, g_vxfield, g_vyfield, DIM, RPADW, DIM, DT, g_tPitch);

            {
                g_planr2c.Exec(g_vxfield.DevicePointer);
                g_planr2c.Exec(g_vyfield.DevicePointer);

                diffuseProject(g_vxfield, g_vyfield, CPADW, DIM, DT, VIS, g_tPitch);

                g_planc2r.Exec(g_vxfield.DevicePointer);
                g_planc2r.Exec(g_vyfield.DevicePointer);
            }
            updateVelocity(g_dvfield, g_vxfield, g_vyfield, DIM, RPADW, DIM, g_tPitch);

            // Map D3D9 vertex buffer to CUDA
            {
                graphicsres.MapAllResources();
                g_mparticles = graphicsres[0].GetMappedPointer <vertex>();
                advectParticles(g_mparticles, g_dvfield, DIM, DIM, DT, g_tPitch);
                graphicsres.UnmapAllResources();
            }

            device.Clear(ClearFlags.Target, new Color4(0.0f, 0, 0), 0.0f, 0);
            device.SetRenderState(RenderState.ZWriteEnable, false);
            device.SetRenderState(RenderState.AlphaBlendEnable, true);
            device.SetRenderState(RenderState.SourceBlend, Blend.One);
            device.SetRenderState(RenderState.DestinationBlend, Blend.One);
            device.SetRenderState(RenderState.PointSpriteEnable, true);
            float size = 16.0f;

            device.SetRenderState(RenderState.PointSize, size);
            device.SetTexture(0, g_pTexture);

            if (device.BeginScene().IsSuccess)
            {
                Result res;
                //Draw particles
                res = device.SetStreamSource(0, g_pVB, 0, Marshal.SizeOf(typeof(vertex)));
                device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
                res = device.DrawPrimitives(PrimitiveType.PointList, 0, DS);
                device.EndScene();
            }
            stopwatch.Stop();

            device.Present();
            fpsCount++;

            if (fpsCount == fpsLimit)
            {
                float  ifps = 1.0f / (stopwatch.GetElapsedTime() / 1000.0f);
                string fps  = string.Format(System.Globalization.CultureInfo.InvariantCulture, "CUDA/D3D9 Stable Fluids ({0} x {1}): {2} fps", DIM, DIM, ifps);
                this.Text = fps;
                fpsCount  = 0;
                fpsLimit  = (int)Math.Max(ifps, 1.0f);
            }
        }
Пример #3
0
        /// <summary>
        /// Renders the entire scene.
        /// </summary>
        /// <param name="doWaitForNextFame"><c>true</c>, if this method should wait to the correct frame start time
        /// before it renders, else <c>false</c>.</param>
        /// <returns><c>true</c>, if the caller should wait some milliseconds before rendering the next time.</returns>
        public static bool Render(bool doWaitForNextFame)
        {
            if (_device == null || !_deviceOk)
            {
                return(true);
            }
#if (MAX_FRAMERATE == false)
            if (doWaitForNextFame)
            {
                WaitForNextFrame();
            }
#endif
            _frameRenderingStartTime = DateTime.Now;
            _renderAndResourceAccessLock.EnterReadLock();
            try
            {
                _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
                _device.BeginScene();

                _screenManager.Render();

                _device.EndScene();
                _device.PresentEx(_setup.Present);

                _fpsCounter += 1;
                TimeSpan ts = DateTime.Now - _fpsTimer;
                if (ts.TotalSeconds >= 1.0f)
                {
                    float secs = (float)ts.TotalSeconds;
                    SkinContext.FPS = _fpsCounter / secs;
#if PROFILE_FRAMERATE
                    ServiceRegistration.Get <ILogger>().Debug("RenderLoop: {0} frames per second, {1} total frames until last measurement", SkinContext.FPS, _fpsCounter);
#endif
                    _fpsCounter = 0;
                    _fpsTimer   = DateTime.Now;
                }
                ContentManager.Instance.Clean();
            }
            catch (Direct3D9Exception e)
            {
                DeviceState state = CheckDeviceState();
                ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: DirectX Exception, DeviceState: {0}", e, state);
                _deviceOk = state == DeviceState.Ok;
                return(!_deviceOk);
            }
            finally
            {
                _renderAndResourceAccessLock.ExitReadLock();
            }
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Renders the entire scene.
        /// </summary>
        /// <param name="doWaitForNextFame"><c>true</c>, if this method should wait to the correct frame start time
        /// before it renders, else <c>false</c>.</param>
        /// <returns><c>true</c>, if the caller should wait some milliseconds before rendering the next time.</returns>
        public static bool Render(bool doWaitForNextFame)
        {
            if (_device == null || !_deviceOk)
            {
                return(true);
            }

            RenderStrategy.BeginRender(doWaitForNextFame);

            _renderAndResourceAccessLock.EnterReadLock();
            try
            {
                _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
                _device.BeginScene();

                Fire(DeviceSceneBegin);

                _screenManager.Render();

                Fire(DeviceSceneEnd);

                _device.EndScene();

                _device.PresentEx(RenderStrategy.PresentMode);

                Fire(DeviceScenePresented);

                ContentManager.Instance.Clean();
            }
            catch (Direct3D9Exception e)
            {
                DeviceState state = CheckDeviceState();
                ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: DirectX Exception, DeviceState: {0}", e, state);
                _deviceOk = state == DeviceState.Ok;
                return(!_deviceOk);
            }
            finally
            {
                _renderAndResourceAccessLock.ExitReadLock();
            }
            return(false);
        }
Пример #5
0
 public void Clear()
 {
     device.Clear(ClearFlags.Target, Color.Transparent, 0, 0);
     device.Present();
 }