|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.opengl.QGLContext
public class QGLContext
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()
function. The makeCurrent()
function makes this context the current rendering context. You can make no context current using doneCurrent()
. The 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()
.
Please note that QGLContext is not thread safe.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QGLContext(QGLFormat format)
Constructs an OpenGL context with the given format which specifies several display options for the context. |
|
QGLContext(QGLFormat format,
QPaintDeviceInterface device)
Constructs an OpenGL context for the given paint device, which can be a widget or a pixmap. |
Method Summary | |
---|---|
int |
bindTexture(QImage image)
Generates and binds a 2D GL texture to the current context, based on image. |
int |
bindTexture(QImage image,
int target)
Generates and binds a 2D GL texture to the current context, based on image. |
int |
bindTexture(QImage image,
int target,
int format)
Generates and binds a 2D GL texture to the current context, based on image. |
int |
bindTexture(QPixmap pixmap)
Generates and binds a 2D GL texture based on pixmap. |
int |
bindTexture(QPixmap pixmap,
int target)
Generates and binds a 2D GL texture based on pixmap. |
int |
bindTexture(QPixmap pixmap,
int target,
int format)
Generates and binds a 2D GL texture based on pixmap. |
int |
bindTexture(java.lang.String fileName)
Reads the DirectDrawSurface (DDS) compressed file fileName and generates a 2D GL texture from it. |
protected boolean |
chooseContext()
This semi-internal function is called by create() . |
protected boolean |
chooseContext(QGLContext shareContext)
This semi-internal function is called by create() . |
boolean |
create()
Creates the GL context. |
boolean |
create(QGLContext shareContext)
Creates the GL context. |
static QGLContext |
currentContext()
Returns the current context, i. |
void |
deleteTexture(int tx_id)
Removes the texture identified by id from the texture cache. |
QPaintDeviceInterface |
device()
Returns the paint device set for this context. |
protected boolean |
deviceIsPixmap()
Returns true if the paint device of this context is a pixmap; otherwise returns false. |
void |
doneCurrent()
Makes no GL context the current context. |
void |
drawTexture(QPointF point,
int textureId)
Draws the given texture at the given point in OpenGL model space. |
void |
drawTexture(QPointF point,
int textureId,
int textureTarget)
Draws the given texture at the given point in OpenGL model space. |
void |
drawTexture(QRectF target,
int textureId)
Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. |
void |
drawTexture(QRectF target,
int textureId,
int textureTarget)
Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. |
QGLFormat |
format()
Returns the frame buffer format that was obtained (this may be a subset of what was requested). |
protected boolean |
initialized()
Returns true if this context has been initialized, i. |
boolean |
isSharing()
Returns true if this context is sharing its GL context with another QGLContext, otherwise false is returned. |
boolean |
isValid()
Returns true if a GL rendering context has been successfully created; otherwise returns false. |
void |
makeCurrent()
Makes this context the current OpenGL rendering context. |
QColor |
overlayTransparentColor()
If this context is a valid context in an overlay plane, returns the plane's transparent color. |
QGLFormat |
requestedFormat()
Returns the frame buffer format that was originally requested in the constructor or setFormat() . |
void |
reset()
Resets the context and makes it invalid. |
void |
setFormat(QGLFormat format)
Sets a format for this context. |
protected void |
setInitialized(boolean on)
If on is true the context has been initialized, i. |
static void |
setTextureCacheLimit(int size)
This function sets the limit for the texture cache to size, expressed in kilobytes. |
protected void |
setWindowCreated(boolean on)
If on is true the context has had a window created for it. |
void |
swapBuffers()
Swaps the screen contents with an off-screen buffer. |
static int |
textureCacheLimit()
Returns the current texture cache limit in kilobytes. |
protected boolean |
windowCreated()
Returns true if a window has been created for this context; otherwise returns false. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QGLContext(QGLFormat format)
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.
format()
, and isValid()
.
public QGLContext(QGLFormat format, QPaintDeviceInterface device)
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.
Method Detail |
---|
public final int bindTexture(QImage image, int target)
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_RGBA8.
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.
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.
deleteTexture()
.
public final int bindTexture(QImage image)
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_RGBA8.
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.
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.
deleteTexture()
.
public final int bindTexture(QImage image, int target, int format)
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_RGBA8.
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.
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.
deleteTexture()
.
public final int bindTexture(QPixmap pixmap, int target)
public final int bindTexture(QPixmap pixmap)
public final int bindTexture(QPixmap pixmap, int target, int format)
public final int bindTexture(java.lang.String fileName)
Only the DXT1, DXT3 and DXT5 DDS formats are supported.
Note that this will only work if the implementation supports the GL_ARB_texture_compression and GL_EXT_texture_compression_s3tc extensions.
deleteTexture()
.
public final void deleteTexture(int tx_id)
bindTexture()
.
public final QPaintDeviceInterface device()
protected final boolean deviceIsPixmap()
public final void drawTexture(QPointF point, int textureId)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QPointF point, int textureId, int textureTarget)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QRectF target, int textureId)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final void drawTexture(QRectF target, int textureId, int textureTarget)
Equivalent to the corresponding QGLContext::drawTexture()
.
public final QGLFormat format()
setFormat()
, and requestedFormat()
.
protected final boolean initialized()
QGLWidget::initializeGL()
has been performed on it; otherwise returns false. setInitialized()
.
public final boolean isSharing()
public final boolean isValid()
public final QColor overlayTransparentColor()
invalid
color. 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.)
The returned 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 QPainter
. See the examples/opengl/overlay_x11 example for details.
public final QGLFormat requestedFormat()
setFormat()
. format()
.
public final void reset()
create()
, and isValid()
.
public final void setFormat(QGLFormat format)
reset
. Call create()
to create a new GL context that tries to match the new format.
// ... QGLFormat f = new QGLFormat(); f.setStereo(true); QGLContext cx = new QGLContext(f); if (!cx.create()) throw new RuntimeException("No OpenGL support, or cannot render on the specified paintdevice."); if (!cx.format().stereo()) throw new RuntimeException("Could not create stereo context.");
format()
, reset()
, and create()
.
protected final void setInitialized(boolean on)
QGLContext::setInitialized()
has been called on it. If on is false the context has not been initialized. initialized()
.
protected final void setWindowCreated(boolean on)
windowCreated()
.
protected final boolean windowCreated()
setWindowCreated()
.
protected final boolean chooseContext()
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.
protected boolean chooseContext(QGLContext shareContext)
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.
public final boolean create()
After successful creation, format()
returns the set of features of the created GL rendering context.
If 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
. Use isSharing()
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 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()
, and isValid()
.
public boolean create(QGLContext shareContext)
After successful creation, format()
returns the set of features of the created GL rendering context.
If 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
. Use isSharing()
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 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()
, and isValid()
.
public void doneCurrent()
public void makeCurrent()
In some very rare cases the underlying call may fail. If this occurs an error message is output to stderr.
public void swapBuffers()
QGLFormat::setDoubleBuffer()
.
public static QGLContext currentContext()
makeCurrent()
.
public static void setTextureCacheLimit(int size)
By default, the cache limit is approximately 64 MB.
textureCacheLimit()
.
public static int textureCacheLimit()
setTextureCacheLimit()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |