内容表

上一话题

QGLColormap

下一话题

QGLFormat

QGLContext

QGLContext class encapsulates an OpenGL rendering context. 更多

Inheritance diagram of PySide2.QtOpenGL.QGLContext

概要

函数

虚函数

静态函数

详细描述

An OpenGL rendering context is a complete set of OpenGL state variables. The rendering context’s format is set in the constructor, but it can also be set later with setFormat() . The format options that are actually set are returned by format() ; the options you asked for are returned by requestedFormat() . Note that after a QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the create() function. The makeCurrent() function makes this context the current rendering context. You can make no context current using doneCurrent() reset() function will reset the context and make it invalid.

You can examine properties of the context with, e.g. isValid() , isSharing() , initialized() , windowCreated() and overlayTransparentColor() .

If you’re using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers() .

请注意 QGLContext is not thread safe.

class QGLContext ( format )
参数

format QGLFormat

PySide2.QtOpenGL.QGLContext. BindOption

A set of options to decide how to bind a texture using bindTexture() .

常量

描述

QGLContext.NoBindOption

Don’t do anything, pass the texture straight through.

QGLContext.InvertedYBindOption

Specifies that the texture should be flipped over the X axis so that the texture coordinate 0,0 corresponds to the top left corner. Inverting the texture implies a deep copy prior to upload.

QGLContext.MipmapBindOption

Specifies that bindTexture() should try to generate mipmaps. If the GL implementation supports the GL_SGIS_generate_mipmap extension, mipmaps will be automatically generated for the texture. Mipmap generation is only supported for the GL_TEXTURE_2D target.

QGLContext.PremultipliedAlphaBindOption

Specifies that the image should be uploaded with premultiplied alpha and does a conversion accordingly.

QGLContext.LinearFilteringBindOption

Specifies that the texture filtering should be set to GL_LINEAR. Default is GL_NEAREST. If mipmap is also enabled, filtering will be set to GL_LINEAR_MIPMAP_LINEAR.

QGLContext.DefaultBindOption

In Qt 4.5 and earlier, bindTexture() would mirror the image and automatically generate mipmaps. This option helps preserve this default behavior.

4.6 版新增。

static PySide2.QtOpenGL.QGLContext. areSharing ( context1 , context2 )
参数
返回类型

bool

返回 true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false .

PySide2.QtOpenGL.QGLContext. bindTexture ( image [ , target=GL_TEXTURE_2D [ , format=GL_RGBA ] ] )
参数
  • image QImage

  • target GLenum

  • format GLint

返回类型

GLuint

PySide2.QtOpenGL.QGLContext. bindTexture ( image , target , format , options )
参数
  • image QImage

  • target GLenum

  • format GLint

  • options BindOptions

返回类型

GLuint

PySide2.QtOpenGL.QGLContext. bindTexture ( pixmap [ , target=GL_TEXTURE_2D [ , format=GL_RGBA ] ] )
参数
  • pixmap QPixmap

  • target GLenum

  • format GLint

返回类型

GLuint

PySide2.QtOpenGL.QGLContext. bindTexture ( pixmap , target , format , options )
参数
  • pixmap QPixmap

  • target GLenum

  • format GLint

  • options BindOptions

返回类型

GLuint

PySide2.QtOpenGL.QGLContext. bindTexture ( fileName )
参数

fileName – unicode

返回类型

GLuint

这是重载函数。

Reads the compressed texture file fileName and generates a 2D GL texture from it.

This function can load DirectDrawSurface (DDS) textures in the DXT1, DXT3 and DXT5 DDS formats if the GL_ARB_texture_compression and GL_EXT_texture_compression_s3tc extensions are supported.

Since 4.6.1, textures in the ETC1 format can be loaded if the GL_OES_compressed_ETC1_RGB8_texture extension is supported and the ETC1 texture has been encapsulated in the PVR container format. Also, textures in the PVRTC2 and PVRTC4 formats can be loaded if the GL_IMG_texture_compression_pvrtc extension is supported.

另请参阅

deleteTexture()

PySide2.QtOpenGL.QGLContext. chooseContext ( [ shareContext=None ] )
参数

shareContext QGLContext

返回类型

bool

This semi-internal function is called by create() . It creates a system-dependent OpenGL handle that matches the format() of shareContext as closely as possible, returning true if successful or false if a suitable handle could not be found.

On Windows, it calls the virtual function choosePixelFormat(), which finds a matching pixel format identifier. On X11, it calls the virtual function chooseVisual() which finds an appropriate X visual. On other platforms it may work differently.

PySide2.QtOpenGL.QGLContext. colorIndex ( c )
参数

c QColor

返回类型

uint

PySide2.QtOpenGL.QGLContext. contextHandle ( )
返回类型

QOpenGLContext

Returns the OpenGL context handle.

PySide2.QtOpenGL.QGLContext. create ( [ shareContext=None ] )
参数

shareContext QGLContext

返回类型

bool

Creates the GL context. Returns true if it was successful in creating a valid GL rendering context on the paint device specified in the constructor; otherwise returns false (i.e. the context is invalid).

If the OpenGL implementation on your system does not support the requested version of OpenGL context, then QGLContext will try to create the closest matching version. The actual created context properties can be queried using the QGLFormat returned by the format() function. For example, if you request a context that supports OpenGL 4.3 Core profile but the driver and/or hardware only supports version 3.2 Core profile contexts then you will get a 3.2 Core profile context.

After successful creation, format() returns the set of features of the created GL rendering context.

shareContext points to a valid QGLContext , this method will try to establish OpenGL display list and texture object sharing between this context and the shareContext . Note that this may fail if the two contexts have different formats 。使用 isSharing() to see if sharing is in effect.

警告

Implementation note: initialization of C++ class members usually takes place in the class constructor. QGLContext is an exception because it must be simple to customize. The virtual functions chooseContext() (and chooseVisual() for X11) can be reimplemented in a subclass to select a particular context. The problem is that virtual functions are not properly called during construction (even though this is correct C++) because C++ constructs class hierarchies from the bottom up. For this reason we need a function.

static PySide2.QtOpenGL.QGLContext. currentContext ( )
返回类型

QGLContext

Returns the current context, i.e. the context to which any OpenGL commands will currently be directed. Returns 0 if no context is current.

另请参阅

makeCurrent()

PySide2.QtOpenGL.QGLContext. deleteTexture ( tx_id )
参数

tx_id GLuint

Removes the texture identified by id from the texture cache, and calls glDeleteTextures() to delete the texture from the context.

另请参阅

bindTexture()

PySide2.QtOpenGL.QGLContext. device ( )
返回类型

QPaintDevice

Returns the paint device set for this context.

另请参阅

QGLContext()

PySide2.QtOpenGL.QGLContext. deviceIsPixmap ( )
返回类型

bool

返回 true if the paint device of this context is a pixmap; otherwise returns false .

Since Qt 5 the paint device is never actually a pixmap. renderPixmap() is however still simulated using framebuffer objects and readbacks, and this function will return true 在这种情况下。

PySide2.QtOpenGL.QGLContext. doneCurrent ( )

Makes no GL context the current context. Normally, you do not need to call this function; QGLContext calls it as necessary.

PySide2.QtOpenGL.QGLContext. drawTexture ( point , textureId [ , textureTarget=GL_TEXTURE_2D ] )
参数
  • point QPointF

  • textureId GLuint

  • textureTarget GLenum

PySide2.QtOpenGL.QGLContext. drawTexture ( target , textureId [ , textureTarget=GL_TEXTURE_2D ] )
参数
  • target QRectF

  • textureId GLuint

  • textureTarget GLenum

PySide2.QtOpenGL.QGLContext. format ( )
返回类型

QGLFormat

Returns the frame buffer format that was obtained (this may be a subset of what was requested).

static PySide2.QtOpenGL.QGLContext. fromOpenGLContext ( platformContext )
参数

platformContext QOpenGLContext

返回类型

QGLContext

Returns an OpenGL context for the window context specified by the context 参数。

PySide2.QtOpenGL.QGLContext. initialized ( )
返回类型

bool

返回 true if this context has been initialized, i.e. if initializeGL() has been performed on it; otherwise returns false .

另请参阅

setInitialized()

PySide2.QtOpenGL.QGLContext. isSharing ( )
返回类型

bool

返回 true if this context is sharing its GL context with another QGLContext , otherwise false is returned. Note that context sharing might not be supported between contexts with different formats.

PySide2.QtOpenGL.QGLContext. isValid ( )
返回类型

bool

返回 true if a GL rendering context has been successfully created; otherwise returns false .

PySide2.QtOpenGL.QGLContext. makeCurrent ( )

Makes this context the current OpenGL rendering context. All GL functions you call operate on this context until another context is made current.

In some very rare cases the underlying call may fail. If this occurs an error message is output to stderr.

If you call this from a thread other than the main UI thread, make sure you’ve first pushed the context to the relevant thread from the UI thread using moveToThread() .

PySide2.QtOpenGL.QGLContext. moveToThread ( thread )
参数

thread QThread

Moves the QGLContext 到给定 thread .

Enables calling swapBuffers() and makeCurrent() on the context in the given thread.

PySide2.QtOpenGL.QGLContext. overlayTransparentColor ( )
返回类型

QColor

If this context is a valid context in an overlay plane, returns the plane’s transparent color. Otherwise returns an invalid 颜色。

The returned color’s pixel value is the index of the transparent color in the colormap of the overlay plane. (Naturally, the color’s RGB values are meaningless.)

返回的 QColor object will generally work as expected only when passed as the argument to qglColor() or qglClearColor() . Under certain circumstances it can also be used to draw transparent graphics with a QPainter .

PySide2.QtOpenGL.QGLContext. requestedFormat ( )
返回类型

QGLFormat

Returns the frame buffer format that was originally requested in the constructor or setFormat() .

另请参阅

format()

PySide2.QtOpenGL.QGLContext. reset ( )

Resets the context and makes it invalid.

PySide2.QtOpenGL.QGLContext. setDevice ( pDev )
参数

pDev QPaintDevice

另请参阅

device()

PySide2.QtOpenGL.QGLContext. setFormat ( format )
参数

format QGLFormat

设置 format for this context. The context is reset .

调用 create() to create a new GL context that tries to match the new format.

cx = QGLContext()
#  ...
f = QGLFormat()
f.setStereo(True)
cx.setFormat(f)
if !cx.create():
    exit() # no OpenGL support, or cannot render on the specified paintdevice
if !cx.format().stereo():
    exit() # could not create stereo context
											
PySide2.QtOpenGL.QGLContext. setInitialized ( on )
参数

on bool

on is true the context has been initialized, i.e. has been called on it. If on is false the context has not been initialized.

另请参阅

initialized()

static PySide2.QtOpenGL.QGLContext. setTextureCacheLimit ( size )
参数

size int

This function sets the limit for the texture cache to size , expressed in kilobytes.

By default, the cache limit is approximately 64 MB.

PySide2.QtOpenGL.QGLContext. setValid ( valid )
参数

valid bool

另请参阅

isValid()

PySide2.QtOpenGL.QGLContext. setWindowCreated ( on )
参数

on bool

on is true the context has had a window created for it. If on is false no window has been created for the context.

另请参阅

windowCreated()

PySide2.QtOpenGL.QGLContext. swapBuffers ( )

Call this to finish a frame of OpenGL rendering, and make sure to call makeCurrent() again before issuing any further OpenGL commands, for example as part of a new frame.

static PySide2.QtOpenGL.QGLContext. textureCacheLimit ( )
返回类型

int

Returns the current texture cache limit in kilobytes.

PySide2.QtOpenGL.QGLContext. windowCreated ( )
返回类型

bool

返回 true if a window has been created for this context; otherwise returns false .