From a82fb634384477fc4e60dc04fdbaec1cab0c54d5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 8 Jun 2018 14:16:19 +0200 Subject: Optionally accept field definition as CLI argument --- src/main.cc | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main.cc b/src/main.cc index 5236f4c..285d31f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,10 +26,6 @@ #include "timer.h" -const unsigned int particle_count = 5000; -const unsigned int max_ups = 100; -const unsigned int texture_count = 20; - float getWorldHeight(int window_width, int window_height, float world_width) { return world_width / window_width * window_height; } @@ -76,14 +72,11 @@ std::string getShaderFunction(const std::string& fx, const std::string& fy) { + "}"; } -int main() { - GlfwGuard glfw; - - if( !glfw.isGood() ) { - std::cerr << "Failed to initialize GLFW." << std::endl; - return -1; - } - +int renderVectorFieldWindow( + const std::string& fx, const std::string& fy, + const unsigned int particle_count = 5000, + const unsigned int max_ups = 100, + const unsigned int texture_count = 20) { Window window("computicle"); if ( !window.isGood() ) { @@ -120,10 +113,11 @@ int main() { scene_shader = std::make_unique( VERTEX_SHADER_CODE, FRAGMENT_SHADER_CODE); + compute_shader = std::make_unique( - getShaderFunction("cos(v.x*sin(v.y))", - "sin(v.x-v.y)")); + getShaderFunction(fx, fy)); compute_shader->workOn(particle_buffer->getBuffer()); + display_shader = std::make_unique( DISPLAY_VERTEX_SHADER_CODE, DISPLAY_FRAGMENT_SHADER_CODE); }); @@ -136,6 +130,11 @@ int main() { return -1; } + if ( !compute_shader->isGood() ) { + std::cerr << "Compute shader error. Check vector field definition." << std::endl; + return -1; + } + auto last_frame = timer::now(); auto last_rotate = timer::now(); @@ -214,3 +213,21 @@ int main() { return 0; } + +int main(int argc, char* argv[]) { + GlfwGuard glfw; + + if( !glfw.isGood() ) { + std::cerr << "Failed to initialize GLFW." << std::endl; + return -1; + } + + const std::vector args(&argv[0], &argv[0 + argc]); + + if ( argc == 3 ) { + return renderVectorFieldWindow(args[1], args[2]); + } else { + return renderVectorFieldWindow("cos(v.x*sin(v.y))", + "sin(v.x-v.y)"); + } +} -- cgit v1.2.3