2016-07-22 02:32:23 +00:00
|
|
|
#include "CLineRendererShaders.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_texAlpha;
|
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_texAdditive;
|
2016-07-22 02:32:23 +00:00
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_noTexAlpha;
|
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_noTexAdditive;
|
2016-07-22 02:32:23 +00:00
|
|
|
|
2018-05-08 05:10:24 +00:00
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_texAlphaZ;
|
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_texAdditiveZ;
|
|
|
|
|
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_noTexAlphaZ;
|
|
|
|
boo::ObjToken<boo::IShaderPipeline> CLineRendererShaders::m_noTexAdditiveZ;
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IVertexFormat> CLineRendererShaders::m_texVtxFmt;
|
|
|
|
boo::ObjToken<boo::IVertexFormat> CLineRendererShaders::m_noTexVtxFmt;
|
2016-07-22 02:32:23 +00:00
|
|
|
|
|
|
|
std::unique_ptr<CLineRendererShaders::IDataBindingFactory> CLineRendererShaders::m_bindFactory;
|
|
|
|
|
|
|
|
void CLineRendererShaders::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:
|
2016-07-22 02:32:23 +00:00
|
|
|
m_bindFactory.reset(Initialize(static_cast<boo::GLDataFactory::Context&>(ctx)));
|
|
|
|
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:
|
|
|
|
m_bindFactory.reset(Initialize(static_cast<boo::ID3DDataFactory::Context&>(ctx)));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Metal:
|
|
|
|
m_bindFactory.reset(Initialize(static_cast<boo::MetalDataFactory::Context&>(ctx)));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
|
|
|
m_bindFactory.reset(Initialize(static_cast<boo::VulkanDataFactory::Context&>(ctx)));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLineRendererShaders::Shutdown()
|
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
m_texAlpha.reset();
|
|
|
|
m_texAdditive.reset();
|
|
|
|
m_noTexAlpha.reset();
|
|
|
|
m_noTexAdditive.reset();
|
2018-05-08 05:10:24 +00:00
|
|
|
m_texAlphaZ.reset();
|
|
|
|
m_texAdditiveZ.reset();
|
|
|
|
m_noTexAlphaZ.reset();
|
|
|
|
m_noTexAdditiveZ.reset();
|
2017-11-05 06:17:12 +00:00
|
|
|
m_texVtxFmt.reset();
|
|
|
|
m_noTexVtxFmt.reset();
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
|
|
|
CLineRenderer& renderer,
|
2017-11-05 06:17:12 +00:00
|
|
|
const boo::ObjToken<boo::ITexture>& texture,
|
2018-05-08 05:10:24 +00:00
|
|
|
bool additive, bool zTest)
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IShaderPipeline> pipeline;
|
2018-05-08 05:10:24 +00:00
|
|
|
if (zTest)
|
2016-07-22 02:32:23 +00:00
|
|
|
{
|
2018-05-08 05:10:24 +00:00
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
if (additive)
|
|
|
|
pipeline = m_texAdditiveZ;
|
|
|
|
else
|
|
|
|
pipeline = m_texAlphaZ;
|
|
|
|
}
|
2016-07-22 02:32:23 +00:00
|
|
|
else
|
2018-05-08 05:10:24 +00:00
|
|
|
{
|
|
|
|
if (additive)
|
|
|
|
pipeline = m_noTexAdditiveZ;
|
|
|
|
else
|
|
|
|
pipeline = m_noTexAlphaZ;
|
|
|
|
}
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-08 05:10:24 +00:00
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
if (additive)
|
|
|
|
pipeline = m_texAdditive;
|
|
|
|
else
|
|
|
|
pipeline = m_texAlpha;
|
|
|
|
}
|
2016-07-22 02:32:23 +00:00
|
|
|
else
|
2018-05-08 05:10:24 +00:00
|
|
|
{
|
|
|
|
if (additive)
|
|
|
|
pipeline = m_noTexAdditive;
|
|
|
|
else
|
|
|
|
pipeline = m_noTexAlpha;
|
|
|
|
}
|
2016-07-22 02:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_bindFactory->BuildShaderDataBinding(ctx, renderer, pipeline, texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|