Horde3D
http://www.horde3d.org/forums/

Change ownership of Render Device & remove global pointer
http://www.horde3d.org/forums/viewtopic.php?f=8&t=1908
Page 1 of 1

Author:  Zuck [ 14.10.2013, 10:58 ]
Post subject:  Change ownership of Render Device & remove global pointer

I think we should change a little bit the way the Render Device, Renderer and Modules classes are in relationship.

At the moment, the structure is:

* Modules has a Render Device pointer. It also duplicate this pointer assigning its value to a global pointer (!!), called gRDI.
* Modules has also a Renderer.
* Renderer uses the Render Device through the global pointer (!!).
* Many classes uses the Render Device through the global pointer (!!).

So there are some kind of circular relationships which make a little bit hard to understand the ownership structure.

In general, it would be more clear and logical to give the ownership of the "Render Device" to the "Renderer" class and remove the ugly gRDI global pointer, so the general structure will become:

* Modules has a Renderer. No more Render Device pointer here (local nor global).
* Renderer has the Render Device with a simple method getRenderDevice().
* Many classes uses the Renderer and could access to the low-level Render Device through its getter.

Linear and logical. Isn't it?

I already have a working patch in my fork.

To provide a retro-compatibility layer, we can use a simple:

Code:
#define gRDI Modules::renderer().getRenderDevice()


And mark it as deprecated (with the idea to remove it in the future).

Author:  Volker [ 14.10.2013, 14:09 ]
Post subject:  Re: Remove gRDI global pointer to Render Device and change i

I guess the reason why marciano has introduced the gRDI pointer was to avoid the function call overhead of Modules::renderer().getRenderDevice() all the time.

Author:  Zuck [ 14.10.2013, 15:05 ]
Post subject:  Re: Remove gRDI global pointer to Render Device and change i

I think that nowadays, with auto compiler optimization, the overhead is practically equal to zero. If not, we can manually cut it to zero simply inlining the getter:

Code:
inline RenderDevice* getRenderDevice() const { return _renderDevice; }

Author:  Volker [ 14.10.2013, 16:53 ]
Post subject:  Re: Remove gRDI global pointer to Render Device and change i

If the RenderDevice becomes a member of Renderer, I guess it would be obvious to use it directly instead of accessing it through using Modules or do I miss something here?

Author:  Zuck [ 15.10.2013, 10:08 ]
Post subject:  Re: Change ownership of Render Device & remove global pointe

Yes, in fact inside the Renderer class it is used directly (except in the static functions, read below), but there are many classes the also use it for low-level rendering, so they can access it through the general "Module::renderer().getRenderDevice()" call.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/