www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/22/09:12:23

From: Doug Eleveld <D DOT J DOT Eleveld AT anest DOT azg DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: RE: Style AND speed in C++? How? Please, I need some radical ideas on this one!
Date: 22 Apr 1997 09:56:13 GMT
Organization: Rijksuniversiteit Groningen
Message-ID: <5ji1vt$51i@info.service.rug.nl>
References: <c=GB%a=_%p=Indigo_Active_Vi%l=CRIANLARICH-970421130655Z-367 AT crianlarich DOT Indigo>
NNTP-Posting-Host: cmb17.med.rug.nl
Mime-Version: 1.0
Lines: 60
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm pretty sure that the overhead of a virtual function call could cause 
you some problems.  It's OK to use virtual function for setup or 
something but don't use it for putpixel or linedraw.  The fastest and 
neatest way that I can think of is to keep function pointers for all the 
fast drawing functions, and fill them in in the constructor of whatever 
video card.  Your base video class can have an non-virtual inine function 
to call the correct function pointer. like this:

// The pointer to the function
void (*_putpixel)(const int x, const int y, const int color);

class videoDriver
   {
   ....
   public:
       inline void putpixel(const int x, const int x, const int color) 
            {
            _putpixel(x,y,color);
            }
   ....
   }

// Here write the fastest putpixel for the S3 driver
void S3putpixel (const int x, const int y, const int color)
    {

    }

class S3videoDriver
   {
   ....
   public:
       S3videoDriver (...)
           {
           ....
           _putpixel = S3putpixel;
           .... 
           }
   ....
   }


  This way you can't use more than 1 video card at a time, but I don't 
think this should be a problem.

If you want maximum speed, don't check that _putpixel is null before you 
call it.  Take as much code as absolutely possible out of the putpixel 
routine.

Of course, always check the assembler output to make sure that the 
videoDriver::putpixel() is in reality inlined properly.

If you have any other questions feel free to mail me, I'm no graphics 
guru but I find this sort of programming interesting...

Doug Eleveld



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019