- Home /
GUI Performance & Texture Atlasing
I've been developing my RPG, and have had awful performance with the GUI System. It really lowers my FPS, and I'm trying to find a way to improve the performance but I have a few questions.
GUI Off:
GUI On:
I was looking into reducing draw calls by using a texture atlas. I have the same texture repeated 10 times in a row right next to eachother (The buttons on the bottom right of my GUI) and it still uses 10 draw calls, rather than 1. Does texture atlasing actually reduce the draw calls and improve the performance of the GUI?
I am not drawing very much on the screen, 10 buttons with 10 images on the buttons, 3 images for the minimap, and about 5 images for the chatbox and a few labels. I think that's very little to be drawn on the screen, and it's really destroying my FPS. What could be the cause?
Here is a little bit of code drawing the buttons on the bottom right.
//Draws tabs
private void DrawTabs ()
{
GUI.DrawTexture (new Rect (Screen.width - 1, Screen.height - Config.TAB_BUTTON_HEIGHT, 1, Config.TAB_BUTTON_HEIGHT), tabBackground [3]);
int activeTabIndex = 0;
for (int i = 0; i < Config.MAX_TABS; i++) {
//Checks to see if tab is enabled
if (!tabSystem.isTabEnabled (i))
continue;
int x = Screen.width - ((activeTabIndex + 1) * Config.TAB_BUTTON_WIDTH) - 1;
int y = Screen.height - Config.TAB_BUTTON_HEIGHT;
Rect rect = new Rect (x, y, Config.TAB_BUTTON_WIDTH, Config.TAB_BUTTON_HEIGHT);
GUIButtonSystem.TextureButtonHover2 (rect, tabBackground [0], tabBackground [1], tabSystem.getCurrentTab () != i ? "Open Tab" : "Close Tab", "", ClickTab, i);
if (tabSystem.getCurrentTab () == i) {
GUI.DrawTexture (rect, tabBackground [2]);
}
if (tabIcons [(i * 2)] != null && tabIcons [(i * 2) + 1] != null)
if (tabSystem.getCurrentTab () != i)
GUIButtonSystem.TextureHover (rect, tabIcons [(i * 2)], tabIcons [(i * 2) + 1]);
else
GUI.DrawTexture (new Rect (rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4), tabIcons [(i * 2)]);
activeTabIndex++;
}
}
public static void TextureButtonHover2 (Rect rect, Texture buttonTexture, Texture buttonHoverTexture, string action, string name, RightClickHandler.menuActionDelegate del, int id)
{
bool inButton = rect.Contains (MousePositionHandler.getMousePositionVerticalSwitch ());
GUI.DrawTexture (rect, inButton ? buttonHoverTexture : buttonTexture);
if(inButton) {
RightClickHandler.addMenuItem(action, name, del, id, 0);
}
}
As you can see, I'm not doing anything too crazy with the code. Why is my performance so bad? All help is really appreciated.
The way I understand it, each GUI call generates a drawcall. Third-party solutions like NGUI and EZGUI use world object and a texture atlas to allow the drawcalls to batch. People in the know say that Unity's upco$$anonymous$$g new UI tools will be based on NGUI. In the meantime you are stuck either purchasing a third-party solution, or rolling your own solution using world objects if you want to reduce drawcalls in your UI.
Note if your row of icons on the lower right are what is causing your drawcalls, you could draw them as one texture and use your own hit detection code to figure out what was clicked. If there are state involved, you might need to have a number of combinations. Just a thought.
Unity really needs to release the new GUI system. It's really slow, and it's simply drawing images on the screen.