[osg-users] Support for sampler arrays

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Tue Mar 22 03:01:55 PDT 2016

Hi Chris,

Following Lionels reply I did a quick test which seems to work:

void addSamplerArray(osg::StateSet* ss)
     osg::Uniform* uniform = new osg::Uniform(osg::Uniform::INT, "test",2);

     osg::Texture2D* tex1 = new 
     osg::Texture2D* tex2 = new 
     ss->setTextureAttributeAndModes(0, tex1, osg::StateAttribute::ON);
     ss->setTextureAttributeAndModes(1, tex2, osg::StateAttribute::ON);

fragment shader:

#version 400 compatibility
uniform sampler2D test[2];
in vec2 texCoord;
void main()
     gl_FragColor = texture2D(test[1], texCoord)*texture2D(test[0], 

> Thanks, I'll have to think about whether it would be feasible for me to spend time in this project altering osg core..
> See i do like texture arrays, they would be ideal, except that I'm dealing with GIS data grids, so stretching/compressing them would lose information or memory space. I want to be able to store several grids of various sizes at the correct resolution, and be able to look up data from them programmatically in the shaders so I can superimpose data from one layer onto another etc.
I see. But be aware that dynamic access is not allowed in every case. 
The value for the look up has some constraints:

[1] https://www.opengl.org/wiki/Data_Type_%28GLSL%29#Opaque_arrays


> ------------------------
> http://www.hrwallingford.com/facilities/ship-simulation-centre (http://www.hrwallingford.com/facilities/ship-simulation-centre)
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=66581#66581
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

More information about the osg-users mailing list