Option to automatically display a 1x1 grid when zoomed past a certain point
ClosedPublic

Authored by lieroz on Jul 9 2017, 2:37 PM.

Details

Summary

Implemented https://phabricator.kde.org/T203. When scaled past 400%, 1x1 grid is displayed.

Test Plan

Couldn't test shader loading and work in openGL version < 3.0
Also need checking if clause where info passed to openGL via lineBuffer.

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
lieroz created this revision.Jul 9 2017, 2:37 PM
lieroz updated this revision to Diff 16388.Jul 9 2017, 3:09 PM
lieroz updated this revision to Diff 16437.Jul 10 2017, 9:19 AM
lieroz updated this revision to Diff 16438.Jul 10 2017, 9:22 AM
lieroz set the repository for this revision to R37 Krita.
lieroz added a project: Krita.
rempt added a subscriber: rempt.EditedJul 10 2017, 9:34 AM

Hi!

Thanks for the patch. I've got a couple of questions, that I put inline, and a third question: shouldn't this patch be split in two, one that allows setting the cursor color, and one for the grid? Also, it's probably a good idea to also add setting the cursor color to the display page in the settings dialog.

Hm... Updated to add: I don't see the grid when I zoom in? Should I configure something manually?

libs/ui/opengl/kis_opengl_canvas2.cpp
507

I wonder -- is there a reason this patch doesn't re-use the existing grid drawing code?

dkazakov requested changes to this revision.Jul 10 2017, 9:42 AM

Hi, @lieroz!

I have tested your patch! It works almost perfectly. There is only one small problem. The spacing between the grid lines is not the same and, which is worse, this spacing jumps to and fro when you do the panning. Please check the code in KisGridDecoration::drawDecoration() for the example.

To solve the issue one needs to have a bit finer control over the rounding happening during the painting. Try using rounding/ceil/floor in different combinations. It might work...

krita/data/shaders/shaders.qrc
14

I would rename it into solid_color.frag so it would be a bit more self-descriptive :)

libs/ui/opengl/kis_opengl_canvas2.cpp
75

I guess this can be removed now, can't it?

76

solidColorShader is probably a bit better name

557

I'm not sure that allocation of the buffer during each run is a good idea. Probably, you could allocate something on resize/pan/zoom event and then just reuse it?

This revision now requires changes to proceed.Jul 10 2017, 9:42 AM
dkazakov added inline comments.Jul 10 2017, 9:50 AM
libs/ui/opengl/kis_opengl_canvas2.cpp
507

We thought that it would be more efficient to draw such a dense grid straight in openGL. And there might be troubles with activation/deactivation of the decoration when zooming, like I had long ago with infinity manager decoration.

The question is good and very disputable of course.

lieroz added a comment.EditedJul 10 2017, 9:57 AM
In D6582#123608, @rempt wrote:

Hi!

Thanks for the patch. I've got a couple of questions, that I put inline, and a third question: shouldn't this patch be split in two, one that allows setting the cursor color, and one for the grid? Also, it's probably a good idea to also add setting the cursor color to the display page in the settings dialog.

Hm... Updated to add: I don't see the grid when I zoom in? Should I configure something manually?

Hello, thanks for review!
In my case, works code without linebuffer where it checks KisOpenGL::hasOpenGL3(), I couldn't test it on my machine, i guess there have to be openGL > 3.0.2 but mine is pure 3.0, could you tell me your version so i will know where to dig in.
About reusage of already existing code. Uhm... I just didn't know about it :)

Update: If you want to test it immediately, you will have to comment blocks with KisOpenGL::hasOpenGL3()

In D6582#123608, @rempt wrote:

Hi!

Thanks for the patch. I've got a couple of questions, that I put inline, and a third question: shouldn't this patch be split in two, one that allows setting the cursor color, and one for the grid? Also, it's probably a good idea to also add setting the cursor color to the display page in the settings dialog.

Hm... Updated to add: I don't see the grid when I zoom in? Should I configure something manually?

Hello, thanks for review!
In my case, works code without linebuffer where it checks KisOpenGL::hasOpenGL3(), I couldn't test it on my machine, i guess there have to be openGL > 3.0.2 but mine is pure 3.0, could you tell me your version so i will know where to dig in.
About reusage of already existing code. Uhm... I just didn't know about it :)

Update: If you want to test it immediately, you will have to comment blocks with KisOpenGL::hasOpenGL3()

Mine is 3.0.0 too at the moment:

OpenGL Info

Vendor:  nouveau                                                                                               
Renderer:  "Gallium 0.4 on NV117"                                                                              
Version:  3.0 Mesa 11.2.2                                                                                      
Shading language:  1.30                                                                                        
Requested format:  QSurfaceFormat(version 3.0, options QFlags(0x4), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 0, profile  2)
Current format:    QSurfaceFormat(version 3.0, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 0, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 0, profile  0)
   Version: 3 . 0
   Supports deprecated functions true

krita has opengl true

lieroz updated this revision to Diff 16476.Jul 10 2017, 9:38 PM
lieroz edited edge metadata.
Restricted Application added a subscriber: woltherav. · View Herald TranscriptJul 10 2017, 9:38 PM
lieroz added a comment.EditedJul 10 2017, 9:42 PM

@rempt, i just updated patch, @dkazakov tested it on Nvidia and said that it works. Could you also check it? And now it displays grid after zoomed past 800%, after a day of work we with @dkazakov agreed on that value.

Update: You'll also have to draw something, cause now it is white colored.

It works pretty good overall and seems to line up with the pixels. I have a few suggestions to make it better...

  1. individual pixel stuff is more important with pixel art. With that people usually work much smaller like 32 x 32. When I make an image at 32 x 32 (72 dpi), the grid turns on at 200% zoom. I would not expect it to turn on at only 200% zoom. 800% would be better like it does at higher pixel densities
  2. It doesn't appear there is an option to turn this off and on. It would probably be a good idea to have that in either the "View" menu or the settings area area. Saving it to the kritarc would probably be a good idea

I played around with this a bit more and there are some odd artifacts appearing on the canvas when I draw. Turning OpenGL off seems to fix the issue. I am testing on a windows 10 machine.

Not sure if anyone else is getting these artifacts.

screenshot

It works pretty good overall and seems to line up with the pixels. I have a few suggestions to make it better...

  1. individual pixel stuff is more important with pixel art. With that people usually work much smaller like 32 x 32. When I make an image at 32 x 32 (72 dpi), the grid turns on at 200% zoom. I would not expect it to turn on at only 200% zoom. 800% would be better like it does at higher pixel densities
  2. It doesn't appear there is an option to turn this off and on. It would probably be a good idea to have that in either the "View" menu or the settings area area. Saving it to the kritarc would probably be a good idea

I played around with this a bit more and there are some odd artifacts appearing on the canvas when I draw. Turning OpenGL off seems to fix the issue. I am testing on a windows 10 machine.

Not sure if anyone else is getting these artifacts.

screenshot

Thanks, i will try to refactor those changes you suggested. However, your issue is realy strange, right know i don't know where the problem is. Could you please paste here your version of openGL and it would be cool if you could qDebug() if/else branch with KisOpenGL::hasOpenGL3() for me to know whether it is trouble in sending info to openGL via buffers.

Here is my graphics card info...

OpenGL Info

Vendor: ATI Technologies Inc.
Renderer: AMD FirePro M4000 Mobility Pro Graphics
Version: 3.0.13411 Compatibility Profile Context FireGL 15.201.2701.0
Shading language: 4.40
 Version: 3.0
   Supports deprecated functions: true

I wonder if anyone else is having this issue? I generally don't have any OpenGL problems on this computer and Krita. Maybe it is just specific to my graphics card? Maybe dmitry or boud can also test.

rempt added a comment.Jul 12 2017, 7:37 AM

After I updated to the binary nvidia drivers for Linux, the grid started to work:

OpenGL Info

Vendor:  NVIDIA Corporation
Renderer:  "Quadro K620/PCIe/SSE2"
Version:  4.5.0 NVIDIA 375.66
Shading language:  4.50 NVIDIA
Requested format:  QSurfaceFormat(version 3.0, options QFlags(0x4), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 0, profile  2)
Current format:    QSurfaceFormat(version 4.5, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 0, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 0, profile  2)
   Version: 4 . 5
   Supports deprecated functions true

krita has opengl true

Hi, @lieroz and @scottpetrovic!

I have just tested the patch on Windows 10 + AMD GPU and everything seems to work fine.

[5240] No "breeze" available.
[5240] Set style "fusion"
[5240] OpenGL Info
[5240]   Vendor:  ATI Technologies Inc.
[5240]   Renderer:  "AMD Radeon(TM) R7 Graphics"
[5240]   Version:  3.0.13474 Compatibility Profile Context 22.19.162.4
[5240]   Shading language:  4.50
[5240]   Requested format:  QSurfaceFormat(version 3.0, options QFlags(0x4), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior 2, swapInterval 0, profile  2)
[5240]   Current format:    QSurfaceFormat(version 3.0, options QFlags(0x4), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior 2, swapInterval 1, profile  0)
[5240]      Version: 3 . 0
[5240]      Supports deprecated functions true
[5240] krita has opengl true

@scottpetrovic, could you please test it once again and check if you have the same issue without the patch applied?

Btw, @scottpetrovic, do you see these artifacts right after the start of Krita or only after some special actions/time?

lieroz updated this revision to Diff 16703.Jul 14 2017, 1:34 PM
scottpetrovic added a comment.EditedJul 14 2017, 3:11 PM

I think this patch is ok.

I re-tested the patch and I am not getting those artifacts any longer. I applied the patch to the tip of master.

I am not sure how I got in the state I did last time. The problem I had before is probably a problem with some situation. It probably isn't related to this patch though. I also am a bit behind in my graphics card updates.

The only comment I would have left is that it would be nice to be able to toggle this functionality off (it can be on by default). I would probably call it something like "Show Pixel Grid" so it won't be confused with the normal grid. It could be in the view main menu.

If it is easier, that could be added as a separate patch...just to get this in the code base

dkazakov accepted this revision.Jul 14 2017, 8:39 PM

Okay, accepting then :)

This revision is now accepted and ready to land.Jul 14 2017, 8:39 PM
This revision was automatically updated to reflect the committed changes.