Mail Archives: djgpp/1997/04/22/09:12:23
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 -