Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Brushes in OnRenderTargetChanged()

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

    Multiple Brushes in OnRenderTargetChanged()

    I am trying to understand brush concepts and I am looking at the documentation for OnRenderTargetChange() which gives this example:

    Code:
    public override void OnRenderTargetChanged()
    {
      // if dxBrush exists on first render target change, dispose of it
      if (dxBrush != null)
      {
        dxBrush.Dispose();
      }
     
      // recalculate dxBrush from value caluled in OnBarUpdated when RenderTarget is recreated
      if (RenderTarget != null)
        dxBrush = brushColor.ToDxBrush(RenderTarget);
    }
    My question is, do I reproduce this code for each brush like this:

    Code:
    public override void OnRenderTargetChanged()
    {
      //first brush
      if (dxBrush != null)  { dxBrush.Dispose(); }
      if (RenderTarget != null){dxBrush = brushColor.ToDxBrush(RenderTarget);}
    
        //second brush
      if (dxBrush2 != null)  { dxBrush2.Dispose(); }
      if (RenderTarget != null){dxBrush2 = brushColor2.ToDxBrush(RenderTarget);}
    
      //third brush
      if (dxBrush3 != null)  { dxBrush3.Dispose(); }
      if (RenderTarget != null){dxBrush3 = brushColor3.ToDxBrush(RenderTarget);}
    }
    Is this a common approach? Any pitfalls that have to do with the order of these?
    Last edited by swcooke; 06-15-2018, 09:47 AM.

    #2
    Hello swcooke,

    Thank you for the post.

    Yes, this is pretty standard and really shouldn't have any pitfalls. The problems would come when not correctly recreating brushes and you end up trying to use invalid objects. Recreating the brushes when the render target changes is needed so this type of logic is suggested to be used.

    I do see you are using the same variable for each line of syntax in your sample unless that was intended:
    Code:
    [B]brushColor[/B].ToDxBrush(RenderTarget);
    I look forward to being of further assistance.

    Comment


      #3
      Thanks for pointing that out. I have edited my post and fixed that. One last question. Can you confirm that the order of each of these does not matter?

      Comment


        #4
        Hello swcooke,

        Yes, the order should not matter, mainly you want to include objects that do need to be recreated in this override. You can make the order inside of the method however it makes logical sense and looks good to you.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        650 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X