OpenFrames
RenderRectangle.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  ***********************************/
16 
21 #ifndef _OF_RENDERRECTANGLE_
22 #define _OF_RENDERRECTANGLE_
23 
24 #include <OpenFrames/Export.h>
28 #include <OpenFrames/SkySphere.hpp>
29 #include <OpenFrames/View.hpp>
30 #include <OpenFrames/VRUtils.hpp>
31 #include <osg/Camera>
32 #include <osg/Referenced>
33 #include <osg/ref_ptr>
34 #include <osgViewer/View>
35 #include <vector>
36 
37 namespace OpenFrames
38 {
50  class OF_EXPORT RenderRectangle : public osg::Referenced
51  {
52  public:
53  typedef std::vector<osg::ref_ptr<View> > ViewList;
54 
57  RenderRectangle(OpenVRDevice *ovrDevice = NULL, VRTextureBuffer *vrTextureBuffer = NULL);
58 
60  void setFrameManager(FrameManager *fm);
61  inline FrameManager* getFrameManager() const { return _frameManager.get(); }
62 
64  osgViewer::View* getSceneView() const { return _sceneView.get(); }
65 
67  osg::Group* getHUD() const { return _hudCamera.get(); }
68 
70  void setGraphicsContext(osg::GraphicsContext *gc);
71 
73  void setViewport(int x, int y, int w, int h);
74 
76  void setSelected(bool select);
77  bool getSelected();
78 
80  void setShowBorder(bool show);
81  bool getShowBorder() { return (_borderGeode->getNodeMask() != 0x0); }
82 
84  void setSkySphereTexture(const std::string& fname);
85 
87  bool setSkySphereStarData(const std::string& catalogName, float minMag, float maxMag, unsigned int maxNumStars = 100000,
88  float minPixSize = 1.0, float maxPixSize = 10.0, float minDimRatio = 0.5f);
89 
91  SkySphere* getSkySphere() const { return _skySphere.get(); }
92 
94  void setBackgroundColor(float r, float g, float b);
95 
97  void setDepthPartitioningEnabled(bool enable) {}
98 
100  void addView(View *view); // Adds view to the end of the view list
101  void removeView(View *view); // Removes all instances of view
102  void removeAllViews(); // Clears entire view list
103 
105  void nextView();
106  void previousView();
107 
109  void selectView(View *view);
110  void selectView(unsigned int newView);
111 
113  View* getCurrentView();
114 
116  void applyCurrentViewProjection();
117 
119  //void enableVR();
120 
121  protected:
122  virtual ~RenderRectangle();
123  void _init();
124 
125  void selectCurrentView(); // Just make sure current view is selected
126  void updateViewProjection(View *view); // Update projection matrix
127 
128  ViewList _views; // All of the added Views
129  osg::ref_ptr<View> _defaultView; // Used if no Views have been added
130  unsigned int _currView; // Currently active View
131 
132  // Contains the ReferenceFrame scene, and any decorations such as
133  // a box around this RenderRectangle
134  osg::ref_ptr<osgViewer::View> _sceneView;
135 
136  // Uses multipass rendering on scenes with large depth ranges
137  osg::ref_ptr<DepthPartitioner> _depthPartitioner;
138 
139  osg::ref_ptr<osg::Group> _scene; // Everything to be drawn
140 
141  // Cameras used to render various parts of the scene
142  osg::ref_ptr<osg::Camera> _hudCamera; // Heads-up-display camera
143  osg::ref_ptr<osg::Camera> _backCamera; // Background camera
144  osg::ref_ptr<osg::Camera> _mirrorCamera; // Camera to mirror scene onto window
145 
146  osg::ref_ptr<VRCamera> _backCameraVR; // VR version of background camera
147 
148  // Render textures used for storing each eye's image in VR
149  osg::observer_ptr<VRTextureBuffer> _vrTextureBuffer;
150 
151  // OpenVR device
152  osg::observer_ptr<OpenVRDevice> _ovrDevice;
153  bool _useVR;
154 
155  osg::ref_ptr<osg::Geode> _borderGeode; // The border rectangle
156  osg::ref_ptr<SkySphere> _skySphere; // The background sky
157 
158  // Manager for access to the ReferenceFrame scene
159  osg::ref_ptr<FrameManager> _frameManager;
160  };
161 
162 }
163 
164 #endif
Extends OpenFrames::Sphere.
Definition: SkySphere.hpp:41
osgViewer::View * getSceneView() const
Definition: RenderRectangle.hpp:64
Encapsulates textures used for VR offscreen rendering.
Definition: VRUtils.hpp:42
Encapsulates a rectangle in which a scene can be rendered.
Definition: RenderRectangle.hpp:50
Represents data needed to use an OpenVR-supported HMD.
Definition: OpenVRDevice.hpp:87
This class allows priority access to a ReferenceFrame heirarchy.
Definition: FrameManager.hpp:52
Definition: CoordinateAxes.hpp:29
void setDepthPartitioningEnabled(bool enable)
Definition: RenderRectangle.hpp:97
osg::Group * getHUD() const
Definition: RenderRectangle.hpp:67
SkySphere * getSkySphere() const
Definition: RenderRectangle.hpp:91
Encapsulates variables needed for a view.
Definition: View.hpp:45