Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:28:37+00:00 2026-06-10T01:28:37+00:00

Possible Duplicate: Explicit vs Automatic attribute location binding for OpenGL shaders In another question

  • 0

Possible Duplicate:
Explicit vs Automatic attribute location binding for OpenGL shaders

In another question of mine one of the answers indicate I should use glBindAttribLocation and not allow the shader compiler to assign its own indices. I’m wondering why this is a recommended practice, what advantages does it have (or rather what disadvantages does not using it have)?

I do understand that if I have multiple programs which share attributes this makes sense, since I can switch between programs and not have to reset those attributes. However, for attributes which aren’t shared, or if my programs just don’t use such sharing, I don’t see that it is necessary to bind the index explicitly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:28:38+00:00Added an answer on June 10, 2026 at 1:28 am

    First of all I don’t think it’s a general recommendation to use explicit binding via glBindAttribLocation​ instead of glGetAttribLocation. That being said, these are the main reasons I stopped using glGetAttribLocation:

    First of all, this can cause unnecessary overhead. It all seems nice and well that you can use a readable names instead of numbers. ‘What the heck is attribute 7’ vs ‘oh right, attribute texture_coordinate’: I’ll explain first what the possible overhead can be and then why that last part doesn’t even make sense.

    If you need the attribute location often, the overhead of calling glGetAttribLocation can become non-negligible, depending on the driver. So to handle the general case you have to build a caching-system. Great, there goes my easy and readable method with names instead of numbers, I just had to write quite a lot of non-trivial wrapper code. Worse, you should really take care that you destroy the cache when the program becomes invalid, it’s quite likely you’ll do this wrong and end up with bugs. So we went from ‘nice readable names’ to ‘horrible buggy mess’.

    Even more, the ‘nice readable names’ argument is flawed. You can perfectly do something like the following for locations defined in the shader itself:

    const GLint vertex_loc_att = 0;
    const GLint texture_coord_att = 1;
    ...
    

    Or you can also use an associative container like this:

    attribute_locations["vertex_location"] = 0;
    attribute_locations["texture_coordinate"] = 1;
    ...
    

    This one you can also combine with glBindAttribLocation, just do this prior to linking:

    foreach name, location in attribute_locations
    {
        glBindAttribLocation(program_id, location, name);
    }
    

    Still very readable, no dynamic cache necessary, just some static variables that even might get optimized away.

    Then, you say it yourself: it obviously has it advantages when using multiple programs, I won’t repeat it here, because Kos explained that one in detail already. I’ll just answer one of your arguments:

    Attributes that don’t need sharing: This implies there are also attributes that need sharing, for which it is a big advantage that you use fixed locations. Why would you mix two location management approaches in one application? Keep yourself from a maintenance headache and stick with one, here obviously the predefined locations because you need them for the shared attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I create an automatic property (no private member) with get and
Possible Duplicate: What does the explicit keyword in C++ mean? explicit CImg(const char *const
Possible Duplicate: Cast string to enum with enum attribute I have a enum like
Possible Duplicate: When should I make explicit use of the this pointer? I'm wondering
Possible Duplicate: Specifying formula in R with glm without explicit declaration of each covariate
Possible Duplicate: C++ invoke explicit template constructor First imagine I have a class Data
Possible Duplicate: How do I create a directory and parent directories in one Perl
Possible Duplicate: Do you prefer explicit namespaces or 'using' in C++? I am a
Possible Duplicate: What does the explicit keyword in C++ mean? what does the keyword
Possible Duplicate: Explicit vs implicit SQL joins I have two queries in SQL Server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.