1 #ifndef AWFUL_SCENEGRAPH_VIEWPORT_H_
2 #define AWFUL_SCENEGRAPH_VIEWPORT_H_
6 #include "Projection.h"
7 #include "math/Rectu32.h"
10 namespace awful
{ namespace scenegraph
12 class ViewPort
: public Serializable
15 ViewPort( const Pointer
< Projection
>& pProjection
, const Pointer
< Camera
>& pCamera
= NULL
) :
16 m_pProjection( pProjection
),
20 m_bClearColorBuffer( true ),
21 m_bClearDepthBuffer( true )
25 ViewPort( const Serialization_tag
& ) {}
27 const Pointer
< Camera
>& getpCamera() const { return m_pCamera
; }
28 void setpCamera( const Pointer
< Camera
>& x
) { m_pCamera
= x
; }
30 const Pointer
< Projection
>& getpProjection() const { return m_pProjection
; }
31 void setpProjection( const Pointer
< Projection
>& x
) { m_pProjection
= x
; }
33 const math::Rectu32
& getRect() const { return m_Rect
; }
34 math::Rectu32
& getRect() { return m_Rect
; }
35 void setRect( const math::Rectu32
& x
) { m_Rect
= x
; }
37 const float& getZNear() const { return m_ZNear
; }
38 void setZNear( const float& x
) { m_ZNear
= x
; }
40 const float& getZFar() const { return m_ZFar
; }
41 void setZFar( const float& x
) { m_ZFar
= x
; }
43 const bool& getbClearColorBuffer() const { return m_bClearColorBuffer
; }
44 void setbClearColorBuffer( const bool& x
) { m_bClearColorBuffer
= x
; }
46 const bool& getbClearDepthBuffer() const { return m_bClearDepthBuffer
; }
47 void setbClearDepthBuffer( const bool& x
) { m_bClearDepthBuffer
= x
; }
49 void renderSetup() const
53 if( m_bClearColorBuffer
)
54 clearflags
|= GL_COLOR_BUFFER_BIT
;
55 if( m_bClearDepthBuffer
)
56 clearflags
|= GL_DEPTH_BUFFER_BIT
;
59 glClear( clearflags
);
61 glViewport( m_Rect
.left(), m_Rect
.top(), m_Rect
.width(), m_Rect
.height() );
63 m_pProjection
->renderSetup( m_Rect
, m_pCamera
? m_pCamera
->getFOV() : 60.f
);
65 // Just for testing purpose, a proper light system will of course need to
67 glEnable( GL_LIGHT0
);
69 GLfloat pos
[] = { 0.f
, -1.f
, 0.f
};
70 glLightfv( GL_LIGHT0
, GL_POSITION
, pos
);
74 void getCameraMatrix( math::Matrix44f
& Dest
)
77 m_pCamera
->matrix( Dest
);
83 template< class C
, typename T
> friend struct awful::attribute_traits
;
84 Pointer
< Projection
> m_pProjection
;
85 Pointer
< Camera
> m_pCamera
;
90 bool m_bClearColorBuffer
;
91 bool m_bClearDepthBuffer
;