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 

Resizing an FBO camera with OSG 3.2.0


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





PostPosted: Fri Dec 08, 2017 9:07 pm    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Hi,

I’m trying to correctly support both OSG 3.2.x and 3.4.x in a codebase (since we need to support older versions of Debian / Ubuntu which still ship OSG 3.2.x as the supported version)

I have some FBO camera which I’m resizing: in 3.4.x I use osg::Camera::resizeAttachments. In 3.2.x there’s no such method of course, so I am manually resizing the FBO backing texture via:

_fboTexture->setTextureSize(width, height);
_fboTexture->dirtyTextureObject();

However, after a resize, I still don’t see the contents of the FBO camera (everything works as expected if I keep the original window size: these are full-screen FBOs so I need to keep them in sync with the main window size).

I’ve look at various pieces of code across the 3.2 branch, and tried a few things to no avail: in particular I hoped this might update the attachment data:

detach(osg::Camera::COLOR_BUFFER);
attach(osg::Camera::COLOR_BUFFER, _fboTexture);

(on my osg::Camera subclass) but to no avail.

I’ve seen some code which calls:

osgViewer::Renderer::setCameraRequiresSetUp

.. but at least for my FBO camera the renderer is null so this doesn’t work for me/

Any hints on what else to try, to work-around this behaviour, or other examples of keeping a full-screen FBO camera in sync with 3.2.x, would be most appreciated.

Kind regards,
James



------------------
Post generated by Mail2Forum
Back to top
James Turner
Guest





PostPosted: Mon Dec 18, 2017 11:15 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Quote:
On 8 Dec 2017, at 21:04, James Turner < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Any hints on what else to try, to work-around this behaviour, or other examples of keeping a full-screen FBO camera in sync with 3.2.x, would be most appreciated.


I guess no one here is using 3.2.x any more? Or people are busy, of course.

Unfortunately this is a release blocker for Flightgear continuing to ship on older distros, maybe it’s time we require OSG 3.4 but we lose a big chunk of Ubuntu users as a consequence.

Kind regards,
James

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


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Mon Dec 18, 2017 11:57 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

HI James,

Quote:
Any hints on what else to try, to work-around this behaviour, or other
examples of keeping a full-screen FBO camera in sync with 3.2.x, would be
most appreciated.


I guess no one here is using 3.2.x any more? Or people are busy, of course.

I've been away for the last 8 days, I guess others are busy too or
just don't have an answer for the problem you have as it's a very
specific usage case that most users will probably not have issues with
so won't have any specific experience to help.

I don't have any specific advice off the top of my head, the general
issues boils down to forcing recreation of FBO and Texture objects as
you can't resize existing FBO and Texture objects. The other part is
resizing the viewport and projection & view matrices.

Perhaps you can get away with implementing the OSG-3.4/master version
of osg::Camera::resizeAttachmentt(..) locally in your app :

void Camera::resizeAttachments(int width, int height)
{
bool modified = false;
for(BufferAttachmentMap::iterator itr = _bufferAttachmentMap.begin();
itr != _bufferAttachmentMap.end();
++itr)
{
Attachment& attachment = itr->second;
if (attachment._texture.valid())
{
{
osg::Texture1D* texture =
dynamic_cast<osg::Texture1D*>(attachment._texture.get());
if (texture && (texture->getTextureWidth()!=width))
{
modified = true;
texture->setTextureWidth(width);
texture->dirtyTextureObject();
}
}

{
osg::Texture2D* texture =
dynamic_cast<osg::Texture2D*>(attachment._texture.get());
if (texture && ((texture->getTextureWidth()!=width) ||
(texture->getTextureHeight()!=height)))
{
modified = true;
texture->setTextureSize(width, height);
texture->dirtyTextureObject();
}
}

{
osg::Texture3D* texture =
dynamic_cast<osg::Texture3D*>(attachment._texture.get());
if (texture && ((texture->getTextureWidth()!=width) ||
(texture->getTextureHeight()!=height)))
{
modified = true;
texture->setTextureSize(width, height,
texture->getTextureDepth());
texture->dirtyTextureObject();
}
}

{
osg::Texture2DArray* texture =
dynamic_cast<osg::Texture2DArray*>(attachment._texture.get());
if (texture && ((texture->getTextureWidth()!=width) ||
(texture->getTextureHeight()!=height)))
{
modified = true;
texture->setTextureSize(width, height,
texture->getTextureDepth());
texture->dirtyTextureObject();
}
}
}

if (attachment._image.valid() &&
(attachment._image->s()!=width || attachment._image->s()!=height) )
{
modified = true;
osg::Image* image = attachment._image.get();
image->allocateImage(width, height, image->r(),
image->getPixelFormat(), image->getDataType(),
image->getPacking());
}
}

if (modified)
{
dirtyAttachmentMap();
}
}

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
James Turner
Guest





PostPosted: Sat Dec 23, 2017 8:11 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Quote:
On 18 Dec 2017, at 11:51, Robert Osfield <> wrote:

if (modified)
{
dirtyAttachmentMap();
}

Thanks Robert,

Unfortunately this line is the part that I can’t figure out how to replicate in OSG-3.2 - resizing the textures is easy enough and I’ve already been doing that, but the attachment-map-dirty mechanism seems to go deeper into the render pass system.

I did try actually removing and re-adding the attachments to the Camera, to trigger the same work as when the attachments are initially made. That compiles but doesn’t make any difference alas.

(Something like….)

camera->detach(osg::Camera::COLOR_BUFFER);
camera ->attach(osg::Camera::COLOR_BUFFER, _fboTexture);

Oh well, thanks for the suggestion anyway.

James



------------------
Post generated by Mail2Forum
Back to top
Wojtek
User


Joined: 02 Nov 2011
Posts: 88

PostPosted: Sat Dec 23, 2017 9:31 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Hi, James,

Unfortunately I could not dig out the code I had to solve this problem. But I did fight with it on couple occasions. I do remember that often the solution I adopted had to use 2 callbacks (cull/update callback + prerender/render/or postrender callbace). One update/cull callback was needed to resize textures (they were tied to main window resolution) and second callback to invoke FBO update setup for new sizes. Somehow it was impossible to do that in one shot (probably because I could not access proper RenderStage in cull/update callback). That second callback had to be a camera PreRender or (some earlier render order camera PostRender or some other earlier render order drawable DrawCalback). Role of that second callback was to obtain proper RenderStage for FBO camera and set its _cameraRequiresSetup flag.   Once _cameraRequiresSetup flag was set to true, next rendering traversal was doing the rest. Really setting RenderStage::_cameraRequiresSetup was the crucial ingredient to solve that problem back then.


Hope this helps,
Wojtek


PS. If you are still fighting with it, but may wait till January, send me a private email and I will dig out the code. Unfortunately I cannot do it right away (I am swamped in December) but may be have more time to scan through my backups and find it in January. 








2017-12-23 9:09 GMT+01:00 James Turner < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:


Quote:
On 18 Dec 2017, at 11:51, Robert Osfield < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

    if (modified)
    {
        dirtyAttachmentMap();
    }

Thanks Robert,

Unfortunately this line is the part that I can’t figure out how to replicate in OSG-3.2 - resizing the textures is easy enough and I’ve already been doing that, but the attachment-map-dirty mechanism seems to go deeper into the render pass system.

I did try actually removing and re-adding the attachments to the Camera, to trigger the same work as when the attachments are initially made. That compiles but doesn’t make any difference alas.

(Something like….)

        camera->detach(osg::Camera::COLOR_BUFFER);
        camera ->attach(osg::Camera::COLOR_BUFFER, _fboTexture);

Oh well, thanks for the suggestion anyway.

James

_______________________________________________
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
View user's profile Send private message
James Turner
Guest





PostPosted: Sat Dec 23, 2017 9:46 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Quote:
On 23 Dec 2017, at 09:28, Wojciech Lewandowski < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Unfortunately I could not dig out the code I had to solve this problem. But I did fight with it on couple occasions. I do remember that often the solution I adopted had to use 2 callbacks (cull/update callback + prerender/render/or postrender callbace). One update/cull callback was needed to resize textures (they were tied to main window resolution) and second callback to invoke FBO update setup for new sizes. Somehow it was impossible to do that in one shot (probably because I could not access proper RenderStage in cull/update callback). That second callback had to be a camera PreRender or (some earlier render order camera PostRender or some other earlier render order drawable DrawCalback). Role of that second callback was to obtain proper RenderStage for FBO camera and set its _cameraRequiresSetup flag. Once _cameraRequiresSetup flag was set to true, next rendering traversal was doing the rest. Really setting RenderStage::_cameraRequiresSetup was the crucial ingredient to solve that problem back then.


Thanks, that’s a big help. I was already aware that getting ‘_cameraRequiresSetup’ flag set was the critical piece - thst’s actually why I was trying detach() + attach() since that *should* set _cameraRequiresSetup to true. But your point about getting the correct RenderStage makes a lot of sense, and might explain the strange things I see indeed.
Quote:

PS. If you are still fighting with it, but may wait till January, send me a private email and I will dig out the code. Unfortunately I cannot do it right away (I am swamped in December) but may be have more time to scan through my backups and find it in January.


I might do that, but it can wait - thank again for your help.

Kind regards,
James

------------------
Post generated by Mail2Forum
Back to top
Wojtek
User


Joined: 02 Nov 2011
Posts: 88

PostPosted: Sat Dec 23, 2017 10:47 am    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Luckily I was able to quickly locate some code. Its a little different to what I described earlier because its using 2 cull callbacks (no render callback) and dummy group to update PreRenderCamera texture sizes but in general its same approach. I have cleaned it a bit from proprietary stuff. So rather treat it as an example code blurb. I did not try to compile it. But in generally this approach worked for me. I think that cull callback attached to PreRenderGroup can be replaced by some callback in main camera. But for some reason we could not do it (I do not recall why, maybe main cam had some other callbacks attached) and  instead just added it in dummy group.



Cheers,
Wojtek Lewandowsk



2017-12-23 10:43 GMT+01:00 James Turner < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:


Quote:
On 23 Dec 2017, at 09:28, Wojciech Lewandowski < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Unfortunately I could not dig out the code I had to solve this problem. But I did fight with it on couple occasions. I do remember that often the solution I adopted had to use 2 callbacks (cull/update callback + prerender/render/or postrender callbace). One update/cull callback was needed to resize textures (they were tied to main window resolution) and second callback to invoke FBO update setup for new sizes. Somehow it was impossible to do that in one shot (probably because I could not access proper RenderStage in cull/update callback). That second callback had to be a camera PreRender or (some earlier render order camera PostRender or some other earlier render order drawable DrawCalback). Role of that second callback was to obtain proper RenderStage for FBO camera and set its _cameraRequiresSetup flag.   Once _cameraRequiresSetup flag was set to true, next rendering traversal was doing the rest. Really setting RenderStage::_cameraRequiresSetup was the crucial ingredient to solve that problem back then.



Thanks, that’s a big help. I was already aware that getting ‘_cameraRequiresSetup’ flag set was the critical piece - thst’s actually why I was trying detach() + attach() since that *should* set _cameraRequiresSetup to true. But your point about getting the correct RenderStage makes a lot of sense, and might explain the strange things I see indeed. 

Quote:


PS. If you are still fighting with it, but may wait till January, send me a private email and I will dig out the code. Unfortunately I cannot do it right away (I am swamped in December) but may be have more time to scan through my backups and find it in January. 



I might do that, but it can wait - thank again for your help.


Kind regards,
James




_______________________________________________
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
View user's profile Send private message
James Turner
Guest





PostPosted: Wed Jan 03, 2018 3:24 pm    Post subject:
Resizing an FBO camera with OSG 3.2.0
Reply with quote

Quote:
On 23 Dec 2017, at 10:45, Wojciech Lewandowski < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Luckily I was able to quickly locate some code. Its a little different to what I described earlier because its using 2 cull callbacks (no render callback) and dummy group to update PreRenderCamera texture sizes but in general its same approach. I have cleaned it a bit from proprietary stuff. So rather treat it as an example code blurb. I did not try to compile it. But in generally this approach worked for me. I think that cull callback attached to PreRenderGroup can be replaced by some callback in main camera. But for some reason we could not do it (I do not recall why, maybe main cam had some other callbacks attached) and instead just added it in dummy group.

Cheers,
Wojtek Lewandowsk



(just catching up on email after the holidays)

Thanks, that’s a big help indeed.

Kind regards,
James

------------------
Post generated by Mail2Forum
Back to top
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 Camera clear color cdp97531 General 1 Sat Dec 01, 2018 8:15 am View latest post
No new posts Camera movement when depending on 3rd... njr3 General 0 Wed Nov 28, 2018 9:46 pm View latest post
No new posts Camera movement when depending on 3rd... njr3 General 0 Wed Nov 28, 2018 9:44 pm View latest post
No new posts Camera movement when depending on 3rd... njr3 General 0 Wed Nov 28, 2018 9:43 pm View latest post
No new posts Camera movement when depending on 3rd... njr3 General 0 Wed Nov 28, 2018 9:41 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