Skip to content

Commit

Permalink
Refactor GetShader
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Aug 4, 2023
1 parent 124471e commit 7e4cd8e
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 434 deletions.
1 change: 1 addition & 0 deletions Dev/Cpp/EffekseerRendererCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(PublicHeaders
)

set(LocalHeaders
EffekseerRendererFlags.h
EffekseerRenderer.CommonUtils.h
EffekseerRenderer.DDSTextureLoader.h
EffekseerRenderer.PngTextureLoader.h
Expand Down
12 changes: 1 addition & 11 deletions Dev/Cpp/EffekseerRendererCommon/EffekseerRenderer.CommonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "EffekseerRenderer.Renderer.h"
#include "EffekseerRenderer.Renderer_Impl.h"
#include "EffekseerRendererFlags.h"
#include <Effekseer.h>
#include <Effekseer/Material/Effekseer.CompiledMaterial.h>
#include <Effekseer/Model/SplineGenerator.h>
Expand Down Expand Up @@ -909,17 +910,6 @@ struct MaterialShaderParameterGenerator
}
};

enum class RendererShaderType
{
Unlit,
Lit,
BackDistortion,
AdvancedUnlit,
AdvancedLit,
AdvancedBackDistortion,
Material,
};

struct ShaderParameterCollector
{
RendererShaderType ShaderType{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,44 @@ void Renderer::Impl::SetDepth(::Effekseer::Backend::TextureRef texture, const De
reconstructionParam_ = reconstructionParam;
}

ShaderBase* Renderer::Impl::GetShader(::EffekseerRenderer::RendererShaderType type) const
{
if (type == ::EffekseerRenderer::RendererShaderType::AdvancedBackDistortion)
{
return ShaderAdDistortion.get();
}
else if (type == ::EffekseerRenderer::RendererShaderType::AdvancedLit)
{
return ShaderAdLit.get();
}
else if (type == ::EffekseerRenderer::RendererShaderType::AdvancedUnlit)
{
return ShaderAdUnlit.get();
}
else if (type == ::EffekseerRenderer::RendererShaderType::BackDistortion)
{
return ShaderDistortion.get();
}
else if (type == ::EffekseerRenderer::RendererShaderType::Lit)
{
return ShaderLit.get();
}
else if (type == ::EffekseerRenderer::RendererShaderType::Unlit)
{
if (externalShaderSettings == nullptr)
{
ShaderUnlit->OverrideShader(nullptr);
}
else
{
ShaderUnlit->OverrideShader(externalShaderSettings->StandardShader);
}

return ShaderUnlit.get();
}

assert(0);
return nullptr;
}

} // namespace EffekseerRenderer
11 changes: 11 additions & 0 deletions Dev/Cpp/EffekseerRendererCommon/EffekseerRenderer.Renderer_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Effekseer.h>

#include "EffekseerRenderer.Renderer.h"
#include "EffekseerRenderer.ShaderBase.h"
#include "EffekseerRendererFlags.h"
#include "VertexBuffer.h"

namespace EffekseerRenderer
Expand Down Expand Up @@ -56,6 +58,13 @@ class Renderer::Impl final : public ::Effekseer::SIMD::AlignedAllocationPolicy<1

std::shared_ptr<VertexBuffer> InternalVertexBuffer;

std::unique_ptr<ShaderBase> ShaderUnlit = nullptr;
std::unique_ptr<ShaderBase> ShaderLit = nullptr;
std::unique_ptr<ShaderBase> ShaderDistortion = nullptr;
std::unique_ptr<ShaderBase> ShaderAdUnlit = nullptr;
std::unique_ptr<ShaderBase> ShaderAdLit = nullptr;
std::unique_ptr<ShaderBase> ShaderAdDistortion = nullptr;

Impl() = default;
~Impl();

Expand Down Expand Up @@ -126,6 +135,8 @@ class Renderer::Impl final : public ::Effekseer::SIMD::AlignedAllocationPolicy<1
void GetDepth(::Effekseer::Backend::TextureRef& texture, DepthReconstructionParameter& reconstructionParam);

void SetDepth(::Effekseer::Backend::TextureRef texture, const DepthReconstructionParameter& reconstructionParam);

ShaderBase* GetShader(::EffekseerRenderer::RendererShaderType type) const;
};

} // namespace EffekseerRenderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ class StandardRenderer
}
else
{
shader_ = m_renderer->GetShader(renderState.Collector.ShaderType);
shader_ = (SHADER*)m_renderer->GetImpl()->GetShader(renderState.Collector.ShaderType);
}

// validate
Expand Down
18 changes: 18 additions & 0 deletions Dev/Cpp/EffekseerRendererCommon/EffekseerRendererFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef __EFFEKSEERRENDERER_FLAGS_H__
#define __EFFEKSEERRENDERER_FLAGS_H__

namespace EffekseerRenderer
{
enum class RendererShaderType
{
Unlit,
Lit,
BackDistortion,
AdvancedUnlit,
AdvancedLit,
AdvancedBackDistortion,
Material,
};
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ RendererImplemented::RendererImplemented(int32_t squareMaxCount)
, m_coordinateSystem(::Effekseer::CoordinateSystem::RH)
, m_renderState(nullptr)
, m_restorationOfStates(true)

, shader_unlit_(nullptr)
, shader_distortion_(nullptr)
, m_standardRenderer(nullptr)
, m_distortingCallback(nullptr)
{
Expand All @@ -295,17 +292,7 @@ RendererImplemented::~RendererImplemented()

ES_SAFE_DELETE(m_distortingCallback);
ES_SAFE_DELETE(m_standardRenderer);

ES_SAFE_DELETE(shader_unlit_);
ES_SAFE_DELETE(shader_distortion_);
ES_SAFE_DELETE(shader_lit_);

ES_SAFE_DELETE(shader_ad_unlit_);
ES_SAFE_DELETE(shader_ad_distortion_);
ES_SAFE_DELETE(shader_ad_lit_);

ES_SAFE_DELETE(m_state);

ES_SAFE_DELETE(m_renderState);
}

Expand Down Expand Up @@ -374,89 +361,95 @@ bool RendererImplemented::Initialize(Backend::GraphicsDeviceRef graphicsDevice,
auto vlLitAd = EffekseerRenderer::GetVertexLayout(graphicsDevice_, EffekseerRenderer::RendererShaderType::AdvancedLit).DownCast<Backend::VertexLayout>();
auto vlDistAd = EffekseerRenderer::GetVertexLayout(graphicsDevice_, EffekseerRenderer::RendererShaderType::AdvancedBackDistortion).DownCast<Backend::VertexLayout>();

shader_unlit_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_VS::g_main,
sizeof(Standard_VS::g_main),
Standard_PS::g_main,
sizeof(Standard_PS::g_main)),
vlUnlit,
"Unlit");
if (shader_unlit_ == nullptr)
auto shader_unlit = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_VS::g_main,
sizeof(Standard_VS::g_main),
Standard_PS::g_main,
sizeof(Standard_PS::g_main)),
vlUnlit,
"Unlit");
if (shader_unlit == nullptr)
return false;

shader_ad_unlit_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_VS_Ad::g_main,
sizeof(Standard_VS_Ad::g_main),
Standard_PS_Ad::g_main,
sizeof(Standard_PS_Ad::g_main)),
vlUnlitAd,
"Unlit Ad");
if (shader_ad_unlit_ == nullptr)
GetImpl()->ShaderUnlit = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_unlit);

auto shader_ad_unlit = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_VS_Ad::g_main,
sizeof(Standard_VS_Ad::g_main),
Standard_PS_Ad::g_main,
sizeof(Standard_PS_Ad::g_main)),
vlUnlitAd,
"Unlit Ad");
if (shader_ad_unlit == nullptr)
return false;

shader_distortion_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Distortion_VS::g_main,
sizeof(Standard_Distortion_VS::g_main),
Standard_Distortion_PS::g_main,
sizeof(Standard_Distortion_PS::g_main)),
vlDist,
"Distortion");
if (shader_distortion_ == nullptr)
GetImpl()->ShaderAdUnlit = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_ad_unlit);

auto shader_distortion = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Distortion_VS::g_main,
sizeof(Standard_Distortion_VS::g_main),
Standard_Distortion_PS::g_main,
sizeof(Standard_Distortion_PS::g_main)),
vlDist,
"Distortion");
if (shader_distortion == nullptr)
return false;

shader_ad_distortion_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Distortion_VS_Ad::g_main,
sizeof(Standard_Distortion_VS_Ad::g_main),
Standard_Distortion_PS_Ad::g_main,
sizeof(Standard_Distortion_PS_Ad::g_main)),
vlDistAd,
"Distortion Ad");
if (shader_ad_distortion_ == nullptr)
GetImpl()->ShaderDistortion = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_distortion);

auto shader_ad_distortion = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Distortion_VS_Ad::g_main,
sizeof(Standard_Distortion_VS_Ad::g_main),
Standard_Distortion_PS_Ad::g_main,
sizeof(Standard_Distortion_PS_Ad::g_main)),
vlDistAd,
"Distortion Ad");
if (shader_ad_distortion == nullptr)
return false;

shader_lit_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Lighting_VS::g_main,
sizeof(Standard_Lighting_VS::g_main),
Standard_Lighting_PS::g_main,
sizeof(Standard_Lighting_PS::g_main)),
vlLit,
"Lit");
if (shader_lit_ == nullptr)
GetImpl()->ShaderAdDistortion = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_ad_distortion);

auto shader_lit = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Lighting_VS::g_main,
sizeof(Standard_Lighting_VS::g_main),
Standard_Lighting_PS::g_main,
sizeof(Standard_Lighting_PS::g_main)),
vlLit,
"Lit");
if (shader_lit == nullptr)
return false;
GetImpl()->ShaderLit = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_lit);

shader_ad_lit_ = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Lighting_VS_Ad::g_main,
sizeof(Standard_Lighting_VS_Ad::g_main),
Standard_Lighting_PS_Ad::g_main,
sizeof(Standard_Lighting_PS_Ad::g_main)),
vlLitAd,
"Lit Ad");
if (shader_ad_lit_ == nullptr)
auto shader_ad_lit = Shader::Create(graphicsDevice_,
graphicsDevice_->CreateShaderFromBinary(
Standard_Lighting_VS_Ad::g_main,
sizeof(Standard_Lighting_VS_Ad::g_main),
Standard_Lighting_PS_Ad::g_main,
sizeof(Standard_Lighting_PS_Ad::g_main)),
vlLitAd,
"Lit Ad");
if (shader_ad_lit == nullptr)
return false;
GetImpl()->ShaderAdUnlit = std::unique_ptr<EffekseerRenderer::ShaderBase>(shader_ad_lit);

shader_unlit_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_unlit_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));
shader_unlit->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_unlit->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));

shader_distortion_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_distortion_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBufferDistortion));
shader_distortion->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_distortion->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBufferDistortion));

shader_ad_unlit_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_unlit_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));
shader_ad_unlit->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_unlit->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));

shader_ad_distortion_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_distortion_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBufferDistortion));
shader_ad_distortion->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_distortion->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBufferDistortion));

shader_lit_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_lit_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));
shader_lit->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_lit->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));

shader_ad_lit_->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_lit_->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));
shader_ad_lit->SetVertexConstantBufferSize(sizeof(EffekseerRenderer::StandardRendererVertexBuffer));
shader_ad_lit->SetPixelConstantBufferSize(sizeof(EffekseerRenderer::PixelConstantBuffer));

m_standardRenderer =
new EffekseerRenderer::StandardRenderer<RendererImplemented, Shader>(this);
Expand Down Expand Up @@ -733,46 +726,6 @@ void RendererImplemented::DrawPolygonInstanced(int32_t vertexCount, int32_t inde
GetContext()->DrawIndexedInstanced(indexCount, instanceCount, 0, 0, 0);
}

Shader* RendererImplemented::GetShader(::EffekseerRenderer::RendererShaderType type) const
{
if (type == ::EffekseerRenderer::RendererShaderType::AdvancedBackDistortion)
{
return shader_ad_distortion_;
}
else if (type == ::EffekseerRenderer::RendererShaderType::AdvancedLit)
{
return shader_ad_lit_;
}
else if (type == ::EffekseerRenderer::RendererShaderType::AdvancedUnlit)
{
return shader_ad_unlit_;
}
else if (type == ::EffekseerRenderer::RendererShaderType::BackDistortion)
{
return shader_distortion_;
}
else if (type == ::EffekseerRenderer::RendererShaderType::Lit)
{
return shader_lit_;
}
else if (type == ::EffekseerRenderer::RendererShaderType::Unlit)
{
if (GetExternalShaderSettings() == nullptr)
{
shader_unlit_->OverrideShader(nullptr);
}
else
{
shader_unlit_->OverrideShader(GetExternalShaderSettings()->StandardShader);
}

return shader_unlit_;
}

assert(0);
return nullptr;
}

void RendererImplemented::BeginShader(Shader* shader)
{
currentShader = shader;
Expand Down
Loading

0 comments on commit 7e4cd8e

Please sign in to comment.