screenshot: Use the new matrix API

This makes the screenshot effect work when the scene is using
dynamically generated shaders.
This commit is contained in:
Fredrik Höglund 2014-04-01 18:09:02 +02:00
parent d2cb9f9bf6
commit e30b1212b6
2 changed files with 6 additions and 28 deletions

View file

@ -128,9 +128,13 @@ void ScreenShotEffect::postPaintScreen()
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
setMatrix(offscreenTexture->width(), offscreenTexture->height());
QMatrix4x4 projection;
projection.ortho(QRect(0, 0, offscreenTexture->width(), offscreenTexture->height()));
d.setProjectionMatrix(projection);
effects->drawWindow(m_scheduledScreenshot, mask, infiniteRegion(), d);
restoreMatrix();
// copy content from framebuffer into image
img = QImage(QSize(width, height), QImage::Format_ARGB32);
glReadnPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, img.byteCount(), (GLvoid*)img.bits());
@ -174,30 +178,6 @@ void ScreenShotEffect::postPaintScreen()
}
}
static QMatrix4x4 s_origProjection;
static QMatrix4x4 s_origModelview;
void ScreenShotEffect::setMatrix(int width, int height)
{
QMatrix4x4 projection;
QMatrix4x4 identity;
projection.ortho(QRect(0, 0, width, height));
ShaderBinder binder(ShaderManager::GenericShader);
GLShader *shader = binder.shader();
s_origProjection = shader->getUniformMatrix4x4("projection");
s_origModelview = shader->getUniformMatrix4x4("modelview");
shader->setUniform(GLShader::ProjectionMatrix, projection);
shader->setUniform(GLShader::ModelViewMatrix, identity);
}
void ScreenShotEffect::restoreMatrix()
{
ShaderBinder binder(ShaderManager::GenericShader);
GLShader *shader = binder.shader();
shader->setUniform(GLShader::ProjectionMatrix, s_origProjection);
shader->setUniform(GLShader::ModelViewMatrix, s_origModelview);
}
void ScreenShotEffect::screenshotWindowUnderCursor(int mask)
{
m_type = (ScreenShotType)mask;

View file

@ -84,8 +84,6 @@ private Q_SLOTS:
private:
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
QString blitScreenshot(const QRect &geometry);
void setMatrix(int width, int height);
void restoreMatrix();
EffectWindow *m_scheduledScreenshot;
ScreenShotType m_type;
};