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

Started by
5 comments, last by Kija 18 years, 8 months ago
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.
The poorest programmer in the game industry!!
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
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(...);
The poorest programmer in the game industry!!
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
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.
Sirob Yes.» - status: Work-O-Rama.
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.
------------------------See my games programming site at: www.toymaker.info
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?

This topic is closed to new replies.

Advertisement