Direct2D slow for general apps?

Started by
10 comments, last by CadetUmfer 13 years, 11 months ago
I've been mucking around with Direct2D and made a simple circle that's set to the mouse's position. What surprises me is that it's slower than gdi/+. The circle lags less behind the mouse if I switch over to software rendering but of course the lag increases with the more objects I add, while hardware mode consistently lags the same as more are added. Btw, it's still rendering at 60fps. Why is this? I also checked one of the Direct2D samples in the SDK that has a square set to the mouses position and it lags behind as well but at 60fps. Should I stick to GDI/+ for general apps?
Advertisement
This is because VSync. To turn it off, just do that when you create the rendertarget:

V_RETURN(MyVars.D2DFactory->CreateHwndRenderTarget( RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,PixelFormat(DXGI_FORMAT_UNKNOWN ,D2D1_ALPHA_MODE_PREMULTIPLIED )), HwndRenderTargetProperties( hw, SizeU( WindowSize.right - WindowSize.left, WindowSize.bottom - WindowSize.top),D2D1_PRESENT_OPTIONS_IMMEDIATELY ), &MyVars.RT));

This will unlock your FPS.

EDIT: Oh, didn't read you post carefully. :( But try setting off vsync, and please show how you set up Direct2D. In my engine, it renders just very fast...
That kind of lag can also be caused by not processing all of your Windows messages every frame. You can generate mouse messages at a rate of much more than 60 per second!
Yes, thats a good point! Please post your Main-Loop :)
Another potential cause is that Direct2D was written by people who don't understand how an API is used or how to write one.

Please post the entire source code for "made a simple circle that's set to the mouse's position" because I want to laugh at how many hoops you have to jump through to do something like that.
Anthony Umfer
Quote:Original post by CadetUmfer
Another potential cause is that Direct2D was written by people who don't understand how an API is used or how to write one.

Please post the entire source code for "made a simple circle that's set to the mouse's position" because I want to laugh at how many hoops you have to jump through to do something like that.


It's meant to be a high-performance graphics API that allows you to use GPU hardware acceleration. The description on MSDN seems to make this quite clear. Such an API obviously requires a lower level of abstraction, requiring you to deal with some specifics of the driver structure and graphics hardware. You can't have your cake and eat it too when it comes to these things...you either work at a low-level or you work with a framework that trades simplicity for flexibility.
Yeah, but when the API is more complex than just using ID3DXSprite...something is wrong.

https://mollyrocket.com/9115

Quote:Original post by MJP
you either work at a low-level or you work with a framework that trades simplicity for flexibility


I think that exact tradeoff is what most potential users of Direct2D would've wanted.
Anthony Umfer
Quote:Original post by CadetUmfer
Yeah, but when the API is more complex than just using ID3DXSprite...something is wrong.

https://mollyrocket.com/9115

Quote:Original post by MJP
you either work at a low-level or you work with a framework that trades simplicity for flexibility


I think that exact tradeoff is what most potential users of Direct2D would've wanted.


The D3DX library is a utility library that sits on top of Direct3D, not a part of the Direct3D specific API. You are comparing apples to oranges.

People who want something higher level should stick to GDI/GDI+.
No I'm not. I'm comparing 2 APIs that can accomplish similar things: tell the GPU to draw a textured quad. In addition, Direct2D is also built on top of Direct3D.

Maybe I'm wrong, and there is a large market of users who want to write high-performance 2D graphics, and want to learn a complex API, but don't want those skills to transfer over to a existing popular 3D API.
Anthony Umfer
Quote:Original post by CadetUmfer
No I'm not. I'm comparing 2 APIs that can accomplish similar things: tell the GPU to draw a textured quad. In addition, Direct2D is also built on top of Direct3D.


You're comparing a single class with an extremely narrow use-case (drawing textured quads) with an entire API that has an extremely broad use-case (drawing 2D graphics and text). If you wanted you could make your own ID3DXSprite-esque class for Direct2D that makes it easy to throw sprites at the screen, since that's the whole point of Direct2D: it'd flexible and low-level enough for you to build higher-level frameworks abstractions on top of it without getting in your way.

If you think that there isn't a need for such an API then you're welcome to feel that way, but I think it was more than a little misguided on your part to claim that the API writers are bad at what they do just because you misunderstood Direct2D's purpose.

This topic is closed to new replies.

Advertisement