//---------------------------------------------------------------------------- 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); }