Can I get Direct3D pointer of Texture2D in Unity3.5?

In OpenGL mode , I can get OpenGL texture name(ID) with Texture2D GetNativeTextureID().

From Unity3.5 , I can get Direct3D device pointer(IDirect3DDevice9) , but I can’t find to get Direct3D Texture Pointer(LPDIRECT3DTEXTURE9).

Is there any method to get Direct3D texture pointer of Texture2D?

Hi!

I have the same problem, getting the texture. How do you get the IDirect3DDevice pointer out of Unity? Have you succeeded in doing so?

Let me know.

Thanks,

Hi!

I gave up to use Direct3D.
Now ,I’m using OpenGL in Windows Standalone & Windows Unity Editor.

Unity.exe -force-opengl <<< for Unity Editor preview

Standalone.exe -force-opengl <<< for Standalone

In standalone build process , [Build&Run] and cancel to run , and I execute it with .bat file .

And using OpenGL 2.x in Windows is very tiresome , but now it works well .
( If you use opengl , search ‘glext.h’ and ‘wglGetProcAddress()’ etc)

Thanks

On Unity 3.5 release , the plugin help was changed , and official example explains to get IDirect3DDevice pointer.

c.f.
http://unity3d.com/support/documentation/Manual/NativePluginInterface.html

Thanks

Hi!

Thank you so much! We’ll definitely look into that, and should we not be able to grab the LPDIRECT3DTEXTURE9 pointer, we’ll revert to OpenGL like you did.

Could you not access the texture by using IDirect3dDevice9->GetTexture(stage, ppTexture)?
You could make a “fake” texture stage assignation, then pass the stage value to your plugin and get the texture pointer immediately thereafter?

Let me know what you think.

Thanks

,Alright! Thanks!

Sorry , I’m not sure.
I didn’t try IDirect3dDevice9->GetTexture(stage, ppTexture).

Is it possible using the Low-level native plugin to tell Unity to render a camera image and grab the pixels off it?

I need to grab many screenshots and I experience lag whenever ReadPixels is called on a Render Texture. I need a workaround.

Thanks

I wrote an example project where I used Microsoft Media Framework and DirectX. On this example, each frame of a windows media video is written to a texture created in Unity. I don’t know this is a correct way to do that but it seems working well. That example is on my post on G+.

You mean like:

	struct Color32

	{

	public:

		char r;

		char g;

		char b;

		char a;

	};

IDirect3DBaseTexture9* pRawTexture;

if (g_D3D9Device->GetTexture(0, &pRawTexture) == D3D_OK)

{

   IDirect3DTexture9* pTexture = (IDirect3DTexture9*)pRawTexture;

   D3DLOCKED_RECT rect;

   ZeroMemory(&rect, sizeof(D3DLOCKED_RECT));

   pTexture->LockRect(0, &rect, NULL, D3DLOCK_READONLY);

   unsigned char *bits = (unsigned char*)rect.pBits;

...

   Color32 color;

   //set pixel

   memcpy(&bits[rect.Pitch * y + 4 * x], &color, 4 );

   //read pixel

   memcpy(&color, &bits[rect.Pitch * y + 4 * x], 4 );

   pTexture->UnlockRect(0);

   pTexture->Release();

}