generated from Persson-dev/OpenGLComputeShader
now in 3D
This commit is contained in:
20
src/Main.cpp
20
src/Main.cpp
@@ -54,7 +54,7 @@ static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, i
|
||||
if (key == GLFW_KEY_R) {
|
||||
s_ComputeShader = ReloadComputeShader(s_ComputeShader, s_ComputeShaderPath);
|
||||
s_GraphicsShader = ReloadGraphicsShader(s_GraphicsShader, s_VertexShaderPath, s_FragmentShaderPath);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * PARTICLE_COUNT * 2, nullptr, GL_DYNAMIC_COPY);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * PARTICLE_COUNT * 3, nullptr, GL_DYNAMIC_COPY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ static GLuint CreateDummyVAO() {
|
||||
glCreateBuffers(1, &vertexBuffer);
|
||||
|
||||
// Buffer with just one point
|
||||
float vertices[] = {0.0f, 0.0f};
|
||||
float vertices[] = {0.0f, 0.0f, 0.0f};
|
||||
glNamedBufferData(vertexBuffer, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glVertexArrayVertexBuffer(vertexArray, 0, vertexBuffer, 0, sizeof(float) * 2);
|
||||
glVertexArrayVertexBuffer(vertexArray, 0, vertexBuffer, 0, sizeof(float) * 3);
|
||||
glEnableVertexArrayAttrib(vertexArray, 0);
|
||||
glVertexArrayAttribFormat(vertexArray, 0, 2, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexArrayAttribFormat(vertexArray, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexArrayAttribBinding(vertexArray, 0, 0);
|
||||
|
||||
return vertexArray;
|
||||
@@ -81,7 +81,7 @@ static void CreateGpuBuffer() {
|
||||
glGenBuffers(1, &ssbo);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * 2 * PARTICLE_COUNT, nullptr,
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * 3 * PARTICLE_COUNT, nullptr,
|
||||
GL_DYNAMIC_COPY); // sizeof(data) only works for statically sized C/C++ arrays.
|
||||
}
|
||||
|
||||
@@ -174,6 +174,16 @@ int main() {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
|
||||
// float positions[3 * PARTICLE_COUNT];
|
||||
// glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(float) * 3 * PARTICLE_COUNT, positions);
|
||||
|
||||
// std::cout << "Positions :\n";
|
||||
// for (size_t i = 0; i < PARTICLE_COUNT; i++)
|
||||
// {
|
||||
// std::cout << "\t" << positions[i * 3] << " " << positions[i * 3 + 1] << " " << positions[i * 3 + 2] << "\n";
|
||||
// }
|
||||
|
||||
|
||||
fps++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user