Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by fullspeed · Mar 29, 2017 at 03:19 PM · renderingglquads

Why drawing GL quads is so slow?

Hi, in my game I'm trying to draw a curve with a specified width. I divided it to small rectangle pieces. I'm using GL.QUADS from this example https://docs.unity3d.com/ScriptReference/GL.QUADS.html. Everything works fine on PC Windows, but when I try to run it on my Xperia E4G the game crashes or plays at really low fps. There are around 300 quads at the same time rendered. Here is my rendering function:

 void OnPostRender()
     {
         GL.PushMatrix();
         GL.LoadProjectionMatrix(GetComponent<Camera>().projectionMatrix);
         var node = extendedNodes.First;
         while (node != null)
         {
             GL.Begin(GL.QUADS);
             GL.Color(new Color(0, 199, 0));
             for (int i = 0; i < 4 && node != null; i++)
             {
                 GL.Vertex(node.Value);
                 node = node.Next;
             }
             GL.End();
         }
         
         GL.PopMatrix();
     }

Have you got any ideas why the problem exists (I thought that calling GL functions should be fast, I don't want to use LineRenderer because it is slow too)?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Mar 29, 2017 at 04:07 PM 0
Share

I'm wondering if it wouldn't be faster just to make a $$anonymous$$esh and let Unity draw it? For that matter, you could probably speed up what you have using GL tri-strips.

Usual caveat: only if what you have isn't good enough already.

avatar image fullspeed Owen-Reynolds · Mar 29, 2017 at 08:12 PM 0
Share

Thanks for commenting. Curve is generated by a mathematical function and it will be rendered continously through whole game level (of course only visible part will be rendered). If you know any other faster method let me know :)

avatar image Owen-Reynolds · Mar 29, 2017 at 11:49 PM 1
Share

Just with the method you're using now, switching to GL.Begin(TRI_STRIP) should be a speed-up. You send every vertex once, ins$$anonymous$$d of twice (but you have to figure out how they work. You'd be faking a quad-strip using a tri-strip.)

If the curve changes every frame, looking at the Unity $$anonymous$$esh class doesn't seem worth it.

avatar image fullspeed Owen-Reynolds · Mar 30, 2017 at 07:30 AM 0
Share

Thanks, I changed to TRI_STRIP and it seems to be faster now.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by fullspeed · Mar 29, 2017 at 12:13 PM

I figured out what was wrong... I was calling GL.Begin(GL.QUADS) every 4 vertexes I was drawing. Here is fixed code:

 void OnPostRender()
     {
         GL.PushMatrix();
         GL.LoadProjectionMatrix(GetComponent<Camera>().projectionMatrix);
         GL.Begin(GL.QUADS);
         GL.Color(new Color(0, 199, 0));
         var node = extendedNodes.First;
         while (node != null)
         {
             GL.Vertex(node.Value);
             node = node.Next;
         }
         GL.End();
         GL.PopMatrix();
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

URP Doesn't Pass Camera.Current to OnRenderObject? 0 Answers

How do you draw a GL quad facing the camera? 0 Answers

fastest way to draw millions of lines? 1 Answer

GL QUADS are being painted with the wrong color 0 Answers

Two transperent object overlapping problem! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges