Skip to content

Commit

Permalink
Add a VertexBuffer on a memory
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Aug 2, 2023
1 parent a64a8f1 commit 82f72ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<VertexBuffer>(size, initialData, isDynamic);
}

Effekseer::Backend::IndexBufferRef GraphicsDevice::CreateIndexBuffer(int32_t elementCount, const void* initialData, Effekseer::Backend::IndexBufferStrideType stride)
{
return Effekseer::MakeRefPtr<IndexBuffer>(elementCount, initialData, stride);
Expand Down
19 changes: 19 additions & 0 deletions Dev/Cpp/EffekseerRendererCommon/GraphicsDeviceCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ namespace EffekseerRendererCPU
namespace Backend
{

class VertexBuffer
: public Effekseer::Backend::VertexBuffer
{
private:
std::vector<uint8_t> 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<uint8_t>& GetBuffer() const
{
return buffer_;
}
};

class IndexBuffer
: public Effekseer::Backend::IndexBuffer
{
Expand All @@ -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;
};

Expand Down

0 comments on commit 82f72ca

Please sign in to comment.