metaforce/Runtime/Graphics/Shaders/TMultiBlendShader.hpp

92 lines
2.9 KiB
C++
Raw Normal View History

2016-08-17 01:58:53 +00:00
#ifndef __URDE_TMULTIBLENDSHADER_HPP__
#define __URDE_TMULTIBLENDSHADER_HPP__
#include "Graphics/CGraphics.hpp"
#include "boo/graphicsdev/GL.hpp"
#include "boo/graphicsdev/D3D.hpp"
#include "boo/graphicsdev/Metal.hpp"
#include "boo/graphicsdev/Vulkan.hpp"
#include "Camera/CCameraFilter.hpp"
namespace urde
{
2017-01-29 03:58:16 +00:00
template <class ShaderImp>
2016-08-17 01:58:53 +00:00
class TMultiBlendShader
{
public:
struct IDataBindingFactory
{
virtual boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
2017-06-01 05:34:24 +00:00
EFilterType type, ShaderImp& filter)=0;
2016-08-17 01:58:53 +00:00
};
static std::unique_ptr<IDataBindingFactory> m_bindFactory;
static boo::GraphicsDataToken m_gfxToken;
static void Initialize()
{
if (!CGraphics::g_BooFactory)
return;
m_gfxToken = CGraphics::CommitResources(
[&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
switch (ctx.platform())
{
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-08-17 01:58:53 +00:00
break;
#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-08-17 01:58:53 +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-08-17 01:58:53 +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-08-17 01:58:53 +00:00
break;
#endif
default: break;
}
return true;
});
}
static void Shutdown()
{
2017-01-29 03:58:16 +00:00
ShaderImp::Shutdown();
2016-08-17 01:58:53 +00:00
m_gfxToken.doDestroy();
}
static boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
2017-06-01 05:34:24 +00:00
EFilterType type, ShaderImp& filter)
2016-08-17 01:58:53 +00:00
{
2017-01-29 03:58:16 +00:00
return m_bindFactory->BuildShaderDataBinding(ctx, type, filter);
2016-08-17 01:58:53 +00:00
}
};
#define URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(cls) \
template <> std::unique_ptr<TMultiBlendShader<cls>::IDataBindingFactory> \
TMultiBlendShader<cls>::m_bindFactory; \
template <> boo::GraphicsDataToken \
TMultiBlendShader<cls>::m_gfxToken; \
#define URDE_SPECIALIZE_MULTI_BLEND_SHADER(cls) \
template <> std::unique_ptr<TMultiBlendShader<cls>::IDataBindingFactory> \
TMultiBlendShader<cls>::m_bindFactory = {}; \
template <> boo::GraphicsDataToken \
TMultiBlendShader<cls>::m_gfxToken = {}; \
\
template class TMultiBlendShader<cls>;
}
#endif // __URDE_TMULTIBLENDSHADER_HPP__