The PocketFrog library by Thierry Tremblay does a good job of this with its
PixelShader class (if I understand what you're trying to do).
You can get the source here: pocketfrog.droneship.com
Here's a few snippets:
struct PixelShader
{
// Override this method to do your custom raster operations.
// src is the source color color specified to the primitive)
// dest is the content of the graphic buffer (dest color)
virtual Pixel operator()( Pixel src, Pixel dest ) const = 0;
};
class Rasterizer : noncopyable
{
public:
/* ... */
void SetDefaultShader();
void SetPixelShader( PixelShader* shader );
/* ... */
};
struct OrPixelShader : PixelShader
{
virtual Pixel operator()( Pixel src, Pixel dest ) const
{
return src | dest;
}
};
It's used like this:
Rasterizer* raster = /* ... */;
OrPixelShader ops;
raster->SetPixelShader(&ops);
/* draw stuff */
raster->SetDefaultShader();
Internally, Rasterizer does something like this:
dest[x][y] = (*currps)(src[x][y], dest[x][y]);
You could also extend this to have a modifier stack with a std::deque,
similar to what gmax and 3d Studio Max do.
- Pete
"Ryan" <pa******@techie.com> wrote in message
news:10*************@corp.supernews.com...
I'm writing a templated class and would like to have a user definable
function to apply algorithmic modifiers. Something alone these lines:
typedef template <typename T> T (*ObjectModifier)(T);
template <typename T>
class Object
{
public:
SetModifier( ObjectModifier om );
ApplyModifier();
private:
T data;
};
The above doesn't actually work though, i.e. it won't compile. But I
think it does a pretty good job of showing the direction I want to go in...is
there a way to do this?
Thanks!