From b164c5e7a609b2406d75b49425fdca96e86a4584 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 5 Dec 2007 11:23:27 +0000 Subject: [PATCH] From Cedric Pinson, first cut at Producer .cfg camera configuration file support. --- src/osgPlugins/CMakeLists.txt | 6 + src/osgPlugins/cfg/CMakeLists.txt | 20 + src/osgPlugins/cfg/Camera.cpp | 776 ++++++++ src/osgPlugins/cfg/Camera.h | 399 ++++ src/osgPlugins/cfg/CameraConfig.cpp | 672 +++++++ src/osgPlugins/cfg/CameraConfig.h | 246 +++ src/osgPlugins/cfg/ConfigLexer.cpp | 2170 ++++++++++++++++++++++ src/osgPlugins/cfg/ConfigLexer.l | 164 ++ src/osgPlugins/cfg/ConfigParser.cpp | 2302 ++++++++++++++++++++++++ src/osgPlugins/cfg/ConfigParser.h | 194 ++ src/osgPlugins/cfg/ConfigParser.y | 654 +++++++ src/osgPlugins/cfg/FlexLexer.h | 186 ++ src/osgPlugins/cfg/ReaderWriterCFG.cpp | 199 ++ src/osgPlugins/cfg/RenderSurface.cpp | 689 +++++++ src/osgPlugins/cfg/RenderSurface.h | 613 +++++++ src/osgPlugins/cfg/VisualChooser.cpp | 744 ++++++++ src/osgPlugins/cfg/VisualChooser.h | 207 +++ 17 files changed, 10241 insertions(+) create mode 100644 src/osgPlugins/cfg/CMakeLists.txt create mode 100644 src/osgPlugins/cfg/Camera.cpp create mode 100644 src/osgPlugins/cfg/Camera.h create mode 100644 src/osgPlugins/cfg/CameraConfig.cpp create mode 100644 src/osgPlugins/cfg/CameraConfig.h create mode 100644 src/osgPlugins/cfg/ConfigLexer.cpp create mode 100644 src/osgPlugins/cfg/ConfigLexer.l create mode 100644 src/osgPlugins/cfg/ConfigParser.cpp create mode 100644 src/osgPlugins/cfg/ConfigParser.h create mode 100644 src/osgPlugins/cfg/ConfigParser.y create mode 100644 src/osgPlugins/cfg/FlexLexer.h create mode 100644 src/osgPlugins/cfg/ReaderWriterCFG.cpp create mode 100644 src/osgPlugins/cfg/RenderSurface.cpp create mode 100644 src/osgPlugins/cfg/RenderSurface.h create mode 100644 src/osgPlugins/cfg/VisualChooser.cpp create mode 100644 src/osgPlugins/cfg/VisualChooser.h diff --git a/src/osgPlugins/CMakeLists.txt b/src/osgPlugins/CMakeLists.txt index cd585d344..5b8d3af36 100644 --- a/src/osgPlugins/CMakeLists.txt +++ b/src/osgPlugins/CMakeLists.txt @@ -48,6 +48,12 @@ ADD_SUBDIRECTORY(net) ADD_SUBDIRECTORY(osg) ADD_SUBDIRECTORY(ive) +############################################################ +# +# Viewer plugins +# +ADD_SUBDIRECTORY(cfg) + ############################################################ # diff --git a/src/osgPlugins/cfg/CMakeLists.txt b/src/osgPlugins/cfg/CMakeLists.txt new file mode 100644 index 000000000..0a3ef8166 --- /dev/null +++ b/src/osgPlugins/cfg/CMakeLists.txt @@ -0,0 +1,20 @@ +SET(TARGET_SRC + CameraConfig.cpp + Camera.cpp + ConfigLexer.cpp + ConfigParser.cpp + ReaderWriterCFG.cpp + RenderSurface.cpp + VisualChooser.cpp +) + +SET(TARGET_H + CameraConfig.h + Camera.h + ConfigParser.h + RenderSurface.h + VisualChooser.h +) + +#### end var setup ### +SETUP_PLUGIN(cfg) diff --git a/src/osgPlugins/cfg/Camera.cpp b/src/osgPlugins/cfg/Camera.cpp new file mode 100644 index 000000000..d1e3ad947 --- /dev/null +++ b/src/osgPlugins/cfg/Camera.cpp @@ -0,0 +1,776 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#ifdef WIN32 +#include +#endif + +#include +#include + +#include "Camera.h" + +using namespace osgProducer; + +Camera::Camera( void ) +{ + _index = 0; + + _projrectLeft = 0.0; + _projrectRight = 1.0; + _projrectBottom = 0.0; + _projrectTop = 1.0; + + osg::Matrix::value_type id[] = { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + memcpy( _viewMatrix, id, sizeof(osg::Matrix::value_type[16])); + _offset._xshear = _offset._yshear = 0.0f; + memcpy( _offset._matrix, id, sizeof(osg::Matrix::value_type[16])); + _offset._multiplyMethod = Offset::PreMultiply; + + _lens = new Lens; + _lens->setAutoAspect(true); + _rs = new RenderSurface; + + _clear_color[0] = 0.2f; + _clear_color[1] = 0.2f; + _clear_color[2] = 0.4f; + _clear_color[3] = 1.0f; + + _focal_distance = 1.0; + + _shareLens = true; + _shareView = true; + + _enabled = true; + _initialized = false; + +} + +Camera::~Camera( void ) +{ +} + + +const osg::Matrix::value_type * Camera::getViewMatrix( void ) const +{ + return _viewMatrix; +} + +void Camera::setViewByMatrix( const osg::Matrix &mat ) +{ + osg::Matrix m; + if ( _offset._multiplyMethod == Offset::PostMultiply ) + m = osg::Matrix( _offset._matrix ) * mat; + else if( _offset._multiplyMethod == Offset::PreMultiply ) + m = mat * osg::Matrix( _offset._matrix ); + memcpy( _viewMatrix, m.ptr(), sizeof( osg::Matrix::value_type[16] )); +} + +void Camera::setViewByLookat( const osg::Vec3 &eye, const osg::Vec3 ¢er, const osg::Vec3 &up ) +{ + osg::Matrix m; + m.makeLookAt(eye,center,up); + setViewByMatrix( m ); +} + +void Camera::setViewByLookat( float eyeX, float eyeY, float eyeZ, + float centerX, float centerY, float centerZ, + float upX, float upY, float upZ ) +{ + setViewByLookat( osg::Vec3(eyeX, eyeY, eyeZ), + osg::Vec3(centerX, centerY, centerZ ), + osg::Vec3(upX, upY, upZ) ); +} + + +Camera::Lens::Lens( void ) +{ +// original defaults. +// _left = -0.5; +// _right = 0.5; +// _bottom = -0.5; +// _top = 0.5; + + // Setting of the frustum which are appropriate for + // a monitor which is 26cm high, 50cm distant from the + // viewer and an horzintal/vetical aspect ratio of 1.25. + // This assumed to be a reasonable average setting for end users. + _left = -0.32; + _right = 0.32; + _bottom = -0.26; + _top = 0.26; + _ortho_left = -1.0; + _ortho_right = 1.0; + _ortho_bottom = -1.0; + _ortho_top = 1.0; + _nearClip = 1.0; + _farClip = 1e6; + _updateFOV(); + _projection = Perspective; +} + +void Camera::Lens::setAspectRatio( double aspectRatio ) +{ + _aspect_ratio = aspectRatio; + _left = -0.5 * (_top - _bottom) * _aspect_ratio; + _right = 0.5 * (_top - _bottom) * _aspect_ratio; + _ortho_left = -0.5 * (_ortho_top - _ortho_bottom) * _aspect_ratio; + _ortho_right = 0.5 * (_ortho_top - _ortho_bottom) * _aspect_ratio; + + if( _projection == Perspective ) + _updateFOV(); +} + +void Camera::Lens::setPerspective( double hfov, double vfov, + double nearClip, double farClip ) +{ + _hfov = osg::DegreesToRadians(hfov); + _vfov = osg::DegreesToRadians(vfov); + _aspect_ratio = tan(0.5*_hfov)/tan(0.5*_vfov); + + _nearClip = nearClip; + _farClip = farClip; + + _left = -_nearClip * tan(_hfov/2.0); + _right = _nearClip * tan(_hfov/2.0); + _bottom = -_nearClip * tan(_vfov/2.0); + _top = _nearClip * tan(_vfov/2.0); + + _projection = Perspective; + setAutoAspect(false); +} + +void Camera::Lens::setFrustum( double left, double right, + double bottom, double top, + double nearClip, double farClip ) +{ + _left = left; + _right = right; + _bottom = bottom; + _top = top; + _nearClip = nearClip; + _farClip = farClip; + _projection = Perspective; + _updateFOV(); + setAutoAspect(false); +} + +void Camera::Lens::setOrtho( double left, double right, + double bottom, double top, + double nearClip, double farClip ) +{ + _ortho_left = left; + _ortho_right = right; + _ortho_bottom = bottom; + _ortho_top = top; + _nearClip = nearClip; + _farClip = farClip; + _projection = Orthographic; + setAutoAspect(false); +} + +void Camera::Lens::setMatrix( const osg::Matrix::value_type matrix[16] ) +{ + memcpy( _matrix, matrix, sizeof(osg::Matrix::value_type[16]) ); + _projection = Manual; + setAutoAspect(false); +} + +bool Camera::Lens::getFrustum( double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar ) const +{ + //The following code was taken from osg's matrix implementation of getFrustum + if (_matrix[3]!=0.0 || _matrix[7]!=0.0 || _matrix[11]!=-1.0 || _matrix[15]!=0.0) return false; + + zNear = _matrix[14] / (_matrix[10]-1.0); + zFar = _matrix[14] / (1.0+_matrix[10]); + + left = zNear * (_matrix[8]-1.0) / _matrix[0]; + right = zNear * (1.0+_matrix[8]) / _matrix[0]; + + top = zNear * (1.0+_matrix[9]) / _matrix[5]; + bottom = zNear * (_matrix[9]-1.0) / _matrix[5]; + + return true; +} + +bool Camera::Lens::getOrtho( double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar ) const +{ + //The following code was taken from osg's matrix implementation of getOrtho + if (_matrix[3]!=0.0 || _matrix[7]!=0.0 || _matrix[11]!=0.0 || _matrix[15]!=1.0) return false; + + zNear = (_matrix[14]+1.0) / _matrix[10]; + zFar = (_matrix[14]-1.0) / _matrix[10]; + + left = -(1.0+_matrix[12]) / _matrix[0]; + right = (1.0-_matrix[12]) / _matrix[0]; + + bottom = -(1.0+_matrix[13]) / _matrix[5]; + top = (1.0-_matrix[13]) / _matrix[5]; + + return true; +} + +bool Camera::Lens::convertToOrtho( float d ) +{ + + if( _projection == Manual ) + { + //Need to extract frustum values from manual matrix + if( !getFrustum(_left,_right,_bottom,_top,_nearClip,_farClip) ) + return false; + + _updateFOV(); + } + + double s = d * tan(_vfov*0.5); + _ortho_bottom = -s; + _ortho_top = s; + _ortho_left = -s*_aspect_ratio; + _ortho_right = s*_aspect_ratio; + _projection = Orthographic; + return true; +} + +bool Camera::Lens::convertToPerspective( float d ) +{ + + if( _projection == Manual ) + { + //Need to extract ortho values from manual matrix + if( !getOrtho(_ortho_left,_ortho_right,_ortho_bottom,_ortho_top,_nearClip,_farClip) ) + return false; + } + + double hfov = 2 * atan( 0.5 * (_ortho_right - _ortho_left)/d); + double vfov = 2 * atan( 0.5 * (_ortho_top - _ortho_bottom)/d); + + _left = -_nearClip * tan(hfov*0.5); + _right = _nearClip * tan(hfov*0.5); + _bottom = -_nearClip * tan(vfov*0.5); + _top = _nearClip * tan(vfov*0.5); + + _projection = Perspective; + //_updateMatrix(); + + return true; +} + +void Camera::Lens::apply(float xshear, float yshear) +{ + osg::Matrix::value_type _matrix[16]; + generateMatrix(xshear,yshear,_matrix); +} + +void Camera::Lens::getParams( double &left, double &right, double &bottom, double &top, + double &nearClip, double &farClip ) +{ + if( _projection == Perspective ) + { + left = _left; + right = _right; + bottom = _bottom; + top = _top; + } + else if( _projection == Orthographic ) + { + left = _ortho_left; + right = _ortho_right; + bottom = _ortho_bottom; + top = _ortho_top; + } + else if( _projection == Manual ) // could only be Manual, but best to make this clear + { + // Check if Manual matrix is either a valid perspective or orthographic matrix + // If neither, then return bogus values -- nothing better we can do + if(getFrustum(left,right,bottom,top,nearClip,farClip)) + return; + + if(getOrtho(left,right,bottom,top,nearClip,farClip)) + return; + + left = _left; + right = _right; + bottom = _bottom; + top = _top; + } + nearClip = _nearClip; + farClip = _farClip; +} + +void Camera::setProjectionRectangle( const float left, const float right, + const float bottom, const float top ) +{ + _projrectLeft = left; + _projrectRight = right; + _projrectBottom = bottom; + _projrectTop = top; +} + +void Camera::getProjectionRectangle( float &left, float &right, + float &bottom, float &top ) const +{ + left = _projrectLeft; + right = _projrectRight; + bottom = _projrectBottom; + top = _projrectTop; +} + +void Camera::setProjectionRectangle( int x, int y, unsigned int width, unsigned int height ) +{ + int _x, _y; + unsigned int _w, _h; + + _rs->getWindowRectangle( _x, _y, _w, _h ); +#if 0 + if( _w == osgProducer::RenderSurface::UnknownDimension || _h == Producer::RenderSurface::UnknownDimension) + { + unsigned int ww; + unsigned int hh; + _rs->getScreenSize( ww, hh ); + if( _w == osgProducer::RenderSurface::UnknownDimension ) + _w = ww; + if( _h == osgProducer::RenderSurface::UnknownDimension ) + _h = hh; + } +#endif + + _projrectLeft = float(x - _x)/float(_w); + _projrectRight = float((x + width) - _x)/float(_w); + _projrectBottom = float(y - _y)/float(_h); + _projrectTop = float((y+height) - _y)/float(_h); +} + +void Camera::getProjectionRectangle( int &x, int &y, unsigned int &width, unsigned int &height ) const +{ + int _x, _y; + unsigned int _w, _h; + float fx, fy, fw, fh; + + _rs->getWindowRectangle( _x, _y, _w, _h ); +#if 0 + if( _w == Producer::RenderSurface::UnknownDimension || _h == Producer::RenderSurface::UnknownDimension ) + { + unsigned int ww; + unsigned int hh; + _rs->getScreenSize( ww, hh ); + if( _w == Producer::RenderSurface::UnknownDimension ) + _w = ww; + if( _h == Producer::RenderSurface::UnknownDimension ) + _h = hh; + } +#endif + + fx = _projrectLeft * _w; + fy = _projrectBottom * _h; + fw = _w * _projrectRight; + fh = _h * _projrectTop; + + x = int(fx); + y = int(fy); + + width = int(fw) - x; + height = int(fh) - y; +} + +void Camera::setClearColor( float r, float g, float b, float a ) +{ + _clear_color[0] = r; + _clear_color[1] = g; + _clear_color[2] = b; + _clear_color[3] = a; +} + +void Camera::getClearColor( float& red, float& green, float& blue, float& alpha) +{ + red = _clear_color[0]; + green = _clear_color[1]; + blue = _clear_color[2]; + alpha = _clear_color[3]; +} + + +void Camera::clear( void ) +{ +#if 0 + if( !_initialized ) _initialize(); + int x, y; + unsigned int w, h; + getProjectionRectangle( x, y, w, h ); + glViewport( x, y, w, h ); + glScissor( x, y, w, h ); + glClearColor( _clear_color[0], _clear_color[1], _clear_color[2], _clear_color[3] ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); +#endif +} + + +#if 0 +void Camera::Lens::_updateMatrix( void ) +{ + switch( _projection ) + { + case Perspective : + _matrix[ 0] = (2 * _nearClip)/(_right - _left); + _matrix[ 1] = 0.0; + _matrix[ 2] = 0.0; + _matrix[ 3] = 0.0; + + _matrix[ 4] = 0.0; + _matrix[ 5] = (2 * _nearClip)/(_top-_bottom); + _matrix[ 6] = 0.0; + _matrix[ 7] = 0.0; + + _matrix[ 8] = (_right + _left)/(_right-_left); + _matrix[ 9] = (_top+_bottom)/(_top-_bottom); + _matrix[10] = -(_farClip + _nearClip)/(_farClip-_nearClip); + _matrix[11] = -1.0; + + _matrix[12] = 0.0; + _matrix[13] = 0.0; + _matrix[14] = -(2 * _farClip * _nearClip)/(_farClip-_nearClip); + _matrix[15] = 0.0; + + _matrix[ 8] += -_xshear; + _matrix[ 9] += -_yshear; + + _hfov = 2.0 * atan(((_right - _left) * 0.5)/_nearClip); + _vfov = 2.0 * atan(((_top - _bottom) * 0.5)/_nearClip); + + break; + + case Orthographic : + + _matrix[ 0] = 2/(_ortho_right - _ortho_left); + _matrix[ 1] = 0.0; + _matrix[ 2] = 0.0; + _matrix[ 3] = 0.0; + + _matrix[ 4] = 0.0; + _matrix[ 5] = 2/(_ortho_top - _ortho_bottom); + _matrix[ 6] = 0.0; + _matrix[ 7] = 0.0; + + _matrix[ 8] = 0.0; + _matrix[ 9] = 0.0; + //_matrix[10] = -2.0/(_farClip - (-_farClip)); + _matrix[10] = -2.0/(_farClip - _nearClip); + _matrix[11] = 0.0; + + _matrix[12] = -(_ortho_right+_ortho_left)/(_ortho_right-_ortho_left); + _matrix[13] = -(_ortho_top+_ortho_bottom)/(_ortho_top-_ortho_bottom); + //_matrix[14] = -(_farClip+(-_farClip))/(_farClip-(-_farClip)); + _matrix[14] = -(_farClip+_nearClip)/(_farClip-_nearClip); + _matrix[15] = 1.0; + + _matrix[12] += _xshear; + _matrix[13] += _yshear; + + //_hfov = 0.0; + //_vfov = 0.0; + + break; + } +} +#endif + +void Camera::Lens::generateMatrix(float xshear, float yshear, osg::Matrix::value_type matrix[16] ) +{ + switch( _projection ) + { + case Perspective : + matrix[ 0] = (2 * _nearClip)/(_right - _left); + matrix[ 1] = 0.0; + matrix[ 2] = 0.0; + matrix[ 3] = 0.0; + + matrix[ 4] = 0.0; + matrix[ 5] = (2 * _nearClip)/(_top-_bottom); + matrix[ 6] = 0.0; + matrix[ 7] = 0.0; + + matrix[ 8] = (_right + _left)/(_right-_left); + matrix[ 9] = (_top+_bottom)/(_top-_bottom); + matrix[10] = -(_farClip + _nearClip)/(_farClip-_nearClip); + matrix[11] = -1.0; + + matrix[12] = 0.0; + matrix[13] = 0.0; + matrix[14] = -(2 * _farClip * _nearClip)/(_farClip-_nearClip); + matrix[15] = 0.0; + + matrix[ 8] += -xshear; + matrix[ 9] += -yshear; + + + break; + + case Orthographic : + + matrix[ 0] = 2/(_ortho_right - _ortho_left); + matrix[ 1] = 0.0; + matrix[ 2] = 0.0; + matrix[ 3] = 0.0; + + matrix[ 4] = 0.0; + matrix[ 5] = 2/(_ortho_top - _ortho_bottom); + matrix[ 6] = 0.0; + matrix[ 7] = 0.0; + + matrix[ 8] = 0.0; + matrix[ 9] = 0.0; + //_matrix[10] = -2.0/(_farClip - (-_farClip)); + matrix[10] = -2.0/(_farClip - _nearClip); + matrix[11] = 0.0; + + matrix[12] = -(_ortho_right+_ortho_left)/(_ortho_right-_ortho_left); + matrix[13] = -(_ortho_top+_ortho_bottom)/(_ortho_top-_ortho_bottom); + //_matrix[14] = -(_farClip+(-_farClip))/(_farClip-(-_farClip)); + matrix[14] = -(_farClip+_nearClip)/(_farClip-_nearClip); + matrix[15] = 1.0; + + matrix[12] += xshear; + matrix[13] += yshear; + + break; + + case Manual: + + memcpy( matrix, _matrix, sizeof(osg::Matrix::value_type[16])); + + if(xshear || yshear) + { + if (matrix[3]!=0.0 || matrix[7]!=0.0 || matrix[11]!=0.0 || matrix[15]!=1.0) + { + // It's not an orthographic matrix so just assume a perspective shear + matrix[ 8] += -xshear; + matrix[ 9] += -yshear; + } + else + { + matrix[12] += xshear; + matrix[13] += yshear; + } + } + break; + } +} + +void Camera::Lens::_updateFOV() +{ + _hfov = 2.0 * atan(((_right - _left) * 0.5)/_nearClip); + _vfov = 2.0 * atan(((_top - _bottom) * 0.5)/_nearClip); + _aspect_ratio = tan(0.5*_hfov)/tan(0.5*_vfov); +} + + +void Camera::setOffset( const osg::Matrix::value_type matrix[16], double xshear, double yshear ) +{ + memcpy( _offset._matrix, matrix, sizeof(osg::Matrix::value_type[16])); + _offset._xshear = xshear; + _offset._yshear = yshear; +} + +void Camera::setOffset( double xshear, double yshear ) +{ + _offset._xshear = xshear; + _offset._yshear = yshear; +} + +#if 0 +void Camera::setSyncBarrier( RefBarrier *b ) +{ + _syncBarrier = b; +} + +void Camera::setFrameBarrier( RefBarrier *b ) +{ + _frameBarrier = b; +} + +int Camera::cancel() +{ +#if 1 + _done = true; +#endif + + Thread::cancel(); + return 0; +} + +void Camera::advance() +{ + _rs->makeCurrent(); + _rs->swapBuffers(); +} + +void Camera::run( void ) +{ + if( !_syncBarrier.valid() || !_frameBarrier.valid() ) + { + std::cerr << "Camera::run() : Threaded Camera requires a Barrier\n"; + return; + } + + _done = false; + + _initialize(); + _syncBarrier->block(); + while( !_done ) + { + // printf(" Camera::run before frame block\n"); + + _frameBarrier->block(); + + if (_done) break; + + // printf(" Camera::run after frame block\n"); + + frame(false); + + if (_done) break; + + // printf(" Camera::run before sycn block\n"); + + _syncBarrier->block(); + + if (_done) break; + + // printf(" Camera::run after sycn block\n"); + + advance(); + } + + // printf("Exiting Camera::run cleanly\n"); +} + + + +bool Camera::removePreCullCallback( Callback *cb ) +{ + return _removeCallback( preCullCallbacks, cb ); +} + +bool Camera::removePostCullCallback( Callback *cb ) +{ + return _removeCallback( postCullCallbacks, cb ); +} + +bool Camera::removePreDrawCallback( Callback *cb ) +{ + return _removeCallback( preDrawCallbacks, cb ); +} + +bool Camera::removePostDrawCallback( Callback *cb ) +{ + return _removeCallback( postDrawCallbacks, cb ); +} + +bool Camera::removePostSwapCallback( Callback *cb ) +{ + return _removeCallback( postSwapCallbacks, cb ); +} + + +bool Camera::_removeCallback( std::vector < ref_ptr > &callbackList, Callback *callback ) +{ + std::vector < Producer::ref_ptr< Producer::Camera::Callback> >::iterator p; + p = std::find( callbackList.begin(), callbackList.end(), callback ); + if( p == callbackList.end() ) + return false; + + callbackList.erase( p ); + return true; +} + +Camera::FrameTimeStampSet::FrameTimeStampSet(): + _pipeStatsDoubleBufferIndex(0), + _pipeStatsFirstSync(true), + _initialized(false) +{ + for( unsigned int i = 0; i < LastPipeStatsID; i++ ) + _pipeStats[i] = 0.0; +} + +Camera::FrameTimeStampSet::~FrameTimeStampSet() +{ +} + +void Camera::FrameTimeStampSet::syncPipeStats() +{ + if( !_initialized ) + return; + + if( _pipeStatsFirstSync == true ) + { + _pipeStatsFirstSync = false; + return; + } + + // We get the stats from the previous frame + for( int i = 0; i < LastPipeStatsID; i++ ) + { + if( _pipeStatsSetMask[1 - _pipeStatsDoubleBufferIndex] & (1<getElapsedTime( _pipeStatsNames[i][ 1 - _pipeStatsDoubleBufferIndex] ); + } + + _pipeStatsFrameNumber = _frameNumber - 1; + _pipeStatsDoubleBufferIndex = 1 - _pipeStatsDoubleBufferIndex; + _pipeStatsSetMask[_pipeStatsDoubleBufferIndex] = 0; +} + +void Camera::FrameTimeStampSet::beginPipeTimer( PipeStatsID id) +{ + if( !_initialized ) + _init(); + + PipeTimer::instance()->begin( _pipeStatsNames[id][_pipeStatsDoubleBufferIndex] ); + _pipeStatsSetMask[_pipeStatsDoubleBufferIndex] |= (1<end() ; +} + +void Camera::FrameTimeStampSet::_init() +{ + if( _initialized ) + return; + + for( unsigned int i = 0; i < (unsigned int)LastPipeStatsID; i++ ) + PipeTimer::instance()->genQueries( 2, _pipeStatsNames[i] ); + + _pipeStatsSetMask[0] = 0; + _pipeStatsSetMask[1] = 0; + + _initialized = true; +} + +const Camera::FrameTimeStampSet &Camera::getFrameStats() +{ + return _frameStamps; +} +#endif diff --git a/src/osgPlugins/cfg/Camera.h b/src/osgPlugins/cfg/Camera.h new file mode 100644 index 000000000..2c9f1ef86 --- /dev/null +++ b/src/osgPlugins/cfg/Camera.h @@ -0,0 +1,399 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#ifndef OSGPRODUCER_CAMERA +#define OSGPRODUCER_CAMERA + +#include "RenderSurface.h" +#include +#include +#include +#include + +#include + +#include + +namespace osgProducer { + +class CameraGroup; +class RenderSurface; + +/** + \class Camera + \brief A Camera provides a programming interface for 3D + graphics applications by means of an abstract camera analogy + + The Camera contains a Lens class and has a RenderSurface. Methods + are provided to give the programmer control over the OpenGL PROJECTION + matrix throught the Lens and over the initial MODELVIEW matrix through + the camera's position and attitude. + + The programmer must provide a class derived from Camera::SceneHandler + to prepare and render the scene. The Camera does not provide direct + control over rendering itself. +*/ + + + +class Camera : public osg::Referenced +{ + + public : + /** + \class SceneHandler + \brief A Scene Handler handles the preparation and rendering + of a scene for Camera + */ + + /** + \class Lens + \brief A Lens provides control over the PROJECTION matrix. + + It is entirely contained within the Camera class. A Lens may + be of type Perspective or Orthographic and set with one of the + setFrustum, setProjection() or setOrtho(). The Lens type is + implied by the method used to set it */ + class Lens : public osg::Referenced + { + public : + + /** Projection types */ + enum Projection { + Perspective, + Orthographic, + Manual + }; + + Lens(); + + /** setMatrix() exists to allow external projection-management tools + (like elumens' spiclops) to do their magic and still work with producer */ + void setMatrix( const osg::Matrix::value_type matrix[16] ); + + /** Set the Projection type to be of Perspective and provide + the following parameters to set the Projection matrix. + hfov - Horizontal Field of View in degrees + vfov - Vertical Field of View in degrees + nearClip - Distance from the viewer to the near plane of the + viewing frustum. + farClip - Distance from the viewer to the far plane of the + viewing frustum. + xshear- Assymetrical shear in viewing frustum in the horizontal + direction. Value given in normalized device coordinates + (see setShear() below). + yshear- Assymetrical shear in viewing frustum in the vertical + direction. Value given in normalized device coordinates + (see setShear() below). + */ + void setPerspective( double hfov, double vfov, + double nearClip, double farClip ); + + /** Set the Projection type to be of Perspective and provide + the dimensions of the left, right, bottom, top, nearClip and farClip + extents of the viewing frustum as indicated. + xshear- Assymetrical shear in viewing frustum in the horizontal + direction. Value given in normalized device coordinates + (see setShear() below). + yshear- Assymetrical shear in viewing frustum in the vertical + direction. Value given in normalized device coordinates + (see setShear() below). + */ + void setFrustum( double left, double right, + double bottom, double top, + double nearClip, double farClip ); + + /** Set the Projection type to be of Orthographic and provide + the left, right, bottom dimensions of the 2D rectangle*/ + void setOrtho( double left, double right, + double bottom, double top, + double nearClip, double farClip ); + + /** convertToOrtho() converts the current perspective view to an + orthographic view with dimensions that conserve the scale of the + objects at distance d. + convertToPerspective() converts the current orthographic view + to a perspective view with parameters that conserve the scale of + objects at distance d. */ + bool convertToOrtho( float d); + bool convertToPerspective( float d); + + /** apply the lens. This generates a projection matrix for OpenGL */ + void apply(float xshear=0.0f, float yshear=0.0); + void generateMatrix( float xshear, float yshear, osg::Matrix::value_type matrix[16] ); + Projection getProjectionType() const { return _projection; } + void getParams( double &left, double &right, double &bottom, double &top, + double &nearClip, double &farClip ); //, double &xshear, double &yshear ); + + float getHorizontalFov() const { return osg::RadiansToDegrees(_hfov); } + float getVerticalFov() const { return osg::RadiansToDegrees(_vfov); } + void setAutoAspect(bool ar) { _auto_aspect = ar; } + bool getAutoAspect() const { return _auto_aspect; } + void setAspectRatio( double aspectRatio ); + double getAspectRatio() { return _aspect_ratio; } + + + protected: + ~Lens(){} + + /* Internal convenience methods */ + bool getFrustum( double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar ) const; + bool getOrtho( double& left, double& right, + double& bottom, double& top, + double& zNear, double& zFar ) const; + + + private : + + double _ortho_left, _ortho_right, _ortho_bottom, _ortho_top; + double _left, _right, _bottom, _top, _nearClip, _farClip; + Projection _projection; + double _aspect_ratio; + bool _auto_aspect; + float _hfov, _vfov; + osg::Matrix::value_type _matrix[16]; + + private : + void _updateFOV( void ); + }; + + struct Offset { + enum MultiplyMethod { + PreMultiply, + PostMultiply + }; + double _xshear; + double _yshear; + osg::Matrix::value_type _matrix[16]; + MultiplyMethod _multiplyMethod; + Offset(): + _xshear(0.0), + _yshear(0.0), + _multiplyMethod(PreMultiply) {} + }; + + + public : + Camera( void ); + + void setRenderSurface( RenderSurface *rs ) { _rs = rs; } + RenderSurface *getRenderSurface() { return _rs.get(); } + const RenderSurface *getRenderSurface() const { return _rs.get(); } + + void setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height, bool resize=true ) + { _rs->setWindowRectangle(x,y,width,height, resize); } + + void setLens( Lens *lens ) + { + if( _lens.get() != lens ) + _lens = lens; + } + + Lens *getLens() { return _lens.get(); } + const Lens *getLens() const { return _lens.get(); } + + ////////////////////////////////////////////////////////////////////////////////////// + /** Convenience method for setting the Lens Perspective. + See Camera::Lens::setPerspective(). */ + void setLensPerspective( double hfov, double vfov, + double nearClip, double farClip, + double xshear=0, double yshear=0 ) + { + _offset._xshear = xshear; + _offset._yshear = yshear; + _lens->setPerspective(hfov,vfov,nearClip,farClip); + } + + /** Convenience method for setting the Lens Frustum. + See Camera::Lens::setFrustum(). */ + void setLensFrustum( double left, double right, + double bottom, double top, + double nearClip, double farClip, + double xshear=0, double yshear=0 ) + { + _offset._xshear = xshear; + _offset._yshear = yshear; + _lens->setFrustum(left,right,bottom,top,nearClip, farClip); + } + + /** Convenience method for setting the lens Orthographic projection. + See Camera::Lens::setOrtho() */ + void setLensOrtho( double left, double right, + double bottom, double top, + double nearClip, double farClip , + double xshear=0, double yshear=0 ) + { + _offset._xshear = xshear; + _offset._yshear = yshear; + _lens->setOrtho( left, right, bottom, top, nearClip, farClip); + } + + /** Convenience method for setting the lens shear. See Camera::Lens::setShear()*/ + void setLensShear( double xshear, double yshear ) + { + _offset._xshear = xshear; + _offset._yshear = yshear; + } + + /** Convenience method for getting the lens shear. See Camera::Lens::getShear() */ + void getLensShear( double &xshear, double &yshear ) + { + xshear = _offset._xshear; + yshear = _offset._yshear; + } + + /** Convenience method for converting the Perpective lens to an + Orthographic lens. see Camera::lens:convertToOrtho() */ + bool convertLensToOrtho( float d) { return _lens->convertToOrtho(d); } + + /** Convenience method for converting the Orthographic lens to an + Perspective lens. see Camera::lens:convertToPerspective() */ + bool convertLensToPerspective( float d) { return _lens->convertToPerspective(d); } + + /** Convenience method for getting the lens projection type. + See Camera::Lens::setAspectRatio() */ + Lens::Projection getLensProjectionType() { return _lens->getProjectionType(); } + + /** Convenience method for applying the lens. See Camera::Lens::apply() */ + void applyLens() { _lens->apply(_offset._xshear, _offset._yshear); } + + /** Convenience method for getting the Lens parameters. + See Camera::Lens::apply() */ + void getLensParams( double &left, double &right, double &bottom, double &top, + double &nearClip, double &farClip, double &xshear, double &yshear ) + { + _lens->getParams(left,right,bottom,top,nearClip,farClip ); + xshear = _offset._xshear; + yshear = _offset._yshear; + } + + /** Convenience method for getting the Lens Horizontal field of view. + See Camera::Lens::getHorizontalFov() */ + float getLensHorizontalFov() { return _lens->getHorizontalFov(); } + + /** Convenience method for getting the Lens Horizontal field of view. + See Camera::Lens::getVerticalFov() */ + float getLensVerticalFov() { return _lens->getVerticalFov(); } + + /** Convenience method for setting the Lens ProjectionMatrix. + See Camera::Lens::setMatrix() */ + // DEPRECATE + //void setLensMatrix( float mat[16] ) { _lens->setMatrix(mat); } + + /** Convenience method for getting the Lens ProjectionMatrix. + See Camera::Lens::getMatrix() */ + void getLensMatrix(osg::Matrix::value_type matrix[16] ) + { + _lens->generateMatrix(_offset._xshear, _offset._yshear, matrix ); + } + + /** Convenience method for setting AutoAspect on the lens. + See Camera::Lens::setAutoAspect() */ + void setLensAutoAspect(bool ar) { _lens->setAutoAspect(ar); } + + /** Convenience method for getting AutoAspect on the lens. + See Camera::Lens::getAutoAspect() */ + bool getLensAutoAspect() { return _lens->getAutoAspect(); } + + /** Convenience method for setting the lens Aspect Ratio. + See Camera::Lens::setAspectRatio() */ + void setLensAspectRatio( double aspectRatio ) { _lens->setAspectRatio(aspectRatio); } + double getLensAspectRatio() { return _lens->getAspectRatio(); } + + ////////////////////////////////////////////////////////////////////////////////////// + + void setProjectionRectangle( const float left, const float right, + const float bottom, const float top ); + + void getProjectionRectangle( float &left, float &right, + float &bottom, float &top ) const; + + void setProjectionRectangle( int x, int y, unsigned int width, unsigned int height ); + void getProjectionRectangle( int &x, int &y, unsigned int &width, unsigned int &height ) const ; + + osg::Matrix::value_type *getProjectionMatrix () + { + _lens->generateMatrix(_offset._xshear, _offset._yshear, _projectionMatrix ); + return _projectionMatrix; + } + + void setViewByLookat( float eyex, float eyey, float eyez, + float centerx, float centery, float centerz, + float upx, float upy, float upz ); + void setViewByLookat( const osg::Vec3 &eye, const osg::Vec3 ¢er, const osg::Vec3 &up ); + void setViewByMatrix( const osg::Matrix &mat ); + void setFocalDistance( double focal_distance ) { _focal_distance = focal_distance; } + const osg::Matrix::value_type *getViewMatrix( void ) const; + const osg::Matrix::value_type *getPositionAndAttitudeMatrix( void ) const { return _viewMatrix; } + void applyView(); + + void setOffset( const osg::Matrix::value_type matrix[16], + osg::Matrix::value_type _xshear=0.0, + osg::Matrix::value_type _yshear=0.0); + void setOffset( double _xshear, double _yshear); + void setOffsetMultiplyMethod( Offset::MultiplyMethod method ) + { + _offset._multiplyMethod = method; + } + + + void setClearColor( float red, float green, float blue, float alpha); + void getClearColor( float& red, float& green, float& blue, float& alpha); + + void clear( void ); + + void setIndex( unsigned int index ) { _index = index; } + unsigned int getIndex() const { return _index; } + + void setShareLens( bool flag ) { _shareLens = flag; } + bool getShareLens() { return _shareLens; } + void setShareView( bool flag ) { _shareView = flag; } + bool getShareView() { return _shareView; } + + protected : + + virtual ~Camera( void ); + osg::ref_ptr _lens; + osg::ref_ptr _rs; + unsigned int _index; + + private : + bool _initialized; + bool _initialize(void); + + bool _enabled; + + float _projrectLeft, + _projrectRight, + _projrectBottom, + _projrectTop; + + Offset _offset; + osg::Matrix::value_type _projectionMatrix[16]; + osg::Matrix::value_type _viewMatrix[16]; + float _clear_color[4]; + double _focal_distance; + + + friend class CameraGroup; + + bool _shareLens; + bool _shareView; +}; + +} + +#endif + diff --git a/src/osgPlugins/cfg/CameraConfig.cpp b/src/osgPlugins/cfg/CameraConfig.cpp new file mode 100644 index 000000000..8995c3b90 --- /dev/null +++ b/src/osgPlugins/cfg/CameraConfig.cpp @@ -0,0 +1,672 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + + +#if defined(WIN32) && !defined(__CYGWIN__) + #include + #include + #include + // set up for windows so acts just like unix access(). + #define F_OK 4 +#else // unix + #include +#endif + + +#ifdef _X11_IMPLEMENTATION +# include +#endif + +#include +#include +#include "CameraConfig.h" +#include +#include +#include + +using namespace osgProducer; + + +unsigned int CameraConfig::getNumberOfScreens() +{ +#if 0 + return RenderSurface::getNumberOfScreens(); +#else + return 1; +#endif +} + + +////////////////// +CameraConfig::CameraConfig() : + _can_add_visual_attributes(false), + _current_render_surface(NULL), + _can_add_render_surface_attributes(false), + _current_camera(NULL), + _can_add_camera_attributes(false), + _input_area(NULL), + _can_add_input_area_entries(false), + _offset_shearx(0.0f), + _offset_sheary(0.0f), + _postmultiply(false) + +{ + _offset_matrix[0] = 1.0; _offset_matrix[1] = 0.0; _offset_matrix[2] = 0.0; _offset_matrix[3] = 0.0; + _offset_matrix[4] = 0.0; _offset_matrix[5] = 1.0; _offset_matrix[6] = 0.0; _offset_matrix[7] = 0.0; + _offset_matrix[8] = 0.0; _offset_matrix[9] = 0.0; _offset_matrix[10] = 1.0; _offset_matrix[11] = 0.0; + _offset_matrix[12] = 0.0; _offset_matrix[13] = 0.0; _offset_matrix[14] = 0.0; _offset_matrix[15] = 1.0; + + _threadModelDirective = CameraGroup::getDefaultThreadModel(); + +} + + +void CameraConfig::beginVisual( void ) +{ + _current_visual_chooser = new VisualChooser; + _can_add_visual_attributes = true; +} + +void CameraConfig::beginVisual( const char * name ) +{ + std::pair::iterator,bool> res = + _visual_map.insert(std::pair(std::string(name), new VisualChooser)); + _current_visual_chooser = (res.first)->second; + _can_add_visual_attributes = true; +} + +void CameraConfig::setVisualSimpleConfiguration( void ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) + { + std::cerr << "CameraConfig::setVisualSimpleConfiguration() : ERROR no current visual\n"; + return; + } + _current_visual_chooser->setSimpleConfiguration(); +} + +void CameraConfig::setVisualByID( unsigned int id ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) + { + std::cerr << "CameraConfig::setVisualByID(id) : ERROR no current visual\n"; + return; + } + _current_visual_chooser->setVisualID( id ); +} + +void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token, int param ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false ) + { + std::cerr << "CameraConfig::addVisualAttribute(token,param) : ERROR no current visual\n"; + return; + } + _current_visual_chooser->addAttribute( token, param ); +} + +void CameraConfig::addVisualAttribute( VisualChooser::AttributeName token ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) + { + std::cerr << "CameraConfig::addVisualAttribute(token) : ERROR no current visual\n"; + return; + } + _current_visual_chooser->addAttribute( token ); +} + +void CameraConfig::addVisualExtendedAttribute( unsigned int token ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) + { + std::cerr << "CameraConfig::addVisualExtendedAttribute(token) : ERROR no current visual\n"; + return; + } + _current_visual_chooser->addExtendedAttribute( token ); +} + +void CameraConfig::addVisualExtendedAttribute( unsigned int token, int param ) +{ + if( !_current_visual_chooser.valid() || _can_add_visual_attributes == false) + { + std::cerr << "CameraConfig::addVisualExtendedAttribute(token, param) : ERROR no current visual\n"; + return; + } + _current_visual_chooser->addExtendedAttribute( token, param ); +} + +void CameraConfig::endVisual( void ) +{ + _can_add_visual_attributes = false; +} + +VisualChooser *CameraConfig::findVisual( const char *name ) +{ + std::map::iterator p; + p = _visual_map.find( std::string(name) ); + if( p == _visual_map.end() ) + return NULL; + else + return (*p).second; +} + +void CameraConfig::beginRenderSurface( const char *name ) +{ + std::pair >::iterator,bool> res = + _render_surface_map.insert(std::pair >( + std::string(name), + new RenderSurface)); + _current_render_surface = (res.first)->second.get(); + _current_render_surface->setWindowName( std::string(name) ); + _can_add_render_surface_attributes = true; +} + +void CameraConfig::setRenderSurfaceVisualChooser( const char *name ) +{ + VisualChooser *vc = findVisual( name ); + if( vc != NULL && _current_render_surface != NULL ) + _current_render_surface->setVisualChooser( vc ); +} + +void CameraConfig::setRenderSurfaceVisualChooser( void ) +{ + if( _current_render_surface != NULL && _current_visual_chooser.valid() ) + _current_render_surface->setVisualChooser( _current_visual_chooser.get() ); +} + +void CameraConfig::setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setWindowRectangle( x, y, width, height ); +} + +void CameraConfig::setRenderSurfaceCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setCustomFullScreenRectangle( x, y, width, height ); +} + +void CameraConfig::setRenderSurfaceOverrideRedirect( bool flag ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->useOverrideRedirect( flag ); +} + +void CameraConfig::setRenderSurfaceHostName( const std::string &name ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setHostName( name ); +} + +void CameraConfig::setRenderSurfaceDisplayNum( int n ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setDisplayNum( n ); +} + +void CameraConfig::setRenderSurfaceScreen( int n ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setScreenNum( n ); +} + +void CameraConfig::setRenderSurfaceBorder( bool flag ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->useBorder( flag ); +} + +void CameraConfig::setRenderSurfaceDrawableType( RenderSurface::DrawableType drawableType ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setDrawableType( drawableType ); +} + +void CameraConfig::setRenderSurfaceRenderToTextureMode( RenderSurface::RenderToTextureMode rttMode ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setRenderToTextureMode( rttMode ); +} + +void CameraConfig::setRenderSurfaceReadDrawable( const char *name ) +{ + if( _current_render_surface != NULL ) + { + osgProducer::RenderSurface *readDrawable = findRenderSurface( name ); + if( readDrawable == NULL ) + { + std::cerr << "setRenderSurfaceReadDrawable(): No Render Surface by name of \"" << name << "\" was found!\n"; + return; + } + _current_render_surface->setReadDrawable( readDrawable ); + } +} + +void CameraConfig::setRenderSurfaceInputRectangle( float x0, float x1, float y0, float y1 ) +{ + if( _current_render_surface != NULL ) + _current_render_surface->setInputRectangle( RenderSurface::InputRectangle(x0,x1,y0,y1) ); +} + +void CameraConfig::endRenderSurface( void ) +{ + _can_add_render_surface_attributes = false; +} + +RenderSurface *CameraConfig::findRenderSurface( const char *name ) +{ + std::map >::iterator p; + p = _render_surface_map.find( std::string(name) ); + if( p == _render_surface_map.end() ) + return NULL; + else + return (*p).second.get(); +} + +unsigned int CameraConfig::getNumberOfRenderSurfaces() +{ + return _render_surface_map.size(); +} + +RenderSurface *CameraConfig::getRenderSurface( unsigned int index ) +{ + if( index >= _render_surface_map.size() ) + return NULL; + std::map >::iterator p; + + unsigned int i = 0; + for( p = _render_surface_map.begin(); p != _render_surface_map.end(); p++ ) + if( i++ == index ) + break; + if( p == _render_surface_map.end() ) + return NULL; + return (p->second.get()); +} + +void CameraConfig::addCamera( std::string name, Camera *camera ) +{ + std::pair >::iterator,bool> res = + _camera_map.insert(std::pair >(name, camera)); + _current_camera = (res.first)->second.get(); + _can_add_camera_attributes = true; + + RenderSurface *rs = camera->getRenderSurface(); + if( rs->getWindowName() == osgProducer::RenderSurface::defaultWindowName ) + { + char name[80]; + sprintf( name, "%s (%02d)", osgProducer::RenderSurface::defaultWindowName.c_str(), (int)_render_surface_map.size() ); + rs->setWindowName( name ); + } + _render_surface_map.insert(std::pair >( rs->getWindowName(), rs )); +} + + +void CameraConfig::beginCamera( std::string name ) +{ + Camera *camera = new Camera; + std::pair >::iterator,bool> res = + _camera_map.insert(std::pair >(name, camera)); + _current_camera = (res.first)->second.get(); + _can_add_camera_attributes = true; +} + +void CameraConfig::setCameraRenderSurface( const char *name ) +{ + RenderSurface *rs = findRenderSurface( name ); + if( rs == NULL ) + { + std::cerr << "setCameraRenderSurface(): No Render Surface by name of \"" << name << "\" was found!\n"; + return; + } + + if( rs != NULL && _current_camera != NULL ) + _current_camera->setRenderSurface( rs ); + +} + +void CameraConfig::setCameraRenderSurface( void ) +{ + + if( _current_camera != NULL && _current_render_surface != NULL ) + _current_camera->setRenderSurface( _current_render_surface.get() ); + +} + +void CameraConfig::setCameraProjectionRectangle( float x0, float x1, float y0, float y1 ) +{ + if( _current_camera != NULL ) + _current_camera->setProjectionRectangle( x0, x1, y0, y1 ); +} + +void CameraConfig::setCameraProjectionRectangle( int x0, int x1, int y0, int y1 ) +{ + if( _current_camera != NULL ) + _current_camera->setProjectionRectangle( x0, x1, y0, y1 ); +} + +void CameraConfig::setCameraOrtho( float left, float right, float bottom, float top, float nearClip, float farClip, + float xshear, float yshear ) +{ + if( _current_camera != NULL ) + _current_camera->setLensOrtho( left, right, bottom, top, nearClip, farClip, xshear, yshear ); +} + +void CameraConfig::setCameraPerspective( float hfov, float vfov, float nearClip, float farClip, + float xshear, float yshear ) +{ + if( _current_camera != 0 ) + _current_camera->setLensPerspective( hfov, vfov, nearClip, farClip, xshear, yshear ); +} + +void CameraConfig::setCameraFrustum( float left, float right, float bottom, float top, float nearClip, float farClip, + float xshear, float yshear ) +{ + if( _current_camera != 0 ) + _current_camera->setLensFrustum( left, right, bottom, top, nearClip, farClip, xshear, yshear ); +} + +void CameraConfig::setCameraLensShear( osg::Matrix::value_type xshear, osg::Matrix::value_type yshear ) +{ + if( _current_camera != NULL ) + _current_camera->setLensShear(xshear,yshear); +} + +void CameraConfig::setCameraShareLens( bool shared ) +{ + if( _current_camera != NULL ) + _current_camera->setShareLens( shared ); +} + +void CameraConfig::setCameraShareView( bool shared ) +{ + if( _current_camera != NULL ) + _current_camera->setShareView( shared ); +} + +void CameraConfig::setCameraClearColor( float r, float g, float b, float a ) +{ + if( _current_camera != NULL ) + _current_camera->setClearColor( r, g, b, a ); +} + +void CameraConfig::beginCameraOffset() +{ + osg::Matrix::value_type id[] = { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + memcpy( _offset_matrix, id, sizeof(osg::Matrix::value_type[16])); + _offset_shearx = _offset_sheary = 0.0; +} + +void CameraConfig::shearCameraOffset( osg::Matrix::value_type shearx, osg::Matrix::value_type sheary ) +{ + _offset_shearx = shearx; + _offset_sheary = sheary; +} + +void CameraConfig::setCameraOffsetMultiplyMethod( Camera::Offset::MultiplyMethod method ) +{ + if( _current_camera != NULL ) + _current_camera->setOffsetMultiplyMethod(method); +} + + +void CameraConfig::endCameraOffset() +{ + if( _current_camera != NULL ) + _current_camera->setOffset( _offset_matrix, _offset_shearx, _offset_sheary); +} + +void CameraConfig::endCamera( void ) +{ + _can_add_camera_attributes = false; +} + +Camera *CameraConfig::findCamera( const char *name ) +{ + std::map >::iterator p; + p = _camera_map.find( std::string(name) ); + if( p == _camera_map.end() ) + return NULL; + else + return (*p).second.get(); +} + +unsigned int CameraConfig::getNumberOfCameras() const +{ + return _camera_map.size(); +} + +const Camera *CameraConfig::getCamera( unsigned int n ) const +{ + if( n >= _camera_map.size() ) + return NULL; + + unsigned int i; + std::map >::const_iterator p; + for( i = 0, p = _camera_map.begin(); p != _camera_map.end(); p++ ) + if( i++ == n ) + break; + if( p == _camera_map.end() ) + return NULL; + return p->second.get(); +} + +Camera *CameraConfig::getCamera( unsigned int n ) +{ + if( n >= _camera_map.size() ) + return NULL; + + unsigned int i; + std::map >::iterator p; + for( i = 0, p = _camera_map.begin(); p != _camera_map.end(); p++ ) + if( i++ == n ) + break; + if( p == _camera_map.end() ) + return NULL; + return p->second.get(); +} + +void CameraConfig::beginInputArea() +{ + _input_area = new InputArea; + _can_add_input_area_entries = true; +} + +void CameraConfig::addInputAreaEntry( char *renderSurfaceName ) +{ + osgProducer::RenderSurface *rs = findRenderSurface( renderSurfaceName ); + if( rs == NULL ) + { + std::cerr << "setInputAreaEntry(): No Render Surface by name of \"" << renderSurfaceName << "\" was found!\n"; + return; + } + if( _input_area != NULL && _can_add_input_area_entries == true ) + _input_area->addRenderSurface( rs ); +} + +void CameraConfig::endInputArea() +{ + _can_add_input_area_entries = false; +} + +void CameraConfig::setInputArea(InputArea *ia) +{ + _input_area=ia; +} + +InputArea *CameraConfig::getInputArea() +{ + return _input_area.get(); +} + +const InputArea *CameraConfig::getInputArea() const +{ + return _input_area.get(); +} + +#if 0 +void CameraConfig::realize( void ) +{ + std::map >::iterator p; + for( p = _render_surface_map.begin(); p != _render_surface_map.end(); p++ ) + { + ((*p).second)->realize(); + } +} +#endif + +std::string findFile( std::string ); + +void CameraConfig::addStereoSystemCommand( int screen, std::string stereoCmd, std::string monoCmd ) +{ + _stereoSystemCommands.push_back(StereoSystemCommand( screen, stereoCmd, monoCmd )); +} + +const std::vector &CameraConfig::getStereoSystemCommands() +{ + return _stereoSystemCommands; +} + + +CameraConfig::~CameraConfig() +{ +} + +////////////////////// + +void CameraConfig::rotateCameraOffset( osg::Matrix::value_type deg, osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ) +{ + osg::Matrix m; + m.invert(osg::Matrix::rotate( osg::DegreesToRadians(deg), x,y,z)); + m = m * osg::Matrix(_offset_matrix); + memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] )); +} + +void CameraConfig::translateCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ) +{ + osg::Matrix m; + m.invert(osg::Matrix::translate( x,y,z)); + m = m * osg::Matrix(_offset_matrix); + memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] )); +} + +void CameraConfig::scaleCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ) +{ + osg::Matrix m = osg::Matrix::scale( x,y,z) * osg::Matrix(_offset_matrix); + memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] )); +} + +bool CameraConfig::fileExists(const std::string& filename) +{ + return access( filename.c_str(), F_OK ) == 0; +} + +// Order of precedence: +// +std::string CameraConfig::findFile( std::string filename ) +{ + if (filename.empty()) return filename; + + std::string path; + // Check env var + char *ptr = getenv( "PRODUCER_CONFIG_FILE_PATH"); + if( ptr != NULL ) + { + path = std::string(ptr) + '/' + filename; + if( fileExists(path)) + return path; + } + + // Check standard location(s) + //path.clear(); + path = std::string( "/usr/local/share/Producer/Config/") + filename; + if( fileExists(path) ) + return path; + + //path.clear(); + path = std::string( "/usr/share/Producer/Config/") + filename; + if( fileExists(path) ) + return path; + + // Check local directory + if(fileExists(filename)) + return filename; + + // Fail + return std::string(); +} + +bool CameraConfig::defaultConfig() +{ + if( getNumberOfCameras() != 0 ) return false; + + char *env = getenv( "PRODUCER_CAMERA_CONFIG_FILE" ); + + // Backwards compatibility + if( env == NULL ) + env = getenv( "PRODUCER_CONFIG_FILE" ); + + if( env != NULL ) + { + std::string file = findFile(env); + return parseFile( file.c_str() ); + } + + unsigned int numScreens = getNumberOfScreens(); + if( numScreens == 0 ) + return false; + + float xshear = float(numScreens-1); + float yshear = 0.0; + float input_xMin = -1.0f; + float input_yMin = -1.0f; + float input_width = 2.0f/float(numScreens); + float input_height = 2.0f; + + // use an InputArea if there is more than one screen. + InputArea *ia = (numScreens>1) ? new InputArea : 0; + setInputArea(ia); + + for( unsigned int i = 0; i < numScreens; i++ ) + { + std::string name = "Screen" + i; + std::pair >::iterator,bool> res = + _camera_map.insert(std::pair >(name, new Camera)); + + ((res.first)->second)->getRenderSurface()->setScreenNum( i ); + ((res.first)->second)->setLensShear( xshear, yshear ); + + RenderSurface *rs = ((res.first)->second)->getRenderSurface(); + rs->setWindowName( name ); + if (ia) + { + rs->setInputRectangle( RenderSurface::InputRectangle(input_xMin, input_xMin+input_width, input_yMin, input_yMin+input_height) ); + input_xMin += input_width; + ia->addRenderSurface(rs); + } + + _render_surface_map.insert(std::pair >( rs->getWindowName(), rs )); + + xshear -= 2.0; + } + + _threadModelDirective = CameraGroup::getDefaultThreadModel(); + + return true; +} + diff --git a/src/osgPlugins/cfg/CameraConfig.h b/src/osgPlugins/cfg/CameraConfig.h new file mode 100644 index 000000000..2267d0477 --- /dev/null +++ b/src/osgPlugins/cfg/CameraConfig.h @@ -0,0 +1,246 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#ifndef PRODUCER_CAMERA_CONFIG +#define PRODUCER_CAMERA_CONFIG + +#include + +#include "Camera.h" +#include "RenderSurface.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +//#undef SUPPORT_CPP + +namespace osgProducer { + +#define notImplemented {std::cout << __FILE__ << " " << __LINE__ << std::endl;} + struct CameraGroup : public osg::Referenced { + enum ThreadModel { + SingleThreaded, + ThreadPerRenderSurface, + ThreadPerCamera, + }; + static ThreadModel getDefaultThreadModel() { return SingleThreaded;} + }; + + + struct InputArea : public osg::Referenced { + void addRenderSurface(RenderSurface* s) { _rs.push_back(s); } + std::vector > _rs; + }; + +#undef notImplemented + + +class CameraConfig : public osg::Referenced +{ + public : + CameraConfig(); + + void beginVisual( void ); + + void beginVisual( const char * name ); + + void setVisualSimpleConfiguration( void ); + + void setVisualByID( unsigned int id ); + + void addVisualAttribute( VisualChooser::AttributeName token, int param ); + + void addVisualAttribute( VisualChooser::AttributeName token ); + + void addVisualExtendedAttribute( unsigned int token ); + + void addVisualExtendedAttribute( unsigned int token, int param ); + + void endVisual( void ); + + VisualChooser *findVisual( const char *name ); + + bool parseFile( const std::string &file ); + + void beginRenderSurface( const char *name ); + + void setRenderSurfaceVisualChooser( const char *name ); + + void setRenderSurfaceVisualChooser( void ); + + void setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height ); + + void setRenderSurfaceCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height ); + + void setRenderSurfaceOverrideRedirect( bool flag ); + + void setRenderSurfaceHostName( const std::string &name ); + + void setRenderSurfaceDisplayNum( int n ); + + void setRenderSurfaceScreen( int n ); + + void setRenderSurfaceBorder( bool flag ); + + void setRenderSurfaceDrawableType( RenderSurface::DrawableType drawableType ); + + void setRenderSurfaceRenderToTextureMode( RenderSurface::RenderToTextureMode rttMode ); + + void setRenderSurfaceReadDrawable( const char *name ); + + void setRenderSurfaceInputRectangle( float x0, float x1, float y0, float y1 ); + + void endRenderSurface( void ); + + RenderSurface *findRenderSurface( const char *name ); + + unsigned int getNumberOfRenderSurfaces(); + + RenderSurface *getRenderSurface( unsigned int index ); + + void addCamera( std::string name, Camera *camera ); + + void beginCamera( std::string name ); + + void setCameraRenderSurface( const char *name ); + + void setCameraRenderSurface( void ); + + void setCameraProjectionRectangle( float x0, float x1, float y0, float y1 ); + + void setCameraProjectionRectangle( int x0, int x1, int y0, int y1 ); + + void setCameraOrtho( float left, float right, float bottom, float top, float nearClip, float farClip, + float xshear=0.0, float yshear=0.0 ); + + void setCameraPerspective( float hfov, float vfov, float nearClip, float farClip, + float xshear=0.0, float yshear=0.0 ); + + void setCameraFrustum( float left, float right, float bottom, float top, float nearClip, float farClip, + float xshear=0.0, float yshear=0.0 ); + + void setCameraLensShear( osg::Matrix::value_type xshear, osg::Matrix::value_type yshear ); + + void setCameraShareLens( bool shared ); + + void setCameraShareView( bool shared ); + + void setCameraClearColor( float r, float g, float b, float a ); + + void beginCameraOffset(); + + void rotateCameraOffset( osg::Matrix::value_type deg, osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); + + void translateCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); + + void scaleCameraOffset( osg::Matrix::value_type x, osg::Matrix::value_type y, osg::Matrix::value_type z ); + + void shearCameraOffset( osg::Matrix::value_type shearx, osg::Matrix::value_type sheary ); + + void setCameraOffsetMultiplyMethod( Camera::Offset::MultiplyMethod method ); + + void endCameraOffset(); + + void endCamera( void ); + + Camera *findCamera( const char *name ); + + unsigned int getNumberOfCameras() const; + + const Camera *getCamera( unsigned int n ) const; + + Camera *getCamera( unsigned int n ); + + void beginInputArea(); + + void addInputAreaEntry( char *renderSurfaceName ); + + void endInputArea() ; + + void setInputArea(InputArea *ia); + + InputArea *getInputArea(); + + const InputArea *getInputArea() const; + + void realize( void ); + + bool defaultConfig(); + + struct StereoSystemCommand + { + int _screen; + std::string _setStereoCommand; + std::string _restoreMonoCommand; + + StereoSystemCommand(int screen, std::string setStereoCommand, std::string restoreMonoCommand ): + _screen(screen), + _setStereoCommand(setStereoCommand), + _restoreMonoCommand(restoreMonoCommand) {} + }; + + static std::string findFile( std::string ); + + void addStereoSystemCommand( int screen, std::string stereoCmd, std::string monoCmd ); + + const std::vector &getStereoSystemCommands(); + + void setThreadModelDirective( CameraGroup::ThreadModel directive ) { _threadModelDirective = directive; } + CameraGroup::ThreadModel getThreadModelDirective() { return _threadModelDirective; } + + protected: + + virtual ~CameraConfig(); + + private : + + std::map _visual_map; + osg::ref_ptr< VisualChooser >_current_visual_chooser; + bool _can_add_visual_attributes; + + std::map > _render_surface_map; + osg::ref_ptr _current_render_surface; + bool _can_add_render_surface_attributes; + + std::map > _camera_map; + osg::ref_ptr _current_camera; + bool _can_add_camera_attributes; + + osg::ref_ptr< InputArea > _input_area; + bool _can_add_input_area_entries; + + unsigned int getNumberOfScreens(); + + static bool fileExists(const std::string& ); + + osg::Matrix::value_type _offset_matrix[16]; + osg::Matrix::value_type _offset_shearx, _offset_sheary; + + std::vector _stereoSystemCommands; + + bool _postmultiply; + + CameraGroup::ThreadModel _threadModelDirective; +}; + +}; + + +#endif diff --git a/src/osgPlugins/cfg/ConfigLexer.cpp b/src/osgPlugins/cfg/ConfigLexer.cpp new file mode 100644 index 000000000..f22779e31 --- /dev/null +++ b/src/osgPlugins/cfg/ConfigLexer.cpp @@ -0,0 +1,2170 @@ +#line 2 "ConfigLexer.cpp" +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + * $Header: /cvs/Producer/Producer/src/ConfigLexer.cpp,v 1.23 2006/09/06 22:56:30 don Exp $ + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include +#ifndef WIN32 +#include +#endif + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include +#include +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 16384 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + std::istream* yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + + +#define yywrap() 1 +#define YY_SKIP_YYWRAP +typedef unsigned char YY_CHAR; +#define yytext_ptr yytext +#define YY_INTERACTIVE + +#include "FlexLexer.h" + + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 83 +#define YY_END_OF_BUFFER 84 +static yyconst short int yy_accept[588] = + { 0, + 0, 0, 84, 83, 3, 2, 1, 6, 7, 83, + 79, 83, 78, 78, 8, 9, 83, 83, 83, 83, + 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, + 83, 83, 83, 83, 83, 83, 83, 83, 4, 5, + 79, 78, 78, 79, 79, 1, 0, 80, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 76, 0, 0, 0, + + 0, 0, 81, 77, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 82, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 13, 0, 0, 57, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 0, 63, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, + 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 64, 59, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 60, 0, 0, 16, 36, + 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 35, 0, 55, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 46, 0, + 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, + 18, 45, 47, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, + 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, + + 0, 0, 0, 0, 67, 39, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 10, 53, 54, + 0, 0, 0, 0, 61, 0, 0, 0, 0, 0, + 0, 21, 0, 0, 0, 58, 0, 22, 0, 0, + 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, + 0, 0, 0, 0, 17, 12, 48, 0, 0, 0, + 0, 0, 0, 56, 0, 65, 0, 0, 0, 0, + 0, 0, 0, 0, 71, 0, 0, 42, 0, 0, + 0, 0, 0, 0, 15, 40, 0, 0, 41, 66, + + 0, 43, 0, 0, 0, 23, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 24, 0, 38, 0, 51, 0, 29, 72, 0, 0, + 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, + 73, 0, 32, 27, 25, 0, 70, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 50, 44, 0, 0, 0, 68, 0, 0, + 0, 0, 74, 0, 0, 69, 0 + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 5, 6, 1, 1, 1, 1, 1, + 1, 1, 7, 8, 9, 10, 11, 12, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 14, 15, 1, + 1, 1, 1, 1, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 1, 1, 25, 26, 27, 28, 29, + 1, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 1, 1, 1, 1, 39, 1, 40, 41, 42, 43, + + 44, 45, 46, 47, 48, 49, 1, 50, 51, 52, + 53, 54, 1, 55, 56, 57, 58, 59, 60, 61, + 62, 1, 63, 1, 64, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[65] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 2, 1, 1, 2, 2, 2, 2, 2, + 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 + } ; + +static yyconst short int yy_base[589] = + { 0, + 0, 0, 667, 668, 668, 668, 668, 668, 668, 55, + 57, 655, 61, 67, 668, 668, 58, 60, 46, 69, + 610, 634, 610, 610, 46, 617, 71, 55, 87, 102, + 48, 612, 77, 619, 605, 69, 602, 612, 668, 668, + 115, 135, 141, 145, 668, 668, 126, 668, 0, 637, + 625, 617, 619, 630, 595, 598, 604, 591, 617, 612, + 588, 603, 584, 621, 584, 585, 604, 585, 579, 614, + 668, 589, 576, 588, 598, 575, 573, 31, 609, 610, + 594, 80, 568, 598, 603, 60, 565, 97, 569, 576, + 564, 578, 561, 589, 563, 564, 668, 568, 554, 555, + + 160, 130, 151, 0, 577, 586, 569, 587, 585, 562, + 560, 563, 545, 569, 583, 545, 538, 541, 576, 538, + 536, 573, 536, 544, 534, 542, 533, 566, 530, 528, + 558, 534, 543, 565, 541, 536, 535, 537, 547, 141, + 525, 530, 542, 517, 531, 524, 514, 524, 515, 508, + 546, 521, 507, 518, 162, 164, 535, 544, 542, 519, + 537, 512, 500, 499, 500, 529, 526, 500, 509, 491, + 520, 494, 488, 519, 668, 490, 498, 488, 485, 518, + 484, 511, 478, 491, 503, 668, 151, 514, 488, 474, + 505, 511, 508, 483, 482, 477, 480, 468, 472, 477, + + 480, 463, 478, 489, 463, 471, 475, 474, 479, 480, + 480, 454, 468, 489, 455, 466, 484, 463, 461, 443, + 461, 459, 154, 668, 455, 440, 668, 448, 475, 450, + 435, 442, 449, 466, 461, 466, 432, 431, 441, 464, + 459, 454, 668, 429, 429, 157, 668, 435, 425, 434, + 426, 425, 439, 413, 171, 441, 450, 446, 430, 668, + 446, 414, 445, 434, 447, 401, 412, 410, 429, 408, + 403, 413, 668, 668, 413, 425, 412, 403, 395, 394, + 412, 422, 431, 407, 163, 668, 161, 421, 668, 668, + 391, 400, 395, 410, 410, 173, 400, 415, 399, 407, + + 411, 410, 404, 413, 408, 410, 392, 398, 373, 377, + 368, 401, 391, 668, 379, 668, 398, 377, 376, 377, + 374, 378, 359, 358, 366, 365, 392, 391, 394, 349, + 350, 354, 668, 389, 366, 354, 351, 358, 354, 338, + 346, 354, 340, 377, 363, 350, 364, 359, 371, 371, + 351, 368, 367, 362, 332, 331, 333, 344, 360, 348, + 341, 668, 338, 320, 346, 343, 326, 325, 318, 318, + 668, 668, 668, 330, 314, 336, 334, 335, 321, 308, + 303, 307, 305, 317, 304, 314, 668, 320, 314, 332, + 334, 333, 313, 331, 320, 668, 311, 290, 292, 296, + + 325, 323, 281, 322, 668, 301, 296, 302, 279, 283, + 286, 283, 293, 288, 288, 310, 306, 668, 668, 668, + 285, 271, 283, 179, 668, 297, 268, 308, 284, 295, + 290, 668, 289, 299, 264, 668, 286, 668, 296, 261, + 668, 262, 270, 283, 267, 260, 247, 278, 257, 266, + 244, 283, 265, 262, 257, 250, 259, 254, 277, 256, + 256, 263, 254, 268, 668, 668, 668, 249, 260, 245, + 242, 239, 266, 668, 223, 668, 240, 239, 240, 224, + 260, 259, 235, 226, 668, 225, 223, 668, 222, 242, + 248, 240, 232, 214, 668, 668, 218, 212, 668, 668, + + 224, 668, 221, 206, 233, 668, 218, 243, 216, 216, + 212, 233, 218, 231, 234, 209, 208, 207, 193, 668, + 194, 217, 204, 193, 190, 200, 193, 204, 221, 202, + 668, 195, 668, 196, 197, 192, 668, 668, 184, 194, + 178, 188, 211, 668, 210, 177, 171, 175, 200, 174, + 668, 193, 668, 668, 668, 193, 668, 176, 168, 180, + 161, 174, 167, 173, 163, 159, 171, 168, 167, 167, + 163, 150, 668, 668, 150, 165, 164, 668, 161, 146, + 139, 106, 668, 79, 79, 668, 668, 92 + } ; + +static yyconst short int yy_def[589] = + { 0, + 587, 1, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 588, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 588, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 0, 587 + } ; + +static yyconst short int yy_nxt[733] = + { 0, + 4, 5, 6, 7, 8, 7, 4, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 4, + 21, 22, 23, 24, 25, 26, 4, 27, 28, 29, + 30, 31, 4, 32, 33, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 34, 4, 4, 4, 4, 4, + 4, 35, 36, 4, 4, 4, 37, 4, 4, 4, + 4, 38, 39, 40, 41, 67, 42, 43, 44, 44, + 41, 75, 43, 43, 131, 50, 41, 45, 43, 43, + 47, 48, 51, 132, 53, 56, 47, 48, 59, 68, + 52, 70, 54, 104, 91, 57, 60, 71, 76, 141, + + 94, 45, 92, 58, 47, 48, 79, 77, 80, 78, + 47, 48, 55, 98, 142, 72, 61, 84, 81, 136, + 71, 49, 586, 62, 95, 73, 44, 44, 585, 74, + 82, 137, 102, 85, 102, 45, 144, 103, 103, 83, + 145, 103, 103, 86, 41, 87, 43, 43, 88, 89, + 41, 584, 43, 43, 47, 48, 44, 44, 90, 45, + 47, 48, 103, 103, 101, 45, 155, 192, 155, 271, + 193, 156, 156, 156, 156, 156, 156, 235, 47, 48, + 236, 292, 583, 272, 47, 48, 301, 302, 101, 45, + 293, 333, 303, 331, 332, 49, 457, 582, 341, 334, + + 304, 342, 581, 580, 579, 578, 577, 576, 458, 575, + 574, 573, 572, 571, 570, 569, 568, 567, 566, 565, + 564, 563, 562, 561, 560, 559, 558, 557, 556, 555, + 554, 553, 552, 551, 550, 549, 548, 547, 546, 545, + 544, 543, 542, 541, 540, 539, 538, 537, 536, 535, + 534, 533, 532, 531, 530, 529, 528, 527, 526, 525, + 524, 523, 522, 521, 520, 519, 518, 517, 516, 515, + 514, 513, 512, 511, 510, 509, 508, 507, 506, 505, + 504, 503, 502, 501, 500, 499, 498, 497, 496, 495, + 494, 493, 492, 491, 490, 489, 488, 487, 486, 485, + + 484, 483, 482, 481, 480, 479, 478, 477, 476, 475, + 474, 473, 472, 471, 470, 469, 468, 467, 466, 465, + 464, 463, 462, 461, 460, 459, 456, 455, 454, 453, + 452, 451, 450, 449, 448, 447, 446, 445, 444, 443, + 442, 441, 440, 439, 438, 437, 436, 435, 434, 433, + 432, 431, 430, 429, 428, 427, 426, 425, 424, 423, + 422, 421, 420, 419, 418, 417, 416, 415, 414, 413, + 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, + 402, 401, 400, 399, 398, 397, 396, 395, 394, 393, + 392, 391, 390, 389, 388, 387, 386, 385, 384, 383, + + 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, + 372, 371, 370, 369, 368, 367, 366, 365, 364, 363, + 362, 361, 360, 359, 358, 357, 356, 355, 354, 353, + 352, 351, 350, 349, 348, 347, 346, 345, 344, 343, + 340, 339, 338, 337, 336, 335, 330, 329, 328, 327, + 326, 325, 324, 323, 322, 321, 320, 319, 318, 317, + 316, 315, 314, 313, 312, 311, 310, 309, 308, 307, + 306, 305, 300, 299, 298, 297, 296, 295, 294, 291, + 290, 289, 288, 287, 286, 285, 284, 283, 282, 281, + 280, 279, 278, 277, 276, 275, 274, 273, 270, 269, + + 268, 267, 266, 265, 264, 263, 262, 261, 260, 259, + 258, 257, 256, 255, 97, 254, 253, 252, 251, 250, + 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, + 239, 238, 237, 234, 233, 232, 231, 230, 229, 228, + 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, + 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, + 207, 71, 206, 205, 204, 203, 202, 201, 200, 199, + 198, 197, 196, 195, 194, 191, 190, 189, 188, 187, + 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, + 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, + + 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, + 71, 154, 97, 153, 152, 151, 150, 149, 148, 147, + 146, 143, 140, 139, 138, 135, 134, 133, 130, 129, + 128, 127, 126, 125, 97, 124, 123, 122, 121, 120, + 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, + 109, 108, 107, 106, 105, 100, 99, 97, 96, 93, + 69, 66, 65, 64, 63, 46, 587, 3, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587 + } ; + +static yyconst short int yy_chk[733] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 10, 25, 10, 10, 11, 11, + 13, 28, 13, 13, 78, 17, 14, 11, 14, 14, + 13, 13, 17, 78, 18, 19, 14, 14, 20, 25, + 17, 27, 18, 588, 31, 19, 20, 27, 28, 86, + + 33, 11, 31, 19, 13, 13, 29, 28, 29, 28, + 14, 14, 18, 36, 86, 27, 20, 30, 29, 82, + 36, 13, 585, 20, 33, 27, 41, 41, 584, 27, + 29, 82, 47, 30, 47, 41, 88, 47, 47, 29, + 88, 102, 102, 30, 42, 30, 42, 42, 30, 30, + 43, 582, 43, 43, 42, 42, 44, 44, 30, 41, + 43, 43, 103, 103, 44, 44, 101, 140, 101, 223, + 140, 101, 101, 155, 155, 156, 156, 187, 42, 42, + 187, 246, 581, 223, 43, 43, 255, 255, 44, 44, + 246, 287, 255, 285, 285, 42, 424, 580, 296, 287, + + 255, 296, 579, 577, 576, 575, 572, 571, 424, 570, + 569, 568, 567, 566, 565, 564, 563, 562, 561, 560, + 559, 558, 556, 552, 550, 549, 548, 547, 546, 545, + 543, 542, 541, 540, 539, 536, 535, 534, 532, 530, + 529, 528, 527, 526, 525, 524, 523, 522, 521, 519, + 518, 517, 516, 515, 514, 513, 512, 511, 510, 509, + 508, 507, 505, 504, 503, 501, 498, 497, 494, 493, + 492, 491, 490, 489, 487, 486, 484, 483, 482, 481, + 480, 479, 478, 477, 475, 473, 472, 471, 470, 469, + 468, 464, 463, 462, 461, 460, 459, 458, 457, 456, + + 455, 454, 453, 452, 451, 450, 449, 448, 447, 446, + 445, 444, 443, 442, 440, 439, 437, 435, 434, 433, + 431, 430, 429, 428, 427, 426, 423, 422, 421, 417, + 416, 415, 414, 413, 412, 411, 410, 409, 408, 407, + 406, 404, 403, 402, 401, 400, 399, 398, 397, 395, + 394, 393, 392, 391, 390, 389, 388, 386, 385, 384, + 383, 382, 381, 380, 379, 378, 377, 376, 375, 374, + 370, 369, 368, 367, 366, 365, 364, 363, 361, 360, + 359, 358, 357, 356, 355, 354, 353, 352, 351, 350, + 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, + + 339, 338, 337, 336, 335, 334, 332, 331, 330, 329, + 328, 327, 326, 325, 324, 323, 322, 321, 320, 319, + 318, 317, 315, 313, 312, 311, 310, 309, 308, 307, + 306, 305, 304, 303, 302, 301, 300, 299, 298, 297, + 295, 294, 293, 292, 291, 288, 284, 283, 282, 281, + 280, 279, 278, 277, 276, 275, 272, 271, 270, 269, + 268, 267, 266, 265, 264, 263, 262, 261, 259, 258, + 257, 256, 254, 253, 252, 251, 250, 249, 248, 245, + 244, 242, 241, 240, 239, 238, 237, 236, 235, 234, + 233, 232, 231, 230, 229, 228, 226, 225, 222, 221, + + 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, + 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, + 200, 199, 198, 197, 196, 195, 194, 193, 192, 191, + 190, 189, 188, 185, 184, 183, 182, 181, 180, 179, + 178, 177, 176, 174, 173, 172, 171, 170, 169, 168, + 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, + 157, 154, 153, 152, 151, 150, 149, 148, 147, 146, + 145, 144, 143, 142, 141, 139, 138, 137, 136, 135, + 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, + 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, + + 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, + 100, 99, 98, 96, 95, 94, 93, 92, 91, 90, + 89, 87, 85, 84, 83, 81, 80, 79, 77, 76, + 75, 74, 73, 72, 70, 69, 68, 67, 66, 65, + 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, + 54, 53, 52, 51, 50, 38, 37, 35, 34, 32, + 26, 24, 23, 22, 21, 12, 3, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 587 + } ; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +#line 1 ".././ConfigLexer.l" +#define INITIAL 0 +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ +#line 15 ".././ConfigLexer.l" +#include +#include +#include "ConfigParser.h" + +//#define DEBUG +#ifdef DEBUG +#define REPORT printf(" %s\n", yytext); +#else +#define REPORT +#endif +/*%option yyclass="ConfigParser"*/ +#line 705 "ConfigLexer.cpp" + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +#define ECHO LexerOutput( yytext, yyleng ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) LexerError( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yyFlexLexer::yylex() +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 35 ".././ConfigLexer.l" + + +#line 835 "ConfigLexer.cpp" + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = &std::cin; + + if ( ! yyout ) + yyout = &std::cout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 588 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 668 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + +do_action: /* This label is used only to access EOF actions. */ + + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 37 ".././ConfigLexer.l" +{ + #ifdef DEBUG + char buff[128]; + int i = 0; + #endif + + char c; + while( (c = yyinput()) != '\n' ) + { + if( c <= 0 ) + break; + #ifdef DEBUG + buff[i++] = c; + #endif + } + #ifdef DEBUG + buff[i] = 0; + printf( "Single line comment: \"%s\"\n", buff ); + #endif + } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 58 ".././ConfigLexer.l" +{ yylineno++;} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 59 ".././ConfigLexer.l" +{ ; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 60 ".././ConfigLexer.l" +{ REPORT return '{'; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 61 ".././ConfigLexer.l" +{ REPORT return '}'; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 62 ".././ConfigLexer.l" +{ + char c; + int i = 0; + while( (c = yyinput()) != '"' ) + yytext[i++] = c; + yytext[i] = 0; + return PRTOKEN_QUOTED_STRING; + } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 70 ".././ConfigLexer.l" +{ REPORT return ','; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 71 ".././ConfigLexer.l" +{ REPORT return ':'; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 72 ".././ConfigLexer.l" +{ REPORT return ';'; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 73 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SET_SIMPLE; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 74 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_VISUAL_ID; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 75 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_BUFFER_SIZE; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 76 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_LEVEL; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 77 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_RGBA; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 78 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_DOUBLEBUFFER; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 79 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_STEREO; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 80 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_AUX_BUFFERS; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 81 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_RED_SIZE; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 82 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_GREEN_SIZE; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 83 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_BLUE_SIZE; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 84 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ALPHA_SIZE; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 85 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_DEPTH_SIZE; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 86 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_STENCIL_SIZE; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 87 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ACCUM_RED_SIZE; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 88 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ACCUM_GREEN_SIZE; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 89 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ACCUM_BLUE_SIZE; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 90 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ACCUM_ALPHA_SIZE; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 91 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SAMPLES; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 92 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SAMPLE_BUFFERS; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 93 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_VISUAL; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 94 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_RENDER_SURFACE; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 95 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_WINDOW_RECT; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 96 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_WINDOW_RECT; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 97 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_HOSTNAME; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 98 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_DISPLAY; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 99 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SCREEN; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 100 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_BORDER; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 101 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_INPUT_RECT; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 102 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_INPUT_RECT; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 103 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_DRAWABLE_TYPE; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 104 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_PBUFFER_TYPE; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 105 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_WINDOW_TYPE; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 106 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_READ_DRAWABLE; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 107 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SET_RTT_MODE; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 108 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_RTT_MODE_NONE; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 109 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_RTT_MODE_RGB; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 110 ".././ConfigLexer.l" +{ REPORT; return PRTOKEN_RTT_MODE_RGBA; } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 113 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_CAMERA_GROUP; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 114 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_CAMERA; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 115 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_PROJECTION_RECT; } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 116 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_PROJECTION_RECT; } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 118 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_LENS; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 119 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SHARELENS; } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 120 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SHAREVIEW; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 121 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FRUSTUM; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 122 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_PERSPECTIVE; } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 123 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ORTHO; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 124 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_CLEAR_COLOR; } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 126 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_OFFSET; } + YY_BREAK +case 60: +YY_RULE_SETUP +#line 127 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_ROTATE; } + YY_BREAK +case 61: +YY_RULE_SETUP +#line 128 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_TRANSLATE; } + YY_BREAK +case 62: +YY_RULE_SETUP +#line 129 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SCALE; } + YY_BREAK +case 63: +YY_RULE_SETUP +#line 130 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SHEAR; } + YY_BREAK +case 64: +YY_RULE_SETUP +#line 131 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_METHOD; } + YY_BREAK +case 65: +YY_RULE_SETUP +#line 132 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_PREMULTIPLY; } + YY_BREAK +case 66: +YY_RULE_SETUP +#line 133 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_POSTMULTIPLY; } + YY_BREAK +case 67: +YY_RULE_SETUP +#line 135 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_INPUT_AREA; } + YY_BREAK +case 68: +YY_RULE_SETUP +#line 137 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_STEREO_SYSTEM_COMMANDS; } + YY_BREAK +case 69: +YY_RULE_SETUP +#line 139 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE; } + YY_BREAK +case 70: +YY_RULE_SETUP +#line 140 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_OVERRIDE_REDIRECT; } + YY_BREAK +case 71: +YY_RULE_SETUP +#line 142 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_THREAD_MODEL; } + YY_BREAK +case 72: +YY_RULE_SETUP +#line 143 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_SINGLE_THREADED; } + YY_BREAK +case 73: +YY_RULE_SETUP +#line 144 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_THREAD_PER_CAMERA; } + YY_BREAK +case 74: +YY_RULE_SETUP +#line 145 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_THREAD_PER_RENDER_SURFACE; } + YY_BREAK +case 75: +YY_RULE_SETUP +#line 148 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_TRUE; } + YY_BREAK +case 76: +YY_RULE_SETUP +#line 149 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FALSE; } + YY_BREAK +case 77: +YY_RULE_SETUP +#line 151 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_HEX_INTEGER; } + YY_BREAK +case 78: +YY_RULE_SETUP +#line 152 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_INTEGER; } + YY_BREAK +case 79: +YY_RULE_SETUP +#line 154 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FLOAT; } + YY_BREAK +case 80: +YY_RULE_SETUP +#line 155 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FLOAT; } + YY_BREAK +case 81: +YY_RULE_SETUP +#line 156 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FLOAT; } + YY_BREAK +case 82: +YY_RULE_SETUP +#line 157 ".././ConfigLexer.l" +{ REPORT return PRTOKEN_FLOAT; } + YY_BREAK +case 83: +YY_RULE_SETUP +#line 162 ".././ConfigLexer.l" +ECHO; + YY_BREAK +#line 1359 "ConfigLexer.cpp" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + +yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout ) + { + yyin = arg_yyin; + yyout = arg_yyout; + yy_c_buf_p = 0; + yy_init = 1; + yy_start = 0; + yy_flex_debug = 0; + yylineno = 1; // this will only get updated if %option yylineno + + yy_did_buffer_switch_on_eof = 0; + + yy_looking_for_trail_begin = 0; + yy_more_flag = 0; + yy_more_len = 0; + yy_more_offset = yy_prev_more_offset = 0; + + yy_start_stack_ptr = yy_start_stack_depth = 0; + yy_start_stack = 0; + + yy_current_buffer = 0; + +#ifdef YY_USES_REJECT + yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2]; +#else + yy_state_buf = 0; +#endif + } + +yyFlexLexer::~yyFlexLexer() + { + delete yy_state_buf; + yy_delete_buffer( yy_current_buffer ); + } + +void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out ) + { + if ( new_in ) + { + yy_delete_buffer( yy_current_buffer ); + yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); + } + + if ( new_out ) + yyout = new_out; + } + +#ifdef YY_INTERACTIVE +int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) +#else +int yyFlexLexer::LexerInput( char* buf, int max_size ) +#endif + { + if ( yyin->eof() || yyin->fail() ) + return 0; + +#ifdef YY_INTERACTIVE + yyin->get( buf[0] ); + + if ( yyin->eof() ) + return 0; + + if ( yyin->bad() ) + return -1; + + return 1; + +#else + (void) yyin->read( buf, max_size ); + + if ( yyin->bad() ) + return -1; + else + return yyin->gcount(); +#endif + } + +void yyFlexLexer::LexerOutput( const char* buf, int size ) + { + (void) yyout->write( buf, size ); + } + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +int yyFlexLexer::yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +yy_state_type yyFlexLexer::yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 588 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) + { + register int yy_is_jam; + register char *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 588 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 587); + + return yy_is_jam ? 0 : yy_current_state; + } + + +void yyFlexLexer::yyunput( int c, register char* yy_bp ) + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } + + +int yyFlexLexer::yyinput() + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + + return c; + } + + +void yyFlexLexer::yyrestart( std::istream* input_file ) + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +void yyFlexLexer::yy_load_buffer_state() + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size ) + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + +extern "C" int isatty YY_PROTO(( int )); +void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file ) + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + b->yy_is_interactive = 0; + } + + +void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#endif + + +#ifndef YY_NO_SCAN_STRING +#endif + + +#ifndef YY_NO_SCAN_BYTES +#endif + + +#ifndef YY_NO_PUSH_STATE +void yyFlexLexer::yy_push_state( int new_state ) + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +void yyFlexLexer::yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +int yyFlexLexer::yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + + +void yyFlexLexer::LexerError( yyconst char msg[] ) + { + std::cerr << msg << '\n'; + exit( YY_EXIT_FAILURE ); + } + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 162 ".././ConfigLexer.l" + + + diff --git a/src/osgPlugins/cfg/ConfigLexer.l b/src/osgPlugins/cfg/ConfigLexer.l new file mode 100644 index 000000000..5bb66c7fb --- /dev/null +++ b/src/osgPlugins/cfg/ConfigLexer.l @@ -0,0 +1,164 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +%{ +#include +#include +#include "ConfigParser.h" + +//#define DEBUG +#ifdef DEBUG +#define REPORT printf(" %s\n", yytext); +#else +#define REPORT +#endif +%} + +%option noyywrap +%option c++ +/*%option yyclass="ConfigParser"*/ + +DIGIT [0-9] +ALPHA [A-Za-z] +HEXALNUM [A-Fa-f0-9] + +%% + +[/][/]|[#]|[!] { + #ifdef DEBUG + char buff[128]; + int i = 0; + #endif + + char c; + while( (c = yyinput()) != '\n' ) + { + if( c <= 0 ) + break; + #ifdef DEBUG + buff[i++] = c; + #endif + } + #ifdef DEBUG + buff[i] = 0; + printf( "Single line comment: \"%s\"\n", buff ); + #endif + } + +[\n] { yylineno++;} +[ \t] { ; } +[{] { REPORT return '{'; } +[}] { REPORT return '}'; } +["] { + char c; + int i = 0; + while( (c = yyinput()) != '"' ) + yytext[i++] = c; + yytext[i] = 0; + return PRTOKEN_QUOTED_STRING; + } +[,] { REPORT return ','; } +[:] { REPORT return ':'; } +[;] { REPORT return ';'; } +SetSimple { REPORT return PRTOKEN_SET_SIMPLE; } +VisualID { REPORT return PRTOKEN_VISUAL_ID; } +BUFFER_SIZE { REPORT return PRTOKEN_BUFFER_SIZE; } +LEVEL { REPORT return PRTOKEN_LEVEL; } +RGBA { REPORT return PRTOKEN_RGBA; } +DOUBLEBUFFER { REPORT return PRTOKEN_DOUBLEBUFFER; } +STEREO { REPORT return PRTOKEN_STEREO; } +AUX_BUFFERS { REPORT return PRTOKEN_AUX_BUFFERS; } +RED_SIZE { REPORT return PRTOKEN_RED_SIZE; } +GREEN_SIZE { REPORT return PRTOKEN_GREEN_SIZE; } +BLUE_SIZE { REPORT return PRTOKEN_BLUE_SIZE; } +ALPHA_SIZE { REPORT return PRTOKEN_ALPHA_SIZE; } +DEPTH_SIZE { REPORT return PRTOKEN_DEPTH_SIZE; } +STENCIL_SIZE { REPORT return PRTOKEN_STENCIL_SIZE; } +ACCUM_RED_SIZE { REPORT return PRTOKEN_ACCUM_RED_SIZE; } +ACCUM_GREEN_SIZE { REPORT return PRTOKEN_ACCUM_GREEN_SIZE; } +ACCUM_BLUE_SIZE { REPORT return PRTOKEN_ACCUM_BLUE_SIZE; } +ACCUM_ALPHA_SIZE { REPORT return PRTOKEN_ACCUM_ALPHA_SIZE; } +SAMPLES { REPORT return PRTOKEN_SAMPLES; } +SAMPLE_BUFFERS { REPORT return PRTOKEN_SAMPLE_BUFFERS; } +Visual { REPORT return PRTOKEN_VISUAL; } +RenderSurface { REPORT return PRTOKEN_RENDER_SURFACE; } +WindowRectangle { REPORT return PRTOKEN_WINDOW_RECT; } +WindowRect { REPORT return PRTOKEN_WINDOW_RECT; } +Hostname { REPORT return PRTOKEN_HOSTNAME; } +Display { REPORT return PRTOKEN_DISPLAY; } +Screen { REPORT return PRTOKEN_SCREEN; } +Border { REPORT return PRTOKEN_BORDER; } +InputRectangle { REPORT return PRTOKEN_INPUT_RECT; } +InputRect { REPORT return PRTOKEN_INPUT_RECT; } +DrawableType { REPORT return PRTOKEN_DRAWABLE_TYPE; } +PBUFFER_TYPE { REPORT return PRTOKEN_PBUFFER_TYPE; } +WINDOW_TYPE { REPORT return PRTOKEN_WINDOW_TYPE; } +ReadDrawable { REPORT return PRTOKEN_READ_DRAWABLE; } +RenderToTextureMode { REPORT return PRTOKEN_SET_RTT_MODE; } +RTT_NONE { REPORT return PRTOKEN_RTT_MODE_NONE; } +RTT_RGB { REPORT return PRTOKEN_RTT_MODE_RGB; } +RTT_RGBA { REPORT; return PRTOKEN_RTT_MODE_RGBA; } + + +CameraGroup { REPORT return PRTOKEN_CAMERA_GROUP; } +Camera { REPORT return PRTOKEN_CAMERA; } +ProjectionRectangle { REPORT return PRTOKEN_PROJECTION_RECT; } +ProjectionRect { REPORT return PRTOKEN_PROJECTION_RECT; } + +Lens { REPORT return PRTOKEN_LENS; } +ShareLens { REPORT return PRTOKEN_SHARELENS; } +ShareView { REPORT return PRTOKEN_SHAREVIEW; } +Frustum { REPORT return PRTOKEN_FRUSTUM; } +Perspective { REPORT return PRTOKEN_PERSPECTIVE; } +Ortho { REPORT return PRTOKEN_ORTHO; } +ClearColor { REPORT return PRTOKEN_CLEAR_COLOR; } + +Offset { REPORT return PRTOKEN_OFFSET; } +Rotate { REPORT return PRTOKEN_ROTATE; } +Translate { REPORT return PRTOKEN_TRANSLATE; } +Scale { REPORT return PRTOKEN_SCALE; } +Shear { REPORT return PRTOKEN_SHEAR; } +Method { REPORT return PRTOKEN_METHOD; } +PreMultiply { REPORT return PRTOKEN_PREMULTIPLY; } +PostMultiply { REPORT return PRTOKEN_POSTMULTIPLY; } + +InputArea { REPORT return PRTOKEN_INPUT_AREA; } + +StereoSystemCommands { REPORT return PRTOKEN_STEREO_SYSTEM_COMMANDS; } + +CustomFullScreenRectangle { REPORT return PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE; } +OverrideRedirect { REPORT return PRTOKEN_OVERRIDE_REDIRECT; } + +ThreadModel { REPORT return PRTOKEN_THREAD_MODEL; } +SingleThreaded { REPORT return PRTOKEN_SINGLE_THREADED; } +ThreadPerCamera { REPORT return PRTOKEN_THREAD_PER_CAMERA; } +ThreadPerRenderSurface { REPORT return PRTOKEN_THREAD_PER_RENDER_SURFACE; } + + +on|ON|true|yes { REPORT return PRTOKEN_TRUE; } +off|OFF|false|no { REPORT return PRTOKEN_FALSE; } + +[-]?0x{HEXALNUM}+ { REPORT return PRTOKEN_HEX_INTEGER; } +[-]?{DIGIT}+ { REPORT return PRTOKEN_INTEGER; } + +[-]?{DIGIT}*"."{DIGIT}*[Ff]? { REPORT return PRTOKEN_FLOAT; } +[-]?{DIGIT}+[fF]{1} { REPORT return PRTOKEN_FLOAT; } +[-]?({DIGIT}+)([eE][-+]?{DIGIT}+)? { REPORT return PRTOKEN_FLOAT; } +[-]?({DIGIT}*\.{DIGIT}+)([eE][-+]?{DIGIT}+)? { REPORT return PRTOKEN_FLOAT; } + + + + +%% + + diff --git a/src/osgPlugins/cfg/ConfigParser.cpp b/src/osgPlugins/cfg/ConfigParser.cpp new file mode 100644 index 000000000..706cb112e --- /dev/null +++ b/src/osgPlugins/cfg/ConfigParser.cpp @@ -0,0 +1,2302 @@ +/* A Bison parser, made by GNU Bison 1.875. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Written by Richard Stallman by simplifying the original so called + ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + +/* If NAME_PREFIX is specified substitute the variables and functions + names. */ +#define yyparse ConfigParser_parse +#define yylex ConfigParser_lex +#define yyerror ConfigParser_error +#define yylval ConfigParser_lval +#define yychar ConfigParser_char +#define yydebug ConfigParser_debug +#define yynerrs ConfigParser_nerrs + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + PRTOKEN_VISUAL = 258, + PRTOKEN_SET_SIMPLE = 259, + PRTOKEN_VISUAL_ID = 260, + PRTOKEN_BUFFER_SIZE = 261, + PRTOKEN_LEVEL = 262, + PRTOKEN_RGBA = 263, + PRTOKEN_DOUBLEBUFFER = 264, + PRTOKEN_STEREO = 265, + PRTOKEN_AUX_BUFFERS = 266, + PRTOKEN_RED_SIZE = 267, + PRTOKEN_GREEN_SIZE = 268, + PRTOKEN_BLUE_SIZE = 269, + PRTOKEN_ALPHA_SIZE = 270, + PRTOKEN_DEPTH_SIZE = 271, + PRTOKEN_STENCIL_SIZE = 272, + PRTOKEN_ACCUM_RED_SIZE = 273, + PRTOKEN_ACCUM_GREEN_SIZE = 274, + PRTOKEN_ACCUM_BLUE_SIZE = 275, + PRTOKEN_ACCUM_ALPHA_SIZE = 276, + PRTOKEN_SAMPLES = 277, + PRTOKEN_SAMPLE_BUFFERS = 278, + PRTOKEN_RENDER_SURFACE = 279, + PRTOKEN_WINDOW_RECT = 280, + PRTOKEN_INPUT_RECT = 281, + PRTOKEN_HOSTNAME = 282, + PRTOKEN_DISPLAY = 283, + PRTOKEN_SCREEN = 284, + PRTOKEN_BORDER = 285, + PRTOKEN_DRAWABLE_TYPE = 286, + PRTOKEN_WINDOW_TYPE = 287, + PRTOKEN_PBUFFER_TYPE = 288, + PRTOKEN_CAMERA_GROUP = 289, + PRTOKEN_CAMERA = 290, + PRTOKEN_PROJECTION_RECT = 291, + PRTOKEN_LENS = 292, + PRTOKEN_FRUSTUM = 293, + PRTOKEN_PERSPECTIVE = 294, + PRTOKEN_ORTHO = 295, + PRTOKEN_OFFSET = 296, + PRTOKEN_ROTATE = 297, + PRTOKEN_TRANSLATE = 298, + PRTOKEN_SCALE = 299, + PRTOKEN_SHEAR = 300, + PRTOKEN_CLEAR_COLOR = 301, + PRTOKEN_INPUT_AREA = 302, + PRTOKEN_ERROR = 303, + PRTOKEN_INTEGER = 304, + PRTOKEN_HEX_INTEGER = 305, + PRTOKEN_FLOAT = 306, + PRTOKEN_TRUE = 307, + PRTOKEN_FALSE = 308, + PRTOKEN_QUOTED_STRING = 309, + PRTOKEN_STEREO_SYSTEM_COMMANDS = 310, + PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE = 311, + PRTOKEN_METHOD = 312, + PRTOKEN_PREMULTIPLY = 313, + PRTOKEN_POSTMULTIPLY = 314, + PRTOKEN_OVERRIDE_REDIRECT = 315, + PRTOKEN_SHARELENS = 316, + PRTOKEN_SHAREVIEW = 317, + PRTOKEN_READ_DRAWABLE = 318, + PRTOKEN_SET_RTT_MODE = 319, + PRTOKEN_RTT_MODE_NONE = 320, + PRTOKEN_RTT_MODE_RGB = 321, + PRTOKEN_RTT_MODE_RGBA = 322, + PRTOKEN_THREAD_MODEL = 323, + PRTOKEN_SINGLE_THREADED = 324, + PRTOKEN_THREAD_PER_CAMERA = 325, + PRTOKEN_THREAD_PER_RENDER_SURFACE = 326 + }; +#endif +#define PRTOKEN_VISUAL 258 +#define PRTOKEN_SET_SIMPLE 259 +#define PRTOKEN_VISUAL_ID 260 +#define PRTOKEN_BUFFER_SIZE 261 +#define PRTOKEN_LEVEL 262 +#define PRTOKEN_RGBA 263 +#define PRTOKEN_DOUBLEBUFFER 264 +#define PRTOKEN_STEREO 265 +#define PRTOKEN_AUX_BUFFERS 266 +#define PRTOKEN_RED_SIZE 267 +#define PRTOKEN_GREEN_SIZE 268 +#define PRTOKEN_BLUE_SIZE 269 +#define PRTOKEN_ALPHA_SIZE 270 +#define PRTOKEN_DEPTH_SIZE 271 +#define PRTOKEN_STENCIL_SIZE 272 +#define PRTOKEN_ACCUM_RED_SIZE 273 +#define PRTOKEN_ACCUM_GREEN_SIZE 274 +#define PRTOKEN_ACCUM_BLUE_SIZE 275 +#define PRTOKEN_ACCUM_ALPHA_SIZE 276 +#define PRTOKEN_SAMPLES 277 +#define PRTOKEN_SAMPLE_BUFFERS 278 +#define PRTOKEN_RENDER_SURFACE 279 +#define PRTOKEN_WINDOW_RECT 280 +#define PRTOKEN_INPUT_RECT 281 +#define PRTOKEN_HOSTNAME 282 +#define PRTOKEN_DISPLAY 283 +#define PRTOKEN_SCREEN 284 +#define PRTOKEN_BORDER 285 +#define PRTOKEN_DRAWABLE_TYPE 286 +#define PRTOKEN_WINDOW_TYPE 287 +#define PRTOKEN_PBUFFER_TYPE 288 +#define PRTOKEN_CAMERA_GROUP 289 +#define PRTOKEN_CAMERA 290 +#define PRTOKEN_PROJECTION_RECT 291 +#define PRTOKEN_LENS 292 +#define PRTOKEN_FRUSTUM 293 +#define PRTOKEN_PERSPECTIVE 294 +#define PRTOKEN_ORTHO 295 +#define PRTOKEN_OFFSET 296 +#define PRTOKEN_ROTATE 297 +#define PRTOKEN_TRANSLATE 298 +#define PRTOKEN_SCALE 299 +#define PRTOKEN_SHEAR 300 +#define PRTOKEN_CLEAR_COLOR 301 +#define PRTOKEN_INPUT_AREA 302 +#define PRTOKEN_ERROR 303 +#define PRTOKEN_INTEGER 304 +#define PRTOKEN_HEX_INTEGER 305 +#define PRTOKEN_FLOAT 306 +#define PRTOKEN_TRUE 307 +#define PRTOKEN_FALSE 308 +#define PRTOKEN_QUOTED_STRING 309 +#define PRTOKEN_STEREO_SYSTEM_COMMANDS 310 +#define PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE 311 +#define PRTOKEN_METHOD 312 +#define PRTOKEN_PREMULTIPLY 313 +#define PRTOKEN_POSTMULTIPLY 314 +#define PRTOKEN_OVERRIDE_REDIRECT 315 +#define PRTOKEN_SHARELENS 316 +#define PRTOKEN_SHAREVIEW 317 +#define PRTOKEN_READ_DRAWABLE 318 +#define PRTOKEN_SET_RTT_MODE 319 +#define PRTOKEN_RTT_MODE_NONE 320 +#define PRTOKEN_RTT_MODE_RGB 321 +#define PRTOKEN_RTT_MODE_RGBA 322 +#define PRTOKEN_THREAD_MODEL 323 +#define PRTOKEN_SINGLE_THREADED 324 +#define PRTOKEN_THREAD_PER_CAMERA 325 +#define PRTOKEN_THREAD_PER_RENDER_SURFACE 326 + + + + +/* Copy the first part of user declarations. */ + + + +#ifndef WIN32 +#include +#include +#include +#include +#endif + +#ifndef WIN32 +#define SUPPORT_CPP 1 +#endif + +#include +#include +#include + +#include "FlexLexer.h" + +#include "CameraConfig.h" + + +using namespace std; +using namespace osgProducer; + +static void ConfigParser_error( const char * ); +static CameraConfig *cfg = 0L; +static std::string fileName = "(stdin)"; + +static yyFlexLexer *flexer = 0L; + +static int yylex() +{ + if( flexer == 0L ) + fprintf( stderr, "Internal error!\n" ); + return flexer->yylex(); +} + + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) + +typedef union YYSTYPE { + char * string; + int integer; + float real; + bool boolean; +} YYSTYPE; +/* Line 191 of yacc.c. */ + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + + +/* Copy the second part of user declarations. */ + + +/* Line 214 of yacc.c. */ + + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# if YYSTACK_USE_ALLOCA +# define YYSTACK_ALLOC alloca +# else +# ifndef YYSTACK_USE_ALLOCA +# if defined (alloca) || defined (_ALLOCA_H) +# define YYSTACK_ALLOC alloca +# else +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# else +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +# define YYSTACK_ALLOC malloc +# define YYSTACK_FREE free +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short yyss; + YYSTYPE yyvs; + }; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + register YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +#if defined (__STDC__) || defined (__cplusplus) + typedef signed char yysigned_char; +#else + typedef short yysigned_char; +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 32 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 279 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 76 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 45 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 122 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 266 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 326 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 75, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 72, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 73, 2, 74, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned short yyprhs[] = +{ + 0, 0, 3, 5, 7, 10, 12, 14, 16, 18, + 20, 22, 24, 26, 29, 33, 35, 37, 39, 45, + 50, 52, 53, 55, 58, 59, 66, 68, 71, 72, + 76, 78, 85, 89, 93, 100, 102, 104, 105, 111, + 113, 116, 121, 128, 134, 140, 144, 146, 148, 153, + 155, 158, 159, 168, 179, 186, 195, 204, 215, 220, + 221, 228, 230, 233, 234, 238, 240, 247, 254, 258, + 262, 266, 270, 277, 281, 285, 289, 293, 295, 297, + 299, 301, 303, 304, 311, 312, 318, 320, 324, 326, + 329, 332, 335, 337, 339, 341, 344, 347, 350, 353, + 356, 359, 362, 365, 368, 371, 374, 377, 379, 382, + 383, 389, 391, 394, 398, 400, 402, 404, 406, 408, + 410, 412, 414 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yysigned_char yyrhs[] = +{ + 77, 0, -1, 78, -1, 79, -1, 78, 79, -1, + 105, -1, 99, -1, 87, -1, 110, -1, 84, -1, + 83, -1, 80, -1, 81, -1, 80, 81, -1, 68, + 82, 72, -1, 69, -1, 70, -1, 71, -1, 55, + 116, 118, 118, 72, -1, 34, 73, 85, 74, -1, + 86, -1, -1, 87, -1, 86, 87, -1, -1, 35, + 117, 88, 73, 89, 74, -1, 90, -1, 89, 90, + -1, -1, 24, 117, 72, -1, 99, -1, 36, 114, + 114, 114, 114, 72, -1, 61, 120, 72, -1, 62, + 120, 72, -1, 46, 114, 114, 114, 114, 72, -1, + 96, -1, 91, -1, -1, 41, 73, 92, 93, 74, + -1, 94, -1, 93, 94, -1, 45, 114, 114, 72, + -1, 42, 114, 114, 114, 114, 72, -1, 43, 114, + 114, 114, 72, -1, 44, 114, 114, 114, 72, -1, + 57, 95, 72, -1, 58, -1, 59, -1, 37, 73, + 97, 74, -1, 98, -1, 97, 98, -1, -1, 40, + 114, 114, 114, 114, 114, 114, 72, -1, 40, 114, + 114, 114, 114, 114, 114, 114, 114, 72, -1, 39, + 114, 114, 114, 114, 72, -1, 39, 114, 114, 114, + 114, 114, 114, 72, -1, 38, 114, 114, 114, 114, + 114, 114, 72, -1, 38, 114, 114, 114, 114, 114, + 114, 114, 114, 72, -1, 45, 114, 114, 72, -1, + -1, 24, 117, 100, 73, 101, 74, -1, 102, -1, + 101, 102, -1, -1, 3, 117, 72, -1, 105, -1, + 25, 116, 116, 116, 116, 72, -1, 26, 115, 115, + 115, 115, 72, -1, 27, 117, 72, -1, 28, 116, + 72, -1, 29, 116, 72, -1, 30, 120, 72, -1, + 56, 116, 116, 116, 116, 72, -1, 60, 120, 72, + -1, 31, 103, 72, -1, 63, 117, 72, -1, 64, + 104, 72, -1, 32, -1, 33, -1, 65, -1, 66, + -1, 67, -1, -1, 3, 117, 106, 73, 108, 74, + -1, -1, 3, 107, 73, 108, 74, -1, 109, -1, + 108, 75, 109, -1, 4, -1, 5, 119, -1, 6, + 116, -1, 7, 116, -1, 8, -1, 9, -1, 10, + -1, 11, 116, -1, 12, 116, -1, 13, 116, -1, + 14, 116, -1, 15, 116, -1, 16, 116, -1, 17, + 116, -1, 18, 116, -1, 19, 116, -1, 20, 116, + -1, 21, 116, -1, 22, 116, -1, 23, -1, 116, + 116, -1, -1, 47, 111, 73, 112, 74, -1, 113, + -1, 112, 113, -1, 24, 117, 72, -1, 51, -1, + 49, -1, 51, -1, 49, -1, 54, -1, 54, -1, + 50, -1, 52, -1, 53, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short yyrline[] = +{ + 0, 144, 144, 147, 147, 150, 150, 150, 150, 150, + 150, 150, 153, 153, 157, 165, 166, 167, 170, 176, + 179, 182, 182, 182, 186, 185, 194, 194, 197, 199, + 203, 207, 211, 215, 219, 223, 224, 228, 227, 237, + 237, 241, 245, 249, 253, 257, 264, 265, 268, 271, + 271, 274, 276, 280, 284, 288, 292, 296, 300, 307, + 306, 317, 318, 321, 323, 327, 331, 335, 339, 343, + 347, 351, 355, 359, 363, 368, 372, 379, 380, 384, + 385, 386, 391, 390, 400, 399, 410, 410, 413, 417, + 422, 426, 431, 435, 439, 443, 447, 452, 457, 461, + 465, 469, 473, 477, 481, 485, 489, 493, 497, 504, + 503, 509, 509, 513, 519, 523, 530, 536, 542, 548, + 555, 563, 563 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE +/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "PRTOKEN_VISUAL", "PRTOKEN_SET_SIMPLE", + "PRTOKEN_VISUAL_ID", "PRTOKEN_BUFFER_SIZE", "PRTOKEN_LEVEL", + "PRTOKEN_RGBA", "PRTOKEN_DOUBLEBUFFER", "PRTOKEN_STEREO", + "PRTOKEN_AUX_BUFFERS", "PRTOKEN_RED_SIZE", "PRTOKEN_GREEN_SIZE", + "PRTOKEN_BLUE_SIZE", "PRTOKEN_ALPHA_SIZE", "PRTOKEN_DEPTH_SIZE", + "PRTOKEN_STENCIL_SIZE", "PRTOKEN_ACCUM_RED_SIZE", + "PRTOKEN_ACCUM_GREEN_SIZE", "PRTOKEN_ACCUM_BLUE_SIZE", + "PRTOKEN_ACCUM_ALPHA_SIZE", "PRTOKEN_SAMPLES", "PRTOKEN_SAMPLE_BUFFERS", + "PRTOKEN_RENDER_SURFACE", "PRTOKEN_WINDOW_RECT", "PRTOKEN_INPUT_RECT", + "PRTOKEN_HOSTNAME", "PRTOKEN_DISPLAY", "PRTOKEN_SCREEN", + "PRTOKEN_BORDER", "PRTOKEN_DRAWABLE_TYPE", "PRTOKEN_WINDOW_TYPE", + "PRTOKEN_PBUFFER_TYPE", "PRTOKEN_CAMERA_GROUP", "PRTOKEN_CAMERA", + "PRTOKEN_PROJECTION_RECT", "PRTOKEN_LENS", "PRTOKEN_FRUSTUM", + "PRTOKEN_PERSPECTIVE", "PRTOKEN_ORTHO", "PRTOKEN_OFFSET", + "PRTOKEN_ROTATE", "PRTOKEN_TRANSLATE", "PRTOKEN_SCALE", "PRTOKEN_SHEAR", + "PRTOKEN_CLEAR_COLOR", "PRTOKEN_INPUT_AREA", "PRTOKEN_ERROR", + "PRTOKEN_INTEGER", "PRTOKEN_HEX_INTEGER", "PRTOKEN_FLOAT", + "PRTOKEN_TRUE", "PRTOKEN_FALSE", "PRTOKEN_QUOTED_STRING", + "PRTOKEN_STEREO_SYSTEM_COMMANDS", + "PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE", "PRTOKEN_METHOD", + "PRTOKEN_PREMULTIPLY", "PRTOKEN_POSTMULTIPLY", + "PRTOKEN_OVERRIDE_REDIRECT", "PRTOKEN_SHARELENS", "PRTOKEN_SHAREVIEW", + "PRTOKEN_READ_DRAWABLE", "PRTOKEN_SET_RTT_MODE", + "PRTOKEN_RTT_MODE_NONE", "PRTOKEN_RTT_MODE_RGB", + "PRTOKEN_RTT_MODE_RGBA", "PRTOKEN_THREAD_MODEL", + "PRTOKEN_SINGLE_THREADED", "PRTOKEN_THREAD_PER_CAMERA", + "PRTOKEN_THREAD_PER_RENDER_SURFACE", "';'", "'{'", "'}'", "','", + "$accept", "config", "entries", "entry", "system_params", + "system_param", "threadModelDirective", "stereo_param", "camera_group", + "camera_group_attributes", "cameras", "camera", "@1", + "camera_attributes", "camera_attribute", "camera_offset", "@2", + "camera_offset_attributes", "camera_offset_attribute", + "offset_multiply_method", "lens", "lens_attributes", "lens_attribute", + "render_surface", "@3", "render_surface_attributes", + "render_surface_attribute", "drawableType", "rtt_mode", "visual", "@4", + "@5", "visual_attributes", "visual_attribute", "input_area", "@6", + "input_area_entries", "input_area_entry", "real", "floatparam", + "intparam", "name", "string", "hex_integer", "bool", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const unsigned short yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 59, 123, 125, 44 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 76, 77, 78, 78, 79, 79, 79, 79, 79, + 79, 79, 80, 80, 81, 82, 82, 82, 83, 84, + 85, 86, 86, 86, 88, 87, 89, 89, 90, 90, + 90, 90, 90, 90, 90, 90, 90, 92, 91, 93, + 93, 94, 94, 94, 94, 94, 95, 95, 96, 97, + 97, 98, 98, 98, 98, 98, 98, 98, 98, 100, + 99, 101, 101, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 103, 103, 104, + 104, 104, 106, 105, 107, 105, 108, 108, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 111, + 110, 112, 112, 113, 114, 114, 115, 116, 117, 118, + 119, 120, 120 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 1, 1, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 3, 1, 1, 1, 5, 4, + 1, 0, 1, 2, 0, 6, 1, 2, 0, 3, + 1, 6, 3, 3, 6, 1, 1, 0, 5, 1, + 2, 4, 6, 5, 5, 3, 1, 1, 4, 1, + 2, 0, 8, 10, 6, 8, 8, 10, 4, 0, + 6, 1, 2, 0, 3, 1, 6, 6, 3, 3, + 3, 3, 6, 3, 3, 3, 3, 1, 1, 1, + 1, 1, 0, 6, 0, 5, 1, 3, 1, 2, + 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 1, 2, 0, + 5, 1, 2, 3, 1, 1, 1, 1, 1, 1, + 1, 1, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const unsigned char yydefact[] = +{ + 0, 84, 0, 0, 0, 109, 0, 0, 0, 2, + 3, 11, 12, 10, 9, 7, 6, 5, 8, 118, + 0, 82, 59, 21, 24, 0, 117, 0, 15, 16, + 17, 0, 1, 4, 13, 0, 0, 0, 0, 20, + 22, 0, 0, 119, 0, 14, 88, 0, 0, 0, + 92, 93, 94, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 107, 0, 86, 0, 0, + 63, 19, 23, 28, 0, 0, 111, 0, 120, 89, + 90, 91, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 85, 0, 108, 0, 84, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 61, 65, 0, 0, 0, 0, 0, 0, 0, + 0, 26, 36, 35, 30, 0, 110, 112, 18, 87, + 83, 82, 0, 116, 0, 0, 0, 0, 121, 122, + 0, 77, 78, 0, 0, 0, 0, 79, 80, 81, + 0, 60, 62, 59, 115, 114, 0, 51, 37, 0, + 0, 0, 25, 27, 113, 64, 0, 0, 68, 69, + 70, 71, 74, 0, 73, 75, 76, 29, 0, 0, + 0, 0, 0, 0, 49, 0, 0, 32, 33, 0, + 0, 0, 0, 0, 0, 0, 0, 48, 50, 0, + 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, + 47, 0, 38, 40, 0, 66, 67, 72, 31, 0, + 0, 0, 58, 0, 0, 0, 0, 45, 34, 0, + 0, 0, 0, 0, 0, 41, 0, 54, 0, 0, + 0, 43, 44, 0, 0, 0, 42, 56, 0, 55, + 52, 0, 0, 0, 57, 53 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const short yydefgoto[] = +{ + -1, 8, 9, 10, 11, 12, 31, 13, 14, 38, + 39, 15, 41, 120, 121, 122, 185, 204, 205, 221, + 123, 183, 184, 16, 37, 110, 111, 143, 150, 17, + 36, 20, 66, 67, 18, 25, 75, 76, 156, 134, + 68, 21, 44, 79, 140 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -130 +static const short yypact[] = +{ + 36, -51, -51, -66, -51, -130, -33, -34, 26, 36, + -130, 10, -130, -130, -130, -130, -130, -130, -130, -130, + 13, -130, -130, 57, -130, 22, -130, 45, -130, -130, + -130, 39, -130, -130, -130, 230, 50, 51, 60, 57, + -130, 52, 111, -130, 45, -130, -130, 86, -33, -33, + -130, -130, -130, -33, -33, -33, -33, -33, -33, -33, + -33, -33, -33, -33, -33, -130, -62, -130, -33, 230, + 202, -130, -130, 66, -51, -10, -130, 65, -130, -130, + -130, -130, -130, -130, -130, -130, -130, -130, -130, -130, + -130, -130, -130, -130, -130, 230, -130, -54, -51, -33, + 96, -51, -33, -33, 16, 73, -33, 16, -51, 15, + 3, -130, -130, -51, 24, 76, 77, 24, 16, 16, + 48, -130, -130, -130, -130, 67, -130, -130, -130, -130, + -130, 79, -33, -130, 96, 80, 81, 87, -130, -130, + 93, -130, -130, 94, -33, 100, 109, -130, -130, -130, + 110, -130, -130, 112, -130, -130, 24, 131, -130, 24, + 114, 115, -130, -130, -130, -130, -33, 96, -130, -130, + -130, -130, -130, -33, -130, -130, -130, -130, 24, 24, + 24, 24, 24, -30, -130, 88, 24, -130, -130, -33, + 96, -33, 24, 24, 24, 24, 24, -130, -130, 24, + 24, 24, 24, 61, 72, -130, 24, 116, 117, 118, + 122, 24, 24, 24, 126, 24, 24, 24, 24, -130, + -130, 127, -130, -130, 128, -130, -130, -130, -130, 24, + 24, 24, -130, 24, 24, 24, 134, -130, -130, 24, + -32, 24, 24, 135, 137, -130, 24, -130, 24, 24, + 140, -130, -130, -27, 141, -26, -130, -130, 24, -130, + -130, 24, 142, 144, -130, -130 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short yypgoto[] = +{ + -130, -130, -130, 209, -130, 208, -130, -130, -130, -130, + -130, -12, -130, -130, 101, -130, -130, -130, 18, -130, + -130, -130, 41, -55, -130, -130, 145, -130, -130, -69, + -130, -130, 156, 159, -130, -130, -130, 151, -38, -129, + -6, 0, 212, -130, -31 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const unsigned short yytable[] = +{ + 27, 112, 22, 19, 24, 167, 98, 23, 179, 180, + 181, 40, 94, 95, 74, 182, 26, 154, 124, 155, + 130, 95, 154, 154, 155, 155, 32, 72, 99, 100, + 101, 102, 103, 104, 105, 28, 29, 30, 190, 1, + 247, 112, 80, 81, 197, 257, 260, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 106, + 2, 208, 96, 107, 126, 124, 108, 109, 138, 139, + 3, 4, 113, 154, 125, 155, 145, 151, 7, 159, + 147, 148, 149, 5, 114, 115, 35, 160, 161, 116, + 113, 6, 4, 132, 117, 42, 136, 137, 131, 43, + 144, 135, 114, 115, 7, 141, 142, 116, 146, 118, + 119, 45, 117, 153, 199, 200, 201, 202, 178, 219, + 220, 186, 162, 69, 70, 73, 166, 118, 119, 203, + 199, 200, 201, 202, 71, 74, 78, 128, 173, 164, + 192, 193, 194, 195, 196, 203, 222, 133, 206, 157, + 158, 165, 168, 169, 210, 211, 212, 213, 214, 170, + 189, 215, 216, 217, 218, 171, 172, 191, 224, 179, + 180, 181, 174, 229, 230, 231, 182, 233, 234, 235, + 236, 175, 176, 207, 177, 209, 187, 188, 225, 226, + 227, 239, 240, 241, 228, 242, 243, 244, 232, 237, + 238, 246, 248, 249, 250, 98, 245, 251, 253, 252, + 254, 255, 256, 259, 264, 258, 265, 261, 33, 34, + 262, 163, 223, 263, 198, 97, 127, 99, 100, 101, + 102, 103, 104, 105, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 129, 152, 77, 0, 106, 0, + 0, 0, 107, 0, 0, 108, 109, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 26 +}; + +static const short yycheck[] = +{ + 6, 70, 2, 54, 4, 134, 3, 73, 38, 39, + 40, 23, 74, 75, 24, 45, 49, 49, 73, 51, + 74, 75, 49, 49, 51, 51, 0, 39, 25, 26, + 27, 28, 29, 30, 31, 69, 70, 71, 167, 3, + 72, 110, 48, 49, 74, 72, 72, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 56, + 24, 190, 68, 60, 74, 120, 63, 64, 52, 53, + 34, 35, 24, 49, 74, 51, 107, 74, 68, 117, + 65, 66, 67, 47, 36, 37, 73, 118, 119, 41, + 24, 55, 35, 99, 46, 73, 102, 103, 98, 54, + 106, 101, 36, 37, 68, 32, 33, 41, 108, 61, + 62, 72, 46, 113, 42, 43, 44, 45, 156, 58, + 59, 159, 74, 73, 73, 73, 132, 61, 62, 57, + 42, 43, 44, 45, 74, 24, 50, 72, 144, 72, + 178, 179, 180, 181, 182, 57, 74, 51, 186, 73, + 73, 72, 72, 72, 192, 193, 194, 195, 196, 72, + 166, 199, 200, 201, 202, 72, 72, 173, 206, 38, + 39, 40, 72, 211, 212, 213, 45, 215, 216, 217, + 218, 72, 72, 189, 72, 191, 72, 72, 72, 72, + 72, 229, 230, 231, 72, 233, 234, 235, 72, 72, + 72, 239, 240, 241, 242, 3, 72, 72, 246, 72, + 248, 249, 72, 72, 72, 253, 72, 255, 9, 11, + 258, 120, 204, 261, 183, 69, 75, 25, 26, 27, + 28, 29, 30, 31, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 95, 110, 44, -1, 56, -1, + -1, -1, 60, -1, -1, 63, 64, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 49 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 3, 24, 34, 35, 47, 55, 68, 77, 78, + 79, 80, 81, 83, 84, 87, 99, 105, 110, 54, + 107, 117, 117, 73, 117, 111, 49, 116, 69, 70, + 71, 82, 0, 79, 81, 73, 106, 100, 85, 86, + 87, 88, 73, 54, 118, 72, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 108, 109, 116, 73, + 73, 74, 87, 73, 24, 112, 113, 118, 50, 119, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 74, 75, 116, 108, 3, 25, + 26, 27, 28, 29, 30, 31, 56, 60, 63, 64, + 101, 102, 105, 24, 36, 37, 41, 46, 61, 62, + 89, 90, 91, 96, 99, 117, 74, 113, 72, 109, + 74, 117, 116, 51, 115, 117, 116, 116, 52, 53, + 120, 32, 33, 103, 116, 120, 117, 65, 66, 67, + 104, 74, 102, 117, 49, 51, 114, 73, 73, 114, + 120, 120, 74, 90, 72, 72, 116, 115, 72, 72, + 72, 72, 72, 116, 72, 72, 72, 72, 114, 38, + 39, 40, 45, 97, 98, 92, 114, 72, 72, 116, + 115, 116, 114, 114, 114, 114, 114, 74, 98, 42, + 43, 44, 45, 57, 93, 94, 114, 116, 115, 116, + 114, 114, 114, 114, 114, 114, 114, 114, 114, 58, + 59, 95, 74, 94, 114, 72, 72, 72, 72, 114, + 114, 114, 72, 114, 114, 114, 114, 72, 72, 114, + 114, 114, 114, 114, 114, 72, 114, 72, 114, 114, + 114, 72, 72, 114, 114, 114, 72, 72, 114, 72, + 72, 114, 114, 114, 72, 72 +}; + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror ("syntax error: cannot back up");\ + YYERROR; \ + } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +/* YYLLOC_DEFAULT -- Compute the default location (before the actions + are run). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.first_line = Rhs[1].first_line; \ + Current.first_column = Rhs[1].first_column; \ + Current.last_line = Rhs[N].last_line; \ + Current.last_column = Rhs[N].last_column; +#endif + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +# define YYDSYMPRINT(Args) \ +do { \ + if (yydebug) \ + yysymprint Args; \ +} while (0) + +# define YYDSYMPRINTF(Title, Token, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Token, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (cinluded). | +`------------------------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_stack_print (short *bottom, short *top) +#else +static void +yy_stack_print (bottom, top) + short *bottom; + short *top; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (/* Nothing. */; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_reduce_print (int yyrule) +#else +static void +yy_reduce_print (yyrule) + int yyrule; +#endif +{ + int yyi; + unsigned int yylineno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", + yyrule - 1, yylineno); + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YYDSYMPRINT(Args) +# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#if YYMAXDEPTH == 0 +# undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif +{ + register const char *yys = yystr; + + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; +} +# endif +# endif + +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif +{ + register char *yyd = yydest; + register const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +#endif /* !YYERROR_VERBOSE */ + + + +#if YYDEBUG +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) +#else +static void +yysymprint (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + if (yytype < YYNTOKENS) + { + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); +# ifdef YYPRINT + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + } + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + switch (yytype) + { + default: + break; + } + YYFPRINTF (yyoutput, ")"); +} + +#endif /* ! YYDEBUG */ +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yydestruct (int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yytype, yyvaluep) + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM); +# else +int yyparse (); +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM) +# else +int yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + register int yystate; + register int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short yyssa[YYINITDEPTH]; + short *yyss = yyssa; + register short *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + register YYSTYPE *yyvsp; + + + +#define YYPOPSTACK (yyvsp--, yyssp--) + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ + int yylen; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; + + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow ("parser stack overflow", + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyoverflowlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyoverflowlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + short *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyoverflowlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; + + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + yystate = yyn; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 14: + + { + osgProducer::CameraGroup::ThreadModel tm = (osgProducer::CameraGroup::ThreadModel)yyvsp[-1].integer; + cfg->setThreadModelDirective( tm ); + ;} + break; + + case 15: + + { yyval.integer = CameraGroup::SingleThreaded; ;} + break; + + case 16: + + { yyval.integer = CameraGroup::ThreadPerCamera; ;} + break; + + case 17: + + { yyval.integer = CameraGroup::ThreadPerRenderSurface; ;} + break; + + case 18: + + { + cfg->addStereoSystemCommand( yyvsp[-3].integer, yyvsp[-2].string, yyvsp[-1].string ); + ;} + break; + + case 24: + + { + cfg->beginCamera( yyvsp[0].string ); + ;} + break; + + case 25: + + { + cfg->endCamera(); + ;} + break; + + case 29: + + { + cfg->setCameraRenderSurface( yyvsp[-1].string ); + ;} + break; + + case 30: + + { + cfg->setCameraRenderSurface(); + ;} + break; + + case 31: + + { + cfg->setCameraProjectionRectangle( yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 32: + + { + cfg->setCameraShareLens( yyvsp[-1].boolean ); + ;} + break; + + case 33: + + { + cfg->setCameraShareView( yyvsp[-1].boolean ); + ;} + break; + + case 34: + + { + cfg->setCameraClearColor( yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 37: + + { + cfg->beginCameraOffset(); + ;} + break; + + case 38: + + { + cfg->endCameraOffset(); + ;} + break; + + case 41: + + { + cfg->shearCameraOffset( yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 42: + + { + cfg->rotateCameraOffset( yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 43: + + { + cfg->translateCameraOffset( yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 44: + + { + cfg->scaleCameraOffset( yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 45: + + { + cfg->setCameraOffsetMultiplyMethod( (osgProducer::Camera::Offset::MultiplyMethod)yyvsp[-1].integer ); + ;} + break; + + case 46: + + { yyval.integer = osgProducer::Camera::Offset::PreMultiply; ;} + break; + + case 47: + + { yyval.integer = osgProducer::Camera::Offset::PostMultiply; ;} + break; + + case 52: + + { + cfg->setCameraOrtho( yyvsp[-6].real, yyvsp[-5].real, yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 53: + + { + cfg->setCameraOrtho( yyvsp[-8].real, yyvsp[-7].real, yyvsp[-6].real, yyvsp[-5].real, yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 54: + + { + cfg->setCameraPerspective( yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 55: + + { + cfg->setCameraPerspective( yyvsp[-6].real, yyvsp[-5].real, yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 56: + + { + cfg->setCameraFrustum( yyvsp[-6].real, yyvsp[-5].real, yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 57: + + { + cfg->setCameraFrustum( yyvsp[-8].real, yyvsp[-7].real, yyvsp[-6].real, yyvsp[-5].real, yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 58: + + { + cfg->setCameraLensShear( yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 59: + + { + cfg->beginRenderSurface( yyvsp[0].string ); + ;} + break; + + case 60: + + { + cfg->endRenderSurface(); + ;} + break; + + case 64: + + { + cfg->setRenderSurfaceVisualChooser( yyvsp[-1].string ); + ;} + break; + + case 65: + + { + cfg->setRenderSurfaceVisualChooser(); + ;} + break; + + case 66: + + { + cfg->setRenderSurfaceWindowRectangle( yyvsp[-4].integer, yyvsp[-3].integer, yyvsp[-2].integer, yyvsp[-1].integer ); + ;} + break; + + case 67: + + { + cfg->setRenderSurfaceInputRectangle( yyvsp[-4].real, yyvsp[-3].real, yyvsp[-2].real, yyvsp[-1].real ); + ;} + break; + + case 68: + + { + cfg->setRenderSurfaceHostName( std::string(yyvsp[-1].string) ); + ;} + break; + + case 69: + + { + cfg->setRenderSurfaceDisplayNum( yyvsp[-1].integer ); + ;} + break; + + case 70: + + { + cfg->setRenderSurfaceScreen( yyvsp[-1].integer ); + ;} + break; + + case 71: + + { + cfg->setRenderSurfaceBorder( yyvsp[-1].boolean ); + ;} + break; + + case 72: + + { + cfg->setRenderSurfaceCustomFullScreenRectangle( yyvsp[-4].integer, yyvsp[-3].integer, yyvsp[-2].integer, yyvsp[-1].integer ); + ;} + break; + + case 73: + + { + cfg->setRenderSurfaceOverrideRedirect( yyvsp[-1].boolean ); + ;} + break; + + case 74: + + { + osgProducer::RenderSurface::DrawableType drawableType = (RenderSurface::DrawableType)yyvsp[-1].integer; + cfg->setRenderSurfaceDrawableType( drawableType ); + ;} + break; + + case 75: + + { + cfg->setRenderSurfaceReadDrawable( yyvsp[-1].string ); + ;} + break; + + case 76: + + { + cfg->setRenderSurfaceRenderToTextureMode( (osgProducer::RenderSurface::RenderToTextureMode)yyvsp[-1].integer ); + ;} + break; + + case 77: + + { yyval.integer = RenderSurface::DrawableType_Window; ;} + break; + + case 78: + + { yyval.integer = RenderSurface::DrawableType_PBuffer; ;} + break; + + case 79: + + { yyval.integer = RenderSurface::RenderToTextureMode_None; ;} + break; + + case 80: + + { yyval.integer = RenderSurface::RenderToRGBTexture; ;} + break; + + case 81: + + { yyval.integer = RenderSurface::RenderToRGBATexture; ;} + break; + + case 82: + + { + cfg->beginVisual( yyvsp[0].string ); + ;} + break; + + case 83: + + { + cfg->endVisual(); + ;} + break; + + case 84: + + { + cfg->beginVisual(); + ;} + break; + + case 85: + + { + cfg->endVisual(); + ;} + break; + + case 88: + + { + cfg->setVisualSimpleConfiguration(); + ;} + break; + + case 89: + + { + cfg->setVisualByID( yyvsp[0].integer ); + ;} + break; + + case 90: + + { + cfg->addVisualAttribute( VisualChooser::BufferSize, yyvsp[0].integer ); + ;} + break; + + case 91: + + { + cfg->addVisualAttribute( VisualChooser::Level, yyvsp[0].integer ); + ;} + break; + + case 92: + + { + cfg->addVisualAttribute( VisualChooser::RGBA ); + ;} + break; + + case 93: + + { + cfg->addVisualAttribute( VisualChooser::DoubleBuffer ); + ;} + break; + + case 94: + + { + cfg->addVisualAttribute( VisualChooser::Stereo ); + ;} + break; + + case 95: + + { + cfg->addVisualAttribute( VisualChooser::AuxBuffers, yyvsp[0].integer ); + ;} + break; + + case 96: + + { + cfg->addVisualAttribute( VisualChooser::RedSize, yyvsp[0].integer ); + ;} + break; + + case 97: + + { + cfg->addVisualAttribute( VisualChooser::GreenSize, yyvsp[0].integer ); + ;} + break; + + case 98: + + { + cfg->addVisualAttribute( VisualChooser::BlueSize, yyvsp[0].integer ); + ;} + break; + + case 99: + + { + cfg->addVisualAttribute( VisualChooser::AlphaSize, yyvsp[0].integer ); + ;} + break; + + case 100: + + { + cfg->addVisualAttribute( VisualChooser::DepthSize, yyvsp[0].integer ); + ;} + break; + + case 101: + + { + cfg->addVisualAttribute( VisualChooser::StencilSize, yyvsp[0].integer ); + ;} + break; + + case 102: + + { + cfg->addVisualAttribute( VisualChooser::AccumRedSize, yyvsp[0].integer ); + ;} + break; + + case 103: + + { + cfg->addVisualAttribute( VisualChooser::AccumGreenSize, yyvsp[0].integer ); + ;} + break; + + case 104: + + { + cfg->addVisualAttribute( VisualChooser::AccumBlueSize, yyvsp[0].integer ); + ;} + break; + + case 105: + + { + cfg->addVisualAttribute( VisualChooser::AccumAlphaSize, yyvsp[0].integer ); + ;} + break; + + case 106: + + { + cfg->addVisualAttribute( VisualChooser::Samples, yyvsp[0].integer ); + ;} + break; + + case 107: + + { + cfg->addVisualAttribute( VisualChooser::SampleBuffers ); + ;} + break; + + case 108: + + { + cfg->addVisualExtendedAttribute( yyvsp[-1].integer, yyvsp[0].integer ); + ;} + break; + + case 109: + + { cfg->beginInputArea(); ;} + break; + + case 110: + + { cfg->endInputArea(); ;} + break; + + case 113: + + { + cfg->addInputAreaEntry( yyvsp[-1].string ); + ;} + break; + + case 114: + + { + yyval.real = atof(flexer->YYText()); + ;} + break; + + case 115: + + { + yyval.real = atof(flexer->YYText()); + ;} + break; + + case 116: + + { + yyval.real = atof(flexer->YYText()); + ;} + break; + + case 117: + + { + yyval.integer = atoi( flexer->YYText() ); + ;} + break; + + case 118: + + { + yyval.string = strdup( flexer->YYText() ); + ;} + break; + + case 119: + + { + yyval.string = strdup( flexer->YYText() ); + ;} + break; + + case 120: + + { + int n; + sscanf( flexer->YYText(), "0x%x", &n ); + yyval.integer = n; + ;} + break; + + case 121: + + { yyval.boolean = true;;} + break; + + case 122: + + { yyval.boolean = false; ;} + break; + + + } + +/* Line 991 of yacc.c. */ + + + yyvsp -= yylen; + yyssp -= yylen; + + + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (YYPACT_NINF < yyn && yyn < YYLAST) + { + YYSIZE_T yysize = 0; + int yytype = YYTRANSLATE (yychar); + char *yymsg; + int yyx, yycount; + + yycount = 0; + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + yysize += yystrlen (yytname[yyx]) + 15, yycount++; + yysize += yystrlen ("syntax error, unexpected ") + 1; + yysize += yystrlen (yytname[yytype]); + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg != 0) + { + char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); + yyp = yystpcpy (yyp, yytname[yytype]); + + if (yycount < 5) + { + yycount = 0; + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); + yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + const char *yyq = ! yycount ? ", expecting " : " or "; + yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yytname[yyx]); + yycount++; + } + } + yyerror (yymsg); + YYSTACK_FREE (yymsg); + } + else + yyerror ("syntax error; also virtual memory exhausted"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror ("syntax error"); + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + /* Return failure if at end of input. */ + if (yychar == YYEOF) + { + /* Pop the error token. */ + YYPOPSTACK; + /* Pop the rest of the stack. */ + while (yyss < yyssp) + { + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[*yyssp], yyvsp); + YYPOPSTACK; + } + YYABORT; + } + + YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); + yydestruct (yytoken, &yylval); + yychar = YYEMPTY; + + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab2; + + +/*----------------------------------------------------. +| yyerrlab1 -- error raised explicitly by an action. | +`----------------------------------------------------*/ +yyerrlab1: + + /* Suppress GCC warning that yyerrlab1 is unused when no action + invokes YYERROR. */ +#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) \ + && !defined __cplusplus + __attribute__ ((__unused__)) +#endif + + + goto yyerrlab2; + + +/*---------------------------------------------------------------. +| yyerrlab2 -- pop states until the error token can be shifted. | +`---------------------------------------------------------------*/ +yyerrlab2: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[yystate], yyvsp); + yyvsp--; + yystate = *--yyssp; + + YY_STACK_PRINT (yyss, yyssp); + } + + if (yyn == YYFINAL) + YYACCEPT; + + YYDPRINTF ((stderr, "Shifting error token, ")); + + *++yyvsp = yylval; + + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*----------------------------------------------. +| yyoverflowlab -- parser overflow comes here. | +`----------------------------------------------*/ +yyoverflowlab: + yyerror ("parser stack overflow"); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; +} + + + + + +static void yyerror( const char *errmsg ) +{ + fprintf( stderr, + "CameraConfig::parseFile(\"%s\") : %s - Line %d at or before \"%s\"\n", + fileName.c_str(), + errmsg, + flexer->lineno(), + flexer->YYText() ); +} + +bool CameraConfig::parseFile( const std::string &file ) +{ + fileName.clear(); + + fileName = findFile(file); + + if( fileName.empty() ) + { + fprintf( stderr, "CameraConfig::parseFile() - Can't find file \"%s\".\n", file.c_str() ); + return false; + } + + bool retval = true; + +#if defined (SUPPORT_CPP) + + char *cpp_path = + #if defined(__APPLE__) + "/usr/bin/cpp"; + #else + "/lib/cpp"; + #endif + + if( access( cpp_path, X_OK ) == 0 ) + { + + int pd[2]; + pipe( pd ); + + flexer = new yyFlexLexer; + if( fork() == 0 ) + { + // we don't want to read from the pipe in the child, so close it. + close( pd[0] ); + close( 1 ); + dup( pd[1] ); + + + /* This was here to allow reading a config file from stdin. + * This has never been directly supported, so commenting out. + if( fileName.empty() ) + execlp( cpp_path, "cpp", "-P", 0L ); + else + */ + execlp( cpp_path, "cpp", "-P", fileName.c_str(), 0L ); + + // This should not execute unless an error happens + perror( "execlp" ); + } + else + { + close( pd[1]); + close( 0 ); + dup( pd[0] ); + + cfg = this; + + retval = ConfigParser_parse() == 0 ? true : false; + + // Wait on child process to finish + int stat; + wait( &stat ); + } + } + else +#endif + { + std::ifstream ifs(fileName.c_str()); + flexer = new yyFlexLexer(&ifs); + cfg = this; + retval = ConfigParser_parse() == 0 ? true : false; + ifs.close(); + delete flexer; + } + return retval; +} + + diff --git a/src/osgPlugins/cfg/ConfigParser.h b/src/osgPlugins/cfg/ConfigParser.h new file mode 100644 index 000000000..2318a56b4 --- /dev/null +++ b/src/osgPlugins/cfg/ConfigParser.h @@ -0,0 +1,194 @@ +/* A Bison parser, made by GNU Bison 1.875. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + PRTOKEN_VISUAL = 258, + PRTOKEN_SET_SIMPLE = 259, + PRTOKEN_VISUAL_ID = 260, + PRTOKEN_BUFFER_SIZE = 261, + PRTOKEN_LEVEL = 262, + PRTOKEN_RGBA = 263, + PRTOKEN_DOUBLEBUFFER = 264, + PRTOKEN_STEREO = 265, + PRTOKEN_AUX_BUFFERS = 266, + PRTOKEN_RED_SIZE = 267, + PRTOKEN_GREEN_SIZE = 268, + PRTOKEN_BLUE_SIZE = 269, + PRTOKEN_ALPHA_SIZE = 270, + PRTOKEN_DEPTH_SIZE = 271, + PRTOKEN_STENCIL_SIZE = 272, + PRTOKEN_ACCUM_RED_SIZE = 273, + PRTOKEN_ACCUM_GREEN_SIZE = 274, + PRTOKEN_ACCUM_BLUE_SIZE = 275, + PRTOKEN_ACCUM_ALPHA_SIZE = 276, + PRTOKEN_SAMPLES = 277, + PRTOKEN_SAMPLE_BUFFERS = 278, + PRTOKEN_RENDER_SURFACE = 279, + PRTOKEN_WINDOW_RECT = 280, + PRTOKEN_INPUT_RECT = 281, + PRTOKEN_HOSTNAME = 282, + PRTOKEN_DISPLAY = 283, + PRTOKEN_SCREEN = 284, + PRTOKEN_BORDER = 285, + PRTOKEN_DRAWABLE_TYPE = 286, + PRTOKEN_WINDOW_TYPE = 287, + PRTOKEN_PBUFFER_TYPE = 288, + PRTOKEN_CAMERA_GROUP = 289, + PRTOKEN_CAMERA = 290, + PRTOKEN_PROJECTION_RECT = 291, + PRTOKEN_LENS = 292, + PRTOKEN_FRUSTUM = 293, + PRTOKEN_PERSPECTIVE = 294, + PRTOKEN_ORTHO = 295, + PRTOKEN_OFFSET = 296, + PRTOKEN_ROTATE = 297, + PRTOKEN_TRANSLATE = 298, + PRTOKEN_SCALE = 299, + PRTOKEN_SHEAR = 300, + PRTOKEN_CLEAR_COLOR = 301, + PRTOKEN_INPUT_AREA = 302, + PRTOKEN_ERROR = 303, + PRTOKEN_INTEGER = 304, + PRTOKEN_HEX_INTEGER = 305, + PRTOKEN_FLOAT = 306, + PRTOKEN_TRUE = 307, + PRTOKEN_FALSE = 308, + PRTOKEN_QUOTED_STRING = 309, + PRTOKEN_STEREO_SYSTEM_COMMANDS = 310, + PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE = 311, + PRTOKEN_METHOD = 312, + PRTOKEN_PREMULTIPLY = 313, + PRTOKEN_POSTMULTIPLY = 314, + PRTOKEN_OVERRIDE_REDIRECT = 315, + PRTOKEN_SHARELENS = 316, + PRTOKEN_SHAREVIEW = 317, + PRTOKEN_READ_DRAWABLE = 318, + PRTOKEN_SET_RTT_MODE = 319, + PRTOKEN_RTT_MODE_NONE = 320, + PRTOKEN_RTT_MODE_RGB = 321, + PRTOKEN_RTT_MODE_RGBA = 322, + PRTOKEN_THREAD_MODEL = 323, + PRTOKEN_SINGLE_THREADED = 324, + PRTOKEN_THREAD_PER_CAMERA = 325, + PRTOKEN_THREAD_PER_RENDER_SURFACE = 326 + }; +#endif +#define PRTOKEN_VISUAL 258 +#define PRTOKEN_SET_SIMPLE 259 +#define PRTOKEN_VISUAL_ID 260 +#define PRTOKEN_BUFFER_SIZE 261 +#define PRTOKEN_LEVEL 262 +#define PRTOKEN_RGBA 263 +#define PRTOKEN_DOUBLEBUFFER 264 +#define PRTOKEN_STEREO 265 +#define PRTOKEN_AUX_BUFFERS 266 +#define PRTOKEN_RED_SIZE 267 +#define PRTOKEN_GREEN_SIZE 268 +#define PRTOKEN_BLUE_SIZE 269 +#define PRTOKEN_ALPHA_SIZE 270 +#define PRTOKEN_DEPTH_SIZE 271 +#define PRTOKEN_STENCIL_SIZE 272 +#define PRTOKEN_ACCUM_RED_SIZE 273 +#define PRTOKEN_ACCUM_GREEN_SIZE 274 +#define PRTOKEN_ACCUM_BLUE_SIZE 275 +#define PRTOKEN_ACCUM_ALPHA_SIZE 276 +#define PRTOKEN_SAMPLES 277 +#define PRTOKEN_SAMPLE_BUFFERS 278 +#define PRTOKEN_RENDER_SURFACE 279 +#define PRTOKEN_WINDOW_RECT 280 +#define PRTOKEN_INPUT_RECT 281 +#define PRTOKEN_HOSTNAME 282 +#define PRTOKEN_DISPLAY 283 +#define PRTOKEN_SCREEN 284 +#define PRTOKEN_BORDER 285 +#define PRTOKEN_DRAWABLE_TYPE 286 +#define PRTOKEN_WINDOW_TYPE 287 +#define PRTOKEN_PBUFFER_TYPE 288 +#define PRTOKEN_CAMERA_GROUP 289 +#define PRTOKEN_CAMERA 290 +#define PRTOKEN_PROJECTION_RECT 291 +#define PRTOKEN_LENS 292 +#define PRTOKEN_FRUSTUM 293 +#define PRTOKEN_PERSPECTIVE 294 +#define PRTOKEN_ORTHO 295 +#define PRTOKEN_OFFSET 296 +#define PRTOKEN_ROTATE 297 +#define PRTOKEN_TRANSLATE 298 +#define PRTOKEN_SCALE 299 +#define PRTOKEN_SHEAR 300 +#define PRTOKEN_CLEAR_COLOR 301 +#define PRTOKEN_INPUT_AREA 302 +#define PRTOKEN_ERROR 303 +#define PRTOKEN_INTEGER 304 +#define PRTOKEN_HEX_INTEGER 305 +#define PRTOKEN_FLOAT 306 +#define PRTOKEN_TRUE 307 +#define PRTOKEN_FALSE 308 +#define PRTOKEN_QUOTED_STRING 309 +#define PRTOKEN_STEREO_SYSTEM_COMMANDS 310 +#define PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE 311 +#define PRTOKEN_METHOD 312 +#define PRTOKEN_PREMULTIPLY 313 +#define PRTOKEN_POSTMULTIPLY 314 +#define PRTOKEN_OVERRIDE_REDIRECT 315 +#define PRTOKEN_SHARELENS 316 +#define PRTOKEN_SHAREVIEW 317 +#define PRTOKEN_READ_DRAWABLE 318 +#define PRTOKEN_SET_RTT_MODE 319 +#define PRTOKEN_RTT_MODE_NONE 320 +#define PRTOKEN_RTT_MODE_RGB 321 +#define PRTOKEN_RTT_MODE_RGBA 322 +#define PRTOKEN_THREAD_MODEL 323 +#define PRTOKEN_SINGLE_THREADED 324 +#define PRTOKEN_THREAD_PER_CAMERA 325 +#define PRTOKEN_THREAD_PER_RENDER_SURFACE 326 + + + + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) + +typedef union YYSTYPE { + char * string; + int integer; + float real; + bool boolean; +} YYSTYPE; +/* Line 1249 of yacc.c. */ + +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +extern YYSTYPE ConfigParser_lval; + + + diff --git a/src/osgPlugins/cfg/ConfigParser.y b/src/osgPlugins/cfg/ConfigParser.y new file mode 100644 index 000000000..162daf168 --- /dev/null +++ b/src/osgPlugins/cfg/ConfigParser.y @@ -0,0 +1,654 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + + +%{ + +#ifndef WIN32 +#include +#include +#include +#include +#endif + +#ifndef WIN32 +#define SUPPORT_CPP 1 +#endif + +#include +#include +#include + +#include "FlexLexer.h" + +#include + + +using namespace std; +using namespace Producer; + +static void ConfigParser_error( const char * ); +static CameraConfig *cfg = 0L; +static std::string fileName = "(stdin)"; + +static yyFlexLexer *flexer = 0L; + +static int yylex() +{ + if( flexer == 0L ) + fprintf( stderr, "Internal error!\n" ); + return flexer->yylex(); +} + +%} + +%token PRTOKEN_VISUAL +%token PRTOKEN_SET_SIMPLE +%token PRTOKEN_VISUAL_ID +%token PRTOKEN_BUFFER_SIZE +%token PRTOKEN_LEVEL +%token PRTOKEN_RGBA +%token PRTOKEN_DOUBLEBUFFER +%token PRTOKEN_STEREO +%token PRTOKEN_AUX_BUFFERS +%token PRTOKEN_RED_SIZE +%token PRTOKEN_GREEN_SIZE +%token PRTOKEN_BLUE_SIZE +%token PRTOKEN_ALPHA_SIZE +%token PRTOKEN_DEPTH_SIZE +%token PRTOKEN_STENCIL_SIZE +%token PRTOKEN_ACCUM_RED_SIZE +%token PRTOKEN_ACCUM_GREEN_SIZE +%token PRTOKEN_ACCUM_BLUE_SIZE +%token PRTOKEN_ACCUM_ALPHA_SIZE +%token PRTOKEN_ACCUM_ALPHA_SIZE +%token PRTOKEN_SAMPLES +%token PRTOKEN_SAMPLE_BUFFERS +%token PRTOKEN_RENDER_SURFACE +%token PRTOKEN_WINDOW_RECT +%token PRTOKEN_INPUT_RECT +%token PRTOKEN_HOSTNAME +%token PRTOKEN_DISPLAY +%token PRTOKEN_SCREEN +%token PRTOKEN_BORDER +%token PRTOKEN_DRAWABLE_TYPE +%token PRTOKEN_WINDOW_TYPE +%token PRTOKEN_PBUFFER_TYPE +%token PRTOKEN_CAMERA_GROUP +%token PRTOKEN_CAMERA +%token PRTOKEN_PROJECTION_RECT +%token PRTOKEN_LENS +%token PRTOKEN_FRUSTUM +%token PRTOKEN_PERSPECTIVE +%token PRTOKEN_ORTHO +%token PRTOKEN_OFFSET +%token PRTOKEN_ROTATE +%token PRTOKEN_TRANSLATE +%token PRTOKEN_SCALE +%token PRTOKEN_SHEAR +%token PRTOKEN_CLEAR_COLOR +%token PRTOKEN_INPUT_AREA +%token PRTOKEN_ERROR +%token PRTOKEN_INTEGER +%token PRTOKEN_HEX_INTEGER +%token PRTOKEN_FLOAT +%token PRTOKEN_TRUE +%token PRTOKEN_FALSE +%token PRTOKEN_QUOTED_STRING +%token PRTOKEN_STEREO_SYSTEM_COMMANDS +%token PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE +%token PRTOKEN_METHOD +%token PRTOKEN_PREMULTIPLY +%token PRTOKEN_POSTMULTIPLY +%token PRTOKEN_OVERRIDE_REDIRECT +%token PRTOKEN_SHARELENS +%token PRTOKEN_SHAREVIEW +%token PRTOKEN_READ_DRAWABLE +%token PRTOKEN_SET_RTT_MODE +%token PRTOKEN_RTT_MODE_NONE +%token PRTOKEN_RTT_MODE_RGB +%token PRTOKEN_RTT_MODE_RGBA +%token PRTOKEN_THREAD_MODEL +%token PRTOKEN_SINGLE_THREADED +%token PRTOKEN_THREAD_PER_CAMERA +%token PRTOKEN_THREAD_PER_RENDER_SURFACE + +%union { + char * string; + int integer; + float real; + bool boolean; +}; + +%type name string; +%type intparam offset_multiply_method; +%type hex_integer; +%type drawableType rtt_mode; +%type threadModelDirective; +%type floatparam; +%type real; +%type bool; + +%% + +config : entries + ; + +entries : entry | entries entry + ; + +entry : visual | render_surface | camera | input_area | camera_group | stereo_param | system_params + ; + +system_params : system_param | system_params system_param + ; + +system_param : + PRTOKEN_THREAD_MODEL threadModelDirective ';' + { + Producer::CameraGroup::ThreadModel tm = (Producer::CameraGroup::ThreadModel)$2; + cfg->setThreadModelDirective( tm ); + } + ; + +threadModelDirective: + PRTOKEN_SINGLE_THREADED { $$ = CameraGroup::SingleThreaded; } + | PRTOKEN_THREAD_PER_CAMERA { $$ = CameraGroup::ThreadPerCamera; } + | PRTOKEN_THREAD_PER_RENDER_SURFACE { $$ = CameraGroup::ThreadPerRenderSurface; } + ; + +stereo_param : PRTOKEN_STEREO_SYSTEM_COMMANDS intparam string string ';' + { + cfg->addStereoSystemCommand( $2, $3, $4 ); + }; + + +camera_group: PRTOKEN_CAMERA_GROUP '{' camera_group_attributes '}' + ; + +camera_group_attributes: cameras + ; + +cameras : /* null */ | camera | cameras camera + ; + +camera : PRTOKEN_CAMERA name + { + cfg->beginCamera( $2 ); + } + '{' camera_attributes '}' + { + cfg->endCamera(); + }; + +camera_attributes : camera_attribute | camera_attributes camera_attribute + ; + +camera_attribute : + /* EMPTY */ + | PRTOKEN_RENDER_SURFACE name ';' + { + cfg->setCameraRenderSurface( $2 ); + } + | render_surface + { + cfg->setCameraRenderSurface(); + } + | PRTOKEN_PROJECTION_RECT real real real real ';' + { + cfg->setCameraProjectionRectangle( $2, $3, $4, $5 ); + } + | PRTOKEN_SHARELENS bool ';' + { + cfg->setCameraShareLens( $2 ); + } + | PRTOKEN_SHAREVIEW bool ';' + { + cfg->setCameraShareView( $2 ); + } + | PRTOKEN_CLEAR_COLOR real real real real ';' + { + cfg->setCameraClearColor( $2, $3, $4, $5 ); + } + | lens + | camera_offset + ; + +camera_offset : PRTOKEN_OFFSET '{' + { + cfg->beginCameraOffset(); + } + camera_offset_attributes '}' + { + cfg->endCameraOffset(); + } + ; + +camera_offset_attributes : camera_offset_attribute | camera_offset_attributes camera_offset_attribute + ; + +camera_offset_attribute : + PRTOKEN_SHEAR real real ';' + { + cfg->shearCameraOffset( $2, $3 ); + } + | PRTOKEN_ROTATE real real real real ';' + { + cfg->rotateCameraOffset( $2, $3, $4, $5 ); + } + | PRTOKEN_TRANSLATE real real real ';' + { + cfg->translateCameraOffset( $2, $3, $4 ); + } + | PRTOKEN_SCALE real real real ';' + { + cfg->scaleCameraOffset( $2, $3, $4 ); + } + | PRTOKEN_METHOD offset_multiply_method ';' + { + cfg->setCameraOffsetMultiplyMethod( (Producer::Camera::Offset::MultiplyMethod)$2 ); + } + ; + +offset_multiply_method: + PRTOKEN_PREMULTIPLY { $$ = Producer::Camera::Offset::PreMultiply; } + | PRTOKEN_POSTMULTIPLY { $$ = Producer::Camera::Offset::PostMultiply; } + ; + +lens : PRTOKEN_LENS '{' lens_attributes '}' + ; + +lens_attributes : lens_attribute | lens_attributes lens_attribute + ; + +lens_attribute : + /* Empty */ + | PRTOKEN_ORTHO real real real real real real ';' + { + cfg->setCameraOrtho( $2, $3, $4, $5, $6, $7 ); + } + | PRTOKEN_ORTHO real real real real real real real real ';' + { + cfg->setCameraOrtho( $2, $3, $4, $5, $6, $7, $8, $9 ); + } + | PRTOKEN_PERSPECTIVE real real real real ';' + { + cfg->setCameraPerspective( $2, $3, $4, $5 ); + } + | PRTOKEN_PERSPECTIVE real real real real real real ';' + { + cfg->setCameraPerspective( $2, $3, $4, $5, $6, $7 ); + } + | PRTOKEN_FRUSTUM real real real real real real ';' + { + cfg->setCameraFrustum( $2, $3, $4, $5, $6, $7 ); + } + | PRTOKEN_FRUSTUM real real real real real real real real ';' + { + cfg->setCameraFrustum( $2, $3, $4, $5, $6, $7, $8, $9 ); + } + | PRTOKEN_SHEAR real real ';' + { + cfg->setCameraLensShear( $2, $3 ); + } + ; + +render_surface : PRTOKEN_RENDER_SURFACE name + { + cfg->beginRenderSurface( $2 ); + } + '{' render_surface_attributes '}' + { + cfg->endRenderSurface(); + } + ; + +render_surface_attributes : + render_surface_attribute + | render_surface_attributes render_surface_attribute + ; + +render_surface_attribute : + /* Empty */ + | PRTOKEN_VISUAL name ';' + { + cfg->setRenderSurfaceVisualChooser( $2 ); + } + | visual + { + cfg->setRenderSurfaceVisualChooser(); + } + | PRTOKEN_WINDOW_RECT intparam intparam intparam intparam ';' + { + cfg->setRenderSurfaceWindowRectangle( $2, $3, $4, $5 ); + } + | PRTOKEN_INPUT_RECT floatparam floatparam floatparam floatparam ';' + { + cfg->setRenderSurfaceInputRectangle( $2, $3, $4, $5 ); + } + | PRTOKEN_HOSTNAME name ';' + { + cfg->setRenderSurfaceHostName( std::string($2) ); + } + | PRTOKEN_DISPLAY intparam ';' + { + cfg->setRenderSurfaceDisplayNum( $2 ); + } + | PRTOKEN_SCREEN intparam ';' + { + cfg->setRenderSurfaceScreen( $2 ); + } + | PRTOKEN_BORDER bool ';' + { + cfg->setRenderSurfaceBorder( $2 ); + } + | PRTOKEN_CUSTOM_FULL_SCREEN_RECTANGLE intparam intparam intparam intparam ';' + { + cfg->setRenderSurfaceCustomFullScreenRectangle( $2, $3, $4, $5 ); + } + | PRTOKEN_OVERRIDE_REDIRECT bool ';' + { + cfg->setRenderSurfaceOverrideRedirect( $2 ); + } + | PRTOKEN_DRAWABLE_TYPE drawableType ';' + { + Producer::RenderSurface::DrawableType drawableType = (RenderSurface::DrawableType)$2; + cfg->setRenderSurfaceDrawableType( drawableType ); + } + | PRTOKEN_READ_DRAWABLE name ';' + { + cfg->setRenderSurfaceReadDrawable( $2 ); + } + | PRTOKEN_SET_RTT_MODE rtt_mode ';' + { + cfg->setRenderSurfaceRenderToTextureMode( (Producer::RenderSurface::RenderToTextureMode)$2 ); + } + ; + +drawableType: + PRTOKEN_WINDOW_TYPE { $$ = RenderSurface::DrawableType_Window; } + | PRTOKEN_PBUFFER_TYPE { $$ = RenderSurface::DrawableType_PBuffer; } + ; + +rtt_mode : + PRTOKEN_RTT_MODE_NONE { $$ = RenderSurface::RenderToTextureMode_None; } + | PRTOKEN_RTT_MODE_RGB { $$ = RenderSurface::RenderToRGBTexture; } + | PRTOKEN_RTT_MODE_RGBA { $$ = RenderSurface::RenderToRGBATexture; } + ; + + +visual : PRTOKEN_VISUAL name + { + cfg->beginVisual( $2 ); + } + '{' visual_attributes '}' + { + cfg->endVisual(); + } + + | PRTOKEN_VISUAL + { + cfg->beginVisual(); + } + '{' visual_attributes '}' + { + cfg->endVisual(); + } + ; + + +visual_attributes : visual_attribute | visual_attributes ',' visual_attribute + ; +visual_attribute : + PRTOKEN_SET_SIMPLE + { + cfg->setVisualSimpleConfiguration(); + } + | PRTOKEN_VISUAL_ID hex_integer + { + cfg->setVisualByID( $2 ); + } + + | PRTOKEN_BUFFER_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::BufferSize, $2 ); + } + | PRTOKEN_LEVEL intparam + { + cfg->addVisualAttribute( VisualChooser::Level, $2 ); + } + + | PRTOKEN_RGBA + { + cfg->addVisualAttribute( VisualChooser::RGBA ); + } + | PRTOKEN_DOUBLEBUFFER + { + cfg->addVisualAttribute( VisualChooser::DoubleBuffer ); + } + | PRTOKEN_STEREO + { + cfg->addVisualAttribute( VisualChooser::Stereo ); + } + | PRTOKEN_AUX_BUFFERS intparam + { + cfg->addVisualAttribute( VisualChooser::AuxBuffers, $2 ); + } + | PRTOKEN_RED_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::RedSize, $2 ); + } + + | PRTOKEN_GREEN_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::GreenSize, $2 ); + } + + | PRTOKEN_BLUE_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::BlueSize, $2 ); + } + | PRTOKEN_ALPHA_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::AlphaSize, $2 ); + } + | PRTOKEN_DEPTH_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::DepthSize, $2 ); + } + | PRTOKEN_STENCIL_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::StencilSize, $2 ); + } + | PRTOKEN_ACCUM_RED_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::AccumRedSize, $2 ); + } + | PRTOKEN_ACCUM_GREEN_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::AccumGreenSize, $2 ); + } + | PRTOKEN_ACCUM_BLUE_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::AccumBlueSize, $2 ); + } + | PRTOKEN_ACCUM_ALPHA_SIZE intparam + { + cfg->addVisualAttribute( VisualChooser::AccumAlphaSize, $2 ); + } + | PRTOKEN_SAMPLES intparam + { + cfg->addVisualAttribute( VisualChooser::Samples, $2 ); + } + | PRTOKEN_SAMPLE_BUFFERS + { + cfg->addVisualAttribute( VisualChooser::SampleBuffers ); + } + | intparam intparam + { + cfg->addVisualExtendedAttribute( $1, $2 ); + } + ; + +input_area : PRTOKEN_INPUT_AREA + { cfg->beginInputArea(); } + '{' input_area_entries '}' + { cfg->endInputArea(); } + ; + +input_area_entries : input_area_entry | input_area_entries input_area_entry + ; + +input_area_entry : + PRTOKEN_RENDER_SURFACE name ';' + { + cfg->addInputAreaEntry( $2 ); + } + ; + +real : PRTOKEN_FLOAT + { + $$ = atof(flexer->YYText()); + } + | PRTOKEN_INTEGER + { + $$ = atof(flexer->YYText()); + } + ; + + +floatparam : PRTOKEN_FLOAT + { + $$ = atof(flexer->YYText()); + } + ; + +intparam : PRTOKEN_INTEGER + { + $$ = atoi( flexer->YYText() ); + } + ; + +name : PRTOKEN_QUOTED_STRING + { + $$ = strdup( flexer->YYText() ); + } + ; + +string : PRTOKEN_QUOTED_STRING + { + $$ = strdup( flexer->YYText() ); + } + ; + + +hex_integer : PRTOKEN_HEX_INTEGER + { + int n; + sscanf( flexer->YYText(), "0x%x", &n ); + $$ = n; + } + ; + +bool : PRTOKEN_TRUE { $$ = true;} | PRTOKEN_FALSE { $$ = false; } + ; + +%% + +static void yyerror( const char *errmsg ) +{ + fprintf( stderr, + "CameraConfig::parseFile(\"%s\") : %s - Line %d at or before \"%s\"\n", + fileName.c_str(), + errmsg, + flexer->lineno(), + flexer->YYText() ); +} + +bool CameraConfig::parseFile( const std::string &file ) +{ + fileName.clear(); + + fileName = findFile(file); + + if( fileName.empty() ) + { + fprintf( stderr, "CameraConfig::parseFile() - Can't find file \"%s\".\n", file.c_str() ); + return false; + } + + bool retval = true; + +#if defined (SUPPORT_CPP) + + char *cpp_path = + #if defined(__APPLE__) + "/usr/bin/cpp"; + #else + "/lib/cpp"; + #endif + + if( access( cpp_path, X_OK ) == 0 ) + { + + int pd[2]; + pipe( pd ); + + flexer = new yyFlexLexer; + if( fork() == 0 ) + { + // we don't want to read from the pipe in the child, so close it. + close( pd[0] ); + close( 1 ); + dup( pd[1] ); + + + /* This was here to allow reading a config file from stdin. + * This has never been directly supported, so commenting out. + if( fileName.empty() ) + execlp( cpp_path, "cpp", "-P", 0L ); + else + */ + execlp( cpp_path, "cpp", "-P", fileName.c_str(), 0L ); + + // This should not execute unless an error happens + perror( "execlp" ); + } + else + { + close( pd[1]); + close( 0 ); + dup( pd[0] ); + + cfg = this; + + retval = ConfigParser_parse() == 0 ? true : false; + + // Wait on child process to finish + int stat; + wait( &stat ); + } + } + else +#endif + { + std::ifstream ifs(fileName.c_str()); + flexer = new yyFlexLexer(&ifs); + cfg = this; + retval = ConfigParser_parse() == 0 ? true : false; + ifs.close(); + delete flexer; + } + return retval; +} + diff --git a/src/osgPlugins/cfg/FlexLexer.h b/src/osgPlugins/cfg/FlexLexer.h new file mode 100644 index 000000000..bb588ec34 --- /dev/null +++ b/src/osgPlugins/cfg/FlexLexer.h @@ -0,0 +1,186 @@ +// $Header: /cvs/Producer/Producer/src/FlexLexer.h,v 1.1 2003/04/08 23:01:09 donr Exp $ + +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex + +// Copyright (c) 1993 The Regents of the University of California. +// All rights reserved. +// +// This code is derived from software contributed to Berkeley by +// Kent Williams and Tom Epperly. +// +// Redistribution and use in source and binary forms with or without +// modification are permitted provided that: (1) source distributions retain +// this entire copyright notice and comment, and (2) distributions including +// binaries display the following acknowledgement: ``This product includes +// software developed by the University of California, Berkeley and its +// contributors'' in the documentation or other materials provided with the +// distribution and in all advertising materials mentioning features or use +// of this software. Neither the name of the University nor the names of +// its contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. +// +// If you want to create multiple lexer classes, you use the -P flag +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include +// ... + +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H +#include + +extern "C++" { + +struct yy_buffer_state; +typedef int yy_state_type; + +class FlexLexer { +public: + virtual ~FlexLexer() { } + + const char* YYText() { return yytext; } + int YYLeng() { return yyleng; } + + virtual void + yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; + virtual struct yy_buffer_state* + yy_create_buffer( std::istream* s, int size ) = 0; + virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; + virtual void yyrestart( std::istream* s ) = 0; + + virtual int yylex() = 0; + + // Call yylex with new input/output sources. + int yylex( std::istream* new_in, std::ostream* new_out = 0 ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( std::istream* new_in = 0, + std::ostream* new_out = 0 ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" +}; + +} +#endif + +#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex man page. +#define yyFlexLexerOnce + +class yyFlexLexer : public FlexLexer { +public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 ); + + virtual ~yyFlexLexer(); + + void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); + struct yy_buffer_state* yy_create_buffer( std::istream* s, int size ); + void yy_delete_buffer( struct yy_buffer_state* b ); + void yyrestart( std::istream* s ); + + virtual int yylex(); + virtual void switch_streams( std::istream* new_in, std::ostream* new_out ); + +protected: + virtual int LexerInput( char* buf, int max_size ); + virtual void LexerOutput( const char* buf, int size ); + virtual void LexerError( const char* msg ); + + void yyunput( int c, char* buf_ptr ); + int yyinput(); + + void yy_load_buffer_state(); + void yy_init_buffer( struct yy_buffer_state* b, std::istream* s ); + void yy_flush_buffer( struct yy_buffer_state* b ); + + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; + + void yy_push_state( int new_state ); + void yy_pop_state(); + int yy_top_state(); + + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans( yy_state_type current_state ); + int yy_get_next_buffer(); + + std::istream* yyin; // input source for default LexerInput + std::ostream* yyout; // output sink for default LexerOutput + + struct yy_buffer_state* yy_current_buffer; + + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; + + // Number of characters read into yy_ch_buf. + int yy_n_chars; + + // Points to current character in buffer. + char* yy_c_buf_p; + + int yy_init; // whether we need to initialize + int yy_start; // start state number + + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). + + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; + + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; + + int yy_lp; + int yy_looking_for_trail_begin; + + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; +}; + +#endif diff --git a/src/osgPlugins/cfg/ReaderWriterCFG.cpp b/src/osgPlugins/cfg/ReaderWriterCFG.cpp new file mode 100644 index 000000000..ebf176c9f --- /dev/null +++ b/src/osgPlugins/cfg/ReaderWriterCFG.cpp @@ -0,0 +1,199 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2007 Cedric Pinson + * + * This application is open source and may be redistributed and/or modified + * freely and without restriction, both in commericial and non commericial + * applications, as long as this copyright notice is maintained. + * + * This application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Authors: + * Cedric Pinson + * + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef DATADIR +#define DATADIR "." +#endif // DATADIR + +#include +#include "RenderSurface.h" +#include "CameraConfig.h" +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace osgProducer; +static osg::GraphicsContext::Traits* buildTrait(RenderSurface& rs) +{ + VisualChooser& vc = *rs.getVisualChooser(); + osg::GraphicsContext::Traits* trait = new osg::GraphicsContext::Traits; + for (std::vector::iterator it = vc._visual_attributes.begin(); it != vc._visual_attributes.end(); it++) { + if (it->_attribute == VisualChooser::DoubleBuffer) + trait->doubleBuffer = true; + else if (it->_attribute == VisualChooser::DepthSize) + trait->depth = it->_parameter; + else if (it->_attribute == VisualChooser::RedSize) + trait->red = it->_parameter; + else if (it->_attribute == VisualChooser::BlueSize) + trait->blue = it->_parameter; + else if (it->_attribute == VisualChooser::GreenSize) + trait->green = it->_parameter; + else if (it->_attribute == VisualChooser::AlphaSize) + trait->alpha = it->_parameter; + else + std::cout << it->_attribute << " value " << it->_parameter << std::endl; + } + + trait->windowName = rs.getWindowName(); + trait->x = rs.getWindowOriginX(); + trait->y = rs.getWindowOriginY(); + trait->width = rs.getWindowWidth(); + trait->height = rs.getWindowHeight(); + trait->windowDecoration = rs.usesBorder(); + trait->sharedContext = 0; + + return trait; +} + +static osgViewer::View* load(const std::string& file, const osgDB::ReaderWriter::Options* option) +{ + osg::ref_ptr config = new CameraConfig; + std::cout << "Parse file " << file << std::endl; + config->parseFile(file); + + RenderSurface* rs = 0; + Camera* cm = 0; + std::map > surfaces; + osgViewer::View* _view = new osgViewer::View; + + for (int i = 0; i < (int)config->getNumberOfCameras(); i++) { + cm = config->getCamera(i); + rs = cm->getRenderSurface(); + if (rs->getDrawableType() != osgProducer::RenderSurface::DrawableType_Window) + continue; + osg::ref_ptr traits; + osg::ref_ptr gc; + if (surfaces.find(rs) != surfaces.end()) { + gc = surfaces[rs]; + traits = gc->getTraits(); + } else { + osg::GraphicsContext::Traits* newtraits; + newtraits = buildTrait(*rs); + newtraits->readDISPLAY(); + if (newtraits->displayNum<0) newtraits->displayNum = 0; + gc = osg::GraphicsContext::createGraphicsContext(newtraits); + surfaces[rs] = gc.get(); + traits = gc->getTraits(); + } + + std::cout << rs->getWindowName() << " " << rs->getWindowOriginX() << " " << rs->getWindowOriginY() << " " << rs->getWindowWidth() << " " << rs->getWindowHeight() << std::endl; + + if (gc.valid()) + { + osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."< camera = new osg::Camera; + camera->setGraphicsContext(gc.get()); + + + int x,y; + unsigned int width,height; + cm->applyLens(); + cm->getProjectionRectangle(x, y, width, height); + camera->setViewport(new osg::Viewport(x, y, width, height)); + + GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; + camera->setDrawBuffer(buffer); + camera->setReadBuffer(buffer); + + osg::Matrix projection(cm->getProjectionMatrix()); + + osg::Matrix offset = osg::Matrix::identity(); + cm->setViewByMatrix(offset); + osg::Matrix view = osg::Matrix(cm->getPositionAndAttitudeMatrix()); +#if 1 + std::cout << "Matrix Projection " << projection << std::endl; + std::cout << "Matrix Projection master " << _view->getCamera()->getProjectionMatrix() << std::endl; + // will work only if it's a post multyply in the producer camera + std::cout << "Matrix View " << view << std::endl; +#endif + // setup projection from parent + osg::Matrix offsetProjection = osg::Matrix::inverse(_view->getCamera()->getProjectionMatrix()) * projection; + std::cout << _view->getCamera()->getProjectionMatrix() * offsetProjection << std::endl; + // std::cout << "setViewByMatrix " << offset << std::endl; + + _view->addSlave(camera.get(), offsetProjection, view); +// _view->getCamera()->setProjectionMatrix(projection); //osg::Matrix::identity()); +// _view->addSlave(camera.get(), osg::Matrix::identity(), view); + } + +#if 0 + if (_view->getNumberOfCameras() == 1) { + _view->addSlave(camera.get()); + } +#endif + + std::cout << "done" << std::endl; + return _view; +} + +// +// OSG interface to read/write from/to a file. +// +class ReaderWriterProducerCFG : public osgDB::ReaderWriter { +public: + virtual const char* className() { return "Producer cfg object reader"; } + + virtual bool acceptsExtension(const std::string& extension) const { + return osgDB::equalCaseInsensitive(extension, "cfg"); + } + + virtual ReadResult readObject(const std::string& fileName, const Options* options = NULL) const { + std::string ext = osgDB::getLowerCaseFileExtension(fileName); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + osgDB::FilePathList* filePathList = 0; + if(options) { + filePathList = const_cast(&(options->getDatabasePathList())); + filePathList->push_back(DATADIR); + } + + std::string path = osgDB::findDataFile(fileName); + if(path.empty()) return ReadResult::FILE_NOT_FOUND; + + ReadResult result; + osg::ref_ptr view = load(path, options); + if(! view.valid()) + result = ReadResult("failed to load " + path); + else + result = ReadResult(view.get()); + + osgDB::writeObjectFile(*view,"test.view"); + + if(options && filePathList) + filePathList->pop_back(); + + return result; + } + +}; + + +REGISTER_OSGPLUGIN(cfg, ReaderWriterProducerCFG) diff --git a/src/osgPlugins/cfg/RenderSurface.cpp b/src/osgPlugins/cfg/RenderSurface.cpp new file mode 100644 index 000000000..7e3ec7a0f --- /dev/null +++ b/src/osgPlugins/cfg/RenderSurface.cpp @@ -0,0 +1,689 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#include "RenderSurface.h" + +using namespace std; +using namespace osgProducer; + +const std::string RenderSurface::defaultWindowName = std::string(" *** Producer::RenderSurface *** "); + +const unsigned int RenderSurface::UnknownDimension = 0xFFFFFFFF; +const unsigned int RenderSurface::UnknownAmount = 0xFFFFFFFF; +unsigned int RenderSurface::_numScreens = RenderSurface::UnknownAmount; + +bool RenderSurface::_shareAllGLContexts = false; +//GLContext RenderSurface::_globallySharedGLContext = 0L; + +void RenderSurface::shareAllGLContexts(bool flag) +{ + _shareAllGLContexts = flag; +} + +bool RenderSurface::allGLContextsAreShared() +{ + return _shareAllGLContexts; +} + + +const std::string &RenderSurface::getDefaultWindowName() +{ + return defaultWindowName; +} + +RenderSurface::RenderSurface( void ) +{ + _drawableType = DrawableType_Window; + _hostname = ""; + _displayNum = 0; +// _screen = 0; + _mayFullScreen = true; + _isFullScreen = true; + + // This used to be #ifdefed for the X11 implementation + // but the code is pure C++ and should compile anywhere + // The _dislayNum variable is used by CGL as well. +#if 0 + char *envptr = getenv( "DISPLAY" ); + if( envptr != NULL && *envptr != 0 ) + { + size_t p0 = 0; + size_t p1 = string(envptr).find(":", p0); + _hostname = string(envptr).substr(p0,p1); + p0 = p1+1; + p1 = string(envptr).find(".", p0); + + if( p1 > 0 ) + { + _displayNum = atoi((string(envptr).substr(p0,p1)).c_str()); + p0 = p1+1; + p1 = string(envptr).length() - p0; + if( p1 > 0 ) + _screen = atoi((string(envptr).substr(p0,p1)).c_str()); + } + else if( p1 < string(envptr).length() ) + { + p1 = string(envptr).length(); + _displayNum = atoi((string(envptr).substr(p0,p1)).c_str()); + _screen = 0; + } + } +#endif + _windowLeft = 0; + _windowRight = 1; + _windowBottom = 0; + _windowTop = 1; + _windowX = 0; + _windowY = 0; + _windowWidth = UnknownDimension; + _windowHeight = UnknownDimension; + _screenWidth = UnknownDimension; + _screenHeight = UnknownDimension; + _customFullScreenOriginX = 0; + _customFullScreenOriginY = 0; + _customFullScreenWidth = UnknownDimension; + _customFullScreenHeight = UnknownDimension; + _useCustomFullScreen = false; +#if 0 + _dpy = NULL; + _win = 0; + _parent = 0; + _readDrawableRenderSurface = 0L; + _visualInfo = NULL; + _visualID = 0; + _currentCursor = 0; + _nullCursor = 0; + _defaultCursor = 0; + _windowName = defaultWindowName; + _realized = false; + _useConfigEventThread = true; + _threadReady = new OpenThreads::Barrier(2); + _overrideRedirectFlag = false; + + char *override_envptr = getenv( "PRODUCER_OVERRIDE_REDIRECT" ); + if( override_envptr != NULL && *override_envptr != 0 ) + { + if (strcmp(override_envptr,"true")==0 || strcmp(override_envptr,"True")==0 || strcmp(override_envptr,"TRUE")==0) + { + _overrideRedirectFlag = true; + } + else + { + _overrideRedirectFlag = false; + } + } +#endif + _decorations = true; + _useCursorFlag = true; + + + + + _useDefaultEsc = true; + _checkOwnEvents = true; + _inputRectangle.set( -1.0, 1.0, -1.0, 1.0 ); + _bindInputRectangleToWindowSize = false; + + + _rtt_mode = RenderToTextureMode_None; + //_rtt_mode = RenderToRGBTexture; + _rtt_target = Texture2D; + _rtt_options = RenderToTextureOptions_Default; + _rtt_mipmap = 0; + _rtt_face = PositiveX; + _rtt_dirty_mipmap = true; + _rtt_dirty_face = true; + + +#ifdef _WIN32_IMPLEMENTATION + _ownWindow = true; + _ownVisualChooser = true; + _ownVisualInfo = true; + _hinstance = NULL; + _glcontext = NULL; + _mx = 0; + _my = 0; + _mbutton = 0; +#endif +} + +RenderSurface::~RenderSurface( void ) +{ +#if 0 + cancel(); + + _fini(); + + while (isRunning()) + { + //std::cout << "waiting for RenderSurface to cancel"<block(); + return true; +} + +void RenderSurface::positionPointer( int x, int y ) +{ + _positionPointer(x,y); +} + +void RenderSurface::initThreads() +{ + _initThreads(); +} +#endif + +RenderSurface::RenderToTextureMode RenderSurface::getRenderToTextureMode() const +{ + return _rtt_mode; +} + + +void RenderSurface::setRenderToTextureMode(RenderToTextureMode mode) +{ + _rtt_mode = mode; +} + + +RenderSurface::RenderToTextureTarget RenderSurface::getRenderToTextureTarget() const +{ + return _rtt_target; +} + + +void RenderSurface::setRenderToTextureTarget(RenderToTextureTarget target) +{ + _rtt_target = target; +} + + +RenderSurface::RenderToTextureOptions RenderSurface::getRenderToTextureOptions() const +{ + return _rtt_options; +} + + +void RenderSurface::setRenderToTextureOptions(RenderToTextureOptions options) +{ + _rtt_options = options; +} + +int RenderSurface::getRenderToTextureMipMapLevel() const +{ + return _rtt_mipmap; +} + + +void RenderSurface::setRenderToTextureMipMapLevel(int level) +{ + _rtt_mipmap = level; + _rtt_dirty_mipmap = true; +} + +RenderSurface::CubeMapFace RenderSurface::getRenderToTextureFace() const +{ + return _rtt_face; +} + + +void RenderSurface::setRenderToTextureFace(CubeMapFace face) +{ + _rtt_face = face; + _rtt_dirty_face = true; +} + +const std::vector &RenderSurface::getPBufferUserAttributes() const +{ + return _user_pbattr; +} + +std::vector &RenderSurface::getPBufferUserAttributes() +{ + return _user_pbattr; +} + + + +void RenderSurface::useOverrideRedirect(bool flag) +{ + _overrideRedirectFlag = flag; +} + +bool RenderSurface::usesOverrideRedirect() +{ + return _overrideRedirectFlag; +} + diff --git a/src/osgPlugins/cfg/RenderSurface.h b/src/osgPlugins/cfg/RenderSurface.h new file mode 100644 index 000000000..4ff44f24c --- /dev/null +++ b/src/osgPlugins/cfg/RenderSurface.h @@ -0,0 +1,613 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + + +#ifndef OSGPRODUCER_RENDER_SURFACE +#define OSGPRODUCER_RENDER_SURFACE 1 + +#include +#include +#include + +#include +#include +#include "VisualChooser.h" + +#ifdef _WIN32_IMPLEMENTATION + #include +#endif + +namespace osgProducer { + +/** + \class RenderSurface + \brief A RenderSurface provides a rendering surface for 3D graphics applications. + + A RenderSurface creates a window in a windowing system for the purpose of 3D + rendering. The focus of a RenderSurface differs from a windowing system window + in that it is not a user input/output device, but rather a context and screen area + specifically designed for 3D applications. Consequently, a RenderSurface does not + provide or impose a requirement on the caller to structure the application around + the capturing or handling of events. Further, RenderSurface provides increased + control over the quality of pixel formats. + */ + +class RenderSurface : public osg::Referenced +{ + public : + + static const unsigned int UnknownDimension; + static const unsigned int UnknownAmount; + static unsigned int _numScreens; + + class Callback : public osg::Referenced + { + public: + Callback() {} + virtual void operator()( const RenderSurface & ) = 0; + + protected: + virtual ~Callback() {} + }; + + struct InputRectangle + { + public: + InputRectangle(): _left(-1.0), _bottom(-1.0), _width(2.0), _height(2.0) {} + InputRectangle( float left, float right, float bottom, float top ): + _left(left), _bottom(bottom), _width(right-left), _height(top-bottom) {} + InputRectangle(const InputRectangle &ir) + { + _left = ir._left; + _bottom = ir._bottom; + _width = ir._width; + _height = ir._height; + } + virtual ~InputRectangle() {} + + void set( float left, float right, float bottom, float top ) + { + _left = left; + _bottom = bottom; + _width = right - left; + _height = top - bottom; + } + float left() const { return _left; } + float bottom() const { return _bottom; } + float width() const { return _width; } + float height() const { return _height; } + + protected: + + private: + float _left, _bottom, _width, _height; + }; + + enum DrawableType { + DrawableType_Window, + DrawableType_PBuffer + }; + + + RenderSurface( void ); + + static unsigned int getNumberOfScreens(void); + + void setDrawableType( DrawableType ); + DrawableType getDrawableType(); + void setReadDrawable( RenderSurface *); + RenderSurface* getReadDrawable() { return _readDrawableRenderSurface; } + + void setInputRectangle( const InputRectangle &ir ); + const InputRectangle &getInputRectangle() const; + void bindInputRectangleToWindowSize(bool); + + + /** Set the name of the Host the window is to be created on. + Ignored on Win32*/ + void setHostName( const std::string & ); + + /** + * Get the name of the Host the window is to be created on. + * Ignored on Win32 */ + const std::string& getHostName( void ) const; + + /** + * Set the number of the display the render surface is to + * be created on. In XWindows, this is the number of the + * XServer. Ignored on Win32 */ + void setDisplayNum( int ); + + /** Get the number of the display the render surface is to + * be created on. In XWindows, this is the number of the + * XServer. Ignored on Win32 */ + int getDisplayNum( void ) const; + + /** Set the number of the screen the render surface is to + * be created on. In XWindows, this is the number of the + * XServer. Ignored on Win32 */ + void setScreenNum( int ); + + /** Get the number of the screen the render surface is to + * be created on. In XWindows, this is the number of the + * XServer. Ignored on Win32 */ + int getScreenNum( void ) const; + + /** Get the size of the screen in pixels the render surface + * is to be created on. */ + void getScreenSize( unsigned int &width, unsigned int &height ) const; + + + /** Default window name */ + static const std::string defaultWindowName; + + static const std::string &getDefaultWindowName(); + + /** Set the Window system Window name of the Render Surface */ + void setWindowName( const std::string & ); + /** Get the Window system Window name of the Render Surface */ + const std::string& getWindowName( void ) const; + + /** Set the windowing system rectangle the RenderSurface will + * occupy on the screen. The parameters are given as integers + * in screen space. x and y determine the lower left hand corner + * of the RenderSurface. Width and height are given in screen + * coordinates */ + void setWindowRectangle( int x, int y, unsigned int width, unsigned int height, + bool resize=true ); + /** Get the windowing system rectangle the RenderSurface will + * occupy on the screen. The parameters are given as integers + * in screen space. x and y determine the lower left hand corner + * of the RenderSurface. Width and height are given in screen + * coordinates */ + void getWindowRectangle( int &x, int &y, unsigned int &width, unsigned int &height ) const; + /** Get the X coordinate of the origin of the RenderSurface's window */ + int getWindowOriginX() const; + + /** Get the Y coordinate of the origin of the RenderSurface's window */ + int getWindowOriginY() const; + + /** Get the width of the RenderSurface in windowing system screen coordinates */ + unsigned int getWindowWidth() const; + + /** Get the height of the RenderSurface in windowing system screen coordinates */ + unsigned int getWindowHeight() const; + +#if 0 + /** Explicitely set the Display variable before realization. (X11 only). */ + void setDisplay( Display *dpy ); + /** Get the Display. (X11 only). */ + Display* getDisplay( void ); + /** Get the const Display. (X11 only). */ + const Display* getDisplay( void ) const; + + /** Explicitely set the Windowing system window before realization. */ + void setWindow( const Window win ); + /** Returns the Windowing system handle to the window */ + Window getWindow( void ) const; + + void setGLContext( GLContext ); + /** Returns the OpenGL context */ + GLContext getGLContext( void ) const; + + /** Set the Windowing system's parent window */ + void setParentWindow( Window parent ); + /** Get the Windowing system's parent window */ + Window getParentWindow( void ) const; + +#endif + + void setVisualChooser( VisualChooser *vc ); + VisualChooser *getVisualChooser( void ); + const VisualChooser *getVisualChooser( void ) const; + +#if 0 + void setVisualInfo( VisualInfo *vi ); + VisualInfo *getVisualInfo( void ); + const VisualInfo *getVisualInfo( void ) const; + + /** Returns true if the RenderSurface has been realized, false if not. */ + bool isRealized( void ) const; +#endif + + /** Request the use of a window border. If flag is false, no border will + * appear after realization. If flag is true, the windowing system window + * will be created in default state. */ + void useBorder( bool flag ); + bool usesBorder(); + + /** Use overrideRedirect (X11 only). This bypasses the window manager + * control over the Window. Ignored on Win32 and Mac CGL versions. + * This call will only have effect if called before realize(). Calling + * it subsequent to realize() will issue a warning. */ + void useOverrideRedirect(bool); + bool usesOverrideRedirect(); + + /** Request whether the window should have a visible cursor. If true, the + * windowing system's default cursor will be assigned to the window. If false + * the window will not have a visible cursor. */ + void useCursor( bool flag ); + +#if 0 + /** Set the current window cursor. Producer provides no functionality to create + * cursors. It is the application's responsiblity to create a Cursor using the + * windowing system of choice. setCursor() will simply set a predefined cursor + * as the current Cursor */ + void setCursor( Cursor ); +#endif + void setCursorToDefault(); + + /** Specify whether the RenderSurface should use a separate thread for + * window configuration events. If flag is set to true, then the + * RenderSurface will spawn a new thread to manage events caused by + * resizing the window, mapping or destroying the window. */ + void useConfigEventThread(bool flag); + + /** shareAllGLContexts will share all OpenGL Contexts between render surfaces + * upon realize. This must be called before any call to renderSurface::realize(). + */ + static void shareAllGLContexts(bool); + + /** Returns true or false indicating the the state flag for sharing contexts + * between RenderSurfaces + */ + static bool allGLContextsAreShared(); + +#if 0 + /** Realize the RenderSurface. When realized, all components of the RenderSurface + * not already configured are configured, a window and a graphics context are + * created and made current. If an already existing graphics context is passed + * through "sharedGLContext", then the graphics context created will share certain + * graphics constructs (such as display lists) with "sharedGLContext". */ + bool realize( VisualChooser *vc=NULL, GLContext sharedGLContext=0 ); + + + void addRealizeCallback( Callback *realizeCB ); + void setRealizeCallback( Callback *realizeCB ) { addRealizeCallback(realizeCB); } + + /** Swaps buffers if RenderSurface quality attribute is DoubleBuffered */ + virtual void swapBuffers(void); + + /** Makes the graphics context and RenderSurface current for rendering */ + bool makeCurrent(void) const; + + /** Where supported, sync() will synchronize with the vertical retrace signal of the + * graphics display device. \a divisor specifies the number of vertical retace signals + * to allow before returning. */ + virtual void sync( int divisor=1 ); + + /** Where supported, getRefreshRate() will return the frequency in hz of the vertical + * retrace signal of the graphics display device. If getRefreshRate() returns 0, then + * the underlying support to get the graphics display device's vertical retrace signal + * is not present. */ + unsigned int getRefreshRate() const; + + /** Where supported, initThreads will initialize all graphics components for thread + * safety. InitThreads() should be called before any other calls to Xlib, or OpenGL + * are made, and should always be called when multi-threaded environments are intended. */ + static void initThreads(); + + /** + * Puts the calling thread to sleep until the RenderSurface is realized. Returns true + * if for success and false for failure. + * */ + bool waitForRealize(); + + /** fullScreen(flag). If flag is true, RenderSurface resizes its window to fill the + * entire screen and turns off the border. If false, the window is returned to a size + * previously specified. If previous state specified a border around the window, a + * the border is replaced + * */ + + /** positionPointer(x,y) places the pointer at window coordinates x, y. + */ + void positionPointer( int x, int y ); + + /** set/getUseDefaultEsc is deprecated */ + void setUseDefaultEsc( bool flag ) {_useDefaultEsc = flag; } + bool getUseDefaultEsc() { return _useDefaultEsc; } + + /** map and unmap the window */ + void mapWindow(); + void unmapWindow(); +#endif + void fullScreen( bool flag ); + /** setCustomFullScreenRencangle(x,y,width,height). Programmer may set a customized + * rectangle to be interpreted as "fullscreen" when fullscreen(true) is called. This + * allows configurations that have large virtual screens that span more than one monitor + * to define a "local" full screen for each monitor. + */ + void setCustomFullScreenRectangle( int x, int y, unsigned int width, unsigned int height ); + /** useDefaultFullScreenRetangle(). Sets the application back to using the default + * screen size as fullscreen rather than the custom full screen rectangle + */ + void useDefaultFullScreenRectangle(); + + /** isFullScreen() returns true if the RenderSurface's window fills the entire screen + * and has no border. */ + bool isFullScreen() const { return _isFullScreen; } + + // TEMPORARY PBUFFER RENDER TO TEXTURE SUPPORT + // Temporary PBuffer support for Windows. Somebody got really + // confused and mixed up PBuffers with a renderable texture and + // caused this messy headache. + // These have no meaning in GLX world..... + enum BufferType { + FrontBuffer, + BackBuffer + }; + + enum RenderToTextureMode { + RenderToTextureMode_None, + RenderToRGBTexture, + RenderToRGBATexture + }; + + enum RenderToTextureTarget { + Texture1D, + Texture2D, + TextureCUBE + }; + + enum RenderToTextureOptions { + RenderToTextureOptions_Default = 0, + RequestSpaceForMipMaps = 1, + RequestLargestPBuffer = 2 + }; + + enum CubeMapFace { + PositiveX = 0, + NegativeX = 1, + PositiveY = 2, + NegativeY = 3, + PositiveZ = 4, + NegativeZ = 5 + }; + + /** + * Bind PBuffer content to the currently selected texture. + * This method affects PBuffer surfaces only. */ + void bindPBufferToTexture(BufferType buffer = FrontBuffer) const; + + /** + * Get the render-to-texture mode (PBuffer drawables only). + * This method has no effect if it is called after realize() */ + RenderToTextureMode getRenderToTextureMode() const; + + /** + * Set the render-to-texture mode (PBuffer drawables only). You + * can pass int values different from the constants defined by + * RenderToTextureMode, in which case they will be applied + * directly as parameters to the WGL_TEXTURE_FORMAT attribute. + * This method has no effect if it is called after realize(). */ + void setRenderToTextureMode(RenderToTextureMode mode); + + /** + * Get the render-to-texture target (PBuffer drawables only). + * This method has no effect if it is called after realize(). */ + RenderToTextureTarget getRenderToTextureTarget() const; + + /** + * Set the render-to-texture target (PBuffer drawables only). You + * can pass int values different from the constants defined by + * RenderToTextureTarget, in which case they will be applied + * directly as parameters to the WGL_TEXTURE_TARGET attribute. + * This method has no effect if it is called after realize(). */ + void setRenderToTextureTarget(RenderToTextureTarget target); + + /** + * Get the render-to-texture options (PBuffer drawables only). + * This method has no effect if it is called after realize(). */ + RenderToTextureOptions getRenderToTextureOptions() const; + + /** + * Set the render-to-texture options (PBuffer drawables only). + * You can pass any combination of the constants defined in + * enum RenderToTextureOptions. + * This method has no effect if it is called after realize(). */ + void setRenderToTextureOptions(RenderToTextureOptions options); + + /** + * Get which mipmap level on the target texture will be + * affected by rendering. */ + int getRenderToTextureMipMapLevel() const; + + /** + * Select which mipmap level on the target texture will be + * affected by rendering. This method can be called after the + * PBuffer has been realized. */ + void setRenderToTextureMipMapLevel(int level); + + /** + * Get which face on the target cube map texture will be + * affected by rendering. */ + CubeMapFace getRenderToTextureFace() const; + + /** + * Select which face on the target cube map texture will be + * affected by rendering. This method can be called after the + * PBuffer has been realized. */ + void setRenderToTextureFace(CubeMapFace face); + + // END TEMPORARY PBUFFER RENDER TO TEXTURE SUPPORT + + /** + * Get the (const) vector of user-defined PBuffer attributes. */ + const std::vector &getPBufferUserAttributes() const; + + /** + * Get the vector of user-defined PBuffer attributes. This + * vector will be used to initialize the PBuffer's attribute list.*/ + std::vector &getPBufferUserAttributes(); + + private : + unsigned int _refreshRate; +#ifdef _X11_IMPLEMENTATION + int (*__glxGetRefreshRateSGI)(unsigned int *); + int (*__glxGetVideoSyncSGI)(unsigned int *); + int (*__glxWaitVideoSyncSGI)(int,int,unsigned int *); + void testVSync( void ); +#endif + +#if 0 + bool _checkEvents( Display *); + void _setBorder( bool flag ); + void _setWindowName( const std::string & ); + void _useCursor(bool); + void _setCursor(Cursor); + void _setCursorToDefault(); + void _positionPointer(int x, int y); + void _resizeWindow(); +#endif + bool _overrideRedirectFlag; + protected : + + virtual ~RenderSurface( void ); + // void _useOverrideRedirect( bool ); + + DrawableType _drawableType; + std::string _hostname; + int _displayNum; + float _windowLeft, _windowRight, + _windowBottom, _windowTop; + int _windowX, _windowY; + unsigned int _windowWidth, _windowHeight; + unsigned int _screenWidth, _screenHeight; + bool _useCustomFullScreen; + int _customFullScreenOriginX; + int _customFullScreenOriginY; + unsigned int _customFullScreenWidth; + unsigned int _customFullScreenHeight; + + int _screen; +#if 0 + Display * _dpy; + Window _win; + Window _parent; +#endif + RenderSurface *_readDrawableRenderSurface; + unsigned int _parentWindowHeight; + bool _realized; + osg::ref_ptr< VisualChooser > _visualChooser; +#if 0 + VisualInfo * _visualInfo; + unsigned int _visualID; + GLContext _glcontext; + GLContext _sharedGLContext; + Cursor _currentCursor; + Cursor _nullCursor; + Cursor _defaultCursor; +#endif + bool _decorations; + bool _useCursorFlag; + std::string _windowName; + unsigned int _frameCount; + bool _mayFullScreen; + bool _isFullScreen; + bool _bindInputRectangleToWindowSize; + + + // Temporary "Pbuffer support for Win32 + RenderToTextureMode _rtt_mode; + RenderToTextureTarget _rtt_target; + RenderToTextureOptions _rtt_options; + int _rtt_mipmap; + CubeMapFace _rtt_face; + bool _rtt_dirty_mipmap; + bool _rtt_dirty_face; + +#ifdef _OSX_AGL_IMPLEMENTATION + GLContext _windowGlcontext; + GLContext _fullscreenGlcontext; + CFDictionaryRef _oldDisplayMode; + + bool _captureDisplayOrWindow(); + void _releaseDisplayOrWindow(); +#endif + + // user-defined PBuffer attributes + std::vector _user_pbattr; + + + bool _useConfigEventThread; + bool _checkOwnEvents; + bool _useDefaultEsc; + + InputRectangle _inputRectangle; + + // void _computeScreenSize( unsigned int &width, unsigned int &height ) const; + +#if 0 + bool _createVisualInfo(); + + virtual bool _init(); + virtual void _fini(); + virtual void run(); + + static void _initThreads(); +#endif + +#ifdef _WIN32_IMPLEMENTATION + + class Client : public Producer::Referenced + { + public: + Client(unsigned long mask); + unsigned int mask() { return _mask; } + EventQueue *getQueue() { return q.get(); } + void queue( ref_ptr ev ); + + private : + unsigned int _mask; + Producer::ref_ptr q; + }; + std::vector < Producer::ref_ptr >clients; + void dispatch( ref_ptr ); + + int _ownWindow; + int _ownVisualChooser; + int _ownVisualInfo; + + HDC _hdc; + HINSTANCE _hinstance; + + BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag); + void KillGLWindow(); + + LONG WINAPI proc( Window, UINT, WPARAM, LPARAM ); + static LONG WINAPI s_proc( Window, UINT, WPARAM, LPARAM ); + static std::map registry; + + /* mouse things */ + int _mx, _my; + unsigned int _mbutton; + WNDPROC _oldWndProc; + + +public: + EventQueue * selectInput( unsigned int mask ); + + // if _parent is set, resize the window to + // fill the client area of the parent + void resizeToParent(); +#endif + + static bool _shareAllGLContexts; + +}; + +} + + +#endif + diff --git a/src/osgPlugins/cfg/VisualChooser.cpp b/src/osgPlugins/cfg/VisualChooser.cpp new file mode 100644 index 000000000..6de38a1e3 --- /dev/null +++ b/src/osgPlugins/cfg/VisualChooser.cpp @@ -0,0 +1,744 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#include +#include + +#include "VisualChooser.h" +#include + +using namespace std; +using namespace osgProducer; + + +VisualChooser::VisualChooser( void ) +{ +// _visual_id = 0; +// _vinfo = 0L; + _strictAdherence = false; +} + +VisualChooser::~VisualChooser(void) +{ + clear(); +} + +#if 0 +void VisualChooser::setVisual( VisualInfo *vinfo ) +{ + clear(); + _vinfo = vinfo; +} +#endif +void VisualChooser::resetVisualInfo() +{ +#ifdef _WIN32_IMPLEMENTATION + if (_vinfo != NULL) delete _vinfo; +#endif + +#ifdef _OSX_AGL_IMPLEMENTATION + if(_vinfo != NULL) free(_vinfo); +#endif + + // _vinfo = 0L; +} + +void VisualChooser::addAttribute( AttributeName attribute ) +{ + resetVisualInfo(); + _visual_attributes.push_back( VisualAttribute( attribute ) ); +} + +void VisualChooser::addAttribute( AttributeName attribute, int parameter ) +{ + resetVisualInfo(); + _visual_attributes.push_back( VisualAttribute( attribute, parameter ) ); +} + +void VisualChooser::addExtendedAttribute( unsigned int attribute ) +{ + resetVisualInfo(); + _visual_attributes.push_back( VisualAttribute( attribute ) ); +} + +void VisualChooser::addExtendedAttribute( unsigned int attribute, int parameter ) +{ + resetVisualInfo(); + _visual_attributes.push_back( VisualAttribute( attribute, parameter ) ); +} + +void VisualChooser::setBufferSize( unsigned int size ) +{ + addAttribute( BufferSize, size ); +} + +void VisualChooser::setLevel( int level ) +{ + addAttribute( Level, level ); + +} +void VisualChooser::useRGBA() +{ + addAttribute( RGBA ); +} +void VisualChooser::useDoubleBuffer() +{ + addAttribute( DoubleBuffer ); +} +void VisualChooser::useStereo() +{ + addAttribute( Stereo ); +} + +void VisualChooser::setAuxBuffers( unsigned int num ) +{ + addAttribute( AuxBuffers, num ); +} + +void VisualChooser::setRedSize( unsigned int size ) +{ + addAttribute( RedSize, size ); +} + +void VisualChooser::setGreenSize( unsigned int size ) +{ + addAttribute( GreenSize, size ); +} + +void VisualChooser::setBlueSize( unsigned int size ) +{ + addAttribute( BlueSize, size ); +} + +void VisualChooser::setAlphaSize( unsigned int size ) +{ + addAttribute( AlphaSize, size ); +} + +void VisualChooser::setDepthSize( unsigned int size ) +{ + addAttribute( DepthSize, size ); +} + +void VisualChooser::setStencilSize( unsigned int size ) +{ + addAttribute( StencilSize, size ); +} + +void VisualChooser::setAccumRedSize( unsigned int size ) +{ + addAttribute( AccumRedSize, size ); +} + +void VisualChooser::setAccumGreenSize( unsigned int size ) +{ + addAttribute( AccumGreenSize, size ); +} + +void VisualChooser::setAccumBlueSize( unsigned int size ) +{ + addAttribute( AccumBlueSize, size ); +} + +void VisualChooser::setAccumAlphaSize( unsigned int size ) +{ + addAttribute( AccumAlphaSize, size ); +} + +void VisualChooser::setSamples( unsigned int size ) +{ + addAttribute( Samples, size ); +} + +void VisualChooser::setSampleBuffers( unsigned int size ) +{ + addAttribute( SampleBuffers, size ); +} + +void VisualChooser::setVisualID( unsigned int id ) +{ + _visual_id = id; +} + +void VisualChooser::setSimpleConfiguration( bool doublebuffer ) +{ + clear(); + addAttribute( RGBA ); + addAttribute( DepthSize, 16 ); + if (doublebuffer) + addAttribute( DoubleBuffer ); +} + +void VisualChooser::clear() +{ + _visual_attributes.clear(); + resetVisualInfo(); + + // Always use UseGL + addAttribute( UseGL ); +} + + +#ifdef _OSX_AGL_IMPLEMENTATION +#include + +void VisualChooser::applyAttribute(const VisualAttribute &va, std::vector &attribs) +{ + if(va.isExtension()) + { + attribs.push_back(static_cast(va.attribute())); + } + else + { + switch(va.attribute()) + { + case UseGL: attribs.push_back(AGL_COMPLIANT); break; + case BufferSize: attribs.push_back(AGL_BUFFER_SIZE); break; + case Level: attribs.push_back(AGL_LEVEL); break; + case RGBA: attribs.push_back(AGL_RGBA); break; + case DoubleBuffer: attribs.push_back(AGL_DOUBLEBUFFER); break; + case Stereo: attribs.push_back(AGL_STEREO); break; + case AuxBuffers: attribs.push_back(AGL_AUX_BUFFERS); break; + case RedSize: attribs.push_back(AGL_RED_SIZE); break; + case GreenSize: attribs.push_back(AGL_GREEN_SIZE); break; + case BlueSize: attribs.push_back(AGL_BLUE_SIZE); break; + case AlphaSize: attribs.push_back(AGL_ALPHA_SIZE); break; + case DepthSize: attribs.push_back(AGL_DEPTH_SIZE); break; + case StencilSize: attribs.push_back(AGL_STENCIL_SIZE); break; + case AccumRedSize: attribs.push_back(AGL_ACCUM_RED_SIZE); break; + case AccumGreenSize: attribs.push_back(AGL_ACCUM_GREEN_SIZE); break; + case AccumBlueSize: attribs.push_back(AGL_ACCUM_BLUE_SIZE); break; + case AccumAlphaSize: attribs.push_back(AGL_ACCUM_ALPHA_SIZE); break; +#if defined (AGL_SAMPLE_BUFFERS_ARB) && defined (AGL_SAMPLES_ARB) + case SampleBuffers: attribs.push_back(AGL_SAMPLE_BUFFERS_ARB); break; + case Samples: attribs.push_back(AGL_SAMPLES_ARB); break; +#endif + default: attribs.push_back((int)va.attribute()); break; + } + } + + if (va.hasParameter()) + { + attribs.push_back(va.parameter()); + } +} + +VisualInfo *VisualChooser::choose( Display *dpy, int screen, bool strict_adherence) +{ + if(_vinfo != NULL) + { + // If VisualInfo exists, then we may be able to reuse it + GLint val; + if((*_vinfo) && (aglDescribePixelFormat(*_vinfo, AGL_NO_RECOVERY, &val))) return _vinfo; + } + else + { + // Use malloc() since new() causes a bus error + _vinfo = (VisualInfo*)malloc(sizeof(VisualInfo*)); + } + // Set up basic attributes if needed + if( _visual_attributes.size() == 0 ) setSimpleConfiguration(); + + bool fullscreen = (screen == 1); // Whether to fullscreen or not + std::vector va; // Visual attributes + + va.push_back(AGL_NO_RECOVERY); + if(fullscreen) va.push_back(AGL_FULLSCREEN); + + vector::const_iterator p; + for( p = _visual_attributes.begin(); p != _visual_attributes.end(); p++ ) + { + applyAttribute(*p, va); + } + va.push_back(AGL_NONE); // Must be last element + + // Copy to GLint vector, since this is what the agl functions require + std::vector glva; + std::vector::iterator i; + for(i = va.begin(); i != va.end(); i++) + { + glva.push_back(*i); + } + + if(fullscreen) + { + GDHandle gdhDisplay; + DMGetGDeviceByDisplayID((DisplayIDType)*dpy, &gdhDisplay, false); + *_vinfo = aglChoosePixelFormat(&gdhDisplay, 1, &(glva.front())); + } + else + { + *_vinfo = aglChoosePixelFormat(NULL, 0, &(glva.front())); + } + + if(*_vinfo == NULL) + { + std::cerr<< "aglChoosePixelFormat failed: " << aglGetError() << std::endl; + for(i=va.begin(); i!=va.end(); ++i) + { + std::cerr << (*i) << ", "; + } + std::cerr << std::endl; + } + return _vinfo; +} + +#endif + +#ifdef _OSX_CGL_IMPLEMENTATION +void VisualChooser::applyAttribute(const VisualAttribute &va, std::vector &attribs) +{ + if(va.isExtension()) + { + attribs.push_back(static_cast(va.attribute())); + } + else + { + switch(va.attribute()) + { + case UseGL: attribs.push_back(kCGLPFACompliant); break; + case BufferSize: attribs.push_back(kCGLPFAColorSize); break; + //case Level: attribs.push_back(GLX_LEVEL); break; + //case RGBA: attribs.push_back(GLX_RGBA); break; + case DoubleBuffer: attribs.push_back(kCGLPFADoubleBuffer); break; + case Stereo: attribs.push_back(kCGLPFAStereo); break; + case AuxBuffers: attribs.push_back(kCGLPFAAuxBuffers); break; + case RedSize: attribs.push_back(kCGLPFAColorSize); break; + case GreenSize: attribs.push_back(kCGLPFAColorSize); break; + case BlueSize: attribs.push_back(kCGLPFAColorSize); break; + case AlphaSize: attribs.push_back(kCGLPFAAlphaSize); break; + case DepthSize: attribs.push_back(kCGLPFADepthSize); break; + case StencilSize: attribs.push_back(kCGLPFAStencilSize); break; + case AccumRedSize: attribs.push_back(kCGLPFAAccumSize); break; + case AccumGreenSize: attribs.push_back(kCGLPFAAccumSize); break; + case AccumBlueSize: attribs.push_back(kCGLPFAAccumSize); break; + case AccumAlphaSize: attribs.push_back(kCGLPFAAccumSize); break; + case SampleBuffers: attribs.push_back(kCGLPFASampleBuffers); break; + case Samples: attribs.push_back(kCGLPFASamples); break; + default: attribs.push_back(va.attribute()); break; + } + } + + if (va.hasParameter()) + { + attribs.push_back(va.parameter()); + } +} + +VisualInfo *VisualChooser::choose( Display *dpy, int screen, bool strict_adherence) +{ + if(_vinfo != NULL) + { + // If VisualInfo exists, then we may be able to reuse it + GLint val; + if(!CGLDescribePixelFormat(*_vinfo, 0L, kCGLPFANoRecovery, &val)) + return _vinfo; + } + + // Set up basic attributes if needed + if( _visual_attributes.size() == 0 ) setSimpleConfiguration(); + + u_int32_t display_id = CGDisplayIDToOpenGLDisplayMask(*dpy); + std::vector va; // Visual attributes + + va.push_back(kCGLPFADisplayMask); + va.push_back((CGLPixelFormatAttribute)display_id); + va.push_back(kCGLPFANoRecovery); + va.push_back( kCGLPFAAccelerated ); + va.push_back( kCGLPFAFullScreen ); + + vector::const_iterator p; + for( p = _visual_attributes.begin(); p != _visual_attributes.end(); p++ ) + { + applyAttribute(*p, va); + } + va.push_back(CGLPixelFormatAttribute(0)); // Must be last element + + long nvirt; + CGLPixelFormatAttribute *array = new CGLPixelFormatAttribute[va.size()]; + memcpy(array, &(va.front()), va.size()*sizeof(CGLPixelFormatAttribute)); + CGLError err = CGLChoosePixelFormat(array, _vinfo, &nvirt); + if(err) + { + std::cerr<< "CGLChoosePixelFormat failed: " << CGLErrorString(err) << std::endl; + std::vector::iterator i; + for(i=va.begin(); i!=va.end(); ++i) + { + std::cerr << (*i) << ", "; + } + std::cerr << std::endl; + } + + return _vinfo; +} + +#endif + +#ifdef _X11_IMPLEMENTATION +#include + +void VisualChooser::applyAttribute(const VisualAttribute &va, std::vector &attribs) +{ + if (va.isExtension()) + { + attribs.push_back(static_cast(va.attribute())); + } + else + { + switch (va.attribute()) + { + case UseGL: attribs.push_back(GLX_USE_GL); break; + case BufferSize: attribs.push_back(GLX_BUFFER_SIZE); break; + case Level: attribs.push_back(GLX_LEVEL); break; + case RGBA: attribs.push_back(GLX_RGBA); break; + case DoubleBuffer: attribs.push_back(GLX_DOUBLEBUFFER); break; + case Stereo: attribs.push_back(GLX_STEREO); break; + case AuxBuffers: attribs.push_back(GLX_AUX_BUFFERS); break; + case RedSize: attribs.push_back(GLX_RED_SIZE); break; + case GreenSize: attribs.push_back(GLX_GREEN_SIZE); break; + case BlueSize: attribs.push_back(GLX_BLUE_SIZE); break; + case AlphaSize: attribs.push_back(GLX_ALPHA_SIZE); break; + case DepthSize: attribs.push_back(GLX_DEPTH_SIZE); break; + case StencilSize: attribs.push_back(GLX_STENCIL_SIZE); break; + case AccumRedSize: attribs.push_back(GLX_ACCUM_RED_SIZE); break; + case AccumGreenSize: attribs.push_back(GLX_ACCUM_GREEN_SIZE); break; + case AccumBlueSize: attribs.push_back(GLX_ACCUM_BLUE_SIZE); break; + case AccumAlphaSize: attribs.push_back(GLX_ACCUM_ALPHA_SIZE); break; +#if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) + case SampleBuffers: attribs.push_back(GLX_SAMPLE_BUFFERS); break; + case Samples: attribs.push_back(GLX_SAMPLES); break; +#endif + default: attribs.push_back(static_cast(va.attribute())); break; + } + } + + if (va.hasParameter()) + { + attribs.push_back(va.parameter()); + } +} + + + // we now ignore this... +VisualInfo *VisualChooser::choose( Display *dpy, int screen, bool strict_adherence) +{ + // Visual info was previously forced. + if( _vinfo != NULL ) + return _vinfo; + + if( _visual_id != 0 ) + { + + VisualInfo temp; + long mask = VisualIDMask; + int n; + temp.visualid = _visual_id; + _vinfo = XGetVisualInfo( dpy, mask, &temp, &n ); + + if( _vinfo != NULL || _strictAdherence ) + return _vinfo; + + } + + if( _visual_attributes.size() == 0 ) + setSimpleConfiguration(); + + vector::const_iterator p; + vectorva; + + for( p = _visual_attributes.begin(); p != _visual_attributes.end(); p++ ) + { + applyAttribute(*p, va); + } + va.push_back(0); + + if( _strictAdherence ) + { + _vinfo = glXChooseVisual( dpy, screen, &(va.front()) ); + } + else + { + p = _visual_attributes.end() - 1; + + while( _vinfo == NULL && va.size() > 0) + { + _vinfo = glXChooseVisual( dpy, screen, &(va.front()) ); + if( _vinfo == NULL && va.size() > 0 ) + { + + // should we report an message that we're relaxing constraints here? + // std::cout << "Popping attributes"<= 2 ) + { + va.pop_back(); + va.pop_back(); + } + else + va.pop_back(); + va.push_back(0); // Push a new NULL terminator + if( p == _visual_attributes.begin() ) + break; + p --; + } + } + } + + if( _vinfo != 0L ) + _visual_id = _vinfo->visualid; + else + _visual_id = 0; + + return _vinfo; +} +#endif + +#ifdef _WIN32_IMPLEMENTATION +#include "WGLExtensions.h" + +void VisualChooser::applyAttribute(const VisualAttribute &va, std::vector &attribs) +{ + if (va.attribute() == UseGL) + { + attribs.push_back(WGL_SUPPORT_OPENGL_ARB); + attribs.push_back(1); + attribs.push_back(WGL_ACCELERATION_ARB); + attribs.push_back(WGL_FULL_ACCELERATION_ARB); + return; + } + + if (va.attribute() == DoubleBuffer) + { + attribs.push_back(WGL_DOUBLE_BUFFER_ARB); + attribs.push_back(1); + attribs.push_back(WGL_SWAP_METHOD_ARB); + attribs.push_back(WGL_SWAP_EXCHANGE_ARB); + return; + } + + // please note that *all* WGL attributes must have a parameter! + // to keep compatibility we'll explicitely set a boolean + // parameter value where needed. + + std::pair attr = std::make_pair(static_cast(va.attribute()), va.parameter()); + + switch (va.attribute()) + { + case Level: return; + case BufferSize: attr.first = WGL_COLOR_BITS_ARB; break; + case RGBA: attr.first = WGL_PIXEL_TYPE_ARB; attr.second = WGL_TYPE_RGBA_ARB; break; + case Stereo: attr.first = WGL_STEREO_ARB; attr.second = 1; break; + case AuxBuffers: attr.first = WGL_AUX_BUFFERS_ARB; break; + case RedSize: attr.first = WGL_RED_BITS_ARB; break; + case GreenSize: attr.first = WGL_GREEN_BITS_ARB; break; + case BlueSize: attr.first = WGL_BLUE_BITS_ARB; break; + case AlphaSize: attr.first = WGL_ALPHA_BITS_ARB; break; + case DepthSize: attr.first = WGL_DEPTH_BITS_ARB; break; + case StencilSize: attr.first = WGL_STENCIL_BITS_ARB; break; + case AccumRedSize: attr.first = WGL_ACCUM_RED_BITS_ARB; break; + case AccumGreenSize: attr.first = WGL_ACCUM_GREEN_BITS_ARB; break; + case AccumBlueSize: attr.first = WGL_ACCUM_BLUE_BITS_ARB; break; + case AccumAlphaSize: attr.first = WGL_ACCUM_ALPHA_BITS_ARB; break; +#if defined(WGL_SAMPLE_BUFFERS_ARB) && defined (WGL_SAMPLES_ARB) + case SampleBuffers: attr.first = WGL_SAMPLE_BUFFERS_ARB; break; + case Samples: attr.first = WGL_SAMPLES_ARB; break; +#endif + default: ; + } + + attribs.push_back(attr.first); + attribs.push_back(attr.second); +} + +VisualInfo *VisualChooser::choose( Display *dpy, int screen, bool strict_adherence) +{ + if (_vinfo) + return _vinfo; + + if (_visual_attributes.empty()) + setSimpleConfiguration(); + + int vid; + bool failed = false; + + WGLExtensions *ext = WGLExtensions::instance(); + if (ext && ext->isSupported(WGLExtensions::ARB_pixel_format)) + { + do + { + std::vector attribs; + for (std::vector::const_iterator i=_visual_attributes.begin(); i!=_visual_attributes.end(); ++i) + applyAttribute(*i, attribs); + attribs.push_back(0); + + unsigned int num_formats; + failed = !ext->wglChoosePixelFormat(*dpy, &attribs.front(), 0, 1, &vid, &num_formats) || num_formats == 0; + if (failed) + { + // **** DRIVER BUG? It seems that some ATI cards don't support + // **** the WGL_SWAP_METHOD_ARB attribute. Now we try to remove + // **** it from the attribute list and choose a pixel format again. + for (std::vector::iterator k=attribs.begin(); k!=attribs.end(); ++k) + { + if (*k == WGL_SWAP_METHOD_ARB) + { + // attribute come in sequential attribute,paramter pairs + // as WGL specifications so we need to delete two entries + attribs.erase(k,k+2); + break; + } + } + + failed = !ext->wglChoosePixelFormat(*dpy, &attribs.front(), 0, 1, &vid, &num_formats) || num_formats == 0; + } + + if (failed) + { + if (strict_adherence || _visual_attributes.empty()) + break; + + std::cerr << "Producer::VisualChooser: the requested visual is not available, trying to relax attributes..." << std::endl; + _visual_attributes.pop_back(); + } + + } while (failed); + } + + if (failed || !ext || !ext->isSupported(WGLExtensions::ARB_pixel_format)) + { + std::cerr << "Producer::VisualChooser: unable to setup a valid visual with WGL extensions, switching to compatibility mode" << std::endl; + + failed = false; + do + { + PIXELFORMATDESCRIPTOR pfd; + ZeroMemory(&pfd, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW; + pfd.iLayerType = PFD_MAIN_PLANE; + + for (std::vector::const_iterator i=_visual_attributes.begin(); i!=_visual_attributes.end(); ++i) + { + if (i->attribute() == UseGL) pfd.dwFlags |= PFD_SUPPORT_OPENGL; + if (i->attribute() == DoubleBuffer) pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_EXCHANGE; + if (i->attribute() == Stereo) pfd.dwFlags |= PFD_STEREO; + if (i->attribute() == RGBA) pfd.iPixelType = PFD_TYPE_RGBA; + if (i->attribute() == BufferSize) pfd.cColorBits = i->parameter(); + if (i->attribute() == RedSize) pfd.cRedBits = i->parameter(); + if (i->attribute() == GreenSize) pfd.cGreenBits = i->parameter(); + if (i->attribute() == BlueSize) pfd.cBlueBits = i->parameter(); + if (i->attribute() == AlphaSize) pfd.cAlphaBits = i->parameter(); + if (i->attribute() == AccumRedSize) pfd.cAccumRedBits = i->parameter(); + if (i->attribute() == AccumGreenSize) pfd.cAccumGreenBits = i->parameter(); + if (i->attribute() == AccumBlueSize) pfd.cAccumBlueBits = i->parameter(); + if (i->attribute() == AccumAlphaSize) pfd.cAccumAlphaBits = i->parameter(); + if (i->attribute() == DepthSize) pfd.cDepthBits = i->parameter(); + if (i->attribute() == StencilSize) pfd.cStencilBits = i->parameter(); + if (i->attribute() == AuxBuffers) pfd.cAuxBuffers = i->parameter(); + } + + pfd.cAccumBits = pfd.cAccumRedBits + pfd.cAccumGreenBits + pfd.cAccumBlueBits + pfd.cAccumAlphaBits; + + vid = ChoosePixelFormat(*dpy, &pfd); + if ( vid != 0 ) + { + // Is this additional check neccessary ? + // Did anyone encountered a situation where + // ChoosePixelFormat returned PXIELFORMAT worse than required ? + _visual_id = static_cast(vid); + VisualInfo pfd; + DescribePixelFormat(*dpy, _visual_id, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + bool boolOK = true; + for (std::vector::const_iterator i=_visual_attributes.begin(); i!=_visual_attributes.end(); ++i) + { + if (i->attribute() == UseGL) boolOK &= !!( pfd.dwFlags & PFD_SUPPORT_OPENGL ); + if (i->attribute() == DoubleBuffer) boolOK &= !!( pfd.dwFlags & ( PFD_DOUBLEBUFFER | PFD_SWAP_EXCHANGE ) ); + if (i->attribute() == Stereo) boolOK &= !!( pfd.dwFlags & PFD_STEREO ); + if (i->attribute() == RGBA) boolOK &= pfd.iPixelType == PFD_TYPE_RGBA; + if (i->attribute() == BufferSize) boolOK &= pfd.cColorBits >= i->parameter(); + if (i->attribute() == RedSize) boolOK &= pfd.cRedBits >= i->parameter(); + if (i->attribute() == GreenSize) boolOK &= pfd.cGreenBits >= i->parameter(); + if (i->attribute() == BlueSize) boolOK &= pfd.cBlueBits >= i->parameter(); + if (i->attribute() == AlphaSize) boolOK &= pfd.cAlphaBits >= i->parameter(); + if (i->attribute() == AccumRedSize) boolOK &= pfd.cAccumRedBits >= i->parameter(); + if (i->attribute() == AccumGreenSize) boolOK &= pfd.cAccumGreenBits >= i->parameter(); + if (i->attribute() == AccumBlueSize) boolOK &= pfd.cAccumBlueBits >= i->parameter(); + if (i->attribute() == AccumAlphaSize) boolOK &= pfd.cAccumAlphaBits >= i->parameter(); + if (i->attribute() == DepthSize) boolOK &= pfd.cDepthBits >= i->parameter(); + if (i->attribute() == StencilSize) boolOK &= pfd.cStencilBits >= i->parameter(); + if (i->attribute() == AuxBuffers) boolOK &= pfd.cAuxBuffers >= i->parameter(); + } + if ( !boolOK ) + vid = 0; + } + + if( vid == 0 ) + { + failed = true; + if (strict_adherence || _visual_attributes.empty()) + break; + + std::cerr << "Producer::VisualChooser: the requested visual is not available, trying to relax attributes..." << std::endl; + _visual_attributes.pop_back(); + } + + } while (failed); + + } + + if (failed) + { + std::cerr << "Producer::VisualChooser: could not choose the pixel format" << std::endl; + return 0; + } + + _visual_id = static_cast(vid); + + // we set _vinfo for compatibility, but it's going to be unused + // because the pixel format is usually chosen by visual ID rather + // than by descriptor. + _vinfo = new VisualInfo; + DescribePixelFormat(*dpy, _visual_id, sizeof(PIXELFORMATDESCRIPTOR), _vinfo); + + return _vinfo; +} + +#endif + +#if 0 +unsigned int VisualChooser::getVisualID() const +{ + return 0; +} + +bool VisualChooser::getStrictAdherence() +{ + return _strictAdherence; +} + +void VisualChooser::setStrictAdherence(bool strictAdherence) +{ + _strictAdherence = strictAdherence; +} +#endif + +bool VisualChooser::isDoubleBuffer() const +{ + for (std::vector::const_iterator i=_visual_attributes.begin(); i!=_visual_attributes.end(); ++i) + if (i->attribute() == DoubleBuffer) + return true; + + return false; +} diff --git a/src/osgPlugins/cfg/VisualChooser.h b/src/osgPlugins/cfg/VisualChooser.h new file mode 100644 index 000000000..85e160ad9 --- /dev/null +++ b/src/osgPlugins/cfg/VisualChooser.h @@ -0,0 +1,207 @@ +/* -*-c++-*- Producer - Copyright (C) 2001-2004 Don Burns + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + */ + +#ifndef OSGPRODUCER_VISUAL_CHOOSER +#define OSGPRODUCER_VISUAL_CHOOSER 1 + +#include + +#include + + +namespace osgProducer { + +class VisualChooser : public osg::Referenced +{ + public : + VisualChooser( void ); + + enum AttributeName { + UseGL, + BufferSize, + Level, + RGBA, + DoubleBuffer, + Stereo, + AuxBuffers, + RedSize, + GreenSize, + BlueSize, + AlphaSize, + DepthSize, + StencilSize, + AccumRedSize, + AccumGreenSize, + AccumBlueSize, + AccumAlphaSize, + Samples, + SampleBuffers + }; +#if 0 + //------------------------------------------------------------------------- + // Explicitely set the visual info pointer. This will override the use of + // glXChooseVisual(). Useful for functions requiring a VisualChooser + // argument, but not a XVisualInfo. + void setVisual( VisualInfo *vinfo ); +#endif + //------------------------------------------------------------------------- + // Chooses a minimal set of parameters + void setSimpleConfiguration(bool doublebuffer = true); + + //------------------------------------------------------------------------- + // Clear the list of parameters + void clear() ; + + //------------------------------------------------------------------------- + // Generic method for adding an attribute without a parameter + // (e.g DoubleBuffer ) + void addAttribute( AttributeName attribute ); + + //------------------------------------------------------------------------- + // Generic method for adding an attribute with a parameter + // (e.g DepthSize, 1 ) + void addAttribute( AttributeName attribute, int parameter ); + + //------------------------------------------------------------------------- + // Generic method for adding an attribute without a parameter + // (e.g DoubleBuffer ) + void addExtendedAttribute( unsigned int attribute ); + + //------------------------------------------------------------------------- + // Generic method for adding an extended attribute with a parameter + // (e.g DepthSize, 1 ) + void addExtendedAttribute( unsigned int attribute, int parameter ); + + //------------------------------------------------------------------------- + // The following method returns whether double buffering is being used + bool isDoubleBuffer() const; + + //------------------------------------------------------------------------- + // The following methods set attributes explicitely + // + void setBufferSize( unsigned int size ); + + void setLevel( int level ); + + void useRGBA(); + + void useDoubleBuffer(); + + void useStereo(); + + void setAuxBuffers( unsigned int num ); + + void setRedSize( unsigned int size ); + + void setGreenSize( unsigned int size ); + + void setBlueSize( unsigned int size ); + + void setAlphaSize( unsigned int size ); + + void setDepthSize( unsigned int size ); + + void setStencilSize( unsigned int size ); + + void setAccumRedSize( unsigned int size ); + + void setAccumGreenSize( unsigned int size ); + + void setAccumBlueSize( unsigned int size ); + + void setAccumAlphaSize( unsigned int size ); + + void setSampleBuffers( unsigned int size ); + + void setSamples( unsigned int size ); + + void setVisualID( unsigned int id ); + + +#if 0 + //------------------------------------------------------------------------- + // Chooses visual based on previously selected attributes and parameters + // dpy = Conection to Xserver as returned by XOpenDisplay() + // screen = XServer screen (Could be DefaultScreen(dpy)) + // strict_adherence = If true, return NULL visual info if the set of + // parameters is not matched verbatim. If set to + // false, choose() will attempt to find a visual that + // matches as much of the attribute list as possible + // + // Important Note : An attribute is removed from the end + // of the list before each retry, implying that the + // attribute list should be specified in priority order, + // most important attriutes first. + // + + VisualInfo *choose( Display *dpy, int screen, bool strict_adherence=false); + + unsigned int getVisualID() const; + + bool getStrictAdherence(); + void setStrictAdherence(bool); +#endif + + protected: + ~VisualChooser(void); + + public : + + struct VisualAttribute + { + unsigned int _attribute; + bool _has_parameter; + int _parameter; + bool _is_extension; + + VisualAttribute( AttributeName attribute, int parameter ) : + _attribute(attribute), + _has_parameter(true), + _parameter(parameter), + _is_extension(false) {} + + VisualAttribute( AttributeName attribute ) : + _attribute(attribute), + _has_parameter(false), + _parameter(0), + _is_extension(false) {} + + VisualAttribute( unsigned int attribute, int parameter ) : + _attribute(attribute), + _has_parameter(true), + _parameter(parameter), + _is_extension(true) {} + + VisualAttribute( unsigned int attribute ) : + _attribute(attribute), + _has_parameter(false), + _parameter(0), + _is_extension(true) {} + + unsigned int attribute() const { return _attribute; } + bool hasParameter() const { return _has_parameter; } + int parameter() const { return _parameter; } + bool isExtension() const { return _is_extension; } + }; + + void applyAttribute(const VisualAttribute &va, std::vector &attribs); + void resetVisualInfo(); + + std::vector _visual_attributes; +// VisualInfo *_vinfo; + unsigned int _visual_id; + bool _strictAdherence; +}; + +} +#endif