2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // BobView.cpp: implementation of the DVisDrawer class.
22 //////////////////////////////////////////////////////////////////////
24 #include "DVisDrawer.h"
26 #include "iglrender.h"
27 #include "math/matrix.h"
36 #include "funchandlers.h"
38 //////////////////////////////////////////////////////////////////////
39 // Construction/Destruction
40 //////////////////////////////////////////////////////////////////////
42 DVisDrawer::DVisDrawer(){
46 GlobalShaderCache().attachRenderable( *this );
49 DVisDrawer::~DVisDrawer(){
50 GlobalShaderCache().detachRenderable( *this );
56 //////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////
59 const char* g_state_solid = "$bobtoolz/visdrawer/solid";
60 const char* g_state_wireframe = "$bobtoolz/visdrawer/wireframe";
62 void DVisDrawer::constructShaders(){
64 GlobalOpenGLStateLibrary().getDefaultState( state );
65 state.m_state = RENDER_COLOURWRITE | RENDER_DEPTHWRITE | RENDER_COLOURCHANGE;
66 state.m_linewidth = 1;
68 GlobalOpenGLStateLibrary().insert( g_state_wireframe, state );
70 GlobalOpenGLStateLibrary().getDefaultState( state );
71 state.m_state = RENDER_FILL | RENDER_BLEND | RENDER_COLOURWRITE | RENDER_COLOURCHANGE | RENDER_SMOOTH | RENDER_DEPTHWRITE;
73 GlobalOpenGLStateLibrary().insert( g_state_solid, state );
75 m_shader_solid = GlobalShaderCache().capture( g_state_solid );
76 m_shader_wireframe = GlobalShaderCache().capture( g_state_wireframe );
79 void DVisDrawer::destroyShaders(){
80 GlobalShaderCache().release( g_state_solid );
81 GlobalShaderCache().release( g_state_wireframe );
82 GlobalOpenGLStateLibrary().erase( g_state_solid );
83 GlobalOpenGLStateLibrary().erase( g_state_wireframe );
86 void DVisDrawer::render( RenderStateFlags state ) const {
88 std::list<DWinding *>::const_iterator l = m_list->begin();
90 for (; l != m_list->end(); l++ )
94 glColor4f( w->clr[0], w->clr[1], w->clr[2], 0.5f );
96 glBegin( GL_POLYGON );
97 for ( int i = 0; i < w->numpoints; i++ ) {
98 glVertex3f( ( w->p[i] )[0], ( w->p[i] )[1], ( w->p[i] )[2] );
104 void DVisDrawer::renderWireframe( Renderer& renderer, const VolumeTest& volume ) const {
109 renderer.SetState( m_shader_wireframe, Renderer::eWireframeOnly );
111 renderer.addRenderable( *this, g_matrix4_identity );
114 void DVisDrawer::renderSolid( Renderer& renderer, const VolumeTest& volume ) const {
119 renderer.SetState( m_shader_solid, Renderer::eWireframeOnly );
120 renderer.SetState( m_shader_solid, Renderer::eFullMaterials );
122 renderer.addRenderable( *this, g_matrix4_identity );
125 void DVisDrawer::SetList( std::list<DWinding*> *pointList ){
133 void DVisDrawer::ClearPoints(){
134 std::list<DWinding *>::const_iterator deadPoint = m_list->begin();
135 for (; deadPoint != m_list->end(); deadPoint++ )