DirectX in WS_OVERLAPPED window vs WS_CHILD window - shader renders differently

Started by
6 comments, last by Buckeye 10 years, 2 months ago

Problem: Shader rendered meshes and ID3DXFont differ in WS_OVERLAPPED (top-level) window (okay) vs. WS_CHILD window (strangely scaled).

I have a windowed app (main window WS_OVERLAPPED style) which renders (to the client area) static and animated (skinned) meshes well. For the animated meshes I use Multianimation.fx and shader.vsh "borrowed" from the DX9 sample Multianimation. Static meshes are rendered via the device pipeline.

Wanting to add some other windows in the client area (properties and other editing aids), I moved the DirectX code to a WS_CHILD of the main window. To start with, the child window is sized to the main window's client area (no other children). Other than creating the child window with a parent in CreateWindow, I changed little in the code (storing the parent's HWND, etc.) and nothing in the DX related stuff. With the child being the same size as the main window client, buffer widths and heights remain the same (client-sized).

Static meshes rendered through the pipeline via mesh->DrawSubset(), DrawPrimitive, etc., are fine. However, the animated meshes rendered by the shader are rendered strangely scaled, differently along different axes, my own character meshes and even tiny.x (Microsoft's own). The only time anything appears scaled correctly is when the aspect ratio is 1:1, and even then, it seems to be only along one (Z) axis.

Trying to find clues, I found that text drawn to the scene using ID3DXFont also exhibits squashing and stretching as the window size changes. However, differing from the shader-draw meshes, the screen text (seems to) appear correct only at the original aspect ratio AND the original window size. Even at the original aspect ratio, the text is distorted at other than the original window size.

I've tried various combinations of things:

- Creating the device (with swapeffect COPY) with the main window's handle and presenting to the child; no change in behavior.

- Defaulting the backbuffer width/height to constant values, whatever the main window size. No joy there, EXCEPT...

- Defaulted the backbuffer width/height for an aspect of 1:1 (e.g., both width and height = 800) and presenting to the child's window handle with the destination rectangle { 0, 0, 800, 800 }. That exhibited the same behavior as any at an aspect of 1:1. Shader-rendered meshes appeared to be scaled correctly only along one axis. The ID3DXFont display was correct (the backbuffer size never changed). Again, stuff rendered via the pipeline was fine.

Again, please note, the static and shader meshes, and the screen text appear fine when renders in the client area of a WS_OVERLAPPED window.

Anyone have any ideas? Has anyone successfully used a WS_CHILD style window for rendering with shaders and/or ID3DXFont text?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

device->GetBackBuffer(...., pSurface);

pSurface->GetDesc(pDesc)

Check if pDesc->Width and pDesc->Height is the same as the client area of the window.

@Tispe - Thanks for the tip! I added a test routine before my render-scene routine to test surface dimensions against present-parameters and the window client. That revealed a logic problem in my window procedure for WM_SIZE (which I have to fix). That test routine resets the device if there's a mismatch and the render scene is skipped that cycle.

That solved the ID3DXFont problem - thanks for that! The screen text appears as-advertised after a window resize.

However, the strange scaling apparently caused in the shader is still there. (Pipeline stuff still appears okay) I checked that the effect is called on device-lost and device-reset. There's some more double-checking I'll do, but, for the moment, that problem persists.

Any more excellent suggestions?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Do you happen to have multiple passes with multiple surfaces? If you are trying to fit one surface on to another it may get squashed depending on difference in surface dimentions.

Sounds like a good question. However. it's a very simple app with regard to drawing - just pipeline calls and a single effect shader for the skinned meshes.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

MY PROBLEM FOUND - due to error checking that Tispe suggested above, I found an additional error in the WM_SIZE routines in both the MainWindow and ChildWindow window procedures. The response to SW_MAXIMIZE and SW_MINIMIZE were incorrect. The problem with ID3DXFont was NOT fixed previously. I just hadn't tried all combinations of resizing the main window - e.g., maximized-to-minimized, minimized-to-restore, etc.

If anyone cares, in summary, here's the general flow I have for maintaining DirectX in a child window:

For each WM_SIZE msg received by the main window, the child windows are resized in a main window routine using SetWindowPos for each child with the appropriate sizes. Lots of bookkeeping to keep track of the child windows sizes.

For the non-DirectX windows, nothing special is done. I let them take care of themselves as they're GDI.

The DirectX routines are paused (a flag set) by the Main Window when a sizing move starts (user dragging the main window frame) starts (WM_ENTERSIZINGMOVE). dxChild->EnterSizingMove method is called to pause the app and set a "sizing-in-progress" flag. The app is unpaused on WM_EXITSIZINGMOVE and an dxChild->ExitSizingMove method is called which unpauses the app and resets the device with the updated buffer size. This is done to prevent hundreds of device resets while the user drags the window.

When the dx child window receives a WM_SIZE, the backbuffer is resized. The device is reset with the new buffer size UNLESS a sizing move is in progress. When the sizing move ends (see above), the device is reset.

When the main window is minimized, the app is paused. When the main window is restored from a minimized state, the app is unpaused.

There may be a couple more subtleties, but that's the gist.

Again, @Tispe - thanks!

Is there a way to revise the topic to add RESOLVED or similar? EDIT: See unbird's comment below. Changed RESOLVED to MY PROBLEM FOUND.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Welcome back Buckeye ... long time no see wink.png

Is there a way to revise the topic to add RESOLVED or similar?


You're not supposed to according to forum rules in order to not prevent further discussion. And I actually have to say something here.

First: Congrats. I've never seen this approach working (rerouting the output to other HWND with Present), so nice to know it's possible.

Usually when rendering to different windows one is supposed to create additional swapchains, one for each window. Doing so has one big advantage: You can omit the obnoxious D3D9 device reset when changing resolution. Though I nowadays mainly play with D3D11 I used this approach even for the main window: Create a (small) dummy backbuffer and use a custom swapchain instead. One can then even e.g. flip v-sync without a device reset wink.png

Your approach still has an advantage I think: I guess each swapchain will reserve device memory, so when you got a bloody lot of child windows you're "wasting" precious memory. Maybe you could combine both approaches, meaning: Use a central swapchain for all your child windows.

Hey, unbird. Good to be back.

The forum rules with regard to labeling problems RESOLVED are, indeed, correct. I'm an old fart and my memory's fading - there have been discussions on the subject.

WRT various Present parameters - thanks for the credit but that was pure hacking. After a couple hours of trying to find my sizing problem, I just read the Present docs and tried a bunch of stuff. After (eventually) correcting the problem, my correctly working code has the "standard" stuff - the device window is the child window, backbuffer sized to the client area, Present(0,0,0,0), etc.

@unbird - thanks for the link to "additional swapchains." At present, I have (as mentioned) only a single DX window, but multiple swapchains may be just the thing to render multiple views in my editor. That should be an adventure! The bookkeeping for setting up swapchains in one window for other windows with differing views which may or may not be visible (or created) at the moment! I've never messed with multiple swapchains. However, the mental and learning challenge is why I program anyhow.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement