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
0
Question by rebser · May 07, 2014 at 01:45 PM · texture2dpluginc++directxdirectx 11

How does Texture2D.CreateExternalTexture work?

I would like to create and update a texture in a C++ plugin in order to build an Interface to a GPUDirect enabled professional video card. What I have already figured out is the way from Unity/DX11 to video. Now I need to figure out how to capture video. Therefore I need a way to write texture data into a texture and use that texture in Unity. I thought Texture2D.CreateExternalTexture would be the way to do this, but whenever I try to use it, I get a hard crash from somewhere inside an internal Unity function.

This is what I do:

 IntPtr retVal = Marshal.ReadIntPtr(GetTexture());
         if(retVal.ToInt32() != 0)
         {
             inputTexture = Texture2D.CreateExternalTexture(1920, 1080, TextureFormat.RGB24, false, false, retVal);
         }

This is the Call Stack:

      Unity.exe!TexturesD3D11::TextureFromShaderResourceView(ID3D11ShaderResourceView * resourceView, ID3D11Texture2D * * texture) Line 146    C++
 >    Unity.exe!TexturesD3D11::RegisterNativeTexture(ID3D11ShaderResourceView * resourceView) Line 160    C++
      Unity.exe!GfxDeviceClient::CreateExternalTextureFromNative(int nativeTex) Line 3108    C++
      Unity.exe!Texture2D::InitTexture(int width, int height, unsigned int format, int options, int imageCount, int nativeTex) Line 469    C++

What am I doing wrong?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by samizzo · Jun 25, 2014 at 09:30 AM

Did you ever get this working? I don't think you want to do a ReadIntPtr - that reads an integer from the memory address that you pass in. What does your GetTexture() function return?

It looks like you are using D3D11, so you should be passing an existing ID3D11ShaderResourceView pointer to CreateExternalTexture. You'll need an IntPtr that is really a pointer to an ID3D11ShaderResourceView, which you should have created in native code somewhere (e.g. in your native plugin).

Comment
Add comment · Show 1 · 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 rebser · Jun 25, 2014 at 10:24 AM 0
Share

my solution was in the end: Create a Texture2D in Unity and pass it to the plugin. The other way wouldn't work.

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

21 People are following this question.

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

Related Questions

How should I release a DirectX11 texture created in a native plugin? 1 Answer

How can I get the Native Plugin example to work on Unity 5? 0 Answers

How Texture2D.CreateExternalTexture works with Direct3D11? 1 Answer

Unity5 filled my SSD? 0 Answers

IL2CPP C# passed ref float[] to C++ can't get right result 1 Answer


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