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 #include "scenegraph/RenderPass.h"
22 using namespace fail::scenegraph
;
24 RenderPass::PassList
RenderPass::ms_RenderList
;
26 RenderPass::RenderPass( const Pointer
< ViewPort
>& pViewPort
) :
27 m_pViewPort( pViewPort
),
28 m_bClearColorBuffer( false ),
29 m_bClearDepthBuffer( false ),
30 m_bClearStencil( false ),
31 m_StencilClearValue( 0 )
35 RenderPass::RenderPass( const Pointer
< ViewPort
>& pViewPort
, const Pointer
< Scissor
>& pScissor
) :
36 m_pViewPort( pViewPort
),
37 m_pScissor( pScissor
),
38 m_bClearColorBuffer( false ),
39 m_bClearDepthBuffer( false ),
40 m_bClearStencil( false ),
41 m_StencilClearValue( 0 )
45 RenderPass::RenderPass( const Serialization_tag
& )
49 void RenderPass::RenderAll()
51 VertexBuffer::ClearBound();
54 PassList::const_iterator it
;
55 for( it
= ms_RenderList
.begin(); it
!= ms_RenderList
.end(); ++it
)
59 void RenderPass::ClearAll()
61 PassList::iterator it
;
62 for( it
= ms_RenderList
.begin(); it
!= ms_RenderList
.end(); ++it
)
65 ms_RenderList
.clear();
68 void RenderPass::render() const
70 PassList::const_iterator it
;
71 for( it
= m_PreRenderList
.begin(); it
!= m_PreRenderList
.end(); ++it
)
76 if( m_bClearColorBuffer
)
77 clearflags
|= GL_COLOR_BUFFER_BIT
;
78 if( m_bClearDepthBuffer
)
79 clearflags
|= GL_DEPTH_BUFFER_BIT
;
82 clearflags
|= GL_STENCIL_BUFFER_BIT
;
83 glClearStencil( m_StencilClearValue
);
87 glClear( clearflags
);
89 if( m_RenderMap
.empty() && m_TextMap
.empty() )
92 m_pViewPort
->renderSetup();
95 m_pScissor
->renderSetup( m_pViewPort
);
99 math::Matrix44f CameraMtx
;
100 m_pViewPort
->getCameraMatrix( CameraMtx
);
104 mcam
[0] = CameraMtx
.v1().x();
105 mcam
[1] = CameraMtx
.v1().z();
106 mcam
[2] = -CameraMtx
.v1().y();
107 mcam
[3] = CameraMtx
.v1().w();
109 mcam
[4] = CameraMtx
.v2().x();
110 mcam
[5] = CameraMtx
.v2().z();
111 mcam
[6] = -CameraMtx
.v2().y();
112 mcam
[7] = CameraMtx
.v2().w();
114 mcam
[8] = CameraMtx
.v3().x();
115 mcam
[9] = CameraMtx
.v3().z();
116 mcam
[10] = -CameraMtx
.v3().y();
117 mcam
[11] = CameraMtx
.v3().w();
119 mcam
[12] = CameraMtx
.v4().x();
120 mcam
[13] = CameraMtx
.v4().z();
121 mcam
[14] = -CameraMtx
.v4().y();
122 mcam
[15] = CameraMtx
.v4().w();
124 glMatrixMode( GL_MODELVIEW
);
126 // Just for testing purpose, a proper light system will of course need to
128 glEnable( GL_LIGHT0
);
130 glLoadMatrixf( mcam
);
131 GLfloat pos
[] = { 0.f
, -1.f
, 0.f
, 0.f
};
132 glLightfv( GL_LIGHT0
, GL_POSITION
, pos
);
134 RenderMap::const_iterator mapit
;
135 for( mapit
= m_RenderMap
.begin(); mapit
!= m_RenderMap
.end(); ++mapit
)
137 mapit
->first
.pMaterial
->renderSetup();
140 const Bucket
& MahBucket
= mapit
->second
;
141 Bucket::const_iterator it
;
142 for( it
= MahBucket
.begin(); it
!= MahBucket
.end(); ++it
)
144 // Render the fucking thing
145 if( ( *it
)->getpFrame()->needSetup() )
147 glLoadMatrixf( mcam
);
149 ( *it
)->getpFrame()->renderSetup();
152 ( *it
)->getpGeometry()->render();
156 TextMap::const_iterator textit
;
157 for( textit
= m_TextMap
.begin(); textit
!= m_TextMap
.end(); ++textit
)
159 textit
->second
->getpMaterial()->renderSetup();
160 if( textit
->second
->getpFrame()->needSetup() )
162 glLoadMatrixf( mcam
);
164 textit
->second
->getpFrame()->renderSetup();
167 if( textit
->second
->getClip() == 0.f
)
168 textit
->second
->getpFont()->drawText( textit
->second
->getTextString() );
170 textit
->second
->getpFont()->drawTextRightClip( textit
->second
->getTextString(), textit
->second
->getClip() );
173 for( it
= m_PostRenderList
.begin(); it
!= m_PostRenderList
.end(); ++it
)
177 void RenderPass::clear()
182 PassList::iterator it
;
183 for( it
= m_PreRenderList
.begin(); it
!= m_PreRenderList
.end(); ++it
)
186 for( it
= m_PostRenderList
.begin(); it
!= m_PostRenderList
.end(); ++it
)
189 m_PreRenderList
.clear();
190 m_PostRenderList
.clear();