~sircmpwn/xrgears

e41ee3b209868c812883716a31ce02166d756912 — Lubosz Sarnecki 4 years ago 798b872
vitamin-k: apply linter style. use relative include paths.
M examples/triangle/triangle.cpp => examples/triangle/triangle.cpp +11 -21
@@ 15,16 15,17 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fstream>
#include <vector>
#include <exception>

#include <vulkan/vulkan.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <vulkan/vulkan.h>
#include <fstream>
#include <vector>
#include <exception>

#include "system/vikApplication.hpp"
#include "render/vikShader.hpp"


@@ 33,8 34,7 @@
// See "prepareVertices" for details on what's staging and on why to use it
#define USE_STAGING true

class Triangle : public vik::Application
{
class Triangle : public vik::Application {
public:
  // Vertex layout used in this example
  struct Vertex {


@@ 133,9 133,7 @@ public:
    vkDestroySemaphore(renderer->device, renderer->semaphores.render_complete, nullptr);

    for (auto& fence : waitFences)
    {
      vkDestroyFence(renderer->device, fence, nullptr);
    }
  }

  // This function is used to request a device memory type that supports all the property flags we request (e.g. device local, host visibile)


@@ 145,15 143,10 @@ public:
  // You can check http://vulkan.gpuinfo.org/ for details on different memory configurations
  uint32_t getMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) {
    // Iterate over all memory types available for the device used in this example
    for (uint32_t i = 0; i < renderer->deviceMemoryProperties.memoryTypeCount; i++)
    {
      if ((typeBits & 1) == 1)
      {
        if ((renderer->deviceMemoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
        {
    for (uint32_t i = 0; i < renderer->deviceMemoryProperties.memoryTypeCount; i++) {
      if ((typeBits & 1) == 1
          && (renderer->deviceMemoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
          return i;
        }
      }
      typeBits >>= 1;
    }



@@ 183,9 176,7 @@ public:
    fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
    waitFences.resize(renderer->cmd_buffers.size());
    for (auto& fence : waitFences)
    {
      vik_log_check(vkCreateFence(renderer->device, &fenceCreateInfo, nullptr, &fence));
    }
  }

  // End the command buffer and submit it to the queue


@@ 303,7 294,7 @@ public:

    VkSubmitInfo submit_info = renderer->init_render_submit_info();
    submit_info.pCommandBuffers = renderer->get_current_command_buffer();
   // Submit to the graphics queue passing a wait fence
    // Submit to the graphics queue passing a wait fence
    vik_log_check(vkQueueSubmit(renderer->queue, 1, &submit_info, waitFences[renderer->currentBuffer]));
  }



@@ 315,8 306,7 @@ public:
    //	what should be done a real-world application, where you should allocate large chunkgs of memory at once isntead.

    // Setup vertices
    std::vector<Vertex> vertexBuffer =
    {
    std::vector<Vertex> vertexBuffer = {
      { {  1.0f,  1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
      { { -1.0f,  1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } },
      { {  0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }

M examples/xrcube/xrcube.cpp => examples/xrcube/xrcube.cpp +9 -13
@@ 4,9 4,8 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fstream>
#include <vector>
#include <exception>

#include <vulkan/vulkan.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE


@@ 14,18 13,17 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/euler_angles.hpp>

#include <vulkan/vulkan.h>
#include <fstream>
#include <vector>
#include <exception>

#include "system/vikApplication.hpp"
#include "render/vikShader.hpp"

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

class XrCube : public vik::Application
{
public:

class XrCube : public vik::Application {
 public:
  void *map;

  struct ubo {


@@ 214,7 212,7 @@ public:
    colorinfo.attachmentCount = 1;
    colorinfo.pAttachments = attachments.data();

    VkDynamicState dynamicStates []  = {
    VkDynamicState dynamicStates[] = {
      VK_DYNAMIC_STATE_VIEWPORT,
      VK_DYNAMIC_STATE_SCISSOR,
    };


@@ 256,7 254,6 @@ public:
  }

  VkDescriptorSetLayout init_descriptor_set_layout() {

    VkDescriptorSetLayoutBinding bindings = {};
    bindings.binding = 0;
    bindings.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;


@@ 576,7 573,6 @@ public:
    vik_log_e_if(r != VK_SUCCESS,
                 "vkEndCommandBuffer: %s", vik::Log::result_string(r).c_str());
  }

};

int main(int argc, char *argv[]) {

M examples/xrgears/xrgears.cpp => examples/xrgears/xrgears.cpp +19 -31
@@ 13,20 13,19 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vector>

#include <vulkan/vulkan.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <gli/gli.hpp>

#include <vulkan/vulkan.h>
#include <vector>

#include "system/vikApplication.hpp"
#include "render/vikModel.hpp"

#include "scene/vikNodeGear.hpp"
#include "scene/vikSkyBox.hpp"
#include "render/vikDistortion.hpp"


@@ 103,8 102,7 @@ public:
    //paused = true;
  }

  ~XRGears()
  {
  ~XRGears() {
    delete offscreenPass;

    vkDestroyPipeline(renderer->device, pipelines.pbr, nullptr);


@@ 147,12 145,13 @@ public:
  void build_command_buffers() {
    vik_log_d("Draw command buffers size: %ld", renderer->cmd_buffers.size());

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

  inline VkRenderPassBeginInfo defaultRenderPassBeginInfo() {


@@ 212,8 211,8 @@ public:
    buildPbrCommandBuffer(offScreenCmdBuffer, unused, true);
  }

  void buildPbrCommandBuffer(VkCommandBuffer& cmdBuffer, VkFramebuffer& framebuffer, bool offScreen) {

  void buildPbrCommandBuffer(const VkCommandBuffer& cmdBuffer,
                             const VkFramebuffer& framebuffer, bool offScreen) {
    VkCommandBufferBeginInfo cmdBufInfo = vik::initializers::commandBufferBeginInfo();
    vik_log_check(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo));



@@ 315,8 314,7 @@ public:
    std::vector<float> rotationOffsets = { 0.0f, -9.0f, -30.0f };

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


@@ 348,11 346,9 @@ public:

    glm::vec3 teapotPosition = glm::vec3(-15.0, -5.0, -5.0);
    teapotNode->setPosition(teapotPosition);

  }

  void prepareVertices()
  {
  void prepareVertices() {
    // Binding and attribute descriptions are shared across all gears
    vertices.bindingDescriptions.resize(1);
    vertices.bindingDescriptions[0] =


@@ 393,8 389,7 @@ public:
    vertices.inputState.pVertexAttributeDescriptions = vertices.attributeDescriptions.data();
  }

  void setupDescriptorPool()
  {
  void setupDescriptorPool() {
    // Example uses two ubos
    std::vector<VkDescriptorPoolSize> poolSizes = {
      vik::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 16),


@@ 410,10 405,8 @@ public:
    vik_log_check(vkCreateDescriptorPool(renderer->device, &descriptorPoolInfo, nullptr, &renderer->descriptorPool));
  }

  void setupDescriptorSetLayout()
  {
    std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings =
    {
  void setupDescriptorSetLayout() {
    std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
      // ubo model
      vik::initializers::descriptorSetLayoutBinding(
      VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,


@@ 530,7 523,7 @@ public:
    if (enableDistortion)
      usedPass = offscreenPass->getRenderPass();
    else
      usedPass =renderer->render_pass;
      usedPass = renderer->render_pass;

    pipelineCreateInfo = vik::initializers::pipelineCreateInfo(pipelineLayout, usedPass);



@@ 542,7 535,6 @@ public:
      vik::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0),					// Location 0: Position
      vik::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 3),	// Location 1: Normals
      vik::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 6),	// Location 2: Color

    };
    VkPipelineVertexInputStateCreateInfo vertexInputState = vik::initializers::pipelineVertexInputStateCreateInfo();
    vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexInputBindings.size());


@@ 572,8 564,7 @@ public:
  }

  // Prepare and initialize uniform buffer containing shader uniforms
  void prepareUniformBuffers()
  {
  void prepareUniformBuffers() {
    renderer->vksDevice->create_and_map(&uniformBuffers.lights, sizeof(uboLights));

    vikCamera->prepareUniformBuffers(renderer->vksDevice);


@@ 584,8 575,7 @@ public:
    updateUniformBuffers();
  }

  void updateUniformBuffers()
  {
  void updateUniformBuffers() {
    vikCamera->update(camera);

    vik::StereoView sv = {};


@@ 598,16 588,14 @@ public:
    updateLights();
  }

  void updateLights()
  {
  void updateLights() {
    const float p = 15.0f;
    uboLights.lights[0] = glm::vec4(-p, -p*0.5f, -p, 1.0f);
    uboLights.lights[1] = glm::vec4(-p, -p*0.5f,  p, 1.0f);
    uboLights.lights[2] = glm::vec4( p, -p*0.5f,  p, 1.0f);
    uboLights.lights[3] = glm::vec4( p, -p*0.5f, -p, 1.0f);

    if (!renderer->timer.animation_paused)
    {
    if (!renderer->timer.animation_paused) {
      uboLights.lights[0].x = sin(glm::radians(renderer->timer.animation_timer * 360.0f)) * 20.0f;
      uboLights.lights[0].z = cos(glm::radians(renderer->timer.animation_timer * 360.0f)) * 20.0f;
      uboLights.lights[1].x = cos(glm::radians(renderer->timer.animation_timer * 360.0f)) * 20.0f;

M vitamin-k/input/vikHMD.hpp => vitamin-k/input/vikHMD.hpp +5 -7
@@ 20,12 20,10 @@

#include <openhmd/openhmd.h>

#include "scene/vikCameraBase.hpp"
#include "render/vikBuffer.hpp"
#include "system/vikLog.hpp"


#include "scene/vikCamera.hpp"
#include "../scene/vikCameraBase.hpp"
#include "../render/vikBuffer.hpp"
#include "../system/vikLog.hpp"
#include "../scene/vikCamera.hpp"

namespace vik {
class HMD {


@@ 121,4 119,4 @@ class HMD {
    *hmdViewRight = glm::make_mat4(mat);
  }
};
}
}  // namespace vik

M vitamin-k/input/vikInput.hpp => vitamin-k/input/vikInput.hpp +12 -3
@@ 1,8 1,18 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 */

#pragma once

namespace vik {
class Input {
public:
 public:
  enum MouseButton {
    Left,
    Middle,


@@ 24,6 34,5 @@ public:
    D,
    P
  };

};
}
}  // namespace vik

M vitamin-k/render/vikBuffer.hpp => vitamin-k/render/vikBuffer.hpp +1 -1
@@ 144,4 144,4 @@ struct Buffer {
      vkFreeMemory(device, memory, nullptr);
  }
};
}  // namespace vks
}  // namespace vik

M vitamin-k/render/vikDebug.hpp => vitamin-k/render/vikDebug.hpp +1 -1
@@ 271,4 271,4 @@ 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 vks
}  // namespace vik

M vitamin-k/render/vikDevice.hpp => vitamin-k/render/vikDevice.hpp +1 -2
@@ 569,6 569,5 @@ class Device {
      printf("perViewPositionAllComponents %d\n", extProps2.perViewPositionAllComponents);
    }
  }

};
}  // namespace vks
}  // namespace vik

M vitamin-k/render/vikDistortion.hpp => vitamin-k/render/vikDistortion.hpp +1 -1
@@ 316,4 316,4 @@ class Distortion {
    vik_log_check(uboHandle.map());
  }
};
}
}  // namespace vik

M vitamin-k/render/vikInitializers.hpp => vitamin-k/render/vikInitializers.hpp +1 -1
@@ 436,4 436,4 @@ inline VkPushConstantRange pushConstantRange(
  return pushConstantRange;
}
}  // namespace initializers
}  // namespace vks
}  // namespace vik

M vitamin-k/render/vikModel.hpp => vitamin-k/render/vikModel.hpp +1 -1
@@ 340,4 340,4 @@ struct Model {
    return loadFromFile(filename, layout, &modelCreateInfo, device, copyQueue, flags);
  }
};
}  // namespace vks
}  // namespace vik

M vitamin-k/render/vikOffscreenPass.hpp => vitamin-k/render/vikOffscreenPass.hpp +1 -1
@@ 319,4 319,4 @@ class OffscreenPass {
    return offScreenFrameBuf.renderPass;
  }
};
}
}  // namespace vik

M vitamin-k/render/vikRenderer.hpp => vitamin-k/render/vikRenderer.hpp +19 -12
@@ 1,3 1,15 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#define VK_PROTOTYPES


@@ 8,23 20,21 @@
#include <functional>

#include "vikSwapChain.hpp"
#include "system/vikSettings.hpp"
#include "vikDebug.hpp"
#include "window/vikWindow.hpp"
#include "vikInitializers.hpp"
#include "vikRenderer.hpp"

#include "vikDevice.hpp"
#include "vikSwapChainVK.hpp"
#include "vikTimer.hpp"
#include "vikTextOverlay.hpp"
#include "system/vikSettings.hpp"
#include "vikShader.hpp"

#include "../system/vikSettings.hpp"
#include "../window/vikWindow.hpp"

namespace vik {

class Renderer {
public:
 public:
  VkInstance instance;
  VkDevice device;
  VkPhysicalDevice physical_device;


@@ 107,7 117,6 @@ public:
      render_cb();
      submit_frame();
    });

  }

  ~Renderer() {


@@ 416,7 425,7 @@ public:

    device = vksDevice->logicalDevice;

    //vksDevice->printMultiviewProperties();
    // vksDevice->printMultiviewProperties();

    // Get a graphics queue from the device
    vkGetDeviceQueue(device, vksDevice->queueFamilyIndices.graphics, 0, &queue);


@@ 426,7 435,6 @@ public:
    assert(validDepthFormat);

    init_semaphores();

  }

  virtual void init_semaphores() {


@@ 462,8 470,7 @@ public:
  }

  virtual void resize() {

    vik_log_e("Resize!");
    vik_log_d("Resize!");

    // Ensure all operations on the device have been finished before destroying resources
    wait_idle();


@@ 708,4 715,4 @@ public:
    check_tick_finnished();
  }
};
}
}  // namespace vik

M vitamin-k/render/vikRendererTextOverlay.hpp => vitamin-k/render/vikRendererTextOverlay.hpp +15 -3
@@ 1,14 1,26 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#include <string>
#include <vector>

#include "vikRenderer.hpp"

namespace vik {

class RendererTextOverlay : public Renderer {
public:

 public:
  TextOverlay *textOverlay;

  VkSemaphore text_overlay_complete;


@@ 123,4 135,4 @@ public:
    vik_log_check(vkCreateSemaphore(device, &semaphore_info, nullptr, &text_overlay_complete));
  }
};
}
}  // namespace vik

M vitamin-k/render/vikShader.hpp => vitamin-k/render/vikShader.hpp +2 -3
@@ 17,7 17,7 @@

#include "vikTools.hpp"

#include "system/vikAssets.hpp"
#include "../system/vikAssets.hpp"

namespace vik {
class Shader {


@@ 34,5 34,4 @@ class Shader {
    return shaderStage;
  }
};
}

}  // namespace vik

M vitamin-k/render/vikSwapChain.hpp => vitamin-k/render/vikSwapChain.hpp +16 -5
@@ 1,3 1,15 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#include <vulkan/vulkan.h>


@@ 5,8 17,8 @@
#include <vector>
#include <functional>

#include "system/vikLog.hpp"
#include "system/vikSettings.hpp"
#include "../system/vikLog.hpp"
#include "../system/vikSettings.hpp"

namespace vik {



@@ 16,7 28,7 @@ struct SwapChainBuffer {
};

class SwapChain {
public:
 public:
  VkPhysicalDevice physical_device;
  VkDevice device;
  VkInstance instance;


@@ 85,6 97,5 @@ public:

    vik_log_check(vkCreateImageView(device, &view_create_info, nullptr, view));
  }

};
}
}  // namespace vik

M vitamin-k/render/vikSwapChainDRM.hpp => vitamin-k/render/vikSwapChainDRM.hpp +23 -14
@@ 1,3 1,19 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2012 Arvin Schnell <arvin.schnell@gmail.com>
 * Copyright (C) 2012 Rob Clark <rob@ti.com>
 * Copyright (C) 2015 Intel Corporation
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on kmscube example written by Rob Clark, based on test app originally
 * written by Arvin Schnell.
 * Based on vkcube example.
 */

#pragma once

#include <gbm.h>


@@ 10,8 26,6 @@
#include <poll.h>
#include <signal.h>

#include <gbm.h>

#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>


@@ 24,6 38,8 @@
#include <linux/vt.h>
#include <linux/major.h>

#include <vector>

#include "vikSwapChain.hpp"

namespace vik {


@@ 36,9 52,7 @@ struct KMSBuffer {
};

class SwapChainDRM : public SwapChain {

public:

 public:
  std::vector<KMSBuffer> kms_buffers;
  int current;



@@ 48,15 62,11 @@ public:
    kms_buffers.resize(image_count);
  }

  ~SwapChainDRM() {
  }
  ~SwapChainDRM() {}

  void cleanup() {
  void cleanup() {}

  }

  void create(uint32_t width, uint32_t height) {
  }
  void create(uint32_t width, uint32_t height) {}

  void init(VkDevice device, VkFormat image_format, gbm_device *gbm_dev, int fd,
            uint32_t width, uint32_t height) {


@@ 129,6 139,5 @@ public:
    vik_log_f_if(ret < 0, "pageflip failed: %m");
    current++;
  }

};
}
}  // namespace vik

M vitamin-k/render/vikSwapChainVK.hpp => vitamin-k/render/vikSwapChainVK.hpp +14 -21
@@ 1,3 1,15 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#include <vulkan/vulkan.h>


@@ 6,7 18,7 @@

namespace vik {
class SwapChainVK : public SwapChain {
public:
 public:
  /** @brief Handle to the current swap chain, required for recreation */
  VkSwapchainKHR swap_chain = VK_NULL_HANDLE;



@@ 184,24 196,6 @@ public:
    return mode;
  }

  void render(VkQueue queue, VkSemaphore semaphore) {
    uint32_t present_index = 0;
    VkResult result = acquire_next_image(semaphore, &present_index);
    switch (result) {
      case VK_SUCCESS:
        render_cb(present_index);
        vik_log_check(present(queue, present_index));
        break;
      case VK_TIMEOUT:
        // TODO: XCB times out
        break;
      default:
        vik_log_e("vkAcquireNextImageKHR failed: %s",
                   Log::result_string(result).c_str());
        break;
    }
  }

  /**
  * Destroy and free Vulkan resources used for the swapchain
  */


@@ 218,6 212,5 @@ public:
    surface = VK_NULL_HANDLE;
    swap_chain = VK_NULL_HANDLE;
  }

};
}
}  // namespace vik

M vitamin-k/render/vikSwapChainVKComplex.hpp => vitamin-k/render/vikSwapChainVKComplex.hpp +1 -2
@@ 249,6 249,5 @@ class SwapChainVkComplex : public vik::SwapChainVK {

    update_images();
  }

};
}
}  // namespace vik

M vitamin-k/render/vikTextOverlay.hpp => vitamin-k/render/vikTextOverlay.hpp +1 -2
@@ 708,6 708,5 @@ class TextOverlay {
    addText(device, 5.0f, 45.0f, TextOverlay::alignLeft);
    endTextUpdate();
  }

};
}
}  // namespace vik

M vitamin-k/render/vikTexture.hpp => vitamin-k/render/vikTexture.hpp +0 -3
@@ 79,7 79,6 @@ 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());

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


@@ 527,7 526,6 @@ class Texture2DArray : public Texture {
      VkQueue copyQueue,
      VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT,
      VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {

    vik_log_f_if(!tools::fileExists(filename),
                 "File not found: Could not load texture from %s",
                 filename.c_str());


@@ 717,7 715,6 @@ class TextureCubeMap : public Texture {
      VkQueue copyQueue,
      VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT,
      VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {

    vik_log_f_if(!tools::fileExists(filename),
                 "File not found: Could not load texture from %s",
                 filename.c_str());

M vitamin-k/render/vikTimer.hpp => vitamin-k/render/vikTimer.hpp +16 -11
@@ 1,11 1,22 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#include <chrono>

namespace vik {
class Timer {
public:

 public:
  const double SECOND_IN_MILLI = 1000.0;

  double time_since_tick = 0.0;


@@ 24,12 35,8 @@ public:

  bool animation_paused = false;

  Timer() {

  }
  ~Timer() {

  }
  Timer() {}
  ~Timer() {}

  bool tick_finnished() {
    return time_since_tick > SECOND_IN_MILLI;


@@ 70,9 77,7 @@ public:
    auto frame_time_end = std::chrono::high_resolution_clock::now();
    auto frame_time_milli = std::chrono::duration<double, std::milli>(frame_time_end - frame_time_start).count();

    //printf("diff: %f frame: %f tick: %f\n", frame_time_milli, frame_time_micro, time_since_tick);

    frame_time_seconds = frame_time_milli / 1000.0f; // to second
    frame_time_seconds = frame_time_milli / 1000.0f;  // to second
    time_since_tick += frame_time_milli;
    return frame_time_seconds;
  }

M vitamin-k/render/vikTools.hpp => vitamin-k/render/vikTools.hpp +1 -2
@@ 254,9 254,8 @@ static void insertImageMemoryBarrier(
}

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

// Load a SPIR-V shader (binary)
static VkShaderModule loadShader(const char *fileName, VkDevice device) {
  std::ifstream is(fileName, std::ios::binary | std::ios::in | std::ios::ate);


M vitamin-k/system/vikApplication.hpp => vitamin-k/system/vikApplication.hpp +23 -15
@@ 1,3 1,15 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2016 Sascha Willems - www.saschawillems.de
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on Vulkan Examples written by Sascha Willems
 */

#pragma once

#include <sys/stat.h>


@@ 17,25 29,24 @@

#include "vikSettings.hpp"

#include "window/vikWindowXCB.hpp"
#include "window/vikWindowWaylandXDG.hpp"
#include "window/vikWindowWaylandShell.hpp"
#include "window/vikWindowKMS.hpp"
#include "window/vikWindowKhrDisplay.hpp"
#include "../window/vikWindowXCB.hpp"
#include "../window/vikWindowWaylandXDG.hpp"
#include "../window/vikWindowWaylandShell.hpp"
#include "../window/vikWindowKMS.hpp"
#include "../window/vikWindowKhrDisplay.hpp"

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

#include "scene/vikCameraBase.hpp"
#include "render/vikRendererTextOverlay.hpp"
#include "../scene/vikCameraBase.hpp"
#include "../render/vikRendererTextOverlay.hpp"

#include "render/vikTimer.hpp"
#include "../render/vikTimer.hpp"

#include "vikApplication.hpp"

namespace vik {
class Application {
public:
 public:
  Settings settings;
  Window *window;
  bool quit = false;


@@ 267,10 278,7 @@ public:

    camera.update_aspect_ratio(renderer->get_aspect_ratio());

    // Notify derived class
    //windowResized();
    view_changed_cb();
  }

};
}

M vitamin-k/system/vikLog.hpp => vitamin-k/system/vikLog.hpp +14 -6
@@ 1,3 1,13 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 */

#pragma once

#include <stdio.h>


@@ 29,10 39,9 @@

namespace vik {
class Log {

  static const bool use_color = true;

public:
 public:
  enum type {
    DEBUG = 0,
    INFO,


@@ 76,7 85,7 @@ public:
  }

  static const char* type_str(type t) {
    switch(t) {
    switch (t) {
      case DEBUG:
        return "d";
      case INFO:


@@ 91,7 100,7 @@ public:
  }

  static int type_color(type t) {
    switch(t) {
    switch (t) {
      case DEBUG:
        return 36;
      case INFO:


@@ 108,7 117,7 @@ public:
#ifdef LOG_TO_STD_ERR
    return stderr;
#endif
    switch(t) {
    switch (t) {
      case DEBUG:
      case INFO:
      case WARNING:


@@ 161,7 170,6 @@ public:
    log_values(file, line, t, format, args);
    va_end(args);
  }

};
}


M vitamin-k/system/vikSettings.hpp => vitamin-k/system/vikSettings.hpp +14 -5
@@ 1,3 1,13 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 */

#pragma once

#include <stdint.h>


@@ 10,8 20,7 @@

namespace vik {
class Settings {
public:

 public:
  enum window_type {
    AUTO = 0,
    KMS,


@@ 51,7 60,7 @@ public:
        "                              [xcb, wayland, kms]\n"
        "  -h, --help                  Display help\n";

    //for (auto const& wsh : window_system_help)
    // for (auto const& wsh : window_system_help)
    //    help += wsh;

    return help;


@@ 130,8 139,9 @@ public:
        type = window_type_from_string(optarg);
        if (type == INVALID)
          vik_log_f("option -m given bad display mode");
      } else
      } else {
        vik_log_f("Unknown option %s", optname.c_str());
      }
    }

    if (optind != argc)


@@ 160,6 170,5 @@ public:
    else
      return INVALID;
  }

};
}

M vitamin-k/window/vikWindow.hpp => vitamin-k/window/vikWindow.hpp +17 -5
@@ 1,14 1,26 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 */

#pragma once

#include <functional>
#include <string>
#include <vector>

#include "render/vikSwapChain.hpp"
#include "input/vikInput.hpp"
#include "system/vikSettings.hpp"
#include "../render/vikSwapChain.hpp"
#include "../input/vikInput.hpp"
#include "../system/vikSettings.hpp"

namespace vik {
class Window {
public:
 public:
  std::string name;

  std::function<void()> quit_cb;


@@ 29,7 41,7 @@ public:

  Settings *settings;

  Window(Settings *s) {
  explicit Window(Settings *s) {
    settings = s;
  }


M vitamin-k/window/vikWindowKMS.hpp => vitamin-k/window/vikWindowKMS.hpp +24 -6
@@ 1,3 1,19 @@
/*
 * vitamin-k
 *
 * Copyright (C) 2012 Arvin Schnell <arvin.schnell@gmail.com>
 * Copyright (C) 2012 Rob Clark <rob@ti.com>
 * Copyright (C) 2015 Intel Corporation
 * Copyright (C) 2017 Lubosz Sarnecki <lubosz.sarnecki@collabora.co.uk>
 *
 * This code is licensed under the GNU General Public License Version 3 (GPLv3)
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 *
 * Based on kmscube example written by Rob Clark, based on test app originally
 * written by Arvin Schnell.
 * Based on vkcube example.
 */

#pragma once

#include <fcntl.h>


@@ 21,9 37,13 @@
#include <linux/vt.h>
#include <linux/major.h>

#include <string>
#include <vector>

#include "vikWindow.hpp"
#include "system/vikLog.hpp"
#include "render/vikSwapChainDRM.hpp"

#include "../system/vikLog.hpp"
#include "../render/vikSwapChainDRM.hpp"

static void
page_flip_handler(int fd, unsigned int frame,


@@ 34,7 54,6 @@ static struct termios save_tio;

namespace vik {
class WindowKMS : public Window {

  drmModeCrtc *crtc;
  drmModeConnector *connector;



@@ 48,8 67,8 @@ class WindowKMS : public Window {

  SwapChainDRM swap_chain;

public:
  WindowKMS(Settings *s) : Window(s) {
 public:
  explicit WindowKMS(Settings *s) : Window(s) {
    gbm_dev = NULL;
    name = "kms";



@@ 218,6 237,5 @@ public:
  VkBool32 check_support(VkPhysicalDevice physical_device) {
    return true;
  }

};
}

M vitamin-k/window/vikWindowKhrDisplay.hpp => vitamin-k/window/vikWindowKhrDisplay.hpp +2 -4
@@ 14,15 14,14 @@
#include <vulkan/vulkan.h>

#include "vikWindow.hpp"
#include "render/vikSwapChainVKComplex.hpp"
#include "../render/vikSwapChainVKComplex.hpp"

namespace vik {
class WindowKhrDisplay  : public Window {

  SwapChainVkComplex swap_chain;

 public:
  WindowKhrDisplay(Settings *s) : Window(s) {}
  explicit WindowKhrDisplay(Settings *s) : Window(s) {}
  ~WindowKhrDisplay() {}

  const std::vector<const char*> required_extensions() {


@@ 30,7 29,6 @@ class WindowKhrDisplay  : public Window {
  }

  void init_swap_chain(uint32_t width, uint32_t height) {

    uint32_t displayPropertyCount;

    VkPhysicalDevice physical_device = swap_chain.physical_device;

M vitamin-k/window/vikWindowWaylandShell.hpp => vitamin-k/window/vikWindowWaylandShell.hpp +0 -2
@@ 18,7 18,6 @@

namespace vik {
class WindowWaylandShell : public WindowWayland {

  wl_shell *shell = nullptr;
  wl_shell_surface *shell_surface = nullptr;



@@ 118,6 117,5 @@ public:

  // Unused callbacks
  static void _popup_done_cb(void *data, wl_shell_surface *shell_surface) {}

};
}

M vitamin-k/window/vikWindowWaylandXDG.hpp => vitamin-k/window/vikWindowWaylandXDG.hpp +3 -5
@@ 6,13 6,12 @@
#include <poll.h>

#include <vulkan/vulkan.h>
#include "../xdg-shell/xdg-shell-unstable-v6-client-protocol.h"
#include "system/vikLog.hpp"
#include "../../xdg-shell/xdg-shell-unstable-v6-client-protocol.h"
#include "../system/vikLog.hpp"
#include "vikWindowWayland.hpp"

namespace vik {
class WindowWaylandXDG : public WindowWayland {

  struct zxdg_shell_v6 *shell = nullptr;
  struct zxdg_surface_v6 *xdg_surface = nullptr;
  struct zxdg_toplevel_v6 *xdg_toplevel = nullptr;


@@ 78,7 77,7 @@ public:
  void registry_global(wl_registry *registry, uint32_t name,
                       const char *interface) {
    if (strcmp(interface, "wl_compositor") == 0) {
      compositor = ( wl_compositor*)
      compositor = (wl_compositor*)
          wl_registry_bind(registry, name, &wl_compositor_interface, 1);
    } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
      shell = (zxdg_shell_v6*)


@@ 142,6 141,5 @@ public:
                                         int32_t width, int32_t height,
                                         struct wl_array *states) {}
  static void _xdg_toplevel_close_cb(void *data, zxdg_toplevel_v6 *toplevel) {}

};
}

M vitamin-k/window/vikWindowXCB.hpp => vitamin-k/window/vikWindowXCB.hpp +0 -2
@@ 172,7 172,6 @@ public:
  }

  Input::Key xcb_to_vik_key(xcb_keycode_t key) {

    xcb_keysym_t xcb_keyp = xcb_key_symbols_get_keysym(syms, key, 0);
    switch (xcb_keyp) {
      case XK_w:


@@ 275,6 274,5 @@ public:
        break;
    }
  }

};
}