~sircmpwn/xrgears

a043469d7a54a9c51ea4d2df14c08c191945560f — Lubosz Sarnecki 4 years ago 734cbe8
lint: fix some linter warnings.
M vitamin-k/input/vikHMD.hpp => vitamin-k/input/vikHMD.hpp +1 -4
@@ 23,7 23,6 @@
#include "../scene/vikCamera.hpp"
#include "../render/vikBuffer.hpp"
#include "../system/vikLog.hpp"
#include "../scene/vikCamera.hpp"
#include "../system/vikSettings.hpp"

namespace vik {


@@ 34,7 33,7 @@ class HMD {
 public:
  ohmd_device* device = nullptr;

  HMD(Settings *s) {
  explicit HMD(Settings *s) {
    context = ohmd_ctx_create();
    int num_devices = ohmd_ctx_probe(context);



@@ 60,8 59,6 @@ class HMD {
              ohmd_list_gets(context, s->hmd, OHMD_PATH));

    ohmd_device_settings_destroy(settings);

    //print_info(device, s->hmd);
  }

  ~HMD() {

M vitamin-k/render/vikBuffer.hpp => vitamin-k/render/vikBuffer.hpp +0 -1
@@ 15,7 15,6 @@
#include "vulkan/vulkan.h"

#include "vikTools.hpp"
//#include "vikDevice.hpp"

namespace vik {
/**

M vitamin-k/render/vikOffscreenPass.hpp => vitamin-k/render/vikOffscreenPass.hpp +0 -2
@@ 72,8 72,6 @@ class OffscreenPass {
      VkFormat format,
      VkImageUsageFlagBits usage,
      FrameBufferAttachment *attachment) {


    attachment->format = format;

    VkImageCreateInfo image = initializers::imageCreateInfo();

M vitamin-k/render/vikRenderer.hpp => vitamin-k/render/vikRenderer.hpp +6 -8
@@ 87,7 87,7 @@ class Renderer {
  std::function<void()> window_resize_cb;
  std::function<void()> enabled_features_cb;

  Renderer(Settings *s) {
  explicit Renderer(Settings *s) {
    settings = s;
    width = s->size.first;
    height = s->size.second;


@@ 252,8 252,6 @@ class Renderer {
    init_vulkan(name, window->required_extensions());
    create_pipeline_cache();

    //window->init();

    window->update_window_title(make_title_string(name));
    window->get_swap_chain()->set_context(instance, physical_device, device);
    window->init_swap_chain(width, height);


@@ 497,17 495,17 @@ class Renderer {
  VkSubmitInfo init_render_submit_info() {
    // Pipeline stage at which the
    // queue submission will wait (via pWaitSemaphores)
    // TODO: stage_flags deallocate at end of function
    //std::array<VkPipelineStageFlags,1> stage_flags = {
    //  VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
    //};
    // TODO(lubosz): stage_flags deallocate at end of function
    // std::array<VkPipelineStageFlags,1> stage_flags = {
    //   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
    // };

    // The submit info structure specifices a
    // command buffer queue submission batch
    VkSubmitInfo submit_info = initializers::submitInfo();

    // Pointer to the list of pipeline stages that the semaphore waits will occur at
    //submit_info.pWaitDstStageMask = stage_flags.data();
    // submit_info.pWaitDstStageMask = stage_flags.data();
    submit_info.waitSemaphoreCount = 1;
    // Semaphore(s) to wait upon before the submitted command buffer starts executing
    submit_info.pWaitSemaphores = &semaphores.present_complete;

M vitamin-k/render/vikRendererTextOverlay.hpp => vitamin-k/render/vikRendererTextOverlay.hpp +3 -3
@@ 27,7 27,7 @@ class RendererTextOverlay : public Renderer {

  std::string name;

  RendererTextOverlay(Settings *s) : Renderer(s) {}
  explicit RendererTextOverlay(Settings *s) : Renderer(s) {}
  ~RendererTextOverlay() {
    vkDestroySemaphore(device, text_overlay_complete, nullptr);
    delete text_overlay;


@@ 63,10 63,10 @@ class RendererTextOverlay : public Renderer {

  VkSubmitInfo init_text_submit_info() {
    // Wait for color attachment output to finish before rendering the text overlay
    //VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
    // VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;

    VkSubmitInfo submit_info = initializers::submitInfo();
    //submit_info.pWaitDstStageMask = &stageFlags;
    // submit_info.pWaitDstStageMask = &stageFlags;
    submit_info.waitSemaphoreCount = 1;
    submit_info.pWaitSemaphores = &semaphores.render_complete;
    submit_info.signalSemaphoreCount = 1;

M vitamin-k/render/vikSwapChainVK.hpp => vitamin-k/render/vikSwapChainVK.hpp +1 -0
@@ 16,6 16,7 @@

#include <vector>
#include <map>
#include <utility>

#include "vikSwapChain.hpp"


M vitamin-k/render/vikTexture.hpp => vitamin-k/render/vikTexture.hpp +1 -1
@@ 721,7 721,7 @@ class TextureCubeMap : public Texture {
                 "File not found: Could not load texture from %s",
                 filename.c_str());

    // TODO: clang freezes here.
    // TODO(lubosz): clang freezes here.
    gli::texture_cube texCube(gli::load(filename));

    assert(!texCube.empty());

M vitamin-k/scene/vikCamera.hpp => vitamin-k/scene/vikCamera.hpp +86 -88
@@ 24,94 24,93 @@
namespace vik {

class Camera {
 protected:
  float fov = 60.f;
  float znear = .001f;
  float zfar = 256.f;

 public:
  enum CameraType { lookat, firstperson };
  CameraType type = CameraType::lookat;

  float rotation_speed = 1.0f;
  float movement_speed = 1.0f;

  glm::vec2 last_mouse_position;
  glm::vec3 rotation = glm::vec3();
  glm::vec3 position = glm::vec3();

  struct {
    bool left = false;
    bool right = false;
    bool middle = false;
  } mouse_buttons;

  struct {
    glm::mat4 projection;
    glm::mat4 view;
  } matrices;

  struct {
    bool left = false;
    bool right = false;
    bool up = false;
    bool down = false;
  } keys;

 public:
  Buffer uniformBuffer;

  struct StereoView {
    glm::mat4 view[2];
  };

  struct UBOCamera {
    glm::mat4 projection[2];
    glm::mat4 view[2];
    glm::mat4 skyView[2];
    glm::vec3 position;
  } ubo;

  virtual ~Camera() {
    uniformBuffer.destroy();
  }

  virtual void update_movement(float deltaTime) {}
  virtual void keyboard_key_cb(Input::Key key, bool state) {}
  virtual void pointer_axis_cb(Input::MouseScrollAxis axis, double value) {}
  virtual void pointer_motion_cb(double x, double y) {}
  virtual void update_view() {}

  virtual glm::mat4 get_view_matrix() {
    return glm::mat4();
  }

protected:
 float fov = 60.f;
 float znear = .001f;
 float zfar = 256.f;

public:
 enum CameraType { lookat, firstperson };
 CameraType type = CameraType::lookat;

 float rotation_speed = 1.0f;
 float movement_speed = 1.0f;

 glm::vec2 last_mouse_position;
 glm::vec3 rotation = glm::vec3();
 glm::vec3 position = glm::vec3();

 struct {
   bool left = false;
   bool right = false;
   bool middle = false;
 } mouse_buttons;

 struct {
   glm::mat4 projection;
   glm::mat4 view;
 } matrices;

 struct {
   bool left = false;
   bool right = false;
   bool up = false;
   bool down = false;
 } keys;

public:
 Buffer uniformBuffer;

 struct StereoView {
   glm::mat4 view[2];
 };

 struct UBOCamera {
   glm::mat4 projection[2];
   glm::mat4 view[2];
   glm::mat4 skyView[2];
   glm::vec3 position;
 } ubo;

 virtual ~Camera() {
   uniformBuffer.destroy();
 }

 virtual void update_movement(float deltaTime) {}
 virtual void keyboard_key_cb(Input::Key key, bool state) {}
 virtual void pointer_axis_cb(Input::MouseScrollAxis axis, double value) {}
 virtual void pointer_motion_cb(double x, double y) {}
 virtual void update_view() {}

 virtual glm::mat4 get_view_matrix() {
   return glm::mat4();
 }

 virtual glm::mat4 get_rotation_matrix() {
   return glm::mat4();
 }

 virtual glm::mat4 get_view_matrix_no_position() {
   return glm::mat4();
 }

 virtual void update_ubo() {
   ubo.projection[0] = matrices.projection;
   ubo.view[0] = matrices.view;
   ubo.skyView[0] = glm::mat4(glm::mat3(matrices.view));
   ubo.position = position * -1.0f;
   memcpy(uniformBuffer.mapped, &ubo, sizeof(ubo));
 }

 void init_ubo(Device *device) {
   device->create_and_map(&uniformBuffer, sizeof(ubo));
 }

 std::function<void()> view_updated_cb = [](){};

 void set_view_updated_cb(std::function<void()> cb) {
   view_updated_cb = cb;
 }
  virtual glm::mat4 get_rotation_matrix() {
    return glm::mat4();
  }

  virtual glm::mat4 get_view_matrix_no_position() {
    return glm::mat4();
  }

  virtual void update_ubo() {
    ubo.projection[0] = matrices.projection;
    ubo.view[0] = matrices.view;
    ubo.skyView[0] = glm::mat4(glm::mat3(matrices.view));
    ubo.position = position * -1.0f;
    memcpy(uniformBuffer.mapped, &ubo, sizeof(ubo));
  }

  void init_ubo(Device *device) {
    device->create_and_map(&uniformBuffer, sizeof(ubo));
  }

  std::function<void()> view_updated_cb = [](){};

  void set_view_updated_cb(std::function<void()> cb) {
    view_updated_cb = cb;
  }

  virtual bool moving() {
    return false;


@@ 165,6 164,5 @@ public:
        break;
    }
  }

};
}  // namespace vik

M vitamin-k/scene/vikCameraArcBall.hpp => vitamin-k/scene/vikCameraArcBall.hpp +2 -5
@@ 14,7 14,7 @@
namespace vik {
class CameraArcBall : public Camera {
 public:
  explicit CameraArcBall() {
  CameraArcBall() {
    rotation_speed = 1.25f;
  }



@@ 74,9 74,6 @@ class CameraArcBall : public Camera {
    return matrix;
  }

  void update_ubo() {


  }
  void update_ubo() {}
};
}  // namespace vik

M vitamin-k/scene/vikCameraFirstPerson.hpp => vitamin-k/scene/vikCameraFirstPerson.hpp +2 -6
@@ 15,7 15,7 @@
namespace vik {
class CameraFirstPerson : public Camera {
 public:
  explicit CameraFirstPerson() {}
  CameraFirstPerson() {}

  void update_view() {
    glm::mat4 rotM = glm::mat4();


@@ 41,7 41,6 @@ class CameraFirstPerson : public Camera {

  void update_movement(float time) {
    if (moving()) {

      float rad_x = glm::radians(rotation.x);
      float rad_y = glm::radians(rotation.y);



@@ 99,9 98,6 @@ class CameraFirstPerson : public Camera {
    last_mouse_position = glm::vec2(x, y);
  }

  void update_ubo() {


  }
  void update_ubo() {}
};
}  // namespace vik

M vitamin-k/system/vikApplication.hpp => vitamin-k/system/vikApplication.hpp +4 -3
@@ 36,10 36,11 @@
#include "../input/vikHMD.hpp"

#define check_feature(f) {\
  if (renderer->deviceFeatures.f) \
  if (renderer->deviceFeatures.f) {\
    renderer->enabledFeatures.f = VK_TRUE; \
  else \
  } else { \
    vik_log_f("Feature not supported: %s", #f);\
  } \
}

namespace vik {


@@ 108,7 109,7 @@ class Application {
  void set_window_callbacks() {
    window->set_pointer_motion_cb(
          [this](double x, double y) {
      camera->pointer_motion_cb(x,y);
      camera->pointer_motion_cb(x, y);
    });
    window->set_pointer_button_cb(
          [this](Input::MouseButton button, bool state) {

M vitamin-k/system/vikSettings.hpp => vitamin-k/system/vikSettings.hpp +5 -7
@@ 16,6 16,7 @@

#include <string>
#include <algorithm>
#include <utility>

#include "vikLog.hpp"
#include "../render/vikTools.hpp"


@@ 55,10 56,10 @@ class Settings {

  bool enable_text_overlay = true;

  std::pair<uint32_t,uint32_t> size = {1280, 720};
  std::pair<uint32_t, uint32_t> size = {1280, 720};

  std::string help_string() {
    std::string help =
    return
        "A XR demo for Vulkan and OpenHMD\n"
        "\n"
        "Options:\n"


@@ 81,13 82,10 @@ class Settings {
        "\n"
        "      --disable-overlay    Disable text overlay\n"
        "  -h, --help               Show this help\n";

 // VK_PRESENT_MODE_FIFO_KHR for vsync
    return help;
  }

  std::pair<uint32_t,uint32_t> parse_size(std::string const& str) {
      std::pair<uint32_t,uint32_t> size;
  std::pair<uint32_t, uint32_t> parse_size(std::string const& str) {
      std::pair<uint32_t, uint32_t> size;
      auto const dimensions = tools::split(str, 'x');

      if (dimensions.size() != 2

M vitamin-k/window/vikWindowWayland.hpp => vitamin-k/window/vikWindowWayland.hpp +5 -6
@@ 35,7 35,7 @@ class WindowWayland : public Window {
  explicit WindowWayland(Settings *s) : Window(s) {}

  struct Mode {
    std::pair<int,int> size;
    std::pair<int, int> size;
    int refresh;
  };



@@ 44,8 44,8 @@ class WindowWayland : public Window {
    std::string make;
    std::string model;
    std::vector<Mode> modes;
    std::pair<int,int> physical_size_mm;
    std::pair<int,int> position;
    std::pair<int, int> physical_size_mm;
    std::pair<int, int> position;
  };

  std::vector<Display> displays;


@@ 74,8 74,6 @@ class WindowWayland : public Window {
  void init_swap_chain(uint32_t width, uint32_t height) {
    VkResult err = create_surface(swap_chain.instance, &swap_chain.surface);
    vik_log_f_if(err != VK_SUCCESS, "Could not create surface!");
    //swap_chain.set_dimension_cb(dimension_cb);
    //swap_chain.select_queue();
    swap_chain.select_surface_format();
    swap_chain.set_settings(settings);
    swap_chain.create(width, height);


@@ 340,7 338,8 @@ class WindowWayland : public Window {
                              m.size.second,
                              (float) m.refresh/1000.0);
    std::string output(size + 1, '\0');
    std::sprintf(&output[0], "%d x %d @ %.2fHz", m.size.first,
    std::snprintf(&output[0], size, "%d x %d @ %.2fHz",
        m.size.first,
        m.size.second,
        (float) m.refresh/1000.0);
    return std::string(output);