• Advertisement

Archived

This topic is now archived and is closed to further replies.

Rasterizer-Design

This topic is 5508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
      
gRasterizer->SetBlendFunc(ONE, ONE);
  
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.
  
     	// ==================================

	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;
	};
      
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]

Share this post


Link to post
Share on other sites
Advertisement
i personally do it so

void GLstate::setBlending( const GLblendfunc &material_blendfunc )
{
if ( material_blendfunc.enable_blend )
{
if ( !current_blendstate.enable_blend )
{
glEnable( GL_BLEND );
CALL_glEnableBlend++;
current_blendstate.enable_blend = true;
}
if ( current_blendstate.blend_SRCfactor != material_blendfunc.blend_SRCfactor ||
current_blendstate.blend_DSTfactor != material_blendfunc.blend_DSTfactor )
{
glBlendFunc( material_blendfunc.blend_SRCfactor, material_blendfunc.blend_DSTfactor );
CALL_glBlendFunc++;
current_blendstate.blend_SRCfactor = material_blendfunc.blend_SRCfactor;
current_blendstate.blend_DSTfactor = material_blendfunc.blend_DSTfactor;
}
}
else
{
if ( current_blendstate.enable_blend )
{
glDisable( GL_BLEND );
CALL_glDisableBlend++;
current_blendstate.enable_blend = false;
}
}
}

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Its the same idea To enable a feature i have this:


    
// ==================================

// this enables a function in the rendering pipline

void CRasterizer::Enable(EnableDisableFunction func)
{
switch(func)
{
case ALPHA_TEST:
if (!m_RanderStates.AlphaTest) // if alpha testing is disabled

{
glEnable(func);
m_RanderStates.AlphaTest = true;
m_StateChanges++;
}
break;


and to disable one:

  
// ==================================

// this disbales a function in the rendering pipline

void CRasterizer::Disable(EnableDisableFunction func)
{
switch(func)
{
case ALPHA_TEST:
if (m_RanderStates.AlphaTest) // if alpha testing is enabled

{
glDisable(func);
m_RanderStates.AlphaTest = false;
m_StateChanges++;
}
break;


It interests me what kind of datatype material_blendfunc.blend_SRCfactor is and if you make it like me with the enum and the warpping around the gl constatns.

[edited by - Austrian Coder on January 22, 2003 1:55:29 PM]

Share this post


Link to post
Share on other sites

  • Advertisement