|
|
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Font and Image rendering slow
|
|
|
Re: Font and Image rendering slow [message #60001 is a reply to message #59968] |
Mon, 03 July 2023 23:00   |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
As for the Draw::IsPainting(),
First you select the area to refresh, using the Refrest(Rect) method, not the Refresh() method.
Then, in the Paint() method, you check for the rectangle, using the Draw::IsPainting() method, and if it is true, only then you paint.
Two -different- examples, using this method to boost the speed:
1) see: CtrlLib/LineEdit.cpp,ln. 468
2) see: UppHub/TerminalCtrl/Renderer.cpp, ln. 196
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
|
|
|
|
|
|
|
Re: Font and Image rendering slow [message #60006 is a reply to message #60004] |
Thu, 06 July 2023 20:44   |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
I have been looking at what you have suggested but I don't see how it can help me. If we are drawing directly to Paint(Upp::Draw& w) which is where we get the speed boost, but then we switch back to ImageBuffer which does not have any function its self to draw lines and rectangle and other things. Then I looked at the Image utility functions and I also don't see any functions that allow drawing lines I only see rectangles, so I am not seeing anyway to do this with out some sort of Painter.
I have tried PaintingPainter, BufferPainter, ImagePainter, DrawingDraw and then used PaintImageBuffer to get that into the ImageBuffer and it is all slow, like 5 FPS.
So I am not sure how to do everything I need. The main Application Has Rectangles, Rectangles with Dashes, Lines, Lines with Dashes, Images, an overlay with transparency and scaling when zoomed in and out with ctrl + scroll wheel.
I figured out the dashes and rectangles and lines but the scaling and overlay with Draw is not possible and the only option after that is to render everything into a ImageBuffer and all the methods I have seen are really slow.
Oblivion wrote on Wed, 05 July 2023 14:18For such operations, you can directly use ImageBuffer & Image utility functions. They are cheaper.
Best regards,
Oblivion
[Updated on: Thu, 06 July 2023 20:47] Report message to a moderator
|
|
|
Re: Font and Image rendering slow [message #60007 is a reply to message #60006] |
Fri, 07 July 2023 01:54   |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
But you can use the painter efficiently. What you need to consider is not using it in a hot path such as Paint, if possible (if you need high FPS, I mean). A basic but very effective strategy: draw the image elsewhere, and only paint it to system draw in Paint. Also, an image cache will help here significantly.
I have attached a simple code that uses an image cache to draw 100x100 icons.
The example code draws the icon to a ImagePainter object and can manipulate (rotate) it on-the-fly, without a significant performance hit. Only 8 slots of the cache will be filled in this code (rotation is in 4 directions * left and right, so 8 images total). Images have alpha channel enabled.
The result of consecutive 305 rotations (window maximized, GTK, 1920x1080), calls to Paint (RELEASE MODE), no explicit clip:
TIMING Paint : 834.63 ms - 2.74 ms (835.00 ms / 305 ), min: 2.00 ms, max: 4.00 ms, nesting: 0 - 305
Edit: Code updated.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 07 July 2023 02:18] Report message to a moderator
|
|
|
|
Re: Font and Image rendering slow [message #60010 is a reply to message #59968] |
Fri, 07 July 2023 22:21   |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
I don't only run on windows. I primarily run on linux and its building against the Gtk libs and not X11. It seems to behave differently than windows.
Also my work machine is old. I am sure my home computer that has a AMD 5950X, with 128Gigs of ram and a 3080TI 12Gig would run just find with out any problems.
But since the software I am making will go into an industrial setting I can't expect them to be running a high end machine to run something as simple as this.
The test I am running is. I add a Refresh directly to the end of the Paint code, so that once its done painting it will draw it again. Then I measure the number of frames it has drawn in a second. The reason for this is that when I Drag and Icon across the screen this is essentially what is happening which is when I see the performance hit.
The example you just gave me gets 51 FPS on my work machine under linux with a 1920x1080 full screen, and the fact that it does not even do any form of clipping and still manages 51 FPS on my machine is better then what I have seen so far. I will get this implemented on my setup.
I believe I can even do scaling in the cache section of the code since you were able to do a rotate.
Now the final problem I am not seeing how to fix though since everything is direct to the Upp::Draw in the main paint section is how to do a full screen transparency effect.
Here is a complete demo:
Zoom In and Out: Ctrl+Scroll
Select Icon: Left Mouse
Toggle Select Multiple: Ctrl+Left Mouse
Group Select: Shift+Left Mouse Drag on blank space and no selected icon
Create Link: Click and drag between icon from there small box handles
Delete Link: Click a link and then press the delete key
Show Link Details: F1 when links are present
Mouse over Summary: Move the cursor over icon and half a second later a summary should pop up
Show Overlay: F2
Show FPS: F3
Scroll Left/Right: Shift+Scroll Wheel
Scroll Up/Down: ScollWheel
This cover all of the Drawing elements that my program currently used.
-
Attachment: upp_demo.zip
(Size: 19.13KB, Downloaded 98 times)
[Updated on: Fri, 07 July 2023 22:25] Report message to a moderator
|
|
|
Re: Font and Image rendering slow [message #60011 is a reply to message #60010] |
Sat, 08 July 2023 11:44   |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
Quote:Now the final problem I am not seeing how to fix though since everything is direct to the Upp::Draw in the main paint section is how to do a full screen transparency effect.
I might be getting you wrong here, but do you mean this? (If you mean window background transparency effect, there is no direct method for that in Upp, not that I know of, at least)
void frm_main::Paint(Draw& w) {
Size sz = GetSize();
w.DrawRect(sz, Yellow()); // System draw, background = yellow.
ImageBuffer ib(sz);
BufferPainter bp(ib, MODE_ANTIALIASED);
bp.Clear(RGBAZero()); // Buffer now has transparent background.
_icons_paint(bp, scroll.Get().x, scroll.Get().y, allow_scaling, render_everything);
if(show_overlay) {
_paint_overlay(bp);
}
SetSurface(w, 0, 0, sz.cx, sz.cy, ~ib); // You need to use SetSurface to directly paint buffer content here (this is optimized for systemdraw (possibly faster than usual image drawing) ...
}
Also, IMO, the optimized way of painting a large painter object is, drawing it in another thread, in parallel -if possible- and only update the system draw -using SetSurface- as needed. (If there is no strict requirement on doing all the work in single-threaded environment, I mean.)
Further note: You can use also use ImagePainter class instead of using a ImageBuffer + BufferPainter. ImagePainter is basically a wrapper for BufferPainter + ImageBuffer.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 08 July 2023 12:10] Report message to a moderator
|
|
|
|
Re: Font and Image rendering slow [message #60040 is a reply to message #59968] |
Fri, 14 July 2023 17:18   |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
So here is a new full demo.
I added a new hot key which is F4 which will draw lines from the first icon to the rest. with that on and with F1 on the FPS for me drops to 3 FPS
I have implemented some of the things suggest but I decided to not do the image cache since once you have a bunch of images cached it actually hurts performance trying to get the correct image.
I did implement a simple cache which is if there is no change the keep current rendered image if there is a change then draw a new one.
I also faked the transparency effect which helped the speed a a lot.
I also switched away from iterators in the draw code.
I also changed how the scaling works.
The performance is much better then it used to be. If you happen to have anymore suggestions on how to get more speed that would be awesome.
-
Attachment: upp_demo.zip
(Size: 19.77KB, Downloaded 88 times)
[Updated on: Fri, 14 July 2023 17:18] Report message to a moderator
|
|
|
Re: Font and Image rendering slow [message #60042 is a reply to message #59968] |
Fri, 14 July 2023 17:47   |
devilsclaw
Messages: 72 Registered: August 2022
|
Member |
|
|
Well the new demo does not work correctly in Windows. It looks fine in linux but not windows. It look like the ImageBuffer which is used for drawing the lines and is 100% transparent every where except the lines and the summary icon is drawing as black. also the randint which is in experimental random does not exist in the windows version it seems.
[Updated on: Fri, 14 July 2023 17:47] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 04:44:37 CEST 2025
Total time taken to generate the page: 0.01079 seconds
|
|
|