add app & scene & singleton
This commit is contained in:
parent
df8e818ac5
commit
5a22344a67
1
engine/3rdparty/zlib/include/zstd/pool.h
vendored
1
engine/3rdparty/zlib/include/zstd/pool.h
vendored
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
namespace zstd {
|
namespace zstd {
|
||||||
template<std::move_constructible T>
|
template<std::move_constructible T>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
namespace zstd {
|
namespace zstd {
|
||||||
template<size_t T>
|
template<size_t T>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <semaphore>
|
#include <semaphore>
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <semaphore>
|
#include <semaphore>
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
|||||||
4
engine/3rdparty/zlog/test/01file.cpp
vendored
4
engine/3rdparty/zlog/test/01file.cpp
vendored
@ -1,8 +1,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
|
#include "singleton.h"
|
||||||
|
#include "assetmanager.h"
|
||||||
int main() {
|
int main() {
|
||||||
zlog::info("hello info");
|
zlog::info("hello info");
|
||||||
zlog::warn("hello {}", "warn");
|
zlog::warn("hello {}", "warn");
|
||||||
zlog::error("hello {}", "error");
|
zlog::error("hello {}", "error");
|
||||||
|
AssetManager re;
|
||||||
|
AssetManager::GetSingleton().GetSingleton();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
1
engine/3rdparty/zlog/test/assetmanager.cpp
vendored
Normal file
1
engine/3rdparty/zlog/test/assetmanager.cpp
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "assetmanager.h"
|
||||||
7
engine/3rdparty/zlog/test/assetmanager.h
vendored
Normal file
7
engine/3rdparty/zlog/test/assetmanager.h
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "singleton.h"
|
||||||
|
class AssetManager :public Singleton<AssetManager> {
|
||||||
|
|
||||||
|
};
|
||||||
|
template<>
|
||||||
|
AssetManager* Singleton<AssetManager>::ms_Singleton = nullptr;
|
||||||
20
engine/3rdparty/zlog/test/singleton.h
vendored
Normal file
20
engine/3rdparty/zlog/test/singleton.h
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Singleton {
|
||||||
|
protected:
|
||||||
|
static T* ms_Singleton;
|
||||||
|
public:
|
||||||
|
explicit Singleton() {
|
||||||
|
ms_Singleton = static_cast<T*>(this);
|
||||||
|
}
|
||||||
|
~Singleton() {
|
||||||
|
ms_Singleton = nullptr;
|
||||||
|
}
|
||||||
|
static T& GetSingleton(void) {
|
||||||
|
return *ms_Singleton;
|
||||||
|
}
|
||||||
|
static T* GetSingletonPtr(void) {
|
||||||
|
return ms_Singleton;
|
||||||
|
}
|
||||||
|
};
|
||||||
3
engine/3rdparty/zlog/xmake.lua
vendored
3
engine/3rdparty/zlog/xmake.lua
vendored
@ -10,4 +10,5 @@ target("zlog_test01_file")
|
|||||||
set_languages("cxx20")
|
set_languages("cxx20")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("zlog")
|
add_deps("zlog")
|
||||||
add_files("test/01file.cpp")
|
add_files("test/*.cpp")
|
||||||
|
add_headerfiles("test/*.h")
|
||||||
20
engine/src/3rdparty/template/singleton.h
vendored
Normal file
20
engine/src/3rdparty/template/singleton.h
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Singleton {
|
||||||
|
protected:
|
||||||
|
static T* ms_Singleton;
|
||||||
|
public:
|
||||||
|
explicit Singleton() {
|
||||||
|
ms_Singleton = static_cast<T*>(this);
|
||||||
|
}
|
||||||
|
~Singleton() {
|
||||||
|
ms_Singleton = nullptr;
|
||||||
|
}
|
||||||
|
static T& GetSingleton(void) {
|
||||||
|
return *ms_Singleton;
|
||||||
|
}
|
||||||
|
static T* GetSingletonPtr(void) {
|
||||||
|
return ms_Singleton;
|
||||||
|
}
|
||||||
|
};
|
||||||
51
engine/src/engine/app.cpp
Normal file
51
engine/src/engine/app.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "app.h"
|
||||||
|
#include "render/renderapi.h"
|
||||||
|
#include "render/window.h"
|
||||||
|
#include "object/mesh/actor.h"
|
||||||
|
#include "object/property/actor_property.h"
|
||||||
|
#include "asset/asset_manager.h"
|
||||||
|
#include "object/scene/scene_manager.h"
|
||||||
|
namespace engineapi {
|
||||||
|
App::App(const string& path)
|
||||||
|
{
|
||||||
|
const char* name = "zengine";
|
||||||
|
RenderAPI::MakeInstance();
|
||||||
|
Window::MakeInstance(3, 640, 720, name);
|
||||||
|
auto scene_manager = new SceneManager();
|
||||||
|
scene_manager->LoadScene(path);
|
||||||
|
new AssetManager();
|
||||||
|
{
|
||||||
|
ActorProperty property;
|
||||||
|
property.id = 1;
|
||||||
|
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||||
|
property.path = "assets/models/cube.obj";
|
||||||
|
auto actor = ActorMesh::New(property);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ActorProperty property;
|
||||||
|
property.id = 1;
|
||||||
|
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||||
|
property.path = "assets/models/box.ply";
|
||||||
|
auto actor = ActorMesh::New(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void App::Launch()
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
Update();
|
||||||
|
Render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void App::Update()
|
||||||
|
{
|
||||||
|
SceneManager::GetSingletonPtr()->GetCurScene()->Update();
|
||||||
|
}
|
||||||
|
void App::Render()
|
||||||
|
{
|
||||||
|
RenderAPI::GetSingletonPtr()->BeginFrame();
|
||||||
|
|
||||||
|
SceneManager::GetSingletonPtr()->GetCurScene()->Render();
|
||||||
|
|
||||||
|
RenderAPI::GetSingletonPtr()->EndFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
engine/src/engine/app.h
Normal file
16
engine/src/engine/app.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
using std::string;
|
||||||
|
namespace engineapi
|
||||||
|
{
|
||||||
|
class App {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
App(const string& path);
|
||||||
|
void Launch();
|
||||||
|
public:
|
||||||
|
void Update();
|
||||||
|
void Render();
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1,6 +1,4 @@
|
|||||||
#include "asset/asset_manager.h"
|
#include "asset/asset_manager.h"
|
||||||
|
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
AssetManager* AssetManager::Instance = nullptr;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,9 +4,10 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
|
#include "singleton.h"
|
||||||
namespace engineapi
|
namespace engineapi
|
||||||
{
|
{
|
||||||
class AssetManager
|
class AssetManager : public Singleton<AssetManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct AssetWrap {
|
struct AssetWrap {
|
||||||
@ -41,7 +42,9 @@ namespace engineapi
|
|||||||
asset->BeginLoad();
|
asset->BeginLoad();
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
static AssetManager* Instance;
|
AssetManager() = default;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
template<>
|
||||||
|
engineapi::AssetManager* Singleton<engineapi::AssetManager>::ms_Singleton = nullptr;
|
||||||
|
|||||||
10
engine/src/engine/object/component.cpp
Normal file
10
engine/src/engine/object/component.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "component.h"
|
||||||
|
|
||||||
|
namespace engineapi {
|
||||||
|
Component::Component()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Component::~Component()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
9
engine/src/engine/object/component.h
Normal file
9
engine/src/engine/object/component.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
namespace engineapi {
|
||||||
|
class Component {
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
Component();
|
||||||
|
~Component();
|
||||||
|
};
|
||||||
|
};
|
||||||
10
engine/src/engine/object/game_object.cpp
Normal file
10
engine/src/engine/object/game_object.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "game_object.h"
|
||||||
|
|
||||||
|
namespace engineapi {
|
||||||
|
GameObject::GameObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
GameObject::~GameObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
10
engine/src/engine/object/game_object.h
Normal file
10
engine/src/engine/object/game_object.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "component.h"
|
||||||
|
namespace engineapi {
|
||||||
|
class GameObject {
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
GameObject();
|
||||||
|
~GameObject();
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -10,7 +10,7 @@ namespace engineapi {
|
|||||||
}
|
}
|
||||||
ActorMesh* ActorMesh::New(ActorProperty& property)
|
ActorMesh* ActorMesh::New(ActorProperty& property)
|
||||||
{
|
{
|
||||||
Model* model = AssetManager::Instance->LoadAsset<Model>(property.path, property.flags);
|
Model* model = AssetManager::GetSingletonPtr()->LoadAsset<Model>(property.path, property.flags);
|
||||||
return new ActorMesh(*model, property);
|
return new ActorMesh(*model, property);
|
||||||
}
|
}
|
||||||
ActorMesh* ActorMesh::New(uint32_t id)
|
ActorMesh* ActorMesh::New(uint32_t id)
|
||||||
|
|||||||
18
engine/src/engine/object/scene/scene.cpp
Normal file
18
engine/src/engine/object/scene/scene.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "scene.h"
|
||||||
|
namespace engineapi {
|
||||||
|
Scene::Scene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Scene::~Scene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Scene::Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Scene::Render()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Scene::AddGameObject(GameObject* gameObject)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
14
engine/src/engine/object/scene/scene.h
Normal file
14
engine/src/engine/object/scene/scene.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../game_object.h"
|
||||||
|
namespace engineapi {
|
||||||
|
class Scene{
|
||||||
|
protected:
|
||||||
|
public:
|
||||||
|
Scene();
|
||||||
|
~Scene();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Render();
|
||||||
|
void AddGameObject(GameObject* gameObject);
|
||||||
|
};
|
||||||
|
}
|
||||||
75
engine/src/engine/object/scene/scene_manager.cpp
Normal file
75
engine/src/engine/object/scene/scene_manager.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "scene_manager.h"
|
||||||
|
#include "zlog.h"
|
||||||
|
namespace engineapi {
|
||||||
|
Scene* SceneManager::GetScene(const string& name)
|
||||||
|
{
|
||||||
|
auto sceneInfo = GetSceneInfo(name);
|
||||||
|
if (sceneInfo == nullptr)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return sceneInfo->scene;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::LoadScene(const string& path, bool switchNow)
|
||||||
|
{
|
||||||
|
curScene = new SceneInfo{
|
||||||
|
path,
|
||||||
|
new Scene()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::SwitchScene(const string& name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::DeleteScene(const string& name)
|
||||||
|
{
|
||||||
|
map<string, SceneInfo*>::iterator iter = scenes.find(name);
|
||||||
|
if (iter != scenes.end())
|
||||||
|
{
|
||||||
|
delete iter->second->scene;
|
||||||
|
delete iter->second;
|
||||||
|
scenes.erase(iter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zlog::info("Attempt to delete a nonexistent scene: {}", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::DeleteAllScene()
|
||||||
|
{
|
||||||
|
for (auto& iter : scenes)
|
||||||
|
{
|
||||||
|
delete iter.second->scene;
|
||||||
|
delete iter.second;
|
||||||
|
}
|
||||||
|
scenes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::ReloadScene()
|
||||||
|
{
|
||||||
|
// 先等待当前所有绘制结束,再卸载场景释放资源
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene* SceneManager::GetCurScene()
|
||||||
|
{
|
||||||
|
return curScene->scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneInfo* SceneManager::GetSceneInfo(const string& name)
|
||||||
|
{
|
||||||
|
map<string, SceneInfo*>::iterator iter = scenes.find(name);
|
||||||
|
if (iter != scenes.end())
|
||||||
|
return iter->second;
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
27
engine/src/engine/object/scene/scene_manager.h
Normal file
27
engine/src/engine/object/scene/scene_manager.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "asset/asset.h"
|
||||||
|
#include "scene.h"
|
||||||
|
#include "singleton.h"
|
||||||
|
namespace engineapi {
|
||||||
|
struct SceneInfo
|
||||||
|
{
|
||||||
|
string path;
|
||||||
|
Scene* scene = nullptr;
|
||||||
|
};
|
||||||
|
class SceneManager :public Singleton<SceneManager> {
|
||||||
|
protected:
|
||||||
|
SceneInfo* curScene = nullptr;
|
||||||
|
map<string, SceneInfo*> scenes;
|
||||||
|
public:
|
||||||
|
Scene* GetScene(const string& name);
|
||||||
|
void LoadScene(const string& path, bool switchNow = true);
|
||||||
|
void SwitchScene(const string& name);
|
||||||
|
void DeleteScene(const string& name);
|
||||||
|
void DeleteAllScene();
|
||||||
|
void ReloadScene();
|
||||||
|
Scene* GetCurScene();
|
||||||
|
SceneInfo* GetSceneInfo(const string& name);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
engineapi::SceneManager* Singleton<engineapi::SceneManager>::ms_Singleton = nullptr;
|
||||||
@ -11,6 +11,6 @@ namespace engineapi {
|
|||||||
void Mesh::BeginLoad()
|
void Mesh::BeginLoad()
|
||||||
{
|
{
|
||||||
Asset::BeginLoad();
|
Asset::BeginLoad();
|
||||||
RenderAPI::GetInstance()->SetStaticMesh(this);
|
RenderAPI::GetSingletonPtr()->SetStaticMesh(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
#include "renderapi.h"
|
#include "renderapi.h"
|
||||||
#define VULKAN_API
|
|
||||||
#ifdef VULKAN_API
|
#ifdef VULKAN_API
|
||||||
#include "vulkanapi/vulkanapi.h"
|
#include "vulkanapi/vulkanapi.h"
|
||||||
#endif // VULKAN_API
|
#endif // VULKAN_API
|
||||||
|
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
RenderAPI* RenderAPI::Instance = nullptr;
|
|
||||||
|
|
||||||
void RenderAPI::MakeInstance()
|
void RenderAPI::MakeInstance()
|
||||||
{
|
{
|
||||||
#ifdef VULKAN_API
|
#ifdef VULKAN_API
|
||||||
Instance = new RenderVulkanAPI();
|
new RenderVulkanAPI();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,19 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "asset/asset_render.h"
|
#include "asset/asset_render.h"
|
||||||
|
#include "singleton.h"
|
||||||
namespace engineapi
|
namespace engineapi
|
||||||
{
|
{
|
||||||
class Mesh;
|
class Mesh;
|
||||||
class RenderAPI
|
class RenderAPI : public Singleton<RenderAPI>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void BeginFrame() = 0;
|
virtual void BeginFrame() = 0;
|
||||||
virtual void EndFrame() = 0;
|
virtual void EndFrame() = 0;
|
||||||
virtual void SetStaticMesh(Mesh* mesh) = 0;
|
virtual void SetStaticMesh(Mesh* mesh) = 0;
|
||||||
public:
|
public:
|
||||||
static RenderAPI* Instance;
|
|
||||||
static void MakeInstance();
|
static void MakeInstance();
|
||||||
static RenderAPI* GetInstance() {
|
|
||||||
return Instance;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
template<>
|
||||||
|
engineapi::RenderAPI* Singleton<engineapi::RenderAPI>::ms_Singleton = nullptr;
|
||||||
@ -1,7 +1,15 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#ifdef VULKAN_API
|
||||||
|
#include "vulkanapi/window.h"
|
||||||
|
#endif // VULKAN_API
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
Window::WindowClass Window::WindowClass::wndClass;
|
Window::WindowClass Window::WindowClass::wndClass;
|
||||||
Window* Window::Instance = nullptr;
|
void Window::MakeInstance(int frames, uint32_t width, uint32_t height, const char* title)
|
||||||
|
{
|
||||||
|
#ifdef VULKAN_API
|
||||||
|
new vulkanapi::Window(frames, width, height, title);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
Window::WindowClass::WindowClass() noexcept
|
Window::WindowClass::WindowClass() noexcept
|
||||||
:
|
:
|
||||||
hInst(GetModuleHandle(nullptr))
|
hInst(GetModuleHandle(nullptr))
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include "singleton.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
class Window {
|
class Window : public Singleton<Window> {
|
||||||
protected:
|
protected:
|
||||||
int mWidth;
|
int mWidth;
|
||||||
int mHeight;
|
int mHeight;
|
||||||
@ -33,9 +35,8 @@ namespace engineapi {
|
|||||||
return mPtr;
|
return mPtr;
|
||||||
}
|
}
|
||||||
static bool ProcessMessages(int& code);
|
static bool ProcessMessages(int& code);
|
||||||
static Window* Instance;
|
static void MakeInstance(int frames, uint32_t width, uint32_t height, const char* title);
|
||||||
static Window* GetInstance() {
|
|
||||||
return Instance;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
template<>
|
||||||
|
engineapi::Window* Singleton<engineapi::Window>::ms_Singleton = nullptr;
|
||||||
@ -18,10 +18,10 @@ namespace vulkanapi {
|
|||||||
deviceCreator.AddQueue(Queue::PresentQueue, VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT, 1.0);
|
deviceCreator.AddQueue(Queue::PresentQueue, VkQueueFlagBits::VK_QUEUE_GRAPHICS_BIT, 1.0);
|
||||||
mDevice = new Device(deviceCreator);
|
mDevice = new Device(deviceCreator);
|
||||||
|
|
||||||
InitWorker(Queue::TransferQueue, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT);
|
InitWorker(Queue::TransferQueue, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
|
||||||
InitWorker(Queue::RenderQueue, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT);
|
InitWorker(Queue::RenderQueue, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
|
||||||
InitWorker(Queue::ComputeQueue, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT);
|
InitWorker(Queue::ComputeQueue, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
|
||||||
InitWorker(Queue::PresentQueue, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT);
|
InitWorker(Queue::PresentQueue, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
|
||||||
|
|
||||||
Backend::TransferWorker = GetWorker(Queue::TransferQueue);
|
Backend::TransferWorker = GetWorker(Queue::TransferQueue);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ namespace vulkanapi {
|
|||||||
|
|
||||||
void CommandWorker::Buffer(CommandBuffer& cmd, commandFn fn, voidFn callback)
|
void CommandWorker::Buffer(CommandBuffer& cmd, commandFn fn, voidFn callback)
|
||||||
{
|
{
|
||||||
|
cmd.Reset();
|
||||||
cmd.BeginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
cmd.BeginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||||
fn(cmd);
|
fn(cmd);
|
||||||
cmd.EndRecord();
|
cmd.EndRecord();
|
||||||
|
|||||||
@ -19,8 +19,8 @@ namespace engineapi
|
|||||||
public:
|
public:
|
||||||
VulkanVAO* GetNextVAO(uint32_t& VAO_index);
|
VulkanVAO* GetNextVAO(uint32_t& VAO_index);
|
||||||
public:
|
public:
|
||||||
static RenderVulkanAPI* GetInstance() {
|
static RenderVulkanAPI* GetSingletonPtr() {
|
||||||
return (RenderVulkanAPI*)RenderAPI::GetInstance();
|
return (RenderVulkanAPI*)RenderAPI::GetSingletonPtr();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -13,7 +13,7 @@ namespace vulkanapi {
|
|||||||
, mSurfaceKHR(nullptr)
|
, mSurfaceKHR(nullptr)
|
||||||
, mSwapchain(nullptr)
|
, mSwapchain(nullptr)
|
||||||
{
|
{
|
||||||
RenderVulkanAPI* api = RenderVulkanAPI::GetInstance();
|
RenderVulkanAPI* api = RenderVulkanAPI::GetSingletonPtr();
|
||||||
if (!api) {
|
if (!api) {
|
||||||
zlog::error("init RenderAPI error,Window is rely on RenderAPI!");
|
zlog::error("init RenderAPI error,Window is rely on RenderAPI!");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ namespace vulkanapi {
|
|||||||
void CommandBuffer::Reset()
|
void CommandBuffer::Reset()
|
||||||
{
|
{
|
||||||
vkResetCommandBuffer(mPtr, VkCommandBufferResetFlagBits::VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
vkResetCommandBuffer(mPtr, VkCommandBufferResetFlagBits::VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||||
|
mPool.ResetFence(mFence);
|
||||||
}
|
}
|
||||||
void CommandBuffer::BeginRecord(VkCommandBufferUsageFlags flag)
|
void CommandBuffer::BeginRecord(VkCommandBufferUsageFlags flag)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -42,6 +42,10 @@ namespace vulkanapi {
|
|||||||
vkDestroyFence(mDevice.Ptr(), fence, NULL);
|
vkDestroyFence(mDevice.Ptr(), fence, NULL);
|
||||||
fence = nullptr;
|
fence = nullptr;
|
||||||
}
|
}
|
||||||
|
void CommandPool::ResetFence(VkFence& fence)
|
||||||
|
{
|
||||||
|
vkResetFences(mDevice.Ptr(), 1, &fence);
|
||||||
|
}
|
||||||
VkFence CommandPool::AllocateFence()
|
VkFence CommandPool::AllocateFence()
|
||||||
{
|
{
|
||||||
VkFence fence;
|
VkFence fence;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ namespace vulkanapi {
|
|||||||
VkCommandBuffer AllocateBuffer(VkCommandBufferLevel level);
|
VkCommandBuffer AllocateBuffer(VkCommandBufferLevel level);
|
||||||
void FreeBuffer(VkCommandBuffer& buf);
|
void FreeBuffer(VkCommandBuffer& buf);
|
||||||
void FreeFence(VkFence& fence);
|
void FreeFence(VkFence& fence);
|
||||||
|
void ResetFence(VkFence& fence);
|
||||||
VkFence AllocateFence();
|
VkFence AllocateFence();
|
||||||
VkCommandPool& Ptr() {
|
VkCommandPool& Ptr() {
|
||||||
return mPtr;
|
return mPtr;
|
||||||
|
|||||||
@ -1,28 +1,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "vulkanapi/window.h"
|
#include "app.h"
|
||||||
#include "object/mesh/actor.h"
|
|
||||||
#include "object/property/actor_property.h"
|
|
||||||
#include "asset/asset_manager.h"
|
|
||||||
#include "render/renderapi.h"
|
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
using namespace engineapi;
|
using namespace engineapi;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
const char* name = "zengine";
|
const char* name = "zengine";
|
||||||
zlog::info("hello {}", name);
|
App game(name);
|
||||||
RenderAPI::MakeInstance();
|
game.Launch();
|
||||||
auto wnd = vulkanapi::Window(3, 640, 720, name);
|
|
||||||
ActorProperty property;
|
|
||||||
property.id = 1;
|
|
||||||
property.flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
|
||||||
property.path = "assets/models/cube.obj";
|
|
||||||
AssetManager instance;
|
|
||||||
AssetManager::Instance = &instance;
|
|
||||||
auto actor = ActorMesh::New(property);
|
|
||||||
while (true) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
||||||
}
|
|
||||||
delete actor;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,10 @@ target("zengine")
|
|||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_rules("volk.env")
|
add_rules("volk.env")
|
||||||
add_deps("zlib","zlog")
|
add_deps("zlib","zlog")
|
||||||
|
add_defines("VULKAN_API")
|
||||||
add_packages("vulkansdk","tinyobjloader","assimp")
|
add_packages("vulkansdk","tinyobjloader","assimp")
|
||||||
add_includedirs("src/engine")
|
add_includedirs("src/engine")
|
||||||
add_includedirs("src/3rdparty/volk", "src/3rdparty/vulkan-memory-allocator")
|
add_includedirs("src/3rdparty/volk", "src/3rdparty/vulkan-memory-allocator", "src/3rdparty/template")
|
||||||
add_syslinks("user32")
|
add_syslinks("user32")
|
||||||
add_files("src/*.cpp", "src/**.cpp")
|
add_files("src/*.cpp", "src/**.cpp")
|
||||||
add_files("src/3rdparty/**.c")
|
add_files("src/3rdparty/**.c")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user