Jump to content
  • Advertisement
Sign in to follow this  
UnshavenBastard

[.net] GDI+ Horribly Slow. Using DX9 for UserControls good idea?

This topic is 4368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I need some advice. Working on a control in C#/.NET, I found GDI+ to be horribly slow. I try to implement an excel like grid, with multiselect and all, and when testing with lots of very small cells, you can...watch the thing drawing. I looked for optimizations on my side, found a few things so far and fixed them. Since excel, too, allows to give each cell to have a different color, drawing everything in a block instead of calling the draw function a couple hundred times is no option. Excel does this fast...so why not me. Are there any typical performance pitfalls that I could have stepped in? (All Dr. Google told me is using BackBuffer, and this won't speed up the drawing) Would using DX9 for user controls / apps in general be a good idea? Or... rather not so good? Could it get me into trouble, because it may not run proberly on some clients' systems or something else? Thanks in advance, unshaven

Share this post


Link to post
Share on other sites
Advertisement
When dealing with the Windows interface, speed comes from not drawing. Draw things once to a buffer, and just bitblit from that buffer each time you need to paint. When things change, just draw the parts that changed to that buffer.

Share this post


Link to post
Share on other sites
You didn't do anything like calling a CreateGraphics function for every line or something?

Share this post


Link to post
Share on other sites

no, I used the graphics object for one entire frame.
drawing in a buffer-bitmap I already tried, doesn't help.

in the text there are 48x48 small cells.
so > 2000 cell interiors and more grid segments have to be drawn (I do not overdraw anything). (since each thing can have a different color, I have to draw them separately)

there are times where the whole grid/all cells need to be redrawn...
and this takes a notable lot of time...

but in excel this works just fine, even with ridiculously tiny cells.
I guess they won't make a (natively) managed version of excel hehe...

I wonder how excel manages to do this.

I mean.... c'mon... 2400 rectangles + twices as much lines...
An old flat-shaded 3D engine I wrote some years ago could handle more in 3D hehe.
I think I won't try to make a game in managed languages anytime soon.







Share this post


Link to post
Share on other sites
Don't draw at all like someone said, but skip the buffer. I've found the old GDI to not work that much better/faster after using a buffer. Instead, figure out what areas for each render that needs to be redrawn, and only draw thoughts. In your case, I would imagine a suitable unit for redrawing is one cell. I don't know about Excel versus GDI+ though, it might very well be so that Excel "cheats" and skips a couple of layers in the GDI to gain speed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Excel dont need to cheat by skipping layers of the gdi. Windows does have common controls that can be user drawn. Most likly what excel does (though they could be creating there own controls as well. Gdi+ is quite capable at doing what you want it to do.

The problem i bet is that you are fool hardy in your allocations. perhaps you are allocating and deallocating for each cell different brushes and pens without realizing it. Reuse them! brushes have a color proper for a reason.

Post code if you want more detail.

Share this post


Link to post
Share on other sites
hey, I know the basics of general optimization... ;-)

I use the graphics object for one frame,
and I have stored the pens for each cell & grid segment.

The buffer thing would work when I really do not have to draw the stuff new, but when, say, I want to assign a thicker frame to all of the selected cells (and that be all which are on the screen), I had to redraw ALL borders. And such a thing just can't take a half to one second. That... sucks.
(release mode no difference, btw)

For this and the next week I have no access to the code...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi,
I've created some controls in Delphi using the GDI+ too, and they are really slow, and I think I have used it well...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!