Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

clCreateFromGLBuffer Unity Native Plugin

Discussion in 'General Graphics' started by JonRurka, Dec 1, 2021.

  1. JonRurka

    JonRurka

    Joined:
    Nov 19, 2012
    Posts:
    35
    Hello,

    I am writing a Unity Native Plugin in which I'm attempting to run OpenCL kernels on existing Unity Compute Buffers. Theoretically, this should be more than possible. The documentation states directly that i can send the handle of a compute buffer with "ComputeBuffer.GetNativeBufferPointer" into a native plugin.

    I should be able to convert it directly to a cl_mem object by sending that handler directly into "clCreateFromGLBuffer":

    https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/clCreateFromGLBuffer.html

    This should issue should now be solved... I have my handle, I have my function to turn it into a cl_men object, and now I just need the "cl_context", which is the OpenCL context created from the OpenGL context bound to said compute buffer. This should be easy to get. In any 3D graphics application, this would be essential to have.

    However, in Unity3d, I cannot find anywhere where I could get this. I have searched everywhere online, but am unable to find any way to find this. I have found this in the documentation that briefly covers OpenGL contexts at the very bottom of the page (stating there are multiple), but it doesn't exactly say how I would GET them:

    https://docs.unity3d.com/Manual/NativePluginInterface.html

    Any help would be very appreciated.