Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spacestationentry/src/external/ogreceguirenderer/OgreCEGUIRenderer.h @ 9983

Last change on this file since 9983 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 14.6 KB
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#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
40#if (OGRE_PLATFORM == OGRE_PLATFORM_WIN32) && !defined(OGRE_GUIRENDERER_STATIC_LIB)
41#   ifdef OGRE_GUIRENDERER_EXPORTS
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/*************************************************************************
61        Forward refs
62*************************************************************************/
63class OgreCEGUITexture;
64class OgreCEGUIRenderer;
65
66
67/*!
68\brief
69        RenderQueueListener based class used to hook into the ogre rendering system
70*/
71class _OgrePrivate CEGUIRQListener : public Ogre::RenderQueueListener
72{
73public:
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        }
80
81        virtual ~CEGUIRQListener() {}
82
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);
85
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;}
89
90private:
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.
97};
98
99
100/*!
101\brief
102        Renderer class to interface with Ogre engine.
103*/
104class OGRE_GUIRENDERER_API OgreCEGUIRenderer : public Renderer
105{
106public:
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.
111
112        \param window
113                Pointer to an Ogre::RenderWindow object.
114
115        \param queue_id
116                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
117
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.
121
122        \param max_quads
123                Obsolete.  Set to 0.
124
125        */
126        OgreCEGUIRenderer(Ogre::RenderWindow* window,
127                Ogre::uint8 queue_id = Ogre::RENDER_QUEUE_OVERLAY,
128                bool post_queue = false, uint max_quads = 0);
129
130
131        /*!
132        \brief
133                Constructor for renderer class that uses Ogre for rendering.
134
135        \param window
136                Pointer to an Ogre::RenderWindow object.
137
138        \param queue_id
139                Ogre::uint8 value that specifies where the GUI should appear in the ogre rendering output.
140
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.
144
145        \param max_quads
146                Obsolete.  Set to 0.
147
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);
152
153
154        /*!
155        \brief
156                Destructor for Ogre renderer.
157        */
158        virtual ~OgreCEGUIRenderer(void);
159
160
161
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);
164
165        // perform final rendering for all queued renderable quads.
166        virtual void    doRender(void);
167
168        // clear the queue
169        virtual void    clearRenderList(void);
170
171
172        /*!
173        \brief
174                Enable or disable the queueing of quads from this point on.
175
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.
180
181        \param setting
182                true to enable queueing, or false to disable queueing (see notes above).
183
184        \return
185                Nothing
186        */
187        virtual void    setQueueingEnabled(bool setting)                {d_queueing = setting;}
188
189
190        // create an empty texture
191        virtual Texture*        createTexture(void);
192
193        // create a texture and load it with the specified file.
194        virtual Texture*        createTexture(const String& filename, const String& resourceGroup = "General");
195
196        // create a texture and set it to the specified size
197        virtual Texture*        createTexture(float size);
198
199    // create an OGRE resource provider.
200    virtual ResourceProvider* createResourceProvider(void);
201
202        // destroy the given texture
203        virtual void            destroyTexture(Texture* texture);
204
205        // destroy all textures still active
206        virtual void            destroyAllTextures(void);
207
208
209        /*!
210        \brief
211                Return whether queueing is enabled.
212
213        \return
214                true if queueing is enabled, false if queueing is disabled.
215        */
216        virtual bool    isQueueingEnabled(void) const   {return d_queueing;}
217
218
219        /*!
220        \brief
221        Return the current width of the display in pixels
222
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();}
227
228
229        /*!
230        \brief
231        Return the current height of the display in pixels
232
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();}
237
238
239        /*!
240        \brief
241        Return the size of the display in pixels
242
243        \return
244        Size object describing the dimensions of the current display.
245        */
246        virtual Size    getSize(void) const                     {return d_display_area.getSize();}
247
248
249        /*!
250        \brief
251        Return a Rect describing the screen
252
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;}
258
259
260        /*!
261        \brief
262                Return the maximum texture size available
263
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
268
269
270        /*!
271        \brief
272                Return the horizontal display resolution dpi
273
274        \return
275                horizontal resolution of the display in dpi.
276        */
277        virtual uint    getHorzScreenDPI(void) const    {return 96;}
278
279
280        /*!
281        \brief
282                Return the vertical display resolution dpi
283
284        \return
285                vertical resolution of the display in dpi.
286        */
287        virtual uint    getVertScreenDPI(void) const    {return 96;}
288
289
290        /*!
291        \brief
292                Set the scene manager to be used for rendering the GUI.
293
294                The GUI system will be unhooked from the current scene manager and attached to what ever
295                is specified here.
296
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.
300
301        \return
302                Nothing.
303        */
304        void    setTargetSceneManager(Ogre::SceneManager* scene_manager);
305
306
307        /*!
308        \brief
309                Set the target render queue for GUI rendering.
310
311        \param queue_id
312                Ogre::uint8 value specifying the render queue that the GUI system should attach to.
313
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.
317
318        \return
319                Nothing.
320        */
321        void    setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue);
322
323
324        /*!
325        \brief
326                Create a texture from an existing Ogre::TexturePtr object.
327
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).
332
333        \param texture
334                pointer to an Ogre::TexturePtr object to be used as the basis for the new CEGUI::Texture
335
336        \return
337                Pointer to the newly created CEGUI::TexturePtr object.
338        */
339        Texture*        createTexture(Ogre::TexturePtr& texture);
340
341
342        /*!
343        \brief
344        Set the size of the display in pixels.
345
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.
348
349        \note
350        This method will cause the EventDisplaySizeChanged event to fire if the
351        display size has changed.
352
353        \param sz
354        Size object describing the size of the display.
355
356        \return
357        Nothing.
358        */
359        void    setDisplaySize(const Size& sz);
360
361
362private:
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
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
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        };
383
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;
394        uint32                  topLeftCol;
395        uint32                  topRightCol;
396        uint32                  bottomLeftCol;
397        uint32                  bottomRightCol;
398
399        QuadSplitMode           splitMode;
400
401                bool operator<(const QuadInfo& other) const
402                {
403                        // this is intentionally reversed.
404                        return z > other.z;
405                }
406        };
407
408
409        /*************************************************************************
410            Implementation Methods
411        *************************************************************************/
412        // setup states etc
413        void    initRenderStates(void);
414
415        // sort quads list according to texture
416        void    sortQuads(void);
417
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);
420
421        // convert colour value to whatever the Ogre render system is expecting.
422    uint32    colourToOgre(const colour& col) const;
423
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);
426
427
428        /*************************************************************************
429            Implementation Data
430        *************************************************************************/
431        Rect                            d_display_area;
432
433        typedef std::multiset<QuadInfo>         QuadList;
434        QuadList d_quadlist;
435        bool     d_queueing;            //!< setting for queueing control.
436
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
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
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;
451
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.
457
458        std::list<OgreCEGUITexture*> d_texturelist;             //!< List used to track textures.
459};
460
461} // End of  CEGUI namespace section
462
463
464#endif  // end of guard _OgreCEGUIRenderer_h_
Note: See TracBrowser for help on using the repository browser.