A little suggestion...

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Haddock
Posts: 15
Joined: Tue Dec 16, 2003 7:19 pm

A little suggestion...

Post by Haddock »

Currently, extending the Irrlicht engine is a bit complicated...
Let's take an example : I would like to extend the DirectX driver in order to support pixel and vertex shaders. I would write a CVideoDirectX8 derivated class, let's say CVideoDirectX8Ex, in which I write new methods.
After that, I have to modify IVideoDriver in order to add new features interface, and I have to fill CVideoNull class with null methods for these features. I have to do this to allow OpenGl driver to compile properly.
As you can see, I have made modifications in several files, and the concern here is that when there is a new engine available, I have to write again all my modifications.
My suggestion for this issue would be adding a COM-like feature in IUnknown.h, a virtual method called QueryInterface. As each Irrlicht object derivates from IUnknown, each object can implement this method which return a given interface if the object support it. Let's talke the previous example. My CVideoDirectX8Ex would derivate from CVideoDirectX8 and from IVideoDirectX8Ex. IVideoDirectX8Ex is an interface with abstract methods which exposes my new features. I don't expose these new features in IVideoDriver anymore. Of course the implementation of these new features remains in the CVideoDirectX8Ex class.
The Query method would be like bool QueryMethod(IID id, void** object_interface). In COM, IID is an unique 128 bit id, here it can be only a 32 bit id. The implementation of this method in CVideoDirectX8Ex would be very simple :
if (id == IID_VideoDirectX8Ex)
{
*object_interface = (IVideoDirectX8Ex*)this ;
return true ;
}
return QueryInterface::QueryInterface(id,object_interface) ;


When my game wants to use these new features, I just have to query this interface, and if it is available, I can use it. If I use an OpenGl driver, it just doesn't return an interface to IVideoDirectX8Ex.
The big advantage of this method is that I don't modify the original source code, I just extend it. So when a new version of Irrlicht is available, it theorically automatically works with my extensions.

Ok, I have to make another modification in the source code : when the object is created, I have to write new CVideoDirectX8Ex instead of new CVideoDirectX8. Here again, I don't know how, there is surely a way to externalize the object creation.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Yep, I already thought about a more plugin-style IVideoDriver interface. I also would like to change the way materials work (but keep them backward-compatible). With the new approach which I have in mind it would be easy to add for example vertex and pixel shaders. But all this could take some time.
Miwa
Posts: 28
Joined: Wed Feb 18, 2004 10:48 pm

Post by Miwa »

I do a hack to do something like this (I need 3d line drawing in directx).

I just added a function that calls DrawPrimitiveUP to the directx8 driver file, and then I cheat and cast my driver pointer to a CVideoDirectX8* and call my function.

Hacky as heck, but hey, it works, and I'm on a tight schedule.

Dunno what to do about ogl, as I turn off everything but dx :)
Post Reply