Thanks Himar,  I've merged you changes with a small tweak - changing
the std::vector<Viewport*> to an std::set<Viewport*>, this cleans the
code up a little.  Changes now checked into svn/trunk.  Cheers.
Robert.

On Mon, Oct 26, 2009 at 11:02 PM, Himar Carmona <[email protected]> wrote:
> Hi,
>
>    this submission resolves an issue regarding the setup of a slave camera
> with an (incorrect) coding style. Sharing the same instance of osg::Viewport
> with a camera and a slave camera causes incorrect rescaling in
> GraphicsContext::resizedImplementation, due to the viewport being rescaled
> twice (once per camera). Though viewports sharing is not intentional, it can
> be done with the current version of OSG and be a potential pitfall for
> anyone.
>
>    As Robert pointed out, i opted for modifying the resize code where the
> break is to minimize code changes, avoiding the duplicate resize of the
> viewport with the use of a vector and a search for duplicates. Not very
> elegant (avoiding an effect of a cause), another approach could be ripping
> out the method osg::Camera::setViewport(osg::Viewport*) which is more inline
> with Roberts rationale behind not to share viewports between cameras and
> left only its overloaded method setViewport(x,y,width,height). But this
> approach need some refactoring due to the intense use of the method. Notice
> also that the resize works well without this change if no sharing occurs,
> and the user of the method can opt for always call setViewport with a new
> instance.
>
>    The modification are for OSG trunk version (revision 10260).
>
> Best regards,
> Himar.
>
>
>>
>>    Hi Himar,
>>
>> The assumption that I made with osg::Camera is that each camera would
>> have it's own Viewport, sharing a Viewport between Camera's is not
>> something I've considered so code like the GraphicsContext code for
>> passing up updates to resizing of the window will probably be resizing
>> the viewport onces for each Camera.
>>
>> Solutions would be to clone the viewport for your slave camera, or
>> modify the resize code so it doesn't resize viewports that it's
>> already resized.  The later is really the best solution as it would
>> remove the assumption of one Viewport per Camera.  I'm currently got
>> my head down on OpenGL ES work so if you could dive into the
>> appropriate code and provide a solution it'd appreciated :-)
>>
>> Cheers,
>> Robert.
>>
>>
>> On Mon, Oct 26, 2009 at 1:45 PM, Himar Carmona <[email protected]>
>> wrote:
>> > Hi,
>> >
>> >   i noticed a strange (buggy?) behavior with two cameras sharing the
>> > same Viewport instance with version 2.9.5 (Windows XP).
>> >
>> >   Situation: Main camera, adding a slave camera (with addSlave) and
>> > setting the slave camera's viewport with this line of code:
>> >
>> >          slaveCamera->setViewport( viewer.getCamera()->getViewport());
>> >
>> >   The objective is to have two cameras rendering to the whole window
>> >
>> >   Problem: If the viewer is in window mode (setUpViewInWindow) and
>> > the window is resized, the viewport updates incorrectly. In my case,
>> > it doesn't fill the window.
>> >
>> >   I suspect this behaviour is due to
>> > GraphicsContext::resizedImplementation having updated the viewport
>> > twice, since it is share between the two cameras.
>> >
>> >   Workaround: Don't share the viewport between two cameras :)
>> >
>> >           slaveCamera->setViewport(new
>> > osg::Viewport(*(viewer.getCamera()->getViewport())));
>> >
>> >       or
>> >
>> >           osg::Viewport* vp = viewer.getCamera()->getViewport();
>> >           slaveCamera->setViewport(vp->x(), vp->y(), vp->width(),
>> > vp->height());
>> >
>> >    If this use isn't as expected (i use it wrong) or if
>> > resizedImplementation need to be fixed, then i could try do the job
>> > and submit a patch for this odd behaviour. At least i could modify
>> > Camera and add some comments regarding this behavior. But first i
>> > wanted to know experts advise about it.
>> >
>> >
>> >   Best regards,
>> > Himar.
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to