• Advertisement
Sign in to follow this  

More Efficient Way?

This topic is 4312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to draw lines in D3D9 with a custom width and height. Here is what I'm currently using: void FillRGBA(float x, float y, float w, float h, int r, int g, int b, int a) { D3DXVECTOR2 vLine[2]; ID3DXLine *pLine; pLine->SetWidth( w ); pLine->SetAntialias( false ); pLine->SetGLLines( true ); vLine[0].x = x + w/2; vLine[0].y = y; vLine[1].x = x + w/2; vLine[1].y = y + h; pLine->Begin( ); pLine->Draw( vLine, 2, D3DCOLOR_RGBA( r, g, b, a ) ); pLine->End( ); } I know there is a better way that causes less Frame Lag. I just can't figure out how I could do it. I would reallllyyy appreciate it if someone could help! :-)

Share this post


Link to post
Share on other sites
Advertisement
ID3DXLine, from what I'm reading on MSDN is a wrapper which renders using textured triangle primitives. I don't see why it would be slow.

The problem, then, is probably somewhere in your code - how often are you calling D3DXCreateLine? Are you calling your FillRGBA function every pass?

I'm not sure how ID3DXLine handles lots of lines, but I have a feeling you might get better performance (with a lot of lines) by just using triangle lists and shoving them all into one big vertex buffer. This would reduce all your drawing calls to a single call.

Additionally, if the lines are static, then you only need to be rendering them every pass - not creating them or setting positions. This is where I'm assuming your bottleneck is - if you spend time tinkering with them every pass you're going to waste cycles.

Finally, you may want to re-address your need for variable-width lines.

Share this post


Link to post
Share on other sites
Agreed. Anything drawn one by one will be slow. You don't draw your meshes by making a drawing call for each triangle, and you shouldn't draw your lines one by one, either. Begin() and End() are there to put a bunch of lines between them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement