Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Reuse BrushDx or not - this is the question
Collapse
X
-
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
Tags: None
-
-
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
-
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
-
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
-
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
-
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
-
HiI am using NT8 B13I 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 ReuseDxBrushesExampleI 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 helpLast edited by doron; 09-21-2016, 09:25 AM.
Comment
-
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
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Change colour of Stop market and limit orders to red and green via indicator script
by Rapine Heihei
Started by Rapine Heihei, 04-23-2024, 07:51 PM
|
2 responses
30 views
0 likes
|
Last Post
by Max238
Today, 02:25 AM
|
||
Started by Shansen, 08-30-2019, 10:18 PM
|
24 responses
943 views
0 likes
|
Last Post
by spwizard
Today, 01:29 AM
|
||
Started by Max238, Today, 01:28 AM
|
0 responses
9 views
0 likes
|
Last Post
by Max238
Today, 01:28 AM
|
||
Started by rocketman7, Today, 01:00 AM
|
0 responses
7 views
0 likes
|
Last Post
by rocketman7
Today, 01:00 AM
|
||
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
28 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 10:43 PM
|
Comment