Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
eqPly/window.cpp
1 
2 /* Copyright (c) 2007-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2007, Tobias Wolf <twolf@access.unizh.ch>
4  * 2010, Cedric Stalder <cedric.stalder@gmail.com>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * - Neither the name of Eyescale Software GmbH nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "window.h"
32 
33 #include "config.h"
34 #include "pipe.h"
35 #include "vertexBufferState.h"
36 
37 #include "fragmentShader.glsl.h"
38 #include "vertexShader.glsl.h"
39 
40 #include <fstream>
41 #include <sstream>
42 
43 namespace eqPly
44 {
45 
46 bool Window::configInitSystemWindow( const eq::uint128_t& initID )
47 {
48 #ifndef Darwin
50  return false;
51 
52  // OpenGL version is less than 2.0.
53  if( !GLEW_EXT_framebuffer_object )
54  {
55  if( getDrawableConfig().accumBits )
56  return true;
57 
59 #endif
60  // try with 64 bit accum buffer
63  return true;
64 
65  // no anti-aliasing possible
67  return eq::Window::configInitSystemWindow( initID );
68 
69 #ifndef Darwin
70  }
71  return true;
72 #endif
73 }
74 
75 bool Window::configInitGL( const eq::uint128_t& initID )
76 {
77  if( !eq::Window::configInitGL( initID ))
78  return false;
79 
80  glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
81  glEnable( GL_CULL_FACE ); // OPT - produces sparser images in DB mode
82  glCullFace( GL_BACK );
83 
84  LBASSERT( !_state );
85  _state = new VertexBufferState( getObjectManager( ));
86 
87  const Config* config = static_cast< const Config* >( getConfig( ));
88  const InitData& initData = config->getInitData();
89 
90  if( initData.showLogo( ))
91  _loadLogo();
92 
93  if( initData.useGLSL() )
94  _loadShaders();
95 
96  return true;
97 }
98 
100 {
101  if( _state && !_state->isShared( ))
102  _state->deleteAll();
103 
104  delete _state;
105  _state = 0;
106 
107  return eq::Window::configExitGL();
108 }
109 
110 namespace
111 {
112 static const std::string _logoTextureName =
113  std::string( lunchbox::getExecutablePath() +
114  "/../share/Equalizer/data/logo.rgb" );
115 }
116 
117 void Window::_loadLogo()
118 {
119  if( !GLEW_ARB_texture_rectangle )
120  {
121  LBWARN << "Can't load overlay logo, GL_ARB_texture_rectangle not "
122  << "available" << std::endl;
123  return;
124  }
125 
127  _logoTexture = om.getEqTexture( _logoTextureName.c_str( ));
128  if( _logoTexture )
129  return;
130 
131  eq::Image image;
132  if( !image.readImage( _logoTextureName, eq::Frame::BUFFER_COLOR ))
133  {
134  LBWARN << "Can't load overlay logo " << _logoTextureName << std::endl;
135  return;
136  }
137 
138  _logoTexture = om.newEqTexture( _logoTextureName.c_str(),
139  GL_TEXTURE_RECTANGLE_ARB );
140  LBASSERT( _logoTexture );
141 
142  image.upload(eq::Frame::BUFFER_COLOR, _logoTexture, eq::Vector2i::ZERO, om);
143  image.deleteGLObjects( om );
144  LBVERB << "Created logo texture of size " << _logoTexture->getWidth() << "x"
145  << _logoTexture->getHeight() << std::endl;
146 }
147 
148 void Window::_loadShaders()
149 {
150  if( _state->getShader( vertexShader_glsl ) != VertexBufferState::INVALID )
151  // already loaded
152  return;
153 
154  // Check if functions are available
155  if( !GLEW_VERSION_2_0 )
156  {
157  LBWARN << "Shader function pointers missing, using fixed function "
158  << "pipeline" << std::endl;
159  return;
160  }
161 
162  const GLuint vShader = _state->newShader( vertexShader_glsl,
163  GL_VERTEX_SHADER );
164  LBASSERT( vShader != VertexBufferState::INVALID );
165  const GLchar* vShaderPtr = vertexShader_glsl;
166  glShaderSource( vShader, 1, &vShaderPtr, 0 );
167  glCompileShader( vShader );
168 
169  GLint status;
170  glGetShaderiv( vShader, GL_COMPILE_STATUS, &status );
171  if( !status )
172  {
173  LBWARN << "Failed to compile vertex shader" << std::endl;
174  return;
175  }
176 
177  const GLuint fShader =
178  _state->newShader( fragmentShader_glsl, GL_FRAGMENT_SHADER );
179  LBASSERT( fShader != VertexBufferState::INVALID );
180  const GLchar* fShaderPtr = fragmentShader_glsl;
181  glShaderSource( fShader, 1, &fShaderPtr, 0 );
182  glCompileShader( fShader );
183  glGetShaderiv( fShader, GL_COMPILE_STATUS, &status );
184  if( !status )
185  {
186  LBWARN << "Failed to compile fragment shader" << std::endl;
187  return;
188  }
189 
190  const GLuint program = _state->newProgram( getPipe() );
191  LBASSERT( program != VertexBufferState::INVALID );
192  glAttachShader( program, vShader );
193  glAttachShader( program, fShader );
194  glLinkProgram( program );
195  glGetProgramiv( program, GL_LINK_STATUS, &status );
196  if( !status )
197  {
198  LBWARN << "Failed to link shader program" << std::endl;
199  return;
200  }
201 
202  // turn off OpenGL lighting if we are using our own shaders
203  glDisable( GL_LIGHTING );
204 
205  LBINFO << "Shaders loaded successfully" << std::endl;
206 }
207 
208 void Window::frameStart( const eq::uint128_t& frameID, const uint32_t frameNumber )
209 {
210  const Pipe* pipe = static_cast<Pipe*>( getPipe( ));
211  const FrameData& frameData = pipe->getFrameData();
212 
213  _state->setRenderMode( frameData.getRenderMode( ));
214  eq::Window::frameStart( frameID, frameNumber );
215 }
216 
217 }
virtual EQ_API bool configInitSystemWindow(const uint128_t &initID)
Initialize the OS-specific window.
The representation of one GPU.
EQ_API const Config * getConfig() const
EQ_API bool upload(const Frame::Buffer buffer, util::Texture *texture, const Vector2i &position, util::ObjectManager &glObjects) const
Upload this image to the frame buffer or a texture.
EQFABRIC_INL void setIAttribute(const WindowSettings::IAttribute attr, const int32_t value)
Set a window attribute.
EQ_API void deleteGLObjects(util::ObjectManager &om)
Delete all OpenGL objects allocated from the given object manager.
virtual EQ_API void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
A holder for pixel data.
Definition: image.h:35
virtual EQ_API bool configExitSystemWindow()
De-initialize the OS-specific window.
virtual bool configInitSystemWindow(const eq::uint128_t &initID)
Initialize the OS-specific window.
virtual bool configExitGL()
De-initialize the OpenGL state for this window.
virtual bool configExitGL()
De-initialize the OpenGL state for this window.
virtual void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
EQ_API int32_t getWidth() const
A facility class to manage OpenGL objects across shared contexts.
Definition: objectManager.h:51
EQ_API int32_t getHeight() const
EQ_API bool readImage(const std::string &filename, const Frame::Buffer buffer)
Read pixel data from an uncompressed rgb image file.
The configuration, run be the EqPly application.
virtual EQ_API bool configInitGL(const uint128_t &initID)
Initialize the OpenGL state for this window.
virtual bool configInitGL(const eq::uint128_t &initID)
Initialize the OpenGL state for this window.
util::ObjectManager & getObjectManager()