The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
render_target.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_RENDER_TARGET
10 #define DUNE_RENDER_TARGET
11 
12 #include <D3D11.h>
13 #include <DirectXMath.h>
14 #include <string>
15 
16 #include "texture.h"
17 
18 namespace dune
19 {
30  class render_target : public texture
31  {
32  protected:
33  ID3D11Device* device_;
34  ID3D11RenderTargetView* rtview_;
35  ID3D11DepthStencilView* dsview_;
36 
37  bool cached_;
38  std::vector<BYTE> cached_copy_;
39 
40  protected:
41  virtual void do_create(ID3D11Device* device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA* subresource);
42 
43  public:
44  render_target();
45  virtual ~render_target() {}
46 
47  /* \brief Returns the render target view (RTV). */
48  ID3D11RenderTargetView* const rtv() const { return rtview_; }
49 
50  /* \brief Returns the depth stencil view (DSV). */
51  ID3D11DepthStencilView* const dsv() const { return dsview_; }
52 
53  /*
54  * \brief Resize the render_target.
55  *
56  * Resizes the render_target. Because new views are generated, old views still bound to the GPU are invalid. After a resize,
57  * all views need to be re-bound!
58  *
59  * \param width The new width of the render_target.
60  * \param height The new height of the render_target.
61  */
62  void resize(UINT width, UINT height);
63 
64  virtual void destroy();
65 
67  void update(ID3D11DeviceContext* context);
68 
70  void copy(const BYTE* data, size_t num_bytes);
71 
73  template<typename T>
74  T data()
75  {
76  return reinterpret_cast<T>(&cached_copy_[0]);
77  }
78 
80 
81  void enable_cached(bool c) { cached_ = c; }
82  bool cached() { return cached_; }
84  };
85 
86  void load_static_target(ID3D11Device* device, const tstring& filename, render_target& t);
87 }
88 
89 #endif // RENDER_TARGET
T data()
Returns a pointer to the internal CPU texture cache.
Definition: render_target.h:74
void update(ID3D11DeviceContext *context)
If this texture is cached, this method will copy the CPU side cache to the render_target texture...
Definition: render_target.cpp:115
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: render_target.cpp:98
void enable_cached(bool c)
Enable caching. If this is true, creating this object will copy the initial subresource to a cache...
Definition: render_target.h:81
A render target wrapper.
Definition: render_target.h:30
void copy(const BYTE *data, size_t num_bytes)
Copy a data array of num_bytes size into the internal CPU cache.
Definition: render_target.cpp:110
Wrapper for a Direct3D texture object.
Definition: texture.h:25
bool cached()
Enable caching. If this is true, creating this object will copy the initial subresource to a cache...
Definition: render_target.h:82