Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
eqAsync.cpp
1 
2 /* Copyright (c) 2009-2011, Maxim Makhinya <maxmah@gmail.com>
3  * 2012, Stefan Eilemann <eile@eyescale.ch>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
31 #include "eqAsync.h"
32 
33 namespace eqAsync
34 {
35 
36 bool Window::configInitGL( const eq::uint128_t& initID )
37 {
38  if( !eq::Window::configInitGL( initID ))
39  return false;
40 
41  Pipe* pipe = static_cast<Pipe*>( getPipe( ));
42  pipe->startAsyncFetcher( this );
43  return true;
44 }
45 
46 void Pipe::startAsyncFetcher( Window* wnd )
47 {
48  if( _initialized )
49  return;
50  _initialized = true;
51  LBINFO << "initialize async fetcher: " << this << ", " << wnd << std::endl;
52  _asyncFetcher.setup( wnd );
53 }
54 
55 
56 void Pipe::frameStart( const eq::uint128_t& frameID, const uint32_t frameNumber)
57 {
58  eq::Pipe::frameStart( frameID, frameNumber );
59 
60  const void* oldKey = _txId.key;
61  if( _asyncFetcher.tryGetTextureId( _txId ))
62  {
63  if( oldKey != 0 )
64  _asyncFetcher.deleteTexture( oldKey );
65 
66  LBINFO << "new texture generated " << _txId.key << std::endl;
67  }
68 }
69 
71 {
72  _asyncFetcher.stop();
73  return eq::Pipe::configExit();
74 }
75 
76 void Channel::frameDraw( const eq::uint128_t& spin )
77 {
78  // setup OpenGL State
79  eq::Channel::frameDraw( spin );
80 
81  Pipe* pipe = static_cast< Pipe* >( getPipe( ));
82  GLuint txId = pipe->getTextureId();
83 
84  if( txId )
85  {
86  glEnable( GL_TEXTURE_2D );
87  glBindTexture( GL_TEXTURE_2D, txId );
88  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
89  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
90  }
91 
92  const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
93  glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
94 
95  const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
96  glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
97 
98  // rotate scene around the origin
99  glRotatef( static_cast< float >( spin.low( )) * 0.1f, 1.0f, 0.5f, 0.25f );
100 
101  float tMin = 0.f;
102  float tMax = 1.f;
103  // render six axis-aligned colored quads around the origin
104  for( int i = 0; i < 6; i++ )
105  {
106  glColor3f( i&1 ? 0.5f : 1.0f, i&2 ? 1.0f : 0.5f, i&4 ? 1.0f : 0.5f );
107 
108  glNormal3f( 0.0f, 0.0f, 1.0f );
109  glBegin( GL_TRIANGLE_STRIP );
110  glTexCoord2f( tMax, tMax );
111  glVertex3f( .7f, .7f, -1.0f );
112  glTexCoord2f( tMin, tMax );
113  glVertex3f( -.7f, .7f, -1.0f );
114  glTexCoord2f( tMax, tMin );
115  glVertex3f( .7f, -.7f, -1.0f );
116  glTexCoord2f( tMin, tMin );
117  glVertex3f( -.7f, -.7f, -1.0f );
118  glEnd();
119 
120  if( i < 3 )
121  glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
122  else if( i == 3 )
123  glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
124  else
125  glRotatef( 180.0f, 1.0f, 0.0f, 0.0f );
126  }
127 
128  if( txId )
129  {
130  glDisable( GL_TEXTURE_2D );
131  }
132 }
133 
134 } // namespace eqAsync
virtual void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
Definition: eqAsync.cpp:56
virtual EQ_API void frameDraw(const uint128_t &frameID)
Draw the scene.
virtual EQ_API bool configExit()
De-initialize this pipe.
virtual bool configExit()
De-initialize this pipe.
Definition: eqAsync.cpp:70
virtual void frameDraw(const eq::uint128_t &spin)
Draw the scene.
Definition: eqAsync.cpp:76
EQ_API Pipe * getPipe()
bool configInitGL(const eq::uint128_t &initID)
Initialize the OpenGL state for this window.
Definition: eqAsync.cpp:36
virtual EQ_API void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
virtual EQ_API bool configInitGL(const uint128_t &initID)
Initialize the OpenGL state for this window.