vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
manager.cpp
Go to the documentation of this file.
1#include <numeric>
2#include <ranges>
3
6
8{
9 // including nonCoherentAtomSize allows us to flush a specific index at once
10 unsigned long alignment = std::lcm(
11 device.getProperties().limits.nonCoherentAtomSize,
12 device.getProperties().limits.minUniformBufferOffsetAlignment
13 );
14 for (auto & uboBuffer : m_uboBuffers) {
15 uboBuffer = std::make_unique<Buffer>(
16 device,
17 sizeof(ObjectBufferData),
19 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
20 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
21 alignment);
22 uboBuffer->map();
23 }
24 Logger::logExecutionTime("Creating default texture", [&] {
25 m_textureDefault = TextureFactory::create(device, "assets/textures/default.png");
26 });
27}
28
29void ven::SceneManager::updateBuffer(GlobalUbo &ubo, const unsigned long frameIndex, const float frameTime)
30{
31 uint8_t lightIndex = 0;
32 const glm::mat4 rotateLight = rotate(glm::mat4(1.F), frameTime, {0.F, -1.F, 0.F});
33
34 for (Object& object : m_objects | std::views::values) {
35 const ObjectBufferData data{
36 .modelMatrix = object.transform.transformMatrix(),
37 .normalMatrix = object.transform.normalMatrix()
38 };
39 m_uboBuffers.at(frameIndex)->writeToIndex(&data, object.getId());
40 object.setBufferInfo(static_cast<int>(frameIndex), m_uboBuffers.at(frameIndex)->descriptorInfoForIndex(object.getId()));
41 }
42
43 for (Light &light : m_lights | std::views::values) {
44 auto&[position, color, shininess, padding] = ubo.pointLights.at(lightIndex);
45 light.transform.translation = glm::vec3(rotateLight * glm::vec4(light.transform.translation, light.transform.scale.x));
46 position = glm::vec4(light.transform.translation, light.transform.scale.x);
47 color = light.color;
48 shininess = light.getShininess();
49 lightIndex++;
50 }
51 ubo.numLights = lightIndex;
52}
53
54void ven::SceneManager::destroyEntity(std::vector<unsigned int> *objectsIds, std::vector<unsigned int> *lightsIds)
55{
56 for (const unsigned int objectId : *objectsIds) {
57 m_objects.erase(objectId);
58 }
59 for (const unsigned int lightId : *lightsIds) {
60 m_lights.erase(lightId);
61 }
62 objectsIds->clear();
63 lightsIds->clear();
64 m_destroyState = false;
65}
This file contains the Texture Factory class.
This file contains the SceneManager class.
Class for device.
Definition Device.hpp:35
VkPhysicalDeviceProperties getProperties() const
Definition Device.hpp:65
Class for light.
Definition Light.hpp:28
static void logExecutionTime(const std::string &message, Func &&func)
Definition Logger.hpp:35
Class for object.
Definition Object.hpp:24
void updateBuffer(GlobalUbo &ubo, unsigned long frameIndex, float frameTime)
Definition manager.cpp:29
std::vector< std::unique_ptr< Buffer > > m_uboBuffers
Definition Manager.hpp:55
std::shared_ptr< Texture > m_textureDefault
Definition Manager.hpp:52
void destroyEntity(std::vector< unsigned int > *objectsIds, std::vector< unsigned int > *lightsIds)
Definition manager.cpp:54
SceneManager(Device &device)
Definition manager.cpp:7
static std::unique_ptr< Texture > create(Device &device, const std::string &filepath)
Definition Texture.hpp:33
static constexpr uint16_t MAX_OBJECTS
Definition Object.hpp:17
std::array< PointLightData, MAX_LIGHTS > pointLights
Definition FrameInfo.hpp:40
uint8_t numLights
Definition FrameInfo.hpp:41