Pixel buffer objects

Hello I am trying to implement OpenGl pixel buffer object, becouse fast upload of data to texture is critical for my use case.

My code that tries to implement it (using ModernGl.jl)

juliaDataType= UInt8

toSend = ones(UInt8,2000,8000)

toSendFlat = reduce(vcat,toSend)

pboIds= [Ref(GLuint(0))] 

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[1][]);

glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(toSendFlat), Ptr{juliaDataType}(), GL_STREAM_DRAW);

# bind the texture and PBO

textureId =wordsDispObj.textureSpec.ID

glActiveTexture(wordsDispObj.textureSpec.actTextrureNumb); # active proper texture unit before binding

glBindTexture(GL_TEXTURE_2D, textureId[]);

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[1][]);

# update data directly on the mapped buffer - this is internal function implemented below

ptrB = Ptr{juliaDataType}(glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY))

for i=1:length(toSend)

    unsafe_store!(ptr, toSend[i], i)


It gives ReadOnlyMemoryError() where I invoke unsafe_store!

The same task with the same data and texture with glTexSubImage2D works without problem.

Any help would be deeply appriciated, Thank You!

Sources that I took inspiration from
GLMakie.jl/GLBuffer.jl at 2717d812fdc66b283f63d5d97237e8d69e2c1f25 ยท JuliaPlots/GLMakie.jl (github.com)