Updating a texture from a plugin for Unity 3.5 and later

I am attempting to update a Unity texture from a native plugin (I’m on Win7).

Prior to Unity 3.5 there were 2 ways of going about this. Utilizing SetPixels32 or forcing Unity to run in OpenGL mode and passing the GL texture ID down to the native code and using OpenGL to do a texture fill. The OpenGL method had some faults due to the fact that forcing OpenGL mode on Windows was kinda unsupported and might yield problems (which in my experiments it did).

In 3.5 and later, I have come to understand that rendering can happen on a different thread than the one the plugin functions are invoked on. So this makes updating the texture OpenGL style problematic. Does this also effect SetPixels32?

What is now the most efficient way to update a texture from a plugin on Windows 7 with Unity3.5.1? I saw that access to the dx device pointer is now possible, but I still run into the rendering thread not necessarily being the same as the plugin thread. I heard there is some kind of callback mechanism, but I am having trouble finding out how to use it for doing plugin texture updates.

What you say is correct, however using the supplied callbacks is very easy, and the documentation can be found here:

[http://unity3d.com/support/documentation/Manual/NativePluginInterface.html][1]

This page contains information about how it works, as well as an example project showing how to call both OpenGL and Direct3D code on the rendering thread.

Hi,
I’ve got same problem here - I’m trying to find a fast way to update texture in Unity. I’ve got no expierience with DX (came from XNA) - have you managed to use a native plugin?

I am having problems understanding how to use Direct3d as well. It seems that to matter how I initialize my Texture2d in unity, the size of the D3DSURFACE_DESC is always 1024x512 in the rendering plugin. This is making my rendering code very difficult. Is there way to set different dimensions?