metaforce/Runtime/Graphics/Shaders/CLineRendererShaders.cpp

122 lines
5.3 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/Shaders/CLineRendererShaders.hpp"
#include <utility>
#include "Runtime/Graphics/CLineRenderer.hpp"
#include <hecl/Pipeline.hpp>
2018-12-08 05:30:43 +00:00
namespace urde {
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_texAlpha;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_texAdditive;
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_noTexAlpha;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_noTexAdditive;
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_texAlphaZ;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_texAdditiveZ;
2018-05-08 05:10:24 +00:00
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_noTexAlphaZ;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_noTexAdditiveZ;
2018-05-08 05:10:24 +00:00
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CLineRendererShaders::m_noTexAlphaZGEqual;
2018-12-08 05:30:43 +00:00
void CLineRendererShaders::Initialize() {
CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) {
2019-03-03 06:19:42 +00:00
m_texAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaAWrite{})};
m_texAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveAWrite{})};
m_noTexAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaAWrite{})};
m_noTexAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveAWrite{})};
m_texAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZAWrite{})};
m_texAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZAWrite{})};
m_noTexAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZAWrite{})};
m_noTexAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZAWrite{})};
m_noTexAlphaZGEqual = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}),
hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqualAWrite{})};
2018-12-08 05:30:43 +00:00
return true;
} BooTrace);
}
2018-12-08 05:30:43 +00:00
void CLineRendererShaders::Shutdown() {
2019-03-03 06:19:42 +00:00
for (auto& s : m_texAlpha) s.reset();
for (auto& s : m_texAdditive) s.reset();
for (auto& s : m_noTexAlpha) s.reset();
for (auto& s : m_noTexAdditive) s.reset();
for (auto& s : m_texAlphaZ) s.reset();
for (auto& s : m_texAdditiveZ) s.reset();
for (auto& s : m_noTexAlphaZ) s.reset();
for (auto& s : m_noTexAdditiveZ) s.reset();
for (auto& s : m_noTexAlphaZGEqual) s.reset();
}
2018-12-08 05:30:43 +00:00
void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer,
const boo::ObjToken<boo::ITexture>& texture, bool additive,
bool zTest, bool zGEqual) {
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* pipeline = nullptr;
2018-12-08 05:30:43 +00:00
if (zGEqual) {
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAlphaZGEqual;
2018-12-08 05:30:43 +00:00
} else if (zTest) {
if (texture) {
if (additive)
2019-03-03 06:19:42 +00:00
pipeline = &m_texAdditiveZ;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_texAlphaZ;
2018-12-08 05:30:43 +00:00
} else {
if (additive)
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAdditiveZ;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAlphaZ;
}
2018-12-08 05:30:43 +00:00
} else {
if (texture) {
if (additive)
2019-03-03 06:19:42 +00:00
pipeline = &m_texAdditive;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_texAlpha;
2018-12-08 05:30:43 +00:00
} else {
if (additive)
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAdditive;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAlpha;
}
2018-12-08 05:30:43 +00:00
}
size_t texCount = 0;
std::array<boo::ObjToken<boo::ITexture>, 1> textures;
2018-10-07 02:59:17 +00:00
2018-12-08 05:30:43 +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 = renderer.m_uniformBuf.getBufferInfo();
if (texture) {
vbufInfo = renderer.m_vertBufTex.getBufferInfo();
textures[0] = texture;
texCount = 1;
} else {
vbufInfo = renderer.m_vertBufNoTex.getBufferInfo();
}
2018-10-07 02:59:17 +00:00
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{ubufInfo.first.get()};
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Fragment};
const std::array<size_t, 1> ubufOffs{size_t(ubufInfo.second)};
const std::array<size_t, 1> ubufSizes{sizeof(CLineRenderer::SDrawUniform)};
2018-10-07 02:59:17 +00:00
for (size_t i = 0; i < renderer.m_shaderBind.size(); ++i) {
renderer.m_shaderBind[i] = ctx.newShaderDataBinding(
(*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(),
ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second);
}
}
2018-12-08 05:30:43 +00:00
} // namespace urde