Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
RendererModules/Direct3D11/Renderer.h
1 /***********************************************************************
2  created: Wed May 5 2010
3 *************************************************************************/
4 /***************************************************************************
5  * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  ***************************************************************************/
26 #ifndef _CEGUIDirect3D11Renderer_h_
27 #define _CEGUIDirect3D11Renderer_h_
28 
29 #include "../../Renderer.h"
30 #include "../../Size.h"
31 #include "../../Vector.h"
32 #include <vector>
33 #include <map>
34 
35 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
36 # ifdef CEGUIDIRECT3D11RENDERER_EXPORTS
37 # define D3D11_GUIRENDERER_API __declspec(dllexport)
38 # else
39 # define D3D11_GUIRENDERER_API __declspec(dllimport)
40 # endif
41 #else
42 # define D3D11_GUIRENDERER_API
43 #endif
44 
45 #if defined(_MSC_VER)
46 # pragma warning(push)
47 # pragma warning(disable : 4251)
48 #endif
49 
50 // D3D forward refs
51 struct ID3D11Device;
52 struct ID3D11DeviceContext;
53 struct ID3DX11Effect;//D3DXEffect11 in dependences
54 struct ID3DX11EffectTechnique;//D3DXEffect11 in dependences
55 struct ID3D11InputLayout;
56 struct ID3DX11EffectShaderResourceVariable;//D3DXEffect11 in dependences
57 struct ID3DX11EffectMatrixVariable;//D3DXEffect11 in dependences
58 struct ID3D11ShaderResourceView;//D3DXEffect11 in dependences
59 struct D3DXMATRIX;
60 
61 #include <d3d11.h>
62 #include <d3dx11.h>
63 #include <d3dx10.h>
64 
65 
66 struct IDevice11//little structure that keeps both device, in order to reduce copy & paste around module
67 {
69  ID3D11Device* d_device;
71  ID3D11DeviceContext* d_context;
72 };
73 
74 // Start of CEGUI namespace section
75 namespace CEGUI
76 {
77 class Direct3D11GeometryBuffer;
78 class Direct3D11Texture;
79 
80 
82 class D3D11_GUIRENDERER_API Direct3D11Renderer : public Renderer
83 {
84 public:
109  static Direct3D11Renderer& bootstrapSystem(ID3D11Device* device,
110  ID3D11DeviceContext* context,
111  const int abi = CEGUI_VERSION_ABI);
112 
128  static void destroySystem();
129 
134  static Direct3D11Renderer& create(ID3D11Device* device,ID3D11DeviceContext* context,
135  const int abi = CEGUI_VERSION_ABI);
136 
144  static void destroy(Direct3D11Renderer& renderer);
145 
146 // //! return the ID3D10Device used by this renderer object.
147 // ID3D11Device& getDirect3DDevice() const;
148 //
149 // //! return the ID3D11Device context used by this renderer object.
150 // ID3D11DeviceContext& getDirect3DDeviceContext() const;
151 
152  //returns d3d11 container for further rendering and creating
153  IDevice11& getDirect3DDevice();
154 
156  void bindTechniquePass(const BlendMode mode, const bool clipped);
158  void setCurrentTextureShaderResource(ID3D11ShaderResourceView* srv);
160  void setProjectionMatrix(D3DXMATRIX& matrix);
162  void setWorldMatrix(D3DXMATRIX& matrix);
163 
164  // Implement interface from Renderer
165  RenderTarget& getDefaultRenderTarget();
166  GeometryBuffer& createGeometryBuffer();
167  void destroyGeometryBuffer(const GeometryBuffer& buffer);
168  void destroyAllGeometryBuffers();
169  TextureTarget* createTextureTarget();
170  void destroyTextureTarget(TextureTarget* target);
171  void destroyAllTextureTargets();
172  Texture& createTexture(const String& name);
173  Texture& createTexture(const String& name,
174  const String& filename,
175  const String& resourceGroup);
176  Texture& createTexture(const String& name, const Sizef& size);
177  void destroyTexture(Texture& texture);
178  void destroyTexture(const String& name);
179  void destroyAllTextures();
180  Texture& getTexture(const String& name) const;
181  bool isTextureDefined(const String& name) const;
182  void beginRendering();
183  void endRendering();
184  void setDisplaySize(const Sizef& sz);
185  const Sizef& getDisplaySize() const;
186  const Vector2f& getDisplayDPI() const;
187  uint getMaxTextureSize() const;
188  const String& getIdentifierString() const;
189 
190 protected:
192  Direct3D11Renderer(ID3D11Device* device,ID3D11DeviceContext* context);
193 
196 
198  Sizef getViewportSize();
199 
201  void throwIfNameExists(const String& name) const;
203  static void logTextureCreation(const String& name);
205  static void logTextureDestruction(const String& name);
206 
210 
212 
220  typedef std::vector<TextureTarget*> TextureTargetList;
224  typedef std::vector<Direct3D11GeometryBuffer*> GeometryBufferList;
229  CEGUI_MAP_ALLOC(String, Direct3D11Texture*)> TextureMap;
233  ID3DX11Effect* d_effect;
235  ID3DX11EffectTechnique* d_normalClippedTechnique;
237  ID3DX11EffectTechnique* d_normalUnclippedTechnique;
239  ID3DX11EffectTechnique* d_premultipliedClippedTechnique;
241  ID3DX11EffectTechnique* d_premultipliedUnclippedTechnique;
243  ID3D11InputLayout* d_inputLayout;
245  ID3DX11EffectShaderResourceVariable* d_boundTextureVariable;
247  ID3DX11EffectMatrixVariable* d_worldMatrixVariable;
249  ID3DX11EffectMatrixVariable* d_projectionMatrixVariable;
250 };
251 
252 
253 } // End of CEGUI namespace section
254 
255 #if defined(_MSC_VER)
256 # pragma warning(pop)
257 #endif
258 
259 #endif // end of guard _CEGUIDirect3D11Renderer_h_