The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
texture.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_TEXTURE
10 #define DUNE_TEXTURE
11 
12 #include <D3D11.h>
13 #include <DirectXMath.h>
14 #include <vector>
15 
16 #include "shader_resource.h"
17 
18 namespace dune
19 {
25  class texture : public shader_resource
26  {
27  protected:
28  ID3D11ShaderResourceView* srview_;
29  ID3D11Texture2D* texture_;
30  DirectX::XMFLOAT2 size_;
31 
32  protected:
33  virtual void do_create(ID3D11Device* device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA* subresource);
34 
35  public:
36  texture();
37  virtual ~texture() {}
38 
39  /* \brief Returns the shader resource view (SRV). */
40  ID3D11ShaderResourceView* const srv() const { return srview_; }
41 
42  void to_vs(ID3D11DeviceContext* context, UINT slot);
43  void to_ps(ID3D11DeviceContext* context, UINT slot);
44 
46 
47  void create(ID3D11Device* device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA* subresource = nullptr);
48  void create(ID3D11Device* device, const DXGI_SURFACE_DESC& desc, UINT num_mipmaps = 1);
49  void create(ID3D11Device* device, UINT width, UINT height, DXGI_FORMAT format, const DXGI_SAMPLE_DESC& msaa, UINT num_mipmaps = 1);
51 
52  virtual void destroy();
53 
62  void* map(ID3D11DeviceContext* context);
63 
64  /* \brief Unmap a previously mapped texture. */
65  void unmap(ID3D11DeviceContext* context);
66 
67  /* \brief Returns the size of the texture as float2(width, height). */
68  DirectX::XMFLOAT2 size() const;
69 
70  /* \brief Returns a texture descriptor of the texture. */
71  D3D11_TEXTURE2D_DESC desc() const;
72 
73  /* \brief Returns a pointer to the actual resource behind the texture. */
74  ID3D11Texture2D* resource() const;
75  };
76 }
77 
78 #endif
void to_vs(ID3D11DeviceContext *context, UINT slot)
Upload the shader resource to register slot of a vertex shader.
Definition: texture.cpp:140
void * map(ID3D11DeviceContext *context)
Map the texture to a pointer.
Definition: texture.cpp:110
A shader resource wrapper.
Definition: shader_resource.h:24
void to_ps(ID3D11DeviceContext *context, UINT slot)
Upload the shader resource to register slot of a pixel shader.
Definition: texture.cpp:146
void create(ID3D11Device *device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA *subresource=nullptr)
Create an empty texture from given descriptor, other resource or single parameters.
Definition: texture.cpp:58
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: texture.cpp:98
Wrapper for a Direct3D texture object.
Definition: texture.h:25