source: OGRE/trunk/ogrenew/Samples/Common/CEGUIRenderer/include/OgreCEGUIRenderer.h @ 692

Revision 692, 14.8 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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