Example #1
0
        private void Renderer_Rendering(Renderer renderer)
        {
            SharpDX.Direct3D9.Device device = renderer.Device;
            camera?.Render(device, ClientSize.Width, ClientSize.Height);

            Scene.Render(device);
        }
Example #2
0
        /// <summary>
        /// <para>この Activity を活性化(有効化)する。</para>
        /// <para>具体的には内部リソースの初期化などを行う。</para>
        /// </summary>
        public virtual void OnActivate(SharpDX.Direct3D9.Device D3D9Device)
        {
            if (this.bActivated)
            {
                return;
            }

            this.bActivated = true;             // このフラグは、以下の処理をする前にセットする。


            // 自身のリソースを作成する。

            this.OnManagedCreateResource(D3D9Device);
            this.OnUnmanagedCreateResources(D3D9Device);


            // すべての子Activityを活性化する。

            foreach (CActivity activity in this.listChildActivities)
            {
                activity.OnActivate(D3D9Device);
            }


            // その他

            this.bJustStartedUpdate = true;
        }
Example #3
0
        private SharpDX.Direct3D9.Texture CreateTextureForDecoder(SharpDX.Direct3D9.Device device, int width, int height, int levels, SharpDX.Direct3D9.Format format, SharpDX.Direct3D9.Usage usage)
        {
            var pool    = SharpDX.Direct3D9.Pool.Default;
            var texture = FTexturePool.GetTexture(EX9.Device.FromPointer(device.NativePointer), width, height, levels, (EX9.Usage)usage, (EX9.Format)format, (EX9.Pool)pool);

            return(new SharpDX.Direct3D9.Texture(texture.ComPointer));
        }
Example #4
0
        public GraphicsDevice( IWindow window )
        {
            d3d = new SharpDX.Direct3D9.Direct3D ();

            IntPtr handle = ( window.Handle as System.Windows.Forms.Form ).Handle;
            this.window = window;

            d3dpp = new SharpDX.Direct3D9.PresentParameters ( 800, 600, SharpDX.Direct3D9.Format.A8R8G8B8,
                    1, SharpDX.Direct3D9.MultisampleType.None, 0, SharpDX.Direct3D9.SwapEffect.Discard,
                    handle, true, true, SharpDX.Direct3D9.Format.D24S8, SharpDX.Direct3D9.PresentFlags.None,
                    0, SharpDX.Direct3D9.PresentInterval.Immediate );

            try
            {
                d3dDevice = new SharpDX.Direct3D9.Device ( d3d, 0, SharpDX.Direct3D9.DeviceType.Hardware,
                        handle, SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing,
                        d3dpp );
            }
            catch
            {
                d3dDevice = new SharpDX.Direct3D9.Device ( d3d, 0, SharpDX.Direct3D9.DeviceType.Hardware,
                        handle, SharpDX.Direct3D9.CreateFlags.SoftwareVertexProcessing,
                        d3dpp );
            }

            Information = new GraphicsDeviceInformation ( d3d );
            BackBuffer = new BackBuffer ( this );

            ImmediateContext = new GraphicsContext ( this );
            //window.Resize += ( object sender, EventArgs e ) => { ResizeBackBuffer ( ( int ) window.ClientSize.X, ( int ) window.ClientSize.Y ); };
        }
Example #5
0
        /// <summary>
        /// <para>Only draw。</para>
        /// <para>This method is called between BeginScene() and EndScene(). メソッド内でいきなり描画を行ってかまわない。</para>
        /// <para>ただし、Direct3D デバイスの変更は行ってはならない。</para>
        /// </summary>
        public virtual void OnDraw(SharpDX.Direct3D9.Device D3D9Device)
        {
            if (this.bNotActivated)
            {
                return;
            }

            /* ここで描画を行う。*/
        }
Example #6
0
        /// <summary>
        /// <p>Creates a DirectX Video Acceleration (DXVA) services object. Call this function if your application uses DXVA directly, without using DirectShow or Media Foundation. </p>
        /// </summary>
        /// <param name="dDRef"><dd> <p> A reference to the <strong><see cref="SharpDX.Direct3D9.Device"/></strong> interface of a Direct3D device. </p> </dd></param>
        /// <param name="riid"><dd> <p> The interface identifier (IID) of the requested interface. Any of the following interfaces might be supported by the Direct3D device: </p> <ul> <li> <strong><see cref="SharpDX.MediaFoundation.DirectX.VideoAccelerationService"/></strong> </li> <li> <strong><see cref="SharpDX.MediaFoundation.DirectX.VideoDecoderService"/></strong> </li> <li> <strong><see cref="SharpDX.MediaFoundation.DirectX.VideoProcessorService"/></strong> </li> </ul> </dd></param>
        /// <param name="serviceOut"><dd> <p> Receives a reference to the interface. The caller must release the interface. </p> </dd></param>
        /// <returns><p>If this function succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
        /// <include file='..\..\Documentation\CodeComments.xml' path="/comments/comment[@id='DXVA2CreateVideoService']/*"/>
        /// <msdn-id>ms704721</msdn-id>
        /// <unmanaged>HRESULT DXVA2CreateVideoService([In] IDirect3DDevice9* pDD,[In] const GUID&amp; riid,[Out] void** ppService)</unmanaged>
        /// <unmanaged-short>DXVA2CreateVideoService</unmanaged-short>
        public static void CreateVideoService(SharpDX.Direct3D9.Device dDRef, System.Guid riid, out System.IntPtr serviceOut)
        {
            unsafe {
                SharpDX.Result __result__;

                fixed(void *serviceOut_ = &serviceOut)
                __result__ =
                    DXVA2CreateVideoService_((void *)((dDRef == null)?IntPtr.Zero:dDRef.NativePointer), &riid, serviceOut_);

                __result__.CheckError();
            }
        }
Example #7
0
        /// <summary>
        /// <para>Unmanaged リソースの作成を行う。</para>
        /// <para>Direct3D デバイスが作成またはリセットされた直後に呼び出されるので、自分が活性化している時に限り、Unmanaged リソースを作成(または再構築)すること。</para>
        /// <para>いつどのタイミングで呼び出されるか(いつDirect3Dが再作成またはリセットされるか)分からないので、いつ何時呼び出されても問題無いようにコーディングしておくこと。</para>
        /// </summary>
        public virtual void OnUnmanagedCreateResources(SharpDX.Direct3D9.Device D3D9Device)
        {
            if (this.bNotActivated)
            {
                return;
            }


            // すべての 子Activity の Unmanaged リソースを作成する。

            foreach (CActivity activity in this.listChildActivities)
            {
                activity.OnUnmanagedCreateResources(D3D9Device);
            }
        }
Example #8
0
        /// <summary>
        /// <para>進行と描画を行う。(これらは分離されず、この1つのメソッドだけで実装する。)</para>
        /// <para>このメソッドは BeginScene() の後に呼び出されるので、メソッド内でいきなり描画を行ってかまわない。</para>
        /// <para>大体はSSTのOn進行とOn描画を合体させたようなものです。</para>
        /// </summary>
        /// <returns>任意の整数。呼び出し元との整合性を合わせておくこと。</returns>
        public virtual int OnUpdateAndDraw(SharpDX.Direct3D9.Device D3D9Device)
        {
            // 活性化してないなら何もしない。
            if (this.bNotActivated)
            {
                return(0);
            }


            /* ここで進行と描画を行う。*/


            // 戻り値とその意味は子クラスで自由に決めていい。
            return(0);
        }
Example #9
0
 /// <summary>
 /// Initialize the device on the control.
 /// </summary>
 /// <param name="control"></param>
 public void Initialize(Control control)
 {
     padding = control.Padding;
     size    = control.Size;
     //! Dispose the layers.
     for (int i = 0; i < layers.Count; i++)
     {
         if (layers[i] != null)
         {
             layers[i].Dispose();
         }
     }
     //! Dispose the sprite.
     if (sprite != null)
     {
         sprite.Dispose();
         sprite = null;
     }
     //! Dispose the main surface.
     if (mainSurface != null)
     {
         mainSurface.Dispose();
         mainSurface = null;
     }
     System.GC.Collect();
     //! if device isn't null then reset the device size.
     if (device != null)
     {
         device.Reset(new SharpDX.Direct3D9.PresentParameters(control.ClientSize.Width, control.ClientSize.Height));
     }
     else
     {
         //! create a new device.
         device = new SharpDX.Direct3D9.Device(new SharpDX.Direct3D9.Direct3D(), 0, SharpDX.Direct3D9.DeviceType.Hardware, control.Handle,
                                               SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing, new SharpDX.Direct3D9.PresentParameters(control.ClientSize.Width, control.ClientSize.Height));
     }
     //! create a new sprite.
     sprite = new SharpDX.Direct3D9.Sprite(device);
     //! Create layers.
     for (int i = 0; i < layers.Count; i++)
     {
         layers[i] = new Layer(new SharpDX.Direct3D9.Texture(device, size.Width, size.Height, 1, SharpDX.Direct3D9.Usage.RenderTarget, SharpDX.Direct3D9.Format.A8R8G8B8, SharpDX.Direct3D9.Pool.Default));
     }
 }
Example #10
0
        public unsafe void tGetBitmap(SharpDX.Direct3D9.Device device, CTexture ctex, int timeMs)
        {
            int bufferSize = 0;
            int hr         = 0x0;

            hr = grabber.GetCurrentBuffer(ref bufferSize, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            if (samplePtr == IntPtr.Zero)
            {
                samplePtr = Marshal.AllocHGlobal(bufferSize);
            }

            DataRectangle rectangle3 = ctex.texture.LockRectangle(0, SharpDX.Direct3D9.LockFlags.None);

            hr = grabber.GetCurrentBuffer(ref bufferSize, rectangle3.DataPointer);
            DsError.ThrowExceptionForHR(hr);
            ctex.texture.UnlockRectangle(0);
        }
Example #11
0
 private EX9.Texture CreateTexture(FrameInfo frameInfo, EX9.Device device)
 {
     using (var sharpDxDevice = new SharpDX.Direct3D9.Device(device.ComPointer))
     {
         ((SharpDX.IUnknown)sharpDxDevice).AddReference(); // Dispose will call release
         var decoder = frameInfo.Decoder;
         if (decoder != null)
         {
             using (var texture = decoder.Decode(sharpDxDevice))
             {
                 ((SharpDX.IUnknown)texture).AddReference(); // Dispose will call release
                 return(SlimDX.Direct3D9.Texture.FromPointer(texture.NativePointer));
             }
         }
         else
         {
             return(null);
         }
     }
 }
Example #12
0
 /// <summary>
 /// Creates a render surface.
 /// </summary>
 /// <param name="device"><dd>  <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Device"/></strong> interface, the device to be associated with the render surface.</p> </dd></param>
 /// <param name="width"><dd>  <p>Width of the render surface, in pixels.</p> </dd></param>
 /// <param name="height"><dd>  <p>Height of the render surface, in pixels.</p> </dd></param>
 /// <param name="format"><dd>  <p>Member of the <see cref="SharpDX.Direct3D9.Format"/> enumerated type, describing the pixel format of the render surface.</p> </dd></param>
 /// <param name="depthStencil"><dd>  <p>If <strong>TRUE</strong>, the render surface supports a depth-stencil surface. Otherwise, this member is set to <strong><see cref="SharpDX.Result.False"/></strong>. This function will create a new depth buffer.</p> </dd></param>
 /// <param name="depthStencilFormat"><dd>  <p>If  <em>DepthStencil</em> is set to <strong>TRUE</strong>, this parameter is a member of the <see cref="SharpDX.Direct3D9.Format"/> enumerated type, describing the depth-stencil format of the render surface.</p> </dd></param>
 /// <msdn-id>bb172791</msdn-id>
 /// <unmanaged>HRESULT D3DXCreateRenderToSurface([In] IDirect3DDevice9* pDevice,[In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] BOOL DepthStencil,[In] D3DFORMAT DepthStencilFormat,[In] ID3DXRenderToSurface** ppRenderToSurface)</unmanaged>
 /// <unmanaged-short>D3DXCreateRenderToSurface</unmanaged-short>
 public RenderToSurface(SharpDX.Direct3D9.Device device, int width, int height, SharpDX.Direct3D9.Format format, bool depthStencil = false, SharpDX.Direct3D9.Format depthStencilFormat = Format.Unknown) : base(IntPtr.Zero)
 {
     D3DX9.CreateRenderToSurface(device, width, height, format, depthStencil, depthStencilFormat, this);
 }
        protected override void Draw(MyProfiler drawProfiler, int lastFrameIndex, int frameToDraw)
        {
            Debug.Assert(frameToDraw >= 0 && frameToDraw < MyProfiler.MAX_FRAMES, "Invalid selected frame");

            // Init linebatch
            if (m_lineBatch == null)
            {
                SharpDX.Direct3D9.Device device = MyRender.GraphicsDevice;
                m_lineBatch = new MyLineBatch(Matrix.Identity, Matrix.CreateOrthographicOffCenter(0, device.Viewport.Width, device.Viewport.Height, 0, 0, -1), 50000);

                m_fpsBlock.Start(false);
            }

            // Handle FPS timer
            m_fpsBlock.End(false);

            float elapsedTime    = (float)m_fpsBlock.Elapsed.Seconds;
            float invElapsedTime = elapsedTime > 0 ? 1 / elapsedTime : 0;

            m_fpsPctg = 0.9f * m_fpsPctg + 0.1f * invElapsedTime;

            if (MemoryProfiling)
            {
                // Handle memory usage for frame
                float processDeltaMB = m_fpsBlock.ProcessDeltaMB;
                m_fpsBlock.ProcessMemory[lastFrameIndex] = processDeltaMB;
            }

            float managedDeltaMB = m_fpsBlock.ManagedDeltaMB;

            m_fpsBlock.ManagedMemory[lastFrameIndex] = managedDeltaMB;
            m_fpsBlock.CustomValues[lastFrameIndex]  = m_fpsBlock.CustomValue;

            m_fpsBlock.Reset();

            m_fpsBlock.Start(false);

            if (m_enabled)
            {
                // Draw events as text
                float eventLineSize     = 20;
                float largeTextLineSize = 28;
                float textOffsetY       = MyRender.GraphicsDevice.Viewport.Height / 2 - 8 * largeTextLineSize;

                // Draw thread name and level limit
                m_text.Clear();
                m_text.ConcatFormat("\"{2}\" ({0}/{1})", m_selectedProfiler.GlobalProfilerIndex + 1, m_threadProfilers.Count, m_selectedProfiler.OwnerThread.Name).AppendLine();
                m_text.Append("Level limit: ").AppendInt32(m_levelLimit).AppendLine();
                MyRender.DrawText(new Vector2(20, textOffsetY), m_text, Color.LightGray, 1);
                textOffsetY += largeTextLineSize * 2 + 10;

                // Draw frame number and local area
                m_text.Clear();
                m_text.Append("Frame: ").AppendInt32(frameToDraw).AppendLine();
                m_text.Append("Local area: ").AppendInt32(m_frameLocalArea);
                MyRender.DrawText(new Vector2(20, textOffsetY), m_text, Color.Yellow, 1);
                textOffsetY += largeTextLineSize * 2 + 10;

                // Draw fps and total calls
                m_text.Clear();
                m_text.Append(m_fpsBlock.Name).Append(" ");
                if (!m_useCustomFrame) // Show FPS only when not using custom frame
                {
                    m_text.AppendDecimal(m_fpsPctg, 3);
                }
                m_text.AppendLine();
                m_text.Append("Total calls: ").AppendInt32(IsValidIndex(frameToDraw, lastFrameIndex) ? m_selectedProfiler.TotalCalls[frameToDraw] : -1);
                MyRender.DrawText(new Vector2(20, textOffsetY), m_text, Color.Red, 1);
                textOffsetY += largeTextLineSize;

                textOffsetY = MyRender.GraphicsDevice.Viewport.Height / 2;
                var children = m_selectedProfiler.SelectedRootChildren;
                for (int i = 0; i < children.Count; i++)
                {
                    MyProfiler.MyProfilerBlock profilerBlock = children[i];

                    DrawEvent(textOffsetY, profilerBlock, i, frameToDraw, lastFrameIndex);
                    textOffsetY += eventLineSize;
                }

                // Draw graphs
                m_lineBatch.Begin();
                DrawPerfEvents(lastFrameIndex);

                VRageRender.Graphics.BlendState.Opaque.Apply();
                m_lineBatch.End();
            }

            // Update horizontal offset
            if (!Paused && !m_useCustomFrame)
            {
                m_selectedFrame = lastFrameIndex;
            }
        }
Example #14
0
 /// <summary>
 /// <p><strong>Applies to: </strong>desktop apps only</p><p>Creates a DirectX Video Acceleration (DXVA) services object. Call this function if your application uses DXVA directly, without using DirectShow or Media Foundation. </p>
 /// </summary>
 /// <param name="device"><dd> <p> A reference to the <strong><see cref="SharpDX.Direct3D9.Device"/></strong> interface of a Direct3D device. </p> </dd></param>
 /// <returns><p>If this function succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
 /// <include file='..\Documentation\CodeComments.xml' path="/comments/comment[@id='DXVA2CreateVideoService']/*"/>
 /// <msdn-id>ms704721</msdn-id>
 /// <unmanaged>HRESULT DXVA2CreateVideoService([In] IDirect3DDevice9* pDD,[In] const GUID&amp; riid,[Out] void** ppService)</unmanaged>
 /// <unmanaged-short>DXVA2CreateVideoService</unmanaged-short>
 public VideoProcessorService(SharpDX.Direct3D9.Device device)
     : base(device)
 {
 }
Example #15
0
 private void Renderer_Drawing(SharpDX.Direct3D9.Device device)
 {
     ecs.Render(renderer);
 }
 public override void Init()
 {
     SharpDX.Direct3D9.Device device = MyRender.GraphicsDevice;
     m_lineBatch = new MyLineBatch(Matrix.Identity, Matrix.CreateOrthographicOffCenter(0, device.Viewport.Width, device.Viewport.Height, 0, 0, -1), 50000);
 }
Example #17
0
 /// <summary>
 /// <p><strong>Applies to: </strong>desktop apps only</p><p>Creates a DirectX Video Acceleration (DXVA) services object. Call this function if your application uses DXVA directly, without using DirectShow or Media Foundation. </p>
 /// </summary>
 /// <param name="device"><dd> <p> A reference to the <strong><see cref="SharpDX.Direct3D9.Device"/></strong> interface of a Direct3D device. </p> </dd></param>
 /// <returns><p>If this function succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
 /// <include file='..\Documentation\CodeComments.xml' path="/comments/comment[@id='DXVA2CreateVideoService']/*"/>
 /// <msdn-id>ms704721</msdn-id>
 /// <unmanaged>HRESULT DXVA2CreateVideoService([In] IDirect3DDevice9* pDD,[In] const GUID&amp; riid,[Out] void** ppService)</unmanaged>
 /// <unmanaged-short>DXVA2CreateVideoService</unmanaged-short>
 public VideoAccelerationService(SharpDX.Direct3D9.Device device)
 {
     System.IntPtr temp;
     DXVAFactory.CreateVideoService(device, Utilities.GetGuidFromType(GetType()), out temp);
     FromTemp(temp);
 }
Example #18
0
 /// <summary>
 /// <p><strong>Applies to: </strong>desktop apps only</p><p>Creates a DirectX Video Acceleration (DXVA) services object. Call this function if your application uses DXVA directly, without using DirectShow or Media Foundation. </p>
 /// </summary>
 /// <param name="device"><dd> <p> A reference to the <strong><see cref="SharpDX.Direct3D9.Device"/></strong> interface of a Direct3D device. </p> </dd></param>
 /// <returns><p>If this function succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
 /// <include file='..\Documentation\CodeComments.xml' path="/comments/comment[@id='DXVA2CreateVideoService']/*"/>
 /// <msdn-id>ms704721</msdn-id>
 /// <unmanaged>HRESULT DXVA2CreateVideoService([In] IDirect3DDevice9* pDD,[In] const GUID&amp; riid,[Out] void** ppService)</unmanaged>
 /// <unmanaged-short>DXVA2CreateVideoService</unmanaged-short>
 public VideoDecoderService(SharpDX.Direct3D9.Device device)
     : base(device)
 {
 }
        public void Draw()
        {
            if (!m_enabled)
            {
                return;
            }

            if (MyProfiler.EnableAsserts)
            {
                MyCommonDebugUtils.AssertDebug(m_selectedProfiler.CurrentProfilingStack.Count == 0, "Stack size must be 0!");
            }

            // Init linebatch
            if (m_lineBatch == null)
            {
                SharpDX.Direct3D9.Device device = MyMinerGame.Static.GraphicsDevice;
                m_lineBatch = new MyLineBatch(
                    Matrix.Identity,
                    Matrix.CreateOrthographicOffCenter(0.0F, device.Viewport.Width, device.Viewport.Height, 0.0F, 0.0F, -1.0F),
                    50000);

                m_fpsBlock.Stopwatch.Start();
            }


            // Handle FPS timer
            m_fpsBlock.End(false);

            float elapsedTime    = (float)m_fpsBlock.Stopwatch.Elapsed.TotalSeconds;
            float invElapsedTime = elapsedTime > 0 ? 1 / elapsedTime : 0;

            m_fpsBlock.averagePctg = 0.9f * m_fpsBlock.averagePctg + 0.1f * invElapsedTime;

#if MEMORY_PROFILING
            // Handle memory usage for frame
            float processDeltaMB = m_fpsBlock.ProcessDeltaMB;
            m_fpsBlock.ProcessMemory[m_index] = processDeltaMB;
#endif

            float managedDeltaMB = m_fpsBlock.ManagedDeltaMB;
            m_fpsBlock.ManagedMemory[m_index] = managedDeltaMB;
            m_fpsBlock.CustomValues[m_index]  = m_fpsBlock.CustomValue;

            m_fpsBlock.Stopwatch.Reset();

            m_fpsBlock.Start(false);

            int numCalls = 0;  // number of calls of StartProfilingBlock

            // Add new measured time to each graph
            if (!Paused)
            {
                foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
                {
                    float dt;

                    profilerBlock.ManagedMemory[m_index] = profilerBlock.ManagedDeltaMB;
#if MEMORY_PROFILING
                    profilerBlock.ProcessMemory[m_index] = profilerBlock.ProcessDeltaMB;
#endif
                    profilerBlock.NumCallsArray[m_index] = profilerBlock.NumCalls;
                    profilerBlock.CustomValues[m_index]  = profilerBlock.CustomValue;

                    dt = (float)profilerBlock.Stopwatch.Elapsed.TotalSeconds * 1000f;

                    profilerBlock.Miliseconds[m_index] = (float)profilerBlock.Stopwatch.Elapsed.TotalMilliseconds;
                    float pctg = (0.001f * dt) * invElapsedTime;
                    profilerBlock.averagePctg        = 0.9f * profilerBlock.averagePctg + (0.1f * pctg);
                    profilerBlock.averagePctg        = System.Math.Min(profilerBlock.averagePctg, 1.0f); // block cannot take more than 100% of elapsed fram time
                    profilerBlock.averageMiliseconds = 0.9f * profilerBlock.averageMiliseconds + 0.1f * (float)profilerBlock.Stopwatch.Elapsed.TotalMilliseconds;
                    profilerBlock.Stopwatch.Reset();

                    if (profilerBlock.ManagedDeltaMB > memoryRange)
                    {
                        memoryRange = 2 * profilerBlock.ManagedDeltaMB;
                    }

#if MEMORY_PROFILING
                    if (profilerBlock.ProcessDeltaMB > memoryRange)
                    {
                        memoryRange = 2 * profilerBlock.ProcessDeltaMB;
                    }
#endif
                    numCalls += profilerBlock.NumCalls;
                    profilerBlock.NumChildCalls = profilerBlock.GetNumChildCalls();
                }
            }

            if (m_enabled)
            {
                // Draw events as text
                float         Y_TEXT_POSITION = MyMinerGame.Static.GraphicsDevice.Viewport.Height / 2;
                StringBuilder text            = new StringBuilder(100);
                int           textOffsetY     = 0;

                if (m_selectedProfiler.SelectedRoot == null)
                {
                    foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
                    {
                        if (profilerBlock.Parent != null)
                        {
                            continue;
                        }

                        profilerBlock.color = textOffsetY < m_colors.Length ? m_colors[textOffsetY].PackedValue : Color.Green.PackedValue;

                        if (profilerBlock.NumCalls == 0)
                        {
                            profilerBlock.Cooldown--;
                        }
                        else
                        {
                            profilerBlock.Cooldown = 1000;
                        }

                        profilerBlock.DrawGraph = true;

                        if (m_useCustomFrame)
                        {
                            DrawEvent(textOffsetY, profilerBlock, m_selectedFrame);
                        }
                        else
                        {
                            DrawEvent(textOffsetY, profilerBlock, Paused ? (m_selectedFrame - 1) % MyProfiler.MAX_FRAMES : m_selectedFrame);
                        }

                        textOffsetY++;
                    }
                }
                else
                {
                    for (int i = 0; i < m_selectedProfiler.SelectedRoot.Children.Count; i++)
                    {
                        MyProfiler.MyProfilerBlock profilerBlock = m_selectedProfiler.SelectedRoot.Children[i];

                        profilerBlock.color = i < m_colors.Length ? m_colors[i].PackedValue : Color.Green.PackedValue;

                        if (profilerBlock.NumCalls == 0)
                        {
                            profilerBlock.Cooldown--;
                        }
                        else
                        {
                            profilerBlock.Cooldown = 1000;
                        }

                        profilerBlock.DrawGraph = true;

                        if (m_useCustomFrame)
                        {
                            DrawEvent(textOffsetY, profilerBlock, m_selectedFrame);
                        }
                        else
                        {
                            DrawEvent(textOffsetY, profilerBlock);
                        }
                        textOffsetY++;
                    }
                }

                // Draw thread name
                text.Clear();
                text.Append("Thread (" + m_selectedProfilerIndex + "/" + m_threadProfilers.Count + "): " + m_selectedThread.Name);
                text.Append(", Level limit: " + m_levelLimit.ToString());
                MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-2) * 20), text, Color.Gray, 1);

                // Draw fps
                text.Clear();
                text.Append(m_fpsBlock.Name);
                if (m_useCustomFrame && m_selectedFrame >= 0 && m_selectedFrame < MyProfiler.MAX_FRAMES)
                {
                    //text.Append(m_fpsBlock.TimePercentage[SelectedFrame].ToString(" #,###0.000"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-1) * 20), text, Color.Red, 1);
                }
                else
                {
                    text.Append(m_fpsBlock.averagePctg.ToString(" #,###0.000"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-1) * 20), text, Color.Red, 1);
                }


                // Total calls
                text.Clear();
                text.Append(numCalls.ToString("Total calls 0"));
                MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (textOffsetY) * 20), text, Color.Red, 1);

                if (m_useCustomFrame)
                {
                    text.Clear();
                    text.Append(m_selectedFrame.ToString("Selected frame: 0"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + 2 * (textOffsetY) * 20), text, Color.Yellow, 1);
                }

                // Handle stack checking
                if (m_stackCheckingDuration > 0)
                {
                    text.Clear();
                    text.Append("Checking Profiler Stack");
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-3) * 20), text, Color.Orange, 1);

                    m_stackCheckingDuration -= elapsedTime;
                    m_stackCheckingDuration  = Math.Max(m_stackCheckingDuration, 0);

                    MyProfiler.StackChecking = true;   // enable checking for next frame
                }
                else
                {
                    MyProfiler.StackChecking = false;
                }


                // Draw graphs
                m_lineBatch.Begin();
                DrawPerfEvents();
                m_lineBatch.End();
            }

            // Update horizontal offset
            if (!Paused)
            {
                m_index = (++m_index) % MyProfiler.MAX_FRAMES;

                if (!m_useCustomFrame)
                {
                    m_selectedFrame = m_index;
                }
            }

            // Reset childs before next run
            foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
            {
                profilerBlock.StackChildren.Clear();
                profilerBlock.StackParent = null;
                profilerBlock.Stopwatch.Reset();
                profilerBlock.DrawGraph     = false;
                profilerBlock.NumCalls      = 0;
                profilerBlock.NumChildCalls = -1; // -1 means it needs to be computed first.

                profilerBlock.StartManagedMB = 0;
                profilerBlock.EndManagedMB   = 0;
                profilerBlock.DeltaManagedB  = 0;

#if MEMORY_PROFILING
                profilerBlock.startProcessMB = 0;
                profilerBlock.endProcessMB   = 0;
                profilerBlock.deltaProcessB  = 0;
#endif

                profilerBlock.CustomValue = 0;
            }
        }
Example #20
0
 protected override void Dispose( bool isDisposing )
 {
     if ( isDisposing )
     {
         SharpDX.Direct3D9.Device device = d3dDevice;
         d3dDevice = null;
         device.Dispose ();
         d3d.Dispose ();
     }
     base.Dispose ( isDisposing );
 }