The QGLContext class encapsulates an OpenGL rendering context. 更多...
| 头: | #include <QGLContext> |
| enum | BindOption { NoBindOption, InvertedYBindOption, MipmapBindOption, PremultipliedAlphaBindOption, LinearFilteringBindOption, DefaultBindOption } |
| flags | BindOptions |
| QGLContext (const QGLFormat & format ) | |
| virtual | ~QGLContext () |
| GLuint | bindTexture (const QImage & image , GLenum target , GLint format , BindOptions options ) |
| GLuint | bindTexture (const QString & fileName ) |
| GLuint | bindTexture (const QImage & image , GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA) |
| GLuint | bindTexture (const QPixmap & pixmap , GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA) |
| GLuint | bindTexture (const QPixmap & pixmap , GLenum target , GLint format , BindOptions options ) |
| virtual bool | create (const QGLContext * shareContext = 0) |
| void | deleteTexture (GLuint id ) |
| QPaintDevice * | device () const |
| virtual void | doneCurrent () |
| void | drawTexture (const QRectF & target , GLuint textureId , GLenum textureTarget = GL_TEXTURE_2D) |
| void | drawTexture (const QPointF & point , GLuint textureId , GLenum textureTarget = GL_TEXTURE_2D) |
| QGLFormat | format () const |
| void * | getProcAddress (const QString & proc ) const |
| bool | isSharing () const |
| bool | isValid () const |
| virtual void | makeCurrent () |
| QColor | overlayTransparentColor () const |
| QGLFormat | requestedFormat () const |
| void | reset () |
| void | setFormat (const QGLFormat & format ) |
| virtual void | swapBuffers () const |
| bool | areSharing (const QGLContext * context1 , const QGLContext * context2 ) |
| const QGLContext * | currentContext () |
| QGLContext * | fromPlatformGLContext (QPlatformGLContext * platformContext ) |
| void | setTextureCacheLimit (int size ) |
| int | textureCacheLimit () |
| virtual bool | chooseContext (const QGLContext * shareContext = 0) |
| virtual void * | chooseMacVisual (GDHandle handle ) |
| virtual int | choosePixelFormat (void * dummyPfd , HDC pdc ) |
| virtual void * | chooseVisual () |
| bool | deviceIsPixmap () const |
| bool | initialized () const |
| void | setInitialized (bool on ) |
| void | setWindowCreated (bool on ) |
| bool | windowCreated () const |
The 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 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() 函数。 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 () 和 overlayTransparentColor ().
If you're using double buffering you can swap the screen contents with the off-screen buffer using swapBuffers ().
请注意 QGLContext 不是 thread-safe .
A set of options to decide how to bind a texture using bindTexture ().
| 常量 | 值 | 描述 |
|---|---|---|
QGLContext::NoBindOption
|
0x0000
|
Don't do anything, pass the texture straight through. |
QGLContext::InvertedYBindOption
|
0x0001
|
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
|
0x0002
|
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
目标。
|
QGLContext::PremultipliedAlphaBindOption
|
0x0004
|
Specifies that the image should be uploaded with premultiplied alpha and does a conversion accordingly. |
QGLContext::LinearFilteringBindOption
|
0x0008
|
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
|
LinearFilteringBindOption | InvertedYBindOption | MipmapBindOption
|
In Qt 4.5 and earlier, 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 引入或被修改。
The BindOptions type is a typedef for QFlags <BindOption>. It stores an OR combination of BindOption values.
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 format () method will return the actual format obtained.
Note that after a QGLContext object has been constructed, 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.
[虚拟]
QGLContext::
~QGLContext
()
销毁 OpenGL context and frees its resources.
[static]
bool
QGLContext::
areSharing
(const
QGLContext
*
context1
, const
QGLContext
*
context2
)
返回 true 若 context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
该函数在 Qt 4.6 引入。
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()
调用。
The
target
parameter specifies the texture target. The default target is
GL_TEXTURE_2D
.
The
format
parameter sets the internal format for the texture. The default format is
GL_RGBA
.
The binding options are a set of options used to decide how to bind the texture to the context.
The texture that is generated is cached, so multiple calls to bindTexture() with the same QImage will return the same texture id.
Note that we assume default values for the glPixelStore() and glPixelTransfer() parameters.
该函数在 Qt 4.6 引入。
另请参阅 deleteTexture ().
这是重载函数。
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 ().
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()
调用。
这是重载函数。
这是重载函数。
Generates and binds a 2D GL texture based on pixmap .
这是重载函数。
Generates and binds a 2D GL texture to the current context, based on pixmap .
该函数在 Qt 4.6 引入。
[virtual protected]
bool
QGLContext::
chooseContext
(const
QGLContext
*
shareContext
= 0)
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.
[virtual protected]
void
* QGLContext::
chooseMacVisual
(
GDHandle
handle
)
Mac OS X only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met.
The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has spcific requirements on visual selection.
The handle argument is always zero and is not used
另请参阅 chooseContext ().
[virtual protected]
int
QGLContext::
choosePixelFormat
(
void
*
dummyPfd
,
HDC
pdc
)
Win32 only: This virtual function chooses a pixel format that matches the OpenGL format . Reimplement this function in a subclass if you need a custom context.
警告:
The
dummyPfd
pointer and
pdc
are used as a
PIXELFORMATDESCRIPTOR*
. We use
void
to avoid using Windows-specific types in our header files.
另请参阅 chooseContext ().
[virtual protected]
void
* QGLContext::
chooseVisual
()
X11 only: This virtual function tries to find a visual that matches the format, reducing the demands if the original request cannot be met.
The algorithm for reducing the demands of the format is quite simple-minded, so override this method in your subclass if your application has spcific requirements on visual selection.
另请参阅 chooseContext ().
[虚拟]
bool
QGLContext::
create
(const
QGLContext
*
shareContext
= 0)
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, 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 create() function.
另请参阅 chooseContext (), format (),和 isValid ().
[static]
const
QGLContext
* QGLContext::
currentContext
()
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 ().
Removes the texture identified by id from the texture cache, and calls glDeleteTextures() to delete the texture from the context.
另请参阅 bindTexture ().
Returns the paint device set for this context.
另请参阅 QGLContext::QGLContext ().
[protected]
bool
QGLContext::
deviceIsPixmap
() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
[虚拟]
void
QGLContext::
doneCurrent
()
Makes no GL context the current context. Normally, you do not need to call this function; QGLContext calls it as necessary.
This function supports the following use cases:
该函数在 Qt 4.4 引入。
This function supports the following use cases:
注意: This function is not supported under any version of OpenGL ES.
该函数在 Qt 4.4 引入。
Returns the frame buffer format that was obtained (this may be a subset of what was requested).
另请参阅 setFormat () 和 requestedFormat ().
[static]
QGLContext
* QGLContext::
fromPlatformGLContext
(
QPlatformGLContext
*
platformContext
)
返回 OpenGL context for the platform-specific OpenGL context given by platformContext .
该函数在 Qt 4.8 引入。
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.
[protected]
bool
QGLContext::
initialized
() const
Returns true if this context has been initialized, i.e. if QGLWidget::initializeGL () has been performed on it; otherwise returns false.
另请参阅 setInitialized ().
Returns 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.
Returns true if a GL rendering context has been successfully created; otherwise returns false.
[虚拟]
void
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 this context is a valid context in an overlay plane, returns the plane's transparent color. Otherwise returns an { QColor::isValid ()}{invalid} color.
返回的 QColor object will generally work as expected only when passed as the argument to QGLWidget::qglColor () 或 QGLWidget::qglClearColor (). Under certain circumstances it can also be used to draw transparent graphics with a QPainter .
Returns the frame buffer format that was originally requested in the constructor or setFormat ().
另请参阅 format ().
Resets the context and makes it invalid.
设置 format for this context. The context is reset .
调用 create () to create a new GL context that tries to match the new format.
QGLContext *cx; // ... QGLFormat f; 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
另请参阅 format (), reset (),和 create ().
[protected]
void
QGLContext::
setInitialized
(
bool
on
)
若 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.
另请参阅 initialized ().
[static]
void
QGLContext::
setTextureCacheLimit
(
int
size
)
This function sets the limit for the texture cache to size , expressed in kilobytes.
By default, the cache limit is approximately 64 MB.
另请参阅 textureCacheLimit ().
[protected]
void
QGLContext::
setWindowCreated
(
bool
on
)
若 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 ().
[虚拟]
void
QGLContext::
swapBuffers
() const
Swaps the screen contents with an off-screen buffer. Only works if the context is in double buffer mode.
另请参阅 QGLFormat::setDoubleBuffer ().
[static]
int
QGLContext::
textureCacheLimit
()
Returns the current texture cache limit in kilobytes.
另请参阅 setTextureCacheLimit ().
[protected]
bool
QGLContext::
windowCreated
() const
Returns true if a window has been created for this context; otherwise returns false.
另请参阅 setWindowCreated ().