metaforce/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp

105 lines
4.6 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp"
#include <iterator>
#include "Runtime/Particle/CParticleSwoosh.hpp"
#include "Runtime/Particle/CSwooshDescription.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> CParticleSwooshShaders::m_texZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texNoZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texAdditiveZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_texAdditiveNoZWrite;
2019-03-03 06:19:42 +00:00
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexNoZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexAdditiveZWrite;
std::array<boo::ObjToken<boo::IShaderPipeline>, 2> CParticleSwooshShaders::m_noTexAdditiveNoZWrite;
2018-12-08 05:30:43 +00:00
void CParticleSwooshShaders::Initialize() {
2019-03-03 06:19:42 +00:00
m_texZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderTexZWriteAWrite{})};
m_texNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWriteAWrite{})};
m_texAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWriteAWrite{})};
m_texAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWriteAWrite{})};
m_noTexZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWriteAWrite{})};
m_noTexNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWriteAWrite{})};
m_noTexAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWriteAWrite{})};
m_noTexAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}),
hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite{})};
2018-10-07 02:59:17 +00:00
}
2018-12-08 05:30:43 +00:00
void CParticleSwooshShaders::Shutdown() {
2019-03-03 06:19:42 +00:00
for (auto& s : m_texZWrite) s.reset();
for (auto& s : m_texNoZWrite) s.reset();
for (auto& s : m_texAdditiveZWrite) s.reset();
for (auto& s : m_texAdditiveNoZWrite) s.reset();
for (auto& s : m_noTexZWrite) s.reset();
for (auto& s : m_noTexNoZWrite) s.reset();
for (auto& s : m_noTexAdditiveZWrite) s.reset();
for (auto& s : m_noTexAdditiveNoZWrite) s.reset();
2018-10-07 02:59:17 +00:00
}
2018-12-08 05:30:43 +00:00
CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
2018-12-08 05:30:43 +00:00
if (desc->x3c_TEXR)
return EShaderClass::Tex;
else
return EShaderClass::NoTex;
}
2018-12-08 05:30:43 +00:00
void CParticleSwooshShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
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 (desc->x3c_TEXR) {
if (desc->x44_31_AALP) {
if (desc->x45_24_ZBUF)
2019-03-03 06:19:42 +00:00
pipeline = &m_texAdditiveZWrite;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_texAdditiveNoZWrite;
2018-12-08 05:30:43 +00:00
} else {
if (desc->x45_24_ZBUF)
2019-03-03 06:19:42 +00:00
pipeline = &m_texZWrite;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_texNoZWrite;
}
2018-12-08 05:30:43 +00:00
} else {
if (desc->x44_31_AALP) {
if (desc->x45_24_ZBUF)
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAdditiveZWrite;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexAdditiveNoZWrite;
2018-12-08 05:30:43 +00:00
} else {
if (desc->x45_24_ZBUF)
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexZWrite;
2018-12-08 05:30:43 +00:00
else
2019-03-03 06:19:42 +00:00
pipeline = &m_noTexNoZWrite;
}
2018-12-08 05:30:43 +00:00
}
const CUVElement* const texr = desc->x3c_TEXR.get();
const std::array<boo::ObjToken<boo::ITexture>, 1> textures{
texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr,
};
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBuf.get()};
for (size_t i = 0; i < gen.m_dataBind.size(); ++i) {
gen.m_dataBind[i] =
ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(),
uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr);
}
2018-10-07 02:59:17 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde