2016-07-22 19:46:30 +00:00
|
|
|
#ifndef __URDE_TSHADER_HPP__
|
|
|
|
#define __URDE_TSHADER_HPP__
|
2016-07-22 02:32:23 +00:00
|
|
|
|
|
|
|
#include "Graphics/CGraphics.hpp"
|
|
|
|
#include "boo/graphicsdev/GL.hpp"
|
|
|
|
#include "boo/graphicsdev/D3D.hpp"
|
|
|
|
#include "boo/graphicsdev/Metal.hpp"
|
|
|
|
#include "boo/graphicsdev/Vulkan.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-01-29 03:58:16 +00:00
|
|
|
template <class ShaderImp>
|
2016-07-22 19:46:30 +00:00
|
|
|
class TShader
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct IDataBindingFactory
|
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
virtual boo::ObjToken<boo::IShaderDataBinding> BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
|
|
|
ShaderImp& filter)=0;
|
2018-04-26 21:12:20 +00:00
|
|
|
virtual ~IDataBindingFactory() = default;
|
2016-07-22 02:32:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static std::unique_ptr<IDataBindingFactory> m_bindFactory;
|
|
|
|
|
|
|
|
static void Initialize()
|
|
|
|
{
|
|
|
|
if (!CGraphics::g_BooFactory)
|
|
|
|
return;
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
CGraphics::CommitResources(
|
2016-07-22 02:32:23 +00:00
|
|
|
[&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
|
|
|
{
|
|
|
|
switch (ctx.platform())
|
|
|
|
{
|
2017-12-06 03:26:15 +00:00
|
|
|
#if BOO_HAS_GL
|
2016-08-24 04:35:35 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::OpenGL:
|
2017-01-29 03:58:16 +00:00
|
|
|
m_bindFactory.reset(ShaderImp::Initialize(static_cast<boo::GLDataFactory::Context&>(ctx)));
|
2016-07-22 02:32:23 +00:00
|
|
|
break;
|
2017-12-06 03:26:15 +00:00
|
|
|
#endif
|
2016-07-22 02:32:23 +00:00
|
|
|
#if _WIN32
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D11:
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D12:
|
2017-01-29 07:27:48 +00:00
|
|
|
m_bindFactory.reset(ShaderImp::Initialize(static_cast<boo::ID3DDataFactory::Context&>(ctx)));
|
2016-07-22 02:32:23 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Metal:
|
2017-01-29 03:58:16 +00:00
|
|
|
m_bindFactory.reset(ShaderImp::Initialize(static_cast<boo::MetalDataFactory::Context&>(ctx)));
|
2016-07-22 02:32:23 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
2017-01-29 07:27:48 +00:00
|
|
|
m_bindFactory.reset(ShaderImp::Initialize(static_cast<boo::VulkanDataFactory::Context&>(ctx)));
|
2016-07-22 02:32:23 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Shutdown()
|
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
switch (CGraphics::g_BooFactory->platform())
|
|
|
|
{
|
2017-12-06 03:26:15 +00:00
|
|
|
#if BOO_HAS_GL
|
2017-11-05 06:17:12 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::OpenGL:
|
|
|
|
ShaderImp::template Shutdown<boo::GLDataFactory>();
|
|
|
|
break;
|
2017-12-06 03:26:15 +00:00
|
|
|
#endif
|
2017-11-05 06:17:12 +00:00
|
|
|
#if _WIN32
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D11:
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D12:
|
|
|
|
ShaderImp::template Shutdown<boo::ID3DDataFactory>();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Metal:
|
|
|
|
ShaderImp::template Shutdown<boo::MetalDataFactory>();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
|
|
|
ShaderImp::template Shutdown<boo::VulkanDataFactory>();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
static boo::ObjToken<boo::IShaderDataBinding>
|
|
|
|
BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, ShaderImp& filter)
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
2017-01-29 03:58:16 +00:00
|
|
|
return m_bindFactory->BuildShaderDataBinding(ctx, filter);
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
#define URDE_DECL_SPECIALIZE_SHADER(cls) \
|
|
|
|
template <> std::unique_ptr<TShader<cls>::IDataBindingFactory> \
|
2017-11-05 06:17:12 +00:00
|
|
|
TShader<cls>::m_bindFactory;
|
2016-07-22 02:32:23 +00:00
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
#define URDE_SPECIALIZE_SHADER(cls) \
|
|
|
|
template <> std::unique_ptr<TShader<cls>::IDataBindingFactory> \
|
|
|
|
TShader<cls>::m_bindFactory = {}; \
|
2016-07-22 02:32:23 +00:00
|
|
|
\
|
2016-07-22 19:46:30 +00:00
|
|
|
template class TShader<cls>;
|
2016-07-22 02:32:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
#endif // __URDE_TSHADER_HPP__
|