Commit 55767a06 authored by Martin Flöser's avatar Martin Flöser
Browse files

Merge together paintBackground and paintGenericScreen

parent 19bc1f12
......@@ -218,6 +218,92 @@ bool SceneOpenGL::selfCheck()
return ok;
}
void SceneOpenGL::paintGenericScreen(int mask, ScreenPaintData data)
{
const bool useShader = ShaderManager::instance()->isValid();
if (mask & PAINT_SCREEN_TRANSFORMED) {
// apply screen transformations
QMatrix4x4 screenTransformation;
screenTransformation.translate(data.xTranslate, data.yTranslate, data.zTranslate);
if (data.rotation) {
screenTransformation.translate(data.rotation->xRotationPoint, data.rotation->yRotationPoint, data.rotation->zRotationPoint);
// translate to rotation point, rotate, translate back
qreal xAxis = 0.0;
qreal yAxis = 0.0;
qreal zAxis = 0.0;
switch (data.rotation->axis) {
case RotationData::XAxis:
xAxis = 1.0;
break;
case RotationData::YAxis:
yAxis = 1.0;
break;
case RotationData::ZAxis:
zAxis = 1.0;
break;
}
screenTransformation.rotate(data.rotation->angle, xAxis, yAxis, zAxis);
screenTransformation.translate(-data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint);
}
screenTransformation.scale(data.xScale, data.yScale, data.zScale);
if (useShader) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
shader->setUniform("screenTransformation", screenTransformation);
} else {
pushMatrix(screenTransformation);
}
} else if (useShader && ((mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS) || (mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS))) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
shader->setUniform("screenTransformation", QMatrix4x4());
}
Scene::paintGenericScreen(mask, data);
if (mask & PAINT_SCREEN_TRANSFORMED) {
if (useShader) {
ShaderManager::instance()->popShader();
} else {
popMatrix();
}
} else if (useShader && ((mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS) ||
(mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS))) {
ShaderManager::instance()->popShader();
}
}
void SceneOpenGL::paintBackground(QRegion region)
{
PaintClipper pc(region);
if (!PaintClipper::clip()) {
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
return;
}
if (pc.clip() && pc.paintArea().isEmpty())
return; // no background to paint
QVector<float> verts;
for (PaintClipper::Iterator iterator; !iterator.isDone(); iterator.next()) {
QRect r = iterator.boundingRect();
verts << r.x() + r.width() << r.y();
verts << r.x() << r.y();
verts << r.x() << r.y() + r.height();
verts << r.x() << r.y() + r.height();
verts << r.x() + r.width() << r.y() + r.height();
verts << r.x() + r.width() << r.y();
}
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setUseColor(true);
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
const bool useShader = ShaderManager::instance()->isValid();
if (useShader) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
shader->setUniform("offset", QVector2D(0, 0));
}
vbo->render(GL_TRIANGLES);
if (useShader) {
ShaderManager::instance()->popShader();
}
}
void SceneOpenGL::windowAdded( Toplevel* c )
{
assert( !windows.contains( c ));
......
......@@ -215,77 +215,6 @@ void SceneOpenGL::flushBuffer( int mask, QRegion damage )
XFlush( display());
}
void SceneOpenGL::paintGenericScreen(int mask, ScreenPaintData data)
{
if (mask & PAINT_SCREEN_TRANSFORMED) {
// apply screen transformations
QMatrix4x4 screenTransformation;
screenTransformation.translate(data.xTranslate, data.yTranslate, data.zTranslate);
if (data.rotation) {
screenTransformation.translate(data.rotation->xRotationPoint, data.rotation->yRotationPoint, data.rotation->zRotationPoint);
// translate to rotation point, rotate, translate back
qreal xAxis = 0.0;
qreal yAxis = 0.0;
qreal zAxis = 0.0;
switch (data.rotation->axis) {
case RotationData::XAxis:
xAxis = 1.0;
break;
case RotationData::YAxis:
yAxis = 1.0;
break;
case RotationData::ZAxis:
zAxis = 1.0;
break;
}
screenTransformation.rotate(data.rotation->angle, xAxis, yAxis, zAxis);
screenTransformation.translate(-data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint);
}
screenTransformation.scale(data.xScale, data.yScale, data.zScale);
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
shader->setUniform("screenTransformation", screenTransformation);
} else if ((mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS) || (mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS)) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader);
shader->setUniform("screenTransformation", QMatrix4x4());
}
Scene::paintGenericScreen(mask, data);
if ((mask & PAINT_SCREEN_TRANSFORMED) ||
(mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS) ||
(mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS)) {
ShaderManager::instance()->popShader();
}
}
void SceneOpenGL::paintBackground(QRegion region)
{
PaintClipper pc(region);
if (!PaintClipper::clip()) {
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
return;
}
if (pc.clip() && pc.paintArea().isEmpty())
return; // no background to paint
QVector<float> verts;
for (PaintClipper::Iterator iterator; !iterator.isDone(); iterator.next()) {
QRect r = iterator.boundingRect();
verts << r.x() + r.width() << r.y();
verts << r.x() << r.y();
verts << r.x() << r.y() + r.height();
verts << r.x() << r.y() + r.height();
verts << r.x() + r.width() << r.y() + r.height();
verts << r.x() + r.width() << r.y();
}
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setUseColor(true);
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
shader->setUniform("offset", QVector2D(0, 0));
vbo->render(GL_TRIANGLES);
ShaderManager::instance()->popShader();
}
//****************************************
// SceneOpenGL::Texture
//****************************************
......
......@@ -702,73 +702,6 @@ void SceneOpenGL::flushBuffer( int mask, QRegion damage )
}
}
void SceneOpenGL::paintGenericScreen( int mask, ScreenPaintData data )
{
if( mask & PAINT_SCREEN_TRANSFORMED )
{ // apply screen transformations
glPushMatrix();
glTranslatef( data.xTranslate, data.yTranslate, data.zTranslate );
if( data.rotation )
{
// translate to rotation point, rotate, translate back
glTranslatef( data.rotation->xRotationPoint, data.rotation->yRotationPoint, data.rotation->zRotationPoint );
float xAxis = 0.0;
float yAxis = 0.0;
float zAxis = 0.0;
switch( data.rotation->axis )
{
case RotationData::XAxis:
xAxis = 1.0;
break;
case RotationData::YAxis:
yAxis = 1.0;
break;
case RotationData::ZAxis:
zAxis = 1.0;
break;
}
glRotatef( data.rotation->angle, xAxis, yAxis, zAxis );
glTranslatef( -data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint );
}
glScalef( data.xScale, data.yScale, data.zScale );
}
Scene::paintGenericScreen( mask, data );
if( mask & PAINT_SCREEN_TRANSFORMED )
{
glPopMatrix();
}
}
void SceneOpenGL::paintBackground( QRegion region )
{
PaintClipper pc( region );
if( !PaintClipper::clip())
{
glPushAttrib( GL_COLOR_BUFFER_BIT );
glClearColor( 0, 0, 0, 1 ); // black
glClear( GL_COLOR_BUFFER_BIT );
glPopAttrib();
return;
}
if( pc.clip() && pc.paintArea().isEmpty())
return; // no background to paint
glPushAttrib( GL_CURRENT_BIT );
glColor4f( 0, 0, 0, 1 ); // black
for( PaintClipper::Iterator iterator;
!iterator.isDone();
iterator.next())
{
glBegin( GL_QUADS );
QRect r = iterator.boundingRect();
glVertex2i( r.x(), r.y());
glVertex2i( r.x() + r.width(), r.y());
glVertex2i( r.x() + r.width(), r.y() + r.height());
glVertex2i( r.x(), r.y() + r.height());
glEnd();
}
glPopAttrib();
}
//****************************************
// SceneOpenGL::Texture
//****************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment