| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #ifndef PRODUCER_CAMERA_CONFIG |
|---|
| 15 | #define PRODUCER_CAMERA_CONFIG |
|---|
| 16 | |
|---|
| 17 | #include <stdio.h> |
|---|
| 18 | |
|---|
| 19 | #include <osg/Referenced> |
|---|
| 20 | #include <osg/Matrix> |
|---|
| 21 | #include <osgViewer/View> |
|---|
| 22 | |
|---|
| 23 | #include <string> |
|---|
| 24 | #include <map> |
|---|
| 25 | #include <vector> |
|---|
| 26 | #include <osg/Notify> |
|---|
| 27 | #include <osg/Vec2> |
|---|
| 28 | #include <iostream> |
|---|
| 29 | |
|---|
| 30 | #include "Camera.h" |
|---|
| 31 | #include "RenderSurface.h" |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | namespace osgProducer { |
|---|
| 36 | |
|---|
| 37 | #define notImplemented {std::cout << __FILE__ << " " << __LINE__ << std::endl;} |
|---|
| 38 | class CameraGroup : public osg::Referenced { |
|---|
| 39 | public: |
|---|
| 40 | enum ThreadModel { |
|---|
| 41 | SingleThreaded, |
|---|
| 42 | ThreadPerRenderSurface, |
|---|
| 43 | ThreadPerCamera |
|---|
| 44 | }; |
|---|
| 45 | static ThreadModel getDefaultThreadModel() { return SingleThreaded;} |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | class InputArea : public osg::Referenced { |
|---|
| 50 | public: |
|---|
| 51 | void addRenderSurface(RenderSurface* s) { _rs.push_back(s); } |
|---|
| 52 | std::vector<osg::ref_ptr<RenderSurface> > _rs; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | #undef notImplemented |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | class CameraConfig : public osg::Referenced |
|---|
| 59 | { |
|---|
| 60 | public : |
|---|
| 61 | CameraConfig(); |
|---|
| 62 | |
|---|
| 63 | void beginVisual( void ); |
|---|
| 64 | |
|---|
| 65 | void beginVisual( const char * name ); |
|---|
| 66 | |
|---|
| 67 | void setVisualSimpleConfiguration( void ); |
|---|
| 68 | |
|---|
| 69 | void setVisualByID( unsigned int id ); |
|---|
| 70 | |
|---|
| 71 | void addVisualAttribute( VisualChooser::AttributeName token, int param ); |
|---|
| 72 | |
|---|
| 73 | void addVisualAttribute( VisualChooser::AttributeName token ); |
|---|
| 74 | |
|---|
| 75 | void addVisualExtendedAttribute( unsigned int token ); |
|---|
| 76 | |
|---|
| 77 | void addVisualExtendedAttribute( unsigned int token, int param ); |
|---|
| 78 | |
|---|
| 79 | void endVisual( void ); |
|---|
| 80 | |
|---|
| 81 | VisualChooser *findVisual( const char *name ); |
|---|
| 82 | |
|---|
| 83 | bool parseFile( const std::string &file ); |
|---|
| 84 | |
|---|
| 85 | void beginRenderSurface( const char *name ); |
|---|
| 86 | |
|---|
| 87 | void setRenderSurfaceVisualChooser( const char *name ); |
|---|
| 88 | |
|---|
| 89 | void setRenderSurfaceVisualChooser( void ); |
|---|
| 90 | |
|---|
| 91 | void setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height ); |
|---|
| 92 | |
|---|
| 93 | void setRenderSurfaceCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height ); |
|---|
| 94 | |
|---|
| 95 | void setRenderSurfaceOverrideRedirect( bool flag ); |
|---|
| 96 | |
|---|
| 97 | void setRenderSurfaceHostName( const std::string &name ); |
|---|
| 98 | |
|---|
| 99 | void setRenderSurfaceDisplayNum( int n ); |
|---|
| 100 | |
|---|
| 101 | void setRenderSurfaceScreen( int n ); |
|---|
| 102 | |
|---|
| 103 | void setRenderSurfaceBorder( bool flag ); |
|---|
| 104 | |
|---|
| 105 | void setRenderSurfaceDrawableType( RenderSurface::DrawableType drawableType ); |
|---|
| 106 | |
|---|
| 107 | void setRenderSurfaceRenderToTextureMode( RenderSurface::RenderToTextureMode rttMode ); |
|---|
| 108 | |
|---|
| 109 | void setRenderSurfaceReadDrawable( const char *name ); |
|---|
| 110 | |
|---|
| 111 | void setRenderSurfaceInputRectangle( float x0, float x1, float y0, float y1 ); |
|---|
| 112 | |
|---|
| 113 | void endRenderSurface( void ); |
|---|
| 114 | |
|---|
| 115 | RenderSurface *findRenderSurface( const char *name ); |
|---|
| 116 | |
|---|
| 117 | unsigned int getNumberOfRenderSurfaces(); |
|---|
| 118 | |
|---|
| 119 | RenderSurface *getRenderSurface( unsigned int index ); |
|---|
| 120 | |
|---|
| 121 | void addCamera( std::string name, Camera *camera ); |
|---|
| 122 | |
|---|
| 123 | void beginCamera( std::string name ); |
|---|
| 124 | |
|---|
| 125 | void setCameraRenderSurface( const char *name ); |
|---|
| 126 | |
|---|
| 127 | void setCameraRenderSurface( void ); |
|---|
| 128 | |
|---|
| 129 | void setCameraProjectionRectangle( float x0, float x1, float y0, float y1 ); |
|---|
| 130 | |
|---|
| 131 | void setCameraProjectionRectangle( int x0, int x1, int y0, int y1 ); |
|---|
| 132 | |
|---|
| 133 | void setCameraOrtho( float left, float right, float bottom, float top, float nearClip, float farClip, |
|---|
| 134 | float xshear=0.0, float yshear=0.0 ); |
|---|
| 135 | |
|---|
| 136 | void setCameraPerspective( float hfov, float vfov, float nearClip, float farClip, |
|---|
| 137 | float xshear=0.0, float yshear=0.0 ); |
|---|
| 138 | |
|---|
| 139 | void setCameraFrustum( float left, float right, float bottom, float top, float nearClip, float farClip, |
|---|
| 140 | float xshear=0.0, float yshear=0.0 ); |
|---|
| 141 | |
|---|
| 142 | void setCameraLensShear( osg::Matrix::value_type xshear, osg::Matrix::value_type yshear ); |
|---|
| 143 | |
|---|
| 144 | void setCameraShareLens( bool shared ); |
|---|
| 145 | |
|---|
| 146 | void setCameraShareView( bool shared ); |
|---|
| 147 | |
|---|
| 148 | void setCameraClearColor( float r, float g, float b, float a ); |
|---|
| 149 | |
|---|
| 150 | void beginCameraOffset(); |
|---|
| 151 | |
|---|
| 152 | void rotateCameraOffset( osg::Matrix::value_type deg, osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); |
|---|
| 153 | |
|---|
| 154 | void translateCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); |
|---|
| 155 | |
|---|
| 156 | void scaleCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); |
|---|
| 157 | |
|---|
| 158 | void shearCameraOffset( osg::Matrix::value_type shearx, osg::Matrix::value_type sheary ); |
|---|
| 159 | |
|---|
| 160 | void setCameraOffsetMultiplyMethod( Camera::Offset::MultiplyMethod method ); |
|---|
| 161 | |
|---|
| 162 | void endCameraOffset(); |
|---|
| 163 | |
|---|
| 164 | void endCamera( void ); |
|---|
| 165 | |
|---|
| 166 | Camera *findCamera( const char *name ); |
|---|
| 167 | |
|---|
| 168 | unsigned int getNumberOfCameras() const; |
|---|
| 169 | |
|---|
| 170 | const Camera *getCamera( unsigned int n ) const; |
|---|
| 171 | |
|---|
| 172 | Camera *getCamera( unsigned int n ); |
|---|
| 173 | |
|---|
| 174 | void beginInputArea(); |
|---|
| 175 | |
|---|
| 176 | void addInputAreaEntry( char *renderSurfaceName ); |
|---|
| 177 | |
|---|
| 178 | void endInputArea() ; |
|---|
| 179 | |
|---|
| 180 | void setInputArea(InputArea *ia); |
|---|
| 181 | |
|---|
| 182 | InputArea *getInputArea(); |
|---|
| 183 | |
|---|
| 184 | const InputArea *getInputArea() const; |
|---|
| 185 | |
|---|
| 186 | void realize( void ); |
|---|
| 187 | |
|---|
| 188 | bool defaultConfig(); |
|---|
| 189 | |
|---|
| 190 | struct StereoSystemCommand |
|---|
| 191 | { |
|---|
| 192 | int _screen; |
|---|
| 193 | std::string _setStereoCommand; |
|---|
| 194 | std::string _restoreMonoCommand; |
|---|
| 195 | |
|---|
| 196 | StereoSystemCommand(int screen, std::string setStereoCommand, std::string restoreMonoCommand ): |
|---|
| 197 | _screen(screen), |
|---|
| 198 | _setStereoCommand(setStereoCommand), |
|---|
| 199 | _restoreMonoCommand(restoreMonoCommand) {} |
|---|
| 200 | }; |
|---|
| 201 | |
|---|
| 202 | static std::string findFile( std::string ); |
|---|
| 203 | |
|---|
| 204 | void addStereoSystemCommand( int screen, std::string stereoCmd, std::string monoCmd ); |
|---|
| 205 | |
|---|
| 206 | const std::vector<StereoSystemCommand> &getStereoSystemCommands(); |
|---|
| 207 | |
|---|
| 208 | void setThreadModelDirective( CameraGroup::ThreadModel directive ) { _threadModelDirective = directive; } |
|---|
| 209 | CameraGroup::ThreadModel getThreadModelDirective() { return _threadModelDirective; } |
|---|
| 210 | |
|---|
| 211 | protected: |
|---|
| 212 | |
|---|
| 213 | virtual ~CameraConfig(); |
|---|
| 214 | |
|---|
| 215 | private : |
|---|
| 216 | |
|---|
| 217 | std::map <std::string, VisualChooser *> _visual_map; |
|---|
| 218 | osg::ref_ptr< VisualChooser >_current_visual_chooser; |
|---|
| 219 | bool _can_add_visual_attributes; |
|---|
| 220 | |
|---|
| 221 | std::map <std::string, osg::ref_ptr<RenderSurface > > _render_surface_map; |
|---|
| 222 | osg::ref_ptr<RenderSurface> _current_render_surface; |
|---|
| 223 | bool _can_add_render_surface_attributes; |
|---|
| 224 | |
|---|
| 225 | std::map <std::string, osg::ref_ptr< Camera > > _camera_map; |
|---|
| 226 | osg::ref_ptr<Camera> _current_camera; |
|---|
| 227 | bool _can_add_camera_attributes; |
|---|
| 228 | |
|---|
| 229 | osg::ref_ptr< InputArea > _input_area; |
|---|
| 230 | bool _can_add_input_area_entries; |
|---|
| 231 | |
|---|
| 232 | unsigned int getNumberOfScreens(); |
|---|
| 233 | |
|---|
| 234 | osg::Matrix::value_type _offset_matrix[16]; |
|---|
| 235 | osg::Matrix::value_type _offset_shearx, _offset_sheary; |
|---|
| 236 | |
|---|
| 237 | std::vector<StereoSystemCommand> _stereoSystemCommands; |
|---|
| 238 | |
|---|
| 239 | bool _postmultiply; |
|---|
| 240 | |
|---|
| 241 | CameraGroup::ThreadModel _threadModelDirective; |
|---|
| 242 | }; |
|---|
| 243 | |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | #endif |
|---|