Crazy Eddies GUI System  0.6.2
d3d9renderer.h
1 /***********************************************************************
2  filename: d3d9renderer.h
3  created: 17/7/2004
4  author: Paul D Turner with D3D 9 Updates by Magnus Österlind
5 
6  purpose: Interface for DirectX 9.0 Renderer class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 /*************************************************************************
31  This file contains code that is specific to Win32 and DirectX
32 *************************************************************************/
33 #ifndef _d3d9renderer_h_
34 #define _d3d9renderer_h_
35 
36 #include "CEGUIBase.h"
37 #include "CEGUIRenderer.h"
38 #include "CEGUITexture.h"
39 #include <d3d9.h>
40 #include <list>
41 #include <set>
42 
43 #if !defined(CEGUI_STATIC)
44  #ifdef DIRECTX9_GUIRENDERER_EXPORTS
45  #define DIRECTX9_GUIRENDERER_API __declspec(dllexport)
46  #else
47  #define DIRECTX9_GUIRENDERER_API __declspec(dllimport)
48  #endif
49 #else
50  #define DIRECTX9_GUIRENDERER_API
51 #endif
52 
53 
54 #if defined(_MSC_VER)
55 # pragma warning(push)
56 # pragma warning(disable : 4251)
57 #endif
58 
59 
60 // Start of CEGUI namespace section
61 namespace CEGUI
62 {
63 /*************************************************************************
64  Forward refs
65 *************************************************************************/
66 class DirectX9Texture;
67 
72 class DIRECTX9_GUIRENDERER_API DirectX9Renderer : public Renderer
73 {
74 public:
85  DirectX9Renderer(LPDIRECT3DDEVICE9 device, uint max_quads);
86 
91  virtual ~DirectX9Renderer(void);
92 
93  // add's a quad to the list to be rendered
94  virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
95 
96  // perform final rendering for all queued renderable quads.
97  virtual void doRender(void);
98 
99  // clear the queue
100  virtual void clearRenderList(void);
101 
102 
118  virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
119 
120 
121  // create an empty texture
122  virtual Texture* createTexture(void);
123 
124  // create a texture and load it with the specified file.
125  virtual Texture* createTexture(const String& filename, const String& resourceGroup);
126 
127  // create a texture and set it to the specified size
128  virtual Texture* createTexture(float size);
129 
130  // destroy the given texture
131  virtual void destroyTexture(Texture* texture);
132 
133  // destroy all textures still active
134  virtual void destroyAllTextures(void);
135 
136  // return ptr to device
137  LPDIRECT3DDEVICE9 getDevice(void) const {return d_device;}
138 
139 
147  virtual bool isQueueingEnabled(void) const {return d_queueing;}
148 
149 
157  virtual float getWidth(void) const {return d_display_area.getWidth();}
158 
159 
167  virtual float getHeight(void) const {return d_display_area.getHeight();}
168 
169 
177  virtual Size getSize(void) const {return d_display_area.getSize();}
178 
179 
188  virtual Rect getRect(void) const {return d_display_area;}
189 
190 
198  virtual uint getMaxTextureSize(void) const {return d_maxTextureSize;}
199 
200 
208  virtual uint getHorzScreenDPI(void) const {return 96;}
209 
210 
218  virtual uint getVertScreenDPI(void) const {return 96;}
219 
220 
227  virtual void preD3DReset(void);
228 
229 
236  virtual void postD3DReset(void);
237 
238 
256  void setDisplaySize(const Size& sz);
257 
258 
259 private:
260  /************************************************************************
261  Implementation Constants
262  ************************************************************************/
263  static const int VERTEX_PER_QUAD;
264  static const int VERTEX_PER_TRIANGLE;
265  static const int VERTEXBUFFER_CAPACITY;
266  static const ulong VERTEX_FVF;
267 
268  /*************************************************************************
269  Implementation Structs & classes
270  *************************************************************************/
275  struct QuadVertex {
276  FLOAT x, y, z, rhw;
277  DWORD diffuse;
278  float tu1, tv1;
279  };
280 
285  struct QuadInfo
286  {
287  LPDIRECT3DTEXTURE9 texture;
288  Rect position;
289  float z;
290  Rect texPosition;
291  ulong topLeftCol;
292  ulong topRightCol;
293  ulong bottomLeftCol;
294  ulong bottomRightCol;
295 
296  QuadSplitMode splitMode;
297 
298  bool operator<(const QuadInfo& other) const
299  {
300  // this is intentionally reversed.
301  return z > other.z;
302  }
303  };
304 
305 
306  /*************************************************************************
307  Implementation Methods
308  *************************************************************************/
309  // setup states etc
310  void initPerFrameStates(void);
311 
312  // renders whatever is in the vertex buffer
313  void renderVBuffer(void);
314 
315  // sort quads list according to texture
316  void sortQuads(void);
317 
318  // render a quad directly to the display
319  void renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
320 
321  // return size of device view port (if possible)
322  Size getViewportSize(void);
323 
324  // method to do work of constructor
325  void constructor_impl(LPDIRECT3DDEVICE9 device, const Size& display_size);
326 
327 
328  /*************************************************************************
329  Implementation Data
330  *************************************************************************/
331  Rect d_display_area;
332 
333  typedef std::multiset<QuadInfo> QuadList;
334  QuadList d_quadlist;
335  bool d_queueing;
336 
337  LPDIRECT3DDEVICE9 d_device;
338  LPDIRECT3DTEXTURE9 d_currTexture;
339  LPDIRECT3DVERTEXBUFFER9 d_buffer;
340  int d_bufferPos;
341 
342  std::list<DirectX9Texture*> d_texturelist;
343 
344  uint d_maxTextureSize;
345 };
346 
347 } // End of CEGUI namespace section
348 
349 #if defined(_MSC_VER)
350 # pragma warning(pop)
351 #endif
352 
353 #endif // end of guard _d3d9renderer_h_