Skip to content

Commit

Permalink
Update Effekseer
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Aug 2, 2023
1 parent eac7a83 commit 439190c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 150 deletions.
56 changes: 39 additions & 17 deletions Dev/Cpp/renderer/EffekseerRendererImplemented.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "EffekseerRendererImplemented.h"
#include "EffekseerRendererIndexBuffer.h"
#include "EffekseerRendererRenderState.h"
#include "EffekseerRendererShader.h"
#include "EffekseerRendererTextureLoader.h"
#include "EffekseerRendererVertexBuffer.h"

#include "GraphicsDeviceCPU.h"

namespace EffekseerPlugin
{
Expand Down Expand Up @@ -387,14 +387,25 @@ RendererImplemented::~RendererImplemented()
{
ES_SAFE_DELETE(m_renderState);
ES_SAFE_DELETE(m_standardRenderer);
ES_SAFE_DELETE(m_vertexBuffer);
// ES_SAFE_DELETE(m_vertexBuffer);
}

bool RendererImplemented::Initialize(int32_t squareMaxCount)
{
m_squareMaxCount = squareMaxCount;
m_renderState = new RenderState();
m_vertexBuffer = new VertexBuffer(EffekseerRenderer::GetMaximumVertexSizeInAllTypes() * m_squareMaxCount * 4, true);
graphicsDevice_ = Effekseer::MakeRefPtr<EffekseerRendererCPU::Backend::GraphicsDevice>();

// generate a vertex buffer
{
GetImpl()->InternalVertexBuffer = std::make_shared<EffekseerRenderer::VertexBufferRing>(
graphicsDevice_, EffekseerRenderer::GetMaximumVertexSizeInAllTypes() * m_squareMaxCount * 4, 1);
if (!GetImpl()->InternalVertexBuffer->GetIsValid())
{
GetImpl()->InternalVertexBuffer = nullptr;
return false;
}
}

unlitShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::Unlit));
backDistortedShader_ = std::unique_ptr<Shader>(new Shader(EffekseerRenderer::RendererShaderType::BackDistortion));
Expand Down Expand Up @@ -500,17 +511,16 @@ ::EffekseerRenderer::DistortingCallback* RendererImplemented::GetDistortingCallb

void RendererImplemented::SetDistortingCallback(::EffekseerRenderer::DistortingCallback* callback) {}

VertexBuffer* RendererImplemented::GetVertexBuffer() { return m_vertexBuffer; }

IndexBuffer* RendererImplemented::GetIndexBuffer() { return nullptr; }

EffekseerRenderer::StandardRenderer<RendererImplemented, Shader>* RendererImplemented::GetStandardRenderer() { return m_standardRenderer; }

::EffekseerRenderer::RenderStateBase* RendererImplemented::GetRenderState() { return m_renderState; }

void RendererImplemented::SetVertexBuffer(VertexBuffer* vertexBuffer, int32_t size) {}
void RendererImplemented::SetVertexBuffer(const Effekseer::Backend::VertexBufferRef& vertexBuffer, int32_t size)
{
vertexBuffer_ = vertexBuffer;
}

void RendererImplemented::SetIndexBuffer(IndexBuffer* indexBuffer) {}
void RendererImplemented::SetIndexBuffer(const Effekseer::Backend::IndexBufferRef& indexBuffer) {}

void RendererImplemented::SetLayout(Shader* shader) {}

Expand Down Expand Up @@ -621,7 +631,7 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)
const auto& nativeMaterial = m_currentShader->GetMaterial();
assert(!nativeMaterial->GetIsSimpleVertex());

auto* origin = (uint8_t*)m_vertexBuffer->GetResource();
auto origin = const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data());

int32_t customDataStride = (nativeMaterial->GetCustomData1Count() + nativeMaterial->GetCustomData2Count()) * sizeof(float);

Expand Down Expand Up @@ -721,7 +731,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)

if (m_currentShader->GetType() == EffekseerRenderer::RendererShaderType::BackDistortion)
{
auto vs = (DynamicVertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<DynamicVertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
auto& v = vs[vi];
Expand All @@ -730,7 +742,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)
}
else
{
auto vs = (EffekseerRenderer::AdvancedLightingVertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<EffekseerRenderer::AdvancedLightingVertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
auto& v = vs[vi];
Expand Down Expand Up @@ -767,7 +781,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)

if (m_currentShader->GetType() == EffekseerRenderer::RendererShaderType::Lit)
{
auto vs = (DynamicVertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<DynamicVertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
auto& v = vs[vi];
Expand All @@ -776,7 +792,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)
}
else
{
auto vs = (EffekseerRenderer::AdvancedLightingVertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<EffekseerRenderer::AdvancedLightingVertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
auto& v = vs[vi];
Expand Down Expand Up @@ -811,7 +829,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)

if (m_currentShader->GetType() == EffekseerRenderer::RendererShaderType::Unlit)
{
auto vs = (Vertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<Vertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
const auto& v = vs[vi];
Expand All @@ -820,7 +840,9 @@ void RendererImplemented::DrawSprites(int32_t spriteCount, int32_t vertexOffset)
}
else
{
auto vs = (EffekseerRenderer::AdvancedSimpleVertex*)m_vertexBuffer->GetResource();
auto vs = reinterpret_cast<EffekseerRenderer::AdvancedSimpleVertex*>(
const_cast<uint8_t*>(vertexBuffer_.DownCast<EffekseerRendererCPU::Backend::VertexBuffer>()->GetBuffer().data()));

for (int32_t vi = vertexOffset; vi < vertexOffset + spriteCount * 4; vi++)
{
const auto& v = vs[vi];
Expand Down
12 changes: 5 additions & 7 deletions Dev/Cpp/renderer/EffekseerRendererImplemented.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek

protected:
int32_t m_squareMaxCount = 0;

VertexBuffer* m_vertexBuffer = nullptr;
Effekseer::Backend::GraphicsDeviceRef graphicsDevice_ = nullptr;
Effekseer::Backend::VertexBufferRef vertexBuffer_ = nullptr;

std::unique_ptr<Shader> unlitShader_;
std::unique_ptr<Shader> backDistortedShader_;
Expand Down Expand Up @@ -398,16 +398,14 @@ class RendererImplemented : public ::EffekseerRenderer::Renderer, public ::Effek
*/
void SetDistortingCallback(::EffekseerRenderer::DistortingCallback* callback) override;

VertexBuffer* GetVertexBuffer();

IndexBuffer* GetIndexBuffer();
Effekseer::Backend::IndexBufferRef GetIndexBuffer() { return nullptr; }

EffekseerRenderer::StandardRenderer<RendererImplemented, Shader>* GetStandardRenderer();

::EffekseerRenderer::RenderStateBase* GetRenderState();

void SetVertexBuffer(VertexBuffer* vertexBuffer, int32_t size);
void SetIndexBuffer(IndexBuffer* indexBuffer);
void SetVertexBuffer(const Effekseer::Backend::VertexBufferRef& vertexBuffer, int32_t size);
void SetIndexBuffer(const Effekseer::Backend::IndexBufferRef& indexBuffer);

void SetLayout(Shader* shader);
void DrawSprites(int32_t spriteCount, int32_t vertexOffset);
Expand Down
2 changes: 0 additions & 2 deletions Dev/Cpp/renderer/EffekseerRendererIndexBuffer.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions Dev/Cpp/renderer/EffekseerRendererIndexBuffer.h

This file was deleted.

75 changes: 0 additions & 75 deletions Dev/Cpp/renderer/EffekseerRendererVertexBuffer.cpp

This file was deleted.

31 changes: 0 additions & 31 deletions Dev/Cpp/renderer/EffekseerRendererVertexBuffer.h

This file was deleted.

2 changes: 1 addition & 1 deletion Dev/Effekseer
Submodule Effekseer updated 319 files

0 comments on commit 439190c

Please sign in to comment.