Crazy Eddies GUI System: renderer.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# renderer.h

    00001 /************************************************************************
    00002         filename:       renderer.h
    00003         created:        15/3/2004
    00004         author:         Paul D Turner
    00005
    00006         purpose:        Interface for DirectX 8.1 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 _DirectX81GUIRenderer_h_
    00030 #define _DirectX81GUIRenderer_h_
    00031
    00032 #ifdef DIRECTX81_GUIRENDERER_EXPORTS
    00033 #define DIRECTX81_GUIRENDERER_API __declspec(dllexport)
    00034 #else
    00035 #define DIRECTX81_GUIRENDERER_API __declspec(dllimport)
    00036 #endif
    00037
    00038 #include "CEGUIBase.h"
    00039 #include "CEGUIRenderer.h"
    00040 #include "CEGUITexture.h"
    00041 #include <d3d8.h>
    00042 #include <list>
    00043 #include <set>
    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 DirectX81Texture;
    00059
    00064 class DIRECTX81_GUIRENDERER_API DirectX81Renderer : public Renderer
    00065 {
    00066 public:
    00077         DirectX81Renderer(LPDIRECT3DDEVICE8 device, uint max_quads = 0);
    00078
    00079
    00090         DirectX81Renderer(LPDIRECT3DDEVICE8 device, const Size& sz);
    00091
    00092
    00097         virtual ~DirectX81Renderer(void);
    00098
    00099         // add's a quad to the list to be rendered
    00100         virtual void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
    00101
    00102         // perform final rendering for all queued renderable quads.
    00103         virtual void    doRender(void);
    00104
    00105         // clear the queue
    00106         virtual void    clearRenderList(void);
    00107
    00108
    00124         virtual void    setQueueingEnabled(bool setting)                {d_queueing = setting;}
    00125
    00126
    00127         // create an empty texture
    00128         virtual Texture*        createTexture(void);
    00129
    00130         // create a texture and load it with the specified file.
    00131         virtual Texture*        createTexture(const String& filename, const String& resourceGroup);
    00132
    00133         // create a texture and set it to the specified size
    00134         virtual Texture*        createTexture(float size);
    00135
    00136         // destroy the given texture
    00137         virtual void            destroyTexture(Texture* texture);
    00138
    00139         // destroy all textures still active
    00140         virtual void            destroyAllTextures(void);
    00141
    00142         // return ptr to device
    00143         LPDIRECT3DDEVICE8       getDevice(void) const           {return d_device;}
    00144
    00145
    00153         virtual bool    isQueueingEnabled(void) const   {return d_queueing;}
    00154
    00155
    00163         virtual float   getWidth(void) const            {return d_display_area.getWidth();}
    00164
    00165
    00173         virtual float   getHeight(void) const           {return d_display_area.getHeight();}
    00174
    00175
    00183         virtual Size    getSize(void) const                     {return d_display_area.getSize();}
    00184
    00185
    00194         virtual Rect    getRect(void) const                     {return d_display_area;}
    00195
    00196
    00204         virtual uint    getMaxTextureSize(void) const           {return d_maxTextureSize;}
    00205
    00206
    00214         virtual uint    getHorzScreenDPI(void) const    {return 96;}
    00215
    00216
    00224         virtual uint    getVertScreenDPI(void) const    {return 96;}
    00225
    00226
    00233         virtual void    preD3DReset(void);
    00234
    00235
    00242         virtual void    postD3DReset(void);
    00243
    00244
    00263         void    setDisplaySize(const Size& sz);
    00264
    00265
    00266 private:
    00267         /************************************************************************
    00268                 Implementation Constants
    00269         ************************************************************************/
    00270         static const int                        VERTEX_PER_QUAD;
    00271         static const int                        VERTEX_PER_TRIANGLE;
    00272         static const int                        VERTEXBUFFER_CAPACITY;
    00273         static const ulong                      VERTEX_FVF;
    00274
    00275         /*************************************************************************
    00276             Implementation Structs & classes
    00277         *************************************************************************/
    00282         struct QuadVertex {
    00283                 FLOAT x, y, z, rhw;
    00284                 DWORD diffuse;
    00285                 float tu1, tv1;
    00286         };
    00287
    00292         struct QuadInfo
    00293         {
    00294                 LPDIRECT3DTEXTURE8      texture;
    00295                 Rect                            position;
    00296                 float                           z;
    00297                 Rect                            texPosition;
    00298                 ulong                           topLeftCol;
    00299                 ulong                           topRightCol;
    00300                 ulong                           bottomLeftCol;
    00301                 ulong                           bottomRightCol;
    00302
    00303         QuadSplitMode       splitMode;
    00304
    00305                 bool operator<(const QuadInfo& other) const
    00306                 {
    00307                         // this is intentionally reversed.
    00308                         return z > other.z;
    00309                 }
    00310         };
    00311
    00312
    00313         /*************************************************************************
    00314             Implementation Methods
    00315         *************************************************************************/
    00316         // setup states etc
    00317         void    initPerFrameStates(void);
    00318
    00319         // renders whatever is in the vertex buffer
    00320         void    renderVBuffer(void);
    00321
    00322         // sort quads list according to texture
    00323         void    sortQuads(void);
    00324
    00325         // render a quad directly to the display
    00326         void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
    00327
    00328         // return size of device view port (if possible)
    00329         Size    getViewportSize(void);
    00330
    00331         // method to do work of constructor
    00332         void    constructor_impl(LPDIRECT3DDEVICE8 device, const Size& display_size);
    00333
    00334
    00335         /*************************************************************************
    00336             Implementation Data
    00337         *************************************************************************/
    00338         Rect                            d_display_area;
    00339
    00340         typedef std::multiset<QuadInfo>         QuadList;
    00341         QuadList d_quadlist;
    00342         bool    d_queueing;
    00343
    00344         LPDIRECT3DDEVICE8               d_device;
    00345         LPDIRECT3DTEXTURE8              d_currTexture;
    00346         LPDIRECT3DVERTEXBUFFER8 d_buffer;
    00347         int                                             d_bufferPos;
    00348
    00349         std::list<DirectX81Texture*>    d_texturelist;
    00350
    00351         uint    d_maxTextureSize;
    00352         bool    d_canGetVPSize;
    00353 };
    00354
    00355 } // End of  CEGUI namespace section
    00356
    00357
    00358 #if defined(_MSC_VER)
    00359 #       pragma warning(pop)
    00360 #endif
    00361
    00362 #endif  // end of guard _DirectX81GUIRenderer_h_