renderWindow.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_VIEW_RENDERING_RENDERINGWINDOW_H
00006 #define BALL_VIEW_RENDERING_RENDERINGWINDOW_H
00007 
00008 #include <BALL/COMMON/global.h>
00009 #include <BALL/VIEW/RENDERING/renderTarget.h>
00010 
00011 #include <boost/static_assert.hpp>
00012 #include <boost/type_traits/is_same.hpp>
00013 
00015 #define BALLVIEW_IS_SAME_TYPE(aTypeA, aTypeB) (boost::is_same<aTypeA, aTypeB>::value)
00016 
00018 #define BALLVIEW_STATIC_ASSERT_TYPE_IS_INT_OR_FLOAT(aType)                                        \
00019         BOOST_STATIC_ASSERT(BALLVIEW_IS_SAME_TYPE(aType, int) || BALLVIEW_IS_SAME_TYPE(aType, float))
00020 
00021 namespace BALL
00022 {
00023   namespace VIEW
00024   {        
00030     template<typename taPixelDatatype>
00031       class BALL_VIEW_EXPORT RenderWindow : public RenderTarget
00032     {
00033       // only int or floats are allowed as template parameters
00034       BALLVIEW_STATIC_ASSERT_TYPE_IS_INT_OR_FLOAT(taPixelDatatype);
00035 
00036       // type of the pixel buffer pointer
00037       typedef boost::shared_array<taPixelDatatype> t_PixelPtr;
00038 
00039       public:
00040 
00041       RenderWindow();
00042 
00043       virtual ~RenderWindow();            
00044 
00045       /* Initialize window internals. After that call, window is ready to receive \link resize \endlink call             
00046        * returns false if the initialization fails
00047        */
00048       virtual bool init();
00049 
00056       virtual bool resize(const unsigned int width, const unsigned int height);
00057 
00066       virtual void refresh();
00067 
00068 
00069       /* =====================
00070        * RenderTarget methods
00071        * ===================== */ 
00072 
00073       /*
00074        * See \link RenderTarget \endlink for general description.
00075        * In addition there is a precondition that \link init \endlink must be called before 
00076        * getBuffer. If not, \link NoBufferAvailable \endlink exception is thrown.
00077        */
00078       virtual FrameBufferPtr getBuffer() throw(BALL::Exception::NoBufferAvailable);            
00079 
00080       /*
00081        * See \link RenderTarget \endlink for description.
00082        */
00083       virtual FrameBufferFormat getFormat() const;
00084 
00085       /*
00086        * See \link RenderTarget \endlink for description.
00087        */
00088       virtual void releaseBuffer(FrameBufferPtr buffer);      
00089 
00090       /* Prepare the window for rendering, e.g., make it current if necessary.
00091        */
00092       virtual void prepareRendering() {};
00093 
00094       protected:
00095       t_PixelPtr m_pixels;          // raw pixel buffer
00096       FrameBufferPtr m_framebuffer;           // frame buffer given out to the wild by getBuffer method
00097       FrameBufferFormat m_fmt;        // description of the buffer format
00098       const PixelFormat m_pfm;                // pixel format of the window
00099       bool m_bufferLocked;          // pixel buffer is being accessed by another object?            
00100       const unsigned int m_minimalWidth;      // minimum with the window can have
00101       const unsigned int m_minimalHeight;     // minimum height the window can have
00102     };
00103 
00104     typedef RenderWindow<float> t_RenderWindow;
00105 
00106   } // namespace VIEW
00107 
00108 } // namespace BALL
00109 
00110 #endif // BALL_VIEW_RENDERING_RENDERINGWINDOW_H