Equalizer  1.2.1
renderer.cpp
00001 
00002 /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch> 
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "renderer.h"
00030 
00031 // light parameters
00032 static GLfloat lightPosition[] = {0.0f, 0.0f, 1.0f, 0.0f};
00033 static GLfloat lightAmbient[]  = {0.1f, 0.1f, 0.1f, 1.0f};
00034 static GLfloat lightDiffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
00035 static GLfloat lightSpecular[] = {0.8f, 0.8f, 0.8f, 1.0f};
00036 
00037 // material properties
00038 static GLfloat materialAmbient[]  = {0.2f, 0.2f, 0.2f, 1.0f};
00039 static GLfloat materialDiffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
00040 static GLfloat materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
00041 static GLint  materialShininess   = 64;
00042 
00043 namespace seqPly
00044 {
00045 
00046 bool Renderer::init( co::Object* initData )
00047 {
00048     _state = new State( glewGetContext( ));
00049     return seq::Renderer::init( initData );
00050 }
00051 
00052 bool Renderer::exit()
00053 {
00054     _state->deleteAll();
00055     delete _state;
00056     _state = 0;
00057     return seq::Renderer::exit();
00058 }
00059 
00060 void Renderer::draw( co::Object* frameDataObj )
00061 {
00062     EQASSERT( _state );
00063 
00064     const FrameData* frameData = static_cast< FrameData* >( frameDataObj );
00065     Application& application = static_cast< Application& >( getApplication( ));
00066     const eq::uint128_t id = frameData->getModelID();
00067     const Model* model = application.getModel( id );
00068     if( !model )
00069         return;
00070 
00071     applyRenderContext();
00072 
00073     glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
00074     glLightfv( GL_LIGHT0, GL_AMBIENT,  lightAmbient  );
00075     glLightfv( GL_LIGHT0, GL_DIFFUSE,  lightDiffuse  );
00076     glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );
00077 
00078     glMaterialfv( GL_FRONT, GL_AMBIENT,   materialAmbient );
00079     glMaterialfv( GL_FRONT, GL_DIFFUSE,   materialDiffuse );
00080     glMaterialfv( GL_FRONT, GL_SPECULAR,  materialSpecular );
00081     glMateriali(  GL_FRONT, GL_SHININESS, materialShininess );
00082 
00083     applyModelMatrix();
00084 
00085     glColor3f( .75f, .75f, .75f );
00086 
00087     // Compute cull matrix
00088     const eq::Matrix4f& modelM = getModelMatrix();
00089     const eq::Matrix4f& view = getViewMatrix();
00090     const eq::Frustumf& frustum = getFrustum();
00091     const eq::Matrix4f projection = frustum.compute_matrix();
00092     const eq::Matrix4f pmv = projection * view * modelM;
00093 
00094     _state->setProjectionModelViewMatrix( pmv );
00095     //_state->setRange( &getRange().start);
00096     _state->setColors( model->hasColors( ));
00097     
00098     model->cullDraw( *_state );
00099 }
00100 
00101 co::Object* Renderer::createObject( const uint32_t type )
00102 {
00103     switch( type )
00104     {
00105       case seq::OBJECTTYPE_FRAMEDATA:
00106           return new eqPly::FrameData;
00107 
00108       default:
00109           EQASSERTINFO( false, "Object type " << type << " unknown" );
00110           return 0;
00111     }
00112 }
00113 
00114 }
00115 
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0