OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Uniform array naming problem


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Glenn Waldron
Guest





PostPosted: Thu Dec 09, 2010 6:46 pm    Post subject:
Uniform array naming problem
Reply with quote

Hi Robert,

I would like to re-raise the issue of uniform array naming, now that it is affecting me personally Smile
To recap:


I have a uniform array in a shader defined as:


   uniform bool positions[1];


osg::Program calls glGetActiveUniform() to build a mapping of compiled uniforms by name. On some systems, the name returned is "positions" and on others it is "positions[0]". When the latter happens, a corresponding osg::Uniform named "positions" will fail since it cannot find a matching uniform location in the mapping (since it's filed under "positions[0]").


I am not convinced that this is a driver bug. It seems more like an ambiguity. The docs say that the 'uniform location for "positions" and "positions[0]" are the same; they point to the first element of the array.' (http://bit.ly/hnqbUi). I don't see anything that says the value returned from glGetActiveUniform() must be one or the other.


If both names are valid and equivalent, shouldn't we account for both possibilities in osg::Program? I suppose you could just alter getUniformLocation(...) to check for both variations.


Here are the past threads on the topic. The issue crops up on both ATI and NVIDIA systems.


   http://markmail.org/thread/5mans4howfbu2qtg
   http://forum.openscenegraph.org/viewtopic.php?t=1828


System: WinXP 32, ATI HD5550/10.11, OSG SVN.


Thanks.


Glenn Waldron : Pelican Mapping

------------------
Post generated by Mail2Forum
Back to top
Michael Platings
Guest





PostPosted: Mon Dec 13, 2010 3:41 pm    Post subject:
Uniform array naming problem
Reply with quote

How about just trimming off any invalid characters from the name returned by glGetActiveUniform?

e.g.

_extensions->glGetActiveUniform( _glProgramHandle,
                    i, maxLen, 0, &size, &type, name );

for (GLsizei j = 0; j < maxLen && name[j]; ++j){     if (!isalnum(name[j]) && name[j] != '_')    {         name[j] = '\0';        break;     }}

On 9 December 2010 18:46, Glenn Waldron < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Robert,

I would like to re-raise the issue of uniform array naming, now that it is affecting me personally Smile
To recap:


I have a uniform array in a shader defined as:


   uniform bool positions[1];


osg::Program calls glGetActiveUniform() to build a mapping of compiled uniforms by name. On some systems, the name returned is "positions" and on others it is "positions[0]". When the latter happens, a corresponding osg::Uniform named "positions" will fail since it cannot find a matching uniform location in the mapping (since it's filed under "positions[0]").


I am not convinced that this is a driver bug. It seems more like an ambiguity. The docs say that the 'uniform location for "positions" and "positions[0]" are the same; they point to the first element of the array.' (opengl.org/wiki/G...). I don't see anything that says the value returned from glGetActiveUniform() must be one or the other.


If both names are valid and equivalent, shouldn't we account for both possibilities in osg::Program? I suppose you could just alter getUniformLocation(...) to check for both variations.


Here are the past threads on the topic. The issue crops up on both ATI and NVIDIA systems.


   http://markmail.org/thread/5mans4howfbu2qtg
   http://forum.openscenegraph.org/viewtopic.php?t=1828


System: WinXP 32, ATI HD5550/10.11, OSG SVN.


Thanks.


Glenn Waldron : Pelican Mapping


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
tassilo.glander
User


Joined: 16 Aug 2010
Posts: 27

PostPosted: Wed Aug 24, 2011 7:41 am    Post subject:
Uniform arrays not bound
Reply with quote

Hi Robert,

I encountered the same problem (Win7 64 Bit, nVidia current driver 280.26), while it does not occur on older versions (like 266.58).
The solution of McKay Davis (http://forum.openscenegraph.org/viewtopic.php?t=1828)
works around this.
Code:

// Strip [0] from uniform array name to work around driver bugs
const int len = strlen(name);
if (len >= 3 && name[len-1] == ']')
name[len-3] = 0;


Apparently uniform arrays are not used so widely, hence there are just few complaints about this.
Anyway, I would support McKay and Glenn. I understand your reluctance to support particular platforms / drivers, but in this case the fix would be still according to the standard to query the location of the array without brackets. So no need to change it back for future drivers, as far as I can see.

Thank you!

Cheers,
Tassilo
Back to top
View user's profile Send private message
pmassi
Newbie


Joined: 29 Aug 2011
Posts: 1

PostPosted: Mon Aug 29, 2011 1:34 pm    Post subject:
Reply with quote

Hi,

Instead of trimming [0] from the name, as previously suggested, we should detect if a uniform name has it, but add BOTH 'name[0]' and 'name' into Program::_uniformInfoMap, so that when the osg::Uniform are applied, there will be a name match for whatever the driver returns... Both are actually valid.

The fix I have applied in my osg version, in
void Program::PerContextProgram::linkProgram(osg::State& state)

after the line:
_uniformInfoMap[reinterpret_cast<char*>(name)] = ActiveVarInfo(loc,type,size);


// For some drivers, active uniform array names are returned as 'name', and for others, 'name[0]'
// The way OSG works is to lookup into the program's active uniforms to see if a uniform set in a StateSet
// is present, and apply it only in that case. But that mechanic fails if the active uniform name
// includes the backets, but not the other, and vice-versa. So add both into the _uniformInfoMap
// to fix this, as both names are valid and allowed by OpenGL specifications
std::string strName(name);
if(strName.length() > 3 && strName.substr(strName.length()-3, 3) == std::string("[0]"))
_uniformInfoMap[strName.substr(0, strName.length()-3)] = ActiveVarInfo(loc,type,size);


Thank you!

Cheers,
Philippe
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem in loading VPB database from ... peckham0927 General 1 Sun Dec 23, 2018 1:25 pm View latest post
No new posts About Interleaved Array Support mp3butcher General 4 Tue Oct 09, 2018 11:13 pm View latest post
No new posts [Help] OSG + ArKit: Problem convertin... Brayner General 4 Mon Oct 08, 2018 7:07 pm View latest post
No new posts osgDB::OutputStream write array optim... Farshid Lashkari Submission 2 Thu Sep 20, 2018 11:17 pm View latest post
No new posts axis / axes with color array doesn't ... Steal General 0 Wed Sep 05, 2018 4:07 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP