67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
#ifndef GP1_DIRECTX_INSTANCEDMESH_H
|
|
#define GP1_DIRECTX_INSTANCEDMESH_H
|
|
|
|
#include "Texture.h"
|
|
#include "Effects/BaseEffect.h"
|
|
#include "Mesh.h"
|
|
|
|
#include <d3d11.h>
|
|
#include <vector>
|
|
|
|
struct alignas(16) InstancedData {
|
|
Matrix worldMatrix;
|
|
Vector4 color;
|
|
};
|
|
|
|
class InstancedMesh {
|
|
public:
|
|
InstancedMesh(ID3D11Device *devicePtr, const std::vector<VertexIn> &verticesIn, const std::vector<Uint32> &indices,
|
|
std::shared_ptr<Material> material, BaseEffect* effectPtr, const std::vector<InstancedData>& instanceData);
|
|
|
|
~InstancedMesh();
|
|
|
|
void Render(ID3D11DeviceContext *deviceContextPtr, const Matrix &worldViewProj) const;
|
|
|
|
void SetCameraPos(const Vector3 &pos) const;
|
|
|
|
Matrix GetWorldMatrix() const;
|
|
|
|
|
|
Material* GetMaterial() const;
|
|
|
|
void SetWorldMatrix(const Matrix &matrix);
|
|
|
|
std::vector<VertexIn>& GetVertices() { return m_VerticesIn; }
|
|
std::vector<Uint32>& GetIndices() { return m_Indices; }
|
|
PrimitiveTopology GetPrimitiveTopology() const { return m_PrimitiveTopology; }
|
|
|
|
void SetMaterial(Material *pMaterial);
|
|
|
|
void UpdateInstanceData(ID3D11DeviceContext* deviceContextPtr, const std::vector<InstancedData>& instanceData);
|
|
|
|
private:
|
|
BaseEffect *m_EffectPtr;
|
|
|
|
Matrix m_WorldMatrix{};
|
|
|
|
ID3D11InputLayout *m_InputLayoutPtr;
|
|
ID3D11Buffer *m_VertexBufferPtr;
|
|
ID3D11Buffer *m_IndexBufferPtr;
|
|
|
|
ID3D11Buffer* m_InstanceBufferPtr;
|
|
std::vector<InstancedData> m_InstancedData;
|
|
UINT m_InstanceCount;
|
|
|
|
std::vector<VertexIn> m_VerticesIn;
|
|
std::vector<uint32_t> m_Indices;
|
|
UINT m_IndicesCount;
|
|
|
|
std::shared_ptr<Material> m_Material{};
|
|
|
|
PrimitiveTopology m_PrimitiveTopology{PrimitiveTopology::TriangleList};
|
|
|
|
};
|
|
|
|
|
|
#endif //GP1_DIRECTX_INSTANCEDMESH_H
|