Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

d3d9renderer.h

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       d3d9renderer.h
00003         created:        17/7/2004
00004         author:         Paul D Turner with D3D 9 Updates by Magnus Österlind
00005         
00006         purpose:        Interface for DirectX 9.0 Renderer class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 /*************************************************************************
00027         This file contains code that is specific to Win32 and DirectX
00028 *************************************************************************/
00029 #ifndef _d3d9renderer_h_
00030 #define _d3d9renderer_h_
00031 
00032 #include "CEGUIBase.h"
00033 #include "CEGUIRenderer.h"
00034 #include "CEGUITexture.h"
00035 #include <d3d9.h>
00036 #include <list>
00037 #include <set>
00038 
00039 #ifdef DIRECTX9_GUIRENDERER_EXPORTS
00040 #define DIRECTX9_GUIRENDERER_API __declspec(dllexport)
00041 #else
00042 #define DIRECTX9_GUIRENDERER_API __declspec(dllimport)
00043 #endif
00044 
00045 
00046 #if defined(_MSC_VER)
00047 #       pragma warning(push)
00048 #       pragma warning(disable : 4251)
00049 #endif
00050 
00051 
00052 // Start of CEGUI namespace section
00053 namespace CEGUI
00054 {
00055 /*************************************************************************
00056         Forward refs
00057 *************************************************************************/
00058 class DirectX9Texture;
00059 
00064 class DIRECTX9_GUIRENDERER_API DirectX9Renderer : public Renderer
00065 {
00066 public:
00077         DirectX9Renderer(LPDIRECT3DDEVICE9 device, uint max_quads);
00078 
00083         virtual ~DirectX9Renderer(void);
00084 
00085         // add's a quad to the list to be rendered
00086         virtual void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00087 
00088         // perform final rendering for all queued renderable quads.
00089         virtual void    doRender(void);
00090 
00091         // clear the queue
00092         virtual void    clearRenderList(void);
00093 
00094 
00110         virtual void    setQueueingEnabled(bool setting)                {d_queueing = setting;}
00111 
00112 
00113         // create an empty texture
00114         virtual Texture*        createTexture(void);
00115 
00116         // create a texture and load it with the specified file.
00117         virtual Texture*        createTexture(const String& filename, const String& resourceGroup);
00118 
00119         // create a texture and set it to the specified size
00120         virtual Texture*        createTexture(float size);
00121 
00122         // destroy the given texture
00123         virtual void            destroyTexture(Texture* texture);
00124 
00125         // destroy all textures still active
00126         virtual void            destroyAllTextures(void);
00127 
00128         // return ptr to device
00129         LPDIRECT3DDEVICE9       getDevice(void) const           {return d_device;}
00130 
00131 
00139         virtual bool    isQueueingEnabled(void) const   {return d_queueing;}
00140 
00141 
00149         virtual float   getWidth(void) const            {return d_display_area.getWidth();}
00150 
00151 
00159         virtual float   getHeight(void) const           {return d_display_area.getHeight();}
00160 
00161 
00169         virtual Size    getSize(void) const                     {return d_display_area.getSize();}
00170 
00171 
00180         virtual Rect    getRect(void) const                     {return d_display_area;}
00181 
00182 
00190         virtual uint    getMaxTextureSize(void) const           {return d_maxTextureSize;}
00191 
00192 
00200         virtual uint    getHorzScreenDPI(void) const    {return 96;}
00201 
00202 
00210         virtual uint    getVertScreenDPI(void) const    {return 96;}
00211 
00212 
00219         virtual void    preD3DReset(void);
00220 
00221 
00228         virtual void    postD3DReset(void);
00229 
00230 
00248         void    setDisplaySize(const Size& sz);
00249 
00250 
00251 private:
00252         /************************************************************************
00253                 Implementation Constants
00254         ************************************************************************/
00255         const static int                        VERTEX_PER_QUAD;                                                        
00256         const static int                        VERTEX_PER_TRIANGLE;                                            
00257         const static int                        VERTEXBUFFER_CAPACITY;                                          
00258         const static ulong                      VERTEX_FVF;                                                                     
00259 
00260         /*************************************************************************
00261             Implementation Structs & classes
00262         *************************************************************************/
00267         struct QuadVertex {
00268                 FLOAT x, y, z, rhw;             
00269                 DWORD diffuse;                  
00270                 float tu1, tv1;                 
00271         };
00272 
00277         struct QuadInfo
00278         {
00279                 LPDIRECT3DTEXTURE9      texture;
00280                 Rect                            position;
00281                 float                           z;
00282                 Rect                            texPosition;
00283                 ulong                           topLeftCol;
00284                 ulong                           topRightCol;
00285                 ulong                           bottomLeftCol;
00286                 ulong                           bottomRightCol;
00287 
00288         QuadSplitMode       splitMode;
00289 
00290                 bool operator<(const QuadInfo& other) const
00291                 {
00292                         // this is intentionally reversed.
00293                         return z > other.z;
00294                 }
00295         };
00296 
00297 
00298         /*************************************************************************
00299             Implementation Methods
00300         *************************************************************************/
00301         // setup states etc
00302         void    initPerFrameStates(void);
00303 
00304         // renders whatever is in the vertex buffer
00305         void    renderVBuffer(void);
00306 
00307         // sort quads list according to texture
00308         void    sortQuads(void);
00309 
00310         // render a quad directly to the display
00311         void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00312 
00313         // return size of device view port (if possible)
00314         Size    getViewportSize(void);
00315 
00316         // method to do work of constructor
00317         void    constructor_impl(LPDIRECT3DDEVICE9 device, const Size& display_size);
00318 
00319 
00320         /*************************************************************************
00321             Implementation Data
00322         *************************************************************************/
00323         Rect                            d_display_area;
00324 
00325         typedef std::multiset<QuadInfo>         QuadList;
00326         QuadList d_quadlist;
00327         bool    d_queueing;             
00328 
00329         LPDIRECT3DDEVICE9               d_device;                       
00330         LPDIRECT3DTEXTURE9              d_currTexture;          
00331         LPDIRECT3DVERTEXBUFFER9 d_buffer;                       
00332         int                                             d_bufferPos;            
00333 
00334         std::list<DirectX9Texture*>     d_texturelist;          
00335 
00336         uint    d_maxTextureSize;               
00337 };
00338 
00339 } // End of  CEGUI namespace section
00340 
00341 #if defined(_MSC_VER)
00342 #       pragma warning(pop)
00343 #endif
00344 
00345 #endif  // end of guard _d3d9renderer_h_

Generated on Wed Feb 16 12:41:08 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1