vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
object.cpp
Go to the documentation of this file.
1#include <ranges>
2
5
6void ven::ObjectRenderSystem::render(const FrameInfo &frameInfo) const
7{
8 getShaders()->bind(frameInfo.commandBuffer);
9
10 vkCmdBindDescriptorSets(frameInfo.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, getPipelineLayout(), 0, 1, &frameInfo.globalDescriptorSet, 0, nullptr);
11
12 for (Object& object : frameInfo.objects | std::views::values) {
13 if (object.getModel() == nullptr) { continue; }
14 auto bufferInfo = object.getBufferInfo(static_cast<int>(frameInfo.frameIndex));
15 auto imageInfo = object.getDiffuseMap()->getImageInfo();
16 VkDescriptorSet objectDescriptorSet = nullptr;
18 .writeBuffer(0, &bufferInfo)
19 .writeImage(1, &imageInfo)
20 .build(objectDescriptorSet);
21
22 vkCmdBindDescriptorSets(
23 frameInfo.commandBuffer,
24 VK_PIPELINE_BIND_POINT_GRAPHICS,
26 1, // starting set (0 is the globalDescriptorSet, 1 is the set specific to this system)
27 1, // set count
28 &objectDescriptorSet,
29 0,
30 nullptr);
31
32 const ObjectPushConstantData push{
33 .modelMatrix = object.transform.transformMatrix(),
34 .normalMatrix = object.transform.normalMatrix()
35 };
36 vkCmdPushConstants(frameInfo.commandBuffer, getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(ObjectPushConstantData), &push);
37 object.getModel()->bind(frameInfo.commandBuffer);
38 object.getModel()->draw(frameInfo.commandBuffer);
39 }
40}
This file contains the ObjectRenderSystem class.
This file contains the DescriptorsWriter class.
VkPipelineLayout getPipelineLayout() const
Definition ABase.hpp:40
std::unique_ptr< DescriptorSetLayout > renderSystemLayout
Definition ABase.hpp:43
const std::unique_ptr< Shaders > & getShaders() const
Definition ABase.hpp:41
Class for descriptor writer.
Definition Writer.hpp:19
DescriptorWriter & writeImage(uint32_t binding, const VkDescriptorImageInfo *imageInfo)
Definition writer.cpp:24
DescriptorWriter & writeBuffer(uint32_t binding, const VkDescriptorBufferInfo *bufferInfo)
Definition writer.cpp:5
bool build(VkDescriptorSet &set)
Definition writer.cpp:43
void render(const FrameInfo &frameInfo) const override
Definition object.cpp:6
Class for object.
Definition Object.hpp:24
Object::Map & objects
Definition FrameInfo.hpp:52
VkCommandBuffer commandBuffer
Definition FrameInfo.hpp:48
VkDescriptorSet globalDescriptorSet
Definition FrameInfo.hpp:50
DescriptorPool & frameDescriptorPool
Definition FrameInfo.hpp:51
unsigned long frameIndex
Definition FrameInfo.hpp:46