Beispiel #1
0
//------------------------------------------------------------------------------
ShaderParameters ReadShaderParameters( std::istream& in )
{
	ShaderParameters params;
	static const char COMMENT_CHAR = '#';
	static const std::string ASSIGNMENT_OPERATOR = "=";
	int lineCount = 0;
	std::string lineBuffer;
	while( std::getline( in, lineBuffer ) )
	{
		++lineCount;
		if( lineBuffer.size() == 0 ) continue;
		std::istringstream is( lineBuffer );
		std::string firstToken;
		is >> firstToken; // type
		if( firstToken[ 0 ] == COMMENT_CHAR ) continue;
		if( ShaderParameterType( firstToken ) == ShaderParameter::GLSL_INVALID_TYPE )
		{
			 std::ostringstream os;
			 os << lineCount;
			 throw ShaderParameterException( "Invalid type at line " + os.str() );
		}
		std::string secondToken;
		is >> secondToken; // identifier name
		if( secondToken.size() == 0 )
		{
			 std::ostringstream os;
			 os << lineCount;
			 throw ShaderParameterException( "Missing Identifier at line " + os.str() );
			 break;
		}
        params.push_back( BuildShaderParameter( firstToken, secondToken, is ) );
	}

	return params;
}
Beispiel #2
0
//----------------------------------------------------------------------------
void Renderer::Enable (const Renderable* renderable,
					   const MaterialInstance* instance, int index)
{
	const MaterialPass* pass = instance->GetPass(index);
	ShaderParameters* vparams = instance->GetVertexParameters(index);
	ShaderParameters* pparams = instance->GetPixelParameters(index);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();

	// 更新着色器常量
	vparams->UpdateConstants(renderable, mCamera);
	pparams->UpdateConstants(renderable, mCamera);

	// 设置渲染状态
	SetAlphaProperty(pass->GetAlphaProperty());
	SetCullProperty(pass->GetCullProperty());
	SetDepthProperty(pass->GetDepthProperty());
	SetOffsetProperty(pass->GetOffsetProperty());
	SetStencilProperty(pass->GetStencilProperty());
	SetWireProperty(pass->GetWireProperty());

	// 激活着色器
	Enable(vshader, vparams);
	Enable(pshader, pparams);
}
Beispiel #3
0
//-----------------------------------------------------------------------------
void SetShaderParameters( GLuint program, ShaderParameters& params )
{
    glUseProgram( program );
	ShaderParameters::iterator i = params.begin();
	for( ; i != params.end(); ++i )
	{
		i->SetShaderParameter( program );
	}
    glUseProgram( 0 );
}
//----------------------------------------------------------------------------
void Renderer::Enable (const Renderable* renderable,
					   const MaterialInstance* instance, int index)
{
	const MaterialPass* pass = instance->GetPass(index);

	MaterialPassMap::iterator iter = mMaterialPasses.find(pass);
	PdrMaterialPass *pdrMaterialPass;
	if (iter != mMaterialPasses.end())
	{
		pdrMaterialPass = iter->second;
	}
	else
	{
		pdrMaterialPass = new0 PdrMaterialPass(this, pass);
		mMaterialPasses[pass] = pdrMaterialPass;
	}

	ShaderParameters* vparams = instance->GetVertexParameters(index);
	ShaderParameters* pparams = instance->GetPixelParameters(index);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();

	// 更新着色器常量
	vparams->UpdateConstants(renderable, mCamera);
	pparams->UpdateConstants(renderable, mCamera);

	// 设置渲染状态
	SetAlphaProperty(pass->GetAlphaProperty());
	SetCullProperty(pass->GetCullProperty());
	SetDepthProperty(pass->GetDepthProperty());
	SetOffsetProperty(pass->GetOffsetProperty());
	SetStencilProperty(pass->GetStencilProperty());
	SetWireProperty(pass->GetWireProperty());

	// 激活着色器
	pdrMaterialPass->Enable(this);
	Enable(vshader, vparams);
	Enable(pshader, pparams);
}
//----------------------------------------------------------------------------
void Renderer::Enable (const Renderable* renderable,
					   const MaterialInstance* instance, int index)
{
	const MaterialPass* pass = instance->GetPass(index);

	PdrMaterialPass *pdrMaterialPass = 0;

	if (1 == (int)msRenderers.size())
	{
		if (pass->PdrPointer)
		{
			pdrMaterialPass = (PdrMaterialPass*)pass->PdrPointer;
		}
		else
		{
			pdrMaterialPass = new0 PdrMaterialPass(this, pass);
			mMaterialPasses[pass] = pdrMaterialPass;
			((MaterialPass*)pass)->PdrPointer = pdrMaterialPass;
		}
	}
	else
	{
		MaterialPassMap::iterator iter = mMaterialPasses.find(pass);
		if (iter != mMaterialPasses.end())
		{
			pdrMaterialPass = iter->second;
		}
		else
		{
			pdrMaterialPass = new0 PdrMaterialPass(this, pass);
			mMaterialPasses[pass] = pdrMaterialPass;
		}
	}

	ShaderParameters* vparams = instance->GetVertexParameters(index);
	ShaderParameters* pparams = instance->GetPixelParameters(index);
	VertexShader* vshader = pass->GetVertexShader();
	PixelShader* pshader = pass->GetPixelShader();

	ShaderStruct struc;
	struc.TheRenderable = (Renderable *)renderable;
	struc.TheCamera = (Camera *)mCamera;
	struc.TheEnvirParam = PX2_GR.GetCurEnvirParam();

	// 更新着色器常量
	vparams->UpdateConstants(&struc);
	pparams->UpdateConstants(&struc);

	// 设置渲染状态
	SetAlphaProperty(pass->GetAlphaProperty());
	SetCullProperty(pass->GetCullProperty());
	SetDepthProperty(pass->GetDepthProperty());
	SetOffsetProperty(pass->GetOffsetProperty());
	SetStencilProperty(pass->GetStencilProperty());
	SetWireProperty(pass->GetWireProperty());

	// 激活着色器
	pdrMaterialPass->Enable(this);
	Enable(vshader, vparams);
	Enable(pshader, pparams);
}