expmtlControl.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: expmtlControl.h
00004 
00005     DESCRIPTION: Classes to extend materials and shaders. These class
00006                  provide control over whether the exposure control
00007                  is to process the shaded values of the material,
00008                  and whether the material should use the exposure
00009                  control to convert self-illumination, reflection and
00010                  refraction from RGB to scaled physical values.
00011 
00012     CREATED BY: Cleve Ard
00013 
00014     HISTORY:
00015 
00016  *> Copyright (c) 2000, All Rights Reserved.
00017  **********************************************************************/
00018 #pragma once
00019 
00020 #include "ifnpub.h"
00021 #include "imtl.h"
00022 
00023 // =====================================================================
00024 // Implementation classes
00135 #define EXPOSURE_MATERIAL_CONTROL Interface_ID(0x153b0cbc, 0x5d6b0879)
00136 
00137 //==============================================================================
00138 // class ExposureMaterialControl
00139 
00183 class ExposureMaterialControl : public FPMixinInterface {
00184 public:
00185     enum {
00186         kGetNoExposureControl = 0,
00187         kSetNoExposureControl = 1,
00188         kGetInvertSelfIllum = 2,
00189         kSetInvertSelfIllum = 3,
00190         kGetInvertReflect = 4,
00191         kSetInvertReflect = 5,
00192         kGetInvertRefract = 6,
00193         kSetInvertRefract = 7
00194     };
00195 
00196     ExposureMaterialControl() :
00197         mNoExposure(false),
00198         mInvertSelfIllum(false),
00199         mInvertReflect(false),
00200         mInvertRefract(false) {}
00201 
00202     BEGIN_FUNCTION_MAP 
00203         PROP_FNS(kGetNoExposureControl, GetNoExposure,
00204             kSetNoExposureControl, SetNoExposure, TYPE_BOOL);
00205         PROP_FNS(kGetInvertSelfIllum, GetInvertSelfIllum,
00206             kSetInvertSelfIllum, SetInvertSelfIllum, TYPE_BOOL);
00207         PROP_FNS(kGetInvertReflect, GetInvertReflect,
00208             kSetInvertReflect, SetInvertReflect, TYPE_BOOL);
00209         PROP_FNS(kGetInvertRefract, GetInvertRefract,
00210             kSetInvertRefract, SetInvertRefract, TYPE_BOOL);
00211     END_FUNCTION_MAP 
00212 
00220     BOOL GetNoExposure() const { return mNoExposure; }
00221 
00229     virtual void SetNoExposure(BOOL on) { mNoExposure = on != 0; }
00230 
00240     BOOL GetInvertSelfIllum() const { return mInvertSelfIllum; }
00241 
00251     virtual void SetInvertSelfIllum(BOOL on) { mInvertSelfIllum = on != 0; }
00252 
00261     BOOL GetInvertReflect() const { return mInvertReflect; }
00262 
00271     virtual void SetInvertReflect(BOOL on) { mInvertReflect = on != 0; }
00272 
00281     BOOL GetInvertRefract() const { return mInvertRefract; }
00282 
00291     virtual void SetInvertRefract(BOOL on) { mInvertRefract = on != 0; }
00292 
00293     ULONG isNoExposure() const { return mNoExposure ? MTLREQ_NOEXPOSURE : 0; }
00294     bool isInvertSelfIllum() const { return !mNoExposure & mInvertSelfIllum; }
00295     bool isInvertReflect() const { return !mNoExposure & mInvertReflect; }
00296     bool isInvertRefract() const { return !mNoExposure & mInvertRefract; }
00297 
00311     IOResult Save(ISave* isave);
00312     
00336     IOResult Load(ILoad* iload);
00337 
00338 protected:
00339     enum {
00340         DATA_CHUNK = 0x322
00341     };
00342 
00343     IOResult write(ISave* isave, bool& b);
00344     IOResult read(ILoad* iload, bool& b);
00345 
00346     bool                mNoExposure;
00347     bool                mInvertSelfIllum;
00348     bool                mInvertReflect;
00349     bool                mInvertRefract;
00350 };
00351 
00352 inline IOResult ExposureMaterialControl::Save(ISave* isave)
00353 {
00354     isave->BeginChunk(DATA_CHUNK);
00355     IOResult res;
00356     if ((res = write(isave, mNoExposure)) == IO_OK
00357             && (res = write(isave, mInvertSelfIllum)) == IO_OK
00358             && (res = write(isave, mInvertReflect)) == IO_OK)
00359         res = write(isave, mInvertRefract);
00360     isave->EndChunk();
00361     return res;
00362 }
00363 
00364 inline IOResult ExposureMaterialControl::Load(ILoad* iload)
00365 {
00366     IOResult res;
00367     USHORT id;
00368     while (IO_OK==(res=iload->OpenChunk())) {
00369         switch(id = iload->CurChunkID())  {
00370         case DATA_CHUNK:
00371             if ((res = read(iload, mNoExposure)) == IO_OK
00372                     && (res = read(iload, mInvertSelfIllum)) == IO_OK
00373                     && (res = read(iload, mInvertReflect)) == IO_OK)
00374                 res = read(iload, mInvertRefract);
00375             break;
00376         }
00377 
00378         iload->CloseChunk();
00379         if (res!=IO_OK) 
00380             return res;
00381     }
00382     return IO_OK;
00383 }
00384 
00385 inline IOResult ExposureMaterialControl::write(ISave* isave, bool& b)
00386 {
00387     DWORD n;
00388     IOResult res = isave->Write(&b, sizeof(b), &n);
00389     if (res != IO_OK)
00390         return res;
00391     return n == sizeof(b) ? IO_OK : IO_ERROR;
00392 }
00393 
00394 inline IOResult ExposureMaterialControl::read(ILoad* iload, bool& b)
00395 {
00396     DWORD n;
00397     IOResult res = iload->Read(&b, sizeof(b), &n);
00398     if (res != IO_OK)
00399         return res;
00400     return n == sizeof(b) ? IO_OK : IO_ERROR;
00401 }
00402 
00403 
00404 inline ExposureMaterialControl* GetExposureMaterialControl(InterfaceServer* mtl)
00405 {
00406     return static_cast<ExposureMaterialControl*>(
00407         mtl->GetInterface(EXPOSURE_MATERIAL_CONTROL));
00408 }
00409 
00410 //==========================================================================================
00411 
00414 class ExposureMaterialControlDesc : public FPInterfaceDesc {
00415 public:
00416     ExposureMaterialControlDesc(
00417         ClassDesc& cd,
00418         int         idsDescrString,
00419         int         idsNoExposureString,
00420         int         idsInvertSelfIllumString,
00421         int         idsInvertReflectString,
00422         int         idsInvertRefractString
00423     ) :
00424         FPInterfaceDesc(EXPOSURE_MATERIAL_CONTROL, _M("ExposureMaterialControl"),
00425                 idsDescrString, &cd, FP_MIXIN,
00426             properties,
00427                 ExposureMaterialControl::kGetNoExposureControl,
00428                     ExposureMaterialControl::kSetNoExposureControl, _M("noExposureControl"),
00429                     idsNoExposureString, TYPE_BOOL,
00430                 ExposureMaterialControl::kGetInvertSelfIllum,
00431                     ExposureMaterialControl::kSetInvertSelfIllum, _M("exposureControlInvertSelfIllum"),
00432                     idsInvertSelfIllumString, TYPE_BOOL,
00433                 ExposureMaterialControl::kGetInvertReflect,
00434                     ExposureMaterialControl::kSetInvertReflect, _M("exposureControlInvertReflection"),
00435                     idsInvertReflectString, TYPE_BOOL,
00436                 ExposureMaterialControl::kGetInvertRefract,
00437                     ExposureMaterialControl::kSetInvertRefract, _M("exposureControlInvertRefraction"),
00438                     idsInvertRefractString, TYPE_BOOL,
00439             end) {}
00440 }; 
00441 
00444 template<class T, class B> class ExposureMaterialControlImp : public B
00445 {
00446 public:
00447     // Visual Studio has problem with using B::GetInterface
00448     // This workaround is to define GetInterface(ULONG id)
00449     // rather than using B::GetInterface. 
00450     void* GetInterface(ULONG id) { return B::GetInterface(id); }
00451 
00452     BaseInterface* GetInterface(Interface_ID id) {
00453         if (id == EXPOSURE_MATERIAL_CONTROL)
00454             return static_cast<ExposureMaterialControl*>(this);
00455         return B::GetInterface(id);
00456     }
00457 
00458     FPInterfaceDesc* GetDesc() { return &T::msExpMtlControlDesc; }
00459 
00460 private:
00461 };
00462 
00465 template<class B> class AddExposureMaterialControl : public B, public ExposureMaterialControl
00466 {
00467 public:
00468     using B::GetInterface;
00469 };
00470