yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-castable.cpp 2#include "slang-castable.h" 3 4namespace Slang 5{ 6 7/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */ 8 9/* static */ ComPtr < ICastable > CastableUtil ::getCastable (ISlangUnknown * unk ) 10{ 11SLANG_ASSERT (unk ); 12ComPtr < ICastable > castable ; 13if (SLANG_SUCCEEDED (unk -> queryInterface (SLANG_IID_PPV_ARGS (castable .writeRef ())))) 14 { 15SLANG_ASSERT (castable ); 16 } 17else 18 { 19castable = new UnknownCastableAdapter (unk ); 20 } 21return castable ; 22} 23 24/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ 25 26void * UnknownCastableAdapter ::castAs (const Guid & guid ) 27{ 28if (auto intf = getInterface (guid )) 29 { 30return intf ; 31 } 32if (auto obj = getObject (guid )) 33 { 34return obj ; 35 } 36 37if (m_found && guid == m_foundGuid ) 38 { 39return m_found ; 40 } 41 42ComPtr < ISlangUnknown > cast ; 43if (SLANG_SUCCEEDED (m_contained -> queryInterface (guid , (void ** )cast .writeRef ()))&& cast ) 44 { 45// Save the interface in the cache 46m_found = cast ; 47m_foundGuid = guid ; 48 49return cast ; 50 } 51return nullptr ; 52} 53 54void * UnknownCastableAdapter ::getInterface (const Guid & guid ) 55{ 56if (guid == ISlangUnknown ::getTypeGuid ()|| guid == ICastable ::getTypeGuid ()|| 57guid == IUnknownCastableAdapter ::getTypeGuid ()) 58 { 59return static_cast < IUnknownCastableAdapter *> (this ); 60 } 61return nullptr ; 62} 63 64void * UnknownCastableAdapter ::getObject (const Guid & guid ) 65{ 66SLANG_UNUSED (guid ); 67return nullptr ; 68} 69 70}// namespace Slang