Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Points drawn with DrawPrimitive shaped by aspect ratio of view window


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Buckeye   Crossbones+   -  Reputation: 5698

Like
0Likes
Like

Posted 08 February 2014 - 08:46 PM

When points are drawn via the device pipline [DrawPrimitive(D3DPT_POINTLIST, ...)] in a swapchain, the shape of the point takes a shape (rectangular vs square) according to the aspect ratio of the swapchain view window. Other shapes drawn via the pipleline (mesh->DrawSubset) and via a shader (effect) appear correctly. The points exhibit that behavior whether drawn in pixels or world units.

 

In the image below, all three views are separate swapchain child windows of the main window. Note the sphere (ID3DXMesh) is not distorted (nor are other objects). The points, as can be seen, seem to appear with the aspect ratio of the view window. Shown here, the points are being drawn in world units.

 

point_display.png

 

Also shown in wireframe fillmode, the appearance is the same in solidfill.

 

As I'm (unsuccessfully) trying to figure out mesh picking in swapchain views, it appears that the points, when being rendered, are affected by the aspect ratio of the window associated with the swapchain, whereas other objects are not.

 

If it's important: I've tried it with hardware and software vertex processing, and with swapeffect = discard and  = copy.

 

Anyone have an explanation? Is this a bug perhaps?

 


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


Sponsor:

#2 Nik02   Crossbones+   -  Reputation: 2881

Like
0Likes
Like

Posted 08 February 2014 - 10:13 PM

In D3D, the viewport coordinates range is -1...1, regardless of the render target dimensions.

 

"Normal objects" usually compensate for this by scaling their perspective transform to match the aspect ratio.


Niko Suni


#3 Buckeye   Crossbones+   -  Reputation: 5698

Like
0Likes
Like

Posted 09 February 2014 - 07:51 AM

I'm not sure what you're saying with regard to points rendering. Could you clarify, please? Or are you saying that points are not "normal" objects?

 

Also, you say "objects" compensate for the aspect ratio. Do you just mean the aspect ratio is set by the current projection transform set for the pipeline, shaders, etc.? That's done, of course. For each swapchain, the projection matrix is setup with an aspect ratio of the render window client and is used by the pipeline and shaders. Although not shown in the image I posted, the same phenomenon occurs when the view matrix is also the same.


Edited by Buckeye, 09 February 2014 - 08:00 AM.

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


#4 unbird   Crossbones+   -  Reputation: 5590

Like
1Likes
Like

Posted 09 February 2014 - 10:33 AM

Actually, the D3D 9 viewport is in pixel-space (well, x and y at least). Normalized device coordinates are in [-1..1] (and [0..1] for z). But yes, aspect ratio is handled with the projection.
 
Point sprites ? I hear they have sometimes driver issues. Though you already checked software vertex processing, also try the reference device.
 
I'm concerned about that wireframe rendering though. Shouldn't the lines be continuous ? It really looks like you (still) have a rendertarget/window size mismatch (which then causes the squash of the points, too) ? I recommend doing (again) what Tispe recommended earlier, i.e. checking all relevant size information: client area, swapchain size, viewport, projection aspect ratio, Present parameters (if you're still using custom rectangles). Best dump it as text in every window and watch it live.
 
Or post your rendering code, maybe I see something.

#5 Buckeye   Crossbones+   -  Reputation: 5698

Like
1Likes
Like

Posted 09 February 2014 - 08:20 PM

@unbird - once again, you pointed out something that pointed to the resolution of the problem - the difference between the wireframe renderings. Turns out the problem was a combination of the viewport settings, projection matrix and the rectangles used by swapchain->Present all having to be set correctly (which I did not).

The app now displays correctly. For each window/swapchain pair:

1. get and set the swapchain backbuffer as the rendertarget

2. set the viewport to the window client size (cRect)

3. set the perspective projection matrix with the aspect of the window client size (use cRect)

4. set the view matrix as desired

(Render stuff with the device)

5. swapChain->Present(&cRect, NULL, handleChildWnd, NULL, 0); // cRect is same client rect used for setting the viewport

6. release the backbuffer

The problem arose simply because I did not match the viewport rectangle and the source rectangle in the Present call.

By the way, the swapchain backbuffer sizes (rendertargets) are always the size of the main window client, from which the device was made. So only if there is one child window the size of the main window client will the backbuffer size be the same as the child window size. I reset the device when the main window is resized with the normal sequence: OnLostDevice(), device->Reset, OnResetDevice. That's to ensure that the buffer size is always large enough for a single child window to render. It's kind of a pain because the swapchains are apparently created in D3DPOOL and all have to be released and recreated.

Now that it's all working, for my purposes, I'm not quite sure what the real benefit of multiple swapchains may be, unless they share a common buffer (?). That would be a memory advantage, I suppose. As you mentioned elsewhere, unbird, it may be possible to use a single swapchain for several windows.


 


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


#6 Buckeye   Crossbones+   -  Reputation: 5698

Like
0Likes
Like

Posted 10 February 2014 - 04:46 PM

Update - I eliminated the swapchains altogether. For each visible child window, my DrawScene routine sets the viewport size to the size of the child's client rect. The projection is set with the aspect ratio of the child window. After gd3ddevice->EndScene():

 

gd3ddevice->Present( &cRect, &cRect, hChildWnd, 0);


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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS