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 EXTERNAL: Forum Cary, Karl A. General 1 Wed Jul 12, 2017 3:28 pm View latest post
No new posts RTT + shaders example Michael Maurus General 42 Wed Jul 12, 2017 11:28 am View latest post
No new posts Read FBO with PBO Cary, Karl A. General 1 Tue Jul 11, 2017 1:28 am View latest post
No new posts Error with InputStream reading osgb f... Riccardo Corsi General 28 Thu Jun 08, 2017 11:20 am View latest post
No new posts how to convert osgb files to old version Haojia General 1 Fri Jun 02, 2017 4:35 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