// Render - render this model (only) //----------------------------------------------------------------------------- void CPUTModelDX11::RenderShadow(CPUTRenderParameters &renderParams) { CPUTRenderParametersDX *pParams = (CPUTRenderParametersDX*)&renderParams; CPUTCamera *pCamera = pParams->mpCamera; #ifdef SUPPORT_DRAWING_BOUNDING_BOXES if( renderParams.mShowBoundingBoxes && (!pCamera || pCamera->mFrustum.IsVisible( mBoundingBoxCenterWorldSpace, mBoundingBoxHalfWorldSpace ))) { DrawBoundingBox( renderParams ); } #endif if( !renderParams.mDrawModels ) { return; } // TODO: add world-space bounding box to model so we don't need to do that work every frame if( !pParams->mRenderOnlyVisibleModels || !pCamera || pCamera->mFrustum.IsVisible( mBoundingBoxCenterWorldSpace, mBoundingBoxHalfWorldSpace ) ) { // Update the model's render states only once (and then iterate over materials) UpdateShaderConstants(renderParams); CPUTMaterialDX11 *pMaterial = (CPUTMaterialDX11*)(mpShadowCastMaterial); pMaterial->SetRenderStates(renderParams); // loop over all meshes in this model and draw them for(UINT ii=0; ii<mMeshCount; ii++) { ((CPUTMeshDX11*)mpMesh[ii])->DrawShadow(renderParams, this); } } }
//----------------------------------------------------------------------------- void CPUTModelDX11::DrawBoundingBox(CPUTRenderParameters &renderParams) { CPUTRenderParametersDX *pParams = (CPUTRenderParametersDX*)&renderParams; UpdateShaderConstants(renderParams); CPUTMaterialDX11 *pMaterial = (CPUTMaterialDX11*)mpBoundingBoxMaterial; pMaterial->SetRenderStates(renderParams); ((CPUTMeshDX11*)mpBoundingBoxMesh)->Draw(renderParams, this); }
//----------------------------------------------------------------------------- void CPUTModelDX11::DrawBoundingBox(CPUTRenderParameters &renderParams) { UpdateShaderConstants(renderParams); UINT index = mpSubMaterialCount[0] + CPUT_MATERIAL_INDEX_BOUNDING_BOX; CPUTMaterialDX11 *pMaterial = (CPUTMaterialDX11*)(mpMaterial[0][index]); pMaterial->SetRenderStates(renderParams); ((CPUTMeshDX11*)mpBoundingBoxMesh)->Draw(renderParams, mpInputLayout[0][index]); }
// Render this model. Render only this model, not its children or siblings. //----------------------------------------------------------------------------- void CPUTModelDX11::Render(CPUTRenderParameters &renderParams, int materialIndex) { CPUTRenderParametersDX *pParams = (CPUTRenderParametersDX*)&renderParams; CPUTCamera *pCamera = pParams->mpCamera; // TODO: Move bboxDirty to member and set only when model moves. bool bboxDirty = true; if( bboxDirty ) { UpdateBoundsWorldSpace(); } #ifdef SUPPORT_DRAWING_BOUNDING_BOXES if( renderParams.mShowBoundingBoxes && (!pCamera || pCamera->mFrustum.IsVisible( mBoundingBoxCenterWorldSpace, mBoundingBoxHalfWorldSpace ))) { DrawBoundingBox( renderParams ); } #endif if( !renderParams.mDrawModels ) { return; } if( !pParams->mRenderOnlyVisibleModels || !pCamera || pCamera->mFrustum.IsVisible( mBoundingBoxCenterWorldSpace, mBoundingBoxHalfWorldSpace ) ) { // Update the model's constant buffer. // Note that the materials reference this, so we need to do it only once for all of the model's meshes. UpdateShaderConstants(renderParams); // loop over all meshes in this model and draw them for(UINT ii=0; ii<mMeshCount; ii++) { UINT finalMaterialIndex = GetMaterialIndex(ii, materialIndex); ASSERT( finalMaterialIndex < mpSubMaterialCount[ii], _L("material index out of range.")); CPUTMaterialDX11 *pMaterial = (CPUTMaterialDX11*)(mpMaterial[ii][finalMaterialIndex]); pMaterial->SetRenderStates(renderParams); ((CPUTMeshDX11*)mpMesh[ii])->Draw(renderParams, mpInputLayout[ii][finalMaterialIndex]); } } }