scenegraph: separated scissoring state in a separate object.
[fail.git] / src / scenegraph / Scissor.h
blobf1c30a2737ef83a0dd5fda1e63af85e3b496239f
1 /*
2 Fail game engine
3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Fail.
7 Fail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Fail is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef FAIL_SCENEGRAPH_SCISSOR_H_
20 #define FAIL_SCENEGRAPH_SCISSOR_H_
22 #include "core/core.h"
23 #include "scenegraph/scenegraph_export.h"
24 #include "ViewPort.h"
25 #include "math/Rectu32.h"
26 #include <GL/gl.h>
28 namespace fail { namespace scenegraph
30 class FLSCENEGRAPH_EXPORT Scissor : public Serializable
32 public:
33 Scissor( const math::Rectu32& rect_ );
34 Scissor( const math::Vector2u32& position_, const math::Vector2u32& size_ );
35 Scissor( uint32_t left_, uint32_t top_, uint32_t width_, uint32_t height_ );
36 Scissor( const Serialization_tag& );
38 const math::Rectu32& getRect() const { return m_Rect; }
39 math::Rectu32& getRect() { return m_Rect; }
40 void setRect( const math::Rectu32& x ) { m_Rect = x; }
42 void renderSetup( ViewPort* pViewPort ) const
44 glScissor( m_Rect.left(), pViewPort->getRect().height() - ( m_Rect.top() + m_Rect.height() ),
45 m_Rect.width(), m_Rect.height() );
46 glEnable( GL_SCISSOR_TEST );
49 static void Clear()
51 glDisable( GL_SCISSOR_TEST );
54 private:
55 template< class C, typename T > friend struct fail::attribute_traits;
56 math::Rectu32 m_Rect;
60 #endif