Jump to content

Strategy for one-off Render() on config dialog close


Recommended Posts

The plugin I'm building runs its own built-in preview window, so I don't tell PDN that anything is changing (ie. not calling FinishTokenUpdate or calling EffectTokenChanged while the user uses my config UI window)


Once a user hits "OK" to render things out, I then want to get my OnRender() called - just the once - so I can push out the final result. My effect has a RenderingSchedule of EffectRenderingSchedule.None and I need to do all the work in a single call.


I've got a solution where I embed an ID into the token and the Effect instance - if it matches in a OnRender() call (or if we're repeating the render) then we do the final result - but regardless, we change the ID in every call to OnRender() so it will only trigger once it's been through the UI.


// some pseudocode...

// in effect code

protected override void OnRender( Rectangle[] rois, int startIndex, int length )
  if ( (Token.RenderFinal && localRenderFinal) || repeatEffect )
	// .. do the stuff

  localRenderFinal = false

// in config form:

private void HwRender_PanelClicked(object sender, MouseEventArgs e)
  (theEffectToken as MyEffectToken).RenderFinal = true
  (Effect as MyEffect).localRenderFinal = true




Hope that makes sense. The approach feels a little hacky and I wanted to check if there was something more standard? I have had a search and found the post where Rick describes some of the plugin internal call flow (and I've done my own tracing / ILSpy) but I couldn't see anything that was quite in this direction ...




Edited by ishani
Link to comment
Share on other sites

1 hour ago, ishani said:

The approach feels a little hacky and I wanted to check if there was something more standard?


The normal approach for a plugin that uses its own preview window is to have the configuration dialog render the final result to a Surface that is stored in the effect token.

If the plugin is called as a repeat effect you would perform rendering in OnSetRenderInfo instead of the configuration dialog.


That way the plugin can do the rendering however it needs to and Paint.NET will use its multi-threading when copying to the destination in Render.


You can look at the OnSetRenderInfo and Render implementations in G'MIC for an example of how this is done.


Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...