I'm working with OpenGL and facing some difficulties because I'm not familiar with OpenGL. I tried to search related example in Google, but I could not find some useful code.
There are five arrays. I bound and changed the data in compute shahder as follows:
computeShader.use();
int bufferSize = sizeof(vertices) * vertices.size();
glGenBuffers(1, &vbo_Previous);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Previous);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &vertices[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vbo_Previous);
glGenBuffers(1, &vbo_Current);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Current);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &vertices[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo_Current);
glGenBuffers(1, &vbo_Next);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Next);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &vertices[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, vbo_Next);
glGenBuffers(1, &vbo_Normal);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Normal);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &normals[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vbo_Normal);
glGenBuffers(1, &vbo_Tangent);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Tangent);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &tangents[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, vbo_Tangent);
glGenBuffers(1, &vbo_Binormal);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Binormal);
glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &binormals[0], GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, vbo_Binormal);
computeShader.unUse();
And I want to use the data in vertex shader. I tried like that, but I doesn't work.
glGenVertexArrays(1, &vao);
glGenBuffers(1, &ebo);
glBindVertexArray(vao);
int bufferOffset = 0;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Next);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));
bufferOffset += sizeof(glm::vec4) * vertices.size();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Normal);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));
bufferOffset += sizeof(glm::vec4) * normals.size();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Tangent);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));
bufferOffset += sizeof(glm::vec4) * tangents.size();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Binormal);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));
//Because the texture coordinate are not changed in compute shader I generated the vbo for texture coordinate data
bufferOffset += sizeof(glm::vec4) * binormals.size();
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2)*texCoords.size(), &texCoords[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));
I hope to use the data in vertex shader as follows:
#version 430 core
layout(location = 0) in vec4 aPos;
layout(location = 1) in vec4 aNormal;
layout(location = 2) in vec4 aTangent;
layout(location = 3) in vec4 aBinormal;
layout(location = 4) in vec2 aTexCoord;
How to set vertex object array to use the data?
ComputeShader.use()
? And if you are passing SSBO to vertex shader you will have to define interface blocks, afaik you can't use them like uniform variables. Check here khronos.org/opengl/wiki/Shader_Storage_Buffer_Object $\endgroup$