The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
sdk_mesh.h
Go to the documentation of this file.
1 /*
2  * Dune D3D library - Tobias Alexander Franke 2011
3  * For copyright and license see LICENSE
4  * http://www.tobias-franke.eu
5  */
6 
9 #ifndef DUNE_SDK_MESH
10 #define DUNE_SDK_MESH
11 
12 #include <memory>
13 
14 #include "mesh.h"
15 #include "cbuffer.h"
16 
17 class CDXUTSDKMesh;
18 
19 namespace dune {
20 
21 const D3D11_INPUT_ELEMENT_DESC sdkmesh_vertex_desc[] =
22 {
23  { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
24  { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
25  { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
26  { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
27  0
28 };
29 
31 class sdk_mesh : public d3d_mesh
32 {
33 protected:
34  std::shared_ptr<CDXUTSDKMesh> sdk_mesh_;
35 
36  struct cbs_mesh_data_ps
37  {
38  DirectX::XMFLOAT4 diffuse_color;
39  BOOL has_diffuse_tex;
40  BOOL has_normal_tex;
41  BOOL has_specular_tex;
42  BOOL has_alpha_tex;
43  };
44 
45  struct cbs_mesh_data_vs
46  {
47  DirectX::XMFLOAT4X4 world;
48  };
49 
50  cbuffer<cbs_mesh_data_ps> cb_mesh_data_ps_;
51  cbuffer<cbs_mesh_data_vs> cb_mesh_data_vs_;
52 
53 protected:
54  virtual void reset();
55  virtual const D3D11_INPUT_ELEMENT_DESC* vertex_desc() { return sdkmesh_vertex_desc; }
56  void load_texture(ID3D11Device* device, ID3D11Resource* texture, ID3D11ShaderResourceView* srv, void* context);
57 
58 public:
59  size_t num_vertices();
60  size_t num_faces();
61 
62  void create(ID3D11Device* device, LPCTSTR file);
63  virtual void render(ID3D11DeviceContext* context, DirectX::XMFLOAT4X4* to_clip);
64 };
65 
66 }
67 
68 #endif // SDK_MESH
size_t num_faces()
Returns the number of faces of a mesh.
Definition: sdk_mesh.cpp:167
const DirectX::XMFLOAT4X4 & world()
Returns the current world matrix of this mesh.
Definition: mesh.h:79
size_t num_vertices()
Returns the number of vertices of a mesh.
Definition: sdk_mesh.cpp:157
A d3d_mesh created with the SDKMesh DXUT loader.
Definition: sdk_mesh.h:31
virtual void render(ID3D11DeviceContext *context, DirectX::XMFLOAT4X4 *to_clip)
Renders the mesh using the shaders previously set.
Definition: sdk_mesh.cpp:67
Wrapper for a Direct3D texture object.
Definition: texture.h:25
Main D3D mesh interface class.
Definition: mesh.h:129