Does OpenGL/GLES has a default vertex attribute format?

I tried to find an answer from GL spec for the following question, but didn’t. So, help needed.

Does OpenGL/GLES has a default vertex attribute format? If the app binds a vertex buffer, but not call glVertexAttribFormat or glVertexAttribPointer to set the format, how should the driver interpret the vertex data in the buffer? Or what type of GL error should the app get? I’m talking about GLES 3.0 and above.

Thanks.

Every piece of state in OpenGL has a default and all of these defaults are documented in the specification.

you have specifically mentioned ES 3.0 and above, so I’ll cite from the ES 3.0.5 specification at https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf

Section 2.8, Vertex Specification, states:

The initial values for all generic vertex attributes are (0.0, 0.0, 0.0, 1.0).

So unless you have otherwise specified a value for a vertex attribute, it will have a value of (0.0, 0.0, 0.0, 1.0).

Section 2.9, Vertex Arrays, states:

In the initial state, the boolean values are each false, the memory pointers are each NULL, the strides are each zero, the array types are each FLOAT, the integers representing values per element are each four, the normalized and pure integer flags are each false, and the divisors are each zero.

Table 6.2: Vertex Array Object State, lists the initial enable/disable state for each vertex attrib array false, and we can see that this value is FALSE for VERTEX_ATTRIB_ARRAY_ENABLED. It also states that the arrays are initially configured as though no buffer object were bound.

So to summarize:

[ul]
[li]All vertex attribute arrays are disabled.[/li][li]Each is initialized to the equivalent of glVertexAttribPointer (n, 4, GL_FLOAT, GL_FALSE, 0, NULL);[/li][li]Buffer object 0 is “bound” for the each.[/li][/ul]

What happens if you attempt to read from such an array? Because no buffer object is associated with the array it’s equivalent to reading from a client-side pointer, and because the pointer is initially NULL, you can expect similar behaviour to what happens if you attempt to dereference a NULL pointer in the general case - or at least you would, if the array weren’t initially disabled. I cannot find a reference in the spec to what actually happens, so we may assume that it’s undefined behaviour.

What do you mean by “binds a vertex buffer”? You mention glVertexAttribFormat, so you probably have an understanding that glBindBuffer(GL_ARRAY_BUFFER, ...) does not associate a buffer object with a VAO. That only glBindVertexBuffer or glVertexAttribPointer following a GL_ARRAY_BUFFER binding will actually put the buffer object in the VAO.

Well obviously if you use glVertexAttribPointer, then you set both the buffer and the format, so it’s impossible to set the buffer without setting the format.

But if you’re using glVertexAttribFormat and its ilk, then the answer is simple: nothing.

The default values for the format (as mhagain correctly stated) are that all attributes are disabled. And the only attributes that get fetched at rendering time are the enabled ones. So, since all attributes are disabled, nothing will be fetched. And therefore, it doesn’t matter what buffers are attached to the VAO.

It is perfectly legal to render without attribute arrays. Granted, with the exception of gl_VertexID and gl_InstanceID, all of your VS invocations will get the same value. But that doesn’t mean you cannot manufacture vertex data from just those built-in attributes.

This is the information I’m looking for. Thank you, mhagain.

[QUOTE=Alfonse Reinheart;1288532]What do you mean by “binds a vertex buffer”?
[/QUOTE]

very helpful analysis of the problem, Alfonse. Sorry, my description of the usage case is not quite clear. I meant “binds a vertex buffer to a VAO”. So the situation is that the VAO has a VBO bound, and the corresponding vertex attribute is also enabled. In this case, if the app does not specify the vertex format, what is the default value? Thanks for the help. Now I know the expected default value should be:

Section 2.9, Vertex Arrays, states:[i]
In the initial state, the boolean values are each false, the memory pointers are each NULL, the strides are each zero, the array types are each FLOAT, the integers representing values per element are each four, the normalized and pure integer flags are each false, and the divisors are each zero.

[/i]