Home · All Classes · Main Classes · Deprecated |
A singleton class for rendering textured quads with custom shaders. More...
Public Member Functions | |
virtual | ~MGLES2Renderer () |
QGLShaderProgram * | getShaderProgram (const QString &frag=QString(), const QString &vert=QString()) |
QGLShaderProgram * | compileShaderProgram (const QString &frag, const QString &vert) |
quint32 | bindX11Pixmap (Qt::HANDLE pixmap) |
void | unbindX11Pixmap (Qt::HANDLE pixmap) |
void | updateX11Pixmap (Qt::HANDLE pixmap) |
void | begin (QPainter *painter) |
void | begin (QPainter *painter, QGLShaderProgram *program) |
void | end () |
void | activateProgram (QGLShaderProgram *program) |
void | bindTexture (const QPixmap &pixmap, quint32 unit=0, const QString &uniformName=QString()) |
void | bindTexture (quint32 texId, const QSize &texSize=QSize(-1,-1), quint32 unit=0, const QString &uniformName=QString()) |
void | setInvertTexture (bool invert) |
void | draw (int x, int y, int width, int height) |
void | draw (int x, int y) |
void | draw (const QRect &rectangle) |
void | draw (const QList< QRect > &targets, const QList< QRect > &sources) |
void | draw (const QRect &target, const QRect &source) |
void | setViewportSize (const QSize &size) |
Static Public Member Functions | |
static MGLES2Renderer * | instance (QGLContext *glContext) |
static MGLES2Renderer * | instance (QGLWidget *glWidget) |
static MGLES2Renderer * | instance () |
static void | activate (QGLContext *glContext) |
static void | activate (QGLWidget *glWidget) |
static void | destroy (QGLContext *glContext) |
static void | destroy (QGLWidget *glWidget) |
static void | destroyAll () |
A singleton class for rendering textured quads with custom shaders.
MGLES2Renderer class implements and provides an easy interface for compiling and setuping glsl shaders. The class also provides functionality for rendering textured quads directly with GLES2. Class caches the compiled shaders so that they can used inside a process without always recompiling them. Following uniforms and attributes are considered default and they are initialized by the MGLES2Renderer class automatically:
//vertex shader variables attribute highp vec4 vertex; //object space vertex coordinate attribute lowp vec2 texCoord; //texture coordinates of the vertex uniform highp mat4 matProj; //projection matrix uniform highp mat4 matWorld; //world transformation matrix uniform highp vec2 invSize; //inversed size of rendered quad //fragment shader variables uniform sampler2D textureX; //textures for each texture unit (eg. texture0, texture1 ...)
virtual MGLES2Renderer::~MGLES2Renderer | ( | ) | [virtual] |
Destructor.
void MGLES2Renderer::activate | ( | QGLContext * | glContext | ) | [static] |
Activates a renderer for the specified QGLContext.
If the renderer for the specified glContext does not yet exist it will be created and initialized.
MWindow is responsible for setting the active renderer automatically when the framework is drawing into it. Widgets should not call this method manually.
void MGLES2Renderer::activate | ( | QGLWidget * | glWidget | ) | [static] |
void MGLES2Renderer::activateProgram | ( | QGLShaderProgram * | program | ) |
Activate a program and program specific data.
void MGLES2Renderer::begin | ( | QPainter * | painter | ) |
Begin painting with MGLES2Renderer using default program.
If painter is not NULL, renderer will extract opacity and transformation and use those when rendering pixmaps into screen. The renderer will also cache the current state of the painter, the state will be restored when calling the end() method.
After calling this method you can still change the opacity and transformation from the painter and they will be taken into account when drawing pixmaps.
void MGLES2Renderer::begin | ( | QPainter * | painter, | |
QGLShaderProgram * | program | |||
) |
Begin painting with MGLES2Renderer using the specified program.
If NULL is given as program, program needs to manually activated by calling activateProgram().
void MGLES2Renderer::bindTexture | ( | const QPixmap & | pixmap, | |
quint32 | unit = 0 , |
|||
const QString & | uniformName = QString() | |||
) |
Bind pixmap as texture.
Bind pixmap to wanted texture unit and shader uniform. By default the pixmaps are bound to shaders using "textureN" as the uniform name, where N equals to unit.
Size of pixmap bound to the unit 0, will be used when drawing textures with drawing methods.
void MGLES2Renderer::bindTexture | ( | quint32 | texId, | |
const QSize & | texSize = QSize(-1, -1) , |
|||
quint32 | unit = 0 , |
|||
const QString & | uniformName = QString() | |||
) |
Bind texture.
Bind texId to wanted texture unit and shader uniform. By default the pixmaps are bound to shaders using "textureN" as the uniform name, where N equals to unit.
Optional texture size can be given as parameter, inversion of it will be given to shaders if they want to use it (uniform name == "invSize"). Only size given when binding unit 0 is used. The texture size is also needed by some of the drawing methods.
quint32 MGLES2Renderer::bindX11Pixmap | ( | Qt::HANDLE | pixmap | ) |
Bind an X pixmap as a texture.
Uses the Nokia texture from pixmap extension to ensure that same pixmap in memory is used as a texture. Returns a texture id that can be drawn with drawTexture() or in later glBindTexture() calls. The texture that is generated is cached, so multiple calls to bindPixmap() with the same X pixmap will return the same texture id. Ideally, this function should be called once as soon as the pixmap id is obtained. Before drawing the contents of the texture, ensure updateX11Pixmap() is called to update its contents.
pixmap | specifies the X pixmap to be bound as a texture |
QGLShaderProgram * MGLES2Renderer::compileShaderProgram | ( | const QString & | frag, | |
const QString & | vert | |||
) |
Compile and link a shader program.
Compiles the specified shader source files and links the objects to a shader program. No caching takes place at this point and a new shader program is always created. Application code should generally call getShaderProgram() instead of this method.
frag | Filename of the fragment shader source | |
vert | Filename of the vertex shader source |
void MGLES2Renderer::destroy | ( | QGLWidget * | glWidget | ) | [static] |
void MGLES2Renderer::destroy | ( | QGLContext * | glContext | ) | [static] |
Destroys a renderer of the specified QGLContext.
The glContext is not destroyed by this method.
void MGLES2Renderer::destroyAll | ( | ) | [static] |
Destroys all the renderer instances.
void MGLES2Renderer::draw | ( | int | x, | |
int | y | |||
) |
Draw texture.
Draws the bound texture(s) at position (x, y). The size that was given as parameter to bindTexture() will be used as width and height.
void MGLES2Renderer::draw | ( | int | x, | |
int | y, | |||
int | width, | |||
int | height | |||
) |
Draw texture.
Draws the bound texture(s) into the rectangle at position (x, y) with the given width and height.
Draw texture.
Draws multiple patches of texture(s) sources into the given targets.
The size that was given as parameter to bindTexture() will be used for calculating the texture coordinates from the source rectangles.
Draw texture.
Draws the rectangular portion source of the bound texture(s) into the given target rectangle.
The size that was given as parameter to bindTexture() will be used for calculating the texture coordinates from the source rectangle.
void MGLES2Renderer::draw | ( | const QRect & | rectangle | ) |
Draw texture.
Draws the bound texture(s) into the given rectangle.
void MGLES2Renderer::end | ( | ) |
Restores to a state that was before calling begin().
QGLShaderProgram * MGLES2Renderer::getShaderProgram | ( | const QString & | frag = QString() , |
|
const QString & | vert = QString() | |||
) |
Fetch a shader program by its source file names.
If the group of shaders does not include a vertex shader or fragment shader a default one is added.
frag | Filename of the fragment shader source | |
vert | Filename of the vertex shader source |
MGLES2Renderer * MGLES2Renderer::instance | ( | QGLWidget * | glWidget | ) | [static] |
MGLES2Renderer * MGLES2Renderer::instance | ( | ) | [static] |
Returns instance of MGLES2Renderer which was previously set active.
Returns NULL if no renderer has been set active.
In normal cases widgets should call this method when they need instance of the renderer. MWindow is responsible for activating a renderer. If the method returns NULL, it usually means that SW rendering has been forcefully applied (or the current development environment does not support GLES2).
MGLES2Renderer * MGLES2Renderer::instance | ( | QGLContext * | glContext | ) | [static] |
Returns instance of MGLES2Renderer object for the specified QGLContext.
If the renderer for the specified glContext does not yet exist it will be created and initialized.
Renderer object is created automatically for each MWindow if SW rendering is enabled.
void MGLES2Renderer::setInvertTexture | ( | bool | invert | ) |
void MGLES2Renderer::setViewportSize | ( | const QSize & | size | ) |
Set the viewport size.
By default the viewport size is defined by the viewport widget (screen size), but for example when rendering into a texture using FBO the viewport size must be set manually to match the FBO size.
The viewport size will be reset to screen size when calling the end() method. Viewport size can be reset manually by giving QSize(-1,-1) as parameter.
QSize | Size of the viewport. |
void MGLES2Renderer::unbindX11Pixmap | ( | Qt::HANDLE | pixmap | ) |
Unbind the texture from an X pixmap.
Deletes the texture cache as well. Call this to free the resources of the pixmap bound as a texture
pixmap | specifies the X pixmap to be bound as a texture |
void MGLES2Renderer::updateX11Pixmap | ( | Qt::HANDLE | pixmap | ) |
Updates the contents of bound X pixmap. Call this every time the contents of the pixmap changes i.e. from X Damage events.
pixmap | specifies the X pixmap to be bound as a texture |
Copyright © 2010 Nokia Corporation | MeeGo Touch |