~sircmpwn/xrgears

ref: c4afd33e13398688fc03f60ef3d0a498bf40bfdd xrgears/vitamin-k/VikNodeGear.hpp -rw-r--r-- 1.6 KiB
c4afd33e — Lubosz Sarnecki add new abstract classes for interfaces between vks and vkc. 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Vulkan Example - Animated gears using multiple uniform buffers
*
* See readme.md for details
*
* Copyright (C) 2015 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#pragma once

#include <math.h>

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

#include <vulkan/vulkan.h>

#include <vector>

#include "../vks/vksTools.hpp"
#include "../vks/vksBuffer.hpp"
#include "../vks/vksCamera.hpp"

#include "VikMaterial.hpp"
#include "VikGear.hpp"
#include "VikSkyBox.hpp"
#include "VikNode.hpp"

class VikNodeGear : public VikNode {
 private:
  VikGear gear;

 public:
  void generate(vks::Device *vulkanDevice, GearInfo *gearinfo, VkQueue queue) {
    gear.generate(vulkanDevice, gearinfo, queue);
  }

  void draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout) {
    VkDeviceSize offsets[1] = { 0 };
    vkCmdBindDescriptorSets(cmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);
    vkCmdBindVertexBuffers(cmdbuffer, 0, 1, &gear.vertexBuffer.buffer, offsets);
    vkCmdBindIndexBuffer(cmdbuffer, gear.indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32);

    vkCmdPushConstants(cmdbuffer,
                       pipelineLayout,
                       VK_SHADER_STAGE_FRAGMENT_BIT,
                       sizeof(glm::vec3),
                       sizeof(Material::PushBlock), &info.material);

    vkCmdDrawIndexed(cmdbuffer, gear.indexCount, 1, 0, 0, 1);
  }
};