Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DirectX11 Receiver on offscreen shared OpenGL context #18

Closed
Qlex42 opened this issue Jun 27, 2016 · 10 comments
Closed

Allow DirectX11 Receiver on offscreen shared OpenGL context #18

Qlex42 opened this issue Jun 27, 2016 · 10 comments

Comments

@Qlex42
Copy link

Qlex42 commented Jun 27, 2016

Hi,

It could be great to allow DirectX11 Spout Receiver on offscreen shared OpenGL context.

Shared OpenGL context linked with wglShareLists and activated in offscreen rendering thread do not have any related HWND:
WindowFromDC(wglGetCurrentDC()) return NULL in this case.

spoutGLDXinterop::OpenDirectX only need an HWND for DirectX9 initialization.
DirectX11 initialization do not use any HWND.

Everywhere is spout code, the potential NULL value of hWnd or g_hWnd is forwarded silently except in SpoutSDK.cpp at line 1080

        if(g_hWnd == NULL) {
            return false;
        }

To made this possible, I modify this line like this:

        if(g_hWnd == NULL && interop.m_bUseDX9) {
            return false;
        }

After this modification, everything work perfectly.
Thanks for your concern about this.

@leadedge
Copy link
Owner

I assume that this works for DirectX 11 because CreateDX11device does not need a window handle.

For DirectX 9, hwnd is used for "CreateDeviceEx. The specification says that "For windowed mode, this parameter (hFocusWindow) may be NULL only if the hDeviceWindow member of pPresentationParameters is set to a valid, non-NULL value.", so that means one way or another hwnd is needed, so I included it twice.

CreateDeviceEx probably needs a check for NULL hwnd.

I am surprised that the interop still works. After wglGetCurrentContext(), does wglGetCurrentDC() return NULL?

@Qlex42
Copy link
Author

Qlex42 commented Jun 27, 2016

Indeed wglGetCurrentDC return a non NULL value. So an offscreen OpenGL context have a Device Context but no windows attached on it.

It seems normal because I create offscreen openGL context with this command list:

HDC hDC = getDC(commonMainHWND); // new DC handle
HGLRC hRC = wglCreateContext(hDC);
wglShareLists(commonRC, hRC);
...

Indeed, this seems to work with DirectX11 only. If I remove the hWnd Null check from SpoutSDK.cpp , DirectX9 implementation do not seems to be happy. So if(g_hWnd == NULL && interop.m_bUseDX9) seems to be the best option.
If I understand the specification, maybe DirectX9 in full screen mode can probably benefit from this too. But I have no code available to made this kind of tests.

By the way, thanks a lot for your reactivity.

@leadedge
Copy link
Owner

In practice I find that hwnd can be NULL for CreateDeviceEx, probably because the device is never used for rendering and is is only used to create a shared texture. But the function is never intended to work in this way, so hwnd should be included I think.

You will notice a comment in "OpenSpout" (which gets g_hWnd), so the test for hwnd could be included in "OpenSpout" and would then be redundant in "OpenReceiver".

I will give this more thought before making any changes. Meanwhile it solves the problem for your project.

leadedge pushed a commit that referenced this issue Jul 1, 2016
@leadedge
Copy link
Owner

leadedge commented Jul 1, 2016

Latest commit changed OpenSpout to fail for DX9 if no hwnd.

OpenSpout precedes the tests in OpenReceiver so they are no longer needed. Please let me know if this modification works or does not work.

@Qlex42
Copy link
Author

Qlex42 commented Jul 1, 2016

Hi Lynn,

Indeed your change seems to fix my issue perfectly.
Thanks a lot for this.
Tested with AMD FirePro w2100, w9100 and NVidia 780GTX

Regards.

@leadedge
Copy link
Owner

leadedge commented Jul 1, 2016

OK thanks for the quick response.

It's interesting that your FirePro W2100 works OK. There has been some trouble with FirePro W7100. That seemed to require DirectX 11. It caused some corruption problem and the cause is unknown.

@Qlex42
Copy link
Author

Qlex42 commented Jul 1, 2016

I only test Spout Receiver with W2100 W9100 and 780GTX with DirectX 11 and Memory Share successfully. Because my receiver use offscreen rendering context, I cannot test DirectX9 for now.

For spout Sender, Its working with W2100, W9100, 780GTX, DirectX 9, DirectX 11 and Memory Share perfectly.

(All in Windows 7 SP1 64)
(for AMD my driver version is 15.301.2601)
Hope this can help.

@leadedge
Copy link
Owner

leadedge commented Jul 1, 2016

Yes this information does help and adds to the knowledgebase. Windows 7 might be the key, but who knows. I will close this one for now. Good luck with your project.

@leadedge leadedge closed this as completed Jul 1, 2016
@Qlex42
Copy link
Author

Qlex42 commented Jul 1, 2016

Thanks you for all of this,
Our project with Spout support public release will be ready soon.
I hope to made its logo and appears on the spout.zeal.co web site if possible.

Best regards.

@leadedge
Copy link
Owner

leadedge commented Jul 1, 2016

OK sounds good. Email direct to spout@zeal.co with the logo image - png if it has transparency. Feel free to make a post on the Announcements forum.

Edit : or Showcase as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants