Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[VR] Add a method to get native Ptr from a texture #5552
Comments
|
You can use reflection to get the native resource.
|
|
Hi, Thank you! How can I get the native pointer of a RenderTexture2D with the DesktopGL paltform? It's ok for DirectX I did that var renderTarget = new RenderTarget2D(Game.GraphicsDevice, (int)width, (int)height);
_textures[eye] = new Texture_t();
var info = typeof(RenderTarget2D).GetField("_texture", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var handle = info.GetValue(renderTarget) as SharpDX.Direct3D11.Resource;
_textures[eye].handle = handle.NativePointer;
_textures[eye].eType = ETextureType.DirectX; |
|
I don't know much about the implementation of openGL platforms. |
|
With that said, I don't think MG will ever expose implementation details like native pointers. From my point of view the spirit of MonoGame is more about providing a common API for things like VR, 3DTVs, etc. |
|
OK, if we can have access of this using the reflection it's fine for me. |
|
Hi again, The native pointer from DirectX doesn't work with OpenVR, however it works great with DesktopGL and SteamVR/OpenGL. This is my code (for information). var info = typeof(RenderTarget2D).GetField("glTexture", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var glTexture = (int)info.GetValue(renderTarget);
_textures[eye].handle = new IntPtr(glTexture);
_textures[eye].eType = ETextureType.OpenGL;I still have an issue with the view/project matrix but OpenVR is working with MonoGame ;) Thanks a lot for your help! |
|
Cool stuff! I can imagine a MonoGame VR target platform that exposes whatever you need. |
|
This is what I'm trying to do in my engine. I have a IVRDevice interface and a VRRenderer. You're free to implement the VR SDK you want to use. |
|
@Jjagg @nkast Please reconsider implementing I don't think "just use reflection" or "just fork MonoGame" are viable solutions to this use case, long term. |
|
You can cache the result of the reflection. That's what I do and it works well. I'm agree that it's a better solution to have a reflection less implementation. |
|
I close the issue because it's fine for now, thank you guys! |
Hi,
I'm working on a VR implementation with Monogame for my game engine. The implementation is almost done, however I'm stuck because I need to have an access to the texture's native pointer.
There is a method called
GetSharedHandle()that returns an IntPtr which is what I want. But Microsoft doesn't recommand to use it and it's not working in my case (it returns IntPtr.Zero).Having access to the native pointer is mandatory for a VR implementation using a compositor (Oculus Home, SteamVR and soon OSVR). In fact you have to create two
RenderTarget2Dand pass theirIntPtrto the VR SDK (the Submit method in my sources).Without that, you can only have a non direct mode rendering and have to manage the screen size, placement, etc. (this is what Oculus did when the DK1 was released).
I'm working on the three implementations (Oculus, OpenVR and OSVR).
Thanks.