Equalizer 1.0
|
00001 00002 /* 00003 * Copyright (c) 00004 * 2008-2009, Thomas McGuire <thomas.mcguire@student.uni-siegen.de> 00005 * 2010, Stefan Eilemann <eile@eyescale.ch> 00006 * 2010, Sarah Amsellem <sarah.amsellem@gmail.com> 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, this 00012 * list of conditions and the following disclaimer. 00013 * - Redistributions in binary form must reproduce the above copyright notice, 00014 * this list of conditions and the following disclaimer in the documentation 00015 * and/or other materials provided with the distribution. 00016 * - Neither the name of Eyescale Software GmbH nor the names of its 00017 * contributors may be used to endorse or promote products derived from this 00018 * software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #include "channel.h" 00034 00035 #include "config.h" 00036 #include "pipe.h" 00037 #include "quad.h" 00038 #include "util.h" 00039 #include "window.h" 00040 00041 #include <osg/MatrixTransform> 00042 #include <osg/Texture2D> 00043 00044 namespace osgScaleViewer 00045 { 00046 00047 Channel::Channel( eq::Window* parent ) 00048 : eq::Channel( parent ) 00049 { 00050 } 00051 00052 00053 void Channel::frameClear( const eq::uint128_t& frameID ) 00054 { 00055 glEnable( GL_SCISSOR_TEST ); 00056 eq::Channel::frameClear( frameID ); 00057 } 00058 00059 void Channel::frameDraw( const eq::uint128_t& frameID ) 00060 { 00061 // setup OpenGL State 00062 eq::Channel::frameDraw( frameID ); 00063 00064 // - 2D viewport 00065 Window *window = static_cast< Window* >( getWindow( )); 00066 osg::ref_ptr< SceneView > view = window->getSceneView(); 00067 00068 const eq::PixelViewport& pvp = getPixelViewport(); 00069 view->setViewport( pvp.x, pvp.y, pvp.w, pvp.h ); 00070 00071 // - Stereo 00072 view->setDrawBufferValue( getDrawBuffer( )); 00073 const eq::ColorMask& colorMask = getDrawBufferMask(); 00074 00075 osgUtil::RenderStage* stage = view->getRenderStage(); 00076 osg::ref_ptr< osg::ColorMask > osgMask = stage->getColorMask(); 00077 osgMask->setMask( colorMask.red, colorMask.green, colorMask.blue, true ); 00078 00079 // - Frustum (Projection matrix) 00080 const eq::Frustumf& frustum = getFrustum(); 00081 view->setProjectionMatrixAsFrustum( 00082 frustum.left(), frustum.right(), frustum.bottom(), frustum.top(), 00083 frustum.near_plane(), frustum.far_plane( )); 00084 00085 // - Camera (Model Matrix) 00086 const Pipe *pipe = static_cast< const Pipe* >( getPipe( )); 00087 const FrameData& frameData = pipe->getFrameData(); 00088 00089 const eq::Vector3f position = frameData.getCameraPosition(); 00090 const eq::Vector3f lookAt = frameData.getCameraLookAtPoint(); 00091 const eq::Vector3f upVector = frameData.getCameraUpVector(); 00092 00093 const osg::Vec3f pos( position.x(), position.y(), position.z( )); 00094 const osg::Vec3f look( lookAt.x(), lookAt.y(), lookAt.z( )); 00095 const osg::Vec3f up( upVector.x(), upVector.y(), upVector.z( )); 00096 00097 view->setViewMatrixAsLookAt( pos, look, up ); 00098 00099 // - Frustum position (View Matrix) 00100 osg::Matrix headView = view->getViewMatrix(); 00101 headView.postMult( vmmlToOsg( getHeadTransform( ))); 00102 view->setViewMatrix( headView ); 00103 00104 // - Render 00105 view->cull(); 00106 view->draw(); 00107 } 00108 00109 void Channel::frameViewFinish( const eq::uint128_t& frameID ) 00110 { 00111 const Pipe *pipe = static_cast< const Pipe* >( getPipe( )); 00112 const FrameData& frameData = pipe->getFrameData(); 00113 if( !frameData.useStatistics( )) 00114 return; 00115 00116 applyBuffer(); 00117 applyViewport(); 00118 drawStatistics(); 00119 } 00120 00121 }