From 82f72cae85a7459ef8d84d50c0bc14469b52218e Mon Sep 17 00:00:00 2001 From: durswd Date: Wed, 2 Aug 2023 22:39:12 +0900 Subject: [PATCH] Add a VertexBuffer on a memory --- .../GraphicsDeviceCPU.cpp | 20 +++++++++++++++++++ .../GraphicsDeviceCPU.h | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.cpp b/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.cpp index 0eca6ec92b..1a2a3b3f3d 100644 --- a/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.cpp +++ b/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.cpp @@ -4,6 +4,21 @@ namespace EffekseerRendererCPU { namespace Backend { + +VertexBuffer::VertexBuffer(int32_t size, const void* initialData, bool isDynamic) +{ + buffer_.resize(size); + if (initialData != nullptr) + { + memcpy(buffer_.data(), initialData, buffer_.size()); + } +} + +void VertexBuffer::UpdateData(const void* src, int32_t size, int32_t offset) +{ + memcpy(buffer_.data() + offset, src, size); +} + IndexBuffer::IndexBuffer(int32_t elementCount, const void* initialData, Effekseer::Backend::IndexBufferStrideType strideType) { elementCount_ = elementCount; @@ -23,6 +38,11 @@ void IndexBuffer::UpdateData(const void* src, int32_t size, int32_t offset) memcpy(buffer_.data() + offset, src, size); } +Effekseer::Backend::VertexBufferRef GraphicsDevice::CreateVertexBuffer(int32_t size, const void* initialData, bool isDynamic) +{ + return Effekseer::MakeRefPtr(size, initialData, isDynamic); +} + Effekseer::Backend::IndexBufferRef GraphicsDevice::CreateIndexBuffer(int32_t elementCount, const void* initialData, Effekseer::Backend::IndexBufferStrideType stride) { return Effekseer::MakeRefPtr(elementCount, initialData, stride); diff --git a/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.h b/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.h index f3ba2911e3..d069d46b7b 100644 --- a/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.h +++ b/Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.h @@ -8,6 +8,23 @@ namespace EffekseerRendererCPU namespace Backend { +class VertexBuffer + : public Effekseer::Backend::VertexBuffer +{ +private: + std::vector buffer_; + +public: + VertexBuffer(int32_t size, const void* initialData, bool isDynamic); + ~VertexBuffer() override = default; + void UpdateData(const void* src, int32_t size, int32_t offset) override; + + const std::vector& GetBuffer() const + { + return buffer_; + } +}; + class IndexBuffer : public Effekseer::Backend::IndexBuffer { @@ -26,6 +43,8 @@ class GraphicsDevice : public Effekseer::Backend::GraphicsDevice GraphicsDevice() = default; ~GraphicsDevice() override = default; + Effekseer::Backend::VertexBufferRef CreateVertexBuffer(int32_t size, const void* initialData, bool isDynamic) override; + Effekseer::Backend::IndexBufferRef CreateIndexBuffer(int32_t elementCount, const void* initialData, Effekseer::Backend::IndexBufferStrideType stride) override; };