[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-kimageshop
Subject: Re: [calligra/krita-opengl2-rempt] krita: Also show the image properly.
From: Dmitry Kazakov <dimula73 () gmail ! com>
Date: 2013-05-18 7:31:42
Message-ID: CAEkBSfV1yhJeXMAWoAA_O00t5xGG_gN+u0N6H21P64tM520LRQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I have Linux Mint in VirtualBox.
On Sat, May 18, 2013 at 11:22 AM, Boudewijn Rempt <boud@valdyas.org> wrote:
> Yes, it doesn't work on Windows yet -- but it should work with all gpu's
> on Linux. It's weird, because Visual Studio's debugger stops in the
> infinity manager's event handler, while gdebugger just hands trying to
> debug the issue.
>
>
> On Sat, 18 May 2013, Dmitry Kazakov wrote:
>
> Hi, Boud!
> >
> > It still crashes on Virtual Box. I'm going to check it on old intel GMA
> > without Virtual Box, but a bit later.
> >
> > On Thu, May 16, 2013 at 6:07 PM, Boudewijn Rempt <boud@valdyas.org>
> > wrote:
> > Git commit 33fbffea6c44747336e6aeb09fed68**612854f61e by Boudewijn
> > Rempt.
> > Committed on 16/05/2013 at 15:59.
> > Pushed by rempt into branch 'krita-opengl2-rempt'.
> >
> > Also show the image properly.
> >
> > CCMAIL:kimageshop@kde.org
> >
> > Please, everyone who has a different gpu from me, build this branch
> > and test painting, zooming, panning, everything. Checkout the
> > krita-opengl2-rempt branch
> >
> > We can now also start testing on windows and osx...
> >
> > TODO:
> >
> > * reintegrate OCIO (which was fragment-only)
> > * move the texture updating to a separate thread
> > * move the canvas rendering to a separate thread
> > * integrate with krita sketch, somehow
> > * reimplement the opengl cursor outline
> > * reimplement the gradient shaders (perhaps? Not sure how useful
> > they were.)
> > * reimplement the 3d cursors (low prio -- they were fun, but I
> > guess no
> > pro artist used them)
> > * figure out a way to move the layerstack composition to the GPU?
> >
> > M +4 -1 krita/data/shaders/display.**frag
> > M +47 -148 krita/ui/opengl/kis_opengl_**canvas2.cpp
> > M +0 -19 krita/ui/opengl/kis_opengl_**canvas2.h
> > M +4 -0 krita/ui/opengl/kis_texture_**tile.h
> >
> > http://commits.kde.org/**calligra/**33fbffea6c44747336e6aeb09fed68*
> > *612854f61e<http://commits.kde.org/calligra/33fbffea6c44747336e6aeb09fed68612854f61e>
> >
> > diff --git a/krita/data/shaders/display.**frag
> > b/krita/data/shaders/display.**frag
> > index 36c5aca..cd8462b 100644
> > --- a/krita/data/shaders/display.**frag
> > +++ b/krita/data/shaders/display.**frag
> > @@ -1,6 +1,9 @@
> > +/*
> > + * shader for handling scaling
> > + */
> > uniform sampler2D texture0;
> >
> > -varying vec4 v_textureCoordinate;
> > +varying mediump vec4 v_textureCoordinate;
> >
> > void main() {
> > gl_FragColor = texture2D(texture0, v_textureCoordinate.st);
> > diff --git a/krita/ui/opengl/kis_opengl_**canvas2.cpp
> > b/krita/ui/opengl/kis_opengl_**canvas2.cpp
> > index 8369a4b..e4eea83 100644
> > --- a/krita/ui/opengl/kis_opengl_**canvas2.cpp
> > +++ b/krita/ui/opengl/kis_opengl_**canvas2.cpp
> > @@ -78,24 +78,18 @@ public:
> > Private()
> > > displayShader(0)
> > , checkerShader(0)
> > - , vertexBuffer(0)
> > - , indexBuffer(0)
> > {
> > }
> >
> > ~Private() {
> > delete displayShader;
> > delete checkerShader;
> > - delete vertexBuffer;
> > - delete indexBuffer;
> > }
> >
> > KisOpenGLImageTexturesSP openGLImageTextures;
> >
> > QGLShaderProgram *displayShader;
> > QGLShaderProgram *checkerShader;
> > - QGLBuffer *vertexBuffer;
> > - QGLBuffer *indexBuffer;
> > };
> >
> > KisOpenGLCanvas2::**KisOpenGLCanvas2(KisCanvas2 *canvas,
> > KisCoordinatesConverter
> > *coordinatesConverter, QWidget *parent, KisOpenGLImageTexturesSP
> > imageTextures)
> > @@ -180,7 +174,7 @@ void KisOpenGLCanvas2::paintEvent(**QPaintEvent
> > *)
> > glClear(GL_COLOR_BUFFER_BIT);
> >
> > drawCheckers();
> > - //drawImage();
> > + drawImage();
> >
> > QRect boundingRect = coordinatesConverter()->**
> > imageRectInWidgetPixels().**toAlignedRect();
> >
> > @@ -263,65 +257,71 @@ void KisOpenGLCanvas2::drawImage()
> >
> > KisCoordinatesConverter *converter = coordinatesConverter();
> >
> > - QRectF widgetRect(0,0, width(), height());
> > - QRectF widgetRectInImagePixels =
> > converter->documentToImage(**converter->widgetToDocument(**
> > widgetRect));
> > -
> > - qreal scaleX, scaleY;
> > - converter->imageScale(&**scaleX, &scaleY);
> > -
> > - QRect wr = widgetRectInImagePixels.**toAlignedRect() &
> > - m_d->openGLImageTextures->**storedImageBounds();
> > -
> > m_d->displayShader->bind();
> >
> > - QVector3D imageSize(m_d->**openGLImageTextures->**
> > storedImageBounds().width(),
> > - m_d->openGLImageTextures->**
> > storedImageBounds().height(),
> > - 0.f);
> > -
> > - QMatrix4x4 model;//(modelTransform);
> > - m_d->displayShader->**setUniformValue("modelMatrix", model);
> > - model.scale(imageSize * scaleX);
> > + QMatrix4x4 projectionMatrix;
> > + projectionMatrix.**setToIdentity();
> > + projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL,
> > FAR_VAL);
> >
> > - //Set view/projection matrices
> > - QMatrix4x4 view;//(textureTransform);
> > - m_d->displayShader->**setUniformValue("viewMatrix", view);
> > + // Set view/projection matrices
> > + QMatrix4x4 modelMatrix(**coordinatesConverter()->**
> > imageToWidgetTransform());
> > + modelMatrix.optimize();
> > + modelMatrix = projectionMatrix * modelMatrix;
> > + m_d->displayShader->**setUniformValue("**modelViewProjection",
> > modelMatrix);
> >
> > -// QMatrix4x4 textureMatrix;//(**textureTransform);
> > -// m_d->checkerShader->**setUniformValue("**textureMatrix",
> > textureMatrix);
> > + QMatrix4x4 textureMatrix;
> > + textureMatrix.setToIdentity()**;
> > + m_d->displayShader->**setUniformValue("**textureMatrix",
> > textureMatrix);
> >
> > - //Setup the geometry for rendering
> > - m_d->vertexBuffer->bind();
> > - m_d->indexBuffer->bind();
> > + QRectF widgetRect(0,0, width(), height());
> > + QRectF widgetRectInImagePixels =
> > converter->documentToImage(**converter->widgetToDocument(**
> > widgetRect));
> >
> > - m_d->displayShader->**setAttributeBuffer("a_**vertexPosition",
> > GL_FLOAT, 0, 3);
> > - m_d->displayShader->**enableAttributeArray("a_**
> > vertexPosition");
> > - m_d->displayShader->**setAttributeBuffer("a_**texturePosition",
> > GL_FLOAT, 12 * sizeof(float), 2);
> > - m_d->displayShader->**enableAttributeArray("a_**
> > vertexPosition");
> > - m_d->displayShader->**setUniformValue("texture0", 0);
> > + qreal scaleX, scaleY;
> > + converter->imageScale(&**scaleX, &scaleY);
> >
> > - // m_d->openGLImageTextures->**
> > activateHDRExposureProgram();
> > + QRect wr = widgetRectInImagePixels.**toAlignedRect() &
> > m_d->openGLImageTextures->**storedImageBounds();
> >
> > int firstColumn = m_d->openGLImageTextures->**
> > xToCol(wr.left());
> > int lastColumn = m_d->openGLImageTextures->**
> > xToCol(wr.right());
> > int firstRow = m_d->openGLImageTextures->**yToRow(wr.top());
> > int lastRow = m_d->openGLImageTextures->**yToRow(wr.bottom());
> >
> > - QMatrix4x4 proj;
> > - proj.ortho(0, 0, width(), height(), NEAR_VAL, FAR_VAL);
> > - m_d->displayShader->**setUniformValue("**projectionMatrix",
> > proj);
> > -
> > for (int col = firstColumn; col <= lastColumn; col++) {
> > for (int row = firstRow; row <= lastRow; row++) {
> >
> > KisTextureTile *tile =
> > m_d->openGLImageTextures->**getTextureTileCR(col,
> > row);
> >
> > - //QRectF textureRect(tile->**
> > tileRectInTexturePixels());
> > + /*
> > + * We create a float rect here to workaround Qt's
> > + * "history reasons" in calculation of right()
> > + * and bottom() coordinates of integer rects.
> > + */
> > + QRectF textureRect(tile->**tileRectInTexturePixels());
> > QRectF modelRect(tile->**tileRectInImagePixels());
> >
> > - model.translate(modelRect.x()**, -modelRect.y());
> > - model.scale(modelRect.width()**, modelRect.height());
> > - m_d->displayShader->**setUniformValue("modelMatrix",
> > model);
> > + //Setup the geometry for rendering
> > + QVector<QVector3D> vertices;
> > + vertices << QVector3D(modelRect.left(),
> > modelRect.bottom(), 0.f)
> > + << QVector3D(modelRect.left(),
> > modelRect.top(), 0.f)
> > + << QVector3D(modelRect.right(),
> > modelRect.bottom(), 0.f)
> > + << QVector3D(modelRect.left(),
> > modelRect.top(), 0.f)
> > + << QVector3D(modelRect.right(),
> > modelRect.top(), 0.f)
> > + << QVector3D(modelRect.right(),
> > modelRect.bottom(), 0.f);
> > +
> > + m_d->displayShader->**enableAttributeArray(PROGRAM_**
> > VERTEX_ATTRIBUTE);
> > + m_d->displayShader->**setAttributeArray(PROGRAM_**VERTEX_ATTRIBUTE,
> > vertices.constData());
> > +
> > + QVector<QVector2D> texCoords;
> > + texCoords << QVector2D(textureRect.left(),
> > textureRect.bottom())
> > + << QVector2D(textureRect.left(),
> > textureRect.top())
> > + << QVector2D(textureRect.right(),
> > textureRect.bottom())
> > + << QVector2D(textureRect.left(),
> > textureRect.top())
> > + << QVector2D(textureRect.right(),
> > textureRect.top())
> > + << QVector2D(textureRect.right(),
> > textureRect.bottom());
> > +
> > + m_d->displayShader->**enableAttributeArray(PROGRAM_**
> > TEXCOORD_ATTRIBUTE);
> > + m_d->displayShader->**setAttributeArray(PROGRAM_**
> > TEXCOORD_ATTRIBUTE,
> > texCoords.constData());
> >
> > glBindTexture(GL_TEXTURE_2D, tile->textureId());
> >
> > @@ -331,57 +331,16 @@ void KisOpenGLCanvas2::drawImage()
> > glTexParameteri(GL_TEXTURE_**2D,
> > GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> > }
> >
> > - glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
> > + glDrawArrays(GL_TRIANGLES, 0, 6);
> >
> > }
> > }
> >
> > // m_d->openGLImageTextures->**
> > deactivateHDRExposureProgram()**;
> > -
> > - m_d->vertexBuffer->release();
> > - m_d->indexBuffer->release();
> > + glBindTexture(GL_TEXTURE_2D, 0);
> > m_d->displayShader->release()**;
> > }
> >
> > -void KisOpenGLCanvas2::saveGLState(**)
> > -{
> > - // Q_ASSERT(!m_d->GLStateSaved);
> > -
> > - // if (!m_d->GLStateSaved) {
> > - // m_d->GLStateSaved = true;
> > -
> > - // glPushAttrib(GL_ALL_ATTRIB_**BITS);
> > - // glMatrixMode(GL_PROJECTION);
> > - // glPushMatrix();
> > - // glMatrixMode(GL_TEXTURE);
> > - // glPushMatrix();
> > - // glMatrixMode(GL_MODELVIEW);
> > - // glPushMatrix();
> > -
> > - // glGetIntegerv(GL_CURRENT_**PROGRAM,
> > &m_d->savedCurrentProgram);
> > - // glUseProgram(NO_PROGRAM);
> > - // }
> > -}
> > -
> > -void KisOpenGLCanvas2::**restoreGLState()
> > -{
> > - // Q_ASSERT(m_d->GLStateSaved);
> > -
> > - // if (m_d->GLStateSaved) {
> > - // m_d->GLStateSaved = false;
> > -
> > - // glMatrixMode(GL_PROJECTION);
> > - // glPopMatrix();
> > - // glMatrixMode(GL_TEXTURE);
> > - // glPopMatrix();
> > - // glMatrixMode(GL_MODELVIEW);
> > - // glPopMatrix();
> > - // glPopAttrib();
> > -
> > - // glUseProgram(m_d->**savedCurrentProgram);
> > - // }
> > -}
> > -
> > void KisOpenGLCanvas2::**initializeShaders()
> > {
> >
> > @@ -406,68 +365,8 @@ void KisOpenGLCanvas2::**initializeShaders()
> > qDebug() << "OpenGL error" << glGetError();
> > qFatal("Failed linking display shader");
> > }
> > -
> > - m_d->vertexBuffer = new QGLBuffer(QGLBuffer::**VertexBuffer);
> > - m_d->vertexBuffer->create();
> > - m_d->vertexBuffer->bind();
> > -
> > - QVector<float> vertices;
> > - /*
> > - * 0.0, 1.0 ---- 1.0, 1.0
> > - * | |
> > - * | |
> > - * 0.0, 0.0 ---- 1.0, 0.0
> > - */
> > - vertices << 0.0f << 0.0f << 0.0f;
> > - vertices << 0.0f << 1.0f << 0.0f;
> > - vertices << 1.0f << 0.0f << 0.0f;
> > - vertices << 1.0f << 1.0f << 0.0f;
> > - int vertSize = sizeof(float) * vertices.count();
> > -
> > - // coordinates to convert vertex points to a position in the
> > texture. Follows order of corner
> > - // points in vertices
> > - QVector<float> uvs;
> > - uvs << 0.f << 0.f;
> > - uvs << 0.f << 1.f;
> > - uvs << 1.f << 0.f;
> > - uvs << 1.f << 1.f;
> > - int uvSize = sizeof(float) * uvs.count();
> > -
> > - m_d->vertexBuffer->allocate(**vertSize + uvSize);
> > - m_d->vertexBuffer->write(0, reinterpret_cast<void*>(**vertices.data()),
> > vertSize);
> > - m_d->vertexBuffer->write(**vertSize,
> > reinterpret_cast<void*>(uvs.**data()), uvSize);
> > - m_d->vertexBuffer->release();
> > -
> > - m_d->indexBuffer = new QGLBuffer(QGLBuffer::**IndexBuffer);
> > - m_d->indexBuffer->create();
> > - m_d->indexBuffer->bind();
> > -
> > - QVector<uint> indices;
> > - // determines where opengl looks for vertex data. create two
> > clockwise triangles from
> > - // the points.
> > - /*
> > - * 1->-3
> > - * |\ |
> > - * ^ \ v
> > - * | \|
> > - * 0...2
> > - */
> > - indices << 0 << 1 << 2 << 1 << 3 << 2;
> > - m_d->indexBuffer->allocate(**reinterpret_cast<void*>(**indices.data()),
> > indices.size() *
> > sizeof(uint));
> > - m_d->indexBuffer->release();
> > -}
> > -
> > -void KisOpenGLCanvas2::beginOpenGL(**void)
> > -{
> > - // saveGLState();
> > }
> >
> > -void KisOpenGLCanvas2::endOpenGL(**void)
> > -{
> > - // restoreGLState();
> > -}
> > -
> > -
> > void KisOpenGLCanvas2::**slotConfigChanged()
> > {
> > notifyConfigChanged();
> > diff --git a/krita/ui/opengl/kis_opengl_**canvas2.h
> > b/krita/ui/opengl/kis_opengl_**canvas2.h
> > index 4f76dde..40f5438 100644
> > --- a/krita/ui/opengl/kis_opengl_**canvas2.h
> > +++ b/krita/ui/opengl/kis_opengl_**canvas2.h
> > @@ -56,22 +56,6 @@ public:
> >
> > virtual ~KisOpenGLCanvas2();
> >
> > - /**
> > - * Prepare the canvas for rendering using native OpenGL
> > - * commands. This sets the projection and model view matrices
> > so
> > - * that primitives can be rendered using coordinates returned
> > - * from pixelToView().
> > - */
> > - void beginOpenGL();
> > -
> > - /**
> > - * Notify the canvas that rendering using native OpenGL
> > commands
> > - * has finished. This restores the state so that the canvas can
> > - * be painted on using a QPainter.
> > - */
> > - void endOpenGL();
> > -
> > -
> > public: // QWidget
> >
> > /// reimplemented method from superclass
> > @@ -108,9 +92,6 @@ private:
> > void drawCheckers();
> >
> > void initializeShaders();
> > -
> > - void saveGLState();
> > - void restoreGLState();
> > };
> >
> > #endif // HAVE_OPENGL
> > diff --git a/krita/ui/opengl/kis_texture_**tile.h
> > b/krita/ui/opengl/kis_texture_**tile.h
> > index 9a3517e..60fd6f6 100644
> > --- a/krita/ui/opengl/kis_texture_**tile.h
> > +++ b/krita/ui/opengl/kis_texture_**tile.h
> > @@ -74,6 +74,10 @@ public:
> > return m_textureRectInImagePixels;
> > }
> >
> > + inline QRectF tileRectInTexturePixels() {
> > + return m_tileRectInTexturePixels;
> > + }
> > +
> > private:
> > void repeatStripes(const KisTextureTileUpdateInfo &updateInfo);
> >
> > ______________________________**_________________
> > Krita mailing list
> > kimageshop@kde.org
> > https://mail.kde.org/mailman/**listinfo/kimageshop<https://mail.kde.org/mailman/listinfo/kimageshop>
> >
> >
> >
> >
> > --
> > Dmitry Kazakov
> >
>
> _______________________________________________
> Krita mailing list
> kimageshop@kde.org
> https://mail.kde.org/mailman/listinfo/kimageshop
>
>
--
Dmitry Kazakov
[Attachment #5 (text/html)]
I have Linux Mint in VirtualBox.<br><br><div class="gmail_quote">On Sat, May 18, 2013 \
at 11:22 AM, Boudewijn Rempt <span dir="ltr"><<a href="mailto:boud@valdyas.org" \
target="_blank">boud@valdyas.org</a>></span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Yes, it doesn't work on Windows yet -- but it should work \
with all gpu's on Linux. It's weird, because Visual Studio's debugger \
stops in the infinity manager's event handler, while gdebugger just hands trying \
to debug the issue.<div class="HOEnZb"> <div class="h5"><br>
<br>
On Sat, 18 May 2013, Dmitry Kazakov wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> Hi, Boud!<br>
<br>
It still crashes on Virtual Box. I'm going to check it on old intel GMA without \
Virtual Box, but a bit later.<br> <br>
On Thu, May 16, 2013 at 6:07 PM, Boudewijn Rempt <<a \
href="mailto:boud@valdyas.org" \
target="_blank">boud@valdyas.org</a>> wrote:<br>
Git commit 33fbffea6c44747336e6aeb09fed68<u></u>612854f61e by Boudewijn \
Rempt.<br> Committed on 16/05/2013 at 15:59.<br>
Pushed by rempt into branch 'krita-opengl2-rempt'.<br>
<br>
Also show the image properly.<br>
<br>
<a href="mailto:CCMAIL%3Akimageshop@kde.org" \
target="_blank">CCMAIL:kimageshop@kde.org</a><br> <br>
Please, everyone who has a different gpu from me, build this branch<br>
and test painting, zooming, panning, everything. Checkout the<br>
krita-opengl2-rempt branch<br>
<br>
We can now also start testing on windows and osx...<br>
<br>
TODO:<br>
<br>
* reintegrate OCIO (which was fragment-only)<br>
* move the texture updating to a separate thread<br>
* move the canvas rendering to a separate thread<br>
* integrate with krita sketch, somehow<br>
* reimplement the opengl cursor outline<br>
* reimplement the gradient shaders (perhaps? Not sure how useful they \
were.)<br>
* reimplement the 3d cursors (low prio -- they were fun, but I guess no<br>
pro artist used them)<br>
* figure out a way to move the layerstack composition to the GPU?<br>
<br>
M +4 -1 krita/data/shaders/display.<u></u>frag<br>
M +47 -148 krita/ui/opengl/kis_opengl_<u></u>canvas2.cpp<br>
M +0 -19 krita/ui/opengl/kis_opengl_<u></u>canvas2.h<br>
M +4 -0 krita/ui/opengl/kis_texture_<u></u>tile.h<br>
<br>
<a href="http://commits.kde.org/calligra/33fbffea6c44747336e6aeb09fed68612854f61e" \
target="_blank">http://commits.kde.org/<u></u>calligra/<u></u>33fbffea6c44747336e6aeb09fed68<u></u>612854f61e</a><br>
<br>
diff --git a/krita/data/shaders/display.<u></u>frag \
b/krita/data/shaders/display.<u></u>frag<br> index 36c5aca..cd8462b 100644<br>
--- a/krita/data/shaders/display.<u></u>frag<br>
+++ b/krita/data/shaders/display.<u></u>frag<br>
@@ -1,6 +1,9 @@<br>
+/*<br>
+ * shader for handling scaling<br>
+ */<br>
uniform sampler2D texture0;<br>
<br>
-varying vec4 v_textureCoordinate;<br>
+varying mediump vec4 v_textureCoordinate;<br>
<br>
void main() {<br>
gl_FragColor = texture2D(texture0, v_textureCoordinate.st);<br>
diff --git a/krita/ui/opengl/kis_opengl_<u></u>canvas2.cpp \
b/krita/ui/opengl/kis_opengl_<u></u>canvas2.cpp<br> index 8369a4b..e4eea83 \
100644<br>
--- a/krita/ui/opengl/kis_opengl_<u></u>canvas2.cpp<br>
+++ b/krita/ui/opengl/kis_opengl_<u></u>canvas2.cpp<br>
@@ -78,24 +78,18 @@ public:<br>
Private()<br>
: displayShader(0)<br>
, checkerShader(0)<br>
- , vertexBuffer(0)<br>
- , indexBuffer(0)<br>
{<br>
}<br>
<br>
~Private() {<br>
delete displayShader;<br>
delete checkerShader;<br>
- delete vertexBuffer;<br>
- delete indexBuffer;<br>
}<br>
<br>
KisOpenGLImageTexturesSP openGLImageTextures;<br>
<br>
QGLShaderProgram *displayShader;<br>
QGLShaderProgram *checkerShader;<br>
- QGLBuffer *vertexBuffer;<br>
- QGLBuffer *indexBuffer;<br>
};<br>
<br>
KisOpenGLCanvas2::<u></u>KisOpenGLCanvas2(KisCanvas2 *canvas, \
KisCoordinatesConverter<br>
*coordinatesConverter, QWidget *parent, KisOpenGLImageTexturesSP \
imageTextures)<br>
@@ -180,7 +174,7 @@ void KisOpenGLCanvas2::paintEvent(<u></u>QPaintEvent \
*)<br> glClear(GL_COLOR_BUFFER_BIT);<br>
<br>
drawCheckers();<br>
- //drawImage();<br>
+ drawImage();<br>
<br>
QRect boundingRect = \
coordinatesConverter()-><u></u>imageRectInWidgetPixels().<u></u>toAlignedRect();<br>
<br>
@@ -263,65 +257,71 @@ void KisOpenGLCanvas2::drawImage()<br>
<br>
KisCoordinatesConverter *converter = coordinatesConverter();<br>
<br>
- QRectF widgetRect(0,0, width(), height());<br>
- QRectF widgetRectInImagePixels =<br>
converter->documentToImage(<u></u>converter->widgetToDocument(<u></u>widgetRect));<br>
-<br>
- qreal scaleX, scaleY;<br>
- converter->imageScale(&<u></u>scaleX, &scaleY);<br>
-<br>
- QRect wr = widgetRectInImagePixels.<u></u>toAlignedRect() &<br>
- \
m_d->openGLImageTextures-><u></u>storedImageBounds();<br>
-<br>
m_d->displayShader->bind();<br>
<br>
- QVector3D \
imageSize(m_d-><u></u>openGLImageTextures-><u></u>storedImageBounds().width(),<br>
- \
m_d->openGLImageTextures-><u></u>storedImageBounds().height(),<br>
- 0.f);<br>
-<br>
- QMatrix4x4 model;//(modelTransform);<br>
- m_d->displayShader-><u></u>setUniformValue("modelMatrix", \
model);<br>
- model.scale(imageSize * scaleX);<br>
+ QMatrix4x4 projectionMatrix;<br>
+ projectionMatrix.<u></u>setToIdentity();<br>
+ projectionMatrix.ortho(0, width(), height(), 0, NEAR_VAL, \
FAR_VAL);<br> <br>
- //Set view/projection matrices<br>
- QMatrix4x4 view;//(textureTransform);<br>
- m_d->displayShader-><u></u>setUniformValue("viewMatrix", \
view);<br> + // Set view/projection matrices<br>
+ QMatrix4x4 \
modelMatrix(<u></u>coordinatesConverter()-><u></u>imageToWidgetTransform());<br> \
+ modelMatrix.optimize();<br> + modelMatrix = projectionMatrix * \
modelMatrix;<br>
+ m_d->displayShader-><u></u>setUniformValue("<u></u>modelViewProjection", \
modelMatrix);<br> <br>
-// QMatrix4x4 textureMatrix;//(<u></u>textureTransform);<br>
-// m_d->checkerShader-><u></u>setUniformValue("<u></u>textureMatrix", \
textureMatrix);<br> + QMatrix4x4 textureMatrix;<br>
+ textureMatrix.setToIdentity()<u></u>;<br>
+ m_d->displayShader-><u></u>setUniformValue("<u></u>textureMatrix", \
textureMatrix);<br> <br>
- //Setup the geometry for rendering<br>
- m_d->vertexBuffer->bind();<br>
- m_d->indexBuffer->bind();<br>
+ QRectF widgetRect(0,0, width(), height());<br>
+ QRectF widgetRectInImagePixels =<br>
converter->documentToImage(<u></u>converter->widgetToDocument(<u></u>widgetRect));<br>
<br>
- m_d->displayShader-><u></u>setAttributeBuffer("a_<u></u>vertexPosition", \
GL_FLOAT, 0, 3);<br>
- m_d->displayShader-><u></u>enableAttributeArray("a_<u></u>vertexPosition");<br>
- m_d->displayShader-><u></u>setAttributeBuffer("a_<u></u>texturePosition", \
GL_FLOAT, 12 * sizeof(float), 2);<br>
- m_d->displayShader-><u></u>enableAttributeArray("a_<u></u>vertexPosition");<br>
- m_d->displayShader-><u></u>setUniformValue("texture0", \
0);<br> + qreal scaleX, scaleY;<br>
+ converter->imageScale(&<u></u>scaleX, &scaleY);<br>
<br>
- // \
m_d->openGLImageTextures-><u></u>activateHDRExposureProgram();<br>
+ QRect wr = widgetRectInImagePixels.<u></u>toAlignedRect() &<br>
m_d->openGLImageTextures-><u></u>storedImageBounds();<br>
<br>
int firstColumn = \
m_d->openGLImageTextures-><u></u>xToCol(wr.left());<br>
int lastColumn = \
m_d->openGLImageTextures-><u></u>xToCol(wr.right());<br>
int firstRow = \
m_d->openGLImageTextures-><u></u>yToRow(wr.top());<br>
int lastRow = \
m_d->openGLImageTextures-><u></u>yToRow(wr.bottom());<br> <br>
- QMatrix4x4 proj;<br>
- proj.ortho(0, 0, width(), height(), NEAR_VAL, FAR_VAL);<br>
- m_d->displayShader-><u></u>setUniformValue("<u></u>projectionMatrix", \
proj);<br>
-<br>
for (int col = firstColumn; col <= lastColumn; col++) {<br>
for (int row = firstRow; row <= lastRow; row++) {<br>
<br>
KisTextureTile *tile =<br>
\
m_d->openGLImageTextures-><u></u>getTextureTileCR(col, row);<br> <br>
- //QRectF \
textureRect(tile-><u></u>tileRectInTexturePixels());<br> + \
/*<br>
+ * We create a float rect here to workaround Qt's<br>
+ * "history reasons" in calculation of \
right()<br>
+ * and bottom() coordinates of integer rects.<br>
+ */<br>
+ QRectF \
textureRect(tile-><u></u>tileRectInTexturePixels());<br>
QRectF \
modelRect(tile-><u></u>tileRectInImagePixels());<br> <br>
- model.translate(modelRect.x()<u></u>, \
-modelRect.y());<br>
- model.scale(modelRect.width()<u></u>, \
modelRect.height());<br>
- \
m_d->displayShader-><u></u>setUniformValue("modelMatrix", model);<br> \
+ //Setup the geometry for rendering<br> + \
QVector<QVector3D> vertices;<br>
+ vertices << QVector3D(modelRect.left(), \
modelRect.bottom(), 0.f)<br>
+ << QVector3D(modelRect.left(), \
modelRect.top(), 0.f)<br>
+ << QVector3D(modelRect.right(), \
modelRect.bottom(), 0.f)<br>
+ << QVector3D(modelRect.left(), \
modelRect.top(), 0.f)<br>
+ << QVector3D(modelRect.right(), \
modelRect.top(), 0.f)<br>
+ << QVector3D(modelRect.right(), \
modelRect.bottom(), 0.f);<br> +<br>
+ \
m_d->displayShader-><u></u>enableAttributeArray(PROGRAM_<u></u>VERTEX_ATTRIBUTE);<br>
+ \
m_d->displayShader-><u></u>setAttributeArray(PROGRAM_<u></u>VERTEX_ATTRIBUTE, \
vertices.constData());<br> +<br>
+ QVector<QVector2D> texCoords;<br>
+ texCoords << QVector2D(textureRect.left(), \
textureRect.bottom())<br>
+ << QVector2D(textureRect.left(), \
textureRect.top())<br>
+ << QVector2D(textureRect.right(), \
textureRect.bottom())<br>
+ << QVector2D(textureRect.left(), \
textureRect.top())<br>
+ << QVector2D(textureRect.right(), \
textureRect.top())<br>
+ << QVector2D(textureRect.right(), \
textureRect.bottom());<br> +<br>
+ \
m_d->displayShader-><u></u>enableAttributeArray(PROGRAM_<u></u>TEXCOORD_ATTRIBUTE);<br>
+ \
m_d->displayShader-><u></u>setAttributeArray(PROGRAM_<u></u>TEXCOORD_ATTRIBUTE,<br>
texCoords.constData());<br>
<br>
glBindTexture(GL_TEXTURE_2D, tile->textureId());<br>
<br>
@@ -331,57 +331,16 @@ void KisOpenGLCanvas2::drawImage()<br>
glTexParameteri(GL_TEXTURE_<u></u>2D, \
GL_TEXTURE_MAG_FILTER, GL_LINEAR);<br> }<br>
<br>
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);<br>
+ glDrawArrays(GL_TRIANGLES, 0, 6);<br>
<br>
}<br>
}<br>
<br>
// \
m_d->openGLImageTextures-><u></u>deactivateHDRExposureProgram()<u></u>;<br>
-<br>
- m_d->vertexBuffer->release();<br>
- m_d->indexBuffer->release();<br>
+ glBindTexture(GL_TEXTURE_2D, 0);<br>
m_d->displayShader->release()<u></u>;<br>
}<br>
<br>
-void KisOpenGLCanvas2::saveGLState(<u></u>)<br>
-{<br>
- // Q_ASSERT(!m_d->GLStateSaved);<br>
-<br>
- // if (!m_d->GLStateSaved) {<br>
- // m_d->GLStateSaved = true;<br>
-<br>
- // glPushAttrib(GL_ALL_ATTRIB_<u></u>BITS);<br>
- // glMatrixMode(GL_PROJECTION);<br>
- // glPushMatrix();<br>
- // glMatrixMode(GL_TEXTURE);<br>
- // glPushMatrix();<br>
- // glMatrixMode(GL_MODELVIEW);<br>
- // glPushMatrix();<br>
-<br>
- // glGetIntegerv(GL_CURRENT_<u></u>PROGRAM, \
&m_d->savedCurrentProgram);<br>
- // glUseProgram(NO_PROGRAM);<br>
- // }<br>
-}<br>
-<br>
-void KisOpenGLCanvas2::<u></u>restoreGLState()<br>
-{<br>
- // Q_ASSERT(m_d->GLStateSaved);<br>
-<br>
- // if (m_d->GLStateSaved) {<br>
- // m_d->GLStateSaved = false;<br>
-<br>
- // glMatrixMode(GL_PROJECTION);<br>
- // glPopMatrix();<br>
- // glMatrixMode(GL_TEXTURE);<br>
- // glPopMatrix();<br>
- // glMatrixMode(GL_MODELVIEW);<br>
- // glPopMatrix();<br>
- // glPopAttrib();<br>
-<br>
- // glUseProgram(m_d-><u></u>savedCurrentProgram);<br>
- // }<br>
-}<br>
-<br>
void KisOpenGLCanvas2::<u></u>initializeShaders()<br>
{<br>
<br>
@@ -406,68 +365,8 @@ void KisOpenGLCanvas2::<u></u>initializeShaders()<br>
qDebug() << "OpenGL error" << \
glGetError();<br>
qFatal("Failed linking display shader");<br>
}<br>
-<br>
- m_d->vertexBuffer = new \
QGLBuffer(QGLBuffer::<u></u>VertexBuffer);<br>
- m_d->vertexBuffer->create();<br>
- m_d->vertexBuffer->bind();<br>
-<br>
- QVector<float> vertices;<br>
- /*<br>
- * 0.0, 1.0 ---- 1.0, 1.0<br>
- * | |<br>
- * | |<br>
- * 0.0, 0.0 ---- 1.0, 0.0<br>
- */<br>
- vertices << 0.0f << 0.0f << 0.0f;<br>
- vertices << 0.0f << 1.0f << 0.0f;<br>
- vertices << 1.0f << 0.0f << 0.0f;<br>
- vertices << 1.0f << 1.0f << 0.0f;<br>
- int vertSize = sizeof(float) * vertices.count();<br>
-<br>
- // coordinates to convert vertex points to a position in the texture. \
Follows order of corner<br>
- // points in vertices<br>
- QVector<float> uvs;<br>
- uvs << 0.f << 0.f;<br>
- uvs << 0.f << 1.f;<br>
- uvs << 1.f << 0.f;<br>
- uvs << 1.f << 1.f;<br>
- int uvSize = sizeof(float) * uvs.count();<br>
-<br>
- m_d->vertexBuffer->allocate(<u></u>vertSize + uvSize);<br>
- m_d->vertexBuffer->write(0, \
reinterpret_cast<void*>(<u></u>vertices.data()), vertSize);<br>
- m_d->vertexBuffer->write(<u></u>vertSize, \
reinterpret_cast<void*>(uvs.<u></u>data()), uvSize);<br>
- m_d->vertexBuffer->release();<br>
-<br>
- m_d->indexBuffer = new \
QGLBuffer(QGLBuffer::<u></u>IndexBuffer);<br>
- m_d->indexBuffer->create();<br>
- m_d->indexBuffer->bind();<br>
-<br>
- QVector<uint> indices;<br>
- // determines where opengl looks for vertex data. create two \
clockwise triangles from<br>
- // the points.<br>
- /*<br>
- * 1->-3<br>
- * |\ |<br>
- * ^ \ v<br>
- * | \|<br>
- * 0...2<br>
- */<br>
- indices << 0 << 1 << 2 << 1 << 3 \
<< 2;<br>
- m_d->indexBuffer->allocate(<u></u>reinterpret_cast<void*>(<u></u>indices.data()), \
indices.size() *<br> sizeof(uint));<br>
- m_d->indexBuffer->release();<br>
-}<br>
-<br>
-void KisOpenGLCanvas2::beginOpenGL(<u></u>void)<br>
-{<br>
- // saveGLState();<br>
}<br>
<br>
-void KisOpenGLCanvas2::endOpenGL(<u></u>void)<br>
-{<br>
- // restoreGLState();<br>
-}<br>
-<br>
-<br>
void KisOpenGLCanvas2::<u></u>slotConfigChanged()<br>
{<br>
notifyConfigChanged();<br>
diff --git a/krita/ui/opengl/kis_opengl_<u></u>canvas2.h \
b/krita/ui/opengl/kis_opengl_<u></u>canvas2.h<br> index 4f76dde..40f5438 100644<br>
--- a/krita/ui/opengl/kis_opengl_<u></u>canvas2.h<br>
+++ b/krita/ui/opengl/kis_opengl_<u></u>canvas2.h<br>
@@ -56,22 +56,6 @@ public:<br>
<br>
virtual ~KisOpenGLCanvas2();<br>
<br>
- /**<br>
- * Prepare the canvas for rendering using native OpenGL<br>
- * commands. This sets the projection and model view matrices so<br>
- * that primitives can be rendered using coordinates returned<br>
- * from pixelToView().<br>
- */<br>
- void beginOpenGL();<br>
-<br>
- /**<br>
- * Notify the canvas that rendering using native OpenGL commands<br>
- * has finished. This restores the state so that the canvas can<br>
- * be painted on using a QPainter.<br>
- */<br>
- void endOpenGL();<br>
-<br>
-<br>
public: // QWidget<br>
<br>
/// reimplemented method from superclass<br>
@@ -108,9 +92,6 @@ private:<br>
void drawCheckers();<br>
<br>
void initializeShaders();<br>
-<br>
- void saveGLState();<br>
- void restoreGLState();<br>
};<br>
<br>
#endif // HAVE_OPENGL<br>
diff --git a/krita/ui/opengl/kis_texture_<u></u>tile.h \
b/krita/ui/opengl/kis_texture_<u></u>tile.h<br> index 9a3517e..60fd6f6 100644<br>
--- a/krita/ui/opengl/kis_texture_<u></u>tile.h<br>
+++ b/krita/ui/opengl/kis_texture_<u></u>tile.h<br>
@@ -74,6 +74,10 @@ public:<br>
return m_textureRectInImagePixels;<br>
}<br>
<br>
+ inline QRectF tileRectInTexturePixels() {<br>
+ return m_tileRectInTexturePixels;<br>
+ }<br>
+<br>
private:<br>
void repeatStripes(const KisTextureTileUpdateInfo \
&updateInfo);<br> <br>
______________________________<u></u>_________________<br>
Krita mailing list<br>
<a href="mailto:kimageshop@kde.org" \
target="_blank">kimageshop@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kimageshop" \
target="_blank">https://mail.kde.org/mailman/<u></u>listinfo/kimageshop</a><br> <br>
<br>
<br>
<br>
--<br>
Dmitry Kazakov<br>
</blockquote>
</div></div><br>_______________________________________________<br>
Krita mailing list<br>
<a href="mailto:kimageshop@kde.org">kimageshop@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kimageshop" \
target="_blank">https://mail.kde.org/mailman/listinfo/kimageshop</a><br> \
<br></blockquote></div><br><br clear="all"><br>-- <br>Dmitry Kazakov
_______________________________________________
Krita mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic