• PySide 模块
  • PySide.QtOpenGL
  • 内容表

    上一话题

    QGLBuffer

    下一话题

    QGLFormat

    QGLContext

    概要

    函数

    虚函数

    静态函数

    详细描述

    PySide.QtOpenGL.QGLContext class encapsulates an OpenGL rendering context.

    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 PySide.QtOpenGL.QGLContext.setFormat() . The format options that are actually set are returned by PySide.QtOpenGL.QGLContext.format() ; the options you asked for are returned by PySide.QtOpenGL.QGLContext.requestedFormat() . Note that after a PySide.QtOpenGL.QGLContext object has been constructed, the actual OpenGL context must be created by explicitly calling the PySide.QtOpenGL.QGLContext.create() function. The PySide.QtOpenGL.QGLContext.makeCurrent() function makes this context the current rendering context. You can make no context current using PySide.QtOpenGL.QGLContext.doneCurrent() PySide.QtOpenGL.QGLContext.reset() function will reset the context and make it invalid.

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

    If you're using double buffering you can swap the screen contents with the off-screen buffer using PySide.QtOpenGL.QGLContext.swapBuffers() .

    请注意 PySide.QtOpenGL.QGLContext 不是 thread-safe .

    class PySide.QtOpenGL. QGLContext ( format )
    参数: format PySide.QtOpenGL.QGLFormat

    Constructs an OpenGL context with the given format which specifies several display options for the context.

    If the underlying OpenGL/Window system cannot satisfy all the features requested in format , the nearest subset of features will be used. After creation, the PySide.QtOpenGL.QGLContext.format() method will return the actual format obtained.

    Note that after a PySide.QtOpenGL.QGLContext object has been constructed, PySide.QtOpenGL.QGLContext.create() must be called explicitly to create the actual OpenGL context. The context will be invalid if it was not possible to obtain a GL context at all.

    PySide.QtOpenGL.QGLContext. BindOption

    A set of options to decide how to bind a texture using PySide.QtOpenGL.QGLContext.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 PySide.QtOpenGL.QGLContext.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, PySide.QtOpenGL.QGLContext.bindTexture() would mirror the image and automatically generate mipmaps. This option helps preserve this default behavior.

    Used by x11 from pixmap to choose whether or not it can bind the pixmap upside down or not.

    Used by paint engines to indicate that the pixmap should be memory managed along side with the pixmap/image that it stems from, e.g. installing destruction hooks in them.

    注意

    该枚举在 Qt 4.6 引入或被修改

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

    PySide.QtCore.bool

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

    PySide.QtOpenGL.QGLContext. bindTexture ( fileName )
    参数: fileName – unicode
    返回类型: PySide.QtOpenGL.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.

    PySide.QtOpenGL.QGLContext. bindTexture ( pixmap , target , format , options )
    参数:
    • pixmap PySide.QtGui.QPixmap
    • target PySide.QtOpenGL.GLenum
    • format PySide.QtOpenGL.GLint
    • options PySide.QtOpenGL.QGLContext.BindOptions
    返回类型:

    PySide.QtOpenGL.GLuint

    PySide.QtOpenGL.QGLContext. bindTexture ( image , target , format , options )
    参数:
    • image PySide.QtGui.QImage
    • target PySide.QtOpenGL.GLenum
    • format PySide.QtOpenGL.GLint
    • options PySide.QtOpenGL.QGLContext.BindOptions
    返回类型:

    PySide.QtOpenGL.GLuint

    PySide.QtOpenGL.QGLContext. bindTexture ( pixmap [ , target=0x0DE1 [ , format=0x1908 ] ] )
    参数:
    返回类型:

    PySide.QtOpenGL.GLuint

    这是重载函数。

    Generates and binds a 2D GL texture based on pixmap .

    PySide.QtOpenGL.QGLContext. bindTexture ( image [ , target=0x0DE1 [ , format=0x1908 ] ] )
    参数:
    返回类型:

    PySide.QtOpenGL.GLuint

    Generates and binds a 2D GL texture to the current context, based on image . The generated texture id is returned and can be used in later glBindTexture() 调用。

    这是重载函数。

    PySide.QtOpenGL.QGLContext. chooseContext ( [ shareContext=None ] )
    参数: shareContext PySide.QtOpenGL.QGLContext
    返回类型: PySide.QtCore.bool

    This semi-internal function is called by PySide.QtOpenGL.QGLContext.create() . It creates a system-dependent OpenGL handle that matches the PySide.QtOpenGL.QGLContext.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.

    PySide.QtOpenGL.QGLContext. colorIndex ( c )
    参数: c PySide.QtGui.QColor
    返回类型: PySide.QtCore.uint

    Returns a colormap index for the color c, in ColorIndex mode. Used by qglColor() and qglClearColor().

    PySide.QtOpenGL.QGLContext. create ( [ shareContext=None ] )
    参数: shareContext PySide.QtOpenGL.QGLContext
    返回类型: PySide.QtCore.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).

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

    shareContext points to a valid PySide.QtOpenGL.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 。使用 PySide.QtOpenGL.QGLContext.isSharing() to see if sharing is in effect.

    警告

    Implementation note: initialization of C++ class members usually takes place in the class constructor. PySide.QtOpenGL.QGLContext is an exception because it must be simple to customize. The virtual functions PySide.QtOpenGL.QGLContext.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 PySide.QtOpenGL.QGLContext.create() 函数。

    static PySide.QtOpenGL.QGLContext. currentContext ( )
    返回类型: PySide.QtOpenGL.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.

    PySide.QtOpenGL.QGLContext. deleteTexture ( tx_id )
    参数: tx_id PySide.QtOpenGL.GLuint

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

    PySide.QtOpenGL.QGLContext. device ( )
    返回类型: PySide.QtGui.QPaintDevice

    Returns the paint device set for this context.

    另请参阅

    QGLContext.QGLContext()

    PySide.QtOpenGL.QGLContext. deviceIsPixmap ( )
    返回类型: PySide.QtCore.bool

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

    PySide.QtOpenGL.QGLContext. doneCurrent ( )

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

    PySide.QtOpenGL.QGLContext. drawTexture ( target , textureId [ , textureTarget=0x0DE1 ] )
    参数:
    • target PySide.QtCore.QRectF
    • textureId PySide.QtOpenGL.GLuint
    • textureTarget PySide.QtOpenGL.GLenum

    This function supports the following use cases:

    • 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.
    PySide.QtOpenGL.QGLContext. drawTexture ( point , textureId [ , textureTarget=0x0DE1 ] )
    参数:

    This function supports the following use cases:

    • 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.

    注意

    This function is not supported under any version of OpenGL ES.

    PySide.QtOpenGL.QGLContext. format ( )
    返回类型: PySide.QtOpenGL.QGLFormat

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

    PySide.QtOpenGL.QGLContext. getProcAddress ( proc )
    参数: proc – unicode
    返回类型: void

    Returns a function pointer to the GL extension function passed in proc . 0 is returned if a pointer to the function could not be obtained.

    PySide.QtOpenGL.QGLContext. initialized ( )
    返回类型: PySide.QtCore.bool

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

    PySide.QtOpenGL.QGLContext. isSharing ( )
    返回类型: PySide.QtCore.bool

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

    PySide.QtOpenGL.QGLContext. isValid ( )
    返回类型: PySide.QtCore.bool

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

    PySide.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.

    PySide.QtOpenGL.QGLContext. overlayTransparentColor ( )
    返回类型: PySide.QtGui.QColor

    If this context is a valid context in an overlay plane, returns the plane's transparent color. Otherwise returns an { QColor.isValid() }{invalid} color.

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

    PySide.QtOpenGL.QGLContext. requestedFormat ( )
    返回类型: PySide.QtOpenGL.QGLFormat

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

    PySide.QtOpenGL.QGLContext. reset ( )

    Resets the context and makes it invalid.

    PySide.QtOpenGL.QGLContext. setDevice ( pDev )
    参数: pDev PySide.QtGui.QPaintDevice
    PySide.QtOpenGL.QGLContext. setFormat ( format )
    参数: format PySide.QtOpenGL.QGLFormat

    设置 format for this context. The context is PySide.QtOpenGL.QGLContext.reset() .

    调用 PySide.QtOpenGL.QGLContext.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
    										
    PySide.QtOpenGL.QGLContext. setInitialized ( on )
    参数: on PySide.QtCore.bool

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

    static PySide.QtOpenGL.QGLContext. setTextureCacheLimit ( size )
    参数: size PySide.QtCore.int

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

    By default, the cache limit is approximately 64 MB.

    PySide.QtOpenGL.QGLContext. setValid ( valid )
    参数: valid PySide.QtCore.bool

    Forces the GL rendering context to be valid.

    PySide.QtOpenGL.QGLContext. setWindowCreated ( on )
    参数: on PySide.QtCore.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.

    PySide.QtOpenGL.QGLContext. swapBuffers ( )

    Swaps the screen contents with an off-screen buffer. Only works if the context is in double buffer mode.

    static PySide.QtOpenGL.QGLContext. textureCacheLimit ( )
    返回类型: PySide.QtCore.int

    Returns the current texture cache limit in kilobytes.

    PySide.QtOpenGL.QGLContext. updatePaintDevice ( )
    PySide.QtOpenGL.QGLContext. windowCreated ( )
    返回类型: PySide.QtCore.bool

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