IMtlRender_Compatibility.h

Go to the documentation of this file.
00001  /**********************************************************************
00002  
00003     FILE:           IMtlRender_Compatibility.h
00004 
00005     DESCRIPTION:    Public interface for determining compatibility
00006                     between a material/texmap and a renderer.
00007 
00008                     The interface also allows 3rd party material/map plugins to
00009                     use custom icons in the material/map browser.
00010 
00011     CREATED BY:     Daniel Levesque, Discreet
00012 
00013     HISTORY:        Created 14 April 2003
00014 
00015  *> Copyright (c) 2003, All Rights Reserved.
00016  **********************************************************************/
00017 #pragma once
00018 
00019 #include "ifnpub.h"
00020 #include "baseinterface.h"
00021 #include <CommCtrl.h> // for HIMAGELIST
00022 #include "plugapi.h"
00023 
00024 // forward declarations
00025 class Renderer;
00026 class MtlBase;
00027 
00028 #define IMTLRENDER_COMPATIBILITY_MTLBASE_INTERFACEID Interface_ID(0x5537445b, 0x70a97e02)
00029 #define IMTLRENDER_COMPATIBILITY_RENDERER_INTERFACEID Interface_ID(0x25d24114, 0xdbe505f)
00030 
00031 //==============================================================================
00032 // class IMtlRender_Compability_MtlBase
00057 //==============================================================================
00058 class IMtlRender_Compatibility_MtlBase : public FPStaticInterface {
00059 
00060 public:
00061 
00064     void Init(ClassDesc& classDesc);
00065 
00069     virtual bool IsCompatibleWithRenderer(ClassDesc& rendererClassDesc) = 0;
00070 
00080     #pragma warning(push)
00081     #pragma warning(disable:4100)
00082     virtual bool GetCustomMtlBrowserIcon(
00083         HIMAGELIST& hImageList,
00084         int& inactiveIndex,
00085         int& activeIndex,
00086         int& disabledIndex
00087     ) 
00088     { 
00089         return false; 
00090     }
00091     #pragma warning(pop)
00092 };
00093 
00094 // Given the class descriptor of a Mtl/Texmap plugin, this returns its compatibility interface (if it exists).
00095 inline IMtlRender_Compatibility_MtlBase* Get_IMtlRender_Compability_MtlBase(ClassDesc& mtlBaseClassDesc) {
00096 
00097     return static_cast<IMtlRender_Compatibility_MtlBase*>(mtlBaseClassDesc.GetInterface(IMTLRENDER_COMPATIBILITY_MTLBASE_INTERFACEID));
00098 }
00099 
00100 //==============================================================================
00101 // class IMtlRender_Compatibility_Renderer
00118 //==============================================================================
00119 class IMtlRender_Compatibility_Renderer : public FPStaticInterface  {
00120 
00121 public:
00122 
00125     void Init(ClassDesc& classDesc);
00126 
00131     virtual bool IsCompatibleWithMtlBase(ClassDesc& mtlBaseClassDesc) = 0;
00132 };
00133 
00134 // Given the class descriptor of a Renderer plugin, this returns its compatibility interface (if it exists).
00135 inline IMtlRender_Compatibility_Renderer* Get_IMtlRender_Compatibility_Renderer(ClassDesc& rendererClassDesc) {
00136 
00137     return static_cast<IMtlRender_Compatibility_Renderer*>(rendererClassDesc.GetInterface(IMTLRENDER_COMPATIBILITY_RENDERER_INTERFACEID));
00138 }
00139 
00141 // bool AreMtlAndRendererCompatible(ClassDesc&, ClassDesc&)
00146 inline bool AreMtlAndRendererCompatible(ClassDesc& mtlBaseClassDesc, ClassDesc& rendererClassDesc) {
00147 
00148     IMtlRender_Compatibility_MtlBase* mtlBaseCompatibility = Get_IMtlRender_Compability_MtlBase(mtlBaseClassDesc);
00149     IMtlRender_Compatibility_Renderer* rendererCompatibility = Get_IMtlRender_Compatibility_Renderer(rendererClassDesc);
00150 
00151     if((mtlBaseCompatibility == NULL) && (rendererCompatibility == NULL)) {
00152         // No compatibility info: compatible by default
00153         return true;
00154     }
00155     else if((mtlBaseCompatibility != NULL) && mtlBaseCompatibility->IsCompatibleWithRenderer(rendererClassDesc)) {
00156         // Material says it's compatible with the renderer: compatible
00157         return true;
00158     }
00159     else if((rendererCompatibility != NULL) && rendererCompatibility->IsCompatibleWithMtlBase(mtlBaseClassDesc)) {
00160         // Renderer says it's compatible with the material: compatible
00161         return true;
00162     }
00163     else {
00164         // Neither material nor renderer says it's compatible: incompatible
00165         return false;
00166     }
00167 }
00168 
00169 //==============================================================================
00170 // class IMtlRender_Compability_MtlBase inlined methods
00171 //==============================================================================
00172 
00173 inline void IMtlRender_Compatibility_MtlBase::Init(ClassDesc& classDesc) {
00174 
00175     LoadDescriptor(IMTLRENDER_COMPATIBILITY_MTLBASE_INTERFACEID, _M("IMtlRender_Compability_MtlBase"), 0, &classDesc, 0, end);
00176 }
00177 
00178 //==============================================================================
00179 // class IMtlRender_Compatibility_Renderer inlined methods
00180 //==============================================================================
00181 
00182 inline void IMtlRender_Compatibility_Renderer::Init(ClassDesc& classDesc) {
00183 
00184     LoadDescriptor(IMTLRENDER_COMPATIBILITY_RENDERER_INTERFACEID, _M("IMtlRender_Compability_Renderer"), 0, &classDesc, 0, end);
00185 }
00186