Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Am I using drawgeometry in onrender loop as intended?

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

    Am I using drawgeometry in onrender loop as intended?

    I have a working onrender method that loops on the displayed bars using fromindex and toindex. Inside this loop I am drawing filled triangles using the SharpDX api. I found an example in the forum and mutated it into the following :

    p0.X = x + trisize ;
    p0.Y = (float)(ChartPanel.H) - trisize ;
    p1.X = x - trisize;
    p1.Y = (float)(ChartPanel.H) - trisize ;
    p2.X = x;
    p2.Y = (float)(ChartPanel.H);
    vectors[0] = p1.ToVector2();
    vectors[1] = p2.ToVector2();

    SharpDX.Direct2D1.PathGeometry geo1 = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFac tory);
    SharpDX.Direct2D1.GeometrySink sink1 = geo1.Open();
    sink1.BeginFigure(p0.ToVector2(), SharpDX.Direct2D1.FigureBegin.Filled); // move to p0
    sink1.AddLines(vectors); // line to p1,p2,p3
    sink1.EndFigure(SharpDX.Direct2D1.FigureEnd.Closed ); // close polygon
    sink1.Close();

    RenderTarget.DrawGeometry(geo1, Brushes.Lime.ToDxBrush(RenderTarget));
    RenderTarget.FillGeometry(geo1, Brushes.Lime.ToDxBrush(RenderTarget));
    geo1.Dispose();
    sink1.Dispose();


    my question is do I need to dispose as listed, or is there a way I can safely create the geo and sink 1 time before the loop, re-assign some way in the loop, and then dispose only 1 time after the loop?

    It just seems highly inefficient to create and dispose so much.

    The basic idea of this indi is to draw a triangle on the bottom of the chart directly under each bar. There is more logic to my code that changes color and direction. I left it out to keep my example easy to read.

    My code is working just fine, but this just seems like it could bog down the CPU during busy times given my indi processes each tick.

    #2
    Hello tulanch,

    Thank you for your post.

    Try creating the objects outside your loop and disposing them outside the loop. Assign them inside the loop if the values are specific to the bars.

    I would also recommend if possible to avoid the loop unless absolutely necessary to loop through the from and to index of the bars on the chart each time rendering is called.

    Please let me know if this helps to improve performance or if you run into any items along the way.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    579 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X