[][src]Struct qt_gui::QOpenGLWindow

#[repr(C)]pub struct QOpenGLWindow { /* fields omitted */ }

The QOpenGLWindow class is a convenience subclass of QWindow to perform OpenGL painting.

C++ class: QOpenGLWindow.

C++ documentation:

The QOpenGLWindow class is a convenience subclass of QWindow to perform OpenGL painting.

QOpenGLWindow is an enhanced QWindow that allows easily creating windows that perform OpenGL rendering using an API that is compatible with QOpenGLWidget and is similar to the legacy QGLWidget. Unlike QOpenGLWidget, QOpenGLWindow has no dependency on the widgets module and offers better performance.

A typical application will subclass QOpenGLWindow and reimplement the following virtual functions:

  • initializeGL() to perform OpenGL resource initialization
  • resizeGL() to set up the transformation matrices and other window size dependent resources
  • paintGL() to issue OpenGL commands or draw using QPainter

To schedule a repaint, call the update() function. Note that this will not immediately result in a call to paintGL(). Calling update() multiple times in a row will not change the behavior in any way.

This is a slot so it can be connected to a QTimer::timeout() signal to perform animation. Note however that in the modern OpenGL world it is a much better choice to rely on synchronization to the vertical refresh rate of the display. See setSwapInterval() on a description of the swap interval. With a swap interval of 1, which is the case on most systems by default, the swapBuffers() call, that is executed internally by QOpenGLWindow after each repaint, will block and wait for vsync. This means that whenever the swap is done, an update can be scheduled again by calling update(), without relying on timers.

To request a specific configuration for the context, use setFormat() like for any other QWindow. This allows, among others, requesting a given OpenGL version and profile, or enabling depth and stencil buffers.

Unlike QWindow, QOpenGLWindow allows opening a painter on itself and perform QPainter-based drawing.

QOpenGLWindow supports multiple update behaviors. The default, NoPartialUpdate is equivalent to a regular, OpenGL-based QWindow or the legacy QGLWidget. In contrast, PartialUpdateBlit and PartialUpdateBlend are more in line with QOpenGLWidget's way of working, where there is always an extra, dedicated framebuffer object present. These modes allow, by sacrificing some performance, redrawing only a smaller area on each paint and having the rest of the content preserved from of the previous frame. This is useful for applications than render incrementally using QPainter, because this way they do not have to redraw the entire window content on each paintGL() call.

Similarly to QOpenGLWidget, QOpenGLWindow supports the Qt::AA_ShareOpenGLContexts attribute. When enabled, the OpenGL contexts of all QOpenGLWindow instances will share with each other. This allows accessing each other's shareable OpenGL resources.

For more information on graphics in Qt, see Graphics.

Methods

impl QOpenGLWindow[src]

pub fn frame_swapped(&self) -> Signal<()>[src]

This signal is emitted after the potentially blocking buffer swap has been done. Applications that wish to continuously repaint synchronized to the vertical refresh, should issue an update() upon this signal. This allows for a much smoother experience compared to the traditional usage of timers.

Returns a built-in Qt signal QOpenGLWindow::frameSwapped that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted after the potentially blocking buffer swap has been done. Applications that wish to continuously repaint synchronized to the vertical refresh, should issue an update() upon this signal. This allows for a much smoother experience compared to the traditional usage of timers.

pub unsafe fn context(&self) -> QPtr<QOpenGLContext>[src]

Returns The QOpenGLContext used by this window or 0 if not yet initialized.

Calls C++ function: QOpenGLContext* QOpenGLWindow::context() const.

C++ documentation:

Returns The QOpenGLContext used by this window or 0 if not yet initialized.

pub unsafe fn default_framebuffer_object(&self) -> u32[src]

The framebuffer object handle used by this window.

Calls C++ function: GLuint QOpenGLWindow::defaultFramebufferObject() const.

C++ documentation:

The framebuffer object handle used by this window.

When the update behavior is set to NoPartialUpdate, there is no separate framebuffer object. In this case the returned value is the ID of the default framebuffer.

Otherwise the value of the ID of the framebuffer object or 0 if not yet initialized.

pub unsafe fn done_current(&self)[src]

Releases the context.

Calls C++ function: void QOpenGLWindow::doneCurrent().

C++ documentation:

Releases the context.

It is not necessary to call this function in most cases, since the widget will make sure the context is bound and released properly when invoking paintGL().

See also makeCurrent().

pub unsafe fn grab_framebuffer(&self) -> CppBox<QImage>[src]

Returns a 32-bit RGB image of the framebuffer.

Calls C++ function: QImage QOpenGLWindow::grabFramebuffer().

C++ documentation:

Returns a 32-bit RGB image of the framebuffer.

Note: This is a potentially expensive operation because it relies on glReadPixels() to read back the pixels. This may be slow and can stall the GPU pipeline.

Note: When used together with update behavior NoPartialUpdate, the returned image may not contain the desired content when called after the front and back buffers have been swapped (unless preserved swap is enabled in the underlying windowing system interface). In this mode the function reads from the back buffer and the contents of that may not match the content on the screen (the front buffer). In this case the only place where this function can safely be used is paintGL() or paintOverGL().

pub unsafe fn is_valid(&self) -> bool[src]

Returns true if the window's OpenGL resources, like the context, have been successfully initialized. Note that the return value is always false until the window becomes exposed (shown).

Calls C++ function: bool QOpenGLWindow::isValid() const.

C++ documentation:

Returns true if the window's OpenGL resources, like the context, have been successfully initialized. Note that the return value is always false until the window becomes exposed (shown).

pub unsafe fn make_current(&self)[src]

Prepares for rendering OpenGL content for this window by making the corresponding context current and binding the framebuffer object, if there is one, in that context context.

Calls C++ function: void QOpenGLWindow::makeCurrent().

C++ documentation:

Prepares for rendering OpenGL content for this window by making the corresponding context current and binding the framebuffer object, if there is one, in that context context.

It is not necessary to call this function in most cases, because it is called automatically before invoking paintGL(). It is provided nonetheless to support advanced, multi-threaded scenarios where a thread different than the GUI or main thread may want to update the surface or framebuffer contents. See QOpenGLContext for more information on threading related issues.

This function is suitable for calling also when the underlying platform window is already destroyed. This means that it is safe to call this function from a QOpenGLWindow subclass' destructor. If there is no native window anymore, an offscreen surface is used instead. This ensures that OpenGL resource cleanup operations in the destructor will always work, as long as this function is called first.

See also QOpenGLContext, context(), paintGL(), and doneCurrent().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QOpenGLWindow::metaObject() const.

pub unsafe fn from_update_behavior_q_window(
    update_behavior: UpdateBehavior,
    parent: impl CastInto<Ptr<QWindow>>
) -> QBox<QOpenGLWindow>
[src]

Constructs a new QOpenGLWindow with the given parent and updateBehavior.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior = …, QWindow* parent = …).

C++ documentation:

Constructs a new QOpenGLWindow with the given parent and updateBehavior.

See also QOpenGLWindow::UpdateBehavior.

pub unsafe fn from_q_opengl_context_update_behavior_q_window(
    share_context: impl CastInto<Ptr<QOpenGLContext>>,
    update_behavior: UpdateBehavior,
    parent: impl CastInto<Ptr<QWindow>>
) -> QBox<QOpenGLWindow>
[src]

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow(QOpenGLContext* shareContext, QOpenGLWindow::UpdateBehavior updateBehavior = …, QWindow* parent = …).

C++ documentation:

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

See also QOpenGLWindow::UpdateBehavior and shareContext.

pub unsafe fn new() -> QBox<QOpenGLWindow>[src]

The QOpenGLWindow class is a convenience subclass of QWindow to perform OpenGL painting.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow().

C++ documentation:

The QOpenGLWindow class is a convenience subclass of QWindow to perform OpenGL painting.

QOpenGLWindow is an enhanced QWindow that allows easily creating windows that perform OpenGL rendering using an API that is compatible with QOpenGLWidget and is similar to the legacy QGLWidget. Unlike QOpenGLWidget, QOpenGLWindow has no dependency on the widgets module and offers better performance.

A typical application will subclass QOpenGLWindow and reimplement the following virtual functions:

  • initializeGL() to perform OpenGL resource initialization
  • resizeGL() to set up the transformation matrices and other window size dependent resources
  • paintGL() to issue OpenGL commands or draw using QPainter

To schedule a repaint, call the update() function. Note that this will not immediately result in a call to paintGL(). Calling update() multiple times in a row will not change the behavior in any way.

This is a slot so it can be connected to a QTimer::timeout() signal to perform animation. Note however that in the modern OpenGL world it is a much better choice to rely on synchronization to the vertical refresh rate of the display. See setSwapInterval() on a description of the swap interval. With a swap interval of 1, which is the case on most systems by default, the swapBuffers() call, that is executed internally by QOpenGLWindow after each repaint, will block and wait for vsync. This means that whenever the swap is done, an update can be scheduled again by calling update(), without relying on timers.

To request a specific configuration for the context, use setFormat() like for any other QWindow. This allows, among others, requesting a given OpenGL version and profile, or enabling depth and stencil buffers.

Unlike QWindow, QOpenGLWindow allows opening a painter on itself and perform QPainter-based drawing.

QOpenGLWindow supports multiple update behaviors. The default, NoPartialUpdate is equivalent to a regular, OpenGL-based QWindow or the legacy QGLWidget. In contrast, PartialUpdateBlit and PartialUpdateBlend are more in line with QOpenGLWidget's way of working, where there is always an extra, dedicated framebuffer object present. These modes allow, by sacrificing some performance, redrawing only a smaller area on each paint and having the rest of the content preserved from of the previous frame. This is useful for applications than render incrementally using QPainter, because this way they do not have to redraw the entire window content on each paintGL() call.

Similarly to QOpenGLWidget, QOpenGLWindow supports the Qt::AA_ShareOpenGLContexts attribute. When enabled, the OpenGL contexts of all QOpenGLWindow instances will share with each other. This allows accessing each other's shareable OpenGL resources.

For more information on graphics in Qt, see Graphics.

pub unsafe fn from_update_behavior(
    update_behavior: UpdateBehavior
) -> QBox<QOpenGLWindow>
[src]

Constructs a new QOpenGLWindow with the given parent and updateBehavior.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior = …).

C++ documentation:

Constructs a new QOpenGLWindow with the given parent and updateBehavior.

See also QOpenGLWindow::UpdateBehavior.

pub unsafe fn from_q_opengl_context_update_behavior(
    share_context: impl CastInto<Ptr<QOpenGLContext>>,
    update_behavior: UpdateBehavior
) -> QBox<QOpenGLWindow>
[src]

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow(QOpenGLContext* shareContext, QOpenGLWindow::UpdateBehavior updateBehavior = …).

C++ documentation:

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

See also QOpenGLWindow::UpdateBehavior and shareContext.

pub unsafe fn from_q_opengl_context(
    share_context: impl CastInto<Ptr<QOpenGLContext>>
) -> QBox<QOpenGLWindow>
[src]

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

Calls C++ function: [constructor] void QOpenGLWindow::QOpenGLWindow(QOpenGLContext* shareContext).

C++ documentation:

Constructs a new QOpenGLWindow with the given parent and updateBehavior. The QOpenGLWindow's context will share with shareContext.

See also QOpenGLWindow::UpdateBehavior and shareContext.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QOpenGLWindow::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QOpenGLWindow::qt_metacast(const char* arg1).

pub unsafe fn share_context(&self) -> QPtr<QOpenGLContext>[src]

Returns The QOpenGLContext requested to be shared with this window's QOpenGLContext.

Calls C++ function: QOpenGLContext* QOpenGLWindow::shareContext() const.

C++ documentation:

Returns The QOpenGLContext requested to be shared with this window's QOpenGLContext.

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QOpenGLWindow::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QOpenGLWindow::trUtf8(const char* s, const char* c, int n).

pub unsafe fn update_behavior(&self) -> UpdateBehavior[src]

Returns the update behavior for this QOpenGLWindow.

Calls C++ function: QOpenGLWindow::UpdateBehavior QOpenGLWindow::updateBehavior() const.

C++ documentation:

Returns the update behavior for this QOpenGLWindow.

Methods from Deref<Target = QPaintDeviceWindow>

pub fn slot_update(&self) -> Receiver<()>[src]

Marks the entire window as dirty and schedules a repaint.

Returns a built-in Qt slot QPaintDeviceWindow::update that can be passed to qt_core::Signal::connect.

C++ documentation:

Marks the entire window as dirty and schedules a repaint.

Note: Subsequent calls to this function before the next paint event will get ignored.

Note: For non-exposed windows the update is deferred until the window becomes exposed again.

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QPaintDeviceWindow::metaObject() const.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QPaintDeviceWindow::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QPaintDeviceWindow::qt_metacast(const char* arg1).

pub unsafe fn update_q_rect(&self, rect: impl CastInto<Ref<QRect>>)[src]

Marks the rect of the window as dirty and schedules a repaint.

Calls C++ function: void QPaintDeviceWindow::update(const QRect& rect).

C++ documentation:

Marks the rect of the window as dirty and schedules a repaint.

Note: Subsequent calls to this function before the next paint event will get ignored, but rect is added to the region to update.

Note: For non-exposed windows the update is deferred until the window becomes exposed again.

pub unsafe fn update_q_region(&self, region: impl CastInto<Ref<QRegion>>)[src]

Marks the region of the window as dirty and schedules a repaint.

Calls C++ function: void QPaintDeviceWindow::update(const QRegion& region).

C++ documentation:

Marks the region of the window as dirty and schedules a repaint.

Note: Subsequent calls to this function before the next paint event will get ignored, but region is added to the region to update.

Note: For non-exposed windows the update is deferred until the window becomes exposed again.

pub unsafe fn update(&self)[src]

Marks the entire window as dirty and schedules a repaint.

Calls C++ function: [slot] void QPaintDeviceWindow::update().

C++ documentation:

Marks the entire window as dirty and schedules a repaint.

Note: Subsequent calls to this function before the next paint event will get ignored.

Note: For non-exposed windows the update is deferred until the window becomes exposed again.

Trait Implementations

impl CppDeletable for QOpenGLWindow[src]

unsafe fn delete(&self)[src]

Destroys the QOpenGLWindow instance, freeing its resources.

Calls C++ function: virtual [destructor] void QOpenGLWindow::~QOpenGLWindow().

C++ documentation:

Destroys the QOpenGLWindow instance, freeing its resources.

The OpenGLWindow's context is made current in the destructor, allowing for safe destruction of any child object that may need to release OpenGL resources belonging to the context provided by this window.

Warning: if you have objects wrapping OpenGL resources (such as QOpenGLBuffer, QOpenGLShaderProgram, etc.) as members of a QOpenGLWindow subclass, you may need to add a call to makeCurrent() in that subclass' destructor as well. Due to the rules of C++ object destruction, those objects will be destroyed before calling this function (but after that the destructor of the subclass has run), therefore making the OpenGL context current in this function happens too late for their safe disposal.

This function was introduced in Qt 5.5.

See also makeCurrent.

impl Deref for QOpenGLWindow[src]

type Target = QPaintDeviceWindow

The resulting type after dereferencing.

fn deref(&self) -> &QPaintDeviceWindow[src]

Calls C++ function: QPaintDeviceWindow* static_cast<QPaintDeviceWindow*>(QOpenGLWindow* ptr).

impl DynamicCast<QOpenGLWindow> for QPaintDeviceWindow[src]

unsafe fn dynamic_cast(ptr: Ptr<QPaintDeviceWindow>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* dynamic_cast<QOpenGLWindow*>(QPaintDeviceWindow* ptr).

impl DynamicCast<QOpenGLWindow> for QWindow[src]

unsafe fn dynamic_cast(ptr: Ptr<QWindow>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* dynamic_cast<QOpenGLWindow*>(QWindow* ptr).

impl DynamicCast<QOpenGLWindow> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* dynamic_cast<QOpenGLWindow*>(QObject* ptr).

impl DynamicCast<QOpenGLWindow> for QSurface[src]

unsafe fn dynamic_cast(ptr: Ptr<QSurface>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* dynamic_cast<QOpenGLWindow*>(QSurface* ptr).

impl DynamicCast<QOpenGLWindow> for QPaintDevice[src]

unsafe fn dynamic_cast(ptr: Ptr<QPaintDevice>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* dynamic_cast<QOpenGLWindow*>(QPaintDevice* ptr).

impl StaticDowncast<QOpenGLWindow> for QPaintDeviceWindow[src]

unsafe fn static_downcast(ptr: Ptr<QPaintDeviceWindow>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* static_cast<QOpenGLWindow*>(QPaintDeviceWindow* ptr).

impl StaticDowncast<QOpenGLWindow> for QWindow[src]

unsafe fn static_downcast(ptr: Ptr<QWindow>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* static_cast<QOpenGLWindow*>(QWindow* ptr).

impl StaticDowncast<QOpenGLWindow> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* static_cast<QOpenGLWindow*>(QObject* ptr).

impl StaticDowncast<QOpenGLWindow> for QSurface[src]

unsafe fn static_downcast(ptr: Ptr<QSurface>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* static_cast<QOpenGLWindow*>(QSurface* ptr).

impl StaticDowncast<QOpenGLWindow> for QPaintDevice[src]

unsafe fn static_downcast(ptr: Ptr<QPaintDevice>) -> Ptr<QOpenGLWindow>[src]

Calls C++ function: QOpenGLWindow* static_cast<QOpenGLWindow*>(QPaintDevice* ptr).

impl StaticUpcast<QObject> for QOpenGLWindow[src]

unsafe fn static_upcast(ptr: Ptr<QOpenGLWindow>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QOpenGLWindow* ptr).

impl StaticUpcast<QPaintDevice> for QOpenGLWindow[src]

unsafe fn static_upcast(ptr: Ptr<QOpenGLWindow>) -> Ptr<QPaintDevice>[src]

Calls C++ function: QPaintDevice* static_cast<QPaintDevice*>(QOpenGLWindow* ptr).

impl StaticUpcast<QPaintDeviceWindow> for QOpenGLWindow[src]

unsafe fn static_upcast(ptr: Ptr<QOpenGLWindow>) -> Ptr<QPaintDeviceWindow>[src]

Calls C++ function: QPaintDeviceWindow* static_cast<QPaintDeviceWindow*>(QOpenGLWindow* ptr).

impl StaticUpcast<QSurface> for QOpenGLWindow[src]

unsafe fn static_upcast(ptr: Ptr<QOpenGLWindow>) -> Ptr<QSurface>[src]

Calls C++ function: QSurface* static_cast<QSurface*>(QOpenGLWindow* ptr).

impl StaticUpcast<QWindow> for QOpenGLWindow[src]

unsafe fn static_upcast(ptr: Ptr<QOpenGLWindow>) -> Ptr<QWindow>[src]

Calls C++ function: QWindow* static_cast<QWindow*>(QOpenGLWindow* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.