# Pixel buffer objects

**URL:** https://discourse.julialang.org/t/pixel-buffer-objects/66557
**Category:** Visualization
**Tags:** question
**Created:** [August 17, 2021, 3:33pm UTC](https://discourse.julialang.org/t/pixel-buffer-objects/66557 "2021-08-17T15:33:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Jakub\_Mitura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakub_mitura/32/19496_2.png) [@Jakub\_Mitura](https://discourse.julialang.org/u/Jakub_Mitura)
#### Post date: [August 17, 2021, 3:33pm UTC](https://discourse.julialang.org/t/pixel-buffer-objects/66557/1 "2021-08-17T15:33:31Z")

</div>

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)
> 
> end
> 
> ```

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)](https://github.com/JuliaPlots/GLMakie.jl/blob/2717d812fdc66b283f63d5d97237e8d69e2c1f25/src/GLAbstraction/GLBuffer.jl)

> **[OpenGL Pixel Buffer Object (PBO)](http://www.songho.ca/opengl/gl_pbo.html)**
>
> OpenGL Pixel Buffer object (FBO) to store pixel data. It is used for faster pixel data transfer from/to GPU.
