root/OpenSceneGraph/trunk/src/osgViewer/Renderer.cpp @ 9385

Revision 9385, 21.2 kB (checked in by robert, 5 years ago)

Fixed warnings

RevLine 
[7178]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <stdio.h>
15
16#include <osg/GLExtensions>
17
18#include <osgUtil/Optimizer>
19#include <osgUtil/GLObjectsVisitor>
20
21#include <osgViewer/Renderer>
22#include <osgViewer/View>
23
24#include <osgDB/DatabasePager>
[8647]25#include <osgDB/ImagePager>
[7178]26
27#include <osg/io_utils>
28
29#include <sstream>
30
31using namespace osgViewer;
32
33//#define DEBUG_MESSAGE osg::notify(osg::NOTICE)
[7858]34#define DEBUG_MESSAGE osg::notify(osg::DEBUG_FP)
[7178]35
36
37OpenGLQuerySupport::OpenGLQuerySupport():
38    _startTick(0),
39    _initialized(false),
40    _timerQuerySupported(false),
41    _extensions(0),
42    _previousQueryTime(0.0)
43{
44}
45
46void OpenGLQuerySupport::checkQuery(osg::Stats* stats)
47{
48    for(QueryFrameNumberList::iterator itr = _queryFrameNumberList.begin();
49        itr != _queryFrameNumberList.end();
50        )
51    {
52        GLuint query = itr->first;
53        GLint available = 0;
54        _extensions->glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &available);
55        if (available)
56        {
57            GLuint64EXT timeElapsed = 0;
58            _extensions->glGetQueryObjectui64v(query, GL_QUERY_RESULT, &timeElapsed);
59
60            double timeElapsedSeconds = double(timeElapsed)*1e-9;
61            double currentTime = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
62            double estimatedEndTime = (_previousQueryTime + currentTime) * 0.5;
63            double estimatedBeginTime = estimatedEndTime - timeElapsedSeconds;
64
65            stats->setAttribute(itr->second, "GPU draw begin time", estimatedBeginTime);
66            stats->setAttribute(itr->second, "GPU draw end time", estimatedEndTime);
67            stats->setAttribute(itr->second, "GPU draw time taken", timeElapsedSeconds);
68
69
70            itr = _queryFrameNumberList.erase(itr);
71            _availableQueryObjects.push_back(query);
72        }
73        else
74        {
75            ++itr;
76        }
77
78    }
79    _previousQueryTime = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
80}
81
82GLuint OpenGLQuerySupport::createQueryObject()
83{
84    if (_availableQueryObjects.empty())
85    {
86        GLuint query;
87        _extensions->glGenQueries(1, &query);
88        return query;
89    }
90    else
91    {
92        GLuint query = _availableQueryObjects.back();
93        _availableQueryObjects.pop_back();
94        return query;
95    }
96}
97
98void OpenGLQuerySupport::beginQuery(int frameNumber)
99{
100    GLuint query = createQueryObject();
101    _extensions->glBeginQuery(GL_TIME_ELAPSED, query);
102    _queryFrameNumberList.push_back(QueryFrameNumberPair(query, frameNumber));       
103}
104
105void OpenGLQuerySupport::endQuery()
106{
107    _extensions->glEndQuery(GL_TIME_ELAPSED);
108}
109
110void OpenGLQuerySupport::initialize(osg::State* state)
111{
112    if (_initialized) return;
113
114    _initialized = true;
115    _extensions = osg::Drawable::getExtensions(state->getContextID(),true);
116    _timerQuerySupported = _extensions && _extensions->isTimerQuerySupported();
117    _previousQueryTime = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
118}
119
120///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121//
122//
[9130]123//  ThreadSafeQueue
[7270]124
[9130]125Renderer::ThreadSafeQueue::ThreadSafeQueue()
[7285]126{
127    _block.set(false);
128}
129
[9130]130Renderer::ThreadSafeQueue::~ThreadSafeQueue()
[7295]131{
132}
133
[9130]134osgUtil::SceneView* Renderer::ThreadSafeQueue::takeFront()
[7270]135{
136    if (_queue.empty()) _block.block();
137
138    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
139    if (_queue.empty()) return 0;
140
141    osgUtil::SceneView* front = _queue.front();
142    _queue.pop_front();
143
144    if (_queue.empty()) _block.set(false);
145   
146    return front;
147}
148
[9130]149void Renderer::ThreadSafeQueue::add(osgUtil::SceneView* sv)
[7270]150{
151    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
152    _queue.push_back(sv);
153    _block.set(true);
154}
155
156static OpenThreads::Mutex s_drawSerializerMutex;
157
158///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
159//
160//
[7178]161//  Renderer
162Renderer::Renderer(osg::Camera* camera):
163    osg::GraphicsOperation("Renderer",true),
164    OpenGLQuerySupport(),
[8121]165    _targetFrameRate(100.0),
166    _minimumTimeAvailableForGLCompileAndDeletePerFrame(0.001),
167    _flushTimeRatio(0.5),
168    _conservativeTimeRatio(0.5),
[7178]169    _camera(camera),
170    _done(false),
[8299]171    _graphicsThreadDoesCull(true),
172    _compileOnNextDraw(true)
[7178]173{
174
175    DEBUG_MESSAGE<<"Render::Render() "<<this<<std::endl;
176
177    _sceneView[0] = new osgUtil::SceneView;
178    _sceneView[1] = new osgUtil::SceneView;
179
180
181    osg::Camera* masterCamera = _camera->getView() ? _camera->getView()->getCamera() : camera;
182    osg::StateSet* stateset = masterCamera->getOrCreateStateSet();
183    osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
184
185    osg::DisplaySettings* ds = _camera->getDisplaySettings() ?  _camera->getDisplaySettings() :
[7212]186                               ((view && view->getDisplaySettings()) ?  view->getDisplaySettings() :  osg::DisplaySettings::instance());
[7178]187
[9208]188    unsigned int sceneViewOptions = osgUtil::SceneView::HEADLIGHT;
189    if (view)
190    {
191        switch(view->getLightingMode())
192        {
193            case(osg::View::NO_LIGHT): sceneViewOptions = 0; break;
194            case(osg::View::SKY_LIGHT): sceneViewOptions = osgUtil::SceneView::SKY_LIGHT; break;
195            case(osg::View::HEADLIGHT): sceneViewOptions = osgUtil::SceneView::HEADLIGHT; break;
196        }
197    }
198
[7178]199    _sceneView[0]->setGlobalStateSet(stateset);
200    _sceneView[1]->setGlobalStateSet(stateset);
201   
202    _sceneView[0]->setDefaults(sceneViewOptions);
203    _sceneView[1]->setDefaults(sceneViewOptions);
204
205    _sceneView[0]->setDisplaySettings(ds);
206    _sceneView[1]->setDisplaySettings(ds);
207
[7205]208    _sceneView[0]->setCamera(_camera.get(), false);
209    _sceneView[1]->setCamera(_camera.get(), false);
[7178]210
211    // lock the mutex for the current cull SceneView to
212    // prevent the draw traversal from reading from it before the cull traversal has been completed.
[7270]213    _availableQueue.add(_sceneView[0].get());
214    _availableQueue.add(_sceneView[1].get());
215       
216    DEBUG_MESSAGE<<"_availableQueue.size()="<<_availableQueue._queue.size()<<std::endl;
[7178]217
218    _flushOperation = new osg::FlushDeletedGLObjectsOperation(0.1);
219}
220
221Renderer::~Renderer()
222{
223    DEBUG_MESSAGE<<"Render::~Render() "<<this<<std::endl;
224}
225
226void Renderer::setGraphicsThreadDoesCull(bool flag)
227{
228    if (_graphicsThreadDoesCull==flag) return;
229
230    _graphicsThreadDoesCull = flag;
231}
232
233void Renderer::updateSceneView(osgUtil::SceneView* sceneView)
234{
235    osg::Camera* masterCamera = _camera->getView() ? _camera->getView()->getCamera() : _camera.get();
236    osg::StateSet* stateset = masterCamera->getOrCreateStateSet();
237
238    if (sceneView->getGlobalStateSet()!=stateset)
239    {
240        sceneView->setGlobalStateSet(stateset);
241    }
242   
243    osg::GraphicsContext* context = _camera->getGraphicsContext();
244    osg::State* state = context ? context->getState() : 0;
245    if (sceneView->getState()!=state)
246    {
247        sceneView->setState(state);
248    }
249
250    osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
[8647]251
[7209]252    osgDB::DatabasePager* databasePager = view ? view->getDatabasePager() : 0;
[7178]253    sceneView->getCullVisitor()->setDatabaseRequestHandler(databasePager);
[8647]254
255    osgDB::ImagePager* imagePager = view ? view->getImagePager() : 0;
256    sceneView->getCullVisitor()->setImageRequestHandler(imagePager);
[7178]257   
[7209]258    sceneView->setFrameStamp(view ? view->getFrameStamp() : state->getFrameStamp());
[7178]259   
260    if (databasePager) databasePager->setCompileGLObjectsForContextID(state->getContextID(), true);
261   
262    osg::DisplaySettings* ds = _camera->getDisplaySettings() ?  _camera->getDisplaySettings() :
263                               ((view &&view->getDisplaySettings()) ?  view->getDisplaySettings() :  osg::DisplaySettings::instance());
264
265    sceneView->setDisplaySettings(ds);
266
[7209]267    if (view) _startTick = view->getStartTick();
[7178]268}
269
[8299]270void Renderer::compile()
271{
272    DEBUG_MESSAGE<<"Renderer::compile()"<<std::endl;
[7178]273
[8299]274    _compileOnNextDraw = false;
275   
276    osgUtil::SceneView* sceneView = _sceneView[0].get();
277    if (!sceneView || _done) return;
278
279    if (sceneView->getSceneData())
280    {
281        osgUtil::GLObjectsVisitor glov;
282        glov.setState(sceneView->getState());
283        sceneView->getSceneData()->accept(glov);
284    }
285}
286
[7178]287void Renderer::cull()
288{
289    DEBUG_MESSAGE<<"cull()"<<std::endl;
290
291    if (_done || _graphicsThreadDoesCull) return;
292
[7648]293    // note we assume lock has already been acquired.
[7270]294    osgUtil::SceneView* sceneView = _availableQueue.takeFront();
[7178]295
[7270]296    DEBUG_MESSAGE<<"cull() got SceneView "<<sceneView<<std::endl;
297
[7178]298    if (sceneView)
299    {
300        updateSceneView(sceneView);
301
302        // osg::notify(osg::NOTICE)<<"Culling buffer "<<_currentCull<<std::endl;
303
304        // pass on the fusion distance settings from the View to the SceneView
305        osgViewer::View* view = dynamic_cast<osgViewer::View*>(sceneView->getCamera()->getView());
306        if (view) sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue());
307
308        osg::Stats* stats = sceneView->getCamera()->getStats();
309        osg::State* state = sceneView->getState();
310        const osg::FrameStamp* fs = state->getFrameStamp();
311        int frameNumber = fs ? fs->getFrameNumber() : 0;
312
[7648]313        // do cull traversal
[7178]314        osg::Timer_t beforeCullTick = osg::Timer::instance()->tick();
315
316        sceneView->inheritCullSettings(*(sceneView->getCamera()));
317        sceneView->cull();
318
319        osg::Timer_t afterCullTick = osg::Timer::instance()->tick();
320
321#if 0
322        if (sceneView->getDynamicObjectCount()==0 && state->getDynamicObjectRenderingCompletedCallback())
323        {
324            // osg::notify(osg::NOTICE)<<"Completed in cull"<<std::endl;
325            state->getDynamicObjectRenderingCompletedCallback()->completed(state);
326        }
327#endif
328        if (stats && stats->collectStats("rendering"))
329        {
330            DEBUG_MESSAGE<<"Collecting rendering stats"<<std::endl;
331       
332            stats->setAttribute(frameNumber, "Cull traversal begin time", osg::Timer::instance()->delta_s(_startTick, beforeCullTick));
333            stats->setAttribute(frameNumber, "Cull traversal end time", osg::Timer::instance()->delta_s(_startTick, afterCullTick));
334            stats->setAttribute(frameNumber, "Cull traversal time taken", osg::Timer::instance()->delta_s(beforeCullTick, afterCullTick));
335        }
336
[7270]337        _drawQueue.add(sceneView);
[7178]338
[7270]339    }
[7178]340
341    DEBUG_MESSAGE<<"end cull() "<<this<<std::endl;
342}
343
344void Renderer::draw()
345{
346    DEBUG_MESSAGE<<"draw() "<<this<<std::endl;
347
[9385]348    // osg::Timer_t startDrawTick = osg::Timer::instance()->tick();
[7178]349
[7270]350    osgUtil::SceneView* sceneView = _drawQueue.takeFront();
351
352    DEBUG_MESSAGE<<"draw() got SceneView "<<sceneView<<std::endl;
353
[7278]354    osg::GraphicsContext* compileContext = sceneView ? osg::GraphicsContext::getCompileContext(sceneView->getState()->getContextID()) : 0;
[7178]355    osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
356
[8299]357    if (sceneView && !_done)
[7178]358    {
[8299]359        if (_compileOnNextDraw)
360        {
361            compile();
362        }
363   
[7178]364        osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
[7209]365        osgDB::DatabasePager* databasePager = view ? view->getDatabasePager() : 0;
[7178]366
367        // osg::notify(osg::NOTICE)<<"Drawing buffer "<<_currentDraw<<std::endl;
368
369        if (_done)
370        {
371            osg::notify(osg::INFO)<<"Renderer::release() causing draw to exit"<<std::endl;
372            return;
373        }
374
375        if (_graphicsThreadDoesCull)
376        {
377            osg::notify(osg::INFO)<<"Renderer::draw() completing early due to change in _graphicsThreadDoesCull flag."<<std::endl;
378            return;
379        }
380
381        // osg::notify(osg::NOTICE)<<"RenderingOperation"<<std::endl;
382
383        osg::Stats* stats = sceneView->getCamera()->getStats();
384        osg::State* state = sceneView->getState();
[7270]385        int frameNumber = state->getFrameStamp()->getFrameNumber();
[7178]386
387        if (!_initialized)
388        {
389            initialize(state);
390        }
391
392        state->setDynamicObjectCount(sceneView->getDynamicObjectCount());
393
394        if (sceneView->getDynamicObjectCount()==0 && state->getDynamicObjectRenderingCompletedCallback())
395        {
396            // osg::notify(osg::NOTICE)<<"Completed in cull"<<std::endl;
397            state->getDynamicObjectRenderingCompletedCallback()->completed(state);
398        }
399
[7648]400        bool acquireGPUStats = stats && _timerQuerySupported && stats->collectStats("gpu");
[7178]401
[7648]402        if (acquireGPUStats)
[7178]403        {
404            checkQuery(stats);
405        }
406
[7648]407        // do draw traversal
408        if (acquireGPUStats)
[7178]409        {
410            checkQuery(stats);
411            beginQuery(frameNumber);
412        }
413
[7270]414        osg::Timer_t beforeDrawTick;
[7274]415       
416       
417        bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch();
[7178]418
[7274]419        if (serializeDraw)
[7270]420        {
421            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_drawSerializerMutex);
422            beforeDrawTick = osg::Timer::instance()->tick();
423            sceneView->draw();
424        }
425        else
426        {
427            beforeDrawTick = osg::Timer::instance()->tick();
428            sceneView->draw();
429        }
430
431        _availableQueue.add(sceneView);
432
[8121]433        osg::Timer_t afterDispatchTick = osg::Timer::instance()->tick();
[7178]434
[8121]435        double dispatchTime = osg::Timer::instance()->delta_s(beforeDrawTick, afterDispatchTick);
[7178]436
[8121]437        // now flush delete OpenGL objects and compile any objects as required by the DatabasePager
438        flushAndCompile(dispatchTime, sceneView, databasePager, compileThread);
439   
[7648]440        if (acquireGPUStats)
[7178]441        {
442            endQuery();
443            checkQuery(stats);
444        }
445
[7270]446        //glFlush();
447       
448        osg::Timer_t afterDrawTick = osg::Timer::instance()->tick();
[7178]449
[7270]450//        osg::notify(osg::NOTICE)<<"Time wait for draw = "<<osg::Timer::instance()->delta_m(startDrawTick, beforeDrawTick)<<std::endl;
451//        osg::notify(osg::NOTICE)<<"     time for draw = "<<osg::Timer::instance()->delta_m(beforeDrawTick, afterDrawTick)<<std::endl;
[7178]452
453        if (stats && stats->collectStats("rendering"))
454        {
455            stats->setAttribute(frameNumber, "Draw traversal begin time", osg::Timer::instance()->delta_s(_startTick, beforeDrawTick));
456            stats->setAttribute(frameNumber, "Draw traversal end time", osg::Timer::instance()->delta_s(_startTick, afterDrawTick));
457            stats->setAttribute(frameNumber, "Draw traversal time taken", osg::Timer::instance()->delta_s(beforeDrawTick, afterDrawTick));
458        }
459    }
460
461    DEBUG_MESSAGE<<"end draw() "<<this<<std::endl;
462}
463
464void Renderer::cull_draw()
465{
466    DEBUG_MESSAGE<<"cull_draw() "<<this<<std::endl;
467
[7270]468    osgUtil::SceneView* sceneView = _sceneView[0].get();
[7178]469    if (!sceneView || _done) return;
470
[8324]471    if (_done)
472    {
473        osg::notify(osg::INFO)<<"Render::release() causing cull_draw to exit"<<std::endl;
474        return;
475    }
476   
477    updateSceneView(sceneView);
478
[8299]479    if (_compileOnNextDraw)
480    {
481        compile();
482    }
483
[7178]484    osgViewer::View* view = dynamic_cast<osgViewer::View*>(_camera->getView());
[7209]485    osgDB::DatabasePager* databasePager = view ? view->getDatabasePager() : 0;
[7178]486
487    osg::GraphicsContext* compileContext = osg::GraphicsContext::getCompileContext(sceneView->getState()->getContextID());
488    osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
489
490
491    // osg::notify(osg::NOTICE)<<"RenderingOperation"<<std::endl;
492
493    // pass on the fusion distance settings from the View to the SceneView
494    if (view) sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue());
495
496    osg::Stats* stats = sceneView->getCamera()->getStats();
497    osg::State* state = sceneView->getState();
498    const osg::FrameStamp* fs = state->getFrameStamp();
499    int frameNumber = fs ? fs->getFrameNumber() : 0;
500
501    if (!_initialized)
502    {
503        initialize(state);
504    }
505
[7648]506    bool acquireGPUStats = stats && _timerQuerySupported && stats->collectStats("gpu");
[7178]507
[7648]508    if (acquireGPUStats)
[7178]509    {
510        checkQuery(stats);
511    }
512
[7648]513    // do cull traversal
[7178]514    osg::Timer_t beforeCullTick = osg::Timer::instance()->tick();
515
516    sceneView->inheritCullSettings(*(sceneView->getCamera()));
517    sceneView->cull();
518
519    osg::Timer_t afterCullTick = osg::Timer::instance()->tick();
520
521#if 0
522    if (state->getDynamicObjectCount()==0 && state->getDynamicObjectRenderingCompletedCallback())
523    {
524        state->getDynamicObjectRenderingCompletedCallback()->completed(state);
525    }
526#endif
527
[7270]528
[7648]529    // do draw traversal
530    if (acquireGPUStats)
[7178]531    {
532        checkQuery(stats);
533        beginQuery(frameNumber);
534    }
535
[7270]536    osg::Timer_t beforeDrawTick;
[7178]537
[7274]538    bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch();
539
540    if (serializeDraw)
[7270]541    {
542        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_drawSerializerMutex);
543       
544        beforeDrawTick = osg::Timer::instance()->tick();
545        sceneView->draw();
546    }
547    else
548    {
549        beforeDrawTick = osg::Timer::instance()->tick();
550        sceneView->draw();
551    }
552
[8121]553    osg::Timer_t afterDispatchTick = osg::Timer::instance()->tick();
554    double cullAndDispatchTime = osg::Timer::instance()->delta_s(beforeCullTick, afterDispatchTick);
[7178]555
[8121]556    // now flush delete OpenGL objects and compile any objects as required by the DatabasePager
557    flushAndCompile(cullAndDispatchTime, sceneView, databasePager, compileThread);
[7178]558
[8121]559
[7648]560    if (acquireGPUStats)
[7178]561    {
562        endQuery();
563        checkQuery(stats);
564    }
565
566    osg::Timer_t afterDrawTick = osg::Timer::instance()->tick();
567
568    if (stats && stats->collectStats("rendering"))
569    {
570        DEBUG_MESSAGE<<"Collecting rendering stats"<<std::endl;
571
572        stats->setAttribute(frameNumber, "Cull traversal begin time", osg::Timer::instance()->delta_s(_startTick, beforeCullTick));
573        stats->setAttribute(frameNumber, "Cull traversal end time", osg::Timer::instance()->delta_s(_startTick, afterCullTick));
574        stats->setAttribute(frameNumber, "Cull traversal time taken", osg::Timer::instance()->delta_s(beforeCullTick, afterCullTick));
575
[7270]576        stats->setAttribute(frameNumber, "Draw traversal begin time", osg::Timer::instance()->delta_s(_startTick, beforeDrawTick));
[7178]577        stats->setAttribute(frameNumber, "Draw traversal end time", osg::Timer::instance()->delta_s(_startTick, afterDrawTick));
[7270]578        stats->setAttribute(frameNumber, "Draw traversal time taken", osg::Timer::instance()->delta_s(beforeDrawTick, afterDrawTick));
[7178]579    }
580
581    DEBUG_MESSAGE<<"end cull_draw() "<<this<<std::endl;
582
583}
584
[8121]585void Renderer::flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager, osg::GraphicsThread* compileThread)
586{
587   
588    double targetFrameRate = _targetFrameRate;
589    double minimumTimeAvailableForGLCompileAndDeletePerFrame = _minimumTimeAvailableForGLCompileAndDeletePerFrame;
590
591    if (databasePager)
592    {
593        targetFrameRate = std::min(targetFrameRate, databasePager->getTargetFrameRate());
594        minimumTimeAvailableForGLCompileAndDeletePerFrame = std::min(minimumTimeAvailableForGLCompileAndDeletePerFrame, databasePager->getMinimumTimeAvailableForGLCompileAndDeletePerFrame());
595    }
596   
597    double targetFrameTime = 1.0/targetFrameRate;
598
599    double availableTime = std::max((targetFrameTime - currentElapsedFrameTime)*_conservativeTimeRatio,
600                                    minimumTimeAvailableForGLCompileAndDeletePerFrame);
601
602    double flushTime = availableTime * _flushTimeRatio;
603    double compileTime = availableTime - flushTime;
604
605#if 0
606    osg::notify(osg::NOTICE)<<"total availableTime = "<<availableTime*1000.0<<std::endl;
607    osg::notify(osg::NOTICE)<<"      flushTime     = "<<flushTime*1000.0<<std::endl;
608    osg::notify(osg::NOTICE)<<"      compileTime   = "<<compileTime*1000.0<<std::endl;
609#endif
610
611    if (compileThread)
612    {
613        compileThread->add(_flushOperation.get());
614    }
615    else
616    {
617        sceneView->flushDeletedGLObjects(flushTime);
618    }
619
620    // if any time left over from flush add this to compile time.       
621    if (flushTime>0.0) compileTime += flushTime;
622
623#if 0
624    osg::notify(osg::NOTICE)<<"      revised compileTime   = "<<compileTime*1000.0<<std::endl;
625#endif
626
627    if (databasePager && databasePager->requiresExternalCompileGLObjects(sceneView->getState()->getContextID()))
628    {
629        databasePager->compileGLObjects(*(sceneView->getState()), compileTime);
630    }
631}
632
[7178]633void Renderer::operator () (osg::Object* object)
634{
635    osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
636    if (context) operator()(context);
637
638    osg::Camera* camera = dynamic_cast<osg::Camera*>(object);
639    if (camera) cull();
640}
641
642void Renderer::operator () (osg::GraphicsContext* context)
643{
644    if (_graphicsThreadDoesCull)
645    {
646        cull_draw();
647    }
648    else
649    {
650        draw();
651    }
652}
653
654void Renderer::release()
655{
656    osg::notify(osg::INFO)<<"Renderer::release()"<<std::endl;
657    _done = true;
658
[7270]659    _availableQueue.release();
660    _drawQueue.release();
[7178]661}
Note: See TracBrowser for help on using the browser.