QGLContext Class Reference

[QtOpenGL module]

该QGLContext类封装了一个OpenGL渲染上下文。More…

Types

  • enum BindOption { NoBindOption, InvertedYBindOption, MipmapBindOption, PremultipliedAlphaBindOption, LinearFilteringBindOption, DefaultBindOption }
  • class **[BindOptions]($docs-index.htm)**

Methods

  • __init__ (self, QGLFormat format, QPaintDevice device)
  • int bindTexture (self, QImage image, int target = GL_TEXTURE_2D, int format = GL_RGBA)
  • int bindTexture (self, QPixmap pixmap, int target = GL_TEXTURE_2D, int format = GL_RGBA)
  • int bindTexture (self, QString fileName)
  • int bindTexture (self, QImage image, int target, int format, BindOptions options)
  • int bindTexture (self, QPixmap pixmap, int target, int format, BindOptions options)
  • bool chooseContext (self, QGLContext shareContext = None)
  • sip.voidptr chooseVisual (self)
  • bool create (self, QGLContext shareContext = None)
  • deleteTexture (self, int tx_id)
  • QPaintDevice device (self)
  • bool deviceIsPixmap (self)
  • doneCurrent (self)
  • drawTexture (self, QRectF target, int textureId, int textureTarget = GL_TEXTURE_2D)
  • drawTexture (self, QPointF point, int textureId, int textureTarget = GL_TEXTURE_2D)
  • QGLFormat format (self)
  • generateFontDisplayLists (self, QFont fnt, int listBase)
  • sip.voidptr getProcAddress (self, QString proc)
  • bool initialized (self)
  • bool isSharing (self)
  • bool isValid (self)
  • makeCurrent (self)
  • QColor overlayTransparentColor (self)
  • QGLFormat requestedFormat (self)
  • reset (self)
  • setFormat (self, QGLFormat format)
  • setInitialized (self, bool on)
  • setWindowCreated (self, bool on)
  • swapBuffers (self)
  • bool windowCreated (self)

Static Methods

  • bool areSharing (QGLContext context1, QGLContext context2)
  • QGLContext currentContext ()
  • setTextureCacheLimit (int size)
  • int textureCacheLimit ()

Detailed Description

该QGLContext类封装了一个OpenGL渲染上下文。

一个OpenGL渲染上下文是一套完整的OpenGL状态变量。渲染上下文的format被设置在构造,但它也可以购买与设置setFormat( ) 。这实际上是设置格式选项由返回format();你要的选项被退回requestedFormat( ) 。请注意,在一个QGLContext对象已建成,实际OpenGL上下文必须通过显式调用创建的create()功能。该makeCurrent()函数使得这方面的当前呈现上下文。您可以no使用上下文电流doneCurrent( ) 。该reset( )函数将重置上下文,并使其无效。

你可以检查上下文的物业,如isValid( )isSharing( )initialized( )windowCreated()和overlayTransparentColor( ) 。

如果你使用双缓冲可以使用换用离屏缓冲屏幕内容swapBuffers( ) 。

请注意, QGLContext是不thread-safe


Type Documentation

  1. QGLContext.BindOption

一组选项来决定如何使用绑定纹理bindTexture( ) 。

Constant Value Description
QGLContext.NoBindOption 0x0000 不要做任何事情,直通传递的质感。
QGLContext.InvertedYBindOption 0x0001 指定纹理应该翻转X轴,以使纹理坐标0,0对应于左上角。反相纹理意味着一个深层副本之前上传。
QGLContext.MipmapBindOption 0x0002 指定bindTexture( )应该生成贴图。如果GL实现支持GL_SGIS_generate_mipmap扩展,贴图将自动为纹理生成。 MIP贴图一代只支持了GL_TEXTURE_2D目标。
QGLContext.PremultipliedAlphaBindOption 0x0004 指定图像应使用预乘alpha上传并做了相应的转换。
QGLContext.LinearFilteringBindOption 0x0008 指定纹理过滤应设置为GL_LINEAR 。默认值是GL_NEAREST 。如果MIP贴图也被启用,过滤将被设置为GL_LINEAR_MIPMAP_LINEAR 。
QGLContext.DefaultBindOption LinearFilteringBindOption | InvertedYBindOption | MipmapBindOption 在Qt 4.5和更早的版本,bindTexture( )将镜像图像,并自动生成贴图。此选项可帮助保护这种默认行为。

通过使用从像素图X11选择它是否可以在像素映射绑定倒挂与否。

用于涂料引擎,表明像素图应该沿着边用像素图/图像进行内存管理,它从,如茎在他们破坏安装钩子。

这个枚举被引入或修改的Qt 4.6 。

该BINDOPTIONS类型是一个typedef为QFlags\u003cBindOption\u003e 。它存储BindOption值的或组合。


Method Documentation

  1. QGLContext.__init__ (self, QGLFormat format, QPaintDevice device)

构造一个OpenGL上下文给定的format它指定为上下文多个显示选项。

如果底层的OpenGL / Window系统不能满足所有要求的功能format,的特征最接近的子集将被使用。创建后,format( )方法将返回所得到的实际格式。

需要注意的是后一QGLContext对象被创建,create( )必须显式地调用来创建实际的OpenGL上下文。上下文会invalid如果它是不能够获得GL上下文的。

See also format()和isValid( ) 。

  1. bool QGLContext.areSharing (QGLContext context1, QGLContext context2)

返回True如果context1context2分享他们吉尔资源,如纹理,着色器程序等,否则返回False 。

此功能被引入Qt的4.6 。

  1. int QGLContext.bindTexture (self, QImage image, int target = GL_TEXTURE_2D, int format = GL_RGBA)

生成和二维GL纹理绑定到当前上下文的基础上,image。生成的纹理ID被返回,并且可以在以后使用中glBindTexture()电话。

target参数指定纹理目标。默认的目标是GL_TEXTURE_2D

format参数设置纹理的内部格式。默认格式为GL_RGBA

绑定options是一组用来决定如何将纹理绑定到上下文选项。

生成的纹理缓存,所以多次调用bindTexture ( )具有相同QImage将返回相同的纹理ID 。

请注意,我们假设为glPixelStore ()和glPixelTransfer ( )参数的默认值。

此功能被引入Qt的4.6 。

See also deleteTexture( ) 。

  1. int QGLContext.bindTexture (self, QPixmap pixmap, int target = GL_TEXTURE_2D, int format = GL_RGBA)

这是一个重载函数。

读取压缩的纹理文件fileName并从它生成一个二维GL纹理。

此功能可以加载DirectDrawSurface ( DDS)纹理的DXT1 , DXT3和DXT5 DDS格式,如果GL_ARB_texture_compressionGL_EXT_texture_compression_s3tc扩展的支持。

自从4.6.1 ,在ETC1格式的纹理可以,如果被加载GL_OES_compressed_ETC1_RGB8_texture扩展支持与ETC1纹理已被封装在PVR的容器格式。另外,在PVRTC2和PVRTC4格式的纹理可以被加载,如果GL_IMG_texture_compression_pvrtc支持扩展。

See also deleteTexture( ) 。

  1. int QGLContext.bindTexture (self, QString fileName)

生成和二维GL纹理绑定到当前上下文的基础上,image。生成的纹理ID被返回,并且可以在以后使用中glBindTexture()电话。

这是一个重载函数。

  1. int QGLContext.bindTexture (self, QImage image, int target, int format, BindOptions options)

这是一个重载函数。

生成并根据绑定一个2D GL纹理pixmap

  1. int QGLContext.bindTexture (self, QPixmap pixmap, int target, int format, BindOptions options)

这是一个重载函数。

生成和二维GL纹理绑定到当前上下文的基础上,pixmap

此功能被引入Qt的4.6 。

  1. bool QGLContext.chooseContext (self, QGLContext shareContext = None)

这个半内部函数被create( ) 。它创建了一个与系统相关的OpenGL手柄相匹配的format的( )shareContext尽可能密切,返回True,如果成功则返回False合适的手柄找不到。

在Windows上,它调用虚函数choosePixelFormat(),它找到一个匹配的像素格式标识符。在X11上,它调用虚函数chooseVisual(),它找到一个恰当的X视觉。在其他平台上也可能有不同的工作。

  1. sip.voidptr QGLContext.chooseVisual (self)

X11 only:这个虚函数试图找到一个可视化的格式相匹配,减少了需求,如果原来的请求不能得到满足。

该算法降低了格式的要求是相当简单的头脑,所以在你的子类中重写此方法,如果你的应用程序有视觉上的选择spcific要求。

See also chooseContext( ) 。

  1. bool QGLContext.create (self, QGLContext shareContext = None)

创建GL上下文。返回True ,如果它是成功地创造在构造函数中指定的绘图设备上的有效GL渲染上下文,否则返回False (即上下文是无效的) 。

创建成功后,format( )返回集合的创建GL渲染上下文的功能。

If shareContext指向一个有效的QGLContext,此方法将尝试建立这样的背景下,并与OpenGL显示列表和纹理对象共享shareContext。请注意,这可能会失败,如果两个上下文有不同的formats。使用isSharing() ,以查看是否共享将发挥作用。

Warning:实现注意事项: C + +的类成员初始化通常发生在类的构造函数。QGLContext是一个例外,因为它必须是简单定制。虚函数chooseContext( ) (和chooseVisual( )用于X11)可以在子类中被重新实现来选择特定的上下文。问题是,虚函数没有正确施工过程中调用(尽管这是正确的C + + )因为C + +构造的类层次结构从下往上。出于这个原因,我们需要一个create( )函数。

See also chooseContext( )format()和isValid( ) 。

  1. QGLContext QGLContext.currentContext ()

[

返回当前上下文,即任何OpenGL命令将当前被定向的上下文。返回0,如果没有上下文是最新的。

]($docs-qglcontext.html)

See also makeCurrent( ) 。

  1. QGLContext.deleteTexture (self, int tx_id)

去除所确定的纹理id从纹理高速缓存,并呼吁glDeleteTextures ()来从上下文中删除的质感。

See also bindTexture( ) 。

  1. QPaintDevice QGLContext.device (self)

[

返回漆设备这方面设置。

]($docs-qpaintdevice.html)

See also QGLContext.QGLContext( ) 。

  1. bool QGLContext.deviceIsPixmap (self)

返回True如果这个上下文的绘图设备是像素图,否则返回False 。

  1. QGLContext.doneCurrent (self)

不作任何GL上下文的当前上下文。通常情况下,你不需要调用此函数;QGLContext调用它是必要的。

  1. QGLContext.drawTexture (self, QRectF target, int textureId, int textureTarget = GL_TEXTURE_2D)

此功能支持以下用例:

  • On OpenGL and OpenGL ES 1.x it draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. The textureTarget should be a 2D texture target.
  • On OpenGL and OpenGL ES 2.x, if a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with type QPaintEngine.OpenGL2, the function will draw the given texture, textureId, to the given target rectangle, target, respecting the current painter state. This will let you draw a texture with the clip, transform, render hints, and composition mode set by the painter. Note that the texture target needs to be GL_TEXTURE_2D for this use case, and that this is the only supported use case under OpenGL ES 2.x.

此功能被引入Qt的4.4 。

  1. QGLContext.drawTexture (self, QPointF point, int textureId, int textureTarget = GL_TEXTURE_2D)

此功能支持以下用例:

  • By default it draws the given texture, textureId, at the given point in OpenGL model space. The textureTarget should be a 2D texture target.
  • If a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with type QPaintEngine.OpenGL2, the function will draw the given texture, textureId, at the given point, respecting the current painter state. This will let you draw a texture with the clip, transform, render hints, and composition mode set by the painter. Note that the texture target needs to be GL_TEXTURE_2D for this use case.

Note:这个功能没有在任何版本的OpenGL ES的支持。

此功能被引入Qt的4.4 。

  1. QGLFormat QGLContext.format (self)

[

返回得到的(这可能是要求什么的一个子集)的帧缓冲格式。

]($docs-qglformat.html)

See also setFormat()和requestedFormat( ) 。

  1. QGLContext.generateFontDisplayLists (self, QFont fnt, int listBase)
  1. sip.voidptr QGLContext.getProcAddress (self, QString proc)

返回一个函数指针传递的GL扩展功能proc。如果不能获得一个指向函数返回0。

  1. bool QGLContext.initialized (self)

返回True如果这方面已经初始化,也就是说,如果QGLWidget.initializeGL( )已在其上被执行,否则返回False 。

See also setInitialized( ) 。

  1. bool QGLContext.isSharing (self)

返回True如果这方面是与另一个共享其GL上下文QGLContext,否则返回假。需要注意的是上下文共享可能不会上下文不同格式之间的支持。

  1. bool QGLContext.isValid (self)

返回True如果一个GL渲染上下文已经成功创建,否则返回False 。

  1. QGLContext.makeCurrent (self)

使得此背景下,当前的OpenGL渲染上下文。你叫所有的GL函数在这样的背景下运作,直到另一个方面是由电流。

在一些非常罕见的情况下,底层调用可能会失败。如果发生这种情况的错误信息输出到stderr 。

  1. QColor QGLContext.overlayTransparentColor (self)

如果这方面是一个复盖面的有效范围内,则返回飞机的透明色。否则返回一个{QColor.isValid() } {无效}颜色。

返回QColor对象将一般工作,只有当作为参数传递如预期QGLWidget.qglColor()或QGLWidget.qglClearColor( ) 。在某些情况下它也可以用于绘制透明的图形用QPainter

  1. QGLFormat QGLContext.requestedFormat (self)

返回的帧缓冲格式最初是要求在构造函数或setFormat( ) 。

See also format( ) 。

  1. QGLContext.reset (self)

重设背景,并使其无效。

See also create()和isValid( ) 。

  1. QGLContext.setFormat (self, QGLFormat format)

设置format此上下文。上下文是reset

Call create()来创建一个新的GL上下文,试图以匹配新的格式。

  1. [QGLContext]($docs-qglcontext.html) *cx;
  2. // ...
  3. [QGLFormat]($docs-qglformat.html) f;
  4. f.setStereo(true);
  5. cx->setFormat(f);
  6. if (!cx->create())
  7. exit(); // no OpenGL support, or cannot render on the specified paintdevice
  8. if (!cx->format().stereo())
  9. exit(); // could not create stereo context

See also format( )reset()和create( ) 。

  1. QGLContext.setInitialized (self, bool on)

If on是真正的上下文被初始化,即QGLContext.setInitialized ( )被调用就可以了。如果on是假的情况下没有被初始化。

See also initialized( ) 。

  1. QGLContext.setTextureCacheLimit (int size)

该函数设置限制的纹理缓存到size,表示以KB为单位。

默认情况下,缓存限制为大约64 MB的。

See also textureCacheLimit( ) 。

  1. QGLContext.setWindowCreated (self, bool on)

If on是真正的上下文已为其创建一个窗口。如果on是假的无窗已为上下文中创建。

See also windowCreated( ) 。

  1. QGLContext.swapBuffers (self)

掉期,一个离屏缓冲屏幕内容。只有当上下文是在双缓冲模式。

See also QGLFormat.setDoubleBuffer( ) 。

  1. int QGLContext.textureCacheLimit ()

返回以KB为单位的当前纹理缓存限制。

See also setTextureCacheLimit( ) 。

  1. bool QGLContext.windowCreated (self)

如果一个窗口已经被用于这样的背景下建立的,则返回True ,否则返回False 。

See also setWindowCreated( ) 。