A little toolkit for single-quad fragment shader demos
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

  1. #include "project.h"
  2. #include <iostream>
  3. Project Project::fromFile(std::string path) {
  4. return Project::fromFile(fs::path(path));
  5. }
  6. Project Project::fromFile(fs::path path) {
  7. auto manifest = cpptoml::parse_file(path);
  8. auto basepath = fs::absolute(path).parent_path();
  9. auto project = Project::fromToml(manifest, basepath);
  10. return project;
  11. }
  12. Project Project::fromToml(std::shared_ptr<cpptoml::table> manifest,
  13. fs::path basepath = fs::path(".")) {
  14. auto project = Project();
  15. project.basepath = basepath;
  16. project.name = manifest->get_qualified_as<std::string>("project.name").value_or("");
  17. project.shader_bundle = std::move(std::make_shared<ShaderBundle>());
  18. auto sceneconf = manifest->get_table_array("scene");
  19. if (sceneconf) {
  20. for (const auto& conf_scene : *sceneconf) {
  21. auto scene = std::make_shared<Scene>();
  22. scene->name = conf_scene->get_as<std::string>("name").value_or("");
  23. auto p_frag = conf_scene->get_as<std::string>("frag");
  24. auto p_vert = conf_scene->get_as<std::string>("vert");
  25. if (p_frag && p_vert) {
  26. std::vector<std::pair<fs::path, ShaderBundle::ShaderType>> shaders;
  27. shaders.push_back(std::make_pair(basepath / *p_vert, GL_VERTEX_SHADER));
  28. shaders.push_back(std::make_pair(basepath / *p_frag, GL_FRAGMENT_SHADER));
  29. scene->shader_p = project.shader_bundle->add_program(shaders);
  30. }
  31. project.scenes.push_back(std::move(scene));
  32. }
  33. }
  34. auto boot_scene = manifest->get_qualified_as<int>("project.boot_scene");
  35. if (boot_scene) {
  36. printf("loading boot scene %i\n", *boot_scene);
  37. project.load_scene(project.scenes[*boot_scene]);
  38. project.shader_bundle->recompile().link();
  39. }
  40. return project;
  41. }
  42. void Project::load_scene(std::shared_ptr<Scene> scene) {
  43. this->current_scene = scene;
  44. this->scene_loaded = true;
  45. }
  46. void Project::reload_shaders() {
  47. this->shader_bundle->recompile().link();
  48. }