Jump to content
  • Advertisement
Sign in to follow this  
Swatter555

Direct2D: Strange behavior

This topic is 2279 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

I have created my own rendering engine using D2D and I have ran into problems much of the way, most of these problems have dealt with the windows message pump in one way or another. Each step of the way I tested and tested to make sure the code was solid, but I am getting some strange behavior when rendering my 2D hex map. During execution, everything seems to run fine, efficiently and as expected. However, randomly, at some point during execution the frame rate creeps to almost nothing. Sometimes it returns to normal, sometimes it doesn't. Generally, in debug mode, the game loop executes a couple million times a second (doesnt do much), while paint calls are made 33 times a second. When the slowdown occurs, both slow down to 17.

The code that renders the map is simply 2 nested for loops rendering a single small bitmap, nothing complicated going on (no other rendering occurring besides diag text). I suspect the message pump is to blame again and my lack of understanding about what is truly going on behind the scenes. I regulate the number of paint calls using SendMessage (WM_PAINT). Most programmers don't use Direct2D and dont have to deal with the windows message pump in game application settings, so I couldn't find any direct examples about how to regulate paint calls. I don't even know is that is related to the problem. I hesitate to post code because I truly have no idea what is going wrong. Any advice, suggestions? I plan to get a book dedicated to win32 programming when my budget allows, so cross that one off the list.

I found rendering textured quads so much simpler in D3D. I don't know if I am riding the new technological wave or barking up the wrong tree with Direct2D. There are some cool things on the horizon for Direct2D, so I hope I can resolve these issues.

Share this post


Link to post
Share on other sites
Advertisement
You shouldn't send WM_PAINT messages. In fact the documentation says it pretty clearly:

"The WM_PAINT message is generated by the system and should not be sent by an application."

With Direct2D you don't have mess around with the message loop any more than a game using Direct3D or any other graphics API. Most games will do something like this:

while(gameIsRunning)
{
// Pump all pending messages
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
DispatchMessage(&msg);

Update();
Render();
}

This way you process all pending messages, and update/draw as fast as you possibly can. There's no need to regulate your rendering with messages, unless you really want to. If it were me I would use some other means of regulating drawing, since messages are pretty clunky and certainly not the fastest way to do things.

Share this post


Link to post
Share on other sites
Direct2D's BeginDraw and EndDraw operate only in response to WM_PAINT messages sent by the window message pump. Setting up a traditional game loop results in the window never updating. You can call Render() outside of the winProc, but it will ignore it. I experienced it first and then read it in the D2D documentation. Perhaps I am misunderstanding your post or perhaps you need to further elaborate.

I do want to create a traditional win32 application, but I need to control the render rate properly.

Share this post


Link to post
Share on other sites
I went ahead and took out my SendMessage calls and substituted it with InvalidateRect calls. Unfortunately the strange bottleneck behavior remains.

Does anybody actively use Direct2D around here who can guide me on how to use it properly in a game application? The MSDN examples only update the frame/window on resize or other rare conditions. If D2D is tailored to games (or is supposed to be), I am truly in the dark to making it work properly. How many truly robust game applications only update the frame/window on rare occasions?

For all of the cool things Direct2D does, there are too many drawbacks. 1) The only real examples I find are on MSDN (which are of limited value). 2) Nobody seems to work with it. 3) Trying to run a robust/updating game application through the windows message pump seems pure folly.

Please, someone guide me down the correct path!

Share this post


Link to post
Share on other sites

Direct2D's BeginDraw and EndDraw operate only in response to WM_PAINT messages sent by the window message pump. Setting up a traditional game loop results in the window never updating. You can call Render() outside of the winProc, but it will ignore it. I experienced it first and then read it in the D2D documentation. Perhaps I am misunderstanding your post or perhaps you need to further elaborate.

I do want to create a traditional win32 application, but I need to control the render rate properly.


I was mistaken, you can place the OnPaint/Render in the traditional manner. Not sure why I couldn't get it to work before and I no doubt misunderstood MSDN docs I read. I do remember reading that you needed to call OnPaint in response to WM_PAINT, which is probably true, but I just didn't understand it in context.

Even so, I still can't get rid of the bottleneck. I must be misusing D2D in some way with the large number of little bitmaps I am drawing for the map.

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!