Code: Select all
void COpenGLShaderMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates, IMaterialRendererServices* services)
{
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (VertexShader)
{
// set new vertex shader
#ifdef GL_ARB_vertex_program
Driver->extGlBindProgram(GL_VERTEX_PROGRAM_ARB, VertexShader);
glEnable(GL_VERTEX_PROGRAM_ARB);
#elif defined(GL_NV_vertex_program)
Driver->extGlBindProgram(GL_VERTEX_PROGRAM_NV, VertexShader);
glEnable(GL_VERTEX_PROGRAM_NV);
#endif
}
// set new pixel shader
if (PixelShader[0])
{
GLuint nextShader=PixelShader[0];
if (material.FogEnable)
{
GLint curFogMode;
glGetIntegerv(GL_FOG_MODE, &curFogMode);
// if (Driver->LinearFog && PixelShader[1])
if (curFogMode==GL_LINEAR && PixelShader[1])
nextShader=PixelShader[1];
// else if (!Driver->LinearFog && PixelShader[2])
else if (curFogMode==GL_EXP && PixelShader[2])
nextShader=PixelShader[2];
else if (curFogMode==GL_EXP2 && PixelShader[3])
nextShader=PixelShader[3];
}
#ifdef GL_ARB_fragment_program
Driver->extGlBindProgram(GL_FRAGMENT_PROGRAM_ARB, nextShader);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
#elif defined(GL_NV_fragment_program)
Driver->extGlBindProgram(GL_FRAGMENT_PROGRAM_NV, nextShader);
glEnable(GL_FRAGMENT_PROGRAM_NV);
#endif
}
if (BaseMaterial)
BaseMaterial->OnSetMaterial(material, material, true, services);
}
//let callback know used material
if (CallBack)
CallBack->OnSetMaterial(material);
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
Driver->setActiveTexture(i, material.getTexture(i));
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
Will destroy the the "BaseMaterial-> OnSetMaterial" and the "CallBack-> OnSetMaterial" setting.
when call addHighLevelShaderMaterial(_vs.c_str(), "vertexMain", video::EVST_VS_3_0, _ps.c_str(), "pixelMain", video::EPST_PS_3_0, cb, EMT_TRANSPARENT_ALPHA_CHANNEL);
BaseMaterial->OnSetMaterial(material, material, true, services) will call glEnable(GL_BLEND).
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates) will call glDisable(GL_BLEND).