c++ - glDrawElementsInstancedBaseInstance() requires preceding glVertexArrayVertexBuffer() -
my objective draw textured quads screen rendering text. trying use gldrawelementsinstancedbaseinstance
render each glyph quad instance of same mesh. in order convey individual information each character quad (like position, size , glyph index) use 2 buffers (quadstorage
, charstorage
), sources vertex attributes (vec2 quadpos
,vec2 quadsize
, unsigned int glyphindex
) advance each instance.
because may want change text on screen occasionally, need way stream buffers. in application, have used immutable buffers (initialized glbufferstorage
) mapped gl_map_persistent_bit
, gl_map_coherent_bit
flags set, enables me map entire buffer "forever" , use mapped pointer c-array. avoid writing memory being read create storage 3 times large need , can use new range in buffer each stream upload. when want use updated data in shaders have rebind buffer bindings reference updated range in buffer using glbindbufferrange
gl_uniform_buffer
s , glvertexarrayvertexbuffer
gl_array_buffer
s bound vao.
but recently, ran few problems. i have found gldrawelementsinstancedbaseinstance
throws invalid_operation
error if not call glvertexarrayvertexbuffer
each frame. wanted stream attribute buffers once when loading screen , let frame loop go on, unless kept updatecharstorage()
function call (which writes pending data mapped pointer , updates buffer binding offset glvertexarrayvertexbuffer
) in frame loop, throw error.
at beginning of research have read gldrawelementsinstancedbaseinstance may throw invalid_operation if buffer object name bound enabled array , buffer object's data store mapped, confused me more, because had buffer mapped beginning , worked. me seems calls glvertexarrayvertexbuffer
causing problems, not find fix. have assured myself call glvertexarrayvertexbuffer
right after data upload , parameters correct. else causing error/behaviour?
this procedure use create buffer storage can stream to:
unsigned int storage; glcreatebuffers(1, &storage); glnamedbufferstorage(storage, capacity, dataptr, gl_map_write_bit| gl_map_persistent_bit| gl_map_coherent_bit); void* mapped_ptr = glmapnamedbufferrange(storage, 0, capacity, gl_map_write_bit| gl_map_persistent_bit| gl_map_coherent_bit);
if want use buffer vertex attributes in shader do:
glvertexarrayvertexbuffer(vao, buffer_binding, storage, 0/*offset*/, stride); glenablevertexarrayattrib(vao, attribute_index); glvertexarrayattribbinding(vao, attribute_index, buffer_binding); glvertexarrayattribformat(vao, attribute_index, count, type, normalize, offset);
streaming works (this updatecharstorage()
does):
//...align update offset opengls alignment requirements... std::memcpy(mapped_ptr + update_offset, data_ptr, upload_size); glvertexarrayvertexbuffer(vao, buffer_binding, storage, update_offset, stride);
when remove glvertexarrayvertexbuffer
call frame loop error, though vao binding has been initialized (with glvertexarrayvertexbuffer
) , draw calls should know buffer use.
Comments
Post a Comment