Adding support for controlling visual settings via environmental variables
and command line paramters. Including support for stereo and stencil buffer.
This commit is contained in:
57
include/osg/ColorMatrix
Normal file
57
include/osg/ColorMatrix
Normal file
@@ -0,0 +1,57 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_COLORMATRIX
|
||||
#define OSG_COLORMATRIX 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Matrix>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture Matrix state class for encapsulating OpenGL texture matrix functionality.*/
|
||||
class SG_EXPORT ColorMatrix : public StateAttribute
|
||||
{
|
||||
public :
|
||||
ColorMatrix( void );
|
||||
|
||||
META_StateAttribute(ColorMatrix, COLORMATRIX);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(ColorMatrix,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_matrix)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
/** Set the color matrix */
|
||||
inline void setMatrix(const Matrix& matrix) { _matrix = matrix; }
|
||||
|
||||
/** Get the color matrix */
|
||||
inline Matrix& getMatrix() { return _matrix; }
|
||||
|
||||
/** Get the const color matrix */
|
||||
inline const Matrix& getMatrix() const { return _matrix; }
|
||||
|
||||
/** apply as OpenGL texture matrix.*/
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ColorMatrix( void );
|
||||
|
||||
Matrix _matrix;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/Camera>
|
||||
#include <osg/VisualsSettings>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
@@ -107,11 +108,20 @@ class SG_EXPORT State : public Referenced
|
||||
/** Get the camera */
|
||||
inline const Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
/** Set the VisualsSettings. Note, nothing is applied, the visual settings are just used
|
||||
* used in the State object to pass the current visual settings to Drawables
|
||||
* during rendering. */
|
||||
inline void setVisualsSettings(VisualsSettings* vs) { _visualsSettings = vs; }
|
||||
|
||||
/** Get the VisualsSettings */
|
||||
inline const VisualsSettings* getVisualsSettings() const { return _visualsSettings.get(); }
|
||||
|
||||
private:
|
||||
|
||||
unsigned int _contextID;
|
||||
ref_ptr<FrameStamp> _frameStamp;
|
||||
ref_ptr<Camera> _camera;
|
||||
unsigned int _contextID;
|
||||
ref_ptr<FrameStamp> _frameStamp;
|
||||
ref_ptr<Camera> _camera;
|
||||
ref_ptr<VisualsSettings> _visualsSettings;
|
||||
|
||||
typedef std::vector<StateAttribute::GLModeValue> ValueVec;
|
||||
|
||||
|
||||
@@ -98,44 +98,50 @@ class SG_EXPORT StateAttribute : public Object
|
||||
enum Types
|
||||
{
|
||||
TEXTURE =0,
|
||||
TEXTURE_0 =TEXTURE+0,
|
||||
TEXTURE_1 =TEXTURE+1,
|
||||
TEXTURE_2 =TEXTURE+2,
|
||||
TEXTURE_3 =TEXTURE+3,
|
||||
MATERIAL =4,
|
||||
ALPHAFUNC =5,
|
||||
ANTIALIAS =6,
|
||||
COLORTABLE =6,
|
||||
CULLFACE =8,
|
||||
FOG =9,
|
||||
FRONTFACE =10,
|
||||
LIGHT =11,
|
||||
LIGHT_0 =LIGHT+0,
|
||||
TEXTURE_0 =TEXTURE,
|
||||
TEXTURE_1 =TEXTURE_0+1,
|
||||
TEXTURE_2 =TEXTURE_1+2,
|
||||
TEXTURE_3 =TEXTURE_2+3,
|
||||
|
||||
MATERIAL =TEXTURE_3+1,
|
||||
ALPHAFUNC =MATERIAL+1,
|
||||
ANTIALIAS =ALPHAFUNC+1,
|
||||
COLORTABLE =ANTIALIAS+1,
|
||||
CULLFACE =COLORTABLE+1,
|
||||
FOG =CULLFACE+1,
|
||||
FRONTFACE =FOG+1,
|
||||
|
||||
LIGHT =FRONTFACE+1,
|
||||
LIGHT_0 =LIGHT,
|
||||
LIGHT_1 =LIGHT+1,
|
||||
LIGHT_2 =LIGHT+2,
|
||||
LIGHT_3 =LIGHT+3,
|
||||
LIGHT_4 =LIGHT+4,
|
||||
LIGHT_5 =LIGHT+5,
|
||||
LIGHT_6 =LIGHT+6,
|
||||
LIGHT_7 =LIGHT+7,
|
||||
POINT =18,
|
||||
POLYGONMODE =19,
|
||||
POLYGONOFFSET =20,
|
||||
TEXENV =21,
|
||||
TEXGEN =22,
|
||||
TEXMAT =23,
|
||||
TRANSPARENCY =24,
|
||||
STENCIL =25,
|
||||
COLORMASK =26,
|
||||
DEPTH =27,
|
||||
VIEWPORT =28,
|
||||
CLIPPLANE =29,
|
||||
CLIPPLANE_0 =CLIPPLANE+0,
|
||||
CLIPPLANE_1 =CLIPPLANE+1,
|
||||
CLIPPLANE_2 =CLIPPLANE+2,
|
||||
CLIPPLANE_3 =CLIPPLANE+3,
|
||||
CLIPPLANE_4 =CLIPPLANE+4,
|
||||
CLIPPLANE_5 =CLIPPLANE+5
|
||||
LIGHT_2 =LIGHT+1,
|
||||
LIGHT_3 =LIGHT+1,
|
||||
LIGHT_4 =LIGHT+1,
|
||||
LIGHT_5 =LIGHT+1,
|
||||
LIGHT_6 =LIGHT+1,
|
||||
LIGHT_7 =LIGHT+1,
|
||||
POINT =LIGHT_7+1,
|
||||
|
||||
POLYGONMODE =POINT+1,
|
||||
POLYGONOFFSET =POLYGONMODE+1,
|
||||
TEXENV =POLYGONOFFSET+1,
|
||||
TEXGEN =TEXENV+1,
|
||||
TEXMAT =TEXGEN+1,
|
||||
TRANSPARENCY =TEXMAT+1,
|
||||
STENCIL =TRANSPARENCY+1,
|
||||
COLORMASK =STENCIL+1,
|
||||
DEPTH =COLORMASK+1,
|
||||
VIEWPORT =DEPTH+1,
|
||||
|
||||
CLIPPLANE =VIEWPORT+1,
|
||||
CLIPPLANE_0 =CLIPPLANE,
|
||||
CLIPPLANE_1 =CLIPPLANE_0+1,
|
||||
CLIPPLANE_2 =CLIPPLANE_1+1,
|
||||
CLIPPLANE_3 =CLIPPLANE_2+1,
|
||||
CLIPPLANE_4 =CLIPPLANE_3+1,
|
||||
CLIPPLANE_5 =CLIPPLANE_4+1,
|
||||
|
||||
COLORMATRIX =CLIPPLANE_5+1
|
||||
};
|
||||
|
||||
StateAttribute() {}
|
||||
|
||||
@@ -59,8 +59,11 @@ class SG_EXPORT Viewport : public StateAttribute
|
||||
inline const int width() const { return _width; }
|
||||
inline const int height() const { return _height; }
|
||||
|
||||
/** return the aspcetRatio of the viewport, which is equal to width/height.*/
|
||||
inline const float aspectRatio() const { return (float)_width/(float)_height; }
|
||||
inline const bool valid() const { return _width!=0 && _height!=0; }
|
||||
|
||||
/** Return the aspcetRatio of the viewport, which is equal to width/height.
|
||||
* If height is zero, the potental division by zero is avoid by simply returning 1.0f.*/
|
||||
inline const float aspectRatio() const { if (_height!=0) return (float)_width/(float)_height; else return 1.0f; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
115
include/osg/VisualsSettings
Normal file
115
include/osg/VisualsSettings
Normal file
@@ -0,0 +1,115 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_VISUALSSETTINGS
|
||||
#define OSG_VISUALSSETTINGS 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** VisualsSettings class for encapsulating what visuals are required and
|
||||
* have been set up, and the status of stereo viewing.*/
|
||||
class SG_EXPORT VisualsSettings : public osg::Referenced
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
VisualsSettings()
|
||||
{
|
||||
setDefaults();
|
||||
readEnvironmentalVariables();
|
||||
}
|
||||
|
||||
VisualsSettings(std::vector<std::string>& commandLine)
|
||||
{
|
||||
setDefaults();
|
||||
readEnvironmentalVariables();
|
||||
readCommandLine(commandLine);
|
||||
}
|
||||
|
||||
VisualsSettings(const VisualsSettings& vs);
|
||||
|
||||
virtual ~VisualsSettings();
|
||||
|
||||
VisualsSettings& operator = (const VisualsSettings& vs);
|
||||
|
||||
void merge(const VisualsSettings& vs);
|
||||
|
||||
void setDefaults();
|
||||
|
||||
void readEnvironmentalVariables();
|
||||
|
||||
/** read the command line string list, removing any matched control sequences.*/
|
||||
void readCommandLine(std::vector<std::string>& commandLine);
|
||||
|
||||
|
||||
|
||||
void setStereo(const bool on) { _stereo = on; }
|
||||
const bool getStereo() const { return _stereo; }
|
||||
|
||||
enum StereoMode
|
||||
{
|
||||
QUAD_BUFFER,
|
||||
ANAGLYPHIC,
|
||||
HORIZONTAL_SPLIT,
|
||||
VERTICAL_SPLIT
|
||||
};
|
||||
|
||||
void setStereoMode(const StereoMode mode) { _stereoMode = mode; }
|
||||
const StereoMode getStereoMode() const { return _stereoMode; }
|
||||
|
||||
void setEyeSeperation(const float eyeSeperation) { _eyeSeperation = eyeSeperation; }
|
||||
const float getEyeSeperation() const { return _eyeSeperation; }
|
||||
|
||||
void setScreenDistance(const float distance) { _screenDistance = distance; }
|
||||
const float getScreenDistance() const { return _screenDistance; }
|
||||
|
||||
|
||||
|
||||
void setDoubleBuffer(const bool flag) { _doubleBuffer = flag; }
|
||||
const bool getDoubleBuffer() const { return _doubleBuffer; }
|
||||
|
||||
|
||||
void setRGB(const bool flag) { _RGB = flag; }
|
||||
const bool getRGB() const { return _RGB; }
|
||||
|
||||
|
||||
void setDepthBuffer(const bool flag) { _depthBuffer = flag; }
|
||||
const bool getDepthBuffer() const { return _depthBuffer; }
|
||||
|
||||
|
||||
void setMinimumNumAlphaBits(const unsigned int bits) { _minimumNumberAlphaBits = bits; }
|
||||
const unsigned int getMinimumNumAlphaBits() const { return _minimumNumberAlphaBits; }
|
||||
const bool getAlphaBuffer() const { return _minimumNumberAlphaBits!=0; }
|
||||
|
||||
|
||||
void setMinimumNumStencilBits(const unsigned int bits) { _minimumNumberStencilBits = bits; }
|
||||
const unsigned int getMinimumNumStencilBits() const { return _minimumNumberStencilBits; }
|
||||
const bool getStencilBuffer() const { return _minimumNumberStencilBits!=0; }
|
||||
|
||||
protected:
|
||||
|
||||
void copy(const VisualsSettings& vs);
|
||||
|
||||
bool _stereo;
|
||||
StereoMode _stereoMode;
|
||||
float _eyeSeperation;
|
||||
float _screenDistance;
|
||||
|
||||
bool _doubleBuffer;
|
||||
bool _RGB;
|
||||
bool _depthBuffer;
|
||||
unsigned int _minimumNumberAlphaBits;
|
||||
unsigned int _minimumNumberStencilBits;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
# endif
|
||||
@@ -36,7 +36,11 @@ OSGDB_EXPORT extern osg::Image* readImageFile(const std::string& filename);
|
||||
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
|
||||
* for the filename extension, and this plugin then handles the request
|
||||
* to read the specified file.*/
|
||||
OSGDB_EXPORT extern osg::Node* readNodeFile(const std::string& filename);
|
||||
OSGDB_EXPORT extern osg::Node* readNodeFile(const std::string& filename);
|
||||
|
||||
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
|
||||
* than one subgraph has been loaded.*/
|
||||
OSGDB_EXPORT extern osg::Node* readNodeFiles(std::vector<std::string>& commandLine);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
namespace osgDB {
|
||||
|
||||
|
||||
/**
|
||||
Registry is a singleton factory which stores
|
||||
the reader/writers which are linked in
|
||||
@@ -38,6 +39,9 @@ class OSGDB_EXPORT Registry
|
||||
static Registry* instance();
|
||||
|
||||
|
||||
/** read the command line string list, removing any matched control sequences.*/
|
||||
void readCommandLine(std::vector<std::string>& commandLine);
|
||||
|
||||
/** register an .fileextension alias to mapExt toExt, the later
|
||||
* should the the extension name of the readerwriter plugin library.
|
||||
* For example to map .tif files to the tiff loader, use
|
||||
@@ -131,6 +135,12 @@ class OSGDB_EXPORT Registry
|
||||
|
||||
};
|
||||
|
||||
/** read the command line string list into the osgDB::Registry(), removing any matched control sequences.*/
|
||||
inline void readCommandLine(std::vector<std::string>& commandLine)
|
||||
{
|
||||
Registry::instance()->readCommandLine(commandLine);
|
||||
}
|
||||
|
||||
/** Proxy class for automatic registration of DotOsgWrappers with the Registry.*/
|
||||
class RegisterDotOsgWrapperProxy
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Timer>
|
||||
#include <osg/VisualsSettings>
|
||||
|
||||
#include <osgUtil/GUIEventAdapter>
|
||||
#include <osgUtil/CameraManipulator>
|
||||
@@ -91,6 +92,9 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter
|
||||
virtual void requestContinuousUpdate(bool /*needed*/) {} // continuous update always
|
||||
virtual void requestWarpPointer(int x,int y);
|
||||
|
||||
/** read the command line string list, removing any matched control sequences.*/
|
||||
void readCommandLine(std::vector<std::string>& commandLine);
|
||||
|
||||
protected:
|
||||
|
||||
static void displayCB();
|
||||
@@ -173,8 +177,8 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter
|
||||
osg::Timer_t frameTick();
|
||||
|
||||
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
osg::ref_ptr<osg::VisualsSettings> _visualsSettings;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <osg/Light>
|
||||
#include <osg/Camera>
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/VisualsSettings>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
@@ -76,6 +77,11 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
_viewport->getViewport(x,y,width,height);
|
||||
}
|
||||
|
||||
/** Set the VisualsSettings. */
|
||||
inline void setVisualsSettings(osg::VisualsSettings* vs) { _visualsSettings = vs; }
|
||||
|
||||
/** Get the VisualsSettings */
|
||||
inline const osg::VisualsSettings* getVisualsSettings() const { return _visualsSettings.get(); }
|
||||
|
||||
|
||||
/** Set the background color used in glClearColor().
|
||||
@@ -105,28 +111,11 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
osg::State* getState() { return _state.get(); }
|
||||
const osg::State* getState() const { return _state.get(); }
|
||||
|
||||
enum StereoMode
|
||||
{
|
||||
MONO,
|
||||
QUAD_BUFFER_STEREO,
|
||||
ANAGLYPHIC_STEREO,
|
||||
HORIZONTAL_SPLIT_STEREO,
|
||||
VERTICAL_SPLIT_STEREO
|
||||
};
|
||||
|
||||
void setStereoMode(const StereoMode mode) { _stereoMode = mode; }
|
||||
const StereoMode getStereoMode() const { return _stereoMode; }
|
||||
|
||||
void setLeftEyeOffset(const osg::Vec3& pos) { _leftEye = pos; }
|
||||
void setRightEyeOffset(const osg::Vec3& pos) { _rightEye = pos; }
|
||||
|
||||
void setFocalLength(float length) { _focalLength = length; }
|
||||
void setScreenDistance(float distance) { _screenDistance = distance; }
|
||||
|
||||
void setCamera(osg::Camera* camera) { _camera = camera; }
|
||||
osg::Camera* getCamera() { return _camera.get(); }
|
||||
const osg::Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
|
||||
|
||||
void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; }
|
||||
osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); }
|
||||
@@ -229,15 +218,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
osg::ref_ptr<osg::StateSet> _globalState;
|
||||
osg::ref_ptr<osg::Light> _light;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
osg::ref_ptr<osg::VisualsSettings> _visualsSettings;
|
||||
osg::ref_ptr<osg::State> _state;
|
||||
|
||||
StereoMode _stereoMode;
|
||||
|
||||
osg::Vec3 _leftEye;
|
||||
osg::Vec3 _rightEye;
|
||||
|
||||
float _focalLength;
|
||||
float _screenDistance;
|
||||
|
||||
bool _initCalled;
|
||||
osg::ref_ptr<osg::NodeVisitor> _initVisitor;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/VisualsSettings>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
|
||||
@@ -27,36 +27,13 @@ class OSGUTIL_EXPORT VisualsRequirementsVisitor : public osg::NodeVisitor
|
||||
* alpha and stencil off.*/
|
||||
VisualsRequirementsVisitor();
|
||||
|
||||
|
||||
/** Set the VisualsSettings. */
|
||||
inline void setVisualsSettings(osg::VisualsSettings* vs) { _vs = vs; }
|
||||
|
||||
void setRequiresDoubleBuffer(const bool flag) { _requiresDoubleBuffer = flag; }
|
||||
|
||||
const bool requiresDoubleBuffer() const { return _requiresDoubleBuffer; }
|
||||
|
||||
|
||||
void setRequiresRGB(const bool flag) { _requiresRBG = flag; }
|
||||
|
||||
const bool requiresRGB() const { return _requiresRBG; }
|
||||
|
||||
|
||||
void setRequiresDepthBuffer(const bool flag) { _requiresDepthBuffer = flag; }
|
||||
|
||||
const bool requiresDepthBuffer() const { return _requiresDepthBuffer; }
|
||||
|
||||
|
||||
void setMinimumNumAlphaBits(const unsigned int bits) { _minimumNumberAlphaBits = bits; }
|
||||
|
||||
const unsigned int getMinimumNumAlphaBits() const { return _minimumNumberAlphaBits; }
|
||||
|
||||
const bool requiresAlphaBuffer() const { return _minimumNumberAlphaBits!=0; }
|
||||
|
||||
|
||||
void setMinimumNumStencilBits(const unsigned int bits) { _minimumNumberStencilBits = bits; }
|
||||
|
||||
const unsigned int getMinimumNumStencilBits() const { return _minimumNumberStencilBits; }
|
||||
/** Get the VisualsSettings */
|
||||
inline const osg::VisualsSettings* getVisualsSettings() const { return _vs.get(); }
|
||||
|
||||
const bool requiresStencilBuffer() const { return _minimumNumberStencilBits!=0; }
|
||||
|
||||
|
||||
virtual void applyStateSet(osg::StateSet& stateset);
|
||||
|
||||
virtual void apply(osg::Node& node);
|
||||
@@ -67,12 +44,8 @@ class OSGUTIL_EXPORT VisualsRequirementsVisitor : public osg::NodeVisitor
|
||||
|
||||
protected:
|
||||
|
||||
bool _requiresDoubleBuffer;
|
||||
bool _requiresRBG;
|
||||
bool _requiresDepthBuffer;
|
||||
unsigned int _minimumNumberAlphaBits;
|
||||
unsigned int _minimumNumberStencilBits;
|
||||
|
||||
osg::ref_ptr<osg::VisualsSettings> _vs;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user