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 frame buffer back into main memory


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Wed Feb 28, 2018 6:05 pm    Post subject:
Read frame buffer back into main memory
Reply with quote

Hi all,

I need to read the frame buffer back into the main memory. I know this will kill performance but I only need to do it once.

Is there a way to do that? I could not find clear answers on the internet.

Thanks,

Antoine.
Back to top
View user's profile Send private message
errno (Lionel Lagarde)
User


Joined: 10 Mar 2009
Posts: 58
Location: Toulouse, France

PostPosted: Thu Mar 01, 2018 7:34 am    Post subject:
Read frame buffer back into main memory
Reply with quote

Hi,

Have a look to glReadPixel. The osg::Image class has a method to read
the frame buffer back to its own memory.


On 28/02/2018 19:05, Antoine Rennuit wrote:
Quote:
Hi all,

I need to read the frame buffer back into the main memory. I know this will kill performance but I only need to do it once.

Is there a way to do that? I could not find clear answers on the internet.

Thanks,

Antoine.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72990#72990










------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message Send e-mail
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Thu Mar 01, 2018 8:57 am    Post subject:
Reply with quote

This looks promising... Thanks!

Antoine.
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 823

PostPosted: Thu Mar 01, 2018 9:00 am    Post subject:
Read frame buffer back into main memory
Reply with quote

Hi Antoine,

set a postDrawCallback to the pass/camera that writes to the texture.


In the callback:

virtual void operator () (osg::RenderInfo& render_info) const
{
osg::State* state=render_info.getState();
state->apply(render_info.getCurrentCamera()->getStateSet());
state->applyTextureAttribute(0, mTexture);
mTexture->apply(*state);

mImage->readImageFromCurrentTexture(render_info.getContextID(),true,
GL_FLOAT ); //change the GL_FLOAT to your needs
}

the mTexture is passed to the callback using the original texture
attached to the MRT.



Cheers
Sebastian

Am 28/02/2018 um 19:05 schrieb Antoine Rennuit:
Quote:
Hi all,

I need to read the frame buffer back into the main memory. I know this will kill performance but I only need to do it once.

Is there a way to do that? I could not find clear answers on the internet.

Thanks,

Antoine.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72990#72990









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Mar 02, 2018 4:12 pm    Post subject:
Reply with quote

Hi all,

Hum, it seems my case is a bit more complex than expected. The camera I want to read the buffer from is a custom created camera:

Code:
    // Curvatures camera.
    m_curvaturesCamera = new osg::Camera();
    m_curvaturesCamera->setClearMask(GL_DEPTH_BUFFER_BIT); // The camera only clears the depth buffer before rendering (not the color buffer).
    m_curvaturesCamera->setRenderOrder(osg::Camera::PRE_RENDER);
    m_curvaturesCamera->setReferenceFrame(osg::Camera::RELATIVE_RF);


I have had a look at osg::Image, but it does not seem very clear which function to use and above all, how I shall indicate to the osg::image which camera it needs to read from.

Any idea?

Thank you!

Cheers,

Antoine.[/code]
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Fri Mar 02, 2018 4:50 pm    Post subject:
Read frame buffer back into main memory
Reply with quote

Hi Antoine,

You can just do your glReadPixels(..) or osg::Image::readPixels(..) in
your own Camera::DrawCallback that you attach as a post draw callback
to your camera.

Robert.

On 2 March 2018 at 16:12, Antoine Rennuit <> wrote:
Quote:
Hi all,

Hum, it seems my case is a bit more complex than expected. The camera I want to read the buffer from is a custom created camera:


Code:
// Curvatures camera.
m_curvaturesCamera = new osg::Camera();
m_curvaturesCamera->setClearMask(GL_DEPTH_BUFFER_BIT); // The camera only clears the depth buffer before rendering (not the color buffer).
m_curvaturesCamera->setRenderOrder(osg::Camera::PRE_RENDER);
m_curvaturesCamera->setReferenceFrame(osg::Camera::RELATIVE_RF);




I have had a look at osg::Image, but it does not seem very clear which function to use and above all, how I shall indicate to the osg::image which camera it needs to read from.

Any idea?

Thank you!

Cheers,

Antoine.[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73002#73002








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Tue Mar 06, 2018 5:44 pm    Post subject:
Reply with quote

Hello Robert,

And thanks for you message. I am trying to write the image to a file using

Code:

class ReadPixelsCallback : public osg::Camera::DrawCallback
{
public:
    virtual void operator()( osg::RenderInfo& renderInfo ) const
    {
        osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext();

        int width = gc->getTraits()->width;
        int height = gc->getTraits()->height;

        osg::ref_ptr<osg::Image> image = new osg::Image;
        image->readPixels(0, 0, gc->getTraits()->width, gc->getTraits()->height, GL_RGB, GL_UNSIGNED_BYTE);



        bool retValBmp = osgDB::writeImageFile(*image, "/home/enjyi/testImage.bmp");
        bool retValJpg = osgDB::writeImageFile(*image, "/home/enjyi/testImage.jpg");
    }
};


but all I get is

Code:

Error writing file /home/arennuit/testImage.bmp: Warning: Could not find plugin to write image to file "/home/arennuit/testImage.bmp".
Error writing file /home/arennuit/testImage.jpg: Warning: Could not find plugin to write image to file "/home/arennuit/testImage.jpg".


Any idea why OSG cannot my plugins?

Regards,

Antoine.[/code]
Back to top
View user's profile Send private message
1
Guest





PostPosted: Wed Mar 07, 2018 1:25 am    Post subject:
TD
Reply with quote

------------------
Post generated by Mail2Forum
Back to top
1
Guest





PostPosted: Wed Mar 07, 2018 1:29 am    Post subject:
取消邮件订阅
Reply with quote

------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Wed Mar 07, 2018 8:43 am    Post subject:
Read frame buffer back into main memory
Reply with quote

Hi Antoine,

On 6 March 2018 at 17:44, Antoine Rennuit <> wrote:
Quote:
Error writing file /home/arennuit/testImage.bmp: Warning: Could not find plugin to write image to file "/home/arennuit/testImage.bmp".
Error writing file /home/arennuit/testImage.jpg: Warning: Could not find plugin to write image to file "/home/arennuit/testImage.jpg".

Any idea why OSG cannot my plugins?

I don't know anything about the OSG version you are using, did you
build it yourself? Do you install it? Are you using a system path
(possibly LD_LIBRARY_PATH) if you are under Unix. Does you OSG
version include the jpeg and bmp plugins? Is it a static build of the
OSG?

To investigate I would recommend setting the OSG_NOTIFY_LEVEL env var
up to DEBUG and then running the application and redirecting the
console output to a text file i.e.

export OSG_NOTIFY_LEVEL=DEBUG
myapplication &> output.txt


Then open up the output.txt in an editor and scroll through looking
for references for the OSG attempting to load plugins. This will show
you where the OSG is searching for plugins, the path to the directory
containing the osgPlugins-version directory should be on the list.

Also have a look at the osgPlugins-version directory to see what
osgdb_* libs there are.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Wed Mar 07, 2018 11:20 am    Post subject:
Reply with quote

Thanks Robert,

This has helped pinpoint the problem!

Antoine.
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Wed Mar 07, 2018 1:34 pm    Post subject:
Reply with quote

Problem solved, thanks to you Robert, Sebastian and Lionel!
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Wed Mar 07, 2018 1:58 pm    Post subject:
Read frame buffer back into main memory
Reply with quote

On 7 March 2018 at 13:34, Antoine Rennuit <> wrote:
Quote:
Problem solved, thanks to you Robert, Sebastian and Lionel!

Could you explain what the issue was and how you solved. This will
help others who search for solution to problems like the one you've
described.

Thanks,
Robert


------------------
Post generated by Mail2Forum
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 Change color of node read from dxf file dhhabyc General 10 Sat Nov 17, 2018 12:58 pm View latest post
No new posts Read Image from RTT romulogcerqueira General 6 Thu Sep 27, 2018 7:06 pm View latest post
No new posts Switch call to viewer::frame() betwee... DrPowers General 4 Tue Sep 11, 2018 6:48 am View latest post
No new posts Load OSG trimesh to ODE: Read Vertice... TKoller General 2 Fri Jul 20, 2018 3:06 pm View latest post
No new posts How to track down memory leaks? OmegaDoom General 9 Wed Jul 11, 2018 1: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