Re: [osg-users] Support for sampler arrays
Thanks Lionel & Seb, that's very helpful. When I tried setting ints to a Sampler2D array it said that it couldn't take ints, which is why I thought it wasn't supported. If I set to ints directly though it does work. 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=66604#66604 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Support for sampler arrays
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); uniform->setElement(0,0); uniform->setElement(1,1); osg::Texture2D* tex1 = new osg::Texture2D(osgDB::readImageFile("./resources/textures/tex1.png")); osg::Texture2D* tex2 = new osg::Texture2D(osgDB::readImageFile("./resources/textures/tex2.png")); ss->addUniform(uniform); 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], texCoord); } 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 Cheers Sebastian 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@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Support for sampler arrays
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. 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@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Support for sampler arrays
Hi, The OpenGL command used to update a sampler* uniform is glUniformi[fv]. Sampler* uniforms are int uniforms. An uniform of type 'array of INT' works (It works for me). On 22/03/2016 10:36, Sebastian Messerschmidt wrote: Hi Chris, Hi, Working on an app that is going to be doing a lot of work with large texture processing, and will need to squeeze as much data into graphics memory as possible and allow many textures to be referenced programmatically. I've got texture arrays working, but can't use this for all requirements since all layers in a texture array have to be the same size. It looks like I could use sampler arrays (e.g. sampler2D myTextures[20]; ), but osg::Uniform doesn't seem to support such a thing. Arrays of samplers is used almost by no one any more. I usually use TextureArrays and simply resize the textures to a common size (usually the "biggest"). Texture arrays are efficient and easy to use. I'd like to see the "array of sampler"-support in OSG anyways, since there might be situations where texture arrays are not efficient. Another alternative are bindless textures, but we would need to add support to OSG too. Last alternative could be a texture atlas. Since you mentioned "texture processing", you might want to look into BufferTextures. They don't have any filtering (only texelfetch), but IIRC they support large amounts of texels. So if you don't need HW-filtering/mipmapping you can use them as atlas textures. Cheers Sebastian I'm also wondering if there's an easy way to easily run your own OpenGL commands in case something isn't supported yet and you just want to use GL directly instead of waiting for the OSG implementation? Thank you! Cheers, Chris 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=66577#66577 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Support for sampler arrays
Hi Chris, Hi, Working on an app that is going to be doing a lot of work with large texture processing, and will need to squeeze as much data into graphics memory as possible and allow many textures to be referenced programmatically. I've got texture arrays working, but can't use this for all requirements since all layers in a texture array have to be the same size. It looks like I could use sampler arrays (e.g. sampler2D myTextures[20]; ), but osg::Uniform doesn't seem to support such a thing. Arrays of samplers is used almost by no one any more. I usually use TextureArrays and simply resize the textures to a common size (usually the "biggest"). Texture arrays are efficient and easy to use. I'd like to see the "array of sampler"-support in OSG anyways, since there might be situations where texture arrays are not efficient. Another alternative are bindless textures, but we would need to add support to OSG too. Last alternative could be a texture atlas. Since you mentioned "texture processing", you might want to look into BufferTextures. They don't have any filtering (only texelfetch), but IIRC they support large amounts of texels. So if you don't need HW-filtering/mipmapping you can use them as atlas textures. Cheers Sebastian I'm also wondering if there's an easy way to easily run your own OpenGL commands in case something isn't supported yet and you just want to use GL directly instead of waiting for the OSG implementation? Thank you! Cheers, Chris 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=66577#66577 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Support for sampler arrays
Hi Chris, You can subclass from osg::StateAttribute and implement your own GL state calls in the same way as all the core StateAttribute classes implement their GL state calls. The osg::Uniform is an exception though as there are particular rules about when uniforms can be applied - you have to know that the appropriate glProgram is applied prior to assign the uniforms to them. osg::State manages this task, applying all osg::StateAttribute then applying the osg::Uniform. The add sampler arrays the natural place would be to modify the core osg::Uniform and simply submit this for inclusion in the core OSG. Robert On 22 March 2016 at 06:32, Chris Kuliukaswrote: > Hi, > > Working on an app that is going to be doing a lot of work with large > texture processing, and will need to squeeze as much data into graphics > memory as possible and allow many textures to be referenced > programmatically. > > I've got texture arrays working, but can't use this for all requirements > since all layers in a texture array have to be the same size. > > It looks like I could use sampler arrays (e.g. sampler2D myTextures[20]; > ), but osg::Uniform doesn't seem to support such a thing. > > > I'm also wondering if there's an easy way to easily run your own OpenGL > commands in case something isn't supported yet and you just want to use GL > directly instead of waiting for the OSG implementation? > > Thank you! > > Cheers, > Chris > > > 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=66577#66577 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Support for sampler arrays
Hi, Working on an app that is going to be doing a lot of work with large texture processing, and will need to squeeze as much data into graphics memory as possible and allow many textures to be referenced programmatically. I've got texture arrays working, but can't use this for all requirements since all layers in a texture array have to be the same size. It looks like I could use sampler arrays (e.g. sampler2D myTextures[20]; ), but osg::Uniform doesn't seem to support such a thing. I'm also wondering if there's an easy way to easily run your own OpenGL commands in case something isn't supported yet and you just want to use GL directly instead of waiting for the OSG implementation? Thank you! Cheers, Chris 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=66577#66577 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org