1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/vertexbuffer-dx.hpp

53 lines
1.2 KiB
C++
Raw Normal View History

2024-04-11 10:38:56 -03:00
#ifndef XNA_PLATFORM_VERTEXBUFFER_DX_HPP
#define XNA_PLATFORM_VERTEXBUFFER_DX_HPP
#include "../graphics/vertexbuffer.hpp"
#include "../graphics/vertexposition.hpp"
2024-04-24 14:40:14 -03:00
#include "dxheaders.hpp"
#include <BufferHelpers.h>
#include <VertexTypes.h>
#include "device-dx.hpp"
2024-04-11 10:38:56 -03:00
namespace xna {
template <typename T>
2024-04-11 10:38:56 -03:00
class VertexBuffer : public IVertexBuffer {
public:
constexpr VertexBuffer() = default;
2024-04-11 10:38:56 -03:00
constexpr VertexBuffer(std::vector<T> const& vertices) : data(vertices) {}
2024-04-11 10:38:56 -03:00
virtual ~VertexBuffer() override {
if (dxBuffer) {
dxBuffer->Release();
dxBuffer = nullptr;
2024-04-11 10:38:56 -03:00
}
}
virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override {
if (!device._device) {
xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL);
return false;
}
2024-04-11 10:38:56 -03:00
if (data.empty()) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false;
}
const auto hr = DirectX::CreateStaticBuffer(device._device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &dxBuffer);
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return false;
}
return true;
}
public:
ID3D11Buffer* dxBuffer = nullptr;
std::vector<T> data;
2024-04-11 10:38:56 -03:00
};
}
#endif