File: renderWindow.h

package info (click to toggle)
ball 1.4.3~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 318,984 kB
  • sloc: cpp: 346,579; ansic: 4,097; python: 2,664; yacc: 1,778; lex: 1,099; xml: 964; sh: 688; sql: 316; awk: 118; makefile: 108
file content (120 lines) | stat: -rw-r--r-- 4,274 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_VIEW_RENDERING_RENDERINGWINDOW_H
#define BALL_VIEW_RENDERING_RENDERINGWINDOW_H

#include <BALL/COMMON/global.h>
#include <BALL/VIEW/RENDERING/renderTarget.h>

#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>

///Macro checks at compile time, whether <tt>aTypeA</tt> and <tt>aTypeB</tt> are the same
#define BALLVIEW_IS_SAME_TYPE(aTypeA, aTypeB) (boost::is_same<aTypeA, aTypeB>::value)

///Macro checks at compile time, whether <tt>aType</tt> is int or float
#define BALLVIEW_STATIC_ASSERT_TYPE_IS_CHAR_OR_FLOAT(aType)				                                \
        BOOST_STATIC_ASSERT(BALLVIEW_IS_SAME_TYPE(aType, char) || BALLVIEW_IS_SAME_TYPE(aType, float))

#define BALL_DEFAULT_PIXEL_TYPE float

namespace BALL
{
	namespace VIEW
	{        
		/**
		 * General rendering window interface.
		 * Such a window represents a surface on a screen or other device, where a buffer encapsulated by
		 * \link RenderTarget \endlink interface can be displayed
		 */
		template<typename taPixelDatatype>
			class BALL_VIEW_EXPORT TRenderWindow : public RenderTarget
		{
			// only int or floats are allowed as template parameters
			BALLVIEW_STATIC_ASSERT_TYPE_IS_CHAR_OR_FLOAT(taPixelDatatype);

			// type of the pixel buffer pointer
			typedef boost::shared_array<taPixelDatatype> t_PixelPtr;

			public:

			TRenderWindow();

			virtual ~TRenderWindow();            

			/* Initialize window internals. After that call, window is ready to receive \link resize \endlink call             
			 * returns false if the initialization fails
			 */
			virtual bool init();

			/** 
			 * Request new window size. 
			 * Returns false if such a size cannot be supplied
			 * This call must be made before the window buffer is handed out to be rendered.
			 * This precondition is being checked automatically, see \link getBuffer \endlink
			 */ 
			virtual bool resize(const unsigned int width, const unsigned int height);

			/**
			 * Request that the image is actually displayed on the screen or other device the window encapsulated.
			 * You should implement this method in subclass.
			 * This is different from \link RenderTarget \endlink \link releaseBuffer \endlink.
			 * ReleaseBuffer only informs the window that a buffer is ready, but does not imply the buffer is actually
			 * displayed somewhere. This is done by refresh. On the other hand, refresh called inbetween
			 * getBuffer and releaseBuffer has no effect.
			 */ 
			virtual void refresh();


			/* =====================
			 * RenderTarget methods
			 * ===================== */	

			/*
			 * See \link RenderTarget \endlink for general description.
			 * In addition there is a precondition that \link init \endlink must be called before 
			 * getBuffer. If not, \link NoBufferAvailable \endlink exception is thrown.
			 */
			virtual FrameBufferPtr getBuffer() throw(BALL::Exception::NoBufferAvailable);            

			/*
			 * See \link RenderTarget \endlink for description.
			 */
			virtual FrameBufferFormat getFormat() const;

			/*
			 * See \link RenderTarget \endlink for description.
			 */
			virtual void releaseBuffer(FrameBufferPtr buffer);			

			/* Prepare the window for rendering, e.g., make it current if necessary.
			 */
			virtual void prepareRendering() {};

			/** @copydoc RenderTarget::doNotResize 
			 */
			virtual bool doNotResize() const { return do_not_resize_; }

			virtual void setDoNotResize(bool do_not_resize) { do_not_resize_ = do_not_resize; }
			 

			protected:
			t_PixelPtr m_pixels;					// raw pixel buffer
			FrameBufferPtr m_framebuffer;           // frame buffer given out to the wild by getBuffer method
			FrameBufferFormat m_fmt;				// description of the buffer format
			const PixelFormat m_pfm;                // pixel format of the window
			bool m_bufferLocked;					// pixel buffer is being accessed by another object?            
			const Size m_minimalWidth;      // minimum with the window can have
			const Size m_minimalHeight;     // minimum height the window can have
			bool do_not_resize_;
		};

		typedef TRenderWindow<BALL_DEFAULT_PIXEL_TYPE> RenderWindow;

	} // namespace VIEW

} // namespace BALL

#endif // BALL_VIEW_RENDERING_RENDERINGWINDOW_H