beginScene VideoData is ignored when using OpenGL driver

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Piranha
Posts: 3
Joined: Fri Apr 29, 2016 1:47 pm

beginScene VideoData is ignored when using OpenGL driver

Post by Piranha »

Hi,

I just started with Irrlicht(Lime) and want to render different views on different WinForm panels.

I do for each panel a function beginScene with a videodata parameter containing the current panel handle.

When I start the application with driver type Direct3D9 it works exactly like expected.
When I use OpenGL it only renders in the first panel (that one I provided at createDevice) and no other panel.

How do I get it working with OpenGL?

Image
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: beginScene VideoData is ignored when using OpenGL driver

Post by Foaly »

Hey there!
Documentation wrote:videoData Handle of another window, if you want the bitmap to be displayed on another window. If this is an empty element, everything will be displayed in the default window. Note: This feature is not fully implemented for all devices.
So this means it may or may not work with all drivers I guess.


But looking into the source code, it looks like the OpenGL driver contains the necessary code for that.
So maybe you are passing a (partly) invalid piece of videoData.

How do you create it? Just by calling "new ExposedVideoData()"?
This is how I'd do it (with Lime):

Code: Select all

 
VideoDriver driver = ...; //I guess you got a video driver from somewhere...
ExposedVideoData data = driver.ExposedVideoData;
data.WindowID = ...; //replace with your window ID
 
//now you can pass "data" with your BeginScene call
 
driver.BeginScene(..., data, ...);
 
I hope this works.
Piranha
Posts: 3
Joined: Fri Apr 29, 2016 1:47 pm

Re: beginScene VideoData is ignored when using OpenGL driver

Post by Piranha »

Yes I use the 'old' ExposedVideoData that I got from the driver and change the WindowID just like in your example.
Looks like I have to stick with Direct3D9 :(
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: beginScene VideoData is ignored when using OpenGL driver

Post by Foaly »

Hey there,

I looked into this further, and it looks like it should work, and it probably works with Linux, but for the window handle is simply ignored in the code, it only changes the context.
So if you are able to generate a second context, you will be able to render into a separate window / panel.
The thing is there actually is a ContextManager class, which allows you to generate a new context, but it sadly re-uses the handle set in the constructor.

I could not find a workaround, and this looks like something really useful, so I hope it gets implemented soon.

Sorry :/
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Workaround

Post by Foaly »

I finally found a way to get this working, but it's probably not the best solution...

So anyways, here's a method which returns an ExposedVideoData object that will work with both D3D and GL.

Code: Select all

public ExposedVideoData GetVideoDataFromHWND(IntPtr hwnd, IrrlichtDevice device, IrrlichtCreationParameters creationParams)
        {
            VideoDriver driver = device.VideoDriver;
            if (driver.DriverType == DriverType.OpenGL)
            {
                ContextManager contextMan = device.ContextManager;
                ExposedVideoData dummyVideoData = driver.ExposedVideoData;
                dummyVideoData.WindowID = hwnd;
                contextMan.Initialize(creationParams, dummyVideoData);
                contextMan.GenerateSurface();
                contextMan.GenerateContext();
 
                ExposedVideoData videoData = contextMan.Context;
                videoData.RenderingContext = dummyVideoData.RenderingContext;
   
                return videoData;
            }
            else
            {
                ExposedVideoData videoData = driver.ExposedVideoData;
                videoData.WindowID = hwnd;
                return videoData;
            }
        }
It needs the IrrlichtCreation params you used for creating your IrrlichtDevice, e.g. like this:

Code: Select all

 IrrlichtCreationParameters deviceParams = new IrrlichtCreationParameters();
            deviceParams.DriverType = DriverType.OpenGL;
            deviceParams.WindowID = <some_HWND>; //put a handle here, so it does not create a separate Irrlicht window
            device = IrrlichtDevice.CreateDevice(deviceParams);
You have to pass the object you got from GetVideoDataFromHWND with every BeginScene call corresponding to that handle.
Also, after you've initialized the ExposedVideoData, loading textures (which may be loaded automatically with models!) will fail!
So you have to load them before or, you can reset the video data before loading the textures every time like this:

Code: Select all

public static bool ResetContext(IrrlichtDevice device)
        {
            ContextManager contextMan = device.ContextManager;
            if (contextMan != null)
                return contextMan.ActivateContext(device.VideoDriver.ExposedVideoData);
            return true;
        }
After this, you won't have to re-create the ExposedVideoData objects, they will continue to work.

I hope this is helpful
Piranha
Posts: 3
Joined: Fri Apr 29, 2016 1:47 pm

Re: beginScene VideoData is ignored when using OpenGL driver

Post by Piranha »

Hi, thank you so much for your solution! :)
Post Reply