2016-02-18 02:42:32 +00:00
|
|
|
#include "CLineRendererShaders.hpp"
|
2016-07-21 05:21:45 +00:00
|
|
|
#include "Graphics/CLineRenderer.hpp"
|
2017-04-22 21:46:18 +00:00
|
|
|
#include "hecl/VertexBufferPool.hpp"
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-18 02:42:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
static const char* VS_GLSL_TEX =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:20:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-18 02:42:32 +00:00
|
|
|
"layout(location=0) in vec4 posIn;\n"
|
|
|
|
"layout(location=1) in vec4 colorIn;\n"
|
|
|
|
"layout(location=2) in vec4 uvIn;\n"
|
|
|
|
"\n"
|
2016-02-24 03:20:07 +00:00
|
|
|
"UBINDING0 uniform LineUniform\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"{\n"
|
|
|
|
" vec4 moduColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
" vec2 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
2016-07-01 02:33:16 +00:00
|
|
|
"SBINDING(0) out VertToFrag vtf;\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" vtf.color = colorIn * moduColor;\n"
|
|
|
|
" vtf.uv = uvIn.xy;\n"
|
2016-07-02 03:46:02 +00:00
|
|
|
" gl_Position = FLIPFROMGL(posIn);\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS_GLSL_TEX =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:20:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-18 02:42:32 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
" vec2 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
2016-07-01 02:33:16 +00:00
|
|
|
"SBINDING(0) in VertToFrag vtf;\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"layout(location=0) out vec4 colorOut;\n"
|
2016-07-08 00:07:11 +00:00
|
|
|
"TBINDING0 uniform sampler2D tex;\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2016-07-08 00:07:11 +00:00
|
|
|
" colorOut = vtf.color * texture(tex, vtf.uv);\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* VS_GLSL_NOTEX =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:20:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-18 02:42:32 +00:00
|
|
|
"layout(location=0) in vec4 posIn;\n"
|
|
|
|
"layout(location=1) in vec4 colorIn;\n"
|
|
|
|
"\n"
|
2016-02-24 03:20:07 +00:00
|
|
|
"UBINDING0 uniform LineUniform\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"{\n"
|
|
|
|
" vec4 moduColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
2016-07-01 02:33:16 +00:00
|
|
|
"SBINDING(0) out VertToFrag vtf;\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" vtf.color = colorIn * moduColor;\n"
|
2016-07-02 03:46:02 +00:00
|
|
|
" gl_Position = FLIPFROMGL(posIn);\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS_GLSL_NOTEX =
|
|
|
|
"#version 330\n"
|
2016-07-03 23:35:03 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-18 02:42:32 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
2016-07-01 02:33:16 +00:00
|
|
|
"SBINDING(0) in VertToFrag vtf;\n"
|
2016-02-18 02:42:32 +00:00
|
|
|
"layout(location=0) out vec4 colorOut;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" colorOut = vtf.color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
2016-02-23 02:34:16 +00:00
|
|
|
struct OGLLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory
|
2016-02-18 02:42:32 +00:00
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
|
|
|
CLineRenderer& renderer,
|
|
|
|
const boo::ObjToken<boo::IShaderPipeline>& pipeline,
|
|
|
|
const boo::ObjToken<boo::ITexture>& texture)
|
2016-02-18 02:42:32 +00:00
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IVertexFormat> vtxFmt;
|
2016-02-18 02:42:32 +00:00
|
|
|
int texCount = 0;
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::ITexture> textures[1];
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
std::pair<boo::ObjToken<boo::IGraphicsBufferD>,
|
|
|
|
hecl::VertexBufferPool<CLineRenderer::SDrawVertTex>::IndexTp> vbufInfo;
|
|
|
|
std::pair<boo::ObjToken<boo::IGraphicsBufferD>,
|
|
|
|
hecl::UniformBufferPool<CLineRenderer::SDrawUniform>::IndexTp> ubufInfo =
|
2017-04-22 21:46:18 +00:00
|
|
|
renderer.m_uniformBuf.getBufferInfo();
|
2016-02-18 02:42:32 +00:00
|
|
|
if (texture)
|
|
|
|
{
|
2017-04-22 21:46:18 +00:00
|
|
|
vbufInfo = renderer.m_vertBufTex.getBufferInfo();
|
2016-02-18 02:42:32 +00:00
|
|
|
textures[0] = texture;
|
|
|
|
texCount = 1;
|
|
|
|
const boo::VertexElementDescriptor TexFmtTex[] =
|
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
{vbufInfo.first.get(), nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{vbufInfo.first.get(), nullptr, boo::VertexSemantic::Color},
|
|
|
|
{vbufInfo.first.get(), nullptr, boo::VertexSemantic::UV4}
|
2016-02-18 02:42:32 +00:00
|
|
|
};
|
2016-03-30 19:16:01 +00:00
|
|
|
vtxFmt = ctx.newVertexFormat(3, TexFmtTex);
|
2016-02-18 02:42:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-22 21:46:18 +00:00
|
|
|
vbufInfo = renderer.m_vertBufNoTex.getBufferInfo();
|
2016-02-18 02:42:32 +00:00
|
|
|
const boo::VertexElementDescriptor TexFmtNoTex[] =
|
|
|
|
{
|
2017-11-05 06:17:12 +00:00
|
|
|
{vbufInfo.first.get(), nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{vbufInfo.first.get(), nullptr, boo::VertexSemantic::Color}
|
2016-02-18 02:42:32 +00:00
|
|
|
};
|
2016-03-30 19:16:01 +00:00
|
|
|
vtxFmt = ctx.newVertexFormat(2, TexFmtNoTex);
|
2016-02-18 02:42:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> uniforms[] = {ubufInfo.first.get()};
|
2017-04-22 21:46:18 +00:00
|
|
|
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
2017-04-25 04:46:24 +00:00
|
|
|
size_t ubufOffs[] = {size_t(ubufInfo.second)};
|
2017-04-22 21:46:18 +00:00
|
|
|
size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)};
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, vtxFmt, vbufInfo.first.get(),
|
2017-04-22 21:46:18 +00:00
|
|
|
nullptr, nullptr, 1, uniforms, stages,
|
|
|
|
ubufOffs, ubufSizes, texCount, textures,
|
|
|
|
nullptr, nullptr, vbufInfo.second);
|
2016-02-18 02:42:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-30 19:16:01 +00:00
|
|
|
CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::GLDataFactory::Context& ctx)
|
2016-02-18 02:42:32 +00:00
|
|
|
{
|
|
|
|
static const char* UniNames[] = {"LineUniform"};
|
2016-07-08 00:07:11 +00:00
|
|
|
static const char* TexNames[] = {"tex"};
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2016-07-08 00:07:11 +00:00
|
|
|
m_texAlpha = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
2017-04-22 06:42:32 +00:00
|
|
|
false, true, false, boo::CullMode::None);
|
2016-07-08 00:07:11 +00:00
|
|
|
m_texAdditive = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
false, true, false, boo::CullMode::None);
|
2017-11-02 09:35:07 +00:00
|
|
|
m_noTexAlpha = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
2017-04-22 06:42:32 +00:00
|
|
|
false, true, false, boo::CullMode::None);
|
2017-11-02 09:35:07 +00:00
|
|
|
m_noTexAdditive = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
false, true, false, boo::CullMode::None);
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2016-02-23 02:34:16 +00:00
|
|
|
return new struct OGLLineDataBindingFactory;
|
2016-02-18 02:42:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 02:34:16 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
struct VulkanLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory
|
|
|
|
{
|
2016-03-30 19:16:01 +00:00
|
|
|
void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer,
|
2017-11-06 06:58:04 +00:00
|
|
|
const boo::ObjToken<boo::IShaderPipeline>& pipeline,
|
|
|
|
const boo::ObjToken<boo::ITexture>& texture)
|
2016-02-23 02:34:16 +00:00
|
|
|
{
|
|
|
|
int texCount = 0;
|
2017-11-06 06:58:04 +00:00
|
|
|
boo::ObjToken<boo::ITexture> textures[1];
|
2016-02-23 02:34:16 +00:00
|
|
|
|
2017-11-06 06:58:04 +00:00
|
|
|
std::pair<boo::ObjToken<boo::IGraphicsBufferD>,
|
|
|
|
hecl::VertexBufferPool<CLineRenderer::SDrawVertTex>::IndexTp> vbufInfo;
|
|
|
|
std::pair<boo::ObjToken<boo::IGraphicsBufferD>,
|
|
|
|
hecl::UniformBufferPool<CLineRenderer::SDrawUniform>::IndexTp> ubufInfo =
|
2017-04-22 21:46:18 +00:00
|
|
|
renderer.m_uniformBuf.getBufferInfo();
|
2016-02-23 02:34:16 +00:00
|
|
|
if (texture)
|
|
|
|
{
|
2017-04-22 21:46:18 +00:00
|
|
|
vbufInfo = renderer.m_vertBufTex.getBufferInfo();
|
2016-02-23 02:34:16 +00:00
|
|
|
textures[0] = texture;
|
|
|
|
texCount = 1;
|
|
|
|
}
|
2017-04-22 21:46:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
vbufInfo = renderer.m_vertBufNoTex.getBufferInfo();
|
|
|
|
}
|
2016-02-23 02:34:16 +00:00
|
|
|
|
2017-11-06 06:58:04 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> uniforms[] = {ubufInfo.first.get()};
|
2017-04-22 21:46:18 +00:00
|
|
|
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
2017-04-25 04:46:24 +00:00
|
|
|
size_t ubufOffs[] = {size_t(ubufInfo.second)};
|
2017-04-22 21:46:18 +00:00
|
|
|
size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)};
|
2016-02-23 02:34:16 +00:00
|
|
|
|
2017-11-06 06:58:04 +00:00
|
|
|
renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, vbufInfo.first.get(),
|
2016-03-30 19:16:01 +00:00
|
|
|
nullptr, nullptr, 1, uniforms,
|
2017-04-22 21:46:18 +00:00
|
|
|
stages, ubufOffs, ubufSizes, texCount, textures,
|
|
|
|
nullptr, nullptr, vbufInfo.second);
|
2016-02-23 02:34:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-30 19:16:01 +00:00
|
|
|
CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::VulkanDataFactory::Context& ctx)
|
2016-02-23 02:34:16 +00:00
|
|
|
{
|
|
|
|
static const boo::VertexElementDescriptor VtxFmtTex[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
2016-03-30 19:16:01 +00:00
|
|
|
m_texVtxFmt = ctx.newVertexFormat(3, VtxFmtTex);
|
2016-02-23 02:34:16 +00:00
|
|
|
|
|
|
|
static const boo::VertexElementDescriptor VtxFmtNoTex[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color}
|
|
|
|
};
|
2016-03-30 19:16:01 +00:00
|
|
|
m_noTexVtxFmt = ctx.newVertexFormat(2, VtxFmtNoTex);
|
2016-02-23 02:34:16 +00:00
|
|
|
|
2016-03-30 19:16:01 +00:00
|
|
|
m_texAlpha = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
true, true, false, boo::CullMode::None);
|
2016-03-30 19:16:01 +00:00
|
|
|
m_texAdditive = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
false, true, false, boo::CullMode::None);
|
2016-03-30 19:16:01 +00:00
|
|
|
m_noTexAlpha = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
true, true, false, boo::CullMode::None);
|
2016-03-30 19:16:01 +00:00
|
|
|
m_noTexAdditive = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt,
|
2017-03-17 23:33:02 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None,
|
|
|
|
false, true, false, boo::CullMode::None);
|
2016-02-23 02:34:16 +00:00
|
|
|
|
|
|
|
return new struct VulkanLineDataBindingFactory;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-18 02:42:32 +00:00
|
|
|
}
|