lib/client/window.h

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQ_WINDOW_H
00019 #define EQ_WINDOW_H
00020 
00021 #include <eq/client/objectManager.h> // member
00022 #include <eq/client/pixelViewport.h> // member
00023 #include <eq/client/renderContext.h> // member
00024 #include <eq/client/types.h>
00025 #include <eq/client/visitorResult.h> // enum
00026 
00027 #include <eq/util/bitmapFont.h>      // member
00028 #include <eq/net/object.h>           // base class
00029 
00030 namespace eq
00031 {
00032     class OSWindow;
00033     class WindowVisitor;
00034     struct Event;
00035 
00051     class Window : public net::Object
00052     {
00053     public:
00055         struct DrawableConfig
00056         {
00057             int32_t stencilBits;
00058             int32_t alphaBits;
00059             float   glVersion;
00060             bool    stereo;
00061             bool    doublebuffered;
00062         };
00063         
00065         class ObjectManager : public eq::ObjectManager< const void* >
00066         {
00067         public:
00068             ObjectManager( Window* window ) 
00069                     : eq::ObjectManager<const void *>(window->glewGetContext( ))
00070                     , _smallFont( window )
00071                     , _mediumFont( window )
00072                 {}
00073             ObjectManager( Window* window, ObjectManager* shared ) 
00074                     : eq::ObjectManager<const void *>(window->glewGetContext(),
00075                                                       shared )
00076                     , _smallFont( window )
00077                     , _mediumFont( window )
00078                 {}
00079             virtual ~ObjectManager(){}
00080             
00082             const util::BitmapFont& getDefaultFont() const { return _smallFont;}
00083 
00085             const util::BitmapFont& getMediumFont() const { return _mediumFont;}
00086 
00087         private:
00088             util::BitmapFont _smallFont;
00089             util::BitmapFont _mediumFont;
00090 
00091             friend class Window;
00092         };
00093 
00095         EQ_EXPORT Window( Pipe* parent );
00096 
00098         EQ_EXPORT virtual ~Window();
00099 
00102         EQ_EXPORT net::CommandQueue* getPipeThreadQueue();
00103 
00105         const Pipe* getPipe() const { return _pipe; }
00106         Pipe*       getPipe()       { return _pipe; }
00107 
00108         EQ_EXPORT const Node* getNode() const; 
00109         EQ_EXPORT Node*       getNode();
00110 
00111         EQ_EXPORT const Config* getConfig() const;
00112         EQ_EXPORT Config*       getConfig();
00113 
00114         EQ_EXPORT ClientPtr getClient();
00115         EQ_EXPORT ServerPtr getServer();
00116 
00117         const ChannelVector& getChannels() { return _channels; }
00118 
00119         const std::string& getName() const { return _name; }
00120 
00121         bool isRunning() const { return (_state == STATE_RUNNING); }
00122 
00133         uint32_t getTasks() const { return _tasks; }
00134 
00141         EQ_EXPORT VisitorResult accept( WindowVisitor& visitor );
00142 
00147         void setSharedContextWindow( Window* sharedContextWindow )
00148             { _sharedContextWindow = sharedContextWindow; }
00149 
00151         const Window* getSharedContextWindow() const 
00152             { return _sharedContextWindow; }
00153 
00155         Window* getSharedContextWindow() 
00156             { return _sharedContextWindow; }
00157 
00158 
00172         EQ_EXPORT GLEWContext* glewGetContext();
00173 
00175         EQ_EXPORT WGLEWContext* wglewGetContext();
00176 
00178         const DrawableConfig& getDrawableConfig() const 
00179             { return _drawableConfig; }
00180 
00182         ObjectManager* getObjectManager() { return _objectManager; }
00183         const ObjectManager* getObjectManager() const { return _objectManager; }
00184 
00192         EQ_EXPORT void setPixelViewport( const PixelViewport& pvp );
00193         
00197         EQ_EXPORT const PixelViewport& getPixelViewport() const { return _pvp; }
00198 
00202         const Viewport& getViewport() const { return _vp; }
00203 
00205         void addRenderContext( const RenderContext& context );
00206 
00208         EQ_EXPORT bool getRenderContext( const int32_t x, const int32_t y,
00209                                          RenderContext& context ) const;
00211 
00216         // Note: also update string array initialization in window.cpp
00218         enum IAttribute
00219         {
00220             IATTR_HINT_STEREO,           
00221             IATTR_HINT_DOUBLEBUFFER,     
00222             IATTR_HINT_FULLSCREEN,       
00223             IATTR_HINT_DECORATION,       
00224             IATTR_HINT_SWAPSYNC,         
00225             IATTR_HINT_DRAWABLE,         
00226             IATTR_HINT_STATISTICS,       
00227             IATTR_HINT_SCREENSAVER,      
00228             IATTR_PLANES_COLOR,          
00229             IATTR_PLANES_ALPHA,          
00230             IATTR_PLANES_DEPTH,          
00231             IATTR_PLANES_STENCIL,        
00232             IATTR_PLANES_ACCUM,          
00233             IATTR_PLANES_ACCUM_ALPHA,    
00234             IATTR_PLANES_SAMPLES,        
00235             IATTR_FILL1,
00236             IATTR_FILL2,
00237             IATTR_ALL
00238         };
00239 
00240         EQ_EXPORT void setIAttribute( const IAttribute attr,
00241                                       const int32_t value );
00242         EQ_EXPORT int32_t  getIAttribute( const IAttribute attr ) const;
00243         EQ_EXPORT static const std::string& getIAttributeString(
00244                                                 const IAttribute attr );
00246 
00250         virtual void flush() const { glFlush(); } 
00252         virtual void finish() const { glFinish(); }
00254 
00268         EQ_EXPORT void setOSWindow( OSWindow* window );
00269 
00270         const OSWindow* getOSWindow() const { return _osWindow; }
00271         OSWindow*       getOSWindow()       { return _osWindow; }
00272 
00274 
00285         EQ_EXPORT void setErrorMessage( const std::string& message );
00287 
00295 
00306         EQ_EXPORT virtual bool processEvent( const Event& event );
00307 
00309 
00311         double getFPS() const { return _avgFPS; }
00312 
00313         /* Draw FPS count */
00314         EQ_EXPORT virtual void drawFPS() const;
00315 
00317         int getColorType();
00318         
00320         EQ_EXPORT bool isFBOWindow();
00321 
00322     protected:
00323         friend class Pipe;
00324 
00325         EQ_EXPORT virtual void attachToSession( const uint32_t id, 
00326                                                 const uint32_t instanceID, 
00327                                                 net::Session* session );
00328 
00336         void startFrame( const uint32_t frameNumber ) { /* currently nop */ }
00337 
00343         void releaseFrame( const uint32_t frameNumber ) { /* currently nop */ }
00344 
00350         void releaseFrameLocal( const uint32_t frameNumber ) { /* nop */ }
00352 
00360 
00366         EQ_EXPORT virtual bool configInit( const uint32_t initID );
00367 
00373         EQ_EXPORT virtual bool configInitOSWindow( const uint32_t initID );
00374 
00382         EQ_EXPORT virtual bool configInitGL( const uint32_t initID );
00383 
00385         EQ_EXPORT virtual bool configExit();
00386 
00388         EQ_EXPORT virtual bool configExitOSWindow();
00389 
00391         virtual bool configExitGL() { return true; }
00392 
00403         virtual void frameStart( const uint32_t frameID, 
00404                                  const uint32_t frameNumber ) 
00405             { startFrame( frameNumber ); }
00406 
00419         EQ_EXPORT virtual void frameFinish( const uint32_t frameID, 
00420                                             const uint32_t frameNumber );
00421 
00431         virtual void frameDrawFinish( const uint32_t frameID, 
00432                                       const uint32_t frameNumber )
00433             { releaseFrameLocal( frameNumber ); }
00434 
00443         EQ_EXPORT virtual void makeCurrent( const bool cache = true ) const;
00444 
00446         EQ_EXPORT virtual void bindFrameBuffer() const;
00447 
00449         EQ_EXPORT virtual void swapBuffers();
00451 
00452     private:
00454         Pipe* const   _pipe;
00455 
00457         std::string    _name;
00458 
00460         Window* _sharedContextWindow;
00461 
00463         std::string    _error;
00464 
00466         OSWindow* _osWindow;
00467 
00469         int32_t _iAttributes[IATTR_ALL];
00471         static std::string _iAttributeStrings[IATTR_ALL];
00472 
00474         uint32_t _tasks;
00475 
00477         ChannelVector     _channels;
00478 
00480         eq::PixelViewport _pvp;
00481 
00483         eq::Viewport      _vp;
00484 
00486         Window::DrawableConfig _drawableConfig;
00487 
00488         enum State
00489         {
00490             STATE_STOPPED,
00491             STATE_INITIALIZING,
00492             STATE_RUNNING
00493         };
00495         State _state;
00496 
00498         ObjectManager* _objectManager;
00499 
00501         double _lastTime;
00502 
00504         double _avgFPS;
00505 
00507         std::vector< RenderContext > _renderContexts[2];
00508         enum 
00509         {
00510             FRONT = 0,
00511             BACK  = 1
00512         };
00513 
00515         int64_t _lastSwapTime;
00516 
00517         union // placeholder for binary-compatible changes
00518         {
00519             char dummy[64];
00520         };
00521 
00522         friend class Channel;
00523         void _addChannel( Channel* channel );
00524         void _removeChannel( Channel* channel );
00525         Channel* _findChannel( const uint32_t id );
00526 
00527         bool _setPixelViewport( const PixelViewport& pvp );
00528         void _setViewport( const Viewport& vp );
00529 
00531         void _setupObjectManager();
00533         void _releaseObjectManager();
00534 
00536         void _queryDrawableConfig();
00537 
00539         void _updateFPS();
00540 
00542         void _enterBarrier( net::ObjectVersion barrier );
00543 
00544         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00545         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00546 
00547         /* The command functions. */
00548         net::CommandResult _cmdCreateChannel( net::Command& command );
00549         net::CommandResult _cmdDestroyChannel(net::Command& command );
00550         net::CommandResult _cmdConfigInit( net::Command& command );
00551         net::CommandResult _cmdConfigExit( net::Command& command );
00552         net::CommandResult _cmdFrameStart( net::Command& command );
00553         net::CommandResult _cmdFrameFinish( net::Command& command );
00554         net::CommandResult _cmdThrottleFramerate( net::Command& command );
00555         net::CommandResult _cmdFinish( net::Command& command );
00556         net::CommandResult _cmdBarrier( net::Command& command );
00557         net::CommandResult _cmdNVBarrier( net::Command& command );
00558         net::CommandResult _cmdSwap( net::Command& command );
00559         net::CommandResult _cmdFrameDrawFinish( net::Command& command );
00560 
00561         CHECK_THREAD_DECLARE( _pipeThread );
00562     };
00563 
00564     std::ostream& operator << ( std::ostream& , const Window::DrawableConfig& );
00565 }
00566 
00567 #endif // EQ_WINDOW_H
00568 
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8