~sircmpwn/xrgears

bed4c8b5a430f86f710ca40894f7d72f741b2ec9 — Lubosz Sarnecki 4 years ago 5629b6b
settings: add option to disable text overlay.
M examples/xrgears/xrgears.cpp => examples/xrgears/xrgears.cpp +1 -1
@@ 127,7 127,7 @@ class XRGears : public vik::Application {
}

  // Enable physical device features required for this example
  virtual void get_enabled_features() {
  virtual void enable_required_features() {
    check_feature(geometryShader);
    check_feature(multiViewport);
    check_feature(textureCompressionBC);

M vitamin-k/render/vikRendererTextOverlay.hpp => vitamin-k/render/vikRendererTextOverlay.hpp +12 -10
@@ 21,7 21,7 @@ namespace vik {

class RendererTextOverlay : public Renderer {
 public:
  TextOverlay *textOverlay;
  TextOverlay *text_overlay;

  VkSemaphore text_overlay_complete;



@@ 31,25 31,26 @@ class RendererTextOverlay : public Renderer {
  virtual ~RendererTextOverlay() {
    vkDestroySemaphore(device, text_overlay_complete, nullptr);
    if (settings->enable_text_overlay)
      delete textOverlay;
      delete text_overlay;
  }

  void init(const std::string &n) {
  void init(const std::string &n,
            std::function<void(vik::TextOverlay *overlay)> cb) {
    Renderer::init(n);
    name = n;
    if (settings->enable_text_overlay) {
      init_text_overlay();
      init_text_overlay(cb);
      update_text_overlay();
    }
  }

  void init_text_overlay() {
  void init_text_overlay(std::function<void(vik::TextOverlay *overlay)> cb) {
    // Load the text rendering shaders
    std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
    shaderStages.push_back(Shader::load(device, "base/textoverlay.vert.spv", VK_SHADER_STAGE_VERTEX_BIT));
    shaderStages.push_back(Shader::load(device, "base/textoverlay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT));

    textOverlay = new TextOverlay(
    text_overlay = new TextOverlay(
          vksDevice,
          queue,
          &frame_buffers,


@@ 58,6 59,7 @@ class RendererTextOverlay : public Renderer {
          &width,
          &height,
          shaderStages);
    text_overlay->set_update_cb(cb);
  }

  VkSubmitInfo init_text_submit_info() {


@@ 86,12 88,12 @@ class RendererTextOverlay : public Renderer {
       << " fps)";
    std::string deviceName(deviceProperties.deviceName);

    textOverlay->update(name, ss.str(), deviceName);
    text_overlay->update(name, ss.str(), deviceName);
  }

  void submit_text_overlay() {
    VkSubmitInfo submit_info = init_text_submit_info();
    submit_info.pCommandBuffers = &textOverlay->cmdBuffers[currentBuffer];
    submit_info.pCommandBuffers = &text_overlay->cmdBuffers[currentBuffer];
    vik_log_check(vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE));
  }



@@ 107,14 109,14 @@ class RendererTextOverlay : public Renderer {
  void resize() {
    Renderer::resize();
    if (settings->enable_text_overlay) {
      textOverlay->reallocateCommandBuffers();
      text_overlay->reallocateCommandBuffers();
      update_text_overlay();
    }
  }

  void submit_frame() {
    VkSemaphore waitSemaphore;
    if (settings->enable_text_overlay && textOverlay->visible) {
    if (settings->enable_text_overlay && text_overlay->visible) {
      submit_text_overlay();
      waitSemaphore = text_overlay_complete;
    } else {

M vitamin-k/render/vikTextOverlay.hpp => vitamin-k/render/vikTextOverlay.hpp +4 -0
@@ 90,6 90,10 @@ class TextOverlay {
  std::function<void(vik::TextOverlay *overlay)>
    update_cb = [](vik::TextOverlay *overlay) {};

  void set_update_cb(std::function<void(vik::TextOverlay *overlay)> cb) {
    update_cb = cb;
  }

  std::vector<VkCommandBuffer> cmdBuffers;

  /**

M vitamin-k/system/vikApplication.hpp => vitamin-k/system/vikApplication.hpp +15 -12
@@ 43,7 43,7 @@ class Application {
  Window *window;
  bool quit = false;

  RendererTextOverlay *renderer = nullptr;
  Renderer *renderer = nullptr;
  Camera *camera = nullptr;

  bool viewUpdated = false;


@@ 60,7 60,10 @@ class Application {
       exit(0);
    }

    renderer = new RendererTextOverlay(&settings);
    if (settings.enable_text_overlay)
      renderer = new RendererTextOverlay(&settings);
    else
      renderer = new Renderer(&settings);

    init_window();



@@ 116,7 119,8 @@ class Application {
          break;
        case Input::Key::F1:
          if (state && settings.enable_text_overlay)
            renderer->textOverlay->visible = !renderer->textOverlay->visible;
            ((RendererTextOverlay*)renderer)->text_overlay->visible =
              !((RendererTextOverlay*)renderer)->text_overlay->visible;
          break;
        case Input::Key::ESCAPE:
          quit = true;


@@ 202,15 206,14 @@ class Application {
  }

  virtual void init() {
    renderer->init(name);

    std::function<void(vik::TextOverlay *overlay)>
      text_overlay_update_cb = [this](vik::TextOverlay *overlay) {
      update_text_overlay(overlay);
    };

    renderer->textOverlay->update_cb = text_overlay_update_cb;

    if (settings.enable_text_overlay) {
      auto update_cb = [this](vik::TextOverlay *overlay) {
        update_text_overlay(overlay);
      };
      ((RendererTextOverlay*)renderer)->init(name, update_cb);
    } else {
      renderer->init(name);
    }
  }

  void loop() {

M vitamin-k/system/vikSettings.hpp => vitamin-k/system/vikSettings.hpp +31 -26
@@ 62,23 62,25 @@ class Settings {
        "A XR demo for Vulkan and OpenHMD\n"
        "\n"
        "Options:\n"
        "  -s, --size WxH          Size of the output window (default: 1280x720)\n"
        "  -f, --fullscreen        Run fullscreen. Optinally specify display and mode.\n"
        "  -d, --display D         Display to fullscreen on. (default: 0)\n"
        "  -m, --mode M            Mode for fullscreen (wayland-shell only) (default: 0)\n"
        "  -w, --window WS         Window system to use (default: auto)\n"
        "                          [xcb, wayland, wayland-shell, kms]\n"
        "  -g, --gpu GPU           GPU to use (default: 0)\n"
        "      --hmd HMD           HMD to use (default: 0)\n"
        "      --format F          Color format to use (default: VK_FORMAT_B8G8R8A8_UNORM)\n"
        "      --presentmode M     Present mode to use (default: VK_PRESENT_MODE_FIFO_KHR)\n"
        "  -s, --size WxH           Size of the output window (default: 1280x720)\n"
        "  -f, --fullscreen         Run fullscreen. Optinally specify display and mode.\n"
        "  -d, --display D          Display to fullscreen on. (default: 0)\n"
        "  -m, --mode M             Mode for fullscreen (wayland-shell only) (default: 0)\n"
        "  -w, --window WS          Window system to use (default: auto)\n"
        "                           [xcb, wayland, wayland-shell, kms]\n"
        "  -g, --gpu GPU            GPU to use (default: 0)\n"
        "      --hmd HMD            HMD to use (default: 0)\n"
        "      --format F           Color format to use (default: VK_FORMAT_B8G8R8A8_UNORM)\n"
        "      --presentmode M      Present mode to use (default: VK_PRESENT_MODE_FIFO_KHR)\n"
        "\n"
        "      --listgpus          List available GPUs\n"
        "      --listdisplays      List available displays\n"
        "      --listhmds          List available HMDs\n"
        "      --listformats       List available color formats\n"
        "      --listpresentmodes  List available present modes\n"
        "  -h, --help              Show this help\n";
        "      --list-gpus          List available GPUs\n"
        "      --list-displays      List available displays\n"
        "      --list-hmds          List available HMDs\n"
        "      --list-formats       List available color formats\n"
        "      --list-presentmodes  List available present modes\n"
        "\n"
        "      --disable-overlay    Disable text overlay\n"
        "  -h, --help               Show this help\n";

 // VK_PRESENT_MODE_FIFO_KHR for vsync
    return help;


@@ 133,11 135,12 @@ class Settings {
      {"hmd", 1, 0, 0},
      {"format", 1, 0, 0},
      {"presentmode", 1, 0, 0},
      {"listgpus", 0, 0, 0},
      {"listdisplays", 0, 0, 0},
      {"listhmds", 0, 0, 0},
      {"listformats", 0, 0, 0},
      {"listpresentmodes", 0, 0, 0},
      {"list-gpus", 0, 0, 0},
      {"list-displays", 0, 0, 0},
      {"list-hmds", 0, 0, 0},
      {"list-formats", 0, 0, 0},
      {"list-presentmodes", 0, 0, 0},
      {"disable-overlay", 0, 0, 0},
      {0, 0, 0, 0}
    };



@@ 157,16 160,18 @@ class Settings {
        exit(0);
      } else if (opt == 'v' || optname == "validation") {
        validation = true;
      } else if (optname == "listgpus") {
      } else if (optname == "list-gpus") {
        list_gpus_and_exit = true;
      } else if (optname == "listdisplays") {
      } else if (optname == "list-displays") {
        list_screens_and_exit = true;
      } else if (optname == "listhmds") {
      } else if (optname == "list-hmds") {
        list_hmds_and_exit = true;
      } else if (optname == "listformats") {
      } else if (optname == "list-formats") {
        list_formats_and_exit = true;
      } else if (optname == "listpresentmodes") {
      } else if (optname == "list-presentmodes") {
        list_present_modes_and_exit = true;
      } else if (optname == "disable-overlay") {
        enable_text_overlay = false;
      } else if (opt == 's' || optname == "size") {
        size = parse_size(optarg);
      } else if (optname == "presentmode") {