I have been looking everywhere and there isn’t anything that clearly says how to do this. I have found things for input buffers, for read write buffers, but nothing useful about output buffers. I think that I know how to get the data back. I need clear instructions and so far I haven’t found any.
void ModelBind::load(vector<nessVertex> vertices)
{
this->vertices = vertices;
}
void ModelBind::bind()
{
if (first) {
//this is the starting stuff so I guess it doesn't have to be done again
//this is my input ssbo
glGenBuffers(1, &buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(nessVertex), &vertices[0], GL_STATIC_DRAW); // Bind to binding point 0 for SSBO
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
//this is supposed to be my output ssbo
glGenBuffers(1, &outputBuffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(glm::vec3), nullptr, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, outputBuffer);
outData.resize(vertices.size());
first = false;
}
else {
//Dynamic write
//glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
//glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, vertices.size() * sizeof(nessVertex), vertices.data());
// so this is just to bind the buffers because the input should be in memory right?
glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
//glBufferData(GL_SHADER_STORAGE_BUFFER, vertices.size() * sizeof(glm::vec3), nullptr, GL_STREAM_COPY);
}
}
void ModelBind::retreive()
{
glBindBuffer(GL_SHADER_STORAGE_BUFFER, outputBuffer);
GLvoid* p = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
memcpy(p, &outData[0], vertices.size() * sizeof(glm::vec3));
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
}