Search Unity

writing NON unity data into a rendertexture

Discussion in 'General Graphics' started by john_snape, May 23, 2018.

  1. john_snape

    john_snape

    Joined:
    May 23, 2018
    Posts:
    2
    OK I'm new to unity but have been writing OpenGL in C++ for years, I've searched the forums but I can't seem to find any answers.
    So we are attempting to move legacy OpenGL graphics to a native windows only unity application.
    I have created a simple Quad with a rendertexture, now I want to update the texture with externally sourced data, generated by a legacy application that writes a 512x512x4 array of pixel data into a shared memory area.
    I have successfully mapped this data to an IntPtr in C# using the windows CreateFileMapping and MapViewOfFile API's, and I know the pixel data is being seen correctly in C#.

    The script has the RenderTexture object visible but I cannot see how to update the underlying texture in Unity/C#.

    In the Old legacy system I would have used:
    glBindTexture(GL_TEXTURE_2D, textureId);

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, memPtr );

    where memPtr is the address of the start of the pixel data, and textureId is the Gl ID returned from GlGenTextures();

    Anyone any idea as to where I should look, or if someone know how to do this, some examples please.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
  3. john_snape

    john_snape

    Joined:
    May 23, 2018
    Posts:
    2
    Thank You,
    after some fiddling I have managed to get it to work with the LoadRawTexture example
     
    richardkettlewell likes this.