Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reuse BrushDx or not - this is the question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Reuse BrushDx or not - this is the question

    Hi
    I am using NT8 B13
    I have an indicator which has "heavy" display.
    The display is made from OnRender by the indicator using sharpdx methods.
    The display include hundreds or several thousand objects in a screen.
    The objects are rectangles , text and lines
    Suppose I need to draw a Rectangle and within it a text. With some predefined Forgroundcolor , BackgroundColor,OutlineColor
    This can be done as follows:
    SharpDX.Direct2D1.Brush textForgroundBrushDx = textForgroundBrush.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush textBackgroundBrushDx = textBackgroundBrush.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush textOutLineBrushDx = textOutLineBrush.ToDxBrush(RenderTarget);
    Textformat definition commands
    Textlayout definition commands
    Rectangle definition commands
    Drawtext operation
    textLayout.Dispose();
    textFormat.Dispose();
    textForgroundBrushDx.Dispose();
    textBackgroundBrushDx.Dispose();
    textOutLineBrushDx.Dispose();
    do you recommend to do it as above i.e. creat BrushDx and Dispose it per each display operation or to generate the BrushDx once, use it whenever needed and never dispose it
    it should be clear that any BrushDx can be used at the same display for many objects and for different objects types and for different purposes

    #2
    Does this discussion help any?

    Comment


      #3
      thx sledge

      It looks they recommend to create the BrushDx colors once .
      And dispose it when
      State == State.Terminated
      Is this the "correct" way ?



      I remember once i read somewhere that creation of BrushDx demand minimal resources






      Last edited by doron; 09-14-2016, 10:46 PM.

      Comment


        #4
        No idea. I haven't even gotten to that point yet.

        Comment


          #5
          Hello doron,

          Below is a link to another thread with an example of reusing brushes efficiently.


          The brushes should be created / disposed of and recreated in OnRenderTargetChanged() and then are reused for each pass of OnRender().

          Use one brush per color and use this brush for any rendered object that you want to use that color with.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            hi

            I read your script about reuse of brushes

            i understand you dispose all brushes you already created in previous pass and create them again.

            why do we need to dispose the brushes and recreate them if we use same brushes again and again ?

            Comment


              #7
              Hello doron,

              The brushes are created for that specific sharpdx render target. When the render target is recreated, you need to make brushes for that new render target.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                hi
                i do not understand
                you wrote : "Use one brush per color and use this brush for any rendered object that you want to use that color with"
                You also Wrote : " brushes are created for that specific sharpdx render target. When the render target is recreated, you need to make brushes for that new render target."
                My on render method is called and I need to draw three objects
                object1 is text object2 is rectangle object3 is line

                i need Red for Forground color Text
                I need the same red for Background color of Rectangle
                I need the same red to the line
                All 3 object are are different render targets can I use the same SharpDx color for all objects ?
                Why do I have to recreate the color again and again ?

                Comment


                  #9
                  Hello doron,

                  That is incorrect. All the drawing objects will use the same render target.

                  There is only one render target. (The chart rendering area is the render target)

                  The brushes will be created for use with any drawing objects on that rendering target.

                  Make one red brush. Use this brush for all red drawing objects.

                  Recreate the brush when the render target is recreated.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    hi

                    Please verify I understood

                    We have two methods OnRender and OnRenderTargetChanged
                    In each activation of OnRenderTargetChanged we should dispose old created BrushDx Colors (if any) and recreate the colors if render target exist
                    Within OnRender (which is activated after OnRenderTargetChanged) all brushes are ready to use

                    thx for your help

                    Comment


                      #11
                      Hello doron,

                      That is correct.

                      OnRenderTargetChanged will be triggered when a new render target is created.
                      Brushes should be disposed of for the old render target and recreated for the new render target.

                      OnRender will be triggered when the chart is rendered.
                      The brushes are already ready to use and reuse.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi
                        I am using NT8 B13
                        I replaced my graphic card and moved to B13 at the same time ( which was a mistake )
                        I reported in several posts about error messages I got usually when I resize a chart or move it. Those errors where related to display with SharpDx methods. And never happened to me before.
                        I develop a complex indicator with heavy display i.e. within my indicator I use SharpDx methods for display in a lot of places.
                        In order to overcome the problem I have made massive changes in my design so that all my drawing requests will be made by a call to 2-3 methods . so that all calls to sharpdx will be from those 2-3 methods. This enable me to control how I am using the sharpdx.
                        After doing that I made the changes as recommended by ninja support team and demonstrated in the indicator ReuseDxBrushesExample
                        I investigated in that almost a week ( I told you , it is a heavy indicator …)
                        the good news is that after doing all that – during last 2 days previous errors did not show again.
                        The bad news is – I have no idea what was wrong as before B13 and the new card I had no errors.
                        Thanks everyone for the help
                        Last edited by doron; 09-21-2016, 09:25 AM.

                        Comment


                          #13
                          The example SampleCustomPlot indicator included with NT8 doesn't do anything like this suggested procedure using OnRenderTargeChangedt; instead it creates the SharpDX brushes within OnRender and disposes of them at the end of that method.

                          I have been doing it that way and don't seem to have any problems; is there a reason I should change to the approach suggested here?

                          Comment


                            #14
                            hi palinuro

                            I suspect that the problem is related somehow to the fact i replaced to new graphic card so the direct - x version and other graphical packages were updated.
                            In order to check this idea try to use your indicator in a computer with a new graphic card

                            doron

                            Comment


                              #15
                              Hello palinuro,

                              The main reason to reuse brushes is for performance reasons.

                              Recreating brushes will cause much higher CPU and memory usage.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              30 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              943 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              28 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X