Eyescale/Equalizer

How can I change the render target to my own win32 Window?

JiaoJianing opened this issue · 6 comments

I have created my own window by win32 api. Can I pass the window's hwnd to Equalizer, then it will render on my window? Or other way to implement that?

  1. I create my win32 window, then I have a HWND;
  2. In eq::client::wgl::Window::configInitWGLWindow, I don't call _createWGLWindow to create a new window, but use my HWND in step 1;
  3. In eq::client::wgl::Window::setWGLWindowHandle it will call initEventHandler, then in eventHandler.cpp, registerHandler will add a key-value-pair(HWND, EventHandler) to "static lunchbox::PerThread< HandlerMap > _handlers";
  4. But int eventHandler.cpp, when call getEventHandler, "HandlerMap* map = _handlers.get();" will return NULL, then in EventHandler::wndProc, "EventHandler* handler = getEventHandler( hWnd );" return NULL too, not to call "handler->_wndProc( hWnd, uMsg, wParam, lParam );"

So my own window won't receive event!

When i debug to "_handlers.get()", it will call TlsCetValue at last, it returns null! That's the problem!

Can u teach me the proper way ?

I realized that I created window in my app's main thread,but when I call registerHandler I was in your thread. Then in wndProc will be main thread again. when call getEventHandler it will call TlsGetValue but return nothing!

Has anyway to resolve that?

eile commented

You can implement your own window based on the Win32 API. The best is to derive from wgl::WindowIF and implement the abstract methods. And yes, you should execute all calls from the render thread, otherwise it's going to be tricky. IIRC Windows dispatches events to the thread which created the window, so the event handler in the render thread will receive nothing.

It seems to be a lot of work... Have you ever wrote something like that? Is it possible to provide a set of interfaces which can pass a hwnd to eq and render on it in a later version?
Imagine I have that window derived from wgl::WindowIF, when and where should I create it ?And how to pass evevt to eq?Can you give me a simple pseudocode?

eile commented

Not sure we understand each other. eq::wgl::WindowIF is the minimal interface to pass a hwnd to eq and render on it in a later version.

when and where should I create it ?

By it, you mean the actual HWND? Your choice, but be aware of Window's threading contract wrt window creation and event handling.

how to pass evevt to eq?

Again, your choice. Eventually you need to call Config::sendEvent, how you get there is up to you and Window's threading contract. ;)

The default wgl::Window implements everything from the pipe render thread.

Can you give me a simple pseudocode?

wgl::Window implements the simple use case, if you strip it of all the different window hints for creation. If you want a different threading model you'll have to figure it out yourself. eq::x11::Window is a very simple SystemWindow for CPU-based rendering.

Maybe I should read the source code more carefully. Thank you!