From 10d624055504dc3008208a1b0c0d83749815e951 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Wed, 24 Jul 2024 10:50:33 +0300 Subject: [PATCH] rework examples according to new changes --- examples/ExampleApps/BillboardExampleApp.cpp | 13 ++++--------- examples/ExampleApps/CubesExampleApp.cpp | 10 +++++++--- examples/ExampleApps/MovingCubeApp.cpp | 4 ++-- examples/ExampleApps/TexturedCubeExampleApp.cpp | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/ExampleApps/BillboardExampleApp.cpp b/examples/ExampleApps/BillboardExampleApp.cpp index b579a17..aa74776 100644 --- a/examples/ExampleApps/BillboardExampleApp.cpp +++ b/examples/ExampleApps/BillboardExampleApp.cpp @@ -73,12 +73,12 @@ namespace OpenVulkano m_uniBuffer.setId = 3; m_drawablesPool.resize(cntDrawables); m_nodesPool.resize(cntDrawables); - m_geo.reserve(cntDrawables); + m_geo.resize(cntDrawables); m_texturedMat.texture = &Texture::PLACEHOLDER; for (uint32_t i = 0; i < cntDrawables; i++) { - Geometry* geo = nullptr; + Geometry* geo = &m_geo[i]; m_nodesPool[i].Init(); if (i < quadsCnt) { @@ -94,11 +94,10 @@ namespace OpenVulkano } else { - geo = GeometryFactory::MakePyramid(1, 1, glm::vec4(0, 1, 0, 1)); + *geo = GeometryFactory::MakePyramid(1, 1, glm::vec4(0, 1, 0, 1)); m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(-5 + std::rand() % 5, -5 + std::rand() % 5, -std::rand() % 10))); m_drawablesPool[i].Init(&m_shader, geo, &m_mat, &m_uniBuffer); } - m_geo.push_back(geo); m_scene.GetRoot()->AddChild(&m_nodesPool[i]); m_nodesPool[i].AddDrawable(&m_drawablesPool[i]); } @@ -123,10 +122,6 @@ namespace OpenVulkano void Close() override { - for (Geometry* g: m_geo) - { - delete g; - } } private: @@ -143,7 +138,7 @@ namespace OpenVulkano std::vector m_nodesPool; Vector3f_SIMD m_position = { 0, 0, -10 }; OpenVulkano::Scene::UI::SimpleUi m_ui; - std::vector m_geo; + std::vector m_geo; std::shared_ptr m_perfInfo; }; diff --git a/examples/ExampleApps/CubesExampleApp.cpp b/examples/ExampleApps/CubesExampleApp.cpp index 8e24702..8b3909b 100644 --- a/examples/ExampleApps/CubesExampleApp.cpp +++ b/examples/ExampleApps/CubesExampleApp.cpp @@ -42,6 +42,7 @@ namespace OpenVulkano std::vector drawablesPool; std::vector nodesPool; Vector3f_SIMD position = {0, 0, -10}; + std::vector m_geos; OpenVulkano::Scene::UI::SimpleUi m_ui; std::shared_ptr m_perfInfo; @@ -61,11 +62,14 @@ namespace OpenVulkano shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basic"); shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription()); drawablesPool.resize(GEOS); + m_geos.reserve(GEOS); for (uint32_t i = 0; i < GEOS; i++) { - Geometry* geo = GeometryFactory::MakeCube(std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, - Vector4f((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1)); - drawablesPool[i].Init(&shader, geo, &mat); + m_geos.push_back(GeometryFactory::MakeCube( + std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, + std::rand() % 1000 / 1000.0f + 0.01f, + Vector4f((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1))); + drawablesPool[i].Init(&shader, &m_geos[i], &mat); } nodesPool.resize(OBJECTS); for (uint32_t i = 0; i < OBJECTS; i++) diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index 281f4e6..1f637b0 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -33,7 +33,7 @@ namespace OpenVulkano { struct SceneElement { - Scene::Geometry *m_geometry; + Scene::Geometry m_geometry; Scene::SimpleDrawable m_drawable; Scene::Node m_node; }; @@ -70,7 +70,7 @@ namespace OpenVulkano void CompleteSceneElement(SceneElement *dest) { - dest->m_drawable.Init(&m_shader, dest->m_geometry, &m_material); + dest->m_drawable.Init(&m_shader, &dest->m_geometry, &m_material); dest->m_node.Init(); m_scene.GetRoot()->AddChild(&dest->m_node); dest->m_node.SetUpdateFrequency(Scene::UpdateFrequency::Always); diff --git a/examples/ExampleApps/TexturedCubeExampleApp.cpp b/examples/ExampleApps/TexturedCubeExampleApp.cpp index 39c6906..af3ba7d 100644 --- a/examples/ExampleApps/TexturedCubeExampleApp.cpp +++ b/examples/ExampleApps/TexturedCubeExampleApp.cpp @@ -49,9 +49,9 @@ namespace OpenVulkano shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basicTexture"); shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription()); shader.AddDescriptorSetLayoutBinding(Texture::DESCRIPTOR_SET_LAYOUT_BINDING); - Geometry* geo = GeometryFactory::MakeCube(); + static Geometry geo = GeometryFactory::MakeCube(); mat.texture = &Texture::PLACEHOLDER; - drawable.Init(&shader, geo, &mat); + drawable.Init(&shader, &geo, &mat); node.Init(); scene.GetRoot()->AddChild(&node); node.SetUpdateFrequency(UpdateFrequency::Always);