Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[Solved] Get Handle to OpenGL Unity Render Context

Discussion in 'Windows' started by Oninova, Aug 23, 2016.

  1. Oninova

    Oninova

    Joined:
    Aug 22, 2016
    Posts:
    6
    I was wondering if anyone knows how to get a handle to the opengl unity render context. I need to create a texture in a external application and render it in Unity using Texture2D.CreateExternalTexture(). When I create the texture in my external application I get a texture id of 1, which seems wrong. I'm guessing its because it has its own render context and does not share a texture pool with Unity. I could be totally wrong about this because I'm a bit of a OpenGL noob. If anyone could point me in the right direction it would be greatly appreciated.
     
  2. Oninova

    Oninova

    Joined:
    Aug 22, 2016
    Posts:
    6
    I was able to grab the handle to the opengl unity render context by using a low-level native plugin and fetching the handle with wglGetCurrentContext(). https://docs.unity3d.com/Manual/NativePluginInterface.html

    Using GetRenderEventFunc() allowed me to call GL.IssuePluginEvent() directly from the render thread, which in turn allowed me to grab the context handle. I am now able to render my textures externally and then display them in Unity using Texture2D.CreateExternalTexture().
     
  3. pavlynne

    pavlynne

    Joined:
    Jan 6, 2018
    Posts:
    1
    If you could show some exact code samples I would really appreciate it
     
    JonRurka likes this.
  4. Varaughe

    Varaughe

    Joined:
    Apr 22, 2013
    Posts:
    41