Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/ogreceguirenderer/OgreCEGUIRenderer.h @ 2750

Last change on this file since 2750 was 2710, checked in by rgrieder, 16 years ago

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

  • Property svn:eol-style set to native
File size: 14.6 KB
RevLine 
[1638]1/************************************************************************
[2602]2        filename:       OgreCEGUIRenderer.h
3        created:        11/5/2004
4        author:         Paul D Turner
[1638]5
[2602]6        purpose:        Interface for main Ogre GUI renderer class
[1638]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/*************************************************************************
[2602]27        This file contains code that is specific to Ogre (http://www.ogre3d.org)
[1638]28*************************************************************************/
[2569]29#ifndef _OgreCEGUIRenderer_h_
30#define _OgreCEGUIRenderer_h_
[1638]31
32#include <CEGUIBase.h>
33#include <CEGUIRenderer.h>
34#include <CEGUITexture.h>
35
36#include <OgreRenderQueueListener.h>
37#include <OgreSceneManagerEnumerator.h>
38#include <OgreTextureUnitState.h>
39
[2569]40#if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_STATIC_LIB)
41#   ifdef OGRE_GUIRENDERER_EXPORTS
[1638]42#       define OGRE_GUIRENDERER_API __declspec(dllexport)
43#   else
44#       if defined(__MINGW32__)
45#           define OGRE_GUIRENDERER_API
46#       else
47#           define OGRE_GUIRENDERER_API __declspec(dllimport)
48#       endif
49#   endif
50#elif defined ( OGRE_GCC_VISIBILITY )
51#    define OGRE_GUIRENDERER_API  __attribute__ ((visibility("default")))
52#else
53#    define OGRE_GUIRENDERER_API
54#endif
55
56
57// Start of CEGUI namespace section
58namespace CEGUI
59{
60/*************************************************************************
[2602]61        Forward refs
[1638]62*************************************************************************/
63class OgreCEGUITexture;
64class OgreCEGUIRenderer;
65
66
67/*!
68\brief
[2602]69        RenderQueueListener based class used to hook into the ogre rendering system
[1638]70*/
71class _OgrePrivate CEGUIRQListener : public Ogre::RenderQueueListener
72{
73public:
[2602]74        CEGUIRQListener(OgreCEGUIRenderer* renderer, Ogre::uint8 queue_id, bool post_queue)
75        {
76                d_renderer              = renderer;
77                d_queue_id              = queue_id;
78                d_post_queue    = post_queue;
79        }
[1638]80
[2602]81        virtual ~CEGUIRQListener() {}
[1638]82
[2602]83        virtual void    renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, bool& skipThisQueue);
84        virtual void    renderQueueEnded(Ogre::uint8 id, const Ogre::String& invocation, bool& repeatThisQueue);
[1638]85
[2602]86        // methods for adjusting target queue settings
87        void    setTargetRenderQueue(Ogre::uint8 queue_id)              {d_queue_id = queue_id;}
88        void    setPostRenderQueue(bool post_queue)             {d_post_queue = post_queue;}
[1638]89
90private:
[2602]91        /*************************************************************************
92                Implementation Data
93        *************************************************************************/
94        OgreCEGUIRenderer*                              d_renderer;             //!< CEGUI renderer object for Ogre.
95        Ogre::uint8     d_queue_id;             //!< ID of the queue that we are hooked into
96        bool                                            d_post_queue;   //!< true if we render after everything else in our queue.
[1638]97};
98
99
100/*!
101\brief
[2602]102        Renderer class to interface with Ogre engine.
[1638]103*/
104class OGRE_GUIRENDERER_API OgreCEGUIRenderer : public Renderer
105{
106public:
[2602]107        /*!
108        \brief
109                Constructor for renderer class that uses Ogre for rendering. Note that if
110                you use this option you must call setTargetSceneManager before rendering.
[1638]111
[2602]112        \param window
113                Pointer to an Ogre::RenderWindow object.
[1638]114
[2602]115        \param queue_id
116                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
[1638]117
[2602]118        \param post_queue
119                set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
120                \a queue_id.
[1638]121
[2602]122        \param max_quads
123                Obsolete.  Set to 0.
[1638]124
[2602]125        */
126        OgreCEGUIRenderer(Ogre::RenderWindow* window,
127                Ogre::uint8 queue_id = Ogre::RENDER_QUEUE_OVERLAY,
128                bool post_queue = false, uint max_quads = 0);
[1638]129
130
[2602]131        /*!
132        \brief
133                Constructor for renderer class that uses Ogre for rendering.
[1638]134
[2602]135        \param window
136                Pointer to an Ogre::RenderWindow object.
[1638]137
[2602]138        \param queue_id
139                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
[1638]140
[2602]141        \param post_queue
142                set to true to have GUI rendered after render queue \a queue_id, or false to have the GUI rendered before render queue
143                \a queue_id.
[1638]144
[2602]145        \param max_quads
146                Obsolete.  Set to 0.
[1638]147
[2602]148        \param scene_manager
149                Pointer to an Ogre::SceneManager object that is to be used for GUI rendering.
150        */
151        OgreCEGUIRenderer(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads, Ogre::SceneManager* scene_manager);
[1638]152
153
[2602]154        /*!
155        \brief
156                Destructor for Ogre renderer.
157        */
158        virtual ~OgreCEGUIRenderer(void);
[1638]159
160
161
[2602]162        // add's a quad to the list to be rendered
163        virtual void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
[1638]164
[2602]165        // perform final rendering for all queued renderable quads.
166        virtual void    doRender(void);
[1638]167
[2602]168        // clear the queue
169        virtual void    clearRenderList(void);
[1638]170
171
[2602]172        /*!
173        \brief
174                Enable or disable the queueing of quads from this point on.
[1638]175
[2602]176                This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
177                disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
178                be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
179                to be added as if queueing had never been disabled.
[1638]180
[2602]181        \param setting
182                true to enable queueing, or false to disable queueing (see notes above).
[1638]183
[2602]184        \return
185                Nothing
186        */
187        virtual void    setQueueingEnabled(bool setting)                {d_queueing = setting;}
[1638]188
189
[2602]190        // create an empty texture
191        virtual Texture*        createTexture(void);
[1638]192
[2602]193        // create a texture and load it with the specified file.
194        virtual Texture*        createTexture(const String& filename, const String& resourceGroup = "General");
[1638]195
[2602]196        // create a texture and set it to the specified size
197        virtual Texture*        createTexture(float size);
[1638]198
199    // create an OGRE resource provider.
200    virtual ResourceProvider* createResourceProvider(void);
201
[2602]202        // destroy the given texture
203        virtual void            destroyTexture(Texture* texture);
[1638]204
[2602]205        // destroy all textures still active
206        virtual void            destroyAllTextures(void);
[1638]207
208
[2602]209        /*!
210        \brief
211                Return whether queueing is enabled.
[1638]212
[2602]213        \return
214                true if queueing is enabled, false if queueing is disabled.
215        */
216        virtual bool    isQueueingEnabled(void) const   {return d_queueing;}
[1638]217
218
[2602]219        /*!
220        \brief
221        Return the current width of the display in pixels
[1638]222
[2602]223        \return
224        float value equal to the current width of the display in pixels.
225        */
226        virtual float   getWidth(void) const            {return d_display_area.getWidth();}
[1638]227
228
[2602]229        /*!
230        \brief
231        Return the current height of the display in pixels
[1638]232
[2602]233        \return
234        float value equal to the current height of the display in pixels.
235        */
236        virtual float   getHeight(void) const           {return d_display_area.getHeight();}
[1638]237
238
[2602]239        /*!
240        \brief
241        Return the size of the display in pixels
[1638]242
[2602]243        \return
244        Size object describing the dimensions of the current display.
245        */
246        virtual Size    getSize(void) const                     {return d_display_area.getSize();}
[1638]247
248
[2602]249        /*!
250        \brief
251        Return a Rect describing the screen
[1638]252
[2602]253        \return
254        A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
255        equal to the screen resolution.
256        */
257        virtual Rect    getRect(void) const                     {return d_display_area;}
[1638]258
259
[2602]260        /*!
261        \brief
262                Return the maximum texture size available
[1638]263
[2602]264        \return
265                Size of the maximum supported texture in pixels (textures are always assumed to be square)
266        */
267        virtual uint    getMaxTextureSize(void) const           {return 2048;}          // TODO: Change to proper value
[1638]268
269
[2602]270        /*!
271        \brief
272                Return the horizontal display resolution dpi
[1638]273
[2602]274        \return
275                horizontal resolution of the display in dpi.
276        */
277        virtual uint    getHorzScreenDPI(void) const    {return 96;}
[1638]278
279
[2602]280        /*!
281        \brief
282                Return the vertical display resolution dpi
[1638]283
[2602]284        \return
285                vertical resolution of the display in dpi.
286        */
287        virtual uint    getVertScreenDPI(void) const    {return 96;}
[1638]288
289
[2602]290        /*!
291        \brief
292                Set the scene manager to be used for rendering the GUI.
[1638]293
[2602]294                The GUI system will be unhooked from the current scene manager and attached to what ever
295                is specified here.
[1638]296
[2602]297        \param scene_manager
298                Pointer to an Ogre::SceneManager object that is the new target Ogre::SceneManager to be
299                used for GUI rendering.
[1638]300
[2602]301        \return
302                Nothing.
303        */
304        void    setTargetSceneManager(Ogre::SceneManager* scene_manager);
[1638]305
306
[2602]307        /*!
308        \brief
309                Set the target render queue for GUI rendering.
[1638]310
[2602]311        \param queue_id
312                Ogre::uint8 value specifying the render queue that the GUI system should attach to.
[1638]313
[2602]314        \param post_queue
315                - true to specify that the GUI should render after everything else in render queue \a queue_id.
316                - false to specify the GUI should render before everything else in render queue \a queue_id.
[1638]317
[2602]318        \return
319                Nothing.
320        */
321        void    setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue);
[1638]322
323
[2602]324        /*!
325        \brief
326                Create a texture from an existing Ogre::TexturePtr object.
[1638]327
[2602]328        \note
329                If you want to use an Ogre::RenderTexture (for putting rendered output onto Gui elements or other
330                advanced techniques), you can get the Ogre::TexturePtr to be used by calling Ogre::TextureManager::getByName()
331                passing the name returned from Ogre::RenderTexture::getName() (and casting the result as necessary).
[1638]332
[2602]333        \param texture
334                pointer to an Ogre::TexturePtr object to be used as the basis for the new CEGUI::Texture
[1638]335
[2602]336        \return
337                Pointer to the newly created CEGUI::TexturePtr object.
338        */
339        Texture*        createTexture(Ogre::TexturePtr& texture);
[1638]340
341
[2602]342        /*!
343        \brief
344        Set the size of the display in pixels.
[1638]345
[2602]346        You do not have to call this method under normal operation as the system
347        will automatically extract the size from the current view port.
[1638]348
[2602]349        \note
350        This method will cause the EventDisplaySizeChanged event to fire if the
351        display size has changed.
[1638]352
[2602]353        \param sz
354        Size object describing the size of the display.
[1638]355
[2602]356        \return
357        Nothing.
358        */
359        void    setDisplaySize(const Size& sz);
[1638]360
361
362private:
[2602]363        /************************************************************************
364                Implementation Constants
365        ************************************************************************/
366        static const size_t    VERTEX_PER_QUAD;                                          //!< number of vertices per quad
367        static const size_t    VERTEX_PER_TRIANGLE;                                      //!< number of vertices for a triangle
[1638]368    static const size_t    VERTEXBUFFER_INITIAL_CAPACITY;                //!< initial capacity of the allocated vertex buffer
369    static const size_t    UNDERUSED_FRAME_THRESHOLD;            //!< number of frames to wait before shrinking buffer
370
[2602]371        /*************************************************************************
372            Implementation Structs & classes
373        *************************************************************************/
374        /*!
375        \brief
376                structure used for all vertices.
377        */
378        struct QuadVertex {
379                float x, y, z;                  //!< The position for the vertex.
380                Ogre::RGBA diffuse;             //!< colour of the vertex
381                float tu1, tv1;                 //!< texture coordinates
382        };
[1638]383
[2602]384        /*!
385        \brief
386                structure holding details about a quad to be drawn
387        */
388        struct QuadInfo
389        {
390                Ogre::TexturePtr                texture;
391                Rect                            position;
392                float                           z;
393                Rect                            texPosition;
[1638]394        uint32                  topLeftCol;
395        uint32                  topRightCol;
396        uint32                  bottomLeftCol;
397        uint32                  bottomRightCol;
398
399        QuadSplitMode           splitMode;
400
[2602]401                bool operator<(const QuadInfo& other) const
402                {
403                        // this is intentionally reversed.
404                        return z > other.z;
405                }
406        };
[1638]407
408
[2602]409        /*************************************************************************
410            Implementation Methods
411        *************************************************************************/
412        // setup states etc
413        void    initRenderStates(void);
[1638]414
[2602]415        // sort quads list according to texture
416        void    sortQuads(void);
[1638]417
[2602]418        // render a quad directly to the display
419        void    renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
[1638]420
[2602]421        // convert colour value to whatever the Ogre render system is expecting.
[1638]422    uint32    colourToOgre(const colour& col) const;
423
[2602]424        // perform main work of the constructor.  This does everything except the final hook into the render system.
425        void    constructor_impl(Ogre::RenderWindow* window, Ogre::uint8 queue_id, bool post_queue, uint max_quads);
[1638]426
427
[2602]428        /*************************************************************************
429            Implementation Data
430        *************************************************************************/
431        Rect                            d_display_area;
[1638]432
[2602]433        typedef std::multiset<QuadInfo>         QuadList;
434        QuadList d_quadlist;
435        bool     d_queueing;            //!< setting for queueing control.
[1638]436
[2602]437        // Ogre specific bits.
438        Ogre::Root*                                     d_ogre_root;            //!< pointer to the Ogre root object that we attach to
439        Ogre::RenderSystem*                     d_render_sys;           //!< Pointer to the render system for Ogre.
440        Ogre::uint8     d_queue_id;                     //!< ID of the queue that we are hooked into
441        Ogre::TexturePtr                        d_currTexture;          //!< currently set texture;
442        Ogre::RenderOperation           d_render_op;            //!< Ogre render operation we use to do our stuff.
443        Ogre::HardwareVertexBufferSharedPtr     d_buffer;       //!< vertex buffer to queue sprite rendering
[1638]444    size_t d_underused_framecount;                  //!< Number of frames elapsed since buffer utilization was above half the capacity
445    Ogre::RenderOperation               d_direct_render_op;             //!< Renderop for cursor
[2602]446        Ogre::HardwareVertexBufferSharedPtr     d_direct_buffer;        //!< Renderop for cursor
447        Ogre::SceneManager*                     d_sceneMngr;            //!< The scene manager we are hooked into.
448        Ogre::LayerBlendModeEx          d_colourBlendMode;      //!< Controls colour blending mode used.
449        Ogre::LayerBlendModeEx          d_alphaBlendMode;       //!< Controls alpha blending mode used.
450        Ogre::TextureUnitState::UVWAddressingMode d_uvwAddressMode;
[1638]451
[2602]452        CEGUIRQListener*                        d_ourlistener;
453        bool                                            d_post_queue;           //!< true if we render after everything else in our queue.
454        size_t                                          d_bufferPos;            //!< index into buffer where next vertex should be put.
455        bool                                            d_sorted;                       //!< true when data in quad list is sorted.
456        Point                                           d_texelOffset;          //!< Offset required for proper texel mapping.
[1638]457
[2602]458        std::list<OgreCEGUITexture*> d_texturelist;             //!< List used to track textures.
[1638]459};
460
461} // End of  CEGUI namespace section
462
463
[2569]464#endif  // end of guard _OgreCEGUIRenderer_h_
Note: See TracBrowser for help on using the repository browser.