9 #ifndef DUNE_SIMPLE_MESH
10 #define DUNE_SIMPLE_MESH
39 std::vector<vertex> vertices_;
41 ID3D11Buffer* mesh_data_;
44 virtual const D3D11_INPUT_ELEMENT_DESC* vertex_desc()
46 static D3D11_INPUT_ELEMENT_DESC l[] =
48 {
"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
68 vertices_.push_back(v);
79 virtual void create(ID3D11Device* device,
const tstring& name)
81 tclog << L
"Creating: simple geometry " << name << L
" with " <<
num_faces() <<
" faces" << std::endl;
84 ZeroMemory(&bd,
sizeof(bd));
85 bd.Usage = D3D11_USAGE_DEFAULT;
86 bd.ByteWidth =
sizeof(vertex)* 3;
87 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
88 bd.CPUAccessFlags = 0;
90 D3D11_SUBRESOURCE_DATA InitData;
91 ZeroMemory(&InitData,
sizeof(InitData));
92 InitData.pSysMem = &vertices_[0];
94 assert_hr(device->CreateBuffer(&bd, &InitData, &mesh_data_));
97 virtual void render(ID3D11DeviceContext* context, DirectX::XMFLOAT4X4* to_clip =
nullptr)
99 context->VSSetShader(vs_,
nullptr, 0);
100 context->IASetInputLayout(vertex_layout_);
101 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
103 static const UINT stride =
sizeof(vertex);
104 static const UINT offset = 0;
106 context->IASetVertexBuffers(0, 1, &mesh_data_, &stride, &offset);
113 return vertices_.size();
virtual void destroy()
Destroy a mesh and free all its resources.
Definition: mesh.cpp:42
virtual size_t num_faces()
Returns the number of faces of a mesh.
Definition: simple_mesh.h:116
virtual void create(ID3D11Device *device, const tstring &name)
Create a new simple_mesh.
Definition: simple_mesh.h:79
virtual void destroy()
Destroy a mesh and free all its resources.
Definition: simple_mesh.h:121
void push_back(DirectX::XMFLOAT3 &p)
Add a new vertex p to the mesh.
Definition: simple_mesh.h:65
virtual size_t num_vertices()
Returns the number of vertices of a mesh.
Definition: simple_mesh.h:111
void safe_release(T &obj)
Safely release an object of type T, setting it to nullptr afterwards.
Definition: d3d_tools.h:61
virtual void render(ID3D11DeviceContext *context, DirectX::XMFLOAT4X4 *to_clip=nullptr)
Renders the mesh using the shaders previously set.
Definition: simple_mesh.h:97
Main D3D mesh interface class.
Definition: mesh.h:129
A very simple mesh class with position-only vertex attributes.
Definition: simple_mesh.h:31