Original Post
Hi everybody!
I am currently working on speed up my little engine. So i have wirtten a small but powerfull class, i think.
Lets say somebody wants to change the blendfunction, then he or she will do it like this:
But you think now whats the advantage of this is? Ok i will tell it you. My engine can minimize with this and a good organiced shader tree the state changes to a minimum.
So now for me the only critical point are the enums, because i have no better idea to this. I define e.g.: ONE = GL_ONE. Also i know no way how i would make it, if i add direct x support in the future.
Now i want to know, what you think about it? How can i make it better?
Greets, Austrian Coder
PS: The enum and the struct are in a header and the other one in a sourcefile.
[edited by - Austrian Coder on January 22, 2003 9:09:55 AM]
[edited by - Austrian Coder on January 22, 2003 9:10:50 AM]
gRasterizer->SetBlendFunc(ONE, ONE);
// ==================================
void CRasterizer::SetBlendFunc(BlendFactor sfactor, BlendFactor dfactor)
{
// check if we must change the current render state
if (m_RanderStates.SourceBlendFactor != sfactor || m_RanderStates.DestinationBlendFactor != dfactor)
{
// we must set net blend factors
m_RanderStates.SourceBlendFactor = sfactor;
m_RanderStates.DestinationBlendFactor = dfactor;
// set new factors
glBlendFunc(sfactor, dfactor);
// count changes
m_StateChanges++;
}
}
// ==================================
// all possible Blendfactors
enum BlendFactor
{
ZERO = GL_ZERO, // The source/destination color is equal to (0,0,0,0)
ONE = GL_ONE, // Use the current source/destination color
DST_COLOR = GL_DST_COLOR, // Multiply the source/destination color by the destination/source color
ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR, // Multiply the source/destination color by [(1,1,1,1) - destination/source color]
SRC_ALPHA = GL_SRC_ALPHA, // Multiply the source/destination color by the source alpha value
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA, // Multiply the source/destination color by (1 - source alpha value)
DST_ALPHA = GL_DST_ALPHA, // Multiply the source/destination color by the destination alpha value
ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA, // Multiply the source/destination color by (1 - destination alpha value)
SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE // Multiply the source/destination color by the minimum of the source and (1 - destination)
};
// ==================================
// the current render states
struct RenderStates_t
{
bool AlphaTest;
bool DepthTest;
bool StencilTest;
bool Blend;
bool CullFace;
bool Lighting;
bool Texture;
int TextureID;
BlendFactor SourceBlendFactor;
BlendFactor DestinationBlendFactor;
DepthFunction DepthFunc;
ShadeModel ShadeMod;
CullMode CullMod;
FrontFace FrontFac;
};