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

  • SEARCH
  • Home
  • 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 7506887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:22:42+00:00 2026-05-29T22:22:42+00:00

I’m not allowed to use a struct with the in keyword, am I? For

  • 0

I’m not allowed to use a struct with the in keyword, am I? For example:

struct Rect {
    float x,y,width,height;
};

layout(location = 7) in Rect TexSrc;

It’s difficult to Google, but I get an error when I try to use my GLSL shader (INVALID_OPERATION). It appears I’m allowed to use float[4] however.

If I’m not allowed to use a struct, what do you suggest I do? Construct the struct out of a float[4], or suck it up, forgo the nice API, and use indices 0-3 everywhere?

(A vec4 would work here as well, I know, but z and w don’t have quite the same meaning as “width” and “height”, and this is only one example)

I suppose you can only specify a single type per location with glVertexAttribPointer, so I can see why a struct would be disallowed… I’m just trying to think of a way to keep my code clean and ledgible without compromising performance.

  • 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-05-29T22:22:43+00:00Added an answer on May 29, 2026 at 10:22 pm

    You cannot have vertex shader inputs of structs.

    The correct way to do this is to just stick them in a vec4. If you use a float[4], this will require four attributes instead of just one. Arrays always take up one attribute per element. So if you do layout(location = 7) in float[4] TexSrc;, this will take up the attribute indices 7, 8, 9, and 10. That’s an awful waste of attributes, and it could degrade performance.

    Just use a vec4 like everyone else. People pack inputs in vec4s all the time; they use comments to explain any semantic oddities.

    BTW, if you’re getting an invalid operation, that probably means you didn’t actually check to see if your shader compiled and linked properly. You should always do that.

    New stuff

    OpenGL 4.4 or the ARB_enhanced_layouts extension, allow you to do something like this.

    As previously stated, the main problem with layout(location = 7) in float[4] TexSrc; is that it takes up 4 input locations. So if you have 4 floats that aren’t really a 4D vector, you still have to pack them into a vec4 for shipping into the shader:

    layout(location = 7) in vec4 rect;
    

    This makes it a lot harder to know what rect.z means in the shader, since it doesn’t have any explicit meaning.

    4.4/enhanced_layouts allow you to pack multiple variables in a single location, so long as their components don’t overlap. So if each location is conceptually a vec4, we can split that into 2 vec2s:

    layout(location = 7, component = 0) in vec2 rectPos;
    layout(location = 7, component = 2) in vec2 rectSize;
    

    Now we get some semantic information. rectPos is the position of the rectangle, while rectSize is its size. And it still only takes up one location.

    The enhanced layouts feature allows this to work for any inputs and outputs, not just vertex shaders.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and

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.