Crazy Eddies GUI System  0.6.2
d3d10renderer.h
1 /***********************************************************************
2  filename: d3d10renderer.h
3  created: 17/7/2004
4  author: Paul D Turner with D3D 9 Updates by Magnus Österlind
5  D3D10 Port by Rajko Stojadinovic
6 
7  purpose: Interface for DirectX 10.0 Renderer class
8 *************************************************************************/
9 /***************************************************************************
10  * Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining
13  * a copy of this software and associated documentation files (the
14  * "Software"), to deal in the Software without restriction, including
15  * without limitation the rights to use, copy, modify, merge, publish,
16  * distribute, sublicense, and/or sell copies of the Software, and to
17  * permit persons to whom the Software is furnished to do so, subject to
18  * the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be
21  * included in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  ***************************************************************************/
31 /*************************************************************************
32  This file contains code that is specific to Win32 and DirectX
33 *************************************************************************/
34 #ifndef _d3d10renderer_h_
35 #define _d3d10renderer_h_
36 
37 #include "CEGUIBase.h"
38 #include "CEGUIRenderer.h"
39 #include "CEGUITexture.h"
40 
41 // Little hack to allow D3D10 to compile on a non-Vista. Of course, actually using this
42 // renderer on XP is out of the question. These fixes are not needed in VC9 anymore.
43 #if _MSC_VER <= 1400 // VC8 and lower
44 
45  // One fix for VC8
46  #define WINAPI_INLINE WINAPI
47 
48  #if _MSC_VER < 1400 // VC7.1 and lower
49 
50  #define __out
51  #define __in
52  #define __inout
53 
54  #define __in_opt
55  #define __out_opt
56  #define __inout_opt
57 
58  #define __in_ecount(THING)
59  #define __in_ecount_opt(THING)
60  #define __out_ecount(THING)
61  #define __out_ecount_opt(THING)
62  #define __inout_ecount(THING)
63  #define __inout_ecount_opt(THING)
64 
65  #define __in_bcount_opt(THING)
66  #define __out_bcount_opt(THING)
67  #define __inout_bcount_opt(THING)
68 
69  #endif // < 1400
70 
71 #endif // <= 1400
72 
73 #include <d3d10.h>
74 #include <list>
75 #include <set>
76 
77 typedef ID3D10Buffer IDirect3DIndexBuffer;
78 typedef ID3D10Buffer IDirect3DVertexBuffer;
79 typedef D3D10_VIEWPORT D3DVIEWPORT;
80 typedef ID3D10VertexShader IDirect3DVertexShader;
81 typedef ID3D10PixelShader IDirect3DPixelShader;
82 typedef ID3D10Device* LPDIRECT3DDEVICE;
83 typedef ID3D10Texture2D* LPDIRECT3DTEXTURE2D;
84 typedef ID3D10Buffer* LPDIRECT3DBUFFER;
85 
86 #if !defined(CEGUI_STATIC)
87  #ifdef DIRECTX10_GUIRENDERER_EXPORTS
88  #define DIRECTX10_GUIRENDERER_API __declspec(dllexport)
89  #else
90  #define DIRECTX10_GUIRENDERER_API __declspec(dllimport)
91  #endif
92 #else
93  #define DIRECTX10_GUIRENDERER_API
94 #endif
95 
96 #if defined(_MSC_VER)
97 # pragma warning(push)
98 # pragma warning(disable : 4251)
99 #endif
100 
101 
102 // Start of CEGUI namespace section
103 namespace CEGUI
104 {
105 /*************************************************************************
106  Forward refs
107 *************************************************************************/
108 class DirectX10Texture;
109 
114 class DIRECTX10_GUIRENDERER_API DirectX10Renderer : public Renderer
115 {
116 public:
128  DirectX10Renderer(LPDIRECT3DDEVICE device, uint max_quads);
129 
134  virtual ~DirectX10Renderer(void);
135 
136  // add a quad to the list to be rendered
137  virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex,
138  const Rect& texture_rect, const ColourRect& colours,
139  QuadSplitMode quad_split_mode);
140 
141  // perform final rendering for all queued renderable quads.
142  virtual void doRender(void);
143 
144  // clear the queue
145  virtual void clearRenderList(void);
146 
166  virtual void setQueueingEnabled(bool setting)
167  { d_queueing = setting; }
168 
169  // create an empty texture
170  virtual Texture* createTexture(void);
171 
172  // create a texture and load it with the specified file.
173  virtual Texture* createTexture(const String& filename,
174  const String& resourceGroup);
175 
176  // create a texture and set it to the specified size
177  virtual Texture* createTexture(float size);
178 
179  // destroy the given texture
180  virtual void destroyTexture(Texture* texture);
181 
182  // destroy all textures still active
183  virtual void destroyAllTextures(void);
184 
186  LPDIRECT3DDEVICE getDevice(void) const
187  { return d_device; }
188 
197  virtual bool isQueueingEnabled(void) const
198  { return d_queueing; }
199 
207  virtual float getWidth(void) const
208  { return d_display_area.getWidth(); }
209 
217  virtual float getHeight(void) const
218  { return d_display_area.getHeight(); }
219 
227  virtual Size getSize(void) const
228  { return d_display_area.getSize(); }
229 
230 
240  virtual Rect getRect(void) const
241  { return d_display_area; }
242 
251  virtual uint getMaxTextureSize(void) const
252  { return d_maxTextureSize; }
253 
261  virtual uint getHorzScreenDPI(void) const
262  { return 96; }
263 
271  virtual uint getVertScreenDPI(void) const
272  { return 96; }
273 
291  void setDisplaySize(const Size& sz);
292 
293 private:
294  /************************************************************************
295  Implementation Constants
296  ************************************************************************/
298  static const int VERTEX_PER_QUAD;
300  static const int VERTEX_PER_TRIANGLE;
302  static const int VERTEXBUFFER_CAPACITY;
303 
304  /*************************************************************************
305  Implementation Structs & classes
306  *************************************************************************/
308  struct QuadVertex {
310  FLOAT x, y, z;
312  DWORD diffuse;
314  float tu1, tv1;
315  };
316 
318  struct QuadInfo
319  {
320  LPDIRECT3DTEXTURE2D texture;
321  ID3D10ShaderResourceView* resview;
322  Rect position;
323  float z;
324  Rect texPosition;
325  ulong topLeftCol;
326  ulong topRightCol;
327  ulong bottomLeftCol;
328  ulong bottomRightCol;
329  QuadSplitMode splitMode;
330 
331  bool operator<(const QuadInfo& other) const
332  {
333  // this is intentionally reversed.
334  return z > other.z;
335  }
336  };
337 
338  /*************************************************************************
339  Implementation Methods
340  *************************************************************************/
342  void renderVBuffer(ID3D10ShaderResourceView *tex);
343 
345  void renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex,
346  const Rect& texture_rect, const ColourRect& colours,
347  QuadSplitMode quad_split_mode);
348 
350  Size getViewportSize(void);
351 
353  void constructor_impl(LPDIRECT3DDEVICE device, const Size& display_size);
354 
355  HRESULT CreateVertexBuffer();
356 
357  /*************************************************************************
358  Implementation Data
359  *************************************************************************/
361  Rect d_display_area;
363  typedef std::multiset<QuadInfo> QuadList;
365  QuadList d_quadlist;
367  bool d_queueing;
369  LPDIRECT3DDEVICE d_device;
371  LPDIRECT3DTEXTURE2D d_currTexture;
372  ID3D10ShaderResourceView* d_currSRView;
374  LPDIRECT3DBUFFER d_buffer;
376  int d_bufferPos;
377  ID3D10InputLayout* d_InputLayout;
378  // D3DX effect interface.
379  ID3D10Effect* d_Effect;
380  ID3D10EffectTechnique* d_Technique;
381  ID3D10EffectShaderResourceVariable* d_DiffuseTexVariable;
382  ID3D10EffectScalarVariable* d_WindowHeight;
383  ID3D10EffectScalarVariable* d_WindowWidth;
385  std::list<DirectX10Texture*> d_texturelist;
387  uint d_maxTextureSize;
388 };
389 
390 } // End of CEGUI namespace section
391 
392 #if defined(_MSC_VER)
393 # pragma warning(pop)
394 #endif
395 
396 #endif // end of guard _d3d10renderer_h_