source: OGRE/trunk/ogrenew/OgreMain/src/OgreRenderQueue.cpp @ 692

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

adding ogre 1.2 and dependencies

RevLine 
[692]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreRenderQueue.h"
28
29#include "OgreRenderable.h"
30#include "OgreMaterial.h"
31#include "OgreRenderQueueSortingGrouping.h"
32#include "OgrePass.h"
33#include "OgreMaterialManager.h"
34
35
36namespace Ogre {
37
38    //---------------------------------------------------------------------
39    RenderQueue::RenderQueue()
40        : mSplitPassesByLightingType(false)
41                , mSplitNoShadowPasses(false)
42        , mShadowCastersCannotBeReceivers(false)
43                , mRenderableListener(0)
44    {
45        // Create the 'main' queue up-front since we'll always need that
46        mGroups.insert(
47            RenderQueueGroupMap::value_type(
48                RENDER_QUEUE_MAIN,
49                new RenderQueueGroup(this,
50                    mSplitPassesByLightingType,
51                    mSplitNoShadowPasses,
52                    mShadowCastersCannotBeReceivers)
53                )
54            );
55
56        // set default queue
57        mDefaultQueueGroup = RENDER_QUEUE_MAIN;
58                mDefaultRenderablePriority = OGRE_RENDERABLE_DEFAULT_PRIORITY;
59
60    }
61    //---------------------------------------------------------------------
62    RenderQueue::~RenderQueue()
63    {
64       
65        // trigger the pending pass updates, otherwise we could leak
66        Pass::processPendingPassUpdates();
67       
68        // Destroy the queues for good
69        RenderQueueGroupMap::iterator i, iend;
70        i = mGroups.begin();
71        iend = mGroups.end();
72        for (; i != iend; ++i)
73        {
74            delete i->second;
75        }
76        mGroups.clear();
77
78
79
80
81    }
82    //-----------------------------------------------------------------------
83    void RenderQueue::addRenderable(Renderable* pRend, uint8 groupID, ushort priority)
84    {
85        // Find group
86        RenderQueueGroup* pGroup = getQueueGroup(groupID);
87
88
89                Technique* pTech;
90
91                // tell material it's been used
92                if (!pRend->getMaterial().isNull())
93                        pRend->getMaterial()->touch();
94
95                // Check material & technique supplied (the former since the default implementation
96        // of getTechnique is based on it for backwards compatibility
97        if(pRend->getMaterial().isNull() || !pRend->getTechnique())
98        {
99            // Use default base white
100                        MaterialPtr baseWhite = MaterialManager::getSingleton().getByName("BaseWhite");
101            pTech = baseWhite->getTechnique(0);
102        }
103        else
104        {
105            // Get technique
106            pTech = pRend->getTechnique();
107        }
108
109                if (mRenderableListener)
110                {
111                        // Allow listener to override technique and to abort
112                        if (!mRenderableListener->renderableQueued(pRend, groupID, priority, &pTech))
113                                return; // rejected
114
115                        // tell material it's been used (incase changed)
116                        pTech->getParent()->touch();
117                }
118               
119        pGroup->addRenderable(pRend, pTech, priority);
120
121    }
122    //-----------------------------------------------------------------------
123    void RenderQueue::clear(bool destroyPassMaps)
124    {
125        // Clear the queues
126        RenderQueueGroupMap::iterator i, iend;
127        i = mGroups.begin();
128        iend = mGroups.end();
129        for (; i != iend; ++i)
130        {
131            i->second->clear(destroyPassMaps);
132        }
133
134        // Now trigger the pending pass updates
135        Pass::processPendingPassUpdates();
136
137        // NB this leaves the items present (but empty)
138        // We're assuming that frame-by-frame, the same groups are likely to
139        //  be used, so no point destroying the vectors and incurring the overhead
140        //  that would cause, let them be destroyed in the destructor.
141    }
142    //-----------------------------------------------------------------------
143    RenderQueue::QueueGroupIterator RenderQueue::_getQueueGroupIterator(void)
144    {
145        return QueueGroupIterator(mGroups.begin(), mGroups.end());
146    }
147    //-----------------------------------------------------------------------
148    void RenderQueue::addRenderable(Renderable* pRend, uint8 groupID)
149    {
150        addRenderable(pRend, groupID, mDefaultRenderablePriority);
151    }
152        //-----------------------------------------------------------------------
153    void RenderQueue::addRenderable(Renderable* pRend)
154    {
155        addRenderable(pRend, mDefaultQueueGroup, mDefaultRenderablePriority);
156    }
157    //-----------------------------------------------------------------------
158    uint8 RenderQueue::getDefaultQueueGroup(void) const
159    {
160        return mDefaultQueueGroup;
161    }
162    //-----------------------------------------------------------------------
163    void RenderQueue::setDefaultQueueGroup(uint8 grp)
164    {
165        mDefaultQueueGroup = grp;
166    }
167    //-----------------------------------------------------------------------
168    ushort RenderQueue::getDefaultRenderablePriority(void) const
169    {
170        return mDefaultRenderablePriority;
171    }
172    //-----------------------------------------------------------------------
173    void RenderQueue::setDefaultRenderablePriority(ushort priority)
174    {
175        mDefaultRenderablePriority = priority;
176    }
177       
178       
179        //-----------------------------------------------------------------------
180        RenderQueueGroup* RenderQueue::getQueueGroup(uint8 groupID)
181        {
182                // Find group
183                RenderQueueGroupMap::iterator groupIt;
184                RenderQueueGroup* pGroup;
185
186                groupIt = mGroups.find(groupID);
187                if (groupIt == mGroups.end())
188                {
189                        // Insert new
190                        pGroup = new RenderQueueGroup(this,
191                mSplitPassesByLightingType,
192                mSplitNoShadowPasses,
193                mShadowCastersCannotBeReceivers);
194                        mGroups.insert(RenderQueueGroupMap::value_type(groupID, pGroup));
195                }
196                else
197                {
198                        pGroup = groupIt->second;
199                }
200
201                return pGroup;
202
203        }
204    //-----------------------------------------------------------------------
205    void RenderQueue::setSplitPassesByLightingType(bool split)
206    {
207        mSplitPassesByLightingType = split;
208
209        RenderQueueGroupMap::iterator i, iend;
210        i = mGroups.begin();
211        iend = mGroups.end();
212        for (; i != iend; ++i)
213        {
214            i->second->setSplitPassesByLightingType(split);
215        }
216    }
217    //-----------------------------------------------------------------------
218    void RenderQueue::setSplitNoShadowPasses(bool split)
219    {
220        mSplitNoShadowPasses = split;
221
222        RenderQueueGroupMap::iterator i, iend;
223        i = mGroups.begin();
224        iend = mGroups.end();
225        for (; i != iend; ++i)
226        {
227            i->second->setSplitNoShadowPasses(split);
228        }
229    }
230        //-----------------------------------------------------------------------
231        void RenderQueue::setShadowCastersCannotBeReceivers(bool ind)
232        {
233                mShadowCastersCannotBeReceivers = ind;
234
235                RenderQueueGroupMap::iterator i, iend;
236                i = mGroups.begin();
237                iend = mGroups.end();
238                for (; i != iend; ++i)
239                {
240                        i->second->setShadowCastersCannotBeReceivers(ind);
241                }
242        }
243
244}
245
Note: See TracBrowser for help on using the repository browser.