25 #ifndef WGETEXTUREUTILS_H
26 #define WGETEXTUREUTILS_H
31 #include <osg/StateSet>
33 #include <osg/Texture1D>
34 #include <osg/Texture2D>
35 #include <osg/Texture3D>
37 #include <boost/lexical_cast.hpp>
39 #include "shaders/WGEPropertyUniform.h"
40 #include "callbacks/WGEPropertyTransformationCallback.h"
42 #include "WExportWGE.h"
63 template <
typename T >
64 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< T > texture,
size_t unit = 0, std::string prefix =
"" );
81 template <
typename T >
82 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr<
WGETexture< T > > texture,
size_t unit = 0, std::string prefix =
"" );
91 void WGE_EXPORT
unbindTexture( osg::ref_ptr< osg::Node > node,
size_t unit,
size_t count = 1 );
108 osg::ref_ptr< WGETexture< osg::Texture1D > > WGE_EXPORT
genWhiteNoiseTexture(
size_t sizeX,
size_t channels );
119 osg::ref_ptr< WGETexture< osg::Texture2D > > WGE_EXPORT
genWhiteNoiseTexture(
size_t sizeX,
size_t sizeY,
size_t channels );
131 osg::ref_ptr< WGETexture< osg::Texture3D > > WGE_EXPORT
genWhiteNoiseTexture(
size_t sizeX,
size_t sizeY,
size_t sizeZ,
size_t channels );
143 osg::ref_ptr< osg::Image > WGE_EXPORT
genWhiteNoiseImage(
size_t sizeX,
size_t sizeY,
size_t sizeZ,
size_t channels = 1 );
146 template <
typename T >
147 void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< T > texture,
size_t unit, std::string prefix )
151 prefix =
"u_texture" + boost::lexical_cast< std::string >( unit );
154 osg::StateSet* state = node->getOrCreateStateSet();
155 state->setTextureAttributeAndModes( unit, texture, osg::StateAttribute::ON );
156 state->addUniform(
new osg::Uniform( ( prefix +
"Sampler" ).c_str(), static_cast< int >( unit ) ) );
157 state->addUniform(
new osg::Uniform( ( prefix +
"Unit" ).c_str(), static_cast< int >( unit ) ) );
158 state->addUniform(
new osg::Uniform( ( prefix +
"SizeX" ).c_str(), static_cast< int >( texture->getTextureWidth() ) ) );
159 state->addUniform(
new osg::Uniform( ( prefix +
"SizeY" ).c_str(), static_cast< int >( texture->getTextureHeight() ) ) );
160 state->addUniform(
new osg::Uniform( ( prefix +
"SizeZ" ).c_str(), static_cast< int >( texture->getTextureDepth() ) ) );
163 template <
typename T >
168 prefix =
"u_texture" + boost::lexical_cast< std::string >( unit );
171 wge::bindTexture< T >( node, osg::ref_ptr< T >( texture ), unit, prefix );
174 osg::TexMat* texMat =
new osg::TexMat( texture->transformation()->get() );
177 node->getOrCreateStateSet()->setTextureAttributeAndModes( unit, texMat, osg::StateAttribute::ON );
180 texture->applyUniforms( prefix, node->getOrCreateStateSet() );
183 #endif // WGETEXTUREUTILS_H