Now I remember…

· by Steve · Read in about 3 min · (490 Words)

Some of you might already know that I started Ogre originally primarily because I wanted to shield my sensitive eyes from the absolute horror that is native D3D code. Obviously it wasn’t long before it was hiding GL too but that remains the original reason I started it - to plaster over wrinkles deeper than Mother Theresas. Anyone who’s had to write a significant amount of D3D code knows what I’m talking about - horrible all-caps structures, unbridled use of Hungarian notation, incredibly sensitive order-dependent windowing hooks, device loss & restoration nightmares, the list goes on. So much code just to baby-sit a library.

Today I decided to help a couple of people out and make it easier in OGRE to switch between fullscreen and windowed modes, and to change fullscreen modes without having to recreate windows. One of those things that we probably should have covered already but never got around to. Anyway, time to implement & test on GL - about 30 minutes. Time to implement and test on Direct3D - about 4 bloody hours. The amount of code involved was actually about the same, the difference is that D3D is a total pain in the ass. Primarily the incredibly irritating timing issues that switching device settings require.

All you actually have to do is change some device settings, change the window settings and recreate some resources. Easy. Except that the timing of and ordering in which you can do things is really quite limited - you have to change the window settings, then wait for the Win32 event to come through, then wait for the device to be ready to reset,  then reset it, then resize the window again (if you don’t, switching to windowed mode doesn’t work properly, the borders get screwed up). In GL, you just do all those things in one list and you’re done. In D3D, you have to experiment with your fragmented pieces of code (some in the trigger method, some in the window event loop, some in the post-device reset code) until you get the timing & ordering right, debugging ‘invalid call’ errors and window decoration errors, all without a debugger because D3D and fullscreen debugging don’t mix (I didn’t feel like setting up remote debugging at this stage although I was getting close).

The initialisation & management code of D3D has always been far more awkward than it needs to be, and today I remembered exactly why I wanted to bury it under 10 meters of API concrete. I can also rant about GL’s extensions, akward RTT system and frequently error-encouraging stateful behaviour but D3D’s device / window management code still earns my greatest ire. Just take one glance at the Dx9 samples and their utility classes and your eyes may in fact start to grow cataracts as a defense mechanism. Today was a ‘Lest I forget’ experience - you OGRE users don’t know how good you got it 😉