Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
renderer.cpp
1 
2 /* Copyright (c) 2011-2013, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "renderer.h"
30 
31 // light parameters
32 static GLfloat lightPosition[] = {0.0f, 0.0f, 1.0f, 0.0f};
33 static GLfloat lightAmbient[] = {0.1f, 0.1f, 0.1f, 1.0f};
34 static GLfloat lightDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
35 static GLfloat lightSpecular[] = {0.8f, 0.8f, 0.8f, 1.0f};
36 
37 // material properties
38 static GLfloat materialAmbient[] = {0.2f, 0.2f, 0.2f, 1.0f};
39 static GLfloat materialDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
40 static GLfloat materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
41 static GLint materialShininess = 64;
42 
43 namespace seqPly
44 {
45 
46 bool Renderer::init( co::Object* initData )
47 {
48  _state = new State( glewGetContext( ));
49  return seq::Renderer::init( initData );
50 }
51 
53 {
54  _state->deleteAll();
55  delete _state;
56  _state = 0;
57  return seq::Renderer::exit();
58 }
59 
60 void Renderer::draw( co::Object* frameDataObj )
61 {
62  const FrameData* frameData = static_cast< FrameData* >( frameDataObj );
63  Application& application = static_cast< Application& >( getApplication( ));
64  const eq::uint128_t& id = frameData->getModelID();
65  const Model* model = application.getModel( id );
66  if( !model )
67  return;
68 
69  updateNearFar( model->getBoundingSphere( ));
71 
72  glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
73  glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
74  glLightfv( GL_LIGHT0, GL_DIFFUSE, lightDiffuse );
75  glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );
76 
77  glMaterialfv( GL_FRONT, GL_AMBIENT, materialAmbient );
78  glMaterialfv( GL_FRONT, GL_DIFFUSE, materialDiffuse );
79  glMaterialfv( GL_FRONT, GL_SPECULAR, materialSpecular );
80  glMateriali( GL_FRONT, GL_SHININESS, materialShininess );
81 
83 
84  glColor3f( .75f, .75f, .75f );
85 
86  // Compute cull matrix
87  const eq::Matrix4f& modelM = getModelMatrix();
88  const eq::Matrix4f& view = getViewMatrix();
89  const eq::Frustumf& frustum = getFrustum();
90  const eq::Matrix4f projection = frustum.compute_matrix();
91  const eq::Matrix4f pmv = projection * view * modelM;
92  const seq::RenderContext& context = getRenderContext();
93 
94  _state->setProjectionModelViewMatrix( pmv );
95  _state->setRange( &context.range.start );
96  _state->setColors( model->hasColors( ));
97 
98  model->cullDraw( *_state );
99 }
100 
101 }
virtual SEQ_API bool init(co::Object *initData 1)
Initialize the renderer.
SEQ_API const Matrix4f & getModelMatrix() const
Range range
database-range wrt to dest channel
Definition: renderContext.h:58
SEQ_API void updateNearFar(const Vector4f &boundingSphere)
Update the near and far planes to tightly enclose the given sphere.
SEQ_API const Frustumf & getFrustum() const
float start
The start position.
Definition: range.h:75
virtual bool exit()
De-initialize the renderer.
Definition: renderer.cpp:52
SEQ_API const GLEWContext * glewGetContext() const
Get the GLEW context for this renderer.
virtual void draw(co::Object *frameData)
Render the scene.
Definition: renderer.cpp:60
virtual SEQ_API void applyRenderContext()
Apply the current rendering parameters to the rendering context.
Application & getApplication()
SEQ_API const RenderContext & getRenderContext() const
SEQ_API const Matrix4f & getViewMatrix() const
virtual SEQ_API bool exit()
De-initialize the renderer.
The context applied to a channel during rendering operations.
Definition: renderContext.h:38
virtual SEQ_API void applyModelMatrix()
Apply the current model matrix to the rendering context.