Crazy Eddies GUI System  0.6.2
renderer.h
1 /***********************************************************************
2  filename: renderer.h
3  created: 15/3/2004
4  author: Paul D Turner
5 
6  purpose: Interface for DirectX 8.1 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 _DirectX81GUIRenderer_h_
34 #define _DirectX81GUIRenderer_h_
35 
36 #if !defined(CEGUI_STATIC)
37  #ifdef DIRECTX81_GUIRENDERER_EXPORTS
38  #define DIRECTX81_GUIRENDERER_API __declspec(dllexport)
39  #else
40  #define DIRECTX81_GUIRENDERER_API __declspec(dllimport)
41  #endif
42 #else
43  #define DIRECTX81_GUIRENDERER_API
44 #endif
45 
46 #include "CEGUIBase.h"
47 #include "CEGUIRenderer.h"
48 #include "CEGUITexture.h"
49 #include <d3d8.h>
50 #include <list>
51 #include <set>
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 DirectX81Texture;
67 
72 class DIRECTX81_GUIRENDERER_API DirectX81Renderer : public Renderer
73 {
74 public:
85  DirectX81Renderer(LPDIRECT3DDEVICE8 device, uint max_quads = 0);
86 
87 
98  DirectX81Renderer(LPDIRECT3DDEVICE8 device, const Size& sz);
99 
100 
105  virtual ~DirectX81Renderer(void);
106 
107  // add's a quad to the list to be rendered
108  virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
109 
110  // perform final rendering for all queued renderable quads.
111  virtual void doRender(void);
112 
113  // clear the queue
114  virtual void clearRenderList(void);
115 
116 
132  virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
133 
134 
135  // create an empty texture
136  virtual Texture* createTexture(void);
137 
138  // create a texture and load it with the specified file.
139  virtual Texture* createTexture(const String& filename, const String& resourceGroup);
140 
141  // create a texture and set it to the specified size
142  virtual Texture* createTexture(float size);
143 
144  // destroy the given texture
145  virtual void destroyTexture(Texture* texture);
146 
147  // destroy all textures still active
148  virtual void destroyAllTextures(void);
149 
150  // return ptr to device
151  LPDIRECT3DDEVICE8 getDevice(void) const {return d_device;}
152 
153 
161  virtual bool isQueueingEnabled(void) const {return d_queueing;}
162 
163 
171  virtual float getWidth(void) const {return d_display_area.getWidth();}
172 
173 
181  virtual float getHeight(void) const {return d_display_area.getHeight();}
182 
183 
191  virtual Size getSize(void) const {return d_display_area.getSize();}
192 
193 
202  virtual Rect getRect(void) const {return d_display_area;}
203 
204 
212  virtual uint getMaxTextureSize(void) const {return d_maxTextureSize;}
213 
214 
222  virtual uint getHorzScreenDPI(void) const {return 96;}
223 
224 
232  virtual uint getVertScreenDPI(void) const {return 96;}
233 
234 
241  virtual void preD3DReset(void);
242 
243 
250  virtual void postD3DReset(void);
251 
252 
271  void setDisplaySize(const Size& sz);
272 
273 
274 private:
275  /************************************************************************
276  Implementation Constants
277  ************************************************************************/
278  static const int VERTEX_PER_QUAD;
279  static const int VERTEX_PER_TRIANGLE;
280  static const int VERTEXBUFFER_CAPACITY;
281  static const ulong VERTEX_FVF;
282 
283  /*************************************************************************
284  Implementation Structs & classes
285  *************************************************************************/
290  struct QuadVertex {
291  FLOAT x, y, z, rhw;
292  DWORD diffuse;
293  float tu1, tv1;
294  };
295 
300  struct QuadInfo
301  {
302  LPDIRECT3DTEXTURE8 texture;
303  Rect position;
304  float z;
305  Rect texPosition;
306  ulong topLeftCol;
307  ulong topRightCol;
308  ulong bottomLeftCol;
309  ulong bottomRightCol;
310 
311  QuadSplitMode splitMode;
312 
313  bool operator<(const QuadInfo& other) const
314  {
315  // this is intentionally reversed.
316  return z > other.z;
317  }
318  };
319 
320 
321  /*************************************************************************
322  Implementation Methods
323  *************************************************************************/
324  // setup states etc
325  void initPerFrameStates(void);
326 
327  // renders whatever is in the vertex buffer
328  void renderVBuffer(void);
329 
330  // sort quads list according to texture
331  void sortQuads(void);
332 
333  // render a quad directly to the display
334  void renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
335 
336  // return size of device view port (if possible)
337  Size getViewportSize(void);
338 
339  // method to do work of constructor
340  void constructor_impl(LPDIRECT3DDEVICE8 device, const Size& display_size);
341 
342 
343  /*************************************************************************
344  Implementation Data
345  *************************************************************************/
346  Rect d_display_area;
347 
348  typedef std::multiset<QuadInfo> QuadList;
349  QuadList d_quadlist;
350  bool d_queueing;
351 
352  LPDIRECT3DDEVICE8 d_device;
353  LPDIRECT3DTEXTURE8 d_currTexture;
354  LPDIRECT3DVERTEXBUFFER8 d_buffer;
355  int d_bufferPos;
356 
357  std::list<DirectX81Texture*> d_texturelist;
358 
359  uint d_maxTextureSize;
360  bool d_canGetVPSize;
361 };
362 
363 } // End of CEGUI namespace section
364 
365 
366 #if defined(_MSC_VER)
367 # pragma warning(pop)
368 #endif
369 
370 #endif // end of guard _DirectX81GUIRenderer_h_