Refactor ExampleApps

This commit is contained in:
2023-10-04 19:59:59 +02:00
parent e0f24153d3
commit 82c3b77666
4 changed files with 90 additions and 70 deletions

View File

@@ -10,7 +10,7 @@
#include <algorithm>
#undef max
namespace openVulkano
namespace OpenVulkano
{
class EngineConfiguration
{

View File

@@ -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 <string>
#include <spdlog/fmt/fmt.h> //TODO replace with external fmt
namespace openVulkano
namespace OpenVulkano
{
inline const char* ENGINE_NAME = "OpenVulkano";

View File

@@ -21,15 +21,18 @@
#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;
namespace OpenVulkano
{
using namespace Scene;
using namespace Input;
using namespace Math;
class CubesExampleAppImpl final : public CubesExampleApp
{
Scene scene;
OpenVulkano::Scene::Scene scene;
PerspectiveCamera cam;
OpenVulkano::FreeCamCameraController camController;
Material mat;
@@ -39,8 +42,11 @@ class CubesExampleAppImpl final : public CubesExampleApp
Vector3f_SIMD position = {0, 0, -10};
public:
std::string GetAppName() override { return "ExampleApp"; }
OpenVulkano::Version GetAppVersion() override { return {"v1.0"}; }
std::string GetAppName() override
{ return "ExampleApp"; }
OpenVulkano::Version GetAppVersion() override
{ return {"v1.0"}; }
void Init() override
{
@@ -52,7 +58,7 @@ public:
scene.Init();
cam.Init(70, 16, 9, 0.1f, 100);
scene.SetCamera(&cam);
cam.SetMatrix(Utils::translate(Matrix4f(1), Vector3f_SIMD(0,0,-10)));
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());
@@ -60,7 +66,8 @@ public:
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));
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);
@@ -70,7 +77,7 @@ public:
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)));
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);
@@ -89,18 +96,21 @@ public:
camController.Tick();
}
void Close() override{}
void Close() override
{}
};
OpenVulkano::IGraphicsApp* CubesExampleApp::Create()
IGraphicsApp* CubesExampleApp::Create()
{
return new CubesExampleAppImpl();
}
std::unique_ptr<OpenVulkano::IGraphicsApp> CubesExampleApp::CreateUnique()
std::unique_ptr<IGraphicsApp> CubesExampleApp::CreateUnique()
{
return std::make_unique<CubesExampleAppImpl>();
}
}
#pragma clang diagnostic pop
#pragma clang diagnostic pop

View File

@@ -9,10 +9,13 @@
#include "Base/IGraphicsApp.hpp"
#include <memory>
class CubesExampleApp : public OpenVulkano::IGraphicsApp
namespace OpenVulkano
{
class CubesExampleApp : public IGraphicsApp
{
public:
static OpenVulkano::IGraphicsApp* Create();
static IGraphicsApp* Create();
static std::unique_ptr<OpenVulkano::IGraphicsApp> CreateUnique();
static std::unique_ptr<IGraphicsApp> CreateUnique();
};
}