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 "../common/WStringUtils.h"
39 #include "shaders/WGEPropertyUniform.h"
40 #include "callbacks/WGEPropertyTransformationCallback.h"
64 template <
typename T >
65 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< T > texture,
size_t unit = 0, std::string prefix =
"" );
85 template <
typename T >
86 void bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr<
WGETexture< T > > texture,
size_t unit = 0, std::string prefix =
"" );
95 void unbindTexture( osg::ref_ptr< osg::Node > node,
size_t unit,
size_t count = 1 );
112 osg::ref_ptr< WGETexture< osg::Texture1D > >
genWhiteNoiseTexture(
size_t sizeX,
size_t channels );
123 osg::ref_ptr< WGETexture< osg::Texture2D > >
genWhiteNoiseTexture(
size_t sizeX,
size_t sizeY,
size_t channels );
135 osg::ref_ptr< WGETexture< osg::Texture3D > >
genWhiteNoiseTexture(
size_t sizeX,
size_t sizeY,
size_t sizeZ,
size_t channels );
147 osg::ref_ptr< osg::Image >
genWhiteNoiseImage(
size_t sizeX,
size_t sizeY,
size_t sizeZ,
size_t channels = 1 );
162 osg::ref_ptr< WGETexture< osg::Texture3D > >
genTuringNoiseTexture( std::size_t sizeX, std::size_t sizeY,
163 std::size_t sizeZ, std::size_t channels = 1 );
166 template <
typename T >
167 void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< T > texture,
size_t unit, std::string prefix )
174 osg::StateSet* state = node->getOrCreateStateSet();
175 state->setTextureAttributeAndModes( unit, texture, osg::StateAttribute::ON );
176 state->addUniform(
new osg::Uniform( ( prefix +
"Sampler" ).c_str(),
static_cast< int >( unit ) ) );
177 state->addUniform(
new osg::Uniform( ( prefix +
"Unit" ).c_str(),
static_cast< int >( unit ) ) );
178 state->addUniform(
new osg::Uniform( ( prefix +
"SizeX" ).c_str(),
static_cast< int >( texture->getTextureWidth() ) ) );
179 state->addUniform(
new osg::Uniform( ( prefix +
"SizeY" ).c_str(),
static_cast< int >( texture->getTextureHeight() ) ) );
180 state->addUniform(
new osg::Uniform( ( prefix +
"SizeZ" ).c_str(),
static_cast< int >( texture->getTextureDepth() ) ) );
183 template <
typename T >
191 wge::bindTexture< T >( node, osg::ref_ptr< T >( texture ), unit, prefix );
194 osg::TexMat* texMat =
new osg::TexMat( texture->transformation()->get() );
197 node->getOrCreateStateSet()->setTextureAttributeAndModes( unit, texMat, osg::StateAttribute::ON );
200 texture->applyUniforms( prefix, node->getOrCreateStateSet() );
This class allows simple creation of WGETexture3D by using a specified grid and value-set.
This calls serves a simple purpose: have a texture and its scaling information together which allows ...
std::string toString(const T &value)
Convert a given value to a string.
Extend the wge utils namespace with additional methods relating WDataTexture3D.
osg::ref_ptr< WGETexture< osg::Texture3D > > genTuringNoiseTexture(std::size_t sizeX, std::size_t sizeY, std::size_t sizeZ, std::size_t channels=1)
Generates a 3D turing noise texture.
osg::ref_ptr< WGETexture< osg::Texture1D > > genWhiteNoiseTexture(size_t sizeX, size_t channels)
This generates an 1D texture only containing white noise in its channels.
void bindTexture(osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture, size_t unit=0, std::string prefix="")
Binds the specified texture to the specified unit.
osg::ref_ptr< osg::Image > genWhiteNoiseImage(size_t sizeX, size_t sizeY, size_t sizeZ, size_t channels=1)
Generates an image only containing white noise in its channels.
size_t getMaxTexUnits()
Returns the maximum number of textures that can be bound to a node.
void unbindTexture(osg::ref_ptr< osg::Node > node, size_t unit, size_t count=1)
Removes the binding associated with the specified unit.