2

Consider the following OpenGL code snippet:

GLuint vao;
glCreateVertexArrays(1, glBindVertexArray(&vao));    

I'm under the impression that what this code does is

  1. Creates a pointer, of type GLuint, that will eventually point to an OpenGL Vertex Array Object. The name of this pointer is vao.
  2. Indirectly allocates memory through OpenGL for the actual Vertex Array Object (i.e., no use of malloc in C or new in C++). The way that this is done is through the function glCreateVertexArrays. This function also makes the pointer vao point to the Vertex Array Object.

Is my understanding correct? If so, in (1), why is the type of the pointer GLuint and not explicitly defined as a pointer type (for example with * in C/C++ or with the OpenGL type GLintptr)?

1 Answer 1

6

This code is invalid, glBindVertexArray returns void so you cannot pass its return value as a parameter to glCreateVertexArrays, because there is none.

The correct way to create a VAO, as per OpenGL 4.5 profile, is:

GLuint vao;
glCreateVertexArrays(1, &vao);

As per the meaning of vao and why its type is GLuint: it is not a pointer. It is an opaque value that is used internally to locate the VAO inside the OpenGL implementation tables. The driver may allocate memory on both, the CPU and/or GPU for storing the state associated with the VAO. It is a complex state with quite a lot of book-keeping, which is much more involved than malloc or new. (In particular malloc can't be used to allocate GPU memory.)

Sign up to request clarification or add additional context in comments.

2 Comments

So I should think of vao as something like an (unsigned integer) key in a hash table lookup (that can get me to a vertex array object)?
@George: Pretty much. That's how all OpenGL Objects work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.