Comments (5)
Sorry that the documentation you refer to has not been updated.
Spout OpenGL texture sharing links a DirectX shared texture with an OpenGL texture using the NVIDIA GL/DX interop functions. But you can still use the class methods to share DirectX textures directly.
Sharing of DirectX textures is done by way of a share handle which is returned when the texture is created. Another application can access the texture using this share handle. For D3D11 use "OpenSharedResource". Have a look at the function "OpenDX11shareHandle" in the SpoutDirectX class. For D3D9 you simply create a new texture with "CreateSharedDX9Texture" using the share handle.
If a sender creates a shared texture and a share handle, a receiver can access the same texture using the handle. All you do is keep updating this texture and the receiver will access it as required.
If you create a shared texture with the Spout function "CreateSharedDX11Texture" (SpoutDirectX class) you will derive a share handle (dxShareHandle), and it will have the format DXGI_FORMAT_B8G8R8A8_UNORM.
I am not sure whether DXGI_FORMAT_R16G16B16A16_UNORM is compatible with the NVIDIA OpenGL/DirectX interop extensions. The last time I tested formats I found that the only one that worked between D3D11 and D3D9 was DXGI_FORMAT_B8G8R8A8_UNORM and so that is used by default.
The 16 bit format might be OK for sharing if both applications use D3D11 and the same format. I am not familiar with OBS and I am not sure whether D3D11 is supported. I believe it supports OpenGL because there is a Syphon plugin. Do you intend to create a plugin for OBS to share your texture?
It would be good if such a plugin could be made so that other applications could share with OBS using Spout.
Edit: I looked at OBS and there is a folder "libobs-d3d11" and a file "d3d11-texture2d.cpp". There is also a folder "libobs-opengl" and a file "gl-texture2d.c", so it seems that support is there for both.
from spout2.
Thanks for the response. I've been reading it over and over again the past few days.
Within Lumberyard I am creating a texture that I am rendering. I've now given it the RESOURCE_MISC_SHARED flag which I am assuming is the only special flag it needs. I am wanting to show this texture in OBS using the Spout Cam which shows up in OBS as a virtual webcam.
If I pass a DX11 shared handler to Spout, do I have to use mutexes in order to do so or can I just pass it like normal. Will a DX11 texture automatically work with the webcam that's already in OBS if I am just using the CreateSender which only takes in a handle?
For updating a new texture, it seems that UpdateSender is called each time with the same texture handler. Is that how updating should be?
from spout2.
The D3D11_RESOURCE_MISC_SHARED flag is one of the requirements but there are other limitations. Look at "CreateSharedDX11Texture" in SpoutDirectX.cpp to see how a shared DirectX 11 texture is created within Spout.
You then use the texture pointer as the "share handle" when you create a Spout sender. All Spout receivers will have immediate access to your shared texture.
After you have created the sender, you should see it listed by running the Spout demo receiver. You can do this for testing regardless of whether you have created a shared texture (as long as you don't select the sender).
A mutex is advisable to control access to the texture. Otherwise it is possible that your sender and multiple receivers could access the texture at the same time which might cause problems. But you can try without a mutex and see how it goes. At least this is the first thing to do to test the function of your program.
You might get some ideas from the Unity plugin :
https://github.com/sloopidoopi/Spout4Unity/blob/master/NativeSpoutPlugin/src/NativeSpoutPlugin.cpp
This gets away without using a mutex, so you might be OK without it. There is some control by the GL/DX interop functions which have a lock before the interop is activated. The mutex is on top of that.
If your texture is received by the Spout demo sender, and you know that SpoutCam works within OBS then SpoutCam will pick it up OK.
If you update your texture dimensions or create a new texture, you need to call UpdateSender. Otherwise the texture pointer remains the same so sender update is not necessary. Receivers will access whatever the texture contains.
from spout2.
Recently I had another look at the UE4 plugin by AleDel -
https://github.com/AleDel/Spout-UE4
This uses DirectX textures and I believe that it is a good example for you to examine.
Let me know here how you are progressing. I will close this issue if there is nothing more to add.
from spout2.
Sorry I should have said something after your last comment. I was able to figure it out with what you said. I only used SpoutSenderNames and SpoutSharedMemory and that was enough to successfully shared a DirectX 11 texture to OBS. R16G16B16A16_FLOAT works as well with OBS.
Thanks for the help, it was invaluable.
from spout2.
Related Issues (20)
- I found 1-2 frame delay fluctuation when I used spout for texture transmission. How can I eliminate this delay? HOT 7
- Windows on ARM binaries missing HOT 8
- Exclude binaries from repo HOT 1
- RFE: get spout version as String HOT 8
- Spout Settings - max senders can't set to a value with more than 2 digits HOT 3
- Support for Vulkan HOT 2
- Laptops with multiple GPUs HOT 4
- D3D11 Format HOT 28
- SpoutSender/Receiver sourcecode HOT 5
- SpoutLibrary : unable to setup multiple named Spout Receivers HOT 11
- Unused #include <d3d9.h> in SpoutLibrary.h makes compilation with JUCE fail. HOT 2
- GL-Spout-NDI-DX ? HOT 3
- Global registry settings HOT 3
- Multiple Senders in SpoutDX HOT 4
- CPU sharing flag is always false in OpenSpout HOT 7
- Small code issue in SpoutGL.cpp HOT 3
- Use SendImage without using OF, Cinder, etc. HOT 2
- flickering because receiver sometimes can't access the shared texture. HOT 5
- Add ossia to the list of Spout-compatible software :) HOT 3
- Should the solutions be removed from the repo? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spout2.