1
votes

I have a Direct2D native application written in C++. The render function is called about 60 times per second, and it is aimed at displaying around 1,000 graphic geometries (essentially ellipses). Following is the code of the rendering function:

void Render()
{
    pRenderTarget->BeginDraw();
    pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::Black));

    const auto transform = D2D1::Matrix3x2F::Identity();
    pRenderTarget->SetTransform(transform);

    // draw all entities
    for (auto& e : entities)
    {
        if (e)
            e->Draw(pRenderTarget, transform);
    }

    pRenderTarget->EndDraw();
}


void Entity::Draw(ID2D1RenderTarget* pTarget, const D2D1_MATRIX_3X2_F& worldTransform) const
{
    pTarget->SetTransform(transform * worldTransform);
    pTarget->FillEllipse(ellipse, pBrush);
    pTarget->SetTransform(worldTransform);
}

Brushes, ellipses and transformations are created at the beginning (entity construcor).

My question is if it is normal that with these parameters my CPU is always around 8/9%. I'd have expected a value close to 0 (if I comment the render function the CPU usage drops to 0, even if the Update function, for example, is always called).

2

2 Answers

1
votes

If your geometry is static (doesn't change every frame), take a look at using geometry realizations. This should dramatically lower the CPU cost of rendering larger numbers of primitives. If you need even more performance, you can also try using a sprite batch; this may be the fastest way of rendering a large number of shapes, provided you can store the shape(s) in a bitmap and don't need per-primitive anti-aliasing.

0
votes

In my similar test application. I call repaint every 20 ms via the timer. In paint event, i draw 1000 rectangles with linear gradient brush and bitmap.

In result: each frame drawing over 20ms and CPU usage over 10-13%.

Answer: I think that it is quite normal.