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()
47 GlobalShaderCache().attachRenderable(*this);
50 DVisDrawer::~DVisDrawer()
52 GlobalShaderCache().detachRenderable(*this);
58 //////////////////////////////////////////////////////////////////////
60 //////////////////////////////////////////////////////////////////////
61 const char *g_state_solid = "$bobtoolz/visdrawer/solid";
62 const char *g_state_wireframe = "$bobtoolz/visdrawer/wireframe";
64 void DVisDrawer::constructShaders()
67 GlobalOpenGLStateLibrary().getDefaultState(state);
68 state.m_state = RENDER_COLOURWRITE | RENDER_DEPTHWRITE | RENDER_COLOURCHANGE;
69 state.m_linewidth = 1;
71 GlobalOpenGLStateLibrary().insert(g_state_wireframe, state);
73 GlobalOpenGLStateLibrary().getDefaultState(state);
75 RENDER_FILL | RENDER_BLEND | RENDER_COLOURWRITE | RENDER_COLOURCHANGE | RENDER_SMOOTH | RENDER_DEPTHWRITE;
77 GlobalOpenGLStateLibrary().insert(g_state_solid, state);
79 m_shader_solid = GlobalShaderCache().capture(g_state_solid);
80 m_shader_wireframe = GlobalShaderCache().capture(g_state_wireframe);
83 void DVisDrawer::destroyShaders()
85 GlobalShaderCache().release(g_state_solid);
86 GlobalShaderCache().release(g_state_wireframe);
87 GlobalOpenGLStateLibrary().erase(g_state_solid);
88 GlobalOpenGLStateLibrary().erase(g_state_wireframe);
91 void DVisDrawer::render(RenderStateFlags state) const
94 std::list<DWinding *>::const_iterator l = m_list->begin();
96 for (; l != m_list->end(); l++) {
99 glColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
102 for (int i = 0; i < w->numpoints; i++) {
103 glVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
109 void DVisDrawer::renderWireframe(Renderer &renderer, const VolumeTest &volume) const
115 renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
117 renderer.addRenderable(*this, g_matrix4_identity);
120 void DVisDrawer::renderSolid(Renderer &renderer, const VolumeTest &volume) const
126 renderer.SetState(m_shader_solid, Renderer::eWireframeOnly);
127 renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
129 renderer.addRenderable(*this, g_matrix4_identity);
132 void DVisDrawer::SetList(std::list<DWinding *> *pointList)
141 void DVisDrawer::ClearPoints()
143 std::list<DWinding *>::const_iterator deadPoint = m_list->begin();
144 for (; deadPoint != m_list->end(); deadPoint++) {