diff --git a/openVulkanoCpp/Base/EngineConfiguration.hpp b/openVulkanoCpp/Base/EngineConfiguration.hpp index 3e18c83..e803bd1 100644 --- a/openVulkanoCpp/Base/EngineConfiguration.hpp +++ b/openVulkanoCpp/Base/EngineConfiguration.hpp @@ -10,7 +10,7 @@ #include #undef max -namespace openVulkano +namespace OpenVulkano { class EngineConfiguration { diff --git a/openVulkanoCpp/Base/EngineConstants.hpp b/openVulkanoCpp/Base/EngineConstants.hpp index 49cbf00..9b1f899 100644 --- a/openVulkanoCpp/Base/EngineConstants.hpp +++ b/openVulkanoCpp/Base/EngineConstants.hpp @@ -1,8 +1,15 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + #pragma once + #include #include //TODO replace with external fmt -namespace openVulkano +namespace OpenVulkano { inline const char* ENGINE_NAME = "OpenVulkano"; diff --git a/openVulkanoCpp/ExampleApps/CubesExampleApp.cpp b/openVulkanoCpp/ExampleApps/CubesExampleApp.cpp index 475026c..0872a92 100644 --- a/openVulkanoCpp/ExampleApps/CubesExampleApp.cpp +++ b/openVulkanoCpp/ExampleApps/CubesExampleApp.cpp @@ -21,85 +21,95 @@ #pragma ide diagnostic ignored "cert-msc50-cpp" #pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions" -using namespace OpenVulkano::Scene; -using namespace OpenVulkano::Input; -using namespace OpenVulkano::Math; uint32_t GEOS = 3000, OBJECTS = 10000, DYNAMIC = 1000; -class CubesExampleAppImpl final : public CubesExampleApp +namespace OpenVulkano { - Scene scene; - PerspectiveCamera cam; - OpenVulkano::FreeCamCameraController camController; - Material mat; - Shader shader; - std::vector drawablesPool; - std::vector nodesPool; - Vector3f_SIMD position = {0,0,-10}; + using namespace Scene; + using namespace Input; + using namespace Math; -public: - std::string GetAppName() override { return "ExampleApp"; } - OpenVulkano::Version GetAppVersion() override { return {"v1.0"}; } - - void Init() override + class CubesExampleAppImpl final : public CubesExampleApp { - auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); - engineConfig->SetNumThreads(4); - engineConfig->SetPreferFramebufferFormatSRGB(false); + OpenVulkano::Scene::Scene scene; + PerspectiveCamera cam; + OpenVulkano::FreeCamCameraController camController; + Material mat; + Shader shader; + std::vector drawablesPool; + std::vector nodesPool; + Vector3f_SIMD position = {0, 0, -10}; - std::srand(1); // Fix seed for random numbers - scene.Init(); - cam.Init(70, 16, 9, 0.1f, 100); - scene.SetCamera(&cam); - cam.SetMatrix(Utils::translate(Matrix4f(1), Vector3f_SIMD(0,0,-10))); - shader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/basic"); - shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basic"); - shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription()); - drawablesPool.resize(GEOS); - for(uint32_t i = 0; i < GEOS; i++) + public: + std::string GetAppName() override + { return "ExampleApp"; } + + OpenVulkano::Version GetAppVersion() override + { return {"v1.0"}; } + + void Init() override { - Geometry* geo = new Geometry(); - geo->InitCube(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); - } - nodesPool.resize(OBJECTS); - for(uint32_t i = 0; i < OBJECTS; i++) - { - nodesPool[i].Init(); - scene.GetRoot()->AddChild(&nodesPool[i]); - if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always); - nodesPool[i].AddDrawable(&drawablesPool[std::rand() % GEOS]); - nodesPool[i].SetMatrix(Utils::translate(glm::mat4x4(1), Vector3f((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5))); + auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); + engineConfig->SetNumThreads(4); + engineConfig->SetPreferFramebufferFormatSRGB(false); + + std::srand(1); // Fix seed for random numbers + scene.Init(); + cam.Init(70, 16, 9, 0.1f, 100); + scene.SetCamera(&cam); + cam.SetMatrix(Math::Utils::translate(Matrix4f(1), Vector3f_SIMD(0, 0, -10))); + shader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/basic"); + shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basic"); + shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription()); + drawablesPool.resize(GEOS); + for (uint32_t i = 0; i < GEOS; i++) + { + Geometry* geo = new Geometry(); + geo->InitCube(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); + } + nodesPool.resize(OBJECTS); + for (uint32_t i = 0; i < OBJECTS; i++) + { + nodesPool[i].Init(); + scene.GetRoot()->AddChild(&nodesPool[i]); + if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always); + nodesPool[i].AddDrawable(&drawablesPool[std::rand() % GEOS]); + nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1), Vector3f((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5))); + } + + GetGraphicsAppManager()->GetRenderer()->SetScene(&scene); + + camController.Init(&cam); + camController.SetDefaultKeybindings(); } - GetGraphicsAppManager()->GetRenderer()->SetScene(&scene); + void Tick() override + { + for (uint32_t i = 0; i < DYNAMIC; i++) + { + nodesPool[i].SetMatrix(glm::translate(glm::mat4x4(1), glm::vec3((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5))); + } - camController.Init(&cam); - camController.SetDefaultKeybindings(); + camController.Tick(); + } + + void Close() override + {} + }; + + IGraphicsApp* CubesExampleApp::Create() + { + return new CubesExampleAppImpl(); } - void Tick() override + std::unique_ptr CubesExampleApp::CreateUnique() { - for(uint32_t i = 0; i < DYNAMIC; i++) - { - nodesPool[i].SetMatrix(glm::translate(glm::mat4x4(1), glm::vec3((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5))); - } - - camController.Tick(); + return std::make_unique(); } - void Close() override{} -}; - -OpenVulkano::IGraphicsApp* CubesExampleApp::Create() -{ - return new CubesExampleAppImpl(); -} - -std::unique_ptr CubesExampleApp::CreateUnique() -{ - return std::make_unique(); } #pragma clang diagnostic pop diff --git a/openVulkanoCpp/ExampleApps/CubesExampleApp.hpp b/openVulkanoCpp/ExampleApps/CubesExampleApp.hpp index 0b502d9..eee5c10 100644 --- a/openVulkanoCpp/ExampleApps/CubesExampleApp.hpp +++ b/openVulkanoCpp/ExampleApps/CubesExampleApp.hpp @@ -9,10 +9,13 @@ #include "Base/IGraphicsApp.hpp" #include -class CubesExampleApp : public OpenVulkano::IGraphicsApp +namespace OpenVulkano { -public: - static OpenVulkano::IGraphicsApp* Create(); + class CubesExampleApp : public IGraphicsApp + { + public: + static IGraphicsApp* Create(); - static std::unique_ptr CreateUnique(); -}; + static std::unique_ptr CreateUnique(); + }; +} \ No newline at end of file