Commiting whatever state I got that gui data grid widget for archival and fond memori...
[fail.git] / src / scenegraph / RenderPass.cpp
blob8174b8052f7bbb2146bb6a8857d9d6d557f934c6
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 #include "scenegraph/RenderPass.h"
21 using namespace fail;
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();
52 Frame::ClearBound();
54 PassList::const_iterator it;
55 for( it = ms_RenderList.begin(); it != ms_RenderList.end(); ++it )
56 ( *it )->render();
59 void RenderPass::ClearAll()
61 PassList::iterator it;
62 for( it = ms_RenderList.begin(); it != ms_RenderList.end(); ++it )
63 ( *it )->clear();
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 )
72 ( *it )->render();
74 GLint clearflags = 0;
76 if( m_bClearColorBuffer )
77 clearflags |= GL_COLOR_BUFFER_BIT;
78 if( m_bClearDepthBuffer )
79 clearflags |= GL_DEPTH_BUFFER_BIT;
80 if( m_bClearStencil )
82 clearflags |= GL_STENCIL_BUFFER_BIT;
83 glClearStencil( m_StencilClearValue );
86 if( clearflags )
87 glClear( clearflags );
89 if( m_RenderMap.empty() && m_TextMap.empty() )
90 return;
92 m_pViewPort->renderSetup();
94 if( m_pScissor )
95 m_pScissor->renderSetup( m_pViewPort );
96 else
97 Scissor::Clear();
99 math::Matrix44f CameraMtx;
100 m_pViewPort->getCameraMatrix( CameraMtx );
102 GLfloat mcam[16];
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
127 // be created later.
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();
139 // I has a bucket
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 );
148 //glLoadIdentity();
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 );
163 // glLoadIdentity();
164 textit->second->getpFrame()->renderSetup();
167 if( textit->second->getClip() == 0.f )
168 textit->second->getpFont()->drawText( textit->second->getTextString() );
169 else
170 textit->second->getpFont()->drawTextRightClip( textit->second->getTextString(), textit->second->getClip() );
173 for( it = m_PostRenderList.begin(); it != m_PostRenderList.end(); ++it )
174 ( *it )->render();
177 void RenderPass::clear()
179 m_RenderMap.clear();
180 m_TextMap.clear();
182 PassList::iterator it;
183 for( it = m_PreRenderList.begin(); it != m_PreRenderList.end(); ++it )
184 ( *it )->clear();
186 for( it = m_PostRenderList.begin(); it != m_PostRenderList.end(); ++it )
187 ( *it )->clear();
189 m_PreRenderList.clear();
190 m_PostRenderList.clear();