generated from Persson-dev/OpenGLComputeShader
chaos game
This commit is contained in:
47
src/Main.cpp
47
src/Main.cpp
@@ -139,7 +139,7 @@ int main()
|
||||
GLuint vertexBuffer;
|
||||
glCreateBuffers(1, &vertexBuffer);
|
||||
|
||||
constexpr int DEPTH = 14;
|
||||
constexpr int DEPTH = 6;
|
||||
|
||||
auto vertices = GetPoints(DEPTH);
|
||||
|
||||
@@ -157,40 +157,19 @@ int main()
|
||||
|
||||
Timer timer;
|
||||
|
||||
constexpr int PARTICLE_COUNT = 64 * 5000;
|
||||
|
||||
GLuint ssbo;
|
||||
glGenBuffers(1, &ssbo);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * vertices.size(), nullptr, GL_DYNAMIC_COPY); // sizeof(data) only works for statically sized C/C++ arrays.
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * PARTICLE_COUNT, nullptr, GL_DYNAMIC_COPY); // sizeof(data) only works for statically sized C/C++ arrays.
|
||||
|
||||
float lastTime = (float)glfwGetTime();
|
||||
|
||||
int fps = 0;
|
||||
float secondsTimer = 0.0f;
|
||||
|
||||
// Compute
|
||||
glUseProgram(s_ComputeShader);
|
||||
glBindImageTexture(0, fb.ColorAttachment.Handle, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
|
||||
|
||||
std::size_t count = 1;
|
||||
for (std::size_t i = 0; i < DEPTH; i++)
|
||||
{
|
||||
glUniform1ui(0, count);
|
||||
std::cout << count << std::endl;
|
||||
|
||||
int dispatchCount = (count - 1) / 64 + 1;
|
||||
std::cout << "DC : " <<dispatchCount<< std::endl;
|
||||
|
||||
glDispatchCompute(dispatchCount, 1, 1);
|
||||
|
||||
// Ensure all writes to the image are complete
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
|
||||
count *= 3;
|
||||
}
|
||||
|
||||
std::cout << "Generated points in " << timer.ElapsedMillis() << " ms\n";
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// ScopedTimer timer("Main Loop");
|
||||
@@ -219,19 +198,19 @@ int main()
|
||||
AttachTextureToFramebuffer(fb, computeShaderTexture);
|
||||
}
|
||||
|
||||
// Compute
|
||||
|
||||
glUseProgram(s_ComputeShader);
|
||||
glDispatchCompute(PARTICLE_COUNT / 64, 1, 1);
|
||||
|
||||
// Ensure all writes to the image are complete
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
|
||||
// Graphics
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb.Handle);
|
||||
glUseProgram(s_GraphicsShader);
|
||||
|
||||
glBindVertexArray(vertexArray);
|
||||
glDrawArraysInstanced(GL_POINTS, 0, 1, vertices.size());
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// Blit
|
||||
{
|
||||
BlitFramebufferToSwapchain(fb);
|
||||
}
|
||||
glDrawArraysInstanced(GL_POINTS, 0, 1, PARTICLE_COUNT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
Reference in New Issue
Block a user