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

Texture2D.CreateExternalTexture and Texture2D.UpdateExternalTexture?

Discussion in 'Editor & General Support' started by superjayman, Dec 1, 2013.

  1. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    Can some one please provide example code on how to use Texture2D.CreateExternalTexture and Texture2D.UpdateExternalTexture with DX11? Also, DOES UNITY ANSWER ANYTHING IN THIS FORUM? I have posted 3 threads related to this issue and there is no reply to anything!!!!!

    In the unity manuals it says:


    Description

    Creates Unity Texture on top of already inited native texture object.


    What is inited??
     
    Last edited: Dec 1, 2013
  2. s0phist

    s0phist

    Joined:
    Mar 30, 2011
    Posts:
    40
    Whoa, I'm going to play with this right now. Do you think we can point it at the texture id of a camera feed or decoded video feed made natively on mobile?
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Inited == Initialised.
     
  4. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    This is mostly a community forum. A number of us Unity-peeps keep an eye on the site and try and help out where we can.

    To answer you real question, no, I don't have a code example. The basic idea is that you'll have a native code plugin that does something with DX11, most likely creating textures. You'd pass a System.IntPtr from the plugin into the Unity script code and call Texture2D.CreateExternalTexture. Unity then fakes up a Texture2D for you to use in your script code, but, in reality, it's using your texture from your plugin. As an when you'd want this texture to change, you would call UpdateExternalTexture on it, passing in a new IntPtr from your plugin.

    There's an example that does something similar, but different, here:

    http://docs.unity3d.com/Documentation/Manual/NativePluginInterface.html

    This shows how your native plugin can do rendering, and passes Unity-created Texture2Ds to the plugin, so works in the opposite direction.
     
  5. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Will Texture2D.CreateExternalTexture work on IOS or Android?

    Reason for asking is because
    "Note: The rendering callbacks to plugins are not currently supported on mobile platforms."

    Cheers.
     
  6. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    @Graham,

    I'm kind a confused about:
    "You'd pass a System.IntPtr from the plugin into the Unity script code and call Texture2D.CreateExternalTexture"

    From the example project at the bottom of http://docs.unity3d.com/Documentation/Manual/NativePluginInterface.html,
    I thought that System.IntPtr is created inside of unity script and then sent to the Plugin.

    How can I create a System.IntPtr from the plugin ?




     
  7. buFFalo94

    buFFalo94

    Joined:
    Sep 14, 2015
    Posts:
    273
    Hi
    When creating texture with CreateExternalTexture I get something like 5 or 6 ms of GFXWaitForPresent why this is happening? The texture is already created on the native side and uploaded to the GPU if I'm not wrong.
    I'm using D3D11.
    So please can you explain me what going on