yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
1.5 KiB70 linesraw
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{
11    SLANG_ASSERT(unk);
12    ComPtr<ICastable> castable;
13    if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))))
14    {
15        SLANG_ASSERT(castable);
16    }
17    else
18    {
19        castable = new UnknownCastableAdapter(unk);
20    }
21    return castable;
22}
23
24/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */
25
26void* UnknownCastableAdapter::castAs(const Guid& guid)
27{
28    if (auto intf = getInterface(guid))
29    {
30        return intf;
31    }
32    if (auto obj = getObject(guid))
33    {
34        return obj;
35    }
36
37    if (m_found && guid == m_foundGuid)
38    {
39        return m_found;
40    }
41
42    ComPtr<ISlangUnknown> cast;
43    if (SLANG_SUCCEEDED(m_contained->queryInterface(guid, (void**)cast.writeRef())) && cast)
44    {
45        // Save the interface in the cache
46        m_found = cast;
47        m_foundGuid = guid;
48
49        return cast;
50    }
51    return nullptr;
52}
53
54void* UnknownCastableAdapter::getInterface(const Guid& guid)
55{
56    if (guid == ISlangUnknown::getTypeGuid() || guid == ICastable::getTypeGuid() ||
57        guid == IUnknownCastableAdapter::getTypeGuid())
58    {
59        return static_cast<IUnknownCastableAdapter*>(this);
60    }
61    return nullptr;
62}
63
64void* UnknownCastableAdapter::getObject(const Guid& guid)
65{
66    SLANG_UNUSED(guid);
67    return nullptr;
68}
69
70} // namespace Slang