// Render - render this model (only) //----------------------------------------------------------------------------- void CPUTModelOGL::Render(CPUTRenderParameters &renderParams, int materialIndex) { CPUTCamera* pCamera = renderParams.mpCamera; UpdateBoundsWorldSpace(); if( renderParams.mDrawModels && !renderParams.mRenderOnlyVisibleModels || !pCamera || pCamera->mFrustum.IsVisible( mBoundingBoxCenterWorldSpace, mBoundingBoxHalfWorldSpace ) ) { 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 < mpLayoutCount[ii], _L("material index out of range.")); CPUTMaterialEffect *pMaterialEffect = (CPUTMaterialEffect*)(mpMaterialEffect[ii][finalMaterialIndex]); mDrawModelCallBackFunc(this, renderParams, mpMesh[ii], pMaterialEffect, NULL, NULL); } } }
// 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]); } } }