Does swapchain->Present always stretch to the target?

Started by
7 comments, last by Buckeye 9 years, 11 months ago

I would like to set the area in the window client area that the swapchain presents to. Is that possible, or does Present always stretch to the entire window client area?

For background, I'm moving from DX9 to D3D11 and I'm converting several apps, a couple of which have child windows of the main window used for GDI stuff. I also used GDI directly in the client. In DX9, device->Present allows for setting the target rectangle which was convenient for allowing child windows to share the client area, and I did GDI stuff also to the client. In D3D11, I've tried creating the buffers and resizing them, but they appear to always be stretched to the full client area.

Will I have to, perhaps, do the reverse? I.e., render to a target child window positioned appropriately in the client area, and use GDI directly in the main window client?

I've also looked into using GDI directly with the buffer texture, but there appear to be format restrictions - e.g., I multisample and (apparently) that makes the surface incompatible for GDI device contexts.

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

Have you set the viewport to the area of the client window that you want to render into? That should let you choose exactly where you are rendering into - unless I am misinterpreting what you are trying to do... If so, can you post an image to show what isn't working properly?


Have you set the viewport to the area of the client window that you want to render into?

Yes, I have. That (apparently) just sets the portion of the buffer which gets rendered, as it does in DX9. That works well to restrict the rendering area, but the entire buffer still gets stretched to the entire client. It's not the area of the buffer I want to restrict, but the area in the target window client area that I want to restrict.


If so, can you post an image to show what isn't working properly?

I could, but it would be an image of a window with the entire client area with the clear color. wink.png

As an example, in the DX9 app below, the device is created with the main window handle. The bottom GDI and right-side GDI stuff are in child windows, and the DX9 buffer gets presented to the window client area in (only) the rectangle with the character (in wireframe). EDIT: Maybe the second image below provides a better explanation of what I'd like to do. In that app, there are no child windows. The rendering is merely presented to a client rectangle smaller than the client.

[attachment=21377:animeditor05.png]

[attachment=21378:client_area_text.png]

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.

I believe it always stretches, so you need a child-window for that.

Present1 has parameters for updated rectangles, but I think it's just for optimization and can still clear the entire area.

If it were me I would just take the hwnd of a child window and give that to DirectX, then it "just works":


then it "just works":

Well, not quite. The child window must be managed - e.g., created, input redirected, resized, moved, etc. - rather than just adjusting the 4 parameters of a RECT.

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.

I think Jason's solution should work, ie; present your back buffer, and draw GDI on top afterwards, although to be honest I feel like I'm and ant among giants in this thread. Have you tried rendering to your MSAA-able surface, and then biltting (if possible) or using that as a texture to draw a full screen quad on to a GDI compatible surface?

I tend to do what others have suggested and just use separate HWNDs and swapchains for child areas of the hwndmain client.


..present your back buffer, and draw GDI on top afterwards

I appreciate your input, but I tried that some time ago. In general, because of the rapid presenting by D3D11 (or DX9 for that matter) and the slower drawing by GDI, the GDI stuff blinks unacceptably.


Have you tried rendering to your MSAA-able surface, and then biltting (if possible) or using that as a texture to draw a full screen quad on to a GDI compatible surface?

Have to give that some thought, Burnt_Fyr. Thinking outside the box - do my own "presenting." As you mention, blt (rather than present) the texture (if possible) to the client and go right into GDI. For me, that'll be something to explore a little later as I haven't gotten into part of D3D11 rendering yet.

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.

If anyone is still curious, I came back to Jason Z's suggestion about setting the viewport to (at least) limit the rendering area, with my attempts to create a GDI compatible backbuffer surface. With some bookkeeping to track area sizes, I can reuse my GDI code to draw graphs, etc., (shown in one of my pictures above.) The entire backbuffer gets the clear color, but, by setting an appropriate viewport for the D3D11 rendering, and now having a GDI compatible backbuffer, I can render both D3D11 and GDI for presentation without any child windows, etc.

I've only just begun the conversion, but shown below is a frame capture (a "feature" of my app) showing a quick experiment with the D3D11 viewport to the upper-left, and a GDI DrawEdge call for a potential "window" along the bottom of the buffer.

[attachment=21411:capture.png]

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