OpenWalnut
1.3.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
core
graphicsEngine
callbacks
WGEPropertyUniformCallback.h
1
//---------------------------------------------------------------------------
2
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
4
//
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
7
//
8
// This file is part of OpenWalnut.
9
//
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.
14
//
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.
19
//
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/>.
22
//
23
//---------------------------------------------------------------------------
24
25
#ifndef WGEPROPERTYUNIFORMCALLBACK_H
26
#define WGEPROPERTYUNIFORMCALLBACK_H
27
28
#include <osg/Uniform>
29
30
#include "../../common/WProperties.h"
31
32
#include "../shaders/WGEUniformTypeTraits.h"
33
34
/**
35
* This class is an OSG Callback which allows uniforms to be controlled by properties. This is useful to simply forward properties to a shader.
36
* Please note that you still need to add this callback to the desired uniforms. A convenience class is WGEPropertyUniform which uses this
37
* callback. On each traversal of the OSG, the callback sets the value of the property to the uniform but does NOT reset the change flag.
38
*
39
* \tparam T the type used as control mechanism. The type specified must support access via T->get(). Specialize the class if
40
* you do not specify a pointer.
41
*/
42
template
<
typename
T >
43
class
WGEPropertyUniformCallback
:
public
osg::Uniform::Callback
44
{
45
public
:
46
/**
47
* Constructor. Creates the callback. You still need to add it to the desired uniform.
48
*
49
* \param property the property containing the value
50
*/
51
explicit
WGEPropertyUniformCallback
( T property );
52
53
/**
54
* Destructor.
55
*/
56
virtual
~WGEPropertyUniformCallback
();
57
58
/**
59
* The callback. Called every render traversal for the uniform. It sets the value of the property to the uniform.
60
*
61
* \param uniform the uniform for which this callback is.
62
* \param nv the visitor.
63
*/
64
virtual
void
operator()
( osg::Uniform* uniform, osg::NodeVisitor* nv );
65
66
/**
67
* The type which is used for this uniform.
68
*/
69
typedef
typename
wge::UniformType< typename T::element_type::ValueType >::Type
UniformType
;
70
71
protected
:
72
/**
73
* The property
74
*/
75
T
m_property
;
76
77
private
:
78
};
79
80
template
<
typename
T >
81
WGEPropertyUniformCallback< T >::WGEPropertyUniformCallback
( T property ):
82
osg::Uniform::Callback(),
83
m_property( property )
84
{
85
// initialize members
86
}
87
88
template
<
typename
T >
89
WGEPropertyUniformCallback< T >::~WGEPropertyUniformCallback
()
90
{
91
// cleanup
92
}
93
94
template
<
typename
T >
95
void
WGEPropertyUniformCallback< T >::operator()
( osg::Uniform* uniform, osg::NodeVisitor*
/*nv*/
)
96
{
97
uniform->set(
static_cast<
typename
WGEPropertyUniformCallback< T >::UniformType
>
( m_property->get() ) );
98
}
99
100
#endif // WGEPROPERTYUNIFORMCALLBACK_H
101
102
Generated by
1.8.4