Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curious "void*" parameter on some GL functions

For some functions in OpenGL, one must specify a byte offset, such as in glVertexAttribPointer(), for stride. At first I would have guessed that it would be a normal number value like an integer. But upon inspection, I realized that it needs to be casted to void* (more specifically GLvoid*). My question is: what is the intended meaning of void* and why must it be used for a byte offset?

like image 200
sgtHale Avatar asked Aug 01 '14 06:08

sgtHale


People also ask

What does void * func () mean?

Void as a Function Return TypeThe void function accomplishes its task and then returns control to the caller. The void function call is a stand-alone statement. For example, a function that prints a message doesn't return a value. The code in C++ takes the form: void printmessage ( )

What is void * param?

param has type void * , which in C serves as a "generic" pointer type; any object pointer type can be converted to void * and vice versa without need for an explicit cast (some implementations allow function pointer types to be converted to void * , but that's not universal and not guaranteed by the language standard).

What is void * C++?

When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."


1 Answers

glVertexAttribPointer() is an older function from before Vertex Buffer Objects.

Before VBO's your vertex data would be stored in client side arrays and you would need to pass a pointer to the data to OpenGL before you could draw.

When VBO's came along they repurposed this function by allowing the pointer to be used to pass an integer offset.

e.g. void* offset = (void*)offsetof(vertexStructName, vertexMemberName);

like image 189
CynicismRising Avatar answered Sep 25 '22 21:09

CynicismRising