Commit fd3b1dda authored by Jan Möbius's avatar Jan Möbius

Removed stereo support from the Core (Now migrated into the classical external renderer)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15961 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 30638be0
......@@ -209,14 +209,6 @@ glViewer::glViewer( QGraphicsScene* _scene,
setHome();
// initialize custom anaglyph stereo
agTexWidth_ = 0;
agTexHeight_ = 0;
agTexture_[0] = 0;
agTexture_[1] = 0;
agProgram_ = 0;
customAnaglyphSupported_ = false;
clickTimer_.setSingleShot (true);
connect (&clickTimer_, SIGNAL(timeout ()), this, SLOT(slotClickTimeout ()));
}
......@@ -227,7 +219,6 @@ glViewer::glViewer( QGraphicsScene* _scene,
glViewer::~glViewer()
{
finiCustomAnaglyphStereo ();
delete glstate_;
}
......@@ -417,7 +408,7 @@ void glViewer::updateProjectionMatrix()
glstate_->reset_projection();
// In stereo mode we have to use a perspective matrix
if ( properties_.stereo() || projectionMode_ == PERSPECTIVE_PROJECTION)
if ( projectionMode_ == PERSPECTIVE_PROJECTION)
{
double aspect;
......@@ -590,10 +581,9 @@ void glViewer::drawScene()
// draw mono or stereo
makeCurrent();
// Check if we use build in default renderers
// Check if we use build in default renderer
if ( renderManager().activeId( properties_.viewerId() ) == 0 ) {
if ( properties_.stereo()) drawScene_stereo();
else drawScene_mono();
drawScene_mono();
} else {
renderManager().active( properties_.viewerId() )->plugin->render(glstate_,properties_);
}
......@@ -747,34 +737,6 @@ void glViewer::drawScene_mono()
}
//-----------------------------------------------------------------------------
void
glViewer::drawScene_stereo()
{
if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::OpenGL && OpenFlipper::Options::glStereo ())
{
drawScene_glStereo ();
return;
}
else if (OpenFlipper::Options::stereoMode () == OpenFlipper::Options::AnaglyphCustom && customAnaglyphSupported_)
{
drawScene_customAnaglyphStereo ();
// if somthing went wrong, fallback to normal anaglyph
if (customAnaglyphSupported_)
return;
}
drawScene_anaglyphStereo ();
}
//-----------------------------------------------------------------------------
void glViewer::setHome()
{
home_modelview_ = glstate_->modelview();
......@@ -799,10 +761,8 @@ void glViewer::home()
}
//-----------------------------------------------------------------------------
void glViewer::viewAll()
{
makeCurrent();
......@@ -892,11 +852,6 @@ void glViewer::initializeGL()
// unlock update (we started locked)
properties_.unLockUpdate();
customAnaglyphSupported_ = ACG::checkExtensionSupported("GL_ARB_fragment_program") &&
(ACG::checkExtensionSupported("GL_ARB_texture_rectangle") ||
ACG::checkExtensionSupported("GL_EXT_texture_rectangle") ||
ACG::checkExtensionSupported("GL_NV_texture_rectangle"));
initialized_ = true;
if (sceneGraphRoot_)
......@@ -948,9 +903,7 @@ void glViewer::paintGL()
glColor4f(1.0,0.0,0.0,1.0);
// clear (stereo mode clears buffers on its own)
if (! properties_.stereo())
glstate_->clearBuffers ();
glstate_->clearBuffers ();
properties_.unLockUpdate();
......@@ -1867,7 +1820,7 @@ void glViewer::viewWheelEvent( QWheelEvent* _event)
if (_event->modifiers() == Qt::ShiftModifier)
factor = properties_.wheelZoomFactorShift();
if (projectionMode() == PERSPECTIVE_PROJECTION || properties_.stereo())
if (projectionMode() == PERSPECTIVE_PROJECTION )
{
double d = -(double)_event->delta() / 120.0 * 0.2 * factor * properties_.trackballRadius() / 3.0;
translate( ACG::Vec3d(0.0, 0.0, d) );
......@@ -1952,10 +1905,8 @@ void glViewer::applyProperties() {
ACG::GLState::disable( GL_CULL_FACE );
// Make sure the right buffer is used in non stereo setup
if (! properties_.stereo()) {
makeCurrent();
ACG::GLState::drawBuffer(GL_BACK);
}
makeCurrent();
ACG::GLState::drawBuffer(GL_BACK);
// Required for stereo toggling
updateProjectionMatrix ();
......@@ -2164,14 +2115,6 @@ void glViewer::updateCursorPosition (QPointF _scenePos)
properties_.cursorPositionValid( false );
}
// only do real pick in stereo mode
else if ( properties_.stereo() && OpenFlipperSettings().value("Core/Gui/glViewer/stereoMousePick",true).toBool() &&
pick (ACG::SceneGraph::PICK_ANYTHING, _scenePos.toPoint(), nodeIdx, targetIdx, &tmp))
{
// the point we get back will contain the view transformation and we have to revert it
properties_.cursorPoint3D( glstate_->modelview ().transform_point (tmp) );
properties_.cursorPositionValid(true);
}
else
{
glstate_->push_modelview_matrix ();
......
......@@ -630,49 +630,6 @@ private:
/** @} */
//===========================================================================
/** @name Stereo
* @{ */
//===========================================================================
private:
/// helper called by drawScene() when stereo viewing is active.
void drawScene_stereo();
/// helper called by drawScene_stereo() when opengl stereo viewing is active.
void drawScene_glStereo();
/// helper called by drawScene_stereo() when anaglyph stereo viewing is active.
void drawScene_anaglyphStereo();
/// helper called by drawScene_stereo() when custom anaglyph stereo viewing is active.
void drawScene_customAnaglyphStereo();
/// helper called to initialize/update custom anaglyph stereo
void updateCustomAnaglyphStereo();
/// helper called to cleanup custom anaglyph stereo
void finiCustomAnaglyphStereo();
/// Draws the scene for a philips stereo display ( Header, left color image, right depth map )
void drawScenePhilipsStereo();
/// Updates the scene for a philips stereo display
void updateScenePhilipsStereo();
private:
// custom anaglyph stuff
int agTexWidth_;
int agTexHeight_;
GLuint agTexture_[2];
GLuint agProgram_;
bool customAnaglyphSupported_;
/** @} */
//===========================================================================
/** @name Key handling
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS glViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtBaseViewer.hh"
#include <QStatusBar>
#include <QToolButton>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <QGLFramebufferObject>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/ShaderUtils/gldebug.h>
//== NAMESPACES ===============================================================
//== IMPLEMENTATION ==========================================================
static const char* customAnaglyphProg = {
"!!ARBfp1.0"
"TEMP left, right, lmul, rmul;"
"TEX left, fragment.texcoord[0], texture[0], RECT;"
"TEX right, fragment.texcoord[0], texture[1], RECT;"
"DP3 lmul.r, left, program.env[0];"
"DP3 lmul.g, left, program.env[1];"
"DP3 lmul.b, left, program.env[2];"
"DP3 rmul.r, right, program.env[3];"
"DP3 rmul.g, right, program.env[4];"
"DP3 rmul.b, right, program.env[5];"
"ADD result.color, lmul, rmul;"
"END"
};
//-----------------------------------------------------------------------------
void
glViewer::drawScene_glStereo()
{
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY",45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = properties_.nearPlane() * tan(radians);
zerop = properties_.nearPlane() + ((properties_.farPlane() - properties_.nearPlane()) * OpenFlipperSettings().value("Core/Stereo/FocalDistance",0.5).toDouble() );
ndfl = properties_.nearPlane() / zerop ;
xrange = a * wd2 * 2 * zerop / properties_.nearPlane();
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance",0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
// left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(+offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
ACG::GLState::drawBuffer(GL_BACK_LEFT);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
drawScene_mono();
// right eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
ACG::GLState::drawBuffer(GL_BACK_RIGHT);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
drawScene_mono();
ACG::GLState::drawBuffer(GL_BACK);
}
//-----------------------------------------------------------------------------
void
glViewer::drawScene_anaglyphStereo()
{
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY", 45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = properties_.nearPlane() * tan(radians);
zerop = properties_.nearPlane() + ((properties_.farPlane() - properties_.nearPlane()) * OpenFlipperSettings().value("Core/Stereo/FocalDistance", 0.5).toDouble() );
ndfl = properties_.nearPlane() / zerop ;
xrange = a * wd2 * 2 * zerop / properties_.nearPlane();
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance", 0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
// left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
// draw red channel for left eye
glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE);
drawScene_mono();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
// right eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_DEPTH_BUFFER_BIT);
// draw green and blue channel for right eye
glColorMask(GL_FALSE,GL_TRUE,GL_TRUE,GL_TRUE);
drawScene_mono();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
}
//-----------------------------------------------------------------------------
void
glViewer::updateCustomAnaglyphStereo()
{
if (!customAnaglyphSupported_)
return;
if ( !ACG::checkExtensionSupported("GL_ARB_texture_rectangle") ) {
std::cerr << "GL_ARB_texture_rectangle not supported! " << std::endl;
customAnaglyphSupported_ = false;
return;
}
if (!agProgram_)
{
GLint errorPos;
glGenProgramsARB (1, &agProgram_);
glGetError ();
glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, agProgram_);
glProgramStringARB (GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen (customAnaglyphProg), customAnaglyphProg);
glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
if (glGetError () != GL_NO_ERROR || errorPos != -1)
{
printf("Error loading program %d %s\n",errorPos, glGetString(GL_PROGRAM_ERROR_STRING_ARB));
glDeleteProgramsARB (1, &agProgram_);
customAnaglyphSupported_ = false;
return;
}
}
if (!agTexture_[0])
glGenTextures (2, agTexture_);
if (!agTexture_[0])
{
finiCustomAnaglyphStereo ();
customAnaglyphSupported_ = false;
return;
}
if (glstate_->viewport_width () != agTexWidth_ ||
glstate_->viewport_height () != agTexHeight_)
{
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[0]);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, glstate_->viewport_width (),
glstate_->viewport_height (), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[1]);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, glstate_->viewport_width (),
glstate_->viewport_height (), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
agTexWidth_ = glstate_->viewport_width ();
agTexHeight_ = glstate_->viewport_height ();
}
}
//-----------------------------------------------------------------------------
void
glViewer::finiCustomAnaglyphStereo()
{
if (!customAnaglyphSupported_)
return;
if (agProgram_)
glDeleteProgramsARB (1, &agProgram_);
if (agTexture_[0])
glDeleteTextures (2, agTexture_);
}
//-----------------------------------------------------------------------------
void
glViewer::drawScene_customAnaglyphStereo()
{
updateCustomAnaglyphStereo ();
if (!customAnaglyphSupported_)
return;
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = glWidth();
h = glHeight();
a = w / h;
double fovy = OpenFlipperSettings().value("Core/Projection/FOVY",45.0).toDouble();
radians = fovy * 0.5 / 180.0 * M_PI;
wd2 = properties_.nearPlane() * tan(radians);
zerop = properties_.nearPlane() + ((properties_.farPlane() - properties_.nearPlane()) * OpenFlipperSettings().value("Core/Stereo/FocalDistance",0.5).toDouble() );
ndfl = properties_.nearPlane() / zerop ;
xrange = a * wd2 * 2 * zerop / properties_.nearPlane();
l = -a*wd2;
r = a*wd2;
t = wd2;
b = -wd2;
double offset = 0.5 * OpenFlipperSettings().value("Core/Stereo/EyeDistance",0.07).toDouble() * xrange;
double offset2 = offset * ndfl;
int vp_l, vp_b, vp_w, vp_h;
glstate_->get_viewport (vp_l, vp_b, vp_w, vp_h);
std::vector<float> le = OpenFlipper::Options::anaglyphLeftEyeColorMatrix();
std::vector<float> re = OpenFlipper::Options::anaglyphRightEyeColorMatrix();
// left eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l+offset2, r+offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
drawScene_mono();
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[0]);
glCopyTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, vp_l, vp_b, vp_w, vp_h);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
// right eye
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(l-offset2, r-offset2, b, t, properties_.nearPlane(), properties_.farPlane());
glTranslatef(-offset, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glstate_->clearBuffers ();
glClear(GL_DEPTH_BUFFER_BIT);
drawScene_mono();
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[1]);
glCopyTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, vp_l, vp_b, vp_w, vp_h);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
ACG::GLState::activeTexture (GL_TEXTURE0);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[0]);
ACG::GLState::enable (GL_TEXTURE_RECTANGLE_ARB);
ACG::GLState::activeTexture (GL_TEXTURE1);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, agTexture_[1]);
ACG::GLState::enable (GL_TEXTURE_RECTANGLE_ARB);
ACG::GLState::enable (GL_FRAGMENT_PROGRAM_ARB);
glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, agProgram_);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 0, le[0], le[3], le[6], 0.0);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 1, le[1], le[4], le[7], 0.0);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 2, le[2], le[5], le[8], 0.0);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 3, re[0], re[3], re[6], 0.0);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 4, re[1], re[4], re[7], 0.0);
glProgramEnvParameter4fARB (GL_FRAGMENT_PROGRAM_ARB, 5, re[2], re[5], re[8], 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, vp_w, vp_h, 0, 0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
ACG::GLState::disable (GL_DEPTH_TEST);
glBegin (GL_QUADS);
glMultiTexCoord2f (GL_TEXTURE0, 0, vp_h);
glMultiTexCoord2f (GL_TEXTURE1, 0, vp_h);
glVertex2i(0, 0);
glMultiTexCoord2f (GL_TEXTURE0, 0, 0);
glMultiTexCoord2f (GL_TEXTURE1, 0, 0);
glVertex2i(0, vp_h);
glMultiTexCoord2f (GL_TEXTURE0, vp_w, 0);
glMultiTexCoord2f (GL_TEXTURE1, vp_w, 0);
glVertex2i(vp_w, vp_h);
glMultiTexCoord2f (GL_TEXTURE0, vp_w, vp_h);
glMultiTexCoord2f (GL_TEXTURE1, vp_w, vp_h);
glVertex2i(vp_w, 0);
glEnd ();
ACG::GLState::enable (GL_DEPTH_TEST);
glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, 0);
ACG::GLState::disable (GL_FRAGMENT_PROGRAM_ARB);
ACG::GLState::activeTexture (GL_TEXTURE1);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
ACG::GLState::disable (GL_TEXTURE_RECTANGLE_ARB);
ACG::GLState::activeTexture (GL_TEXTURE0);
ACG::GLState::bindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
ACG::GLState::disable (GL_TEXTURE_RECTANGLE_ARB);
}
//=============================================================================
//=============================================================================
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment