The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
gbuffer.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_GBUFFER
10 #define DUNE_GBUFFER
11 
12 #include "render_target.h"
13 
14 #include <vector>
15 #include <string>
16 
17 #include <D3D11.h>
18 
19 namespace dune
20 {
30  class gbuffer : public shader_resource
31  {
32  protected:
33  typedef std::vector<render_target> targets_vec;
34  typedef std::vector<ID3D11ShaderResourceView*> srv_vec;
35 
36  srv_vec srvs_;
37  targets_vec buffers_;
38  ID3D11Device* device_;
39 
40  protected:
42 
43  render_target* target(const tstring& name);
44  const render_target* target(const tstring& name) const;
46 
48  void srvs(srv_vec& srv_array);
49 
50  public:
51  gbuffer();
52  virtual ~gbuffer() {}
53 
54  void create(ID3D11Device* device, const tstring& name);
55  virtual void destroy();
56 
58 
59  void add_target(const tstring& name, render_target& target);
60  void add_target(const tstring& name, const D3D11_TEXTURE2D_DESC& desc, bool cached = false);
61  void add_target(const tstring& name, const DXGI_SURFACE_DESC& desc, UINT num_mipmaps = 1);
62  void add_depth(const tstring& name, DXGI_SURFACE_DESC desc);
64 
66  targets_vec& targets();
67 
69 
70  render_target* operator[](const tstring& name);
71  const render_target* operator[](const tstring& name) const;
73 
75  void resize(UINT width, UINT height);
76 
77  void to_ps(ID3D11DeviceContext* context, UINT start_slot);
78  void to_gs(ID3D11DeviceContext* context, UINT start_slot);
79  void to_vs(ID3D11DeviceContext* context, UINT start_slot);
80  };
81 }
82 
83 #endif
void add_target(const tstring &name, render_target &target)
Create a new render_target in the gbuffer. These functions basically forward parameters to the render...
Definition: gbuffer.cpp:79
A shader resource wrapper.
Definition: shader_resource.h:24
void to_ps(ID3D11DeviceContext *context, UINT start_slot)
Upload the shader resource to register slot of a pixel shader.
Definition: gbuffer.cpp:134
void add_depth(const tstring &name, DXGI_SURFACE_DESC desc)
Create a new render_target in the gbuffer. These functions basically forward parameters to the render...
Definition: gbuffer.cpp:113
render_target * operator[](const tstring &name)
Fetch a render_target with its name.
Definition: gbuffer.cpp:32
render_target * target(const tstring &name)
Return a named target.
Definition: gbuffer.cpp:53
void to_gs(ID3D11DeviceContext *context, UINT start_slot)
Upload the shader resource to register slot of a geometry shader.
Definition: gbuffer.cpp:139
void srvs(srv_vec &srv_array)
Fill up a vector of ID3D11ShaderResourceView with the SRVs of all render_target objects in this gbuff...
A render target wrapper.
Definition: render_target.h:30
void to_vs(ID3D11DeviceContext *context, UINT start_slot)
Upload the shader resource to register slot of a vertex shader.
Definition: gbuffer.cpp:144
void resize(UINT width, UINT height)
Resize all render_target objects in this gbuffer to a new width and height.
Definition: gbuffer.cpp:47
A geometry buffer (collection of render_target objects).
Definition: gbuffer.h:30
targets_vec & targets()
Returns all render_target objects in this gbuffer.
Definition: gbuffer.cpp:42
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: gbuffer.cpp:24