Equalizer  1.6.1
eVolve/window.cpp
1 
2 /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com>
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 "window.h"
30 
31 #include "error.h"
32 #include "pipe.h"
33 
34 namespace eVolve
35 {
36 
37 bool Window::configInit( const eq::uint128_t& initID )
38 {
39  // Enforce alpha channel, since we need one for rendering
41 
42  return eq::Window::configInit( initID );
43 }
44 
45 bool Window::configInitGL( const eq::uint128_t& initID )
46 {
47  Pipe* pipe = static_cast<Pipe*>( getPipe() );
48  Renderer* renderer = pipe->getRenderer();
49 
50  if( !renderer )
51  return false;
52 
53  if( !GLEW_ARB_shader_objects )
54  {
55  setError( ERROR_EVOLVE_ARB_SHADER_OBJECTS_MISSING );
56  return false;
57  }
58  if( !GLEW_EXT_blend_func_separate )
59  {
60  setError( ERROR_EVOLVE_EXT_BLEND_FUNC_SEPARATE_MISSING );
61  return false;
62  }
63  if( !GLEW_ARB_multitexture )
64  {
65  setError( ERROR_EVOLVE_ARB_MULTITEXTURE_MISSING );
66  return false;
67  }
68 
69  glEnable( GL_SCISSOR_TEST ); // needed to constrain channel viewport
70 
71  glClear( GL_COLOR_BUFFER_BIT );
72  swapBuffers();
73  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
74 
75  renderer->glewSetContext( glewGetContext( ));
76 
77  if( !renderer->loadShaders( ))
78  {
79  setError( ERROR_EVOLVE_LOADSHADERS_FAILED );
80  return false;
81  }
82 
83  _loadLogo();
84  return true;
85 }
86 
87 namespace
88 {
89 #ifdef EQ_RELEASE
90 # ifdef _WIN32 // final INSTALL_DIR is not known at compile time
91 static const std::string _logoTextureName =
92  std::string( "../share/Equalizer/data/logo.rgb" );
93 # else
94 static const std::string _logoTextureName = std::string( EQ_INSTALL_DIR ) +
95  std::string( "share/Equalizer/data/logo.rgb" );
96 # endif
97 #else
98 static const std::string _logoTextureName = std::string( EQ_SOURCE_DIR ) +
99  std::string( "examples/eVolve/logo.rgb" );
100 #endif
101 }
102 
103 void Window::_loadLogo()
104 {
105  if( !GLEW_ARB_texture_rectangle )
106  {
107  LBWARN << "Can't load overlay logo, GL_ARB_texture_rectangle not "
108  << "available" << std::endl;
109  return;
110  }
111 
113  _logoTexture = om->getEqTexture( _logoTextureName.c_str( ));
114  if( _logoTexture )
115  return;
116 
117  eq::Image image;
118  if( !image.readImage( _logoTextureName, eq::Frame::BUFFER_COLOR ))
119  {
120  LBWARN << "Can't load overlay logo " << _logoTextureName << std::endl;
121  return;
122  }
123 
124  _logoTexture = om->newEqTexture( _logoTextureName.c_str(),
125  GL_TEXTURE_RECTANGLE_ARB );
126  LBASSERT( _logoTexture );
127 
128  image.upload(eq::Frame::BUFFER_COLOR, _logoTexture, eq::Vector2i::ZERO, om);
129  image.deleteGLObjects( om );
130  LBVERB << "Created logo texture of size " << _logoTexture->getWidth() << "x"
131  << _logoTexture->getHeight() << std::endl;
132 }
133 
134 
136 {
137  const Pipe* pipe = static_cast<Pipe*>( getPipe( ));
138  const FrameData& frameData = pipe->getFrameData();
139  const eq::Channels& channels = getChannels();
140 
141  if( frameData.useStatistics() && !channels.empty( ))
142  EQ_GL_CALL( channels.back()->drawStatistics( ));
143 
145 }
146 }
bool upload(const Frame::Buffer buffer, util::Texture *texture, const Vector2i &position, ObjectManager *glObjects) const
Upload this image to the frame buffer or a texture.
virtual void swapBuffers()
Swap the front and back buffer of the window.
virtual bool configInit(const eq::uint128_t &initID)
Initialize this window.
A holder for pixel data.
Definition: image.h:35
int32_t getHeight() const
A facility class to manage OpenGL objects across shared contexts.
bool readImage(const std::string &filename, const Frame::Buffer buffer)
Read pixel data from an uncompressed rgb image file.
void deleteGLObjects(ObjectManager *om)
Delete all OpenGL objects allocated from the given object manager.
virtual bool configInit(const uint128_t &initID)
Initialize this window.
virtual bool configInitGL(const eq::uint128_t &initID)
Initialize the OpenGL state for this window.
ObjectManager * getObjectManager()
std::vector< Channel * > Channels
A vector of pointers to eq::Channel.
void setError(const int32_t error)
Set an error code why the last operation failed.
void setIAttribute(const IAttribute attr, const int32_t value)
Set a window attribute.
int32_t getWidth() const
virtual void swapBuffers()
Swap the front and back buffer of the window.
const GLEWContext * glewGetContext() const
Get the GLEW context for this window.