Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QGLAbstractSurface Class

The QGLAbstractSurface class represents an OpenGL drawing surface. More...

 #include <QGLAbstractSurface>

Inherited by: QGLFramebufferObjectSurface, QGLPixelBufferSurface, QGLSubsurface, and QGLWindowSurface.

This class was introduced in Qt 4.8.

Public Types

enum SurfaceType { Window, FramebufferObject, PixelBuffer, Subsurface, User }

Public Functions

virtual ~QGLAbstractSurface()
virtual bool activate(QGLAbstractSurface * prevSurface = 0) = 0
virtual qreal aspectRatio() const
QOpenGLContext * context() const
virtual void deactivate(QGLAbstractSurface * nextSurface = 0) = 0
QOpenGLFramebufferObject * framebufferObject() const
virtual bool isValid() const
void setContext(QOpenGLContext * context)
void setFramebufferObject(QOpenGLFramebufferObject * framebufferObject)
void setWindow(QWindow * window)
int surfaceType() const
bool switchTo(QGLAbstractSurface * nextSurface)
virtual QRect viewportGL() const = 0
QRect viewportRect() const
QWindow * window() const

Static Public Members

QGLAbstractSurface * createSurfaceForContext(QOpenGLContext * context)

Protected Functions

QGLAbstractSurface(int surfaceType)

Detailed Description

The QGLAbstractSurface class represents an OpenGL drawing surface.

OpenGL can be used to draw into a number of different surface types: windows, pixel buffers (pbuffers), framebuffer objects, and so on. It is also possible to use only part of a surface by setting the glViewport() to restrict drawing to that part. An example of a subsurface may be the left or right eye image of a stereoscopic pair that is rendered into the two halves of a window.

Note that pixelbuffers are only supported when Qt is built with the OpenGL library.

Activating a surface for OpenGL drawing, and deactivating it afterwards can be quite varied across surface types. Sometimes it is enough to just make a QOpenGLContext current and set the glViewport(). Other times a context must be made current, followed by binding a framebuffer object, and finally setting the glViewport().

QGLAbstractSurface and its subclasses simplify the activation and deactivation of surfaces by encapsulating the logic needed to use a particular kind of surface into activate() and deactivate() respectively.

Normally surfaces are activated by calling QGLPainter::pushSurface() as in the following example of switching drawing to a framebuffer object:

 QGLPainter painter;
 painter.begin(widget);
 QGLFramebufferObjectSurface surface(fbo);
 painter.pushSurface(&surface);
 ... // draw into the fbo
 painter.popSurface();
 ... // draw into the widget

QGLPainter maintains a stack of surfaces, starting with the paint device specified to QGLPainter::begin() (usually a widget). The QGLPainter::pushSurface() function calls deactivate() on the current surface, activate() on the new surface, and then adjusts the glViewport() to match the value of viewportGL() for the new surface. When QGLPainter::popSurface() is called, the previous surface is re-activated and the glViewport() changed accordingly.

See also QGLFramebufferObjectSurface, QGLWindowSurface, QGLSubsurface, QGLPixelBufferSurface, and QGLPainter::pushSurface().

Member Type Documentation

enum QGLAbstractSurface::SurfaceType

This enum defines the type of a QGLAbstractSurface.

ConstantValueDescription
QGLAbstractSurface::Window0Instance of QGLWindowSurface.
QGLAbstractSurface::FramebufferObject1Instance of QGLFramebufferObjectSurface.
QGLAbstractSurface::PixelBuffer?Instance of QGLPixelBufferSurface.
QGLAbstractSurface::Subsurface2Instance of QGLSubsurface.
QGLAbstractSurface::User1000First user-defined surface type for use by applications.

Member Function Documentation

QGLAbstractSurface::QGLAbstractSurface(int surfaceType) [protected]

Constructs an OpenGL drawing surface of the specified surfaceType.

QGLAbstractSurface::~QGLAbstractSurface() [virtual]

Destroys this OpenGL drawing surface.

bool QGLAbstractSurface::activate(QGLAbstractSurface * prevSurface = 0) [pure virtual]

Activate this surface.

If prevSurface is null, then that surface has just been deactivated in the process of switching to this surface. This may allow activate() to optimize the transition to avoid unnecessary state changes.

Typically implementations should assert if this fails in debug mode, since no rendering into the surface is possible.

See also deactivate() and switchTo().

qreal QGLAbstractSurface::aspectRatio() const [virtual]

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.

QOpenGLContext * QGLAbstractSurface::context() const

Returns the OpenGL context which is associated with this surface, if any. When this surface is first activated, if this value is null then it will be set to the context current at that time.

The default value is null.

See also setContext().

QGLAbstractSurface * QGLAbstractSurface::createSurfaceForContext(QOpenGLContext * context) [static]

Creates an OpenGL drawing surface using the given context. This relies on the context having a valid surface which is a QWindow in which case the surface returned is a QGLWindowSurface.

If not, then a generic surface based on the OpenGL context is returned. In this case the generic surface will fail unless an underlying rendering surface becomes available prior to attempting to activate the surface.

void QGLAbstractSurface::deactivate(QGLAbstractSurface * nextSurface = 0) [pure virtual]

Deactivate this surface from the current context, but leave the context current. Typically this will release the framebuffer object associated with the surface.

If nextSurface is not-null, then that surface will be activated next in the process of switching away from this surface. This may allow deactivate() to optimize the transition to avoid unnecessary state changes.

See also activate() and switchTo().

QOpenGLFramebufferObject * QGLAbstractSurface::framebufferObject() const

Returns the QOpenGLFramebufferObject which is associated with this surface if any. The default value is null.

See also setFramebufferObject().

bool QGLAbstractSurface::isValid() const [virtual]

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.

void QGLAbstractSurface::setContext(QOpenGLContext * context)

Sets the OpenGL context which is to be associated with this surface. When this surface is first activated, if this value is null then it will be set to the context current at that time.

See also context().

void QGLAbstractSurface::setFramebufferObject(QOpenGLFramebufferObject * framebufferObject)

Sets the QOpenGLFramebufferObject which is to be associated with this surface to be framebufferObject.

See also framebufferObject().

void QGLAbstractSurface::setWindow(QWindow * window)

Sets the QWindow which is to be associated with this surface to be window.

See also window().

int QGLAbstractSurface::surfaceType() const

Returns the type of this surface.

bool QGLAbstractSurface::switchTo(QGLAbstractSurface * nextSurface)

Switches from this surface to nextSurface by calling deactivate() on this surface and activate() on nextSurface.

Returns true if nextSurface was activated, or false otherwise. If nextSurface could not be activated, then this surface will remain activated.

See also activate() and deactivate().

QRect QGLAbstractSurface::viewportGL() const [pure virtual]

Returns the rectangle of the surface that is occupied by the viewport for this surface. The origin is at the bottom-left, which makes the value suitable for passing to glViewport():

 QRect viewport = surface->viewportGL();
 glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());

Normally the viewport rectangle is the full extent of the device(), but it could be smaller if the application only wishes to draw into a subpart of the device(). An example would be rendering left and right stereo eye images into the two halves of a QGLWidget. The eye surfaces would typically be instances of QGLSubsurface.

Note that the value returned from this function is not defined before the activate() function has been called at least once.

See also viewportRect() and device().

QRect QGLAbstractSurface::viewportRect() const

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.

See also viewportGL() and device().

QWindow * QGLAbstractSurface::window() const

Returns the QWindow which is associated with this surface if any. The default value is null.

See also setWindow().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web