From 47340389c1dc92653af91bb7d0e3551c1896e49d Mon Sep 17 00:00:00 2001 From: Adam Jensen Date: Fri, 21 Oct 2022 17:41:35 +0100 Subject: [PATCH] add PCDX11SimpleDynamicVertexBuffer --- rendering/PCDX11RenderDevice.cpp | 1 + .../buffers/PCDX11SimpleDynamicVertexBuffer.h | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 rendering/buffers/PCDX11SimpleDynamicVertexBuffer.h diff --git a/rendering/PCDX11RenderDevice.cpp b/rendering/PCDX11RenderDevice.cpp index 7897b2c..5f9f790 100644 --- a/rendering/PCDX11RenderDevice.cpp +++ b/rendering/PCDX11RenderDevice.cpp @@ -15,6 +15,7 @@ #include "PCDX11StateManager.h" #include "RenderPasses.h" #include "Types.h" +#include "buffers/PCDX11SimpleDynamicVertexBuffer.h" #include "shaders/PCDX11ShaderLib.h" #include "surfaces/PCDX11DefaultRenderTarget.h" #include "surfaces/PCDX11DepthBuffer.h" diff --git a/rendering/buffers/PCDX11SimpleDynamicVertexBuffer.h b/rendering/buffers/PCDX11SimpleDynamicVertexBuffer.h new file mode 100644 index 0000000..923a083 --- /dev/null +++ b/rendering/buffers/PCDX11SimpleDynamicVertexBuffer.h @@ -0,0 +1,46 @@ +#pragma once +#include "PCDX11VertexBuffer.h" +#include "../PCDX11DeviceManager.h" +#include + +namespace cdc { + +class PCDX11SimpleDynamicVertexBuffer : + public PCDX11VertexBuffer +{ +public: + PCDX11SimpleDynamicVertexBuffer(uint32_t stride, uint32_t numVertices) : + stride(stride), + numVertices(numVertices) + { + D3D11_BUFFER_DESC vertexBufferDesc = {}; + vertexBufferDesc.ByteWidth = stride * numVertices; + vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC; + vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + deviceManager->getD3DDevice()->CreateBuffer(&vertexBufferDesc, nullptr, &buffer); + } + + uint32_t stride; // 4 + uint32_t numVertices; // 8 + ID3D11Buffer *buffer; // C + + uint32_t getBaseVertex() override { return 0; } + ID3D11Buffer *getD3DBuffer() override { return buffer; } + uint32_t method0C() override { return numVertices; } + uint32_t getStride() override { return stride; } + void method14() override {} + + void *map() { + D3D11_MAPPED_SUBRESOURCE subresourceData; + deviceManager->getD3DDeviceContext()->Map( + buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &subresourceData); + return subresourceData.pData; + } + + void unmap() { + deviceManager->getD3DDeviceContext()->Unmap(buffer, 0); + } +}; + +}