Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Inquiry about attribute locations in glsl  (Read 1373 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Kernel


Medals: 438
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Posted 2014-03-12 02:36:25 »

I have the following code in my application:
1  
2  
3  
positionLocation = glGetAttribLocation(pid, "position");
normalLocation = glGetAttribLocation(pid, "normal");
texCoordsLocation = glGetAttribLocation(pid, "texCoords");


positionLocation = 2
normalLocation = 0
texCoordsLocation = 1

Can someone explain the logic to how these locations are assigned their values? I would think they would be assigned chronologically... but I guess not.

First Recon. A java made online first person shooter!
Offline TeamworkGuy2

Junior Devvie


Medals: 10



« Reply #1 - Posted 2014-03-12 03:56:59 »

The short answer is that the OpenGL graphics driver picks these values when it compiles the shader.
The long answer, buried somewhere in the Graphics driver, could relate to any number of variables including how the variables are used in the shader, what data types they refer to, which appear first in shader, their alphabetical names, etc...  Clueless
Offline The Lion King
« Reply #2 - Posted 2014-03-12 04:30:13 »

I believe it's random, but you can always assign the location in GLSL like so.

1  
2  
3  
layout (location = 0) in vec4 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 texCoord;

"You have to want it more than you want to breath, then you will be successful"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #3 - Posted 2014-03-12 05:40:24 »

only in modern GSLS version, I don't know atm 3.3 maybe.
Offline The Lion King
« Reply #4 - Posted 2014-03-12 05:49:38 »

only in modern GSLS version, I don't know atm 3.3 maybe.

GLSL 1.40 which was released with openGL 3.1 .

Good point

"You have to want it more than you want to breath, then you will be successful"
Offline quew8

JGO Knight


Medals: 53



« Reply #5 - Posted 2014-03-12 23:02:25 »

And pre GLSL 1.4 you can assign it in the program with glBindAttribLocation(): http://www.opengl.org/sdk/docs/man2/xhtml/glBindAttribLocation.xml
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1675 views)
2018-06-10 19:43:48

EgonOlsen (1723 views)
2018-06-10 19:43:44

EgonOlsen (1161 views)
2018-06-10 19:43:20

DesertCoockie (1588 views)
2018-05-13 18:23:11

nelsongames (1189 views)
2018-04-24 18:15:36

nelsongames (1717 views)
2018-04-24 18:14:32

ivj94 (2542 views)
2018-03-24 14:47:39

ivj94 (1767 views)
2018-03-24 14:46:31

ivj94 (2848 views)
2018-03-24 14:43:53

Solater (973 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!