CNullDriver
CNullDriver
Hi,
i'm trying to understand the code and ideas of implementations behind the irrlicht project.
I didn't really understand why the Videodriverclasses like CD3D9Driver is
derived from CNullDriver.
What is the idea behind CNullDriver?
Why is it not enough deriving from IVideoDriver?
Like CD3D9Driver : public IVideoDriver
Maybee some of you can help me understanding this.
Thank you
i'm trying to understand the code and ideas of implementations behind the irrlicht project.
I didn't really understand why the Videodriverclasses like CD3D9Driver is
derived from CNullDriver.
What is the idea behind CNullDriver?
Why is it not enough deriving from IVideoDriver?
Like CD3D9Driver : public IVideoDriver
Maybee some of you can help me understanding this.
Thank you
The reason is code reuse simply. CNullDriver does the generic part of the implementation of the IVideoDriver interface. Else this interface had to be implemented inside a header, which were acceptable for smaller functions, but not for 40k big source. Other alternative were to implement those functions in each of the drivers, but such code duplication is bad for obvious reasons.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
But you have to be really careful with this. The camera nodes also do this inheritance and thus the interface of a specialized camera cannot be extended that easily.
And for the drivers some additional stubs would also help, e.g. in preparation for DirectX10 (many methods are shared between all those drivers) and for OpenGL derivates such as OpenGL-ES.
And for the drivers some additional stubs would also help, e.g. in preparation for DirectX10 (many methods are shared between all those drivers) and for OpenGL derivates such as OpenGL-ES.
Because you then had to write the same code in the opengl driver and the software drivers. Why write the same code four times, when a single time suffices?
General info on this topic:
http://en.wikipedia.org/wiki/Code_reuse
The code reuse technique used in this case:
http://en.wikipedia.org/wiki/Implementation_inheritance
Hope this makes it clearer.
General info on this topic:
http://en.wikipedia.org/wiki/Code_reuse
The code reuse technique used in this case:
http://en.wikipedia.org/wiki/Implementation_inheritance
Hope this makes it clearer.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Because some methods are exactly the same for all drivers. And if you call IVideoDriverObject->redundantMethod() it searches in the specific driver class first, then in its parent and so on. That way it's best to put the methods the nearest to the root as possible. The interfaces are kept as small as possible (as said before) so the NullDriver is the best solution for larger methods for all drivers. It's simply the way it's done in OO programming.
???Saturn wrote:Because you then had to write the same code in the opengl driver and the software drivers. Why write the same code four times, when a single time suffices?
But the code is already written in DirectX.cpp files in OpenGL.cpp etc..
So the virtual prototypes of IVideoDriver can get their bodies from directx.cpp or opengl.cpp etc..
Why need a seperate Class CNullDriver for this?
BUT THEY ARE implemented again and again ...hybrid wrote:No you do not need to implement them again if a superclass already implements them (and they are declared virtual).
Have a look at the DirectX.cpp and opengl.cpp files.
And you will see that they all have a function body with driverdependent code ...
So,why you always say these methods only implemented in CNullDriver? Thats not true,all the methods got code in the driverXXX.cpp files too!
I really see no difference between these cpp files and the nulldriver cpp file.
The Nulldriver just have the same methods implemented like the directx and opengl driver.cpp files.
So it's only just another classname,thats all i can see ...