Improved support for anaglyphic stereo.
Integrated texture CLAMP_TO_EDGE, submitted by Ulrich Hertlein.
This commit is contained in:
@@ -254,6 +254,22 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
|
||||
|
||||
}
|
||||
|
||||
// clamp-to-edge mode.
|
||||
{
|
||||
// create the texture attribute
|
||||
osg::Texture* texture = new osg::Texture;
|
||||
texture->setImage(image);
|
||||
|
||||
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
||||
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
||||
|
||||
// add the transform node to root group node.
|
||||
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
|
||||
|
||||
local_offset += local_delta;
|
||||
|
||||
}
|
||||
|
||||
// repeat wrap mode.
|
||||
{
|
||||
// create the texture attribute
|
||||
|
||||
@@ -148,6 +148,9 @@ int main( int argc, char **argv )
|
||||
// initialize the viewer.
|
||||
osgGLUT::Viewer viewer;
|
||||
viewer.addViewport( rootnode );
|
||||
|
||||
osgUtil::SceneView* sceneview = viewer.getViewportSceneView(0);
|
||||
sceneview->setStereoMode(osgUtil::SceneView::ANAGLYPHIC_STEREO);
|
||||
|
||||
// register trackball, flight and drive.
|
||||
viewer.registerCameraManipulator(new osgUtil::TrackballManipulator);
|
||||
|
||||
@@ -597,7 +597,6 @@ void Camera::calculateMatricesAndClippingVolume() const
|
||||
float dx = -_eyeOffset.x()*(1.0f/_screenDistance);
|
||||
left += dx;
|
||||
right += dx;
|
||||
cout << "dx="<<dx<<" left="<<left<<" right="<<right<<endl;
|
||||
}
|
||||
|
||||
// set up the projection matrix.
|
||||
@@ -697,13 +696,7 @@ void Camera::calculateMatricesAndClippingVolume() const
|
||||
|
||||
if (_useEyeOffset)
|
||||
{
|
||||
cout << " screenDistance ="<<_screenDistance<<" focalLength="<<_focalLength<<endl;
|
||||
cout << " offset="<<_eyeOffset<<endl;
|
||||
// cout << " trans ="<<-_eyeOffset*(_screenDistance/_focalLength)<<endl;
|
||||
cout << " trans ="<<-_eyeOffset*(_screenDistance)<<endl;
|
||||
|
||||
// (*_modelViewMatrix) = (*_modelViewMatrix) * Matrix::trans(-_eyeOffset*(_screenDistance/_focalLength)) ;
|
||||
(*_modelViewMatrix) = (*_modelViewMatrix) * Matrix::trans(-_eyeOffset*_focalLength/_screenDistance) ;
|
||||
(*_modelViewMatrix) = (*_modelViewMatrix) * Matrix::trans(-_eyeOffset*_focalLength/_screenDistance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ void Texture::apply(State& state) const
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (_image.valid() && _image->data())
|
||||
{
|
||||
|
||||
glGenTextures( 1L, (GLuint *)&handle );
|
||||
@@ -253,29 +253,31 @@ void Texture::applyImmediateMode(State& state) const
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,_image->packing());
|
||||
|
||||
if (_wrap_s == MIRROR || _wrap_t == MIRROR)
|
||||
{
|
||||
static bool s_mirroredSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat");
|
||||
WrapMode ws = _wrap_s, wt = _wrap_t;
|
||||
|
||||
// check for support of mirror-repeated textures
|
||||
// if not supported fall back to repeated textures
|
||||
WrapMode ws = _wrap_s, wt = _wrap_t;
|
||||
if (!s_mirroredSupported)
|
||||
{
|
||||
if (ws == MIRROR)
|
||||
ws = REPEAT;
|
||||
if (wt == MIRROR)
|
||||
wt = REPEAT;
|
||||
}
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ws );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wt );
|
||||
}
|
||||
else
|
||||
// GL_IBM_texture_mirrored_repeat, fall-back REPEAT
|
||||
static bool s_mirroredSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat");
|
||||
if (!s_mirroredSupported)
|
||||
{
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _wrap_s );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _wrap_t );
|
||||
if (ws == MIRROR)
|
||||
ws = REPEAT;
|
||||
if (wt == MIRROR)
|
||||
wt = REPEAT;
|
||||
}
|
||||
|
||||
// GL_EXT_texture_edge_clamp, fall-back CLAMP
|
||||
static bool s_edgeClampSupported = isGLExtensionSupported("GL_EXT_texture_edge_clamp");
|
||||
if (!s_edgeClampSupported)
|
||||
{
|
||||
if (ws == CLAMP_TO_EDGE)
|
||||
ws = CLAMP;
|
||||
if (wt == CLAMP_TO_EDGE)
|
||||
wt = CLAMP;
|
||||
}
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ws );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wt );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _min_filter);
|
||||
|
||||
if (_mag_filter == ANISOTROPIC)
|
||||
|
||||
@@ -173,6 +173,7 @@ bool Texture_writeLocalData(const Object& obj, Output& fw)
|
||||
bool Texture_matchWrapStr(const char* str,Texture::WrapMode& wrap)
|
||||
{
|
||||
if (strcmp(str,"CLAMP")==0) wrap = Texture::CLAMP;
|
||||
else if (strcmp(str,"CLAMP_TO_EDGE")==0) wrap = Texture::CLAMP_TO_EDGE;
|
||||
else if (strcmp(str,"REPEAT")==0) wrap = Texture::REPEAT;
|
||||
else if (strcmp(str,"MIRROR")==0) wrap = Texture::MIRROR;
|
||||
else return false;
|
||||
@@ -185,6 +186,7 @@ const char* Texture_getWrapStr(Texture::WrapMode wrap)
|
||||
switch(wrap)
|
||||
{
|
||||
case(Texture::CLAMP): return "CLAMP";
|
||||
case(Texture::CLAMP_TO_EDGE): return "CLAMP_TO_EDGE";
|
||||
case(Texture::REPEAT): return "REPEAT";
|
||||
case(Texture::MIRROR): return "MIRROR";
|
||||
}
|
||||
|
||||
@@ -138,6 +138,9 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO)<< "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
initPerformer();
|
||||
|
||||
@@ -214,6 +214,7 @@ void SceneView::cull()
|
||||
if (earthSky->getRequiresClear())
|
||||
{
|
||||
_renderStage->setClearColor(earthSky->getClearColor());
|
||||
_renderStage->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
// really should set clear mask here, but what to? Need
|
||||
// to consider the stencil and accumulation buffers..
|
||||
// will defer to later. Robert Osfield. October 2001.
|
||||
@@ -302,44 +303,50 @@ void SceneView::draw()
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> left_camera = new osg::Camera(*_camera);
|
||||
osg::ref_ptr<osg::Camera> right_camera = new osg::Camera(*_camera);
|
||||
float screenDistance = 3.5f;
|
||||
float iod = 0.05;
|
||||
|
||||
left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f),screenDistance);
|
||||
right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f),screenDistance);
|
||||
left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f),_screenDistance);
|
||||
right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f),_screenDistance);
|
||||
|
||||
cout << "draw"<<endl;
|
||||
cout << " back left"<<endl;
|
||||
glDrawBuffer(GL_BACK_LEFT);
|
||||
_renderStage->setCamera(left_camera.get());
|
||||
_renderStage->draw(*_state,previous);
|
||||
|
||||
|
||||
cout << " back right"<<endl;
|
||||
glDrawBuffer(GL_BACK_RIGHT);
|
||||
_renderStage->setCamera(right_camera.get());
|
||||
_renderStage->_stageDrawnThisFrame = false;
|
||||
_renderStage->draw(*_state,previous);
|
||||
}
|
||||
break;
|
||||
case(RED_GREEN_STEREO):
|
||||
case(ANAGLYPHIC_STEREO):
|
||||
{
|
||||
osg::ref_ptr<osg::Camera> left_camera = new osg::Camera(*_camera);
|
||||
osg::ref_ptr<osg::Camera> right_camera = new osg::Camera(*_camera);
|
||||
float iod = 0.05;
|
||||
|
||||
left_camera->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f),_screenDistance);
|
||||
right_camera->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f),_screenDistance);
|
||||
|
||||
osg::ColorMask* red = new osg::ColorMask;
|
||||
osg::ColorMask* green = new osg::ColorMask;
|
||||
|
||||
red->setMask(true,false,false,true);
|
||||
_renderStage->setColorMask(red);
|
||||
_renderStage->setCamera(left_camera.get());
|
||||
_renderStage->draw(*_state,previous);
|
||||
|
||||
green->setMask(false,true,false,true);
|
||||
green->setMask(false,true,true,true);
|
||||
_renderStage->setColorMask(green);
|
||||
_renderStage->_stageDrawnThisFrame = false;
|
||||
_renderStage->setCamera(right_camera.get());
|
||||
_renderStage->draw(*_state,previous);
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning: stereo camera mode not implemented yet."<<endl;
|
||||
_renderStage->draw(*_state,previous);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user