1 /* 2 * Copyright (C) 2016 Google, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef MESHES_H 24 #define MESHES_H 25 26 #include <vulkan/vulkan.h> 27 #include <vector> 28 29 class Meshes { 30 public: 31 Meshes(VkDevice dev, const std::vector<VkMemoryPropertyFlags> &mem_flags); 32 ~Meshes(); 33 vertex_input_state()34 const VkPipelineVertexInputStateCreateInfo &vertex_input_state() const { return vertex_input_state_; } input_assembly_state()35 const VkPipelineInputAssemblyStateCreateInfo &input_assembly_state() const { return input_assembly_state_; } 36 37 enum Type { 38 MESH_PYRAMID, 39 MESH_ICOSPHERE, 40 MESH_TEAPOT, 41 42 MESH_COUNT, 43 }; 44 45 void cmd_bind_buffers(VkCommandBuffer cmd) const; 46 void cmd_draw(VkCommandBuffer cmd, Type type) const; 47 48 private: 49 void allocate_resources(VkDeviceSize vb_size, VkDeviceSize ib_size, const std::vector<VkMemoryPropertyFlags> &mem_flags); 50 51 VkDevice dev_; 52 53 VkVertexInputBindingDescription vertex_input_binding_; 54 std::vector<VkVertexInputAttributeDescription> vertex_input_attrs_; 55 VkPipelineVertexInputStateCreateInfo vertex_input_state_; 56 VkPipelineInputAssemblyStateCreateInfo input_assembly_state_; 57 VkIndexType index_type_; 58 59 std::vector<VkDrawIndexedIndirectCommand> draw_commands_; 60 61 VkBuffer vb_; 62 VkBuffer ib_; 63 VkDeviceMemory mem_; 64 VkDeviceSize ib_mem_offset_; 65 }; 66 67 #endif // MESHES_H 68