4

I have a MFC program that use Direct2D to paint.
Below is a very simple version of the draw method that use FillGeometry to fill a triangle.

// AFX_WM_DRAW2D event handler
afx_msg LRESULT CChildView::OnDraw2d( WPARAM wParam, LPARAM lParam )
{
    CHwndRenderTarget* pclRenderTarget = (CHwndRenderTarget*)lParam;
    ASSERT_VALID( pclRenderTarget );
    // Clear window background
    pclRenderTarget->Clear( D2D1::ColorF( D2D1::ColorF::Red ) );

    const float fZoom = 0.2f;
    const float fOffset = 50000000;
    pclRenderTarget->SetTransform( D2D1::Matrix3x2F::Translation( D2D1::Size( -fOffset, -fOffset ) ) * D2D1::Matrix3x2F::Scale( fZoom , fZoom )  );

    CD2DPathGeometry clPath( pclRenderTarget );
    clPath.Create( pclRenderTarget );
    ID2D1GeometrySink* pclSink = clPath.Open();
    pclSink->SetFillMode( D2D1_FILL_MODE_WINDING );
    pclSink->BeginFigure( D2D1::Point2F( fOffset + 100,   fOffset + 100 ), D2D1_FIGURE_BEGIN_FILLED );
    pclSink->AddLine( D2D1::Point2F(     fOffset + 100,   fOffset + 10000 ) );
    pclSink->AddLine( D2D1::Point2F(     fOffset + 10000, fOffset + 100 ) );
    pclSink->EndFigure( D2D1_FIGURE_END_CLOSED );
    pclSink->Close();
    pclRenderTarget->FillGeometry( &clPath, m_pBlueBrush );
    return TRUE;
}

When I run the program it looks like this. enter image description here

As it can be seen the triangle has some red horizontal and vertical lines that should not be there.
I found that if I remove the D2D1_FILL_MODE_WINDING the triangle is filled without any lines as expected.
I have also found that if I reduced the Offset the lines get thinner and eventually disappear.
I have tried the program on different computers.

Lines shows on
* Windows 10 (1803) with Nvidia GeForce GTX 1050 Ti
* Windows 10 (1803) with AMD Radeon R9 370
* Windows 10 (1709) with Nvidia Quadro P400
* Windows 10 (1803) with Intel HD 5500

Lines do not show on
* Windows 10 (1803) with AMD FirePro2270
* Windows 7 with AMD Radeon 8790M / Intel
* Windows 10 (1803) in VirualBox

But I can not find any patteren in the behaviour.

Can somebody explain what maybe happening here?

First I was thinking it might be a driver bug, but because I see it with different graphics cards I am reluctant to accept this.

Update
This is the output I get in the Visual Studio Graphics Analyzer.
The lines show up in the first Draw.
enter image description here

Kennet
  • 323
  • 4
  • 12
  • Wild guess: `50000000` might be too large for `float` values. Try using much smaller scale and make use of precision points. – Barmak Shemirani Aug 14 '18 at 08:57
  • I have tried to see if the lines align with values that can be represented in a float but this is not the case. A float can store the values 50000100.0, 50000104.0, 50000108.0, 50000112.0 etc. so there should have been a lot more lines if this was the case. – Kennet Aug 14 '18 at 10:09
  • Have you enabled the [Direct2D Debug Layer](https://learn.microsoft.com/en-us/windows/desktop/direct2d/direct2ddebuglayer-portal)? Maybe it produces messages that provide helpful hints. The [Visual Studio Graphics Diagnostics](https://learn.microsoft.com/en-us/visualstudio/debugger/graphics/visual-studio-graphics-diagnostics) may also prove to be insightful in exposing the Direct3D calls your Direct2D code gets transformed to. – IInspectable Aug 14 '18 at 12:41
  • What does emitted mesh look like (you can inspect it using graphics debugger)? – user7860670 Aug 15 '18 at 08:56
  • I am not sure exactly what "emitted mesh" is but in the graphics debugger I can see a ID3D11DeviceContext->Draw(6,0) in the GPU Work view. When I select that the render target shows the first sign of the lines. – Kennet Aug 15 '18 at 12:01
  • Regarding the enabling of debug this is not so easy. Because I use the MFC encapsuling of Direct2D and in that the D2D1CreateFactory is done within _AFX_D2D_STATE::InitD2D so I can not change the debugLevel to D2D1_DEBUG_LEVEL_INFORMATION. – Kennet Aug 15 '18 at 12:08

0 Answers0