fendevel / Guide-to-Modern-OpenGL-Functions

A guide to using modern OpenGL functions.
Creative Commons Zero v1.0 Universal
1.12k stars 42 forks source link

It is not necessary to use the GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT parameter for the example of storing index and vertex data in a single buffer. #12

Open eharquin opened 1 year ago

eharquin commented 1 year ago

Everything is in the title, your example is good but I don't understand why you use GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT.

Solution :

`GLuint vao = GL_NONE; GLuint buffer = GL_NONE;

auto const ind_len = GLsizei(ind_count sizeof(element_t)); auto const vrt_len = GLsizei(vrt_count sizeof(vertex));

auto const ind_offset = vrt_len; auto const vrt_offset = 0;

glCreateBuffers(1, &buffer); glNamedBufferStorage(buffer, ind_len + vrt_len, nullptr, GL_DYNAMIC_STORAGE_BIT);

glNamedBufferSubData(buffer, ind_offset, ind_len, ind_data); glNamedBufferSubData(buffer, vrt_offset, vrt_len, vrt_data);

glCreateVertexArrays(1, &vao); glVertexArrayVertexBuffer(vao, 0, buffer, vrt_offset, sizeof(vertex)); glVertexArrayElementBuffer(vao, buffer);`

EternalSaga commented 3 weeks ago

Yes, I have the same question. If this is only a performance optimize option, it should be emphasized in the document.