Reputation: 7317
Consider the following OpenGL code snippet:
GLuint vao;
glCreateVertexArrays(1, glBindVertexArray(&vao));
I'm under the impression that what this code does is
GLuint
, that will eventually point to an OpenGL Vertex Array Object. The name of this pointer is vao
.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
)?
Upvotes: 2
Views: 272
Reputation: 72479
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.)
Upvotes: 6