home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / renderers / directx81GUIRenderer / renderer.h next >
Encoding:
C/C++ Source or Header  |  2005-11-08  |  10.7 KB  |  363 lines

  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.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. /*************************************************************************
  27.     This file contains code that is specific to Win32 and DirectX
  28. *************************************************************************/
  29. #ifndef _DirectX81GUIRenderer_h_
  30. #define _DirectX81GUIRenderer_h_
  31.  
  32. #ifdef DIRECTX81_GUIRENDERER_EXPORTS
  33. #define DIRECTX81_GUIRENDERER_API __declspec(dllexport)
  34. #else
  35. #define DIRECTX81_GUIRENDERER_API __declspec(dllimport)
  36. #endif
  37.  
  38. #include "CEGUIBase.h"
  39. #include "CEGUIRenderer.h"
  40. #include "CEGUITexture.h"
  41. #include <d3d8.h>
  42. #include <list>
  43. #include <set>
  44.  
  45.  
  46. #if defined(_MSC_VER)
  47. #    pragma warning(push)
  48. #    pragma warning(disable : 4251)
  49. #endif
  50.  
  51.  
  52. // Start of CEGUI namespace section
  53. namespace CEGUI
  54. {
  55. /*************************************************************************
  56.     Forward refs
  57. *************************************************************************/
  58. class DirectX81Texture;
  59.  
  60. /*!
  61. \brief
  62.     Renderer class to interface with Microsoft DirectX 8.1
  63. */
  64. class DIRECTX81_GUIRENDERER_API DirectX81Renderer : public Renderer
  65. {
  66. public:
  67.     /*!
  68.     \brief
  69.         Constructor for Direct3D 8.1 Renderer object
  70.  
  71.     \param device
  72.         Pointer to the IDirect3DDevice8 interface object that will be used for all rendering
  73.  
  74.     \param max_quads
  75.         Obsolete.  Set to 0.
  76.     */
  77.     DirectX81Renderer(LPDIRECT3DDEVICE8 device, uint max_quads = 0);
  78.  
  79.  
  80.     /*!
  81.     \brief
  82.         Constructor for Direct3D 8.1 Renderer object
  83.         
  84.     \param device
  85.         Pointer to the IDirect3DDevice8 interface object that will be used for all rendering
  86.  
  87.     \param sz
  88.         Size object describing the initial size of the display (the dimensions should be >0)
  89.     */
  90.     DirectX81Renderer(LPDIRECT3DDEVICE8 device, const Size& sz);
  91.  
  92.  
  93.     /*!
  94.     \brief
  95.         Destructor for DirectX81Renderer objects
  96.     */
  97.     virtual ~DirectX81Renderer(void);
  98.  
  99.     // add's a quad to the list to be rendered
  100.     virtual    void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
  101.  
  102.     // perform final rendering for all queued renderable quads.
  103.     virtual    void    doRender(void);
  104.  
  105.     // clear the queue
  106.     virtual    void    clearRenderList(void);
  107.  
  108.  
  109.     /*!
  110.     \brief
  111.         Enable or disable the queueing of quads from this point on.
  112.  
  113.         This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
  114.         disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
  115.         be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
  116.         to be added as if queueing had never been disabled.
  117.  
  118.     \param setting
  119.         true to enable queueing, or false to disable queueing (see notes above).
  120.  
  121.     \return
  122.         Nothing
  123.     */
  124.     virtual void    setQueueingEnabled(bool setting)        {d_queueing = setting;}
  125.  
  126.  
  127.     // create an empty texture
  128.     virtual    Texture*    createTexture(void);
  129.  
  130.     // create a texture and load it with the specified file.
  131.     virtual    Texture*    createTexture(const String& filename, const String& resourceGroup);
  132.  
  133.     // create a texture and set it to the specified size
  134.     virtual    Texture*    createTexture(float size);
  135.  
  136.     // destroy the given texture
  137.     virtual    void        destroyTexture(Texture* texture);
  138.  
  139.     // destroy all textures still active
  140.     virtual void        destroyAllTextures(void);
  141.  
  142.     // return ptr to device
  143.     LPDIRECT3DDEVICE8    getDevice(void) const        {return d_device;}
  144.  
  145.  
  146.     /*!
  147.     \brief
  148.         Return whether queueing is enabled.
  149.  
  150.     \return
  151.         true if queueing is enabled, false if queueing is disabled.
  152.     */
  153.     virtual bool    isQueueingEnabled(void) const    {return d_queueing;}
  154.  
  155.  
  156.     /*!
  157.     \brief
  158.     Return the current width of the display in pixels
  159.  
  160.     \return
  161.     float value equal to the current width of the display in pixels.
  162.     */
  163.     virtual float    getWidth(void) const        {return d_display_area.getWidth();}
  164.  
  165.  
  166.     /*!
  167.     \brief
  168.     Return the current height of the display in pixels
  169.  
  170.     \return
  171.     float value equal to the current height of the display in pixels.
  172.     */
  173.     virtual float    getHeight(void) const        {return d_display_area.getHeight();}
  174.  
  175.  
  176.     /*!
  177.     \brief
  178.     Return the size of the display in pixels
  179.  
  180.     \return
  181.     Size object describing the dimensions of the current display.
  182.     */
  183.     virtual Size    getSize(void) const            {return d_display_area.getSize();}
  184.  
  185.  
  186.     /*!
  187.     \brief
  188.     Return a Rect describing the screen
  189.  
  190.     \return
  191.     A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
  192.     equal to the screen resolution.
  193.     */
  194.     virtual Rect    getRect(void) const            {return d_display_area;}
  195.  
  196.  
  197.     /*!
  198.     \brief
  199.         Return the maximum texture size available
  200.  
  201.     \return
  202.         Size of the maximum supported texture in pixels (textures are always assumed to be square)
  203.     */
  204.     virtual    uint    getMaxTextureSize(void) const        {return d_maxTextureSize;}
  205.  
  206.  
  207.     /*!
  208.     \brief
  209.         Return the horizontal display resolution dpi
  210.  
  211.     \return
  212.         horizontal resolution of the display in dpi.
  213.     */
  214.     virtual    uint    getHorzScreenDPI(void) const    {return 96;}
  215.  
  216.  
  217.     /*!
  218.     \brief
  219.         Return the vertical display resolution dpi
  220.  
  221.     \return
  222.         vertical resolution of the display in dpi.
  223.     */
  224.     virtual    uint    getVertScreenDPI(void) const    {return 96;}
  225.  
  226.  
  227.     /*!
  228.     \brief
  229.         Direct3D support method that must be called prior to a Reset call on the
  230.         Direct3DDevice; this is required so that the GUI renderer can release any
  231.         unmanaged D3D resources as needed for the device reset to succeed.
  232.     */
  233.     virtual    void    preD3DReset(void);
  234.  
  235.  
  236.     /*!
  237.     \brief
  238.         Direct3D support method that must be called after a Reset call on the
  239.         Direct3DDevice; this is required so that the GUI renderer can rebuild any
  240.         unmanaged D3D resources after the device has been reset.
  241.     */
  242.     virtual    void    postD3DReset(void);
  243.  
  244.  
  245.     /*!
  246.     \brief
  247.         Set the size of the display in pixels.
  248.  
  249.         This method is important if your D3D 8 device is a pure device; since
  250.         with a pure device the system is unable to determine the size of the
  251.         view port, so you must manually tell it the size by using this method.
  252.  
  253.     \note
  254.         This method will cause the EventDisplaySizeChanged event to fire if the
  255.         display size has changed.
  256.  
  257.     \param sz
  258.         Size object describing the size of the display.
  259.  
  260.     \return
  261.         Nothing.
  262.     */
  263.     void    setDisplaySize(const Size& sz);
  264.  
  265.  
  266. private:
  267.     /************************************************************************
  268.         Implementation Constants
  269.     ************************************************************************/
  270.     static const int            VERTEX_PER_QUAD;                            //!< number of vertices per quad
  271.     static const int            VERTEX_PER_TRIANGLE;                        //!< number of vertices for a triangle
  272.     static const int            VERTEXBUFFER_CAPACITY;                        //!< capacity of the allocated vertex buffer
  273.     static const ulong            VERTEX_FVF;                                    //!< FVF specifier constant
  274.  
  275.     /*************************************************************************
  276.         Implementation Structs & classes
  277.     *************************************************************************/
  278.     /*!
  279.     \brief
  280.         FVF structure used for all vertices.
  281.     */
  282.     struct QuadVertex {
  283.         FLOAT x, y, z, rhw;        //!< The transformed position for the vertex.
  284.         DWORD diffuse;            //!< colour of the vertex
  285.         float tu1, tv1;            //!< texture coordinates
  286.     };
  287.  
  288.     /*!
  289.     \brief
  290.         structure holding details about a quad to be drawn
  291.     */
  292.     struct QuadInfo
  293.     {
  294.         LPDIRECT3DTEXTURE8    texture;
  295.         Rect                position;
  296.         float                z;
  297.         Rect                texPosition;
  298.         ulong                topLeftCol;
  299.         ulong                topRightCol;
  300.         ulong                bottomLeftCol;
  301.         ulong                bottomRightCol;
  302.  
  303.         QuadSplitMode       splitMode;
  304.  
  305.         bool operator<(const QuadInfo& other) const
  306.         {
  307.             // this is intentionally reversed.
  308.             return z > other.z;
  309.         }
  310.     };
  311.  
  312.  
  313.     /*************************************************************************
  314.         Implementation Methods
  315.     *************************************************************************/
  316.     // setup states etc
  317.     void    initPerFrameStates(void);
  318.  
  319.     // renders whatever is in the vertex buffer
  320.     void    renderVBuffer(void);
  321.  
  322.     // sort quads list according to texture
  323.     void    sortQuads(void);
  324.  
  325.     // render a quad directly to the display
  326.     void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
  327.  
  328.     // return size of device view port (if possible)
  329.     Size    getViewportSize(void);
  330.  
  331.     // method to do work of constructor
  332.     void    constructor_impl(LPDIRECT3DDEVICE8 device, const Size& display_size);
  333.  
  334.  
  335.     /*************************************************************************
  336.         Implementation Data
  337.     *************************************************************************/
  338.     Rect                d_display_area;
  339.  
  340.     typedef std::multiset<QuadInfo>        QuadList;
  341.     QuadList d_quadlist;
  342.     bool    d_queueing;        //!< setting for queueing control.
  343.  
  344.     LPDIRECT3DDEVICE8        d_device;            //!< Base Direct3DDevice8 interface that we use for rendering
  345.     LPDIRECT3DTEXTURE8        d_currTexture;        //!< currently set texture;
  346.     LPDIRECT3DVERTEXBUFFER8    d_buffer;            //!< vertex buffer to queue sprite rendering
  347.     int                        d_bufferPos;        //!< index into buffer where next vertex should be put.
  348.  
  349.     std::list<DirectX81Texture*>    d_texturelist;        //!< List used to track textures.
  350.  
  351.     uint    d_maxTextureSize;        //!< Holds maximum supported texture size (in pixels).
  352.     bool    d_canGetVPSize;            //!< true if we should try to extract the view port size ourselves.
  353. };
  354.  
  355. } // End of  CEGUI namespace section
  356.  
  357.  
  358. #if defined(_MSC_VER)
  359. #    pragma warning(pop)
  360. #endif
  361.  
  362. #endif    // end of guard _DirectX81GUIRenderer_h_
  363.