Exemplo n.º 1
0
/*!
    Returns the aspect ratio of viewportGL().

    The return value is used to correct perspective and orthographic
    projections for the aspect ratio of the drawing surface.

    No adjustments are made for DPI.

    Subclasses may override this function to further adjust the return value
    if the DPI in the horizontal vs vertical direction is not the same,
    that is, the pixels are not square.
*/
float QGLAbstractSurface::aspectRatio() const
{
    Q_ASSERT(isValid());

    // Get the size of the current viewport.
    QSize size = viewportGL().size();
    if (size.width() == size.height())
        return 1.0f;

    // Return the final aspect ratio based on viewport.
    return float(size.width()) / float(size.height());
}
Exemplo n.º 2
0
/*!
    Returns the rectangle of the surface device() that is occupied by
    the viewport for this surface.  The origin is at the top-left.

    This function calls viewportGL() and then flips the rectangle
    upside down using the height of device() so that the origin
    is at the top-left instead of the bottom-left.

    \sa viewportGL(), device()
*/
QRect QGLAbstractSurface::viewportRect() const
{
    Q_ASSERT(isValid());

    QRect view = viewportGL();
    int height = 0;
    if (surfaceType() == Window)
    {
        Q_ASSERT(window());
        height = window()->height();
    }
    else if (surfaceType() == FramebufferObject)
    {
        Q_ASSERT(framebufferObject());
        height = framebufferObject()->size().height();
    }

    return QRect(view.x(), height - (view.y() + view.height()),
                 view.width(), view.height());
}
Exemplo n.º 3
0
QRect FboCubeSurface::viewportRect() const {
    QRect view = viewportGL();
    return QRect(view.x(), height - (view.y() + view.height()), view.width(), view.height());
}
Exemplo n.º 4
0
/*!
    Returns true if this surface is valid and ready to be drawn into with OpenGL
    commands.  Typically it will be true if the surface has been associated with
    an opengl context and a supported painting context such as a window or fbo.

    Sub-class implementations can use this fall-back, which simply checks for
    a valid viewport rectangle.

    Note that the surface may only become valid during activate() calls.
*/
bool QGLAbstractSurface::isValid() const
{
    return viewportGL().isValid();
}