OpenSceneGraph 3.6.5
ViewerBase
Go to the documentation of this file.
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#ifndef OSGVIEWER_VIEWERBASE
15#define OSGVIEWER_VIEWERBASE 1
16
17#include <osg/Stats>
18
19#include <osgUtil/UpdateVisitor>
21
22#include <osgGA/EventVisitor>
23#include <osgGA/EventQueue>
24
25#include <osgViewer/Scene>
27
28namespace osgViewer {
29
30#define USE_REFERENCE_TIME DBL_MAX
31
32class View;
33
36{
37 public:
38
41
42
44 virtual void setViewerStats(osg::Stats* stats) = 0;
45
47 virtual osg::Stats* getViewerStats() = 0;
48
50 virtual const osg::Stats* getViewerStats() const = 0;
51
52
54 virtual bool readConfiguration(const std::string& filename) = 0;
55
57 virtual bool isRealized() const = 0;
58
60 virtual void realize() = 0;
61
62
65
68
70 virtual void configureAffinity();
71
73 virtual void setProcessorAffinity(const OpenThreads::Affinity& affinity) { _affinity = affinity; }
74 OpenThreads::Affinity& getProcessorAffinity() { return _affinity; }
75 const OpenThreads::Affinity& getProcessorAffinity() const { return _affinity; }
76
87
89 virtual void setThreadingModel(ThreadingModel threadingModel);
90
93
96
98 virtual void setUpThreading();
99
101 bool areThreadsRunning() const { return _threadsRunning; }
102
104 virtual void stopThreading();
105
107 virtual void startThreading();
108
114
121
124
130
133
134
136 void setDone(bool done) { _done = done; }
137
139 bool done() const { return _done; }
140
142 void setEventVisitor(osgGA::EventVisitor* eventVisitor) { _eventVisitor = eventVisitor; }
143
146
148 const osgGA::EventVisitor* getEventVisitor() const { return _eventVisitor.get(); }
149
154 void setKeyEventSetsDone(int key) { _keyEventSetsDone = key; }
155
158
160 void setQuitEventSetsDone(bool flag) { _quitEventSetsDone = flag; }
161
164
165
174
177
178
180 void setUpdateVisitor(osgUtil::UpdateVisitor* updateVisitor) { _updateVisitor = updateVisitor; }
181
184
187
188
191
194
197
200
203
204
207
210
213
216
221
224
225
231
234
235 void setRunMaxFrameRate(double frameRate) { _runMaxFrameRate = frameRate; }
236 double getRunMaxFrameRate() const { return _runMaxFrameRate; }
237
243 virtual int run();
244
246 virtual bool checkNeedToDoFrame() = 0;
247
249 virtual bool checkEvents() = 0;
250
253 virtual void frame(double simulationTime=USE_REFERENCE_TIME);
254
255 virtual void advance(double simulationTime=USE_REFERENCE_TIME) = 0;
256
257 virtual void eventTraversal() = 0;
258
259 virtual void updateTraversal() = 0;
260
261 virtual void renderingTraversals();
262
263 typedef std::vector<osg::Camera*> Cameras;
264 virtual void getCameras(Cameras& cameras, bool onlyActive=true) = 0;
265
266 typedef std::vector<osg::GraphicsContext*> Contexts;
267 virtual void getContexts(Contexts& contexts, bool onlyValid=true) = 0;
268
269 typedef std::vector<osgViewer::GraphicsWindow*> Windows;
270 virtual void getWindows(Windows& windows, bool onlyValid=true);
271
272 typedef std::vector<OpenThreads::Thread*> Threads;
273 virtual void getAllThreads(Threads& threads, bool onlyActive=true) = 0;
274
275 typedef std::vector<osg::OperationThread*> OperationThreads;
276 virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true) = 0;
277
278 typedef std::vector<osgViewer::Scene*> Scenes;
279 virtual void getScenes(Scenes& scenes, bool onlyValid=true) = 0;
280
281 typedef std::vector<osgViewer::View*> Views;
282 virtual void getViews(Views& views, bool onlyValid=true) = 0;
283
286
291 void checkWindowStatus(const Contexts& contexts);
292
293 virtual double elapsedTime() = 0;
294
296
298 virtual void getUsage(osg::ApplicationUsage& usage) const = 0;
299
300 bool getRequestRedraw() const { return _requestRedraw; }
301
303
304protected:
305
307
308 friend class osgViewer::View;
309
311 {
312 if (_currentContext==gc) return;
313
315
316 if (gc && gc->valid() && gc->makeCurrent()) _currentContext = gc;
317 }
318
319 inline void releaseContext()
320 {
321 if (_currentContext.valid() && _currentContext->valid())
322 {
323 _currentContext->releaseContext();
324 }
325 _currentContext = 0;
326 }
327
328 virtual void viewerInit() = 0;
329
331 bool _done;
335
337 OpenThreads::Affinity _affinity;
340
343
346
347
350
354
356
359
363
365
366 private:
367
368 // Define private copy constructor
369 // otherwsie VS2015 will construct it's own which will call the private copy operator from osg::Object resulting in an compile error.
370 ViewerBase& operator = (const ViewerBase&) { return *this; }
371};
372
373}
374
375#endif
#define USE_REFERENCE_TIME
Definition ViewerBase:30
The osgViewer library provides high level viewer functionality designed to make it easier to write a ...
Definition ApplicationUsage:26
Class which encapsulates the frame number, reference time and calendar time of specific frame,...
Definition FrameStamp:35
Base class for providing Windowing API agnostic access to creating and managing graphics context.
Definition GraphicsContext:30
virtual bool valid() const =0
Return whether a valid and usable GraphicsContext has been created.
bool makeCurrent()
Make this graphics context current.
PreBlockOp
Definition GraphicsThread:70
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for observed objects, that automatically set pointers to them to null when they are del...
Definition observer_ptr:39
Base class for implementing graphics operations.
Definition OperationThread:51
Definition OperationThread:91
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition Stats:29
Basic EventVisitor implementation for animating a scene.
Definition EventVisitor:42
Definition IncrementalCompileOperation:56
Basic UpdateVisitor implementation for animating a scene.
Definition UpdateVisitor:38
View holds a single view on a scene, this view may be composed of one or more slave cameras.
Definition View:76
osg::ref_ptr< osgGA::EventVisitor > _eventVisitor
Definition ViewerBase:355
osg::BarrierOperation::PreBlockOp _endBarrierOperation
Definition ViewerBase:349
osg::Operation * getCleanUpOperation()
Get the graphics operation to call before the viewers graphics contexts close.
Definition ViewerBase:215
void makeCurrent(osg::GraphicsContext *gc)
Definition ViewerBase:310
FrameScheme getRunFrameScheme() const
Definition ViewerBase:233
virtual void startThreading()
Start any threads required by the viewer.
const osg::OperationQueue * getUpdateOperations() const
Get the const Update OperationQueue.
Definition ViewerBase:196
bool _requestRedraw
Definition ViewerBase:341
const OpenThreads::Affinity & getProcessorAffinity() const
Definition ViewerBase:75
virtual bool readConfiguration(const std::string &filename)=0
read the viewer configuration from a configuration file.
bool getUseConfigureAffinity() const
get whether the setUpThreading() method should call configureAffinity() to set up up the processor af...
Definition ViewerBase:67
virtual void getAllThreads(Threads &threads, bool onlyActive=true)=0
ThreadingModel
Definition ViewerBase:78
@ AutomaticSelection
Definition ViewerBase:85
@ CullThreadPerCameraDrawThreadPerContext
Definition ViewerBase:83
@ CullDrawThreadPerContext
Definition ViewerBase:80
@ SingleThreaded
Definition ViewerBase:79
@ ThreadPerCamera
Definition ViewerBase:84
@ ThreadPerContext
Definition ViewerBase:81
@ DrawThreadPerContext
Definition ViewerBase:82
void setDone(bool done)
Set the done flag to signal the viewer's work is done and should exit the frame loop.
Definition ViewerBase:136
virtual void getCameras(Cameras &cameras, bool onlyActive=true)=0
osg::ref_ptr< osg::Operation > _cleanUpOperation
Definition ViewerBase:361
OpenThreads::Affinity & getProcessorAffinity()
Definition ViewerBase:74
virtual bool isRealized() const =0
Get whether at least of one of this viewers windows are realized.
ThreadingModel getThreadingModel() const
Get the threading model the rendering traversals will use.
Definition ViewerBase:92
void setUpdateOperations(osg::OperationQueue *operations)
Set the Update OperationQueue.
Definition ViewerBase:190
void setCleanUpOperation(osg::Operation *op)
Set the graphics operation to call before the viewers graphics contexts close.
Definition ViewerBase:212
osg::ref_ptr< osg::BarrierOperation > _endRenderingDispatchBarrier
Definition ViewerBase:352
virtual void configureAffinity()
analyse the viewer configuration and select an appropriate Affinity for main thread,...
void setUseConfigureAffinity(bool flag)
Set whether the setUpThreading() method should call configureAffinity() to set up up the processor af...
Definition ViewerBase:64
void checkWindowStatus()
Check to see if any windows are still open.
std::vector< OpenThreads::Thread * > Threads
Definition ViewerBase:272
OpenThreads::Affinity _affinity
Definition ViewerBase:337
osg::observer_ptr< osg::GraphicsContext > _currentContext
Definition ViewerBase:364
virtual void getViews(Views &views, bool onlyValid=true)=0
virtual osg::Stats * getViewerStats()=0
Get the Viewers Stats object.
osg::ref_ptr< osg::EndOfDynamicDrawBlock > _endDynamicDrawBlock
Definition ViewerBase:353
virtual void setViewerStats(osg::Stats *stats)=0
Set the Stats object used to collect various frame related timing and scene graph stats.
osg::ref_ptr< osgUtil::UpdateVisitor > _updateVisitor
Definition ViewerBase:358
virtual int run()
Execute a main frame loop.
virtual void stopThreading()
Stop any threads being run by viewer.
virtual void updateTraversal()=0
virtual void getWindows(Windows &windows, bool onlyValid=true)
bool getQuitEventSetsDone() const
Definition ViewerBase:163
void setRealizeOperation(osg::Operation *op)
Set the graphics operation to call on realization of the viewers graphics windows.
Definition ViewerBase:206
bool _useConfigureAffinity
Definition ViewerBase:336
virtual ThreadingModel suggestBestThreadingModel()
Let the viewer suggest the best threading model for the viewers camera/window setup and the hardware ...
BarrierPosition
Definition ViewerBase:110
@ AfterSwapBuffers
Definition ViewerBase:112
@ BeforeSwapBuffers
Definition ViewerBase:111
void setQuitEventSetsDone(bool flag)
if the flag is true, the viewer set its done flag when a QUIT_APPLICATION is received,...
Definition ViewerBase:160
std::vector< osg::OperationThread * > OperationThreads
Definition ViewerBase:275
virtual void viewerInit()=0
osg::Operation * getRealizeOperation()
Get the graphics operation to call on realization of the viewers graphics windows.
Definition ViewerBase:209
int _keyEventSetsDone
Definition ViewerBase:332
void setRunFrameScheme(FrameScheme fs)
Definition ViewerBase:232
void addUpdateOperation(osg::Operation *operation)
Add an update operation.
osg::ref_ptr< osg::BarrierOperation > _startRenderingBarrier
Definition ViewerBase:351
osg::OperationQueue * getUpdateOperations()
Get the Update OperationQueue.
Definition ViewerBase:193
virtual void realize()=0
set up windows and associated threads.
virtual void getOperationThreads(OperationThreads &threads, bool onlyActive=true)=0
virtual void eventTraversal()=0
std::vector< osgViewer::View * > Views
Definition ViewerBase:281
osg::ref_ptr< osgUtil::IncrementalCompileOperation > _incrementalCompileOperation
Definition ViewerBase:362
void checkWindowStatus(const Contexts &contexts)
Check to see if windows are still open using the list of contexts given as a parameter.
virtual osg::FrameStamp * getViewerFrameStamp()=0
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)
Set the incremental compile operation.
double getRunMaxFrameRate() const
Definition ViewerBase:236
bool _firstFrame
Definition ViewerBase:330
virtual void renderingTraversals()
virtual void frame(double simulationTime=USE_REFERENCE_TIME)
Render a complete new frame.
osgUtil::IncrementalCompileOperation * getIncrementalCompileOperation()
Get the incremental compile operation.
Definition ViewerBase:223
void setRunMaxFrameRate(double frameRate)
Definition ViewerBase:235
bool done() const
Return true if viewer's work is done and should exit the frame loop.
Definition ViewerBase:139
osgUtil::UpdateVisitor * getUpdateVisitor()
Get the UpdateVisitor.
Definition ViewerBase:183
void setEndBarrierPosition(BarrierPosition bp)
Set the position of the end barrier.
std::vector< osg::Camera * > Cameras
Definition ViewerBase:263
void setReleaseContextAtEndOfFrameHint(bool hint)
Hint to tell the renderingTraversals() method whether to call releaseContext() on the last context th...
Definition ViewerBase:173
BarrierPosition getEndBarrierPosition() const
Get the end barrier position.
Definition ViewerBase:123
virtual void setUpThreading()
Set up the threading and processor affinity as per the viewers threading model.
bool getRequestContinousUpdate() const
Definition ViewerBase:302
virtual void getScenes(Scenes &scenes, bool onlyValid=true)=0
virtual void setProcessorAffinity(const OpenThreads::Affinity &affinity)
Set the processor affinity of main thread.
Definition ViewerBase:73
virtual void setThreadingModel(ThreadingModel threadingModel)
Set the threading model the rendering traversals will use.
bool _done
Definition ViewerBase:331
int getKeyEventSetsDone() const
get the key event that the viewer checks on each frame to see if the viewer's done flag.
Definition ViewerBase:157
const osgGA::EventVisitor * getEventVisitor() const
Get the const EventVisitor.
Definition ViewerBase:148
std::vector< osg::GraphicsContext * > Contexts
Definition ViewerBase:266
bool _requestContinousUpdate
Definition ViewerBase:342
virtual const osg::Stats * getViewerStats() const =0
Get the Viewers Stats object.
ThreadingModel _threadingModel
Definition ViewerBase:338
void setEndBarrierOperation(osg::BarrierOperation::PreBlockOp op)
Set the end barrier operation.
BarrierPosition _endBarrierPosition
Definition ViewerBase:348
osgGA::EventVisitor * getEventVisitor()
Get the EventVisitor.
Definition ViewerBase:145
bool _releaseContextAtEndOfFrameHint
Definition ViewerBase:334
ViewerBase(const ViewerBase &vb)
FrameScheme
Definition ViewerBase:227
@ ON_DEMAND
Definition ViewerBase:228
@ CONTINUOUS
Definition ViewerBase:229
std::vector< osgViewer::Scene * > Scenes
Definition ViewerBase:278
void setKeyEventSetsDone(int key)
Set the key event that the viewer checks on each frame to see if the viewer's done flag should be set...
Definition ViewerBase:154
bool _threadsRunning
Definition ViewerBase:339
void releaseContext()
Definition ViewerBase:319
void removeUpdateOperation(osg::Operation *operation)
Remove an update operation.
double _runMaxFrameRate
Definition ViewerBase:345
virtual bool checkNeedToDoFrame()=0
check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.
osg::ref_ptr< osg::Operation > _realizeOperation
Definition ViewerBase:360
virtual void getContexts(Contexts &contexts, bool onlyValid=true)=0
virtual double elapsedTime()=0
bool _quitEventSetsDone
Definition ViewerBase:333
bool getRequestRedraw() const
Definition ViewerBase:300
bool getReleaseContextAtEndOfFrameHint() const
Hint to tell the renderingTraversals() method whether to call releaseContext().
Definition ViewerBase:176
const osgUtil::UpdateVisitor * getUpdateVisitor() const
Get the const UpdateVisitor.
Definition ViewerBase:186
virtual bool checkEvents()=0
check to see if events have been received, return true if events are now available.
osg::ref_ptr< osg::OperationQueue > _updateOperations
Definition ViewerBase:357
bool areThreadsRunning() const
Return true if viewer threads are running.
Definition ViewerBase:101
virtual void getUsage(osg::ApplicationUsage &usage) const =0
Get the keyboard and mouse usage of this viewer.
std::vector< osgViewer::GraphicsWindow * > Windows
Definition ViewerBase:269
osg::BarrierOperation::PreBlockOp getEndBarrierOperation() const
Get the end barrier operation.
Definition ViewerBase:132
virtual void advance(double simulationTime=USE_REFERENCE_TIME)=0
FrameScheme _runFrameScheme
Definition ViewerBase:344
void setEventVisitor(osgGA::EventVisitor *eventVisitor)
Set the EventVisitor.
Definition ViewerBase:142
void setUpdateVisitor(osgUtil::UpdateVisitor *updateVisitor)
Set the UpdateVisitor.
Definition ViewerBase:180
#define OSGVIEWER_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.