1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
27
#include "../kernel/WKernel.h"
29
#include "WFiberDrawable.h"
31
// The constructor here does nothing. One thing that may be necessary is
32
// disabling display lists. This can be done by calling
33
// setSupportsDisplayList (false);
34
// Display lists should be disabled for 'Drawable's that can change over
35
// time (that is, the vertices drawn change from time to time).
36
WFiberDrawable::WFiberDrawable():
40
setSupportsDisplayList( false );
41
// This contructor intentionally left blank. Duh.
44
// I can't say much about the methods below, but OSG seems to expect
45
// that we implement them.
46
WFiberDrawable::WFiberDrawable( const WFiberDrawable& /*pg*/, const osg::CopyOp& /*copyop*/ ):
51
osg::Object* WFiberDrawable::cloneType() const
53
return new WFiberDrawable();
56
osg::Object* WFiberDrawable::clone( const osg::CopyOp& copyop ) const
58
return new WFiberDrawable( *this, copyop );
61
// Real work is done here. THERE IS A VERY IMPORTANT THING TO NOTE HERE:
62
// the 'drawImplementation()' method receives an 'osg::State' as
63
// parameter. This can be used to change the OpenGL state, but changing
64
// the OpenGL state here is something to be avoided as much as possible.
65
// Do this *only* if it is *absolutely* necessary to make your rendering
66
// algorithm work. The "right" (most efficient and flexible) way to change
67
// the OpenGL state in OSG is by attaching 'StateSet's to 'Node's and
69
// That said, the example below shows how to change the OpenGL state in
70
// these rare cases in which it is necessary. But always keep in mind:
71
// *Change the OpenGL state only if strictly necessary*.
72
void WFiberDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const //NOLINT
80
drawFibers( renderInfo );
84
void WFiberDrawable::drawFibers( osg::RenderInfo& renderInfo ) const //NOLINT
86
osg::State& state = *renderInfo.getState();
88
state.disableAllVertexArrays();
89
state.setVertexPointer( 3, GL_FLOAT , 0, &( *m_verts )[0] );
90
state.setColorPointer( 3 , GL_FLOAT , 0, &( *m_colors )[0] );
91
//state.setNormalPointer( GL_FLOAT , 0, &( *m_tangents )[0] );
92
for( size_t i = 0; i < m_active->size(); ++i )
96
state.glDrawArraysInstanced( GL_LINE_STRIP, (*m_startIndexes)[i], (*m_pointsPerLine)[i], 1);
100
state.disableVertexPointer();
101
state.disableColorPointer();
104
void WFiberDrawable::drawTubes() const
106
for( size_t i = 0; i < m_active->size(); ++i )
110
glBegin( GL_QUAD_STRIP );
111
int idx = m_startIndexes->at( i ) * 3;
112
for( size_t k = 0; k < m_pointsPerLine->at( i ); ++k )
114
glNormal3f( m_tangents->at( idx ), m_tangents->at( idx + 1 ), m_tangents->at( idx + 2 ) );
115
glColor3f( m_colors->at( idx ), m_colors->at( idx + 1 ), m_colors->at( idx + 2 ) );
116
glTexCoord1f( -1.0f );
117
glVertex3f( m_verts->at( idx ), m_verts->at( idx + 1 ), m_verts->at( idx + 2 ) );
118
glTexCoord1f( 1.0f );
119
glVertex3f( m_verts->at( idx ), m_verts->at( idx + 1 ), m_verts->at( idx + 2 ) );