Spade-Editor / Spade

Cross-platform raster graphics editor inspired by Paint.NET
GNU General Public License v3.0
41 stars 10 forks source link

Custom grids #99

Open HeroesGrave opened 9 years ago

HeroesGrave commented 9 years ago

Suggested by LiquidNitrogen on IRC.

Allow users to have multiple custom pixel-grids, with different scales, colours, etc.

BurntPizza commented 9 years ago

[Warning: feature creep] Maybe per-layer?

Longor1996 commented 9 years ago

Drawing grids onto the image is a performance hog that slows down Spade to turtle-speed right now. Should be fixed before implementing even more grids...

HeroesGrave commented 9 years ago

Are you having performance troubles?

At the moment, it draws lines only where they're visible, and only switches to the dashed lines once you zoom past a certain threshold.

And besides, having lower precision grids will improve performance if anything.

Longor1996 commented 9 years ago

Yes, I am having performance problems. Whenever I zoom in at 1500% into a image, no matter what image-size, the repaint has noticable stutters. Note that this only happens between 1000% and 3000% zoom. Weird that it only happens at these zoom-levels.

On a related note: The entire application starts lagging when resizing/moving any dialog (and the main-window) on the screen.

HeroesGrave commented 9 years ago

Hmm. There seems to be some bugs with the grid and zooming in general. I'll have a look.

HeroesGrave commented 9 years ago

This is weird.

When I run the program in Eclipse, it works perfectly fine. When I export it and run with java -jar, I get lag, the grid moves out of place, and the image disappears completely when I zoom to a certain point.

HeroesGrave commented 9 years ago

Further attempts show that the grid and image artifacts only happen with OpenJDK 8, although with OpenJDK 7 it does slow down.

I'm a bit busy at the moment. I'll try and sort everything out ASAP.

Longor1996 commented 9 years ago

And thats why using Java2D for a image-editor is actually a bad idea.

I am thinking about making a hardware accelerated version of the 'PaintCanvas' using LWJGL. Problem with that would be that LWJGL doesn't work correctly with WebLAF (overdraw problems).

HeroesGrave commented 9 years ago

Hmm. Would JavaFX be a viable option?

axelf4 commented 9 years ago

I'd like this project to switch to OpenGL (with LWJGL). The whole UI being hardware accelerated whould be ideal, but require to much work. With OpenGL you could interfere with drawing at a much lower level, something that wouldn't be possible with Java2D (and maybe JavaFX, not sure). You could for example directly load plugins as GLSL shaders and send options as uniforms.

And as a side note; the performance would be top notch. If some optimized code would run slow-the host would be a potato. Or you'd have to get into jni.

HeroesGrave commented 9 years ago

Problem with OpenGL is that we have to write an entire UI library from scratch

axelf4 commented 9 years ago

Yeah, I mentioned it. I'm thinking of embedding an OpenGL context into some kind of Swing component. It's possible in Qt (or so I remember).

SuperDisk commented 9 years ago

For what it's worth, you can actually just set a flag in Java2d (System.setProperty("sun.java2d.opengl", "true");) and it'll do its rendering with OpenGL. I'm sure that's not as efficient as actually writing the renderer by hand, but hey.

Also, there's the path of using VolitileImages and whatnot, but I'm not sure how suitable that would be for a graphics editor.

HeroesGrave commented 9 years ago

IIRC, the System.setProperty("sun.java2d.opengl", "true"); flag only has an effect on Windows to override using directx for rendering. I don't think there's any performance to be gained.

VolatileImages wouldn't work because we do all the editing by modifying the backbuffer of the BufferedImage.

SuperDisk commented 9 years ago

All that being said, I still get quite decent performance on my 2008 Macbook (even with the grids), so I don't see much of a reason to switch to a 3d rendering engine for speed.

axelf4 commented 9 years ago

I thought that Java2D used OpenGL by default.. Anyway, for me OpenGL would be a long-term goal. It would remove the need for a custom plugin library.

HeroesGrave commented 9 years ago

The other problem with OpenGL is that it's not really designed for raster graphics.

axelf4 commented 9 years ago

True. I'm not saying that OpenGL is the way to go, but you could use draw to a framebuffer and only read it when saving to disk.

SuperDisk commented 9 years ago

According to the docs, the available Java2d pipelines are:

X11 - Default for Linux. (Slow!!) OpenGL - Not used by default, but is available for Linux and Windows. (Fast!) DirectDraw/GDI - Default on Windows. (Slow!) Direct3D - Available for Windows, but not used by default. (Fast!)

I think doing a combination of testing for platform and selecting Direct3d and Opengl, then falling back to the slow stuff is the way to go, at least for now.

HeroesGrave commented 9 years ago

Interesting. I didn't think Java would use XRender at all, let alone have it as default.