Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by learningunity · Mar 27, 2015 at 01:14 AM · pluginnativemultithreadinggl

When can GL.IssuePluginEvent be called?

The Unity documentation mentions that GL.IssuePluginEvent could be called by the OnPostRender function of a "camera" script.

The documentation also has a link to an example of a low-level rendering plugin, and a corresponding Unity project which calls GL.IssuePluginEvent in a coroutine which waits for all drawing for the current frame to finish (by constructing a WaitForEndOfFrame yield instruction), where the coroutine is started by the Start function of a script.

The documentation does not mention any particular limitation on when a call to GL.IssuePluginEvent could be made -- and it seems reasonable to assume that such a call would simply set a flag which the drawing thread would eventually detect, at which point the drawing thread would implicitly call UnityRenderEvent in the plugin DLL -- and if that's the case, then there would seem to be no limitation at all on when GL.IssuePluginEvent could be called. Any script could call GL.IssuePluginEvent at any time. But, is this actually the case?

Specifically, I'm interested in possibly calling GL.IssuePluginEvent in the Update, LateUpdate, or OnPreRender event handlers for an arbitrary script.

Does anyone have any experience with calling GL.IssuePluginEvent from any place other than OnPostRender or a coroutine which waits for the end of the current frame? Or is there any part of the Unity documentation which explicitly mentions the acceptability of calling GL.IssuePluginEvent from other places?

Some relevant links for people who are interested in this topic:

Determine if Unity is doing multi-threaded drawing (which would require calling GL.IssuePluginEvent): http://docs.unity3d.com/ScriptReference/SystemInfo-graphicsMultiThreaded.html

Overview of native plugin interface: http://docs.unity3d.com/Manual/NativePluginInterface.html

The GL.IssuePluginEvent function: http://docs.unity3d.com/ScriptReference/GL.IssuePluginEvent.html

Source code for a native plugin which calls native drawing API functions (e.g., DX9, DX11, OpenGL), and a Unity project showing how to use the native plugin: http://docs.unity3d.com/uploads/Examples/RenderingPluginExample45.zip [This link is found on the page for the "Native Plugin Interface", and the file name seems likely to eventually change. I only cite this specific, transient URL to point out that such examples exist in this approximate location.]

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paraself · Sep 30, 2015 at 05:39 PM 0
Share

I tried calling GL.IssuePluginEvent in Start(), sadly it does not work....still investigating more into this issue....

avatar image joe234321 · Dec 08, 2015 at 06:41 PM 0
Share

Hello,

Have you had any success getting more information regarding the behavior GLIssuePluginEvent?

I'm trying to do something similar. I'm updating a texture from a native plugin each frame. If I invoke the event at the end of the frame as demonstrating in the native plugin interface sample, a 1 frame delay is introduced. I'd like to perform the copy before rendering begins.

Would placing the GL.IssuePluginEvent in an OnPreRender function on the camera script work? Would this break if the rendering is multi-threaded?

Thanks, Joe

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by AngelGabriel · Mar 21, 2017 at 08:17 AM

Two years after original post, and the documentation still does not address this...

Just tried some not-at-all scientific experiments - Using Unity 5.5 on Windows. - Rendering is multi-threaded - Test is simply retrieving a web camera image and comparing timestamps (std::chrono::high_resolution_clock::now) - GL.IssuePluginEvent can be called from Update, LateUpdate, OnPreRender, OnPostRender, even in Start.

Calling seems to be required for each rendered frame. Calling at start yielded one image that never updates. Therefore, calling clearly needs to be per-rendered frame.

Comparing time stamps to determine latency from image received in plugin to image used in Unity showed NO VARIATION. In particular, the latency in the OnPostRender stage was always greater than OnPreRender, even if the GL.IssuePluginEvent was made in OnPostRender.

All of this seems like it confirms the OP's guess:

it seems reasonable to assume that such a call would simply set a flag which the drawing thread would eventually detect, at which point the drawing thread would implicitly call UnityRenderEvent in the plugin

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by AngelGabriel · Mar 21, 2017 at 08:17 AM

Update: when waiting until a new frame from the webcam is ready in the OnPreRender stage, the latency is minimized when GL.IssuePluginEvent is called during the LateUpdate execution stage.

Calling GL.IssuePluginEvent in OnPreRender and then waiting yields more latency. Likewise, calling GL.IssuePluginEvent at the end of frame and waiting in OnPreRender also increases latency.

While I'm not sure how to interpret that observation, it seems like it might be a good thing for others to test as well.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by blossomgames · Oct 11, 2018 at 04:06 PM

My experience is different. I do some plugin rendering. Now: - when I call plugin in Update, my data gets screwed (probably my plugin code is finishing halfway through or something) - when I call plugin in OnPostRender nothing works - when I call just like the Unity's big plugin rendering example it seems fine

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Low-level native plugin on iOS 1 Answer

Why does deferred rendering flip the view and change the viewToWorldMatrix? 0 Answers

Is it possible to have editor-only native plugins? 0 Answers

Creating a native photo picker screen on iOS 2 Answers

Why is GL.IssuePluginEvent not listed on documentation page for "GL" class? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges