Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGLContext Class

TheQGLContext class encapsulates anOpenGL rendering context.More...

Header:#include <QGLContext>

Public Types

enumBindOption { NoBindOption, InvertedYBindOption, MipmapBindOption, PremultipliedAlphaBindOption, LinearFilteringBindOption, DefaultBindOption }
flagsBindOptions

Public Functions

QGLContext(const QGLFormat & format)
virtual~QGLContext()
GLuintbindTexture(const QImage & image, GLenum target, GLint format, BindOptions options)
GLuintbindTexture(const QString & fileName)
GLuintbindTexture(const QImage & image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA)
GLuintbindTexture(const QPixmap & pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA)
GLuintbindTexture(const QPixmap & pixmap, GLenum target, GLint format, BindOptions options)
virtual boolcreate(const QGLContext * shareContext = 0)
voiddeleteTexture(GLuint id)
QPaintDevice *device() const
virtual voiddoneCurrent()
voiddrawTexture(const QRectF & target, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D)
voiddrawTexture(const QPointF & point, GLuint textureId, GLenum textureTarget = GL_TEXTURE_2D)
QGLFormatformat() const
void *getProcAddress(const QString & proc) const
boolisSharing() const
boolisValid() const
virtual voidmakeCurrent()
QColoroverlayTransparentColor() const
QGLFormatrequestedFormat() const
voidreset()
voidsetFormat(const QGLFormat & format)
virtual voidswapBuffers() const

Static Public Members

boolareSharing(const QGLContext * context1, const QGLContext * context2)
const QGLContext *currentContext()
QGLContext *fromPlatformGLContext(QPlatformGLContext * platformContext)
voidsetTextureCacheLimit(int size)
inttextureCacheLimit()

Protected Functions

virtual boolchooseContext(const QGLContext * shareContext = 0)
virtual void *chooseMacVisual(GDHandle handle)
virtual intchoosePixelFormat(void * dummyPfd, HDC pdc)
virtual void *chooseVisual()
booldeviceIsPixmap() const
boolinitialized() const
voidsetInitialized(bool on)
voidsetWindowCreated(bool on)
boolwindowCreated() const

Detailed Description

TheQGLContext class encapsulates anOpenGL rendering context.

AnOpenGL rendering context is a complete set ofOpenGL state variables. The rendering context'sformat is set in the constructor, but it can also be set later withsetFormat(). The format options that are actually set are returned byformat(); the options you asked for are returned byrequestedFormat(). Note that after aQGLContext object has been constructed, the actualOpenGL context must be created by explicitly calling thecreate() function. ThemakeCurrent() function makes this context the current rendering context. You can makeno context current usingdoneCurrent(). Thereset() function will reset the context and make it invalid.

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

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

Please note thatQGLContext is notthread-safe.

Member Type Documentation

enum QGLContext::BindOption
flags QGLContext::BindOptions

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

ConstantValueDescription
QGLContext::NoBindOption0x0000Don't do anything, pass the texture straight through.
QGLContext::InvertedYBindOption0x0001Specifies 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::MipmapBindOption0x0002Specifies thatbindTexture() should try to generate mipmaps. If the GL implementation supports theGL_SGIS_generate_mipmap extension, mipmaps will be automatically generated for the texture. Mipmap generation is only supported for theGL_TEXTURE_2D target.
QGLContext::PremultipliedAlphaBindOption0x0004Specifies that the image should be uploaded with premultiplied alpha and does a conversion accordingly.
QGLContext::LinearFilteringBindOption0x0008Specifies 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::DefaultBindOptionLinearFilteringBindOption | InvertedYBindOption | MipmapBindOptionIn 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.

This enum was introduced or modified in Qt 4.6.

The BindOptions type is a typedef forQFlags<BindOption>. It stores an OR combination of BindOption values.

Member Function Documentation

QGLContext::QGLContext(constQGLFormat & format)

Constructs anOpenGL context with the givenformat which specifies several display options for the context.

If the underlyingOpenGL/Window system cannot satisfy all the features requested informat, the nearest subset of features will be used. After creation, theformat() method will return the actual format obtained.

Note that after aQGLContext object has been constructed,create() must be called explicitly to create the actualOpenGL context. The context will beinvalid if it was not possible to obtain a GL context at all.

See alsoformat() andisValid().

[virtual]QGLContext::~QGLContext()

Destroys theOpenGL context and frees its resources.

[static]bool QGLContext::areSharing(constQGLContext * context1, constQGLContext * context2)

Returns true ifcontext1 andcontext2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.

This function was introduced in Qt 4.6.

GLuint QGLContext::bindTexture(constQImage & image,GLenum target,GLint format,BindOptions options)

Generates and binds a 2D GL texture to the current context, based onimage. The generated texture id is returned and can be used in laterglBindTexture() calls.

Thetarget parameter specifies the texture target. The default target isGL_TEXTURE_2D.

Theformat parameter sets the internal format for the texture. The default format isGL_RGBA.

The bindingoptions 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 sameQImage will return the same texture id.

Note that we assume default values for the glPixelStore() and glPixelTransfer() parameters.

This function was introduced in Qt 4.6.

See alsodeleteTexture().

GLuint QGLContext::bindTexture(constQString & fileName)

This is an overloaded function.

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

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

Since 4.6.1, textures in the ETC1 format can be loaded if theGL_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 theGL_IMG_texture_compression_pvrtc extension is supported.

See alsodeleteTexture().

GLuint QGLContext::bindTexture(constQImage & image,GLenum target = GL_TEXTURE_2D,GLint format = GL_RGBA)

Generates and binds a 2D GL texture to the current context, based onimage. The generated texture id is returned and can be used in laterglBindTexture() calls.

This is an overloaded function.

GLuint QGLContext::bindTexture(constQPixmap & pixmap,GLenum target = GL_TEXTURE_2D,GLint format = GL_RGBA)

This is an overloaded function.

Generates and binds a 2D GL texture based onpixmap.

GLuint QGLContext::bindTexture(constQPixmap & pixmap,GLenum target,GLint format,BindOptions options)

This is an overloaded function.

Generates and binds a 2D GL texture to the current context, based onpixmap.

This function was introduced in Qt 4.6.

[virtual protected]bool QGLContext::chooseContext(constQGLContext * shareContext = 0)

This semi-internal function is called bycreate(). It creates a system-dependentOpenGL handle that matches theformat() ofshareContext as closely as possible, returning true if successful or false if a suitable handle could not be found.

On Windows, it calls the virtual functionchoosePixelFormat(), which finds a matching pixel format identifier. On X11, it calls the virtual functionchooseVisual() 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.

Thehandle argument is always zero and is not used

See alsochooseContext().

[virtual protected]int QGLContext::choosePixelFormat(void * dummyPfd,HDC pdc)

Win32 only: This virtual function chooses a pixel format that matches theOpenGLformat. Reimplement this function in a subclass if you need a custom context.

Warning: ThedummyPfd pointer andpdc are used as aPIXELFORMATDESCRIPTOR*. We usevoid to avoid using Windows-specific types in our header files.

See alsochooseContext().

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

See alsochooseContext().

[virtual]bool QGLContext::create(constQGLContext * 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.

IfshareContext points to a validQGLContext, this method will try to establishOpenGL display list and texture object sharing between this context and theshareContext. Note that this may fail if the two contexts have differentformats. UseisSharing() to see if sharing is in effect.

Warning: 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 functionschooseContext() (andchooseVisual() 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.

See alsochooseContext(),format(), andisValid().

[static]constQGLContext * QGLContext::currentContext()

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

See alsomakeCurrent().

void QGLContext::deleteTexture(GLuint id)

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

See alsobindTexture().

QPaintDevice * QGLContext::device() const

Returns the paint device set for this context.

See alsoQGLContext::QGLContext().

[protected]bool QGLContext::deviceIsPixmap() const

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

[virtual]void QGLContext::doneCurrent()

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

void QGLContext::drawTexture(constQRectF & target,GLuint textureId,GLenum textureTarget = GL_TEXTURE_2D)

This function supports the following use cases:

  • OnOpenGL andOpenGL ES 1.x it draws the given texture,textureId, to the given target rectangle,target, inOpenGL model space. ThetextureTarget should be a 2D texture target.
  • OnOpenGL andOpenGL ES 2.x, if a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with typeQPaintEngine::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 underOpenGL ES 2.x.

This function was introduced in Qt 4.4.

void QGLContext::drawTexture(constQPointF & point,GLuint textureId,GLenum textureTarget = GL_TEXTURE_2D)

This function supports the following use cases:

  • By default it draws the given texture,textureId, at the givenpoint inOpenGL model space. ThetextureTarget should be a 2D texture target.
  • If a painter is active, not inside a beginNativePainting / endNativePainting block, and uses the engine with typeQPaintEngine::OpenGL2, the function will draw the given texture,textureId, at the givenpoint, 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:This function is not supported under any version ofOpenGL ES.

This function was introduced in Qt 4.4.

QGLFormat QGLContext::format() const

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

See alsosetFormat() andrequestedFormat().

[static]QGLContext * QGLContext::fromPlatformGLContext(QPlatformGLContext * platformContext)

Returns aOpenGL context for the platform-specificOpenGL context given byplatformContext.

This function was introduced in Qt 4.8.

void * QGLContext::getProcAddress(constQString & proc) const

Returns a function pointer to the GL extension function passed inproc. 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. ifQGLWidget::initializeGL() has been performed on it; otherwise returns false.

See alsosetInitialized().

bool QGLContext::isSharing() const

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

bool QGLContext::isValid() const

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

[virtual]void QGLContext::makeCurrent()

Makes this context the currentOpenGL 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.

QColor QGLContext::overlayTransparentColor() const

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

The returnedQColor object will generally work as expected only when passed as the argument toQGLWidget::qglColor() orQGLWidget::qglClearColor(). Under certain circumstances it can also be used to draw transparent graphics with aQPainter.

QGLFormat QGLContext::requestedFormat() const

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

See alsoformat().

void QGLContext::reset()

Resets the context and makes it invalid.

See alsocreate() andisValid().

void QGLContext::setFormat(constQGLFormat & format)

Sets aformat for this context. The context isreset.

Callcreate() 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 paintdeviceif (!cx->format().stereo())    exit();// could not create stereo context

See alsoformat(),reset(), andcreate().

[protected]void QGLContext::setInitialized(bool on)

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

See alsoinitialized().

[static]void QGLContext::setTextureCacheLimit(int size)

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

By default, the cache limit is approximately 64 MB.

See alsotextureCacheLimit().

[protected]void QGLContext::setWindowCreated(bool on)

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

See alsowindowCreated().

[virtual]void QGLContext::swapBuffers() const

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

See alsoQGLFormat::setDoubleBuffer().

[static]int QGLContext::textureCacheLimit()

Returns the current texture cache limit in kilobytes.

See alsosetTextureCacheLimit().

[protected]bool QGLContext::windowCreated() const

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

See alsosetWindowCreated().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp