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
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class FilterImp>
|
2016-07-22 19:46:30 +00:00
|
|
|
class TShader
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct IDataBindingFactory
|
|
|
|
{
|
2016-08-17 01:58:53 +00:00
|
|
|
virtual boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
|
|
|
boo::IShaderPipeline* pipeline,
|
|
|
|
boo::IVertexFormat* vtxFmt,
|
|
|
|
FilterImp& filter)=0;
|
2016-07-22 02:32:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static boo::IShaderPipeline* m_pipeline;
|
|
|
|
static boo::IVertexFormat* m_vtxFmt; /* No OpenGL */
|
|
|
|
|
|
|
|
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:
|
2016-07-22 02:32:23 +00:00
|
|
|
m_bindFactory.reset(FilterImp::Initialize(static_cast<boo::GLDataFactory::Context&>(ctx),
|
|
|
|
m_pipeline));
|
|
|
|
break;
|
|
|
|
#if _WIN32
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D11:
|
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D12:
|
|
|
|
m_bindFactory.reset(FilterImp::Initialize(static_cast<boo::ID3DDataFactory::Context&>(ctx),
|
|
|
|
m_pipeline, m_vtxFmt));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Metal:
|
|
|
|
m_bindFactory.reset(FilterImp::Initialize(static_cast<boo::MetalDataFactory::Context&>(ctx),
|
|
|
|
m_pipeline, m_vtxFmt));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
|
|
|
m_bindFactory.reset(FilterImp::Initialize(static_cast<boo::VulkanDataFactory::Context&>(ctx),
|
|
|
|
m_pipeline, m_vtxFmt));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Shutdown()
|
|
|
|
{
|
|
|
|
m_gfxToken.doDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
static boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, FilterImp& filter)
|
|
|
|
{
|
2016-08-17 01:58:53 +00:00
|
|
|
return m_bindFactory->BuildShaderDataBinding(ctx, m_pipeline, m_vtxFmt, filter);
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
#define URDE_DECL_SPECIALIZE_SHADER(cls) \
|
2016-07-22 02:32:23 +00:00
|
|
|
template <> boo::IShaderPipeline* \
|
2016-07-22 19:46:30 +00:00
|
|
|
TShader<cls>::m_pipeline; \
|
2016-07-22 02:32:23 +00:00
|
|
|
template <> boo::IVertexFormat* \
|
2016-07-22 19:46:30 +00:00
|
|
|
TShader<cls>::m_vtxFmt; \
|
|
|
|
\
|
|
|
|
template <> std::unique_ptr<TShader<cls>::IDataBindingFactory> \
|
|
|
|
TShader<cls>::m_bindFactory; \
|
|
|
|
template <> boo::GraphicsDataToken \
|
|
|
|
TShader<cls>::m_gfxToken; \
|
2016-07-22 02:32:23 +00:00
|
|
|
|
2016-07-22 19:46:30 +00:00
|
|
|
#define URDE_SPECIALIZE_SHADER(cls) \
|
2016-07-22 02:32:23 +00:00
|
|
|
template <> boo::IShaderPipeline* \
|
2016-07-22 19:46:30 +00:00
|
|
|
TShader<cls>::m_pipeline = nullptr; \
|
2016-07-22 02:32:23 +00:00
|
|
|
template <> boo::IVertexFormat* \
|
2016-07-22 19:46:30 +00:00
|
|
|
TShader<cls>::m_vtxFmt = nullptr; \
|
2016-07-22 02:32:23 +00:00
|
|
|
\
|
2016-07-22 19:46:30 +00:00
|
|
|
template <> std::unique_ptr<TShader<cls>::IDataBindingFactory> \
|
|
|
|
TShader<cls>::m_bindFactory = {}; \
|
2016-07-22 02:32:23 +00:00
|
|
|
template <> boo::GraphicsDataToken \
|
2016-07-22 19:46:30 +00:00
|
|
|
TShader<cls>::m_gfxToken = {}; \
|
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__
|