Sign in to follow this  

Best way to render GUI widgets in Direct3D?

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

Hi folks, I am at the point where my GUI engine mechanics are working decently now, as shown in a snap demo i released last week ( Download ui_demo_6.zip. However, if you will notice, the application is slow. A system hog even on high-end computers. This is due to my inefficient way of rendering the components making up the GUI. Currently i am locking and unlocking vertices every frame to define quads that represent the 2D sprites of the GUI. And every component (button or dialogbox) is composed of 9 quads - 4 corners, 4 edges, and center square. With lots of windows, buttons and other GUI component that are active simultaneously, frame rate can really drop significantly. I would really appreciate if anyone can share with me how they approach rendering in their GUI systems. Thanks in advance. Here is a snapshot of the demo by the way: Photo Sharing and Video Hosting at Photobucket [Edited by - harmless on September 18, 2007 2:05:03 PM]

Share this post


Link to post
Share on other sites
Currently I am working on a GUI system too, and I'm following Chad Vernon's approach on his GUI tutorial for the CUnit engine. This works by defining a Quad element, and every component has a property to return the list of quads it implements.

The is a class which acts as a GUI manager, which holds the Render method for the entire GUI subsystem. This class has a vertexBuffer (the only vertex buffer for the entire GUI, instead of a vertex buffer for each component). When the render method is called, we collect the Quads from all the controls currently on display into a single vector, and then we render this vector. This way we just need to lock the vertex buffer once.

Hope that helps.. chers!
Pablo

Share this post


Link to post
Share on other sites
Ensuring you have the correct usage and lock flags when manipulating the data can make a huge difference.

Using "bounded buffer" tricks? This can help hide the GPU stalling but introduce 1-2 frames of latency.

Also, and the biggest improvement I ever achieved, is temporal optimization. Do you really need to modify things every frame? If it hasn't changed since the last time you rendered why are you re-writing the vertex data? (etc...)

hth
Jack

Share this post


Link to post
Share on other sites
Wow Pablo, i google'd Chad Vernon and found his blog site. Amazing Demo reel!

Jack, thanks for the reply. If you remember the old versions of directx 8.1+, there's a CD3DFont class that was popular back then because D3DXFONT was using GDI that time still. The technique in rendering glyphs in that class is how i render the quads for my UI engine.

I created a "Tile" class where it initializes a fixed size vertex buffer. This is how i render:

1. I have a begin() function to lock the vertices and initialize vertex and triangle counter.

2. Upon a call to GUI engine's Render() function, it iterates all the components of the UI then one by one it passes its rectangular coordinates to my Tile class Draw() function. Draw() function then sets the coordinates to vertex buffer. Since every widget is composed of 9 quads, it uses up to 54 vertices. Once vertices are programmed, i increment my vertex counter to monitor how many vertices i already used.

Then on the next call of Draw(), it checks if i still have enough vertex buffer to program the next set of coordinates. If it's not enough, then i call End() to render the programmed vertices and reset my counter. Then call Begin() again to continue programming the remaining widgets.

3. Then i have an End() function unlock the vertex buffer, render the triangles based on triangle counter, and finally reset the counter.

I am not too sure if this is a good way to render my widgets. If this seems promising, then i'll stick to it and try to optimize as much as i can. My concern here is that i only lock the vertices once (provided i set my vertex buffer size to be large enough) which is good. However, i read somewhere that if i lock the vertex buffers for too long, it will be bad because it stalls the CPU for a long time.

I kinda notice it though, when i push 100 dialog boxes in the screen, the frame rate is still fine but windows randomly gets stucked i cannot drag them.

Share this post


Link to post
Share on other sites

This topic is 3739 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this