Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Does OpenGL/GLES has a default vertex attribute format?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    California
    Posts
    7

    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.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,668
    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/Ope...s_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:
    • All vertex attribute arrays are disabled.
    • Each is initialized to the equivalent of glVertexAttribPointer (n, 4, GL_FLOAT, GL_FALSE, 0, NULL);
    • Buffer object 0 is "bound" for the each.


    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.

  3. #3
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,892
    Quote Originally Posted by samwyi View Post
    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?
    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    California
    Posts
    7
    Quote Originally Posted by mhagain View Post
    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.


    This is the information I'm looking for. Thank you, mhagain.
    Last edited by samwyi; 09-14-2017 at 03:27 PM.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2004
    Location
    California
    Posts
    7
    Quote Originally Posted by Alfonse Reinheart View Post
    What do you mean by "binds a vertex buffer"?
    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:
    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.




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •