What are the locations of the attributes for the fixed function pipeline in the OpenGL 4.0 ++ kernel profile?

I would like to know the location of the attributes inside a fixed pipeline (no shader) for nVidia OpenGL drivers:

glVertex = 0
glColor = 3
glNormal = ?
glTexCoord = ?
glMultiTexCoord 0..7 = ?
glSecondaryColor = ?
glFog = ?

      

Empirically I've found the vertex and primary color arrangements, but it will still be good to know all of them.

If you want to know why, then for compatibility reasons and even for GLSL debugging (just to check if I am not passing in the correct data to fix locations when the shader is not running yet), etc.

+2


source to share


2 answers


Outside of NVIDIA drivers, this doesn't work (reliably). The corresponding drivers will only be an alias glVertexPointer (...)

for the slot 0 attribute . NV in their infinite wisdom developed a standard non-standard schema many years ago where they flattened all fixed function pointers at certain attribute locations, but I don't know if the new NV drivers support this (I honestly never bothered to try , it's such a bad practice). You can still find NV documentation for your alias mappings, but you are not using anything by taking advantage of their non-standard behavior.

While other drivers may also look like fixed function pointers to common vertex attribute attributes, there is no documentation for their mappings. Unlike NV, I would not believe the mapping will not change between driver versions, hardware, or platform. In fact, even using NV drivers, you shouldn't be using this - it is intended to support old support, not as a feature used for new software.

The bottom line is used in place of the use of the common attributes of vertices or using compatibility profile and GLSL version, which still maintains a pre-declared variables that are specifically designed to obtain data of the vertex function with a fixed function (eg gl_Color

, gl_Normal

, gl_MultiTexCoord0...7

, ...). But don't mix and match how you describe.

It also takes some time to browse glGetPointerv (...)

. If you want information about fixed function pointers outside of GLSL, this is the right way to do it. Do not rely on vertex attribute aliasing, as the concept of attribute layout is in principle a programmable function of the pipeline. It didn't even exist in unbuilt OpenGL until 2.0 (it was introduced with ARB Vertex assembly language and promoted to the kernel with GLSL).




Update:

While I still highly recommend using this information, I was able to find exactly what you wanted:

Release Notes for Shading Language Support for NVIDIA OpenGL - November 9, 2006 - pp. 7-8

Vertex Attribute Attribution

GLSL tries to eliminate vertex attribute overlays, but this is an integral part of NVIDIA's hardware approach and is necessary to ensure compatibility with existing OpenGL applications that NVIDIA customers rely on.

     

Thus, the GLSL implementation of NVIDIAs does not allow inline vertex attributes to clash with shared vertex attributes that are assigned to a specific vertex attribute index with glBindAttribLocation . For example, you should not use gl_Normal (the built-in vertex attribute), nor should you use glBindAttribLocation to bind a generic vertex attribute named "whatever" to vertex attribute index 2 , since gl_Normal aliases are indexed 2 .

  Table excerpt

In case you are interested, this is also stated in Table X.1 of the ARB Vertex Program specification . The only reason I mentioned NV is because they chose to reuse aliases in GLSL, whereas compatible implementations from other vendors will only do the first alias ( glVertexPointer (...)

up to 0 ) in GLSL.

+12


source


I've moved this answer from the duplicate and deleted question using the vertex attribute index 0 instead of the fixed function attribute GL_VERTEX_ARRAY, here.


If the OpenGL extension is valid, then there is a mapping between fixed function attributes and attribute indices: ARB_vertex_program; Modify Section 2.7, Vertex Specification

ARB_vertex_program; Modify Section 2.7, Vertex Specification

Setting a common vertex attribute to zero points to a vertex; the four vertex coordinates are taken from attribute values ​​zero. A Vertex2, Vertex3, or Vertex4 command is fully equivalent to the corresponding zero-indexed VertexAttrib command. Setting any other common vertex attribute updates the current attribute values. There are no current values ​​for a null vertex attribute.

Implementations can optionally use the same store for the current values ​​of common and some traditional vertex attributes . If any common vertex attribute other than zero is specified, the current values ​​for the corresponding common attribute in Table X.1 are undefined. In addition, when a normal node attribute is specified, the current values ​​for the corresponding common node attribute in Table X.1 are undefined. For example, setting the current normal value will leave the shared attribute of vertex 2 undefined, and vice versa.

| Generic Attribute |  Conventional Attribute  | Conventional Attribute Command |
|-------------------|--------------------------|--------------------------------|
| 0                 | vertex position          | Vertex                         |
| 1                 | vertex weights 0-3       | WeightARB, VertexWeightEXT     |
| 2                 | normal                   | Normal                         |
| 3                 | primary color            | Color                          |
| 4                 | secondary color          | SecondaryColorEXT              |
| 5                 | fog coordinate           | FogCoordEXT                    |
| 6                 | -                        | -                              |
| 7                 | -                        | -                              |
| 8                 | texture coordinate set 0 | MultiTexCoord(TEXTURE0, ...    |
| ...               |                          |                                |

      

This means that there is a "mapping" between a vertex attribute 0 and a fixed function attribute GL_VERTEX_ARRAY

, but not necessarily a mapping for any other vertex attribute.


Nvidia goes one step further as stated in the Release Notes for NVIDIA OpenGL shader language support; November 9, 2006; - from. 7-8 .
There is an actual correspondence between the fixed function attributes and the vertex attribute indices as indicated in the table above.
See also the answer to the question " What are the attribute locations for the fixed function pipeline in OpenGL 4.0 ++ main profile"?

I did some testing and found that the following code works on an Nvidia GeForce 940MX but does not work on an integrated Intel (R) HD Graphics 620.

The triangle is indicated as follows

static const float varray[]
{ 
  // x        y         red   green blue  alpha
    -0.707f, -0.75f,    1.0f, 0.0f, 0.0f, 1.0f, 
     0.707f, -0.75f,    1.0f, 1.0f, 0.0f, 1.0f,
     0.0f,    0.75f,    0.0f, 0.0f, 1.0f, 1.0f
};

      

can be drawn without any shader, with glEnd

sequence glBegin

/ glEnd

,

glBegin( GL_TRIANGLES );
for ( int j=0; j < 3; ++j )
{
    glVertex2fv( varray + j*6 );
    glColor4fv( varray + j*6 + 2 );
}
glEnd();

      



by specifying the attributes of the fixed function,

glVertexPointer( 2, GL_FLOAT, 6*sizeof(*varray), varray );
glColorPointer( 4, GL_FLOAT, 6*sizeof(*varray), varray+2 );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glDrawArrays( GL_TRIANGLES, 0, 3 );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );

      

and specifying an array of common vertex attributes with indices 0 and 3, with corresponding fixed attributes of functions GL_VERTEX_ARRAY

and GL_COLOR_ARRAY

for Nvidia equipment:

glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 6*sizeof(*varray), varray );
glVertexAttribPointer( 3, 4, GL_FLOAT, GL_FALSE, 6*sizeof(*varray), varray+2 );
glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 3 );
glDrawArrays( GL_TRIANGLES, 0, 3 );
glDisableVertexAttribArray( 0 );
glDisableVertexAttribArray( 3 );

      


The same code will be run with the following OpenGL 2.0 shader program,

Vertex shader

#version 110

varying vec4 vertCol;

void main()
{
    vertCol     = gl_Color;
    gl_Position = gl_Vertex;
}

      

or the following OpenGL 4.0 shader program:

Vertex shader

#version 400

layout (location = 0) in vec3 inPos;
layout (location = 3) in vec4 inColor;

out vec4 vertCol;

void main()
{
    vertCol     = inColor;
    gl_Position = vec4(inPos, 1.0);
}

      

The Fragment shader works in both of the above cases (for the sake of completeness):

#version 400

in vec4 vertCol;

out vec4 fragColor;

void main()
{
    fragColor = vertCol;
}

      

+1


source







All Articles