• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_VULKAN_VERTEX_BUFFER_H_
16 #define SRC_VULKAN_VERTEX_BUFFER_H_
17 
18 #include <map>
19 #include <memory>
20 #include <vector>
21 
22 #include "amber/result.h"
23 #include "amber/value.h"
24 #include "amber/vulkan_header.h"
25 #include "src/buffer.h"
26 #include "src/format.h"
27 #include "src/vulkan/transfer_buffer.h"
28 
29 namespace amber {
30 namespace vulkan {
31 
32 class CommandBuffer;
33 class Device;
34 
35 /// Wrapper around vertex data information.
36 class VertexBuffer {
37  public:
38   explicit VertexBuffer(Device* device);
39   ~VertexBuffer();
40 
41   Result SendVertexData(CommandBuffer* command);
VertexDataSent()42   bool VertexDataSent() const { return !is_vertex_data_pending_; }
43 
44   void SetData(uint8_t location,
45                Buffer* buffer,
46                InputRate rate,
47                Format* format,
48                uint32_t offset,
49                uint32_t stride);
50 
GetVkVertexInputAttr()51   const std::vector<VkVertexInputAttributeDescription>& GetVkVertexInputAttr()
52       const {
53     return vertex_attr_desc_;
54   }
GetVkVertexInputBinding()55   const std::vector<VkVertexInputBindingDescription>& GetVkVertexInputBinding()
56       const {
57     return vertex_binding_desc_;
58   }
59 
60   void BindToCommandBuffer(CommandBuffer* command);
61 
62  private:
63   Device* device_ = nullptr;
64 
65   bool is_vertex_data_pending_ = true;
66 
67   std::vector<std::unique_ptr<TransferBuffer>> transfer_buffers_;
68 
69   std::vector<Buffer*> data_;
70   std::vector<VkVertexInputBindingDescription> vertex_binding_desc_;
71   std::vector<VkVertexInputAttributeDescription> vertex_attr_desc_;
72   std::map<Buffer*, VkBuffer> buffer_to_vk_buffer_;
73 };
74 
75 }  // namespace vulkan
76 }  // namespace amber
77 
78 #endif  // SRC_VULKAN_VERTEX_BUFFER_H_
79