Author Topic: Panels and Draw Calls  (Read 15971 times)

n3k0san

  • Guest
Panels and Draw Calls
« on: April 17, 2012, 03:25:04 AM »
Hello again

Currently in my HUD I have 4 anchors, since the GUI elements are positioned relatively so they switch nicely on any resolution.
The anchors are called "Center, Top-Left, Top-Right ant Top-Center". This is also their position on screen (and the value for their "Side" property).
Now, every anchor has a Panel as a child, with several widgets in it. In the UIPanel script, I can also see the number of "Draw calls" and "Widgets".
Even though it says 1 draw call, this is per panel, from what I see. So 4 panels means 4 draw calls.

In the Statistics Window, in the "Draw calls" value, I can see this decreasing if I deactivate panels one by one while the game runs.
Is there any way to make this all take 1 draw call? Or maybe we only have 1 draw call per panel or per anchor and I did not understand it right.

Anyway, currently I have between 32-34 draw calls, and if I disable the NGUI GUI completely, I get around 22 draw calls, which is quite an improvement for a mobile game. Question is, what am I doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panels and Draw Calls
« Reply #1 on: April 17, 2012, 04:37:05 AM »
Structure your UI like this:
UIRoot
- UIPanel
-- UIAnchor (Left)
--- Widget 1
--- Widget 2
--- Widget 3
-- UIAnchor (Center)
--- Widget 1
--- Widget 2
--- Widget 3

n3k0san

  • Guest
Re: Panels and Draw Calls
« Reply #2 on: April 17, 2012, 05:42:57 AM »
I changed the structure. Now All my anchors are a child of MainPanel and I removed the panels I had in the anchors...

I still get the same draw calls number.

I attached 2 screens. Draw calls number with GUI enabled, and without GUI.
As you can see the GUI eats about 8 draw calls...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panels and Draw Calls
« Reply #3 on: April 17, 2012, 05:43:55 AM »
Do you use different atlases?

n3k0san

  • Guest
Re: Panels and Draw Calls
« Reply #4 on: April 17, 2012, 05:46:21 AM »
No. It's 1 atlas for the hud

dlewis

  • Guest
Re: Panels and Draw Calls
« Reply #5 on: April 17, 2012, 05:59:46 AM »
If you open the Panel manager window (I don't have NGUI at home so I can't tell you the proper name unfortunately) it will tell you how many draw calls are being made per panel, that might help diagnose where the draw calls are coming from.

n3k0san

  • Guest
Re: Panels and Draw Calls
« Reply #6 on: April 17, 2012, 06:12:01 AM »
At the moment there are 2 UIPanel scripts. One is attached to GUI, which is also the UIRoot. This was attached automatically when I created the UI.
This one says I have 0 draw calls and 0 widgets.
The only other panel used is "MainPanel", which says "1 draw call and 13 widgets". (It's 11 widgets during play since 2 of them are hidden at start).

If it's only 1 draw call why do I gain 8 draw calls once I hide the GUI gameobject alltogether?

n3k0san

  • Guest
Re: Panels and Draw Calls
« Reply #7 on: April 17, 2012, 10:40:40 AM »
Figured out what the issue was...

I had 2 cameras. One for the GUI, one for the Game.

The GUI elements were placed at 0,0,0 in the center of the map, but they were still in the game camera's view frustrum (even if they were hidden by game geometry), and so were drawn both in the GUI, and in the Game.
So what I did was to set a layer for the menu elements and remove this layer from the Game camera's culling mask.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Panels and Draw Calls
« Reply #8 on: April 18, 2012, 02:27:37 AM »
Ah heh, yeah, this is something that happens ofte, since you can't see the UI in the "big" game camera since the whole thing is inside of about 1 pixel on that. I had that issue too. :)

kfboelter

  • Guest
Re: Panels and Draw Calls
« Reply #9 on: August 21, 2013, 10:02:12 PM »
Structure your UI like this:
UIRoot
- UIPanel
-- UIAnchor (Left)
--- Widget 1
--- Widget 2
--- Widget 3
-- UIAnchor (Center)
--- Widget 1
--- Widget 2
--- Widget 3

I feel I MUST ask this..
But why does NGUI automatically creates a Panel as child of an Anchor, if that is not the best structure to be used?

I took a little while before understanding why I was getting multiple draw calls when using same materials.. answer was: because I was using one panel per anchor :/

Still.. NGUI rocks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panels and Draw Calls
« Reply #10 on: August 22, 2013, 11:06:02 AM »
Whether the panel should be below the anchor or above it depends on the kind of UI you're making. Moving panels is more efficient than moving anchors. For a simple UI, it's easy to put the panel either on the anchor, or above it. For more complex UI where you have multiple anchor points and multiple windows, it makes sense to create a panel for each window.

kfboelter

  • Guest
Re: Panels and Draw Calls
« Reply #11 on: August 22, 2013, 02:35:01 PM »
Great piece of info!