# How can I access an OpenGl buffer from within a GLSL 330 shader?

I am currently attempting to create a simulation using OpenGl's GPU acceleration for both the simulation computations and rendering. The rendering portion of my simulation is complete and working, but I still need to create the simulation portion. To do this, I want to use transform feedback, for I am rendering as GL_POINTS and each point needs to be moved in relation to every other point each frame. This matches nicely to a vertex shader and transform feedback abstraction. The issue comes from the fact that my input data (the initial positions of each point) is in a buffer, and each vertex shader invocation in the transform feedback render only has access to that specific entry in my buffer, while I need access to all entries in my buffer. How can I solve this issue?

I can't use compute shaders because I am targeting OpenGl 3.3. I have also considered taking the buffer data, copying it to the CPU, and then back to the GPU in the form of a texture, however this is likely to be incredibly inefficient, especially as I begin scaling up how many points I am working with. This is further exasperated by the fact that textures don't allow me to get pixels at integer coordinates, and passing whole numbers as floating point coordinates is likely to cause floating point error to be sufficiently significant to be a problem, especially with texture filtering (I have thousands of points for now, but that will increase to whatever my GPU can handle once I have it working).

This is further exasperated by the fact that textures don't allow me to get pixels at integer coordinates, and passing whole numbers as floating point coordinates is likely to cause floating point error to be sufficiently significant to be a problem, especially with texture filtering (I have thousands of points for now, but that will increase to whatever my GPU can handle once I have it working).

Considering that the absolute maximum texture size you will have access to will likely be 4096x4096, you will have no problem with floating point error when it comes to accessing pixels. A 4096x4096 rgb texture will give you 16,777,216 points, which is already more than you will be able to compute in your simulation due to n^2 complexity. You should use GL_NEAREST to be sure that there is no interpolation between texels.

Here is an example implementation for the rendering process:

Pass indices as a buffer to the vertex shader.

int indices [8] = [0,1,2,3,4,5,6,7];


Convert the index to UV coordinates.

int _u = index / 4096;
int _v = index % 4096;
vec2 uv = vec2(float(_u),float(_v)) / 4096.0;


Then, sample from the texture and convert rgb to xyz vertex coordinates. (you can also use multiple textures here if you want)

gl_Position = mvp * vec4(texture(tex, uv).rgb, 1.0);


For the simulation process, you can draw the texture to an fbo with a viewport of equal size to the texture so that 1 fragment = 1 texel = 1 vertex, and perform your simulation in the fragment shader.