Jump to content
  • Advertisement
Sign in to follow this  
pcwlai

In DX9, draw own UI with Draw*UP or?

This topic is 4829 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

Currently, I am using Draw*UP (2 triangles to form a rectangle) and texel to pixel texture coordinates to draw the user interfaces. I found it a bit slow when I need to draw quite a few UI with lots of elements on them. So, I revised the presentations and technical documentations from nVidia. Most of them points out that, using Draw*UP would stall and slow the GPU (especially for the parallelism with CPU). So, is there any way to optimizr it or is there any way to draw the user interface exact with Draw* only? Thanks for the advice.

Share this post


Link to post
Share on other sites
Advertisement
The best way to do this would be to store all of them in one vertex buffer. The Draw* instructions allow you to specify a start point and how many verts to render. This is a lot faster in that you don't have to switch vertex buffers, which is VERY slow. If this isn't what you want, some sample code would be nice.

Hope this helps,
ProgrammingNerd

Share this post


Link to post
Share on other sites
My current method is to call DrawPrimitivesUP with 2 triangles forming a rectangle with a single texture as the background (or design) of the window (or form).

Besides to draw the basic background, I use this method to draw information and text (I need to draw Asian languages).

e.g.

// Draw the background with 2 triangles and the background texture
SetTexture(...);
DrawPrimitivesUP(...);

// Draw the HP words (in Asian languages) with 2 triangles and the text texture
SetTexture(...);
DrawPrimitievsUP(...);

// Draw the HP bar with 2 triangles and the bar texture
SetTexture(...);
DrawPrimitievsUP(...);

Share this post


Link to post
Share on other sites
Use the ID3DXSprite interface to draw sprites; it is extrodinarily fast for this kind of work. Of course, you don't have to.

You can use DrawIndexedPrimitiveUP to draw multiple sprites stored in one vb

Syntax:

HRESULT DrawIndexedPrimitiveUP(
D3DPRIMITIVETYPE PrimitiveType,
UINT MinVertexIndex,
UINT NumVertexIndices,
UINT PrimitiveCount,
const void *pIndexData,
D3DFORMAT IndexDataFormat,
CONST void* pVertexStreamZeroData,
UINT VertexStreamZeroStride
);

Notice the 2nd and 3rd parameters. You can set the starting vertex in the 2nd param and the number of verts in the third.

Hope this helps,
ProgrammingNerd

Share this post


Link to post
Share on other sites
In almost any case, using the UP equivalents won't hurt performance even moderatly. I think in most cases, the performance decrease won't even be noticed.

Despite this, it would still be a very good idea to use one DrawPrimitiveUp to draw as many triangles as possible (This applies the same for the non-UP versions). If possible, try making a triangle buffer (doesn't have to be a VB) and using one DrawPrimitiveUp to draw them all.

Lastly, as mentioned, the DX9 sprite interface is a hoot, so unless you've got a reason not to use it (like wanting to learn how to do stuff yourself) I'd definatly recommend it.

EDIT:
You also mention having several different textures for you HUD. If possible, I'd recommend using a single texture which contains several different textures grouped together, and using texcoords to select the right section out of it. This is made even simpler with the Sprite interface, as it allows you to use pixel units to pick the source rectangle.
Doing this would reduce your calls to SetTexture (or D3DXSprite's calls to it) which would, in turn, increase performance.

Share this post


Link to post
Share on other sites
Yes I would recommned the sprite interface, the whole UI in my T2 program uses this method and it is very fast. I had tried many methods like you before but found the d3dxsprite interface faster than what I had written. Make sure when using it you allow it to batch well etc.

Share this post


Link to post
Share on other sites
I'm also about to implement a GUI system, similar to DXUT. I was thinking of doing it with vertex buffers but then I read this and I'm considering the ID3DXSprite interface, after checking the (HUGE) code from DXUT it seems like they are using it too, though they have some Draw*UP calls aswell O.o

To get to the point, I haven't found much any information about ID3DXSprite, it seems pretty easy and straightforward though. However, Trip99, you said "Make sure when using it you allow it to batch well etc.", could you explain what you mean or point to good information about it?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!