Commit 65f5ed9e authored by Adrian Page's avatar Adrian Page

Start to make the OpenGL canvas work. It now displays the image but doesn't update or

scroll properly.


svn path=/trunk/koffice/; revision=648673
parent aac97d1d
......@@ -117,6 +117,7 @@ void KisCanvas2::createQPainterCanvas()
m_d->openGLImageContext = 0;
#endif
setCanvasWidget( new KisQPainterCanvas( this, m_d->view ) );
m_d->currentCanvasIsOpenGL = false;
}
void KisCanvas2::createCanvas()
......
......@@ -67,7 +67,7 @@ public:
};
KisOpenGLCanvas2::KisOpenGLCanvas2( KisCanvas2 * canvas, QWidget * parent, KisOpenGLImageContextSP context )
: QGLWidget( QGLFormat(QGL::SampleBuffers), parent )
: QGLWidget( QGLFormat(QGL::SampleBuffers), parent, context->sharedContextWidget() )
{
m_d = new Private();
m_d->canvas = canvas;
......@@ -92,8 +92,8 @@ void KisOpenGLCanvas2::initializeGL()
{
qglClearColor(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0));
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
//glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
}
void KisOpenGLCanvas2::resizeGL(int w, int h)
......@@ -119,6 +119,19 @@ void KisOpenGLCanvas2::paintGL()
if ( !img ) return;
QRect vr = QRect(0, 0, width(), height());
// Zoom factor
double sx, sy;
m_d->viewConverter->zoom(&sx, &sy);
// Resolution
double pppx,pppy;
pppx = img->xRes();
pppy = img->yRes();
// Compute the scale factors
double scaleX = sx / pppx;
double scaleY = sy / pppy;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width(), height());
......@@ -137,20 +150,6 @@ void KisOpenGLCanvas2::paintGL()
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
// Zoom factor
double sx, sy;
m_d->viewConverter->zoom(&sx, &sy);
// Resolution
double pppx,pppy;
pppx = img->xRes();
pppy = img->yRes();
// Compute the scale factors
double scaleX = sx / pppx;
double scaleY = sy / pppy;
glTexCoord2f((img->width() * scaleX) / KisOpenGLImageContext::BACKGROUND_TEXTURE_WIDTH, 0.0);
glVertex2f(img->width() * scaleX, 0.0);
......
......@@ -161,7 +161,7 @@ QGLWidget *KisOpenGLImageContext::sharedContextWidget() const
void KisOpenGLImageContext::updateImageTextureTiles(const QRect& rect)
{
//kDebug(41007) << "updateImageTextureTiles " << rect << endl;
kDebug(41001) << "updateImageTextureTiles " << rect << endl;
QRect updateRect = rect & m_image->bounds();
......@@ -190,8 +190,8 @@ void KisOpenGLImageContext::updateImageTextureTiles(const QRect& rect)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
QImage tileUpdateImage = m_image->convertToQImage(tileUpdateRect.left(), tileUpdateRect.top(),
tileUpdateRect.right(), tileUpdateRect.bottom(),
QImage tileUpdateImage = m_image->convertToQImage(tileUpdateRect.x(), tileUpdateRect.y(),
tileUpdateRect.width(), tileUpdateRect.height(),
m_monitorProfile, m_exposure);
if (m_displaySelection) {
......@@ -205,13 +205,13 @@ void KisOpenGLImageContext::updateImageTextureTiles(const QRect& rect)
if (tileUpdateRect.width() == m_imageTextureTileWidth && tileUpdateRect.height() == m_imageTextureTileHeight) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_imageTextureTileWidth, m_imageTextureTileHeight, 0,
GL_BGRA, GL_UNSIGNED_BYTE, QGLWidget::convertToGLFormat( tileUpdateImage ).bits());
GL_BGRA, GL_UNSIGNED_BYTE, tileUpdateImage.bits());
} else {
int xOffset = tileUpdateRect.x() - tileRect.x();
int yOffset = tileUpdateRect.y() - tileRect.y();
glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, tileUpdateRect.width(), tileUpdateRect.height(),
GL_BGRA, GL_UNSIGNED_BYTE, QGLWidget::convertToGLFormat( tileUpdateImage ).bits());
GL_BGRA, GL_UNSIGNED_BYTE, tileUpdateImage.bits());
}
GLenum error = glGetError ();
......
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