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

Stereo support and new buffer handling in shader pipeline renderer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18234 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3b2ff163
......@@ -33,17 +33,42 @@ void Renderer::render(ACG::GLState* _glState, Viewer::ViewerProperties& _propert
// collect renderobjects + prepare OpenGL state
prepareRenderingPipeline(_glState, _properties.drawMode(), PluginFunctions::getSceneGraphRootNode());
// render every object
// clear back buffer
ACG::Vec4f clearColor = _properties.backgroundColor();
glClearColor(clearColor[0], clearColor[1], clearColor[2], 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (!_properties.stereo())
{
for (int i = 0; i < getNumRenderObjects(); ++i)
renderObject(sortedObjects_[i]);
}
else
{
ACG::GLMatrixd projLeft, projRight;
computeProjStereo(_glState, _properties, &projLeft, &projRight);
// draw red channel for left eye
// render every object
for (int i = 0; i < getNumRenderObjects(); ++i)
{
ACG::GLMatrixd prev = sortedObjects_[i]->proj;
sortedObjects_[i]->proj = projLeft;
sortedObjects_[i]->glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
renderObject(sortedObjects_[i]);
sortedObjects_[i]->proj = prev;
}
// draw green and blue channel for right eye
for (int i = 0; i < getNumRenderObjects(); ++i)
renderObject(sortedObjects_[i]);
glClear(GL_DEPTH_BUFFER_BIT);
for (int i = 0; i < getNumRenderObjects(); ++i)
{
sortedObjects_[i]->proj = projRight;
sortedObjects_[i]->glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
renderObject(sortedObjects_[i]);
}
}
// restore common opengl state
......@@ -75,6 +100,44 @@ QString Renderer::checkOpenGL()
return missing;
}
void Renderer::computeProjStereo( ACG::GLState* _glState, Viewer::ViewerProperties& _properties, ACG::GLMatrixd* _outLeft, ACG::GLMatrixd* _outRight )
{
double l, r, t, b, w, h, a, radians, wd2, ndfl, zerop, xrange;
w = _glState->viewport_width();
h = _glState->viewport_height();
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;
if (_outLeft)
{
_outLeft->identity();
_outLeft->frustum(l+offset2, r+offset2, b, t, _properties.nearPlane(), _properties.farPlane());
_outLeft->translate(offset, 0.0, 0.0);
}
if (_outRight)
{
_outRight->identity();
_outRight->frustum(l-offset2, r-offset2, b, t, _properties.nearPlane(), _properties.farPlane());
_outRight->translate(-offset, 0.0, 0.0);
}
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( shaderrenderer , Renderer );
#endif
......
......@@ -95,6 +95,10 @@ private slots:
QString checkOpenGL();
private:
void computeProjStereo(ACG::GLState* _glState, Viewer::ViewerProperties& _properties,
ACG::GLMatrixd* _outLeft, ACG::GLMatrixd* _outRight);
};
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