locked
Poor performance of ID2D1RenderTarget::DrawText method

    Question

  • We're developing a GIS app aimed at Windows store. Our app follows the Direct3D+XAML pattern and uses the SwapChainBackgroundPanel scheme. We call the ID2D1RenderTarget::DrawText method to display city/town/station names but find the text rendering performance is terrible. For example, when rendering 5000 strings, we see an unacceptable performance drop in our app, sweep zooming, panning no longer follow the input pointer (be it finger or mouse), UI is retarded too. Any ideas to improve the performance? thanks. Here is our code to call the ID2D1RenderTarget::DrawText method:

    void drawString(const wchar_t *str, float x, float y, float dx, float dy, float theta)
    {
       ComPtr<ID2D1SolidColorBrush> brush;
       D2D1_RECT_F rectf;
       float r, g, b, a;
       int num_char;
       float x_offset, y_offset;
    
       num_char = wcslen(str);   
       x_offset = dx >= 0 ? dx*char_width : dx*num_char*char_width;
       y_offset = dy*char_height;
    
       r = m_constantBufferData.penColor.r;
       g = m_constantBufferData.penColor.g;
       b = m_constantBufferData.penColor.b;
       a = m_constantBufferData.penColor.a;
       DX::ThrowIfFailed(m_d2dContext->CreateSolidColorBrush(D2D1::ColorF(r,g,b,a), &brush));
    
       rectf = D2D1::RectF(x+x_offset, y+y_offset, x+x_offset+num_char*char_width, y+y_offset+char_height);
    
       m_d2dContext->BeginDraw();
    
       m_d2dContext->SetTransform(
          D2D1::Matrix3x2F::Rotation(-theta, 
                                     D2D1::Point2F(0.5*(rectf.left+rectf.right), 0.5*(rectf.top+rectf.bottom))
          )
       );
    
       m_d2dContext->DrawText(str, num_char,  m_textFormat.Get(),  rectf, brush.Get());
    
       DX::ThrowIfFailed(m_d2dContext->EndDraw());
    }

     
    Friday, November 23, 2012 3:05 PM

Answers

All replies