Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does glVertexAttribPointer work for bytes?

Tags:

opengl

From my understanding, OpenGL casts all vertex attribute data to 32-bit float before it gets used in the vertex shader. But glVertexAttribPointer also takes data types GL_BYTE and GL_UNSIGNED_BYTE (8 bits). If I buffer and send an array of unsigned bytes to the gpu and use

glVertexAttribPointer(0, 3, GL_UNSIGNED_BYTE, GL_FALSE, 3 * sizeof(unsigned char), (void*)0);

does this, send-to/store-on the gpu as an array of bytes and then cast them to floats as the shader reads them? This would quadruple my update speed and quarter my memory space. Or does this send/store them as floats or do something else? Is there a way to read VBO as ints or bytes in shader? Does glVertexAttribIPointer do anything different? If your wondering why, my game uses 256x256x256 chunks so...

like image 289
jake Avatar asked May 26 '26 10:05

jake


1 Answers

See glVertexAttribPointer Each byte is a single component of the attribute and converted to a floating point value. If the argument normalized is set to GL_TRUE, GL_UNSIGNED_BYTE components are treated as unsigned normalized values and mapped from the range [0, 255] to [0.0, 1.0].

If you want to use integer attributes (int, ivec2, ivec3, ivec4) you must use glVertexAttribIPointer (focus on I) to load attributes from arrays with integral component values. glVertexAttribIPointer keeps the integral numbers and does not convert them to floating point numbers.

Note that the type argument does not say anything about the type of the shader attribute. It only specifies the type of source data in the array.

like image 172
Rabbid76 Avatar answered May 30 '26 09:05

Rabbid76