Skip to main content
GameDev.net gamedev.net
🔒 Locked

before i possibly kill my program...

Started by billybob Jan 27, 2003 at 3:49 AM 3 replies 100+ views
Original Post
billybob
billybob
i have a multi api system set up that uses a pure base class that defines all the rendering functions that will be needed. there are some things performed in these functions that will be the same for every api implementation, so i was wondering if it would kill the performance too much to do this:
class CBaseRenderer
{
   virtual void iSomeRenderingFunction(...) = 0;
   virtual void iSomeRedneringFunction2(...) = 0;
   virtual void iSomeRenderingFunction3(...) = 0;
   ...
public:
   CBaseRenderer();
   virtual ~CBaseRenderer();

   void SomeRenderingFunction(...)
   {
       //stuff thats performed no matter what the api
       iSomeRenderingFunction(...);
   }
   void SomeRenderingFunction2(...)
   {
       //same stuff thats performed every api
       iSomeRenderingFunction2(...);
   }
   ...
};
  
how bad would that hurt performance? there is still only one virtual function call, but it would still be a huge pain to change it and see what happens, and it'd be a way bigger pain if it turned out bad it also wouldn't really change how i wrote my code, but if someone downloaded it and decided to write a glide one or something like that, they wouldn't have to do that redundant stuff that the base class function does. btw, i chose 'i' just for 'implementation' or something, it was random, it has no significance. [edited by - billybob on January 27, 2003 4:49:55 AM]
Qw3r7yU10p!
Qw3r7yU10p!
if you''re worried about virtual calls don''t use c++
billybob
billybob
err, thanks anyway...
Qoy
Qoy
It depends on what level the virtual function calls are at in your pipeline. You probably don''t want to make a virtual call for every triangle, but one for each model probably won''t hurt. A virtual call is only one pointer derefence slower than a regular call, and that isn''t that much. Anyway, lots of commercial 3D games do it basically the way you''re describing here.
Waverider
Waverider
As long as the routines themselves are well optimized to send your model structures to the rendering pipeline, it shouldn''t be a problem.

The general consensus is that function calls are most costly at the innermost portion of the loop. If each function loops through your structures and submits them in an optimized way to the renderer, your program will spend most of its time in those loops, and the virtual function call to get there would have little impact on the speed of your program.

So, basically, what Qoy said, for the above reasons.
It's not what you're taught, it's what you learn.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.