[osg-users] OSG in Gtk3 GLArea

Robert Osfield robert.osfield at gmail.com
Wed Jun 6 00:51:54 PDT 2018


Hi Steve,

On 6 June 2018 at 03:42, Steve Hardy <osgforum at tevs.eu> wrote:
> Problems remaining:
>
> 1. the aspect ratio does not adjust properly on window size changes, so that the scene just stretches like rubber.
> ....
> For (1), I was assuming that
>
>     camera->setViewport(new osg::Viewport(0,0,width,height));
>     camera->setProjectionMatrixAsPerspective(30.0f, 1.*width/height, 1.0f, 10000.0f);
>
> on the slave and main (?) cameras would fix that up, but no.  Maybe there's something cached somewhere, even though I am completely reconstructing the slave camera on each resize.
>
> Any suggestions where to look?
>

In osg::Camera there is support for adjusting the projection matrix to
track changes in he viewport:

        enum ProjectionResizePolicy
        {
            FIXED, /**< Keep the projection matrix fixed, despite
window resizes.*/
            HORIZONTAL, /**< Adjust the HORIZONTAL field of view on
window resizes.*/
            VERTICAL /**< Adjust the VERTICAL field of view on window resizes.*/
        };

        /** Set the policy used to determine if and how the projection
matrix should be adjusted on window resizes. */
        inline void setProjectionResizePolicy(ProjectionResizePolicy
policy) { _projectionResizePolicy = policy; }

        /** Get the policy used to determine if and how the projection
matrix should be adjusted on window resizes. */
        inline ProjectionResizePolicy getProjectionResizePolicy()
const { return _projectionResizePolicy; }


> 2. there is a truly horrendous amount of copying data.
> ....
> For (2), after the hardware renders the scene, and the PBO is mapped back into userspace RAM, the following copies occur:
>
> - memcpy to the osg::Image data
> - image->flipVertical()  since 2D library has Y inverted w.r.t GL.
> - copy to a new Python string object
> - copy to a new GdkPixbuf object
> - copy to the cairo context (that's the Gtk 2D graphics engine).

To avoid the flip you could flip the projection matrices y axis so
that the it renders upside down,

> I think a lot of this could be eliminated by creating the GdkPixbuf directly from the PBO map, flipping the row order in this copy.  Although it performs OK, we have to run on low-end systems.

Another approach might be to look at trying to use a GL context for
the actual window and see if you can keep the data resident in
graphics memory and copy it across without doing the round trip to the
CPU.

Robert.


More information about the osg-users mailing list