Pointer to buffer on gpu

Hello,
I currently can draw multiple chunks consisting of a lot of tiles which each only have a VertexArray bound and no buffer or VertexAttributes. I draw them with glDrawArraysInstanced and don’t pass any vertex data. The position and transform of the tiles are calculated by the shader based on some small uniforms that I can set. Each tile indexes an array of tilemap indices with its gl_InstaceID. The vertex shader then passes the calculated UV coordinates to the fragment shader to determine the texture of each tile. Currently, for testing purposes, I am passing the array of tileset indices as uniforms.

Is it possible to create an array on the GPU and just get a pointer to it if I want to change the texture of a tile(for example for animations)? Because uploading such big arrays every frame would be pretty slow and unnecessary since I only update a small number of tiles each frame.
Thanks for your answers :slight_smile:

glMapBuffer and glMapBufferRange allow you to map all or part of a buffer to the CPU’s address space for reading and writing. The latter function offers more control over the mapping.

Accessing GPU memory may still be slower than accessing CPU memory, so it’s worth structuring the data appropriately. Interleaving attributes (array of structs) may be less efficient than keeping static and dynamic attributes separate (struct of arrays).

Also, if you’re using instancing with one instance per tile, that tends to be inefficient. Implementations typically don’t combine multiple instances into a single work group, so the vertex shader will only use as many cores as the tile has vertices; the rest will be idle. If you’re doing “fake instancing” (retrieving per-instance data from arrays/textures rather than attributes), you’re probably better off using non-instanced rendering and just dividing gl_VertexID by the number of vertices per “instance”.

Interesting! Thank you very much :slight_smile:

I am now using the technique you described and it indeed renders much faster!