Qyoto  4.0.6
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtOpenGL.QGLContext Class Reference

The QGLContext class encapsulates an OpenGL rendering context. More...

Inheritance diagram for QtOpenGL.QGLContext:
Collaboration diagram for QtOpenGL.QGLContext:

Public Types

enum  BindOption {
  CanFlipNativePixmapBindOption = 32, DefaultBindOption = 11, InternalBindOption = 20, InvertedYBindOption = 1,
  LinearFilteringBindOption = 8, MemoryManagedBindOption = 16, MipmapBindOption = 2, NoBindOption = 0,
  PremultipliedAlphaBindOption = 4
}
  More...
 

Public Member Functions

 QGLContext (QGLFormat format)
 
 
 QGLContext (QGLFormat format, IQPaintDevice device)
 
 
virtual void CreateProxy ()
 
new uint BindTexture (QImage image)
 
 
new uint BindTexture (QPixmap pixmap)
 
 
new uint BindTexture (QImage image, int target)
 
 
new uint BindTexture (QPixmap pixmap, int target)
 
 
new uint BindTexture (QImage image, int target, int format)
 
 
new uint BindTexture (QPixmap pixmap, int target, int format)
 
 
new uint BindTexture (QImage image, int target, int format, QGLContext.BindOption options)
 
 
new uint BindTexture (QPixmap pixmap, int target, int format, QGLContext.BindOption options)
 
 
new uint BindTexture (string fileName)
 
 
virtual bool Create (QGLContext shareContext=null)
 
 
new void DeleteTexture (uint tx_id)
 
 
virtual void DoneCurrent ()
 
 
new void DrawTexture (QRectF target, uint textureId)
 
 
new void DrawTexture (QPointF point, uint textureId)
 
 
new void DrawTexture (QRectF target, uint textureId, int textureTarget)
 
 
new void DrawTexture (QPointF point, uint textureId, int textureTarget)
 
 
virtual void MakeCurrent ()
 
 
new void Reset ()
 
 
virtual void SwapBuffers ()
 
 
new void Dispose ()
 

Static Public Member Functions

static bool AreSharing (QGLContext context1, QGLContext context2)
 
 

Protected Member Functions

 QGLContext (System.Type dummy)
 
virtual bool ChooseContext (QGLContext shareContext=null)
 
 
new uint ColorIndex (QColor c)
 
new void GenerateFontDisplayLists (QFont fnt, int listBase)
 
 
new void SetValid (bool valid)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

IQPaintDevice Device [get, set]
 
 
QGLFormat Format [get, set]
 
 
bool Initialized [get, set]
 
 
static int TextureCacheLimit [get, set]
 
 
bool WindowCreated [get, set]
 
 
static QGLContext CurrentContext [get]
 
 
bool DeviceIsPixmap [get]
 
 
bool IsSharing [get]
 
 
bool IsValid [get]
 
 
QColor OverlayTransparentColor [get]
 
 
QGLFormat RequestedFormat [get]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
static new QGLContext CurrentCtx [get, set]
 

Detailed Description

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.

Member Enumeration Documentation

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

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.

Enumerator:
CanFlipNativePixmapBindOption 
DefaultBindOption 

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

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

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.

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

NoBindOption 

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

PremultipliedAlphaBindOption 

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

Constructor & Destructor Documentation

QtOpenGL.QGLContext.QGLContext ( System.Type  dummy)
protected
QtOpenGL.QGLContext.QGLContext ( QGLFormat  format)

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.

See also format() and isValid().

QtOpenGL.QGLContext.QGLContext ( QGLFormat  format,
IQPaintDevice  device 
)

Constructs an OpenGL context for the given paint device, which can be a widget or a pixmap. The format 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.

Member Function Documentation

static bool QtOpenGL.QGLContext.AreSharing ( QGLContext  context1,
QGLContext  context2 
)
static

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

This function was introduced in Qt 4.6.

new uint QtOpenGL.QGLContext.BindTexture ( QImage  image)

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() calls.

This is an overloaded function.

new uint QtOpenGL.QGLContext.BindTexture ( QPixmap  pixmap)

This is an overloaded function.

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

new uint QtOpenGL.QGLContext.BindTexture ( QImage  image,
int  target 
)

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() calls.

This is an overloaded function.

new uint QtOpenGL.QGLContext.BindTexture ( QPixmap  pixmap,
int  target 
)

This is an overloaded function.

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

new uint QtOpenGL.QGLContext.BindTexture ( QImage  image,
int  target,
int  format 
)

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() calls.

This is an overloaded function.

new uint QtOpenGL.QGLContext.BindTexture ( QPixmap  pixmap,
int  target,
int  format 
)

This is an overloaded function.

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

new uint QtOpenGL.QGLContext.BindTexture ( QImage  image,
int  target,
int  format,
QGLContext.BindOption  options 
)

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() calls.

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.

This function was introduced in Qt 4.6.

See also deleteTexture().

new uint QtOpenGL.QGLContext.BindTexture ( QPixmap  pixmap,
int  target,
int  format,
QGLContext.BindOption  options 
)

This is an overloaded function.

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

This function was introduced in Qt 4.6.

new uint QtOpenGL.QGLContext.BindTexture ( string  fileName)

This is an overloaded function.

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.

See also deleteTexture().

virtual bool QtOpenGL.QGLContext.ChooseContext ( QGLContext  shareContext = null)
protectedvirtual

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.

new uint QtOpenGL.QGLContext.ColorIndex ( QColor  c)
protected
virtual bool QtOpenGL.QGLContext.Create ( QGLContext  shareContext = null)
virtual

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.

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.

See also chooseContext(), format(), and isValid().

virtual void QtOpenGL.QGLContext.CreateProxy ( )
virtual
new void QtOpenGL.QGLContext.DeleteTexture ( uint  tx_id)

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

See also bindTexture().

new void QtOpenGL.QGLContext.Dispose ( )
virtual void QtOpenGL.QGLContext.DoneCurrent ( )
virtual

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

new void QtOpenGL.QGLContext.DrawTexture ( QRectF  target,
uint  textureId 
)

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.

This function was introduced in Qt 4.4.

new void QtOpenGL.QGLContext.DrawTexture ( QPointF  point,
uint  textureId 
)

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.

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

This function was introduced in Qt 4.4.

new void QtOpenGL.QGLContext.DrawTexture ( QRectF  target,
uint  textureId,
int  textureTarget 
)

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.

This function was introduced in Qt 4.4.

new void QtOpenGL.QGLContext.DrawTexture ( QPointF  point,
uint  textureId,
int  textureTarget 
)

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.

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

This function was introduced in Qt 4.4.

new void QtOpenGL.QGLContext.GenerateFontDisplayLists ( QFont  fnt,
int  listBase 
)
protected

Generates a set of 256 display lists for the 256 first characters in the font font. The first list will start at index listBase.

See also QGLWidget::renderText().

virtual void QtOpenGL.QGLContext.MakeCurrent ( )
virtual

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.

new void QtOpenGL.QGLContext.Reset ( )

Resets the context and makes it invalid.

See also create() and isValid().

new void QtOpenGL.QGLContext.SetValid ( bool  valid)
protected
virtual void QtOpenGL.QGLContext.SwapBuffers ( )
virtual

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

See also QGLFormat::setDoubleBuffer().

Member Data Documentation

SmokeInvocation QtOpenGL.QGLContext.interceptor
protected

Property Documentation

QGLContext QtOpenGL.QGLContext.CurrentContext
staticget

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

See also makeCurrent().

new QGLContext QtOpenGL.QGLContext.CurrentCtx
staticgetsetprotected
IQPaintDevice QtOpenGL.QGLContext.Device
getset

Returns the paint device set for this context.

bool QtOpenGL.QGLContext.DeviceIsPixmap
get

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

QGLFormat QtOpenGL.QGLContext.Format
getset

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

Sets a format for this context. The context is reset.

Call 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

bool QtOpenGL.QGLContext.Initialized
getset

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

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

bool QtOpenGL.QGLContext.IsSharing
get

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.

bool QtOpenGL.QGLContext.IsValid
get

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

QColor QtOpenGL.QGLContext.OverlayTransparentColor
get

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

QGLFormat QtOpenGL.QGLContext.RequestedFormat
get

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

See also format().

virtual System.IntPtr QtOpenGL.QGLContext.SmokeObject
getset
int QtOpenGL.QGLContext.TextureCacheLimit
staticgetset

Returns the current texture cache limit in kilobytes.

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

By default, the cache limit is approximately 64 MB.

bool QtOpenGL.QGLContext.WindowCreated
getset

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

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