I just ran into problems using this code:

for (size_t i=0; i<m_tl.size(); ++i) { // bind the texture and bind the location to a uniform sampler
           state->setTextureAttribute(i, m_tl[i], osg::StateAttribute::ON);
osg::ref_ptr<osg::Uniform> uniform = new osg::Uniform((std::string("input_texture_") + toString(i+1)).c_str(), i);
           state->addUniform(uniform, osg::StateAttribute::ON);
       }

where m_tl is an std::vector of osg::Texture ref_ptrs. While this code is technically incorrect (uniform samplers are signed ints), the unsigned support patch breaks it. The value for 'i' is seen as unsigned (size_t is usually unsigned) in the Uniform ctor call, and consequently the sampler is not setup correctly. Explicitly casting 'i' to (int) solves it.

Just thought I'd let you all know, in case others experience similar problems... may be hard to fix if you don't know. The compiler does what it is supposed to do and choses the correct overload silently, and OSG only gives a cryptic error "Warning: detected OpenGL error 'invalid operation' after RenderBin::draw(,)"

Robert Osfield wrote:
Hi Ferdi,

Could you post the whole modified files rather than a patch.

Thanks,
Robert.

On Sat, Nov 15, 2008 at 4:25 PM, Ferdi Smit <[EMAIL PROTECTED]> wrote:
I attached a small patch to add support for unsigned typed uniform
variables. In particular, uniform unsigned int, uniform uvec2, uniform
uvec3, uniform uvec4. These uniform variables can now be set with
osg::Uniform("name", unsigned int(42)), and so on. Previously, osg::Uniform
only supported "float" and "int", this adds support for "unsigned int".
Because of the double-token typename, some minor changes to the .osg writer
plugin for uniform were also required. Relies on gpu_shader4 and
glUniform[n]uivEXT

I did some simple tests using a uniform unsigned in a shader, writing it to
an .osg file, and loading it again. All worked fine. Possible issues may
potentially arise for existing software using unsigned int C++ types to set
(signed) uniform int types, due to the new overload. I haven't noticed this
yet, though.

--
Regards,

Ferdi Smit
Email: [EMAIL PROTECTED]
Room: C0.07  Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands


_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org


_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to