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 

Read/write shaders from/to external files


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission
View previous topic :: View next topic  
Author Message
rocco martino
Guest





PostPosted: Wed Oct 19, 2016 2:02 pm    Post subject:
Read/write shaders from/to external files
Reply with quote

Hi all,


once a scene is exported to osgt format, the only way to edit a shader is to
modify the inline source and I found it uncomfortable. That's why I decided to
modify my local copy of OSG to allow I/O to external file and now want to share.


I added two options:

    ReadShaderHint=<hint>

        Import option: Hint of reading shaders from stream:
            <UseInline> uses inline data (default) ;
            <UseExternal> reads the sources from Shader::getFileName()*



    WriteShaderHint=<hint>

        Export option: Hint of writing shaders to stream:
            <UseInline> uses inline data (default) ;
            <UseExternal> writes the sources to Shader::getFileName()*




    * The "FileName" field is not serialized so need to update the serializer
      and break its compatibility.





Two files attached:


    src/osgPlugins/osg/ReaderWriterOSG2.cpp:

        added the new options in the constructor (  supportsOption(...)  )




    src/osgWrappers/serializers/osg/Shader.cpp

        added missing "FileName" serializer. I didn't fully understand what to
        put in UPDATE_TO_SCOPED_VERSION and left it blank ;

        readShaderSource: read the source as usual, then replace the content
        of the variable "code" with the external source

        writeShaderSource: write the source as usual, then write to external
        file too.





If FileName is missing and WriteShaderHint=UseExternal, it generates a new
file in the current directory whose name is

    "shader_" + <pointer to the shader object> + extension





Note that readShaderSource is never called if there's no inline source.
To solve this, checkShaderSource should be modified somehow.


Tested osg 3.4 and current on Slackware64 14.2



Yet another note: if I use osgDB::[read,write]ShaderFile instead of doing it
manually I get a strange warning at exit:

    Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!
    [Inferior 1 (process 7546) exited with code 0177]]




I hope you have a nice day
Martino

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission 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 About Shapefiles and .dbf files in os... Rambabu General 0 Tue Apr 25, 2017 4:57 am View latest post
No new posts Text colors in shaders wernerM General 5 Fri Feb 24, 2017 12:00 pm View latest post
No new posts How to read FBO attachment back to th... MariusD General 2 Fri Jan 06, 2017 12:05 pm View latest post
No new posts Text following lines shaders with osg... kragnfroll General 1 Mon Jan 02, 2017 1:25 pm View latest post
No new posts Flat Earth Files gwaldron General 3 Tue Dec 06, 2016 12:03 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