If your material supports hardware rendering it can indicate so the user through the interface IMaterialViewportShading. 3ds Max will query for this interface to report what support is offered to the user. This interface is defined as a ULONG, so it uses the override of Animatable::GetInterface( ULONG). The system allows for any material to define if it supports a hardware mode. A simple example is shown below. For a more complete example, see samples\material\StdMaterialViewportShading.cpp.
void mrArchMaterialShading::SetMaterial(MtlBase* pMaterial) { if (NULL != pMaterial && pMaterial->ClassID() == MRARCHMATERIAL_CLASS_ID) { m_pMaterial = pMaterial; } else { m_pMaterial = NULL; } } bool mrArchMaterialShading::IsShadingModelSupported( IN MaterialViewportShading_tmodel) const { DbgAssert(NULL != m_pMaterial); if(!TestDxSupport()) { returnfalse; } switch (model) { case MaterialViewportShading::Standard: case MaterialViewportShading::Hardware: returntrue; default: returnfalse; } } MaterialViewportShading_t mrArchMaterialShading::GetCurrentShadingModel()const { DbgAssert(NULL != m_pMaterial); if (m_pMaterial->TestMtlFlag(MTL_HW_MAT_ENABLED)) { returnMaterialViewportShading::Hardware; } else { returnMaterialViewportShading::Standard; } } bool mrArchMaterialShading::SetCurrentShadingModel( IN MaterialViewportShading_tmodel) { DbgAssert(NULL != m_pMaterial); if (model == GetCurrentShadingModel()) { returntrue; } switch (model) { case MaterialViewportShading::Hardware: m_pMaterial->SetMtlFlag(MTL_HW_MAT_ENABLED); GetCOREInterface()->ForceCompleteRedraw(); break; case MaterialViewportShading::Standard: m_pMaterial->ClearMtlFlag(MTL_HW_MAT_ENABLED); GetCOREInterface()->ForceCompleteRedraw(); break; default: returnfalse; } return true; } int mrArchMaterialShading::GetSupportedMapLevels()const { return 1; }
Key to note is the setting of the material flag MTL_HW_MAT_ENABLED. This is the flag that tells the system to look for all the additional interfaces used to support hardware shading. If this is not set, then the original viewport drawing code is used. Also note that it tests for DirectX and only continues if this is active.