~sircmpwn/xrgears

e8439a3f54ef1f2238d974be4b67ef9eae34e8c7 — Lubosz Sarnecki 4 years ago 7c9cc68
fix -Wall warnings.
M CMakeLists.txt => CMakeLists.txt +32 -37
@@ 1,58 1,53 @@

cmake_minimum_required(VERSION 3.8)
project(xrgears)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")

# use XCB

function(add_cxxflag FLAG)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}" PARENT_SCOPE)
endfunction(add_cxxflag)

add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)

add_cxxflag("-std=c++14")

# warnings
add_cxxflag("-Werror")

add_cxxflag("-Wall")
#add_cxxflag("-Wcast-qual")
#add_cxxflag("-Wconversion")
#add_cxxflag("-Wsign-conversion")
#add_cxxflag("-Winline")
#add_cxxflag("-Weffc++")
#add_cxxflag("-Wextra")
#add_cxxflag("-Wformat=2")
#add_cxxflag("-Winline")
#add_cxxflag("-Wlogical-op")
#add_cxxflag("-Wmissing-declarations")
#add_cxxflag("-Wno-cast-qual")
#add_cxxflag("-Wno-delete-non-virtual-dtor")
#add_cxxflag("-Wno-sign-compare")
#add_cxxflag("-Wno-switch")
#add_cxxflag("-Wno-unused-parameter")
#add_cxxflag("-Wold-style-cast")
#add_cxxflag("-Woverflow")
#add_cxxflag("-Woverloaded-virtual")
#add_cxxflag("-Wpointer-arith")
#add_cxxflag("-Wredundant-decls")
#add_cxxflag("-Wsign-conversion")
#add_cxxflag("-Wsuggest-attribute=const")
#support ISO C++ standard (remove GNU extensions)
add_cxxflag("-Wundef")
add_cxxflag("-Wuninitialized")
add_cxxflag("-Wunreachable-code")

#add_cxxflag("-ansi")
#warnings for strict ISO C and ISO C++
#add_cxxflag("-pedantic")

add_cxxflag("-std=c++14")
# gcc coverage stats
#add_cxxflag("--coverage")

function(add_verbose_warnings)
    add_cxxflag("-Werror")
    add_cxxflag("-Wall")
    add_cxxflag("-Wextra")
    add_cxxflag("-Wuninitialized")
    #add_cxxflag("-Wold-style-cast")
    add_cxxflag("-Woverloaded-virtual")
    add_cxxflag("-Wformat=2")
    add_cxxflag("-Wundef")
    add_cxxflag("-Wpointer-arith")
    add_cxxflag("-Wcast-qual")
    add_cxxflag("-Wlogical-op")
    add_cxxflag("-Woverflow")
    add_cxxflag("-Wmissing-declarations")
    add_cxxflag("-Wredundant-decls")
    add_cxxflag("-Wno-sign-compare")
    add_cxxflag("-Wno-unused-parameter")
    add_cxxflag("-Wno-delete-non-virtual-dtor")
    add_cxxflag("-Wno-cast-qual")
    add_cxxflag("-Wno-switch")
    add_cxxflag("-Wunreachable-code")
endfunction(add_verbose_warnings)

#    add_cxxflag("--coverage")

add_cxxflag("-fPIC")

# find_package(XCB REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")

file(GLOB VITAMINK_SRC vitamin-k/*.hpp)
file(GLOB XDG_SRC xdg-shell/*.c)


@@ 64,7 59,7 @@ include_directories(
    xdg-shell
    /usr/include/openhmd
    /usr/include/libdrm/
)
    )

# glslc -o gears.vert.spv gears.vert



@@ 106,7 101,7 @@ set(EXAMPLE_LIBS
    xdg-shell
    gbm
    drm
)
    )

# Function for building single example
function(buildExample EXAMPLE_NAME)

M examples/triangle/triangle.cpp => examples/triangle/triangle.cpp +1 -5
@@ 167,7 167,7 @@ class Triangle : public vik::Application {

    vik_log_d("we will process %ld draw buffers", renderer->cmd_buffers.size());

    for (int32_t i = 0; i < renderer->cmd_buffers.size(); ++i) {
    for (uint32_t i = 0; i < renderer->cmd_buffers.size(); ++i) {
      renderPassBeginInfo.framebuffer = renderer->frame_buffers[i];

      vik_log_check(vkBeginCommandBuffer(renderer->cmd_buffers[i], &cmdBufInfo));


@@ 310,10 310,6 @@ class Triangle : public vik::Application {
      vik_log_check(vkAllocateMemory(renderer->device, &memAlloc, nullptr, &indices.memory));
      vik_log_check(vkBindBufferMemory(renderer->device, indices.buffer, indices.memory, 0));

      VkCommandBufferBeginInfo cmdBufferBeginInfo = {};
      cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
      cmdBufferBeginInfo.pNext = nullptr;

      // Buffer copies have to be submitted to a queue, so we need a command buffer for them
      // Note: Some devices offer a dedicated transfer queue (with only the transfer bit set) that may be faster when doing lots of copies
      VkCommandBuffer copyCmd = renderer->create_command_buffer();

M examples/xrcube/xrcube.cpp => examples/xrcube/xrcube.cpp +1 -1
@@ 63,7 63,7 @@ class XrCube : public vik::Application {
  }

  void build_command_buffers() {
    for (int32_t i = 0; i < renderer->cmd_buffers.size(); ++i) {
    for (uint32_t i = 0; i < renderer->cmd_buffers.size(); ++i) {
      build_command_buffer(renderer->cmd_buffers[i], renderer->frame_buffers[i]);
    }
  }

M examples/xrgears/xrgears.cpp => examples/xrgears/xrgears.cpp +3 -3
@@ 144,10 144,10 @@ class XRGears : public vik::Application {
    vik_log_d("Draw command buffers size: %ld", renderer->cmd_buffers.size());

    if (enableDistortion) {
      for (int32_t i = 0; i < renderer->cmd_buffers.size(); ++i)
      for (uint32_t i = 0; i < renderer->cmd_buffers.size(); ++i)
        buildWarpCommandBuffer(renderer->cmd_buffers[i], renderer->frame_buffers[i]);
    } else {
      for (int32_t i = 0; i < renderer->cmd_buffers.size(); ++i)
      for (uint32_t i = 0; i < renderer->cmd_buffers.size(); ++i)
        buildPbrCommandBuffer(renderer->cmd_buffers[i], renderer->frame_buffers[i], false);
    }
  }


@@ 312,7 312,7 @@ class XRGears : public vik::Application {
    std::vector<float> rotationOffsets = { 0.0f, -9.0f, -30.0f };

    nodes.resize(positions.size());
    for (int32_t i = 0; i < nodes.size(); ++i) {
    for (uint32_t i = 0; i < nodes.size(); ++i) {
      vik::Node::NodeInfo gearNodeInfo = {};
      vik::GearInfo gearInfo = {};
      gearInfo.innerRadius = innerRadiuses[i];

M vitamin-k/input/vikHMD.hpp => vitamin-k/input/vikHMD.hpp +0 -2
@@ 76,8 76,6 @@ class HMD {
    right_lens_center[0] = sep/2.0f;
    // asume calibration was for lens view to which ever edge of screen is further away from lens center
    float warp_scale = (left_lens_center[0] > right_lens_center[0]) ? left_lens_center[0] : right_lens_center[0];
    float warp_adj = 1.0f;

    ohmd_device_settings_destroy(settings);

    if (!openHmdDevice) {

M vitamin-k/input/vikInput.hpp => vitamin-k/input/vikInput.hpp +1 -0
@@ 24,6 24,7 @@ class Input {
  };

  enum Key {
    UNKNOWN,
    ESCAPE,
    SPACE,
    F1,

M vitamin-k/render/vikDebug.hpp => vitamin-k/render/vikDebug.hpp +6 -0
@@ 150,6 150,7 @@ static void setup(VkDevice device) {
// Sets the debug name of an object
// All Objects in Vulkan are represented by their 64-bit handles which are passed into this function
// along with the object type
/*
static void setObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name) {
  // Check for valid function pointer (may not be present if not running in a debugging application)
  if (pfnDebugMarkerSetObjectName) {


@@ 175,6 176,7 @@ static void setObjectTag(VkDevice device, uint64_t object, VkDebugReportObjectTy
    pfnDebugMarkerSetObjectTag(device, &tagInfo);
  }
}
*/

// Start a new debug marker region
static void beginRegion(VkCommandBuffer cmdbuffer, const char* pMarkerName, glm::vec4 color) {


@@ 187,6 189,7 @@ static void beginRegion(VkCommandBuffer cmdbuffer, const char* pMarkerName, glm:
    pfnCmdDebugMarkerBegin(cmdbuffer, &markerInfo);
  }
}
/*
// Insert a new debug marker into the command buffer
static void insert(VkCommandBuffer cmdbuffer, std::string markerName, glm::vec4 color) {
  // Check for valid function pointer (may not be present if not running in a debugging application)


@@ 198,6 201,7 @@ static void insert(VkCommandBuffer cmdbuffer, std::string markerName, glm::vec4 
    pfnCmdDebugMarkerInsert(cmdbuffer, &markerInfo);
  }
}
*/
// End the current debug marker region
static void endRegion(VkCommandBuffer cmdBuffer) {
  // Check for valid function (may not be present if not runnin in a debugging application)


@@ 206,6 210,7 @@ static void endRegion(VkCommandBuffer cmdBuffer) {
}

// Object specific naming functions
/*
static void setCommandBufferName(VkDevice device, VkCommandBuffer cmdBuffer, const char * name) {
  setObjectName(device, (uint64_t)cmdBuffer, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, name);
}


@@ 269,5 274,6 @@ static void setFenceName(VkDevice device, VkFence fence, const char * name) {
static void setEventName(VkDevice device, VkEvent _event, const char * name) {
  setObjectName(device, (uint64_t)_event, VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, name);
}
*/
}  // namespace debugmarker
}  // namespace vik

M vitamin-k/render/vikDistortion.hpp => vitamin-k/render/vikDistortion.hpp +0 -2
@@ 210,8 210,6 @@ class Distortion {
  }

  void drawQuad(const VkCommandBuffer& commandBuffer) {
    VkDeviceSize offsets[1] = { 0 };

    vkCmdBindDescriptorSets(commandBuffer,
                            VK_PIPELINE_BIND_POINT_GRAPHICS,
                            pipelineLayout, 0, 1,

M vitamin-k/render/vikOffscreenPass.hpp => vitamin-k/render/vikOffscreenPass.hpp +1 -0
@@ 100,6 100,7 @@ class OffscreenPass {
    image.samples = VK_SAMPLE_COUNT_1_BIT;
    image.tiling = VK_IMAGE_TILING_OPTIMAL;
    image.usage = usage | VK_IMAGE_USAGE_SAMPLED_BIT;
    image.initialLayout = imageLayout;

    VkMemoryAllocateInfo memAlloc = initializers::memoryAllocateInfo();
    VkMemoryRequirements memReqs;

M vitamin-k/render/vikRendererTextOverlay.hpp => vitamin-k/render/vikRendererTextOverlay.hpp +2 -2
@@ 28,7 28,7 @@ class RendererTextOverlay : public Renderer {
  std::string name;

  RendererTextOverlay(Settings *s, Window *w) : Renderer(s, w) {}
  ~RendererTextOverlay() {
  virtual ~RendererTextOverlay() {
    vkDestroySemaphore(device, text_overlay_complete, nullptr);
    if (settings->enable_text_overlay)
      delete textOverlay;


@@ 89,7 89,7 @@ class RendererTextOverlay : public Renderer {
    textOverlay->update(name, ss.str(), deviceName);
  }

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

M vitamin-k/render/vikSwapChainVK.hpp => vitamin-k/render/vikSwapChainVK.hpp +1 -1
@@ 128,7 128,7 @@ class SwapChainVK : public SwapChain {
                    physical_device, surface, &count, formats.data()));

    surface_format.format = VK_FORMAT_UNDEFINED;
    for (int i = 0; i < count; i++) {
    for (uint32_t i = 0; i < count; i++) {
      switch (formats[i].format) {
        case VK_FORMAT_R8G8B8A8_SRGB:
        case VK_FORMAT_B8G8R8A8_SRGB:

M vitamin-k/render/vikTexture.hpp => vitamin-k/render/vikTexture.hpp +2 -1
@@ 80,7 80,8 @@ class Texture2D : public Texture {
      VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT,
      VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
      bool forceLinear = false) {
    vik_log_f_if(!tools::fileExists(filename), "File not found: Could not load texture from %s", filename.c_str());
    bool exists = tools::fileExists(filename);
    vik_log_f_if(!exists, "File not found: Could not load texture from %s", filename.c_str());

    gli::texture2d tex2D(gli::load(filename.c_str()));


M vitamin-k/render/vikTools.hpp => vitamin-k/render/vikTools.hpp +1 -29
@@ 224,35 224,6 @@ static void setImageLayout(
  setImageLayout(cmdbuffer, image, oldImageLayout, newImageLayout, subresourceRange, srcStageMask, dstStageMask);
}

/** @brief Inser an image memory barrier into the command buffer */
static void insertImageMemoryBarrier(
    VkCommandBuffer cmdbuffer,
    VkImage image,
    VkAccessFlags srcAccessMask,
    VkAccessFlags dstAccessMask,
    VkImageLayout oldImageLayout,
    VkImageLayout newImageLayout,
    VkPipelineStageFlags srcStageMask,
    VkPipelineStageFlags dstStageMask,
    VkImageSubresourceRange subresourceRange) {
  VkImageMemoryBarrier imageMemoryBarrier = initializers::imageMemoryBarrier();
  imageMemoryBarrier.srcAccessMask = srcAccessMask;
  imageMemoryBarrier.dstAccessMask = dstAccessMask;
  imageMemoryBarrier.oldLayout = oldImageLayout;
  imageMemoryBarrier.newLayout = newImageLayout;
  imageMemoryBarrier.image = image;
  imageMemoryBarrier.subresourceRange = subresourceRange;

  vkCmdPipelineBarrier(
        cmdbuffer,
        srcStageMask,
        dstStageMask,
        0,
        0, nullptr,
        0, nullptr,
        1, &imageMemoryBarrier);
}

// Display error message and exit on fatal error
// void exitFatal(std::string message, std::string caption);



@@ 286,6 257,7 @@ static VkShaderModule loadShader(const char *fileName, VkDevice device) {
}

/** @brief Checks if a file exists */
#pragma GCC diagnostic ignored "-Wunused-function"
static bool fileExists(const std::string &filename) {
  std::ifstream f(filename.c_str());
  return !f.fail();

M vitamin-k/scene/vikCamera.hpp => vitamin-k/scene/vikCamera.hpp +1 -1
@@ 32,7 32,7 @@ class Camera {
    glm::vec3 position;
  } uboCamera;

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


M vitamin-k/scene/vikGear.hpp => vitamin-k/scene/vikGear.hpp +1 -1
@@ 66,7 66,7 @@ class Gear {
    std::vector<Vertex> vBuffer;
    std::vector<uint32_t> iBuffer;

    int i, j;
    int i;
    float r0, r1, r2;
    float ta, da;
    float u1, v1, u2, v2, len;

M vitamin-k/system/vikApplication.hpp => vitamin-k/system/vikApplication.hpp +4 -2
@@ 177,6 177,8 @@ class Application {
        case Input::Key::ESCAPE:
          quit = true;
          break;
        default:
          break;
      }

      if (state)


@@ 210,12 212,12 @@ class Application {
      case Settings::WAYLAND_SHELL:
        window = new WindowWaylandShell(&settings);
        break;
        break;
      case Settings::KHR_DISPLAY:
        window = new WindowKhrDisplay(&settings);
      case Settings::AUTO:
      default:
        return -1;
    }
    return 0;
  }

  void init_window_auto() {

M vitamin-k/system/vikLog.hpp => vitamin-k/system/vikLog.hpp +4 -0
@@ 95,6 95,8 @@ class Log {
        return "e";
      case FATAL:
        return "fatal";
      default:
        return "?";
    }
  }



@@ 109,6 111,8 @@ class Log {
      case ERROR:
      case FATAL:
        return 31;
      default:
        return 36;
    }
  }


M vitamin-k/window/vikWindow.hpp => vitamin-k/window/vikWindow.hpp +1 -1
@@ 44,7 44,7 @@ class Window {
    settings = s;
  }

  ~Window() {}
  virtual ~Window() {}


  void set_render_frame_cb(std::function<void()> cb) {

M vitamin-k/window/vikWindowKhrDisplay.hpp => vitamin-k/window/vikWindowKhrDisplay.hpp +4 -1
@@ 141,7 141,10 @@ class WindowKhrDisplay  : public Window {

  void update_window_title(const std::string& title) {}

  int init(uint32_t width, uint32_t height) {}
  int init(uint32_t width, uint32_t height) {
    return 0;
  }

  void iterate() {}

  VkBool32 check_support(VkPhysicalDevice physical_device) {

M vitamin-k/window/vikWindowWayland.hpp => vitamin-k/window/vikWindowWayland.hpp +6 -0
@@ 92,6 92,8 @@ class WindowWayland : public Window {
        return Input::Key::F1;
      case KEY_ESC:
        return Input::Key::ESCAPE;
      default:
        return Input::Key::UNKNOWN;
    }
  }



@@ 101,6 103,8 @@ class WindowWayland : public Window {
        return Input::MouseScrollAxis::X;
      case REL_Y:
        return Input::MouseScrollAxis::Y;
      default:
        return Input::MouseScrollAxis::X;
    }
  }



@@ 112,6 116,8 @@ class WindowWayland : public Window {
        return Input::MouseButton::Middle;
      case BTN_RIGHT:
        return Input::MouseButton::Right;
      default:
        return Input::MouseButton::Left;
    }
  }


M vitamin-k/window/vikWindowXCB.hpp => vitamin-k/window/vikWindowXCB.hpp +4 -0
@@ 177,6 177,8 @@ class WindowXCB : public Window {
        return Input::MouseButton::Middle;
      case XCB_BUTTON_INDEX_3:
        return Input::MouseButton::Right;
      default:
        return Input::MouseButton::Left;
    }
  }



@@ 197,6 199,8 @@ class WindowXCB : public Window {
        return Input::Key::F1;
      case XK_Escape:
        return Input::Key::ESCAPE;
      default:
        return Input::Key::ESCAPE;
    }
  }