Compare commits
30 Commits
ba69726e33
...
main
Author | SHA1 | Date | |
---|---|---|---|
391fd5a8a8
|
|||
7349c0eb16 | |||
19b630104c | |||
7ec13a7020 | |||
4a84df7c3e | |||
a297c7cb3a | |||
8ef886df83 | |||
817d0bdca9 | |||
c640ac574b | |||
0b2148ad55 | |||
95f77209cf | |||
f7e087ee8d | |||
e52db0fafd | |||
5bdc0034d1 | |||
ceb485018f | |||
daf26c304b | |||
550c1b6e5b | |||
c82398205a | |||
43fc721413 | |||
52747202d3 | |||
fef75ec64b | |||
3c38e2a988 | |||
e9852fe0e7 | |||
8e202f9d59 | |||
d8627d0357 | |||
ec8045c4f4 | |||
042dc3a457 | |||
28927d9a4e | |||
89f5b1497f | |||
7448017701 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,3 +1,4 @@
|
|||||||
*.png filter=lfs diff=lfs merge=lfs -text
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
*.webp filter=lfs diff=lfs merge=lfs -text
|
*.webp filter=lfs diff=lfs merge=lfs -text
|
||||||
*.xcf filter=lfs diff=lfs merge=lfs -text
|
*.xcf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,3 +22,6 @@ libs/physx/physx/compiler/
|
|||||||
libs/physx/physx/buildtools/
|
libs/physx/physx/buildtools/
|
||||||
libs/physx/physx/bin/
|
libs/physx/physx/bin/
|
||||||
libs/nativefiledialog/build/
|
libs/nativefiledialog/build/
|
||||||
|
.docker
|
||||||
|
|
||||||
|
**/bin/
|
||||||
|
8
.gitmodules
vendored
8
.gitmodules
vendored
@ -14,6 +14,7 @@
|
|||||||
[submodule "ImGui"]
|
[submodule "ImGui"]
|
||||||
path = libs/ImGui
|
path = libs/ImGui
|
||||||
url = https://github.com/ocornut/imgui.git
|
url = https://github.com/ocornut/imgui.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "assimp"]
|
[submodule "assimp"]
|
||||||
path = libs/assimp
|
path = libs/assimp
|
||||||
url = https://github.com/assimp/assimp.git
|
url = https://github.com/assimp/assimp.git
|
||||||
@ -24,21 +25,28 @@
|
|||||||
[submodule "libs/physx"]
|
[submodule "libs/physx"]
|
||||||
path = libs/physx
|
path = libs/physx
|
||||||
url = https://git.barink.dev/Nigel/PhysX.git
|
url = https://git.barink.dev/Nigel/PhysX.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/entt"]
|
[submodule "libs/entt"]
|
||||||
path = libs/entt
|
path = libs/entt
|
||||||
url = https://github.com/skypjack/entt.git
|
url = https://github.com/skypjack/entt.git
|
||||||
[submodule "libs/guizmo"]
|
[submodule "libs/guizmo"]
|
||||||
path = libs/guizmo
|
path = libs/guizmo
|
||||||
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/yaml-cpp"]
|
[submodule "libs/yaml-cpp"]
|
||||||
path = libs/yaml-cpp
|
path = libs/yaml-cpp
|
||||||
url = https://git.barink.dev/Nigel/yaml-cpp.git
|
url = https://git.barink.dev/Nigel/yaml-cpp.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/nativefiledialog"]
|
[submodule "libs/nativefiledialog"]
|
||||||
path = libs/nativefiledialog
|
path = libs/nativefiledialog
|
||||||
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
||||||
|
ignore = dirty
|
||||||
[submodule "libs/mINI"]
|
[submodule "libs/mINI"]
|
||||||
path = libs/mINI
|
path = libs/mINI
|
||||||
url = https://github.com/pulzed/mINI.git
|
url = https://github.com/pulzed/mINI.git
|
||||||
[submodule "libs/imgui-filebrowser"]
|
[submodule "libs/imgui-filebrowser"]
|
||||||
path = libs/imgui-filebrowser
|
path = libs/imgui-filebrowser
|
||||||
url = https://github.com/AirGuanZ/imgui-filebrowser.git
|
url = https://github.com/AirGuanZ/imgui-filebrowser.git
|
||||||
|
[submodule "libs/googletest"]
|
||||||
|
path = libs/googletest
|
||||||
|
url = https://github.com/google/googletest.git
|
||||||
|
21
CmakeLists.txt
Normal file
21
CmakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
CMAKE_MINIMUM_REQUIRED (VERSION 4.0)
|
||||||
|
project(Yoggie)
|
||||||
|
set(EXPORT_COMPILE_COMMANDS_JSON ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4099")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wclass-struct-conversion")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_compile_definitions(GLFW_STATIC)
|
||||||
|
|
||||||
|
add_subdirectory(Editor)
|
||||||
|
add_subdirectory(SandboxApp)
|
||||||
|
include(libraries.cmake)
|
||||||
|
add_subdirectory(YoggieEngine)
|
||||||
|
|
||||||
|
|
1
Editor/.gitignore
vendored
Normal file
1
Editor/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
**.dll
|
17
Editor/CMakeLists.txt
Normal file
17
Editor/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||||
|
file(GLOB HEADER_FILES "src/*.h")
|
||||||
|
add_executable(Editor ${SOURCE_FILES} "../libs/glad/src/glad.c" ${HEADER_FILES})
|
||||||
|
|
||||||
|
target_include_directories(Editor PRIVATE
|
||||||
|
"../YoggieEngine/src"
|
||||||
|
"../libs/guizmo"
|
||||||
|
)
|
||||||
|
target_link_directories(Editor PRIVATE
|
||||||
|
"../libs/ImGui/build/Release"
|
||||||
|
"../libs/guizmo/build/Release" )
|
||||||
|
target_link_libraries(Editor
|
||||||
|
thirdparty_tools
|
||||||
|
YoggieEngine
|
||||||
|
ImGui
|
||||||
|
ImGuizmo
|
||||||
|
)
|
@ -1,47 +0,0 @@
|
|||||||
project "Editor"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building editor ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine",
|
|
||||||
"ImGuizmo",
|
|
||||||
"yaml-cpp",
|
|
||||||
"nfd.lib"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
|
|
||||||
"../YoggieEngine/build/Debug",
|
|
||||||
|
|
||||||
-- I'd prefer if didn't need these..
|
|
||||||
-- We'll figure that out some time later
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
"../libs/physx/pxshared/include",
|
|
||||||
incfolder["lua"],
|
|
||||||
incfolder["spdlog"],
|
|
||||||
incfolder["glm"],
|
|
||||||
incfolder["assimp"],
|
|
||||||
incfolder["glad"],
|
|
||||||
incfolder["glfw"],
|
|
||||||
|
|
||||||
incfolder["imgui"],
|
|
||||||
incfolder["imguizmo"],
|
|
||||||
incfolder["entt"],
|
|
||||||
incfolder["yamlcpp"],
|
|
||||||
incfolder["nativefiledialog"],
|
|
||||||
incfolder["mINI"]
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
staticlib["yoggie"],
|
|
||||||
staticlib["nativefiledialog"]
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"../libs/glad/src/glad.c",
|
|
||||||
"./src/**.h",
|
|
||||||
"./src/**.cpp"
|
|
||||||
}
|
|
BIN
Editor/rsc/Yoggie.png
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/Yoggie.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
BIN
Editor/rsc/Yoggie2.jpeg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -1,46 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
enum class ASSET_TYPE {
|
|
||||||
Unknown = -1,
|
|
||||||
Mesh,
|
|
||||||
Texture,
|
|
||||||
Material
|
|
||||||
};
|
|
||||||
|
|
||||||
class Asset {
|
|
||||||
public:
|
|
||||||
Asset(const char* name): name(name) {}
|
|
||||||
virtual ASSET_TYPE GetType() { return ASSET_TYPE::Unknown; }
|
|
||||||
const char* GetName() const { return name.c_str(); }
|
|
||||||
bool isFolder = false ;
|
|
||||||
protected:
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class MeshAsset : Asset {
|
|
||||||
public:
|
|
||||||
MeshAsset(YoggieEngine::Mesh mesh) : Asset("New MeshAsset"), mesh(mesh) {}
|
|
||||||
ASSET_TYPE GetType() override { return ASSET_TYPE::Mesh; }
|
|
||||||
private:
|
|
||||||
YoggieEngine::Mesh& mesh;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TextureAsset : Asset {
|
|
||||||
public:
|
|
||||||
TextureAsset (YoggieEngine::Texture texture): Asset("New TextureAsset"), texture(texture) {}
|
|
||||||
ASSET_TYPE GetType() override { return ASSET_TYPE::Texture; }
|
|
||||||
private:
|
|
||||||
YoggieEngine::Texture& texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MaterialAsset : Asset {
|
|
||||||
public:
|
|
||||||
MaterialAsset () : Asset("New MaterialAsset"){}
|
|
||||||
ASSET_TYPE GetType() override { return ASSET_TYPE::Material; }
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
@ -1,68 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "EditorWindow.h"
|
|
||||||
#include "AssetManagement/AssetManager.h"
|
|
||||||
|
|
||||||
class AssetFinder : EditorWindow {
|
|
||||||
public:
|
|
||||||
AssetFinder() : EditorWindow("Assets") {}
|
|
||||||
|
|
||||||
void Draw() override {
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::BeginTable("##resources", 3))
|
|
||||||
{
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
|
||||||
|
|
||||||
YoggieEngine::Texture folderIcon = YoggieEngine::Texture("rsc/folderIcon.png");
|
|
||||||
YoggieEngine::Texture assetIcon = YoggieEngine::Texture("rsc/assetIcon.png");
|
|
||||||
|
|
||||||
|
|
||||||
int row = 0;
|
|
||||||
int column = 0;
|
|
||||||
for (auto& asset : AssetManager::assets) {
|
|
||||||
if (column % 3 == 0) {
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
column = 0;
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(column);
|
|
||||||
|
|
||||||
if (asset.isFolder) {
|
|
||||||
ImGui::ImageButton(
|
|
||||||
(ImTextureID)folderIcon.GetID(),
|
|
||||||
ImVec2{ (float)iconSize,(float)iconSize });
|
|
||||||
ImGui::Text(asset.GetName(), row);
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ImGui::ImageButton(
|
|
||||||
(ImTextureID)assetIcon.GetID(),
|
|
||||||
ImVec2{ (float)iconSize, (float)iconSize });
|
|
||||||
ImGui::Text(asset.GetName(), row);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
column++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::PopStyleColor(3);
|
|
||||||
ImGui::EndTable();
|
|
||||||
const GLuint textures[2]{ assetIcon.GetID(), folderIcon.GetID() };
|
|
||||||
glDeleteTextures(2, textures);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int iconSize = 60;
|
|
||||||
};
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
|||||||
#include "AssetManager.h"
|
|
||||||
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
std::vector<Asset> AssetManager::assets;
|
|
||||||
std::filesystem::path AssetManager::currentPath;
|
|
||||||
|
|
||||||
void AssetManager::Init()
|
|
||||||
{
|
|
||||||
assets = std::vector<Asset>();
|
|
||||||
currentPath = std::filesystem::path(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssetManager::BuildAssetView()
|
|
||||||
{
|
|
||||||
if (currentPath.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& dir_entry : std::filesystem::directory_iterator(currentPath))
|
|
||||||
{
|
|
||||||
auto asset = Asset(dir_entry.path().filename().string().c_str());
|
|
||||||
|
|
||||||
if (dir_entry.is_directory()) {
|
|
||||||
asset.isFolder = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
assets.push_back(asset);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssetManager::setAssetPath(std::filesystem::path path)
|
|
||||||
{
|
|
||||||
currentPath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
YoggieEngine::Mesh* AssetManager::LoadFromAssetFile(const std::filesystem::path assetPath)
|
|
||||||
{
|
|
||||||
YoggieEngine::Mesh* imported = nullptr;
|
|
||||||
|
|
||||||
std::ifstream AssetFile;
|
|
||||||
AssetFile.open(assetPath, std::ios::binary);
|
|
||||||
if (AssetFile.is_open()) {
|
|
||||||
|
|
||||||
char* Header = (char*)malloc(8);
|
|
||||||
unsigned long long Vsize = 0;
|
|
||||||
uint32_t Vnum = 0;
|
|
||||||
uint32_t Enum = 0;
|
|
||||||
|
|
||||||
// Read header
|
|
||||||
AssetFile.read(Header, 8);
|
|
||||||
AssetFile.read((char*)&Vsize, sizeof(unsigned long long));
|
|
||||||
AssetFile.read((char*)&Vnum, sizeof(uint32_t));
|
|
||||||
AssetFile.read((char*)&Enum, sizeof(uint32_t));
|
|
||||||
|
|
||||||
// print Header info
|
|
||||||
std::cout << "File has header: " << Header << std::endl;
|
|
||||||
std::cout << "Vertex size: " << Vsize << std::endl;
|
|
||||||
std::cout << "Number of Vertices: " << Vnum << std::endl;
|
|
||||||
std::cout << "Number of Elements: " << Enum << std::endl;
|
|
||||||
free(Header);
|
|
||||||
|
|
||||||
|
|
||||||
imported = new YoggieEngine::Mesh();
|
|
||||||
// Load Vertices (Vertex + UV )
|
|
||||||
imported->vertices = std::vector < YoggieEngine::Vertex>();
|
|
||||||
for (int i = 0; i < Vnum; i++)
|
|
||||||
{
|
|
||||||
YoggieEngine::Vertex data = YoggieEngine::Vertex();
|
|
||||||
AssetFile.read((char*)&data, Vsize);
|
|
||||||
|
|
||||||
imported->vertices.push_back(data);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip x bytes
|
|
||||||
AssetFile.ignore(sizeof(char) * 3);
|
|
||||||
|
|
||||||
// Load Elements
|
|
||||||
imported->elements = std::vector<unsigned int>();
|
|
||||||
for (int i = 0; i < Enum; i++) {
|
|
||||||
unsigned int data = 0;
|
|
||||||
AssetFile.read((char*)&data, sizeof(unsigned int));
|
|
||||||
imported->elements.push_back(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "Failed ot open mesh " << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return imported;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
YoggieEngine::Renderable* AssetManager::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder)
|
|
||||||
{
|
|
||||||
|
|
||||||
auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string());
|
|
||||||
YoggieEngine::Mesh* exportMesh = model->renderable->mesh;
|
|
||||||
std::filesystem::path MeshFileName = assetFolder / srcPath.filename().replace_extension(".mesh");
|
|
||||||
std::cout << "Save path: " << MeshFileName << std::endl;
|
|
||||||
|
|
||||||
std::ofstream meshAsset;
|
|
||||||
meshAsset.open(MeshFileName, std::ios::binary);
|
|
||||||
if (meshAsset.is_open()) {
|
|
||||||
|
|
||||||
// write a header
|
|
||||||
static const char* HEADER = "MESH";
|
|
||||||
meshAsset.write(HEADER, sizeof(HEADER));
|
|
||||||
auto Vsize = sizeof(YoggieEngine::Vertex);
|
|
||||||
std::cout << "size of vertex: " << Vsize << std::endl;
|
|
||||||
std::cout << "Addr of vSize: " << &Vsize << std::endl;
|
|
||||||
auto Vnum = exportMesh->vertices.size();
|
|
||||||
auto Enum = exportMesh->elements.size();
|
|
||||||
|
|
||||||
meshAsset.write((char*)&Vsize, sizeof(unsigned long long));
|
|
||||||
meshAsset.write((char*)&Vnum, sizeof(uint32_t));
|
|
||||||
meshAsset.write((char*)&Enum, sizeof(uint32_t));
|
|
||||||
// write all vertices
|
|
||||||
for (auto& vertice : exportMesh->vertices)
|
|
||||||
{
|
|
||||||
meshAsset.write((char*)&vertice, sizeof(vertice));
|
|
||||||
}
|
|
||||||
|
|
||||||
// write 3 x 0 byte
|
|
||||||
meshAsset.write((const char*)"\0\0\0", sizeof(char) * 3);
|
|
||||||
|
|
||||||
// write all indices
|
|
||||||
for (auto index : exportMesh->elements) {
|
|
||||||
meshAsset.write((char*)&index, sizeof(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
meshAsset.close();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
spdlog::error("Failed to create/open mesh file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return model->renderable;
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include "Asset.h"
|
|
||||||
|
|
||||||
class AssetManager {
|
|
||||||
public:
|
|
||||||
|
|
||||||
static void Init();
|
|
||||||
static void BuildAssetView();
|
|
||||||
static void setAssetPath(std::filesystem::path path);
|
|
||||||
|
|
||||||
static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath);
|
|
||||||
static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder);
|
|
||||||
|
|
||||||
static std::vector<Asset> assets ;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static std::filesystem::path currentPath;
|
|
||||||
|
|
||||||
};
|
|
@ -31,9 +31,9 @@ public:
|
|||||||
location = std::string(path);
|
location = std::string(path);
|
||||||
break;
|
break;
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
std::cout << "NFD_CANCEL" << std::endl;
|
spdlog::info("NFD_CANCEL" );
|
||||||
case (NFD_ERROR):
|
case (NFD_ERROR):
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
spdlog::error("NFD_Error: {0}" , NFD_GetError() );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
19
Editor/src/EditorCamera.h
Normal file
19
Editor/src/EditorCamera.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
|
|
||||||
|
class EditorCamera : public YoggieEngine::Camera {
|
||||||
|
public:
|
||||||
|
EditorCamera () : Camera(){
|
||||||
|
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||||
|
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||||
|
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
glm::vec3 Front;
|
||||||
|
glm::vec3 Right;
|
||||||
|
glm::vec3 Up;
|
||||||
|
};
|
517
Editor/src/EditorLayer.h
Normal file
517
Editor/src/EditorLayer.h
Normal file
@ -0,0 +1,517 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <mini/ini.h>
|
||||||
|
#include <nfd.h>
|
||||||
|
#include <ImGuizmo.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Inspector.h"
|
||||||
|
#include "Console.h"
|
||||||
|
#include "IconsMaterialDesign.h"
|
||||||
|
#include "Project.h"
|
||||||
|
#include "EditorCamera.h"
|
||||||
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
|
|
||||||
|
class EditorLayer : public Layer {
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
EditorLayer() : Layer()
|
||||||
|
{
|
||||||
|
|
||||||
|
Logo.Load("rsc/Yoggie.png");
|
||||||
|
Selected = YoggieEngine::Entity{ (entt::entity)-1, (scene.get()) };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnStartup() override {
|
||||||
|
std::string path = (std::filesystem::current_path()).string();
|
||||||
|
scene = std::make_unique<Scene>();
|
||||||
|
project = std::make_unique<Project>();
|
||||||
|
project.get()->setProjectDirectory(path);
|
||||||
|
LoadLastOrEmptyProject();
|
||||||
|
//Console console = Console();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate() override {
|
||||||
|
scene.get()->Update();
|
||||||
|
renderer.get()->Render(*scene, *camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void OnUI() override {
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { ImGui::GetWindowWidth(), 7 });
|
||||||
|
ImGui::BeginMainMenuBar();
|
||||||
|
int scaleFactor = 30;
|
||||||
|
ImGui::Image((ImTextureID)Logo.GetID(), { Logo.getSize().x / scaleFactor , Logo.getSize().y / scaleFactor });
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("App")) {
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Load Project"))
|
||||||
|
{
|
||||||
|
nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path);
|
||||||
|
switch (result) {
|
||||||
|
case(NFD_OKAY):
|
||||||
|
//Project::LoadProject(path, project);
|
||||||
|
//AssetRegistry::setAssetPath(project.GetProjectDirectory());
|
||||||
|
//AssetRegistry::BuildAssetView();
|
||||||
|
break;
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
spdlog::error("NFD_Error: {0}", NFD_GetError());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Save project as...")) {
|
||||||
|
nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path);
|
||||||
|
switch (result) {
|
||||||
|
case(NFD_OKAY):
|
||||||
|
spdlog::info("Save as: {0}", path);
|
||||||
|
//Project::SaveProject(path, project);
|
||||||
|
break;
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
spdlog::error("NFD_Error: {0}", NFD_GetError());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
if (ImGui::BeginMenu("Scene")) {
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Save scene"))
|
||||||
|
{
|
||||||
|
nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path);
|
||||||
|
switch (result) {
|
||||||
|
case(NFD_OKAY):
|
||||||
|
//SaveScene(path, scene);
|
||||||
|
|
||||||
|
//project.AddScene(scene);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Load scene"))
|
||||||
|
{
|
||||||
|
auto result = NFD_OpenDialog({ "yscene" }, NULL, &path);
|
||||||
|
switch (result) {
|
||||||
|
case (NFD_OKAY):
|
||||||
|
//LoadScene(path, scene);
|
||||||
|
break;
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Add Entity"))
|
||||||
|
{
|
||||||
|
//scene.AddEntity("New Entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Import Model"))
|
||||||
|
{
|
||||||
|
auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path);
|
||||||
|
switch (result) {
|
||||||
|
case(NFD_OKAY):
|
||||||
|
// Import Model
|
||||||
|
/*
|
||||||
|
AssetRegistry::LoadFromSource(
|
||||||
|
path,
|
||||||
|
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
break;
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Import MeshAsset (temp)"))
|
||||||
|
{
|
||||||
|
auto result = NFD_OpenDialog("mesh", NULL, &path);
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case(NFD_OKAY):
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case(NFD_CANCEL):
|
||||||
|
spdlog::debug("User cancelled action");
|
||||||
|
break;
|
||||||
|
case(NFD_ERROR):
|
||||||
|
spdlog::warn("Something went wrong!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine(ImGui::GetWindowWidth() / 4 * 3);
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
|
ImGui::Button(ICON_MD_ROCKET_LAUNCH "Project");
|
||||||
|
|
||||||
|
ImGui::SameLine(ImGui::GetWindowWidth() - 120);
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(1);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::EndMainMenuBar();
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::Begin("RuntimeControls");
|
||||||
|
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text(ICON_MD_TRANSFORM);
|
||||||
|
|
||||||
|
auto spacing = 10;
|
||||||
|
float buttonWidth = 75.0f;
|
||||||
|
float buttonHeight = 30;
|
||||||
|
float ColorIntensity = 0.5f;
|
||||||
|
float ColorIntensityHovered = 0.75;
|
||||||
|
float ColorIntensityActive = 0.85;
|
||||||
|
float yPadding = 6.f;
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{0, yPadding });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.0f,ColorIntensity ,0.0f ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.0f,ColorIntensityHovered ,0.0f ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.0f,ColorIntensityActive ,0.0f ,1.0f });
|
||||||
|
ImGui::SameLine(0, spacing);
|
||||||
|
if (ImGui::Button("Translate", { buttonWidth,buttonHeight }))
|
||||||
|
activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 0, yPadding });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ ColorIntensity, 0.0f ,0.0f ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ ColorIntensityHovered, 0.0f ,0.0f ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ ColorIntensityActive, 0.0f ,0.0f ,1.0f });
|
||||||
|
ImGui::SameLine(0, spacing);
|
||||||
|
if (ImGui::Button("Rotate", { buttonWidth,buttonHeight }))
|
||||||
|
activeOperation = ImGuizmo::OPERATION::ROTATE;
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 0, yPadding });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.0f, 0.0f ,ColorIntensity ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.0f, 0.0f ,ColorIntensityHovered ,1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.0f, 0.0f ,ColorIntensityActive ,1.0f });
|
||||||
|
ImGui::SameLine(0, spacing);
|
||||||
|
if (ImGui::Button("Scale", { buttonWidth,buttonHeight }))
|
||||||
|
activeOperation = ImGuizmo::OPERATION::SCALE;
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(9);
|
||||||
|
ImGui::PopStyleVar(3);
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
|
ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - (90));
|
||||||
|
auto color = ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001 * 69, 1.0f };
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||||
|
const float strengthIncrease = 1.5f;
|
||||||
|
ImGui::PushStyleColor(
|
||||||
|
ImGuiCol_ButtonHovered,
|
||||||
|
ImVec4{
|
||||||
|
color.x * strengthIncrease,
|
||||||
|
color.y * strengthIncrease,
|
||||||
|
color.z * strengthIncrease,
|
||||||
|
color.w
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (ImGui::Button(ICON_MD_PLAY_ARROW, { 90,25 })) {
|
||||||
|
// Play game
|
||||||
|
}
|
||||||
|
ImGui::PopStyleColor(2);
|
||||||
|
ImGui::SameLine();
|
||||||
|
color = ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f };
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(
|
||||||
|
ImGuiCol_ButtonHovered,
|
||||||
|
ImVec4{
|
||||||
|
color.x * strengthIncrease,
|
||||||
|
color.y * strengthIncrease,
|
||||||
|
color.z * strengthIncrease,
|
||||||
|
color.w
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ImGui::Button(ICON_MD_ELECTRIC_BOLT, { 90,25 })) {
|
||||||
|
// Simulate physics
|
||||||
|
}
|
||||||
|
ImGui::PopStyleColor(2);
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int viewportWindowFlags = ImGuiWindowFlags_NoTitleBar
|
||||||
|
| ImGuiWindowFlags_NoDecoration
|
||||||
|
| ImGuiWindowFlags_NoScrollbar
|
||||||
|
| ImGuiWindowFlags_NoMove
|
||||||
|
| ImGuiWindowFlags_NoCollapse;
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 });
|
||||||
|
ImGui::Begin("SceneView",nullptr,viewportWindowFlags);
|
||||||
|
// spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
|
SceneisFocused = ImGui::IsWindowFocused() || ImGui::IsWindowHovered();
|
||||||
|
ImGui::Image((ImTextureID)(intptr_t)renderer.get()->getCurrentFrameBuffer().GetColourAttachment(),
|
||||||
|
ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ImGuizmo::ViewManipulate(glm::value_ptr(cameraView), 1, ImGui::GetWindowPos(), { 90,90 }, 0x22CCCCCCC);
|
||||||
|
|
||||||
|
|
||||||
|
if(Selected.isValid()){
|
||||||
|
|
||||||
|
|
||||||
|
ImGuizmo::SetOrthographic(false);
|
||||||
|
ImGuizmo::SetDrawlist();
|
||||||
|
|
||||||
|
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
|
|
||||||
|
const auto& ProjMatrix = camera->getProjection(ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||||
|
const glm::mat4& viewMatrix = glm::inverse(camera->getTransform());
|
||||||
|
|
||||||
|
|
||||||
|
auto& tc = Selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||||
|
auto transform = tc.GetTransform();
|
||||||
|
ImGuizmo::Manipulate(
|
||||||
|
glm::value_ptr(viewMatrix),
|
||||||
|
glm::value_ptr(ProjMatrix),
|
||||||
|
activeOperation, ImGuizmo::LOCAL, glm::value_ptr(transform));
|
||||||
|
if (ImGuizmo::IsUsing())
|
||||||
|
{
|
||||||
|
tc.Decompose(transform);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::Begin("EditorCamera");
|
||||||
|
|
||||||
|
ImGui::SliderFloat3("position", glm::value_ptr(camera->Position), -50, 50);
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::Begin(ICON_MD_MENU "SceneExplorer",nullptr);
|
||||||
|
scene.get()->getReg().each([&](entt::entity enttNumber) {
|
||||||
|
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &*scene.get());
|
||||||
|
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||||
|
if (ImGui::Selectable(id.name.c_str(), entity == Selected)) {
|
||||||
|
Selected = YoggieEngine::Entity(enttNumber, &*scene);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::Begin("Asset", nullptr);
|
||||||
|
|
||||||
|
const char* hidden_extensions[]{
|
||||||
|
".exe",
|
||||||
|
".pdb",
|
||||||
|
".idb",
|
||||||
|
".dll",
|
||||||
|
".ini"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
std::vector <Asset> files = std::vector<Asset>();
|
||||||
|
|
||||||
|
int iconSize = 60;
|
||||||
|
int maxColumns = 3;
|
||||||
|
|
||||||
|
YoggieEngine::Texture folderIcon;
|
||||||
|
YoggieEngine::Texture assetIcon;
|
||||||
|
|
||||||
|
//assetIcon = YoggieEngine::Texture("rsc/AssetIcon.png");
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
||||||
|
ImGui::DragInt("Max. Columns", &maxColumns, 1, 1, 6);
|
||||||
|
|
||||||
|
if (ImGui::BeginTable("##Resources", 3)) {
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.f, 1.f, 1.f, 0.2f));
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int column = 0;
|
||||||
|
for (auto& asset : files) {
|
||||||
|
if (column % 3 == 0) {
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
column = 0;
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(column);
|
||||||
|
|
||||||
|
ImGui::ImageButton(
|
||||||
|
(ImTextureID)assetIcon.GetID(),
|
||||||
|
ImVec2{ (float)iconSize, (float)iconSize });
|
||||||
|
ImGui::Text(asset.Handle.String().c_str(), row);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
column++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
ImGui::EndTable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::ShowDemoWindow();
|
||||||
|
//ImGui::ShowMetricsWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OnCreate() override {
|
||||||
|
spdlog::info(" Layer Create!" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDestroy() override {
|
||||||
|
spdlog::info( " Layer Destroy!" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool OnKey(int key, int mode) override {
|
||||||
|
float movement_speed = 0.10f;
|
||||||
|
|
||||||
|
if (SceneisFocused) {
|
||||||
|
if (key == YOGGIE_KEY_UP)
|
||||||
|
camera->Rotation.x += movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_DOWN)
|
||||||
|
camera->Rotation.x -= movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_LEFT)
|
||||||
|
camera->Rotation.y += movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_RIGHT)
|
||||||
|
camera->Rotation.y -= movement_speed;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_A)
|
||||||
|
camera->Position += glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_S)
|
||||||
|
camera->Position += glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == YOGGIE_KEY_D)
|
||||||
|
camera->Position -= glm::vec3(1.0f, 0.0f, 0.0f) * movement_speed;
|
||||||
|
|
||||||
|
if (key == GLFW_KEY_W)
|
||||||
|
camera->Position -= glm::vec3(0.0f, 0.0f, -1.0f) * movement_speed;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Inspector> inspector = std::make_unique<Inspector>(Selected);
|
||||||
|
std::unique_ptr<Renderer> renderer = std::make_unique<Renderer>();
|
||||||
|
std::unique_ptr<EditorCamera> camera = std::make_unique<EditorCamera>();
|
||||||
|
std::unique_ptr<Project> project;
|
||||||
|
std::unique_ptr<Scene> scene;
|
||||||
|
|
||||||
|
Texture Logo;
|
||||||
|
|
||||||
|
|
||||||
|
bool SimulatePhysics = true;
|
||||||
|
bool SceneisFocused = false;
|
||||||
|
|
||||||
|
YoggieEngine::Entity Selected;
|
||||||
|
ImGuizmo::OPERATION activeOperation = ImGuizmo::OPERATION::TRANSLATE;
|
||||||
|
|
||||||
|
char* path = nullptr;
|
||||||
|
|
||||||
|
void LoadLastOrEmptyProject() {
|
||||||
|
// Check if there is a last known loaded project and
|
||||||
|
// load that one .
|
||||||
|
|
||||||
|
// Otherwise load no project..
|
||||||
|
// OR
|
||||||
|
// Load an empty project.
|
||||||
|
mINI::INIStructure ini;
|
||||||
|
|
||||||
|
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
||||||
|
{
|
||||||
|
mINI::INIFile file("build\\Debug\\Editor.ini");
|
||||||
|
file.read(ini);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::debug("Could not find an `Editor.ini` file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||||
|
{
|
||||||
|
|
||||||
|
Project::LoadProject(ini["cache"]["project"], *project);
|
||||||
|
///LoadScene(ini["cache"]["scene"], scene);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::debug("Starting without a project. Please create one.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -9,7 +9,8 @@ public:
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
ImGui::Begin(name.c_str(), false, flags);
|
|
||||||
|
ImGui::Begin(name.c_str(), nullptr, flags);
|
||||||
Draw();
|
Draw();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
2244
Editor/src/IconsMaterialDesign.h
Normal file
2244
Editor/src/IconsMaterialDesign.h
Normal file
File diff suppressed because it is too large
Load Diff
197
Editor/src/Inspector.cpp
Normal file
197
Editor/src/Inspector.cpp
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
#include "Inspector.h"
|
||||||
|
#include "TransformVec3.h"
|
||||||
|
#include "IconsMaterialDesign.h"
|
||||||
|
|
||||||
|
void Inspector::Draw()
|
||||||
|
{
|
||||||
|
if (selected.isValid()) {
|
||||||
|
AddComponentDropDown();
|
||||||
|
ShowComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void AddComponent(YoggieEngine::Entity selected , int i) {
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
|
selected.AddComponent<YoggieEngine::ScriptComponent>();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
selected.AddComponent<YoggieEngine::CameraComponent>();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
selected.AddComponent<YoggieEngine::LightComponent>();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
selected.AddComponent<YoggieEngine::Render3DComponent>();
|
||||||
|
default:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Inspector::AddComponentDropDown()
|
||||||
|
{
|
||||||
|
static char* names[] = { "Script Component", "Camera Component", "Light Component", "Render3D"};
|
||||||
|
if (ImGui::Button("Add Component"))
|
||||||
|
ImGui::OpenPopup("Component picker");
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::BeginPopup("Component picker")) {
|
||||||
|
|
||||||
|
for (int i = 0; i < IM_ARRAYSIZE(names); i++) {
|
||||||
|
if (ImGui::MenuItem(names[i]))
|
||||||
|
AddComponent(selected, i);
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
|
||||||
|
}
|
||||||
|
ImGui::NewLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Inspector::ShowComponents()
|
||||||
|
{
|
||||||
|
auto component = selected.GetComponent<YoggieEngine::IdentifierComponent>();
|
||||||
|
ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly);
|
||||||
|
|
||||||
|
|
||||||
|
if (selected.HasComponent<YoggieEngine::TransformComponent>()) {
|
||||||
|
auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>();
|
||||||
|
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 1.0, 1.0f, 1.0f, 0.0f });
|
||||||
|
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - 20);
|
||||||
|
ImGui::Button(ICON_MD_SETTINGS, { 20,20 });
|
||||||
|
ImGui::OpenPopupOnItemClick("##myContext", ImGuiPopupFlags_MouseButtonRight);
|
||||||
|
if (ImGui::BeginPopupContextWindow("##myContext")) {
|
||||||
|
if (ImGui::MenuItem("Reset")) {
|
||||||
|
spdlog::info("Reset component");
|
||||||
|
}
|
||||||
|
if (ImGui::MenuItem("Copy Component")) {
|
||||||
|
spdlog::info("Copy component");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
/*
|
||||||
|
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f);
|
||||||
|
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f);
|
||||||
|
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f);
|
||||||
|
*/
|
||||||
|
auto something = glm::value_ptr(transform.Position);
|
||||||
|
|
||||||
|
ImGuiExtension::TransformVec3("Position", transform.Position);
|
||||||
|
ImGuiExtension::TransformVec3("Rotation", transform.Rotation);
|
||||||
|
ImGuiExtension::TransformVec3("Scale", transform.Scale);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (selected.HasComponent<YoggieEngine::RelationComponent>()) {
|
||||||
|
ImGui::Text("Has relation");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (selected.HasComponent<YoggieEngine::Render3DComponent>()) {
|
||||||
|
auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>();
|
||||||
|
const char* AssetNames[]{ "Asset1" , "Asset2" };
|
||||||
|
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||||
|
|
||||||
|
if (ImGui::Button("Select Renderable Asset"))
|
||||||
|
ImGui::OpenPopup("Renderable_list_popup");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::TextUnformatted(render3d.mesh.elements.empty() ? "<None>" : "ASSET_GUID_OR_ID");
|
||||||
|
if (ImGui::BeginPopup("Renderable_list_popup")) {
|
||||||
|
ImGui::Text("None");
|
||||||
|
ImGui::Separator();
|
||||||
|
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
||||||
|
if(ImGui::Selectable(AssetNames[i]))
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
||||||
|
|
||||||
|
ImGui::Checkbox("Use static rendering:", &render3d.isStatic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static bool deferred = true;
|
||||||
|
|
||||||
|
|
||||||
|
if (selected.HasComponent<YoggieEngine::LightComponent>()) {
|
||||||
|
auto& light = selected.GetComponent<YoggieEngine::LightComponent>();
|
||||||
|
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||||
|
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
|
||||||
|
ImGui::Checkbox("Deferred", &deferred);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected.HasComponent <YoggieEngine::CameraComponent>()) {
|
||||||
|
auto& camera = selected.GetComponent<YoggieEngine::CameraComponent>();
|
||||||
|
if (ImGui::CollapsingHeader("Camera")) {
|
||||||
|
ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f);
|
||||||
|
ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected.HasComponent<YoggieEngine::RigidBody>()) {
|
||||||
|
auto& rigibody = selected.GetComponent<YoggieEngine::RigidBody>();
|
||||||
|
if (ImGui::CollapsingHeader("RigidBody")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected.HasComponent<YoggieEngine::ScriptComponent>()) {
|
||||||
|
const char* AssetNames[]{ "Script 1" , "Script 2" };
|
||||||
|
if (ImGui::CollapsingHeader("Script", ImGuiTreeNodeFlags_Leaf)) {
|
||||||
|
|
||||||
|
if (ImGui::Button("Select Renderable Asset"))
|
||||||
|
ImGui::OpenPopup("Scripts_list_popup");
|
||||||
|
|
||||||
|
if (ImGui::BeginPopup("Scripts_list_popup")) {
|
||||||
|
ImGui::Text("None");
|
||||||
|
ImGui::Separator();
|
||||||
|
for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) {
|
||||||
|
if (ImGui::Selectable(AssetNames[i]))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
std::string scriptAssetId = "<Random_GUID>";
|
||||||
|
ImGui::InputText("asset", scriptAssetId.data(), scriptAssetId.length(), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ComponentView(const std::string& componentName, voidFunction func)
|
||||||
|
{
|
||||||
|
ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None;
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
|
||||||
|
ImGui::BeginChild(componentName.c_str());
|
||||||
|
|
||||||
|
func();
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
#include "../EditorWindow.h"
|
#include "EditorWindow.h"
|
||||||
|
|
||||||
typedef void (*voidFunction) (void);
|
typedef void (*voidFunction) (void);
|
||||||
|
|
@ -1,194 +0,0 @@
|
|||||||
#include "MainMenuBar.h"
|
|
||||||
#include <nfd.h>
|
|
||||||
#include "AssetManagement/AssetManager.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MainMenuBar::MainMenuBar()
|
|
||||||
{
|
|
||||||
ImGui::BeginMainMenuBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::ApplicationMenu(Project& project) {
|
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Application")) {
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Load Project"))
|
|
||||||
{
|
|
||||||
nfdresult_t result = NFD_OpenDialog({ "yproj" }, NULL, &path);
|
|
||||||
switch (result) {
|
|
||||||
case(NFD_OKAY):
|
|
||||||
Project::LoadProject(path, project);
|
|
||||||
AssetManager::setAssetPath(project.GetProjectDirectory());
|
|
||||||
AssetManager::BuildAssetView();
|
|
||||||
break;
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save project as...")) {
|
|
||||||
nfdresult_t result = NFD_SaveDialog({ "yproj" }, NULL, &path);
|
|
||||||
switch (result) {
|
|
||||||
case(NFD_OKAY):
|
|
||||||
std::cout << "Save as: " << path << std::endl;
|
|
||||||
Project::SaveProject(path, project);
|
|
||||||
break;
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Preferences"))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Exit"))
|
|
||||||
{
|
|
||||||
// TODO: Exit application
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) {
|
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Scene")) {
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save scene"))
|
|
||||||
{
|
|
||||||
nfdresult_t result = NFD_SaveDialog({ "yscene" }, NULL, &path);
|
|
||||||
switch (result) {
|
|
||||||
case(NFD_OKAY):
|
|
||||||
SaveScene(path, scene);
|
|
||||||
|
|
||||||
project.AddScene(scene);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Load scene"))
|
|
||||||
{
|
|
||||||
auto result = NFD_OpenDialog({ "yscene" }, NULL, &path);
|
|
||||||
switch (result) {
|
|
||||||
case (NFD_OKAY):
|
|
||||||
LoadScene(path, scene);
|
|
||||||
break;
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Add Entity"))
|
|
||||||
{
|
|
||||||
scene.AddEntity("New Entity");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Import Model"))
|
|
||||||
{
|
|
||||||
auto result = NFD_OpenDialog("obj,fbx,gltf", NULL, &path);
|
|
||||||
switch (result) {
|
|
||||||
case(NFD_OKAY):
|
|
||||||
// Import Model
|
|
||||||
|
|
||||||
AssetManager::LoadFromSource(
|
|
||||||
path,
|
|
||||||
"build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
std::cout << "NFD_Error: " << NFD_GetError() << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Import MeshAsset (temp)"))
|
|
||||||
{
|
|
||||||
auto result = NFD_OpenDialog("mesh", NULL, &path);
|
|
||||||
|
|
||||||
switch (result) {
|
|
||||||
case(NFD_OKAY):
|
|
||||||
{
|
|
||||||
YoggieEngine::Mesh* importedMesh = AssetManager::LoadFromAssetFile(path);
|
|
||||||
if (importedMesh != nullptr)
|
|
||||||
{
|
|
||||||
auto full_name = std::filesystem::path(path);
|
|
||||||
auto importedModel = scene.AddEntity(full_name.filename().u8string());
|
|
||||||
auto& rendererComponent = importedModel.AddComponent<YoggieEngine::Render3DComponent>();
|
|
||||||
rendererComponent.mesh = *importedMesh;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case(NFD_CANCEL):
|
|
||||||
spdlog::debug("User cancelled action");
|
|
||||||
break;
|
|
||||||
case(NFD_ERROR):
|
|
||||||
spdlog::warn("Something went wrong!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::DebugMenu()
|
|
||||||
{
|
|
||||||
if (ImGui::BeginMenu("Debug")) {
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::SelectMenu() {
|
|
||||||
if (ImGui::BeginMenu("Select")) {
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::WindowMenu() {
|
|
||||||
if (ImGui::BeginMenu("Window")) {
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuBar::Help() {
|
|
||||||
if (ImGui::BeginMenu("Help")) {
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MainMenuBar::~MainMenuBar()
|
|
||||||
{
|
|
||||||
ImGui::EndMainMenuBar();
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <imgui.h>
|
|
||||||
#include "AssetManagement/SceneSerializer.h"
|
|
||||||
#include "../../YoggieEngine/src/Scene/Scene.h"
|
|
||||||
#include "Project/Project.h"
|
|
||||||
|
|
||||||
|
|
||||||
class MainMenuBar {
|
|
||||||
|
|
||||||
public:
|
|
||||||
MainMenuBar();
|
|
||||||
|
|
||||||
void ApplicationMenu(Project& project);
|
|
||||||
|
|
||||||
void SceneMenu(Project& project, YoggieEngine::Scene& scene);
|
|
||||||
|
|
||||||
void DebugMenu();
|
|
||||||
|
|
||||||
void SelectMenu();
|
|
||||||
|
|
||||||
void WindowMenu();
|
|
||||||
|
|
||||||
void Help();
|
|
||||||
|
|
||||||
~MainMenuBar();
|
|
||||||
|
|
||||||
private:
|
|
||||||
char* path = nullptr;
|
|
||||||
|
|
||||||
};
|
|
@ -31,6 +31,11 @@ void Project::SaveProject(std::filesystem::path path, Project& project)
|
|||||||
|
|
||||||
void Project::LoadProject(std::filesystem::path path, Project& project)
|
void Project::LoadProject(std::filesystem::path path, Project& project)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(path)) {
|
||||||
|
throw std::runtime_error("Couldn't find project file!");
|
||||||
|
}
|
||||||
|
|
||||||
std::string YAMLProject;
|
std::string YAMLProject;
|
||||||
std::stringstream sstream;
|
std::stringstream sstream;
|
||||||
std::ifstream projectFile;
|
std::ifstream projectFile;
|
||||||
@ -47,7 +52,7 @@ void Project::LoadProject(std::filesystem::path path, Project& project)
|
|||||||
// this is probably not perfect but it seems to work for now
|
// this is probably not perfect but it seems to work for now
|
||||||
project = node.as<Project>();
|
project = node.as<Project>();
|
||||||
|
|
||||||
std::cout << "loading..." << project.Name << std::endl;
|
spdlog::info("loaded project {0}", project.Name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -63,8 +68,13 @@ namespace YAML {
|
|||||||
{
|
{
|
||||||
if (!node.IsMap())
|
if (!node.IsMap())
|
||||||
return false;
|
return false;
|
||||||
rhs.setName(node["Project"].as<std::string>());
|
|
||||||
rhs.setProjectDirectory(node["Directory"].as<std::string>());
|
std::string projectName = node["Project"].as<std::string>();
|
||||||
|
rhs.setName(projectName);
|
||||||
|
|
||||||
|
|
||||||
|
std::string projectDirectory = node["Directory"].as<std::string>();
|
||||||
|
rhs.setProjectDirectory(projectDirectory);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -9,7 +9,7 @@ class Project {
|
|||||||
public:
|
public:
|
||||||
Project() = default;
|
Project() = default;
|
||||||
Project(const std::string& name): Name(name){}
|
Project(const std::string& name): Name(name){}
|
||||||
~Project() { std::cout << "Unloading project..." << Name << std::endl; }
|
~Project() { spdlog::info("Unloading project {0}...", Name);}
|
||||||
|
|
||||||
void setName(std::string& name) { Name = name; }
|
void setName(std::string& name) { Name = name; }
|
||||||
const std::string& GetName()const { return Name; }
|
const std::string& GetName()const { return Name; }
|
@ -1,7 +0,0 @@
|
|||||||
#include "ProjectInfo.h"
|
|
||||||
|
|
||||||
void ProjectInfo::Draw()
|
|
||||||
{
|
|
||||||
ImGui::Text("Project: %s", project.GetName().c_str());
|
|
||||||
ImGui::Text("Directory: %s", project.GetProjectDirectory().u8string().c_str());
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
#include "Project.h"
|
|
||||||
|
|
||||||
class ProjectInfo : public EditorWindow {
|
|
||||||
public:
|
|
||||||
ProjectInfo(Project& project) : EditorWindow("Project Info"), project(project) {}
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Project& project;
|
|
||||||
|
|
||||||
};
|
|
@ -1,48 +0,0 @@
|
|||||||
#include "Settings.h"
|
|
||||||
|
|
||||||
void Settings::Draw() {
|
|
||||||
ImGui::LabelText("##title-settings", "Fine grain control over the engine!");
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Graphics API", GraphicsAPI[selectedGfxAPI])) {
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
bool isSelected = i == selectedGfxAPI;
|
|
||||||
if (ImGui::Selectable(GraphicsAPI[i], isSelected)) {
|
|
||||||
selectedGfxAPI = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSelected)
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::NewLine();
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Physics Engine", PhysicsEngine[selectedPhysicsEngine])) {
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
bool isSelected = i == selectedPhysicsEngine;
|
|
||||||
if (ImGui::Selectable(PhysicsEngine[i], isSelected)) {
|
|
||||||
selectedGfxAPI = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSelected)
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::InputFloat3("Gravity", glm::value_ptr(Gravity));
|
|
||||||
|
|
||||||
ImGui::NewLine();
|
|
||||||
if (ImGui::Button("Show Advanced options ")) {
|
|
||||||
ShowAdvancedOptions = !ShowAdvancedOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ShowAdvancedOptions)
|
|
||||||
{
|
|
||||||
ImGui::Checkbox("Debug Engine", &DebugEngine);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Settings : public EditorWindow {
|
|
||||||
public:
|
|
||||||
Settings() : EditorWindow("Settings") {}
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int selectedGfxAPI = 0;
|
|
||||||
int selectedPhysicsEngine = 0;
|
|
||||||
glm::vec3 Gravity = glm::vec3(0.0f, -9.81f, 0.0f);
|
|
||||||
bool ShowAdvancedOptions = false;
|
|
||||||
bool DebugEngine = false;
|
|
||||||
|
|
||||||
const char* PhysicsEngine[2] = {
|
|
||||||
"PhysX",
|
|
||||||
"Jolt Physics"
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* GraphicsAPI[3] = {
|
|
||||||
"OpenGL",
|
|
||||||
"Vulkan",
|
|
||||||
"Metal (Apple)"
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
@ -1,107 +0,0 @@
|
|||||||
#include "Inspector.h"
|
|
||||||
|
|
||||||
|
|
||||||
void Inspector::Draw()
|
|
||||||
{
|
|
||||||
if (selected.isValid()) {
|
|
||||||
AddComponentDropDown();
|
|
||||||
ShowComponents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Inspector::AddComponentDropDown()
|
|
||||||
{
|
|
||||||
static char* names[] = { "Script Component", "Camera Component", "Light Component" };
|
|
||||||
if (ImGui::Button("Add Component"))
|
|
||||||
ImGui::OpenPopup("Component picker");
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::BeginPopup("Component picker")) {
|
|
||||||
|
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
|
|
||||||
if (ImGui::MenuItem(names[i])) {
|
|
||||||
std::cout << "Add a " << names[i] << " to "
|
|
||||||
<< selected.GetComponent<YoggieEngine::IdentifierComponent>().name << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
|
||||||
ImGui::NewLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Inspector::ShowComponents()
|
|
||||||
{
|
|
||||||
auto component = selected.GetComponent<YoggieEngine::IdentifierComponent>();
|
|
||||||
ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly);
|
|
||||||
|
|
||||||
|
|
||||||
if (selected.HasComponent<YoggieEngine::TransformComponent>()) {
|
|
||||||
auto& transform = selected.GetComponent<YoggieEngine::TransformComponent>();
|
|
||||||
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
||||||
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f);
|
|
||||||
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f);
|
|
||||||
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f);
|
|
||||||
}
|
|
||||||
if (selected.HasComponent<YoggieEngine::RelationComponent>()) {
|
|
||||||
ImGui::Text("Has relation");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (selected.HasComponent<YoggieEngine::Render3DComponent>()) {
|
|
||||||
auto& render3d = selected.GetComponent<YoggieEngine::Render3DComponent>();
|
|
||||||
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
||||||
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
|
||||||
|
|
||||||
ImGui::Checkbox("Use static rendering:", &render3d.isStatic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static bool deferred = true;
|
|
||||||
if (selected.HasComponent<YoggieEngine::LightComponent>()) {
|
|
||||||
auto& light = selected.GetComponent<YoggieEngine::LightComponent>();
|
|
||||||
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
||||||
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
|
|
||||||
ImGui::Checkbox("Deferred", &deferred);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected.HasComponent <YoggieEngine::CameraComponent>()) {
|
|
||||||
auto& camera = selected.GetComponent<YoggieEngine::CameraComponent>();
|
|
||||||
if (ImGui::CollapsingHeader("Camera")) {
|
|
||||||
ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f);
|
|
||||||
ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected.HasComponent<YoggieEngine::RigidBody>()) {
|
|
||||||
auto& rigibody = selected.GetComponent<YoggieEngine::RigidBody>();
|
|
||||||
if (ImGui::CollapsingHeader("RigidBody")) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected.HasComponent<YoggieEngine::ScriptComponent>()) {
|
|
||||||
ComponentView("Scripting", [] {
|
|
||||||
ImGui::LabelText("##--", "Hello scripting");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ComponentView(const std::string& componentName, voidFunction func)
|
|
||||||
{
|
|
||||||
ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None;
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
|
|
||||||
ImGui::BeginChild(componentName.c_str());
|
|
||||||
|
|
||||||
func();
|
|
||||||
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
#include "SceneExplorer.h"
|
|
||||||
|
|
||||||
void SceneExplorer::Draw()
|
|
||||||
{
|
|
||||||
scene.getReg().each([&](entt::entity enttNumber) {
|
|
||||||
YoggieEngine::Entity entity = YoggieEngine::Entity(enttNumber, &scene);
|
|
||||||
auto id = entity.GetComponent<YoggieEngine::IdentifierComponent>();
|
|
||||||
|
|
||||||
if (ImGui::Selectable(id.name.c_str(), entity == selected)) {
|
|
||||||
selected = YoggieEngine::Entity(enttNumber, &scene);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
#include "../../src/Scene/Entity.h"
|
|
||||||
|
|
||||||
class SceneExplorer : public EditorWindow {
|
|
||||||
public:
|
|
||||||
SceneExplorer(YoggieEngine::Entity& selected, YoggieEngine::Scene& scene)
|
|
||||||
: EditorWindow("SceneExplorer"), scene(scene), selected(selected)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
YoggieEngine::Entity& selected;
|
|
||||||
YoggieEngine::Scene& scene;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
@ -1,27 +0,0 @@
|
|||||||
#include "RuntimeControls.h"
|
|
||||||
|
|
||||||
void RuntimeControls::Draw() {
|
|
||||||
ImGui::SameLine((ImGui::GetWindowContentRegionMax().x / 2) - (numButtons * buttonSize.x));
|
|
||||||
for (int i = 0; i < numButtons; i++) {
|
|
||||||
ImVec4 color = button[i].Color;
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
|
||||||
const float strengthIncrease = 1.5f;
|
|
||||||
ImGui::PushStyleColor(
|
|
||||||
ImGuiCol_ButtonHovered,
|
|
||||||
ImVec4{
|
|
||||||
color.x * strengthIncrease,
|
|
||||||
color.y * strengthIncrease,
|
|
||||||
color.z * strengthIncrease,
|
|
||||||
color.w
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (ImGui::Button(button[i].Name, buttonSize)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
|
|
||||||
#define RuntimeControlWindowFlags (ImGuiWindowFlags_)(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse)
|
|
||||||
|
|
||||||
struct ButtonInfo {
|
|
||||||
const char* Name;
|
|
||||||
ImVec4 Color;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RuntimeControls : public EditorWindow {
|
|
||||||
public:
|
|
||||||
RuntimeControls() : EditorWindow("RuntimeControls", RuntimeControlWindowFlags) {}
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ImVec2 buttonSize = ImVec2{ 90 ,25 };
|
|
||||||
unsigned int numButtons = 2;
|
|
||||||
ButtonInfo button[2] = {
|
|
||||||
{"Play" , ImVec4{ 0.001 * 12 , 0.001 * 201 , 0.001 * 69, 1.0f}},
|
|
||||||
{"Simulate", ImVec4{ 0.001 * 14, 0.001 * 157, 0.001 * 201, 1.0f}}
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
59
Editor/src/TransformVec3.h
Normal file
59
Editor/src/TransformVec3.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <imgui_widgets.cpp>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
namespace ImGuiExtension {
|
||||||
|
|
||||||
|
|
||||||
|
void TransformVec3(const char* label, glm::vec3& vector) {
|
||||||
|
|
||||||
|
ImGui::PushID(label);
|
||||||
|
ImGui::Columns(2);
|
||||||
|
ImGui::SetColumnWidth(0, 100.0f);
|
||||||
|
ImGui::Text(label);
|
||||||
|
|
||||||
|
ImGui::NextColumn();
|
||||||
|
|
||||||
|
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f,0.2f,0.2f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f,0.1f,0.15f, 1.0f });
|
||||||
|
if (ImGui::Button("X"))
|
||||||
|
vector.x = 0;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##X", &glm::value_ptr(vector)[0], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f,0.8f,0.3f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f,0.7f,0.2f, 1.0f });
|
||||||
|
if (ImGui::Button("Y"))
|
||||||
|
vector.y = 0;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Y", &glm::value_ptr(vector)[1], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.2f,0.35f,0.9f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.1f,0.25f,0.8f, 1.0f });
|
||||||
|
if (ImGui::Button("Z"))
|
||||||
|
vector.z = 0;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Z", &glm::value_ptr(vector)[2], 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::Columns(1);
|
||||||
|
ImGui::PopID();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
#include "Viewport.h"
|
|
||||||
|
|
||||||
Viewport::Viewport(YoggieEngine::Scene& scene ):
|
|
||||||
EditorWindow("SceneView"),
|
|
||||||
renderer(YoggieEngine::RendererConfig{ 1200, 700, glm::vec3(0), true }),
|
|
||||||
cam(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90),
|
|
||||||
scene(scene)
|
|
||||||
{
|
|
||||||
renderer.SetMainCamera(cam);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Viewport::Draw() {
|
|
||||||
|
|
||||||
auto group = scene.getReg().view<YoggieEngine::TransformComponent, YoggieEngine::Render3DComponent>();
|
|
||||||
group.each([&](auto enity, YoggieEngine::TransformComponent& t, YoggieEngine::Render3DComponent& renderComponent) {
|
|
||||||
renderer.Submit(renderComponent, t);
|
|
||||||
});
|
|
||||||
|
|
||||||
cam.Update();
|
|
||||||
renderer.Render(scene);
|
|
||||||
|
|
||||||
ImVec2 WinPos = ImGui::GetWindowPos();
|
|
||||||
ImVec2 ContentRegionMin = ImGui::GetWindowContentRegionMin();
|
|
||||||
ImVec2 ContentRegionMax = ImGui::GetWindowContentRegionMax();
|
|
||||||
ImVec2 ScreenSpaceMin = { ContentRegionMin.x + WinPos.x, ContentRegionMin.y + WinPos.y };
|
|
||||||
ImVec2 ScreenSpaceMax = { ContentRegionMax.x + WinPos.x,ContentRegionMax.y + WinPos.y };
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::Image(
|
|
||||||
(void*)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(),
|
|
||||||
ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight() }
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
ImGuizmo::Enable(true);
|
|
||||||
ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y);
|
|
||||||
|
|
||||||
glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix);
|
|
||||||
|
|
||||||
//ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f);
|
|
||||||
//ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC);
|
|
||||||
|
|
||||||
// Matrix is the model matrix we would want to manipulate
|
|
||||||
//ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix));
|
|
||||||
|
|
||||||
if (ImGui::IsWindowFocused())
|
|
||||||
{
|
|
||||||
isFocused = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
isFocused = false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
|
||||||
#include "../EditorWindow.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include <imgui.h>
|
|
||||||
#include "../../libs/guizmo/ImGuizmo.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Viewport : public EditorWindow {
|
|
||||||
public:
|
|
||||||
bool isFocused = false;
|
|
||||||
YoggieEngine::Camera cam;
|
|
||||||
|
|
||||||
Viewport(YoggieEngine::Scene& scene);
|
|
||||||
|
|
||||||
void Draw() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
YoggieEngine::Renderer renderer;
|
|
||||||
YoggieEngine::Scene& scene;
|
|
||||||
|
|
||||||
};
|
|
@ -1,192 +1,17 @@
|
|||||||
#include "../../YoggieEngine/src/EntryPoint.h"
|
#include "EditorLayer.h"
|
||||||
#include <mini/ini.h>
|
#include "EntryPoint.h"
|
||||||
#include <glm/glm.hpp>
|
#include <stack>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include "AssetManagement/SceneSerializer.h"
|
|
||||||
#include "AssetManagement/AssetManager.h"
|
|
||||||
#include "Views/Viewport.h"
|
|
||||||
#include "PropertyPanels/SceneExplorer.h"
|
|
||||||
#include "AssetManagement/AssetFinder.h"
|
|
||||||
#include "MainMenuBar.h"
|
|
||||||
#include "PropertyPanels/Inspector.h"
|
|
||||||
#include "Project/ProjectInfo.h"
|
|
||||||
#include "Runtime/RuntimeControls.h"
|
|
||||||
#include "Project/Settings.h"
|
|
||||||
#include "Console.h"
|
|
||||||
|
|
||||||
using namespace YoggieEngine;
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
class Editor : public Application {
|
class Editor : public Application {
|
||||||
public:
|
public:
|
||||||
Editor() : Application("Editor"){}
|
Editor() : Application("Editor") {}
|
||||||
|
|
||||||
void Run() override
|
|
||||||
{
|
|
||||||
std::string path = (std::filesystem::current_path()).string();
|
|
||||||
project.setProjectDirectory(path);
|
|
||||||
|
|
||||||
AssetManager::Init();
|
|
||||||
AssetManager::setAssetPath(project.GetProjectDirectory());
|
|
||||||
AssetManager::BuildAssetView();
|
|
||||||
|
|
||||||
LoadLastOrEmptyProject();
|
|
||||||
|
|
||||||
ProjectInfo projectInfo(project);
|
|
||||||
Viewport sceneview = Viewport(scene);
|
|
||||||
RuntimeControls rc = RuntimeControls();
|
|
||||||
SceneExplorer explorer(Selected, scene);
|
|
||||||
Inspector inspector = Inspector(Selected);
|
|
||||||
Settings settings = Settings();
|
|
||||||
// AssetFinder assetsView = AssetFinder();
|
|
||||||
Console console = Console();
|
|
||||||
|
|
||||||
Selected = YoggieEngine::Entity((entt::entity) -1, &scene);
|
|
||||||
|
|
||||||
double previous = glfwGetTime();
|
|
||||||
double lag = 0.0;
|
|
||||||
while (!appWindow.WindowShouldClose())
|
|
||||||
{
|
|
||||||
PollEvents();
|
|
||||||
double now = glfwGetTime();
|
|
||||||
double elapsed = now - previous ;
|
|
||||||
previous = now;
|
|
||||||
lag += elapsed;
|
|
||||||
|
|
||||||
if (sceneview.isFocused)
|
|
||||||
{
|
|
||||||
const float movement_speed = 0.1f;
|
|
||||||
static float lastX = 400, lastY = 300;
|
|
||||||
const float sensitivity = 0.1;
|
|
||||||
static bool firstMouse = true;
|
|
||||||
|
|
||||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
|
||||||
|
|
||||||
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
||||||
auto newX = getCursorPosX(&appWindow);
|
|
||||||
auto newY = getCursorPosY(&appWindow);
|
|
||||||
|
|
||||||
if (firstMouse)
|
|
||||||
{
|
|
||||||
lastX = newX;
|
|
||||||
lastY = newY;
|
|
||||||
firstMouse = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float xoffset = newX - lastX;
|
|
||||||
float yoffset = newY - lastY;
|
|
||||||
|
|
||||||
lastX = newX;
|
|
||||||
lastY = newY;
|
|
||||||
|
|
||||||
xoffset *= sensitivity;
|
|
||||||
yoffset *= sensitivity;
|
|
||||||
|
|
||||||
sceneview.cam.yaw += xoffset;
|
|
||||||
sceneview.cam.pitch += yoffset;
|
|
||||||
|
|
||||||
if (sceneview.cam.pitch > 89.0f)
|
|
||||||
sceneview.cam.pitch = 89.0f;
|
|
||||||
if (sceneview.cam.pitch < -89.0f)
|
|
||||||
sceneview.cam.pitch = -89.0f;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (firstMouse == false)
|
|
||||||
{
|
|
||||||
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
firstMouse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Camara movement input here!
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_W))
|
|
||||||
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_A))
|
|
||||||
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_S))
|
|
||||||
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_D))
|
|
||||||
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
GuiBegin();
|
|
||||||
{
|
|
||||||
MainMenuBar menuBar = MainMenuBar();
|
|
||||||
|
|
||||||
// Show a menu bar
|
|
||||||
menuBar.ApplicationMenu(project);
|
|
||||||
menuBar.SceneMenu(project, scene);
|
|
||||||
menuBar.SelectMenu();
|
|
||||||
menuBar.WindowMenu();
|
|
||||||
menuBar.DebugMenu();
|
|
||||||
menuBar.Help();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
projectInfo.Update();
|
|
||||||
sceneview.Update();
|
|
||||||
rc.Update();
|
|
||||||
explorer.Update();
|
|
||||||
settings.Update();
|
|
||||||
inspector.Update();
|
|
||||||
console.Update();
|
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
|
||||||
ImGui::ShowMetricsWindow();
|
|
||||||
|
|
||||||
|
|
||||||
GuiEnd();
|
|
||||||
SwapBuffers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LoadLastOrEmptyProject() {
|
|
||||||
// Check if there is a last known loaded project and
|
|
||||||
// load that one .
|
|
||||||
|
|
||||||
// Otherwise load no project..
|
|
||||||
// OR
|
|
||||||
// Load an empty project.
|
|
||||||
mINI::INIStructure ini;
|
|
||||||
|
|
||||||
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
|
||||||
{
|
|
||||||
mINI::INIFile file("build\\Debug\\Editor.ini");
|
|
||||||
file.read(ini);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spdlog::debug("Could not find an `Editor.ini` file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ini["editor"]["openlastproject"] == "TRUE")
|
|
||||||
{
|
|
||||||
Project::LoadProject(ini["cache"]["project"], project);
|
|
||||||
LoadScene(ini["cache"]["scene"], scene);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
spdlog::debug("Starting without a project. Please create one.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool SimulatePhysics = true;
|
|
||||||
YoggieEngine::Entity Selected;
|
|
||||||
|
|
||||||
Project project;
|
|
||||||
Scene scene;
|
|
||||||
|
|
||||||
|
void Run() override {
|
||||||
|
PushLayer(new EditorLayer());
|
||||||
|
Application::Run();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
YoggieEngine::Application* CreateApplication() {
|
YoggieEngine::Application *CreateApplication() { return new Editor(); }
|
||||||
|
|
||||||
return new Editor();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
project "ImGui"
|
|
||||||
kind "StaticLib"
|
|
||||||
|
|
||||||
includedirs {
|
|
||||||
"../libs/glfw/include",
|
|
||||||
"../libs/ImGui"
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"../libs/ImGui/*.cpp",
|
|
||||||
"../libs/ImGui/backends/imgui_impl_glfw.cpp",
|
|
||||||
"../libs/ImGui/backends/imgui_impl_Opengl3.cpp",
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs{
|
|
||||||
"../libs/ImGui",
|
|
||||||
"../libs/glad"
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
project "ImGuizmo"
|
|
||||||
kind "StaticLib"
|
|
||||||
|
|
||||||
includedirs {
|
|
||||||
"../libs/glfw/include",
|
|
||||||
"../libs/ImGui",
|
|
||||||
"../libs/guizmo"
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"../libs/guizmo/*.cpp",
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs{
|
|
||||||
"../libs/ImGui",
|
|
||||||
"../libs/glad"
|
|
||||||
}
|
|
||||||
|
|
||||||
include("../ImGui")
|
|
@ -1,39 +0,0 @@
|
|||||||
project "Runtime"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building the runtime ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
"./../YoggieEngine/src",
|
|
||||||
-- I'd prefer if didn't need these..
|
|
||||||
-- We'll figure that out some time later
|
|
||||||
"./../libs/lua/include",
|
|
||||||
"./../libs/spdlog/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/GorillaAudio/include",
|
|
||||||
|
|
||||||
"./../libs/assimp/include",
|
|
||||||
"./../libs/glad/include",
|
|
||||||
"./../libs/glfw/include",
|
|
||||||
"./../libs/tinygltf",
|
|
||||||
"./../libs/glew/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/ImGui",
|
|
||||||
|
|
||||||
|
|
||||||
"./include"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
'./../YoggieEngine/build/Debug'
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"./src/*.h",
|
|
||||||
"./src/*.cpp"
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::cout << "Welcome to the runtime!" << std::endl;
|
|
||||||
}
|
|
6
SandboxApp/CMakeLists.txt
Normal file
6
SandboxApp/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
file(GLOB SOURCE_FILES "src/*.cpp")
|
||||||
|
file(GLOB HEADER_FILES "src/*.h")
|
||||||
|
add_executable(SandboxApp ${SOURCE_FILES} ${HEADER_FILES} )
|
||||||
|
target_link_directories(SandboxApp PRIVATE "../build/YoggieEngine/Debug")
|
||||||
|
target_link_libraries(SandboxApp YoggieEngine)
|
||||||
|
target_include_directories(SandboxApp PRIVATE "../YoggieEngine/src")
|
@ -1,40 +0,0 @@
|
|||||||
project "SandboxApp"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building SandboxApp ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"YoggieEngine"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
"./../YoggieEngine/Include",
|
|
||||||
|
|
||||||
-- I'd prefer if didn't need these..
|
|
||||||
-- We'll figure that out some time later
|
|
||||||
"./../libs/lua/include",
|
|
||||||
"./../libs/spdlog/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/GorillaAudio/include",
|
|
||||||
|
|
||||||
"./../libs/assimp/include",
|
|
||||||
"./../libs/glad/include",
|
|
||||||
"./../libs/glfw/include",
|
|
||||||
"./../libs/tinygltf",
|
|
||||||
"./../libs/glew/include",
|
|
||||||
"./../libs/glm",
|
|
||||||
"./../libs/ImGui",
|
|
||||||
|
|
||||||
"../libs/entt/src",
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
'./../YoggieEngine/build/Debug'
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"./src/*.h",
|
|
||||||
"./src/*.cpp"
|
|
||||||
}
|
|
@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "YoggieEngine.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
|
||||||
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
|
|
||||||
|
|
||||||
void CameraTool();
|
void CameraTool();
|
||||||
void ScriptingTool(char* code);
|
void ScriptingTool(char *code);
|
||||||
///void transformWindow(Transform& transform, std::string PanelName);
|
/// void transformWindow(Transform& transform, std::string PanelName);
|
||||||
void materialWindow(Material& material, std::string PanelName);
|
void materialWindow(Material &material, std::string PanelName);
|
||||||
void SceneExplorer(const std::string& PanelName);
|
void SceneExplorer(const std::string &PanelName);
|
||||||
void SceneView(Framebuffer& framebuffer);
|
void SceneView(Framebuffer &framebuffer);
|
||||||
|
@ -1,123 +1,102 @@
|
|||||||
#include <imgui.h>
|
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
#include "YoggieEngine.h"
|
||||||
#include "../../YoggieEngine/src/Scene/Components.h"
|
|
||||||
#include "../../YoggieEngine/src/Scene/Scene.h"
|
|
||||||
#include "../../YoggieEngine/src/Scene/Entity.h"
|
|
||||||
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
|
||||||
#include "../../YoggieEngine/src/PerfCounter.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define globals
|
* Define globals
|
||||||
*/
|
*/
|
||||||
Scene scene;
|
Scene scene;
|
||||||
|
|
||||||
BarinkEngine::Renderable* renderable;
|
BarinkEngine::Renderable *renderable;
|
||||||
BarinkEngine::SceneObject* object;
|
BarinkEngine::SceneObject *object;
|
||||||
Entity cube;
|
Entity cube;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs once at startup
|
* Runs once at startup
|
||||||
* - USe to initialize the game/sandbox/demo
|
* - USe to initialize the game/sandbox/demo
|
||||||
*/
|
*/
|
||||||
void Start() {
|
void Start() {
|
||||||
auto importer = BarinkEngine::ModelImporter();
|
auto importer = BarinkEngine::ModelImporter();
|
||||||
|
|
||||||
// Load in asset(S)
|
// Load in asset(S)
|
||||||
object = importer.Import("build/Debug/Models/Cube.obj");
|
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||||
renderable = object->renderable;
|
renderable = object->renderable;
|
||||||
|
|
||||||
|
// Add Entities to the scene
|
||||||
|
cube = scene.AddEntity("cube");
|
||||||
|
auto &render3DComponent =
|
||||||
|
cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
render3DComponent.mesh = *renderable->mesh;
|
||||||
|
cube.GetComponent<BarinkEngine::TransformComponent>().transform =
|
||||||
|
glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f, 1.0f, 0.0f));
|
||||||
|
|
||||||
// Add Entities to the scene
|
// Create a second cube
|
||||||
cube = scene.AddEntity("cube");
|
|
||||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
|
||||||
render3DComponent.mesh = *renderable->mesh;
|
|
||||||
cube.GetComponent<BarinkEngine::TransformComponent>()
|
|
||||||
.transform = glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f,1.0f,0.0f));
|
|
||||||
|
|
||||||
|
auto cube2 = scene.AddEntity("Cube2");
|
||||||
|
auto &cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
cube2Render.mesh = *renderable->mesh;
|
||||||
|
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
auto &cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
||||||
|
cube2Trans.transform =
|
||||||
|
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 5.0f));
|
||||||
|
|
||||||
// Create a second cube
|
// Create a light
|
||||||
|
auto AmbientLight = scene.AddEntity("AmbientLight");
|
||||||
auto cube2 = scene.AddEntity("Cube2");
|
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
||||||
auto& cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
|
||||||
cube2Render.mesh = *renderable->mesh;
|
|
||||||
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
auto& cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
|
||||||
cube2Trans.transform = glm::translate( glm::mat4(1.0f), glm::vec3(1.0f,0.0f, 5.0f));
|
|
||||||
|
|
||||||
// Create a light
|
|
||||||
auto AmbientLight = scene.AddEntity("AmbientLight");
|
|
||||||
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
|
||||||
|
|
||||||
renderer.Prepare(scene);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs every frame
|
|
||||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
|
||||||
*/
|
|
||||||
void ImmediateGraphicsDraw()
|
|
||||||
{
|
|
||||||
// Show internal BarinkEngine stats
|
|
||||||
EngineInstrumentation::ShowStats();
|
|
||||||
|
|
||||||
ImGui::Begin("Scene view");
|
|
||||||
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
|
||||||
group.each([](auto entity, BarinkEngine::IdentifierComponent& identifier) {
|
|
||||||
|
|
||||||
ImGui::Text("%s", identifier.name.c_str());
|
|
||||||
|
|
||||||
});
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
ImGui::ShowMetricsWindow();
|
|
||||||
|
|
||||||
ImGui::Begin("Settings");
|
|
||||||
|
|
||||||
|
|
||||||
auto& a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
|
||||||
|
|
||||||
auto& b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
|
||||||
|
|
||||||
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
ImGui::DragFloat3("Position", &b.transform[3][0], 0.01f, 0.0f, 16.0f);
|
|
||||||
|
|
||||||
auto l = scene.getReg().view<BarinkEngine::LightComponent>();
|
|
||||||
l.each([](auto entity, BarinkEngine::LightComponent& light) {
|
|
||||||
ImGui::Text("Lighting");
|
|
||||||
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
|
||||||
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
|
renderer.Prepare(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs every frame
|
* Runs every frame
|
||||||
* - Meant for game logic ( non-physics related)
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||||
*/
|
*/
|
||||||
void Update()
|
void ImmediateGraphicsDraw() {
|
||||||
{
|
// Show internal BarinkEngine stats
|
||||||
}
|
EngineInstrumentation::ShowStats();
|
||||||
|
|
||||||
void Render()
|
ImGui::Begin("Scene view");
|
||||||
{
|
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
||||||
renderer.Render(scene);
|
group.each([](auto entity, BarinkEngine::IdentifierComponent &identifier) {
|
||||||
|
ImGui::Text("%s", identifier.name.c_str());
|
||||||
|
});
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::ShowMetricsWindow();
|
||||||
|
|
||||||
|
ImGui::Begin("Settings");
|
||||||
|
|
||||||
|
auto &a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
|
||||||
|
auto &b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
||||||
|
|
||||||
|
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
ImGui::DragFloat3("Position", &b.transform[3][0], 0.01f, 0.0f, 16.0f);
|
||||||
|
|
||||||
|
auto l = scene.getReg().view<BarinkEngine::LightComponent>();
|
||||||
|
l.each([](auto entity, BarinkEngine::LightComponent &light) {
|
||||||
|
ImGui::Text("Lighting");
|
||||||
|
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
||||||
|
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
||||||
|
});
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs at the end of the program
|
* Runs every frame
|
||||||
* - Meant for cleanup
|
* - Meant for game logic ( non-physics related)
|
||||||
*/
|
*/
|
||||||
void Stop()
|
void Update() {}
|
||||||
{
|
|
||||||
}
|
void Render() { renderer.Render(scene); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs at the end of the program
|
||||||
|
* - Meant for cleanup
|
||||||
|
*/
|
||||||
|
void Stop() {}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../YoggieEngine/src/BarinkEngine.h"
|
#include "YoggieEngine.h"
|
||||||
|
|
||||||
//void PrintSceneTree(Node& node, int depth);
|
// void PrintSceneTree(Node& node, int depth);
|
||||||
|
|
||||||
//glm::mat4 CalculateModelMat(Transform& transform);
|
// glm::mat4 CalculateModelMat(Transform& transform);
|
||||||
|
22
YoggieEngine/CMakeLists.txt
Normal file
22
YoggieEngine/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
file(GLOB SOURCE_FILES src/*.cpp)
|
||||||
|
add_library(YoggieEngine ${SOURCE_FILES} )
|
||||||
|
#target_precompile_headers(YoggieEngine PUBLIC src/YoggieEngine.h )
|
||||||
|
|
||||||
|
target_link_directories(YoggieEngine PUBLIC
|
||||||
|
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
|
||||||
|
)
|
||||||
|
target_link_libraries(YoggieEngine
|
||||||
|
thirdparty_tools
|
||||||
|
PhysX_64
|
||||||
|
PhysXCooking_64
|
||||||
|
PhysXCommon_64
|
||||||
|
PhysXFoundation_64
|
||||||
|
PhysXPvdSDK_static_64
|
||||||
|
PhysXExtensions_static_64
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(YoggieEngine PUBLIC
|
||||||
|
"../libs/physx/pxshared/include"
|
||||||
|
"../libs/physx/physx/include"
|
||||||
|
)
|
||||||
|
|
@ -1,83 +0,0 @@
|
|||||||
project "YoggieEngine"
|
|
||||||
kind "StaticLib"
|
|
||||||
|
|
||||||
pchheader "YoggieEngine.h"
|
|
||||||
pchsource "src/YoggieEngine.cpp"
|
|
||||||
|
|
||||||
|
|
||||||
buildmessage "Building Yoggie Engine"
|
|
||||||
disablewarnings{
|
|
||||||
"4099" -- Ignore the missing debug signals for GLFW warning
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
includedirs {
|
|
||||||
"./src",
|
|
||||||
"../libs/spdlog/include",
|
|
||||||
"../libs/glm",
|
|
||||||
|
|
||||||
"../libs/glfw/include",
|
|
||||||
"../libs/glew/include",
|
|
||||||
"../libs/glad/include",
|
|
||||||
|
|
||||||
|
|
||||||
"../libs/assimp/include",
|
|
||||||
"../libs/entt/src",
|
|
||||||
|
|
||||||
"../libs/physx/pxshared/include",
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
|
|
||||||
"../libs/lua/include",
|
|
||||||
|
|
||||||
"../libs/GorillaAudio/include",
|
|
||||||
"../libs/steam-audio/include",
|
|
||||||
|
|
||||||
"../libs/ImGui",
|
|
||||||
}
|
|
||||||
|
|
||||||
links {
|
|
||||||
-- This needs to fall under the filter as the names can differ on different platforms
|
|
||||||
"phonon",
|
|
||||||
"lua54",
|
|
||||||
"spdlog",
|
|
||||||
"assimp-vc143-mtd",
|
|
||||||
"glfw3",
|
|
||||||
"ImGui",
|
|
||||||
|
|
||||||
"PhysX_64",
|
|
||||||
"PhysXCooking_64",
|
|
||||||
"PhysXCommon_64",
|
|
||||||
"PhysXFoundation_64",
|
|
||||||
"PhysXPvdSDK_static_64",
|
|
||||||
"PhysXExtensions_static_64"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
"../libs/steam-audio/lib/windows-x64",
|
|
||||||
"../libs/lua",
|
|
||||||
"../libs/spdlog/build/Release",
|
|
||||||
"../libs/assimp/lib/Debug",
|
|
||||||
"../libs/glfw/build/src/Debug",
|
|
||||||
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
|
|
||||||
"./src/**.cpp",
|
|
||||||
"./src/**.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
prebuildcommands
|
|
||||||
{
|
|
||||||
ok,err = os.copyfile("YoggieEngine/src/Graphics/shaders/*" ,"SandboxApp/build/Debug/")
|
|
||||||
}
|
|
||||||
|
|
||||||
postbuildcommands
|
|
||||||
{
|
|
||||||
ok,err = os.copyfile("YoggieEngine/build/Debug/intermediates/YoggieEngine.pch", "YoggieEngine/build/Debug/YoggieEngine.pch")
|
|
||||||
}
|
|
||||||
|
|
@ -4,13 +4,15 @@
|
|||||||
#include <backends/imgui_impl_opengl3.h>
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include <backends/imgui_impl_glfw.h>
|
#include <backends/imgui_impl_glfw.h>
|
||||||
#include "../../libs/guizmo/ImGuizmo.h"
|
#include "../../libs/guizmo/ImGuizmo.h"
|
||||||
|
#include "../../Editor/src/IconsMaterialDesign.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
Application::Application(const std::string& name)
|
Application::Application(const std::string& name)
|
||||||
: m_AppName(name), appWindow(1200, 700)
|
: m_AppName(name)
|
||||||
{
|
{
|
||||||
|
appWindow = CreateNativeWindow(1200, 700, m_AppName.c_str());
|
||||||
|
|
||||||
// Initialize engine should possibly happen here
|
// Initialize engine should possibly happen here
|
||||||
EngineInstrumentation::PerfomanceSamplerInit();
|
EngineInstrumentation::PerfomanceSamplerInit();
|
||||||
|
|
||||||
@ -21,32 +23,94 @@ namespace YoggieEngine {
|
|||||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
||||||
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/Roboto-Regular.ttf", 18);
|
||||||
|
ImFontConfig config;
|
||||||
|
config.MergeMode = true;
|
||||||
|
config.GlyphMinAdvanceX = 18.0f;
|
||||||
|
static const ImWchar icon_ranges[] = { ICON_MIN_MD , ICON_MAX_MD, 0 };
|
||||||
|
io.Fonts->AddFontFromFileTTF("build/Debug/Fonts/MaterialIcons-Regular.ttf", 24, &config, icon_ranges);
|
||||||
|
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
|
/*
|
||||||
|
ImGuiStyle* style = &ImGui::GetStyle();
|
||||||
|
ImVec4* colors = style->Colors;
|
||||||
|
|
||||||
ImGui_ImplGlfw_InitForOpenGL(appWindow.GetGLFWHandle(), true);
|
colors[ImGuiCol_TitleBg] = ImVec4(0.72f, 0.24f, 0.87f, 1.00f);
|
||||||
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.72f, 0.24f, 0.87f, 1.00f);
|
||||||
|
colors[ImGuiCol_Tab] = ImVec4(0.53f, 0.09f, 0.67f, 1.00f);
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)appWindow->GetHandle(), true);
|
||||||
ImGui_ImplOpenGL3_Init("#version 450");
|
ImGui_ImplOpenGL3_Init("#version 450");
|
||||||
|
|
||||||
ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext());
|
ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext());
|
||||||
ImGuizmo::SetOrthographic(true);
|
//ImGuizmo::SetOrthographic(true);
|
||||||
|
|
||||||
|
|
||||||
init_inputSystem(&appWindow);
|
//init_inputSystem(appWindow);
|
||||||
|
glfwSetWindowUserPointer((GLFWwindow*)this->appWindow->GetHandle(), this);
|
||||||
|
glfwSetKeyCallback((GLFWwindow*)this->appWindow->GetHandle(), HandleKey);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Application::HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||||
|
auto app = (Application*)glfwGetWindowUserPointer(window);
|
||||||
|
for (auto i = app->AppLayerstack.begin(); i < app->AppLayerstack.end(); i++) {
|
||||||
|
if ((*i)->OnKey(key, action)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::Run() {
|
void Application::Run() {
|
||||||
std::cout << "No run function implemented!";
|
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnStartup();
|
||||||
|
}
|
||||||
|
|
||||||
|
double previous = glfwGetTime();
|
||||||
|
double lag = 0.0;
|
||||||
|
|
||||||
|
while (!appWindow->WindowShouldClose()) {
|
||||||
|
PollEvents();
|
||||||
|
double now = glfwGetTime();
|
||||||
|
double elapsed = now - previous;
|
||||||
|
previous = now;
|
||||||
|
lag += elapsed;
|
||||||
|
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiBegin();
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnUI();
|
||||||
|
}
|
||||||
|
GuiEnd();
|
||||||
|
|
||||||
|
SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = AppLayerstack.begin(); i < AppLayerstack.end(); i++) {
|
||||||
|
(*i)->OnDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Application::PollEvents() {
|
void Application::PollEvents() {
|
||||||
appWindow.Poll();
|
appWindow->Poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::SwapBuffers()
|
void Application::SwapBuffers()
|
||||||
{
|
{
|
||||||
appWindow.SwapBuffers();
|
appWindow->SwapBuffers();
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +121,12 @@ namespace YoggieEngine {
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
ImGuizmo::BeginFrame();
|
ImGuizmo::BeginFrame();
|
||||||
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::GuiEnd() {
|
void Application::GuiEnd() {
|
||||||
|
|
||||||
ImGui::EndFrame();
|
ImGui::EndFrame();
|
||||||
|
|
||||||
|
|
||||||
@ -76,10 +143,19 @@ namespace YoggieEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::PushLayer(Layer* layer)
|
||||||
|
{
|
||||||
|
AppLayerstack.PushLayer(layer);
|
||||||
|
layer->OnAttach();
|
||||||
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
delete appWindow;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "YoggieEngine.h"
|
#include "YoggieEngine.h"
|
||||||
|
#include "LayerStack.h"
|
||||||
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
@ -17,11 +18,21 @@ namespace YoggieEngine {
|
|||||||
void GuiBegin();
|
void GuiBegin();
|
||||||
void GuiEnd();
|
void GuiEnd();
|
||||||
|
|
||||||
|
void PushLayer(Layer* layer);
|
||||||
|
static Application& Get() { return *Application::instance; }
|
||||||
|
static void HandleKey(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
|
static void HandleMouseButton(GLFWwindow* window, int button, int action, int mods);
|
||||||
|
static void HandleScroll(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
protected:
|
protected:
|
||||||
std::string m_AppName;
|
std::string m_AppName;
|
||||||
NativeWindow appWindow;
|
NativeWindow* appWindow;
|
||||||
friend class ApplicationRuntime;
|
|
||||||
|
LayerStack AppLayerstack;
|
||||||
|
Layer* guiLayer;
|
||||||
|
static Application* instance ;
|
||||||
|
|
||||||
|
friend class ImGuiLayer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,102 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "ModelImporter.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
SceneObject* ModelImporter::Import(const std::string path)
|
|
||||||
{
|
|
||||||
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
|
||||||
|
|
||||||
Assimp::Importer importer;
|
|
||||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
|
||||||
|
|
||||||
aiNode* currentNode = scene->mRootNode;
|
|
||||||
|
|
||||||
std::vector<Mesh> meshes = processNode(currentNode, scene);
|
|
||||||
|
|
||||||
std::cout << "[DEBUG]: Loaded " << meshes.size() << " meshes!" << std::endl;
|
|
||||||
|
|
||||||
// create a renderable (per mesh ?? )
|
|
||||||
root->renderable = new Renderable();
|
|
||||||
root->renderable->mesh = new Mesh(meshes[0]);
|
|
||||||
|
|
||||||
return root;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::vector<Mesh> meshes;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
|
||||||
meshes.push_back(processMesh(mesh, scene));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
|
||||||
auto m2 = processNode(node->mChildren[i], scene);
|
|
||||||
|
|
||||||
for (auto m : m2) {
|
|
||||||
meshes.push_back(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return meshes;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
|
||||||
std::vector<unsigned int> indices;
|
|
||||||
std::vector<Vertex> vertices;
|
|
||||||
|
|
||||||
ProcessVertices(mesh, vertices);
|
|
||||||
|
|
||||||
ProcessIndices(mesh, indices);
|
|
||||||
|
|
||||||
Mesh result;
|
|
||||||
result.vertices = vertices;
|
|
||||||
result.elements = indices;
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices) {
|
|
||||||
// Process vertices
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
|
||||||
Vertex v{};
|
|
||||||
glm::vec3 vector;
|
|
||||||
vector.x = mesh->mVertices[i].x;
|
|
||||||
vector.y = mesh->mVertices[i].y;
|
|
||||||
vector.z = mesh->mVertices[i].z;
|
|
||||||
|
|
||||||
v.vertices = vector;
|
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0]) {
|
|
||||||
|
|
||||||
glm::vec2 texCoord;
|
|
||||||
|
|
||||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
|
||||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
|
||||||
|
|
||||||
v.uv = texCoord;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
out_vertices.push_back(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
|
||||||
// Process Indices
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
|
||||||
aiFace face = mesh->mFaces[i];
|
|
||||||
if (face.mNumIndices < 3)
|
|
||||||
continue;
|
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
|
||||||
out_indices.push_back(face.mIndices[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../Graphics/Primitives/Mesh.h"
|
|
||||||
#include <assimp/Importer.hpp>
|
|
||||||
#include <assimp/scene.h>
|
|
||||||
#include <assimp/postprocess.h>
|
|
||||||
#include <string>
|
|
||||||
#include "../Scene/TransformTree/SceneNodeTypes.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
|
||||||
void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices);
|
|
||||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
|
||||||
|
|
||||||
class ModelImporter {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
SceneObject* Import(const std::string path);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
|
|
||||||
static std::vector<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
22
YoggieEngine/src/Assets/Asset.h
Normal file
22
YoggieEngine/src/Assets/Asset.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "uuid.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef uuid::v4::UUID AssetHandle;
|
||||||
|
|
||||||
|
|
||||||
|
enum class AssetType {
|
||||||
|
Unknown = -1,
|
||||||
|
Mesh,
|
||||||
|
Texture,
|
||||||
|
Material,
|
||||||
|
Shader
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Asset {
|
||||||
|
AssetHandle Handle;
|
||||||
|
|
||||||
|
template<class T >
|
||||||
|
static AssetType GetType(T t) { return t.GetType(); }
|
||||||
|
virtual AssetType GetType() { return AssetType::Unknown; }
|
||||||
|
};
|
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
143
YoggieEngine/src/Assets/AssetImporter.cpp
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
#include <YoggieEngine.h>
|
||||||
|
#include "AssetImporter.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<YoggieEngine::Vertex>& out_vertices) {
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
|
YoggieEngine::Vertex v{};
|
||||||
|
|
||||||
|
glm::vec3 vector{};
|
||||||
|
vector.x = mesh->mVertices[i].x;
|
||||||
|
vector.y = mesh->mVertices[i].y;
|
||||||
|
vector.z = mesh->mVertices[i].z;
|
||||||
|
|
||||||
|
v.vertices = vector;
|
||||||
|
|
||||||
|
if (mesh->mTextureCoords[0]) {
|
||||||
|
glm::vec2 texCoord{};
|
||||||
|
|
||||||
|
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||||
|
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||||
|
|
||||||
|
v.uv = texCoord;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
out_vertices.push_back(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
|
if (face.mNumIndices < 3)
|
||||||
|
continue;
|
||||||
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
|
out_indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
YoggieEngine::Mesh processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
|
std::vector<unsigned int> indices;
|
||||||
|
std::vector<YoggieEngine::Vertex> vertices;
|
||||||
|
|
||||||
|
ProcessVertices(mesh, vertices);
|
||||||
|
ProcessIndices(mesh, indices);
|
||||||
|
|
||||||
|
YoggieEngine::Mesh result;
|
||||||
|
result.vertices = vertices;
|
||||||
|
result.elements = indices;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<YoggieEngine::Mesh> processNode(aiNode* node, const aiScene* scene) {
|
||||||
|
|
||||||
|
std::vector<YoggieEngine::Mesh> meshes = std::vector<YoggieEngine::Mesh>();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||||
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
|
meshes.push_back(processMesh(mesh, scene));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||||
|
auto m2 = processNode(node->mChildren[i], scene);
|
||||||
|
|
||||||
|
for (auto m : m2) {
|
||||||
|
meshes.push_back(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return meshes;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadModelFile(std::filesystem::path path) {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene* scene = importer.ReadFile(path.string(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
auto meshes = processNode(currentNode, scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSupportedImageFormat(const std::string& extension) {
|
||||||
|
static std::vector<std::string> supported_image_extensions = { "jpeg", "jpg", "png","bmp","hdr","psd","tga","gif","pic","psd","pgm","ppm" };
|
||||||
|
|
||||||
|
for (auto support_extension : supported_image_extensions) {
|
||||||
|
if (extension == support_extension)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Asset AssetImporter::ImportAsset(AssetMetadata& metadata) {
|
||||||
|
|
||||||
|
static Asset emptyAsset;
|
||||||
|
|
||||||
|
|
||||||
|
// Check file extension so we can choose our loader
|
||||||
|
if (metadata.filepath.has_extension() == true)
|
||||||
|
{
|
||||||
|
spdlog::error("Asset file has no extension!");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto extension = metadata.filepath.extension().string();
|
||||||
|
|
||||||
|
// Handle as Model file
|
||||||
|
bool IsSupportedModelFile = importer.IsExtensionSupported(extension);
|
||||||
|
if (IsSupportedModelFile) {
|
||||||
|
LoadModelFile(metadata.filepath);
|
||||||
|
return emptyAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Handle as Texture
|
||||||
|
if (IsSupportedImageFormat(extension))
|
||||||
|
{
|
||||||
|
Texture texture;
|
||||||
|
texture.Load(metadata.filepath.string());
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle as shader
|
||||||
|
if (extension == "glsl" || extension == "vert" || extension == "frag") {
|
||||||
|
//Shader shader;
|
||||||
|
//shader.
|
||||||
|
return emptyAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return emptyAsset;
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
12
YoggieEngine/src/Assets/AssetImporter.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "AssetMetadata.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
namespace YoggieEngine{
|
||||||
|
class AssetImporter {
|
||||||
|
public:
|
||||||
|
static Asset ImportAsset(AssetMetadata& metadata);
|
||||||
|
private:
|
||||||
|
static Assimp::Importer importer;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
16
YoggieEngine/src/Assets/AssetManager.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <map>
|
||||||
|
#include "AssetMetaData.h"
|
||||||
|
|
||||||
|
typedef std::map<AssetHandle, AssetMetadata> AssetRegistry;
|
||||||
|
|
||||||
|
class AssetManager {
|
||||||
|
public:
|
||||||
|
virtual Asset& GetAsset(AssetHandle handle) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AssetRegistry Assets;
|
||||||
|
std::map<AssetHandle, Asset> LoadedAssets;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
41
YoggieEngine/src/Assets/AssetManagerEditor.cpp
Normal file
41
YoggieEngine/src/Assets/AssetManagerEditor.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "YoggieEngine.h"
|
||||||
|
#include "AssetManagerEditor.h"
|
||||||
|
#include "AssetImporter.h"
|
||||||
|
using namespace YoggieEngine;
|
||||||
|
|
||||||
|
Asset& AssetManagerEditor::GetAsset(AssetHandle handle)
|
||||||
|
{
|
||||||
|
static Asset EmptyAsset{};
|
||||||
|
|
||||||
|
// 1. Check if handle is valid
|
||||||
|
if (IsAssetHandleValid(handle) == false)
|
||||||
|
return EmptyAsset;
|
||||||
|
|
||||||
|
// 2. check if asset needs loading
|
||||||
|
Asset asset;
|
||||||
|
if (IsAssetLoaded(handle)) {
|
||||||
|
asset = LoadedAssets.at(handle);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Load asset
|
||||||
|
// Get MetaData
|
||||||
|
//auto& metadata = Assets[handle];
|
||||||
|
|
||||||
|
// Load Asset
|
||||||
|
//asset = AssetImporter::ImportAsset(metadata);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. return asset.
|
||||||
|
return asset;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManagerEditor::IsAssetHandleValid(AssetHandle handle)
|
||||||
|
{
|
||||||
|
return Assets.find(handle) != Assets.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManagerEditor::IsAssetLoaded(AssetHandle handle ) {
|
||||||
|
return LoadedAssets.find(handle) != LoadedAssets.end();
|
||||||
|
}
|
11
YoggieEngine/src/Assets/AssetManagerEditor.h
Normal file
11
YoggieEngine/src/Assets/AssetManagerEditor.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "AssetManager.h"
|
||||||
|
|
||||||
|
class AssetManagerEditor : public AssetManager {
|
||||||
|
public:
|
||||||
|
Asset& GetAsset(AssetHandle handle) override;
|
||||||
|
private:
|
||||||
|
bool IsAssetHandleValid(AssetHandle handle);
|
||||||
|
bool IsAssetLoaded(AssetHandle handle);
|
||||||
|
|
||||||
|
};
|
7
YoggieEngine/src/Assets/AssetMetadata.h
Normal file
7
YoggieEngine/src/Assets/AssetMetadata.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <filesystem>
|
||||||
|
#include "Asset.h"
|
||||||
|
struct AssetMetadata{
|
||||||
|
AssetHandle handle;
|
||||||
|
std::filesystem::path filepath;
|
||||||
|
};
|
72
YoggieEngine/src/Assets/uuid.h
Normal file
72
YoggieEngine/src/Assets/uuid.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* SOURCE: https://github.com/rkg82/uuid-v4/blob/main/uuid/v4/uuid.h
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef __UUID__
|
||||||
|
#define __UUID__
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace uuid::v4
|
||||||
|
{
|
||||||
|
// Encaasulate the genaeration of a Version 4 UUID object
|
||||||
|
// A Version 4 UUID is a universally unique identifier that is generated using random numbers.
|
||||||
|
class UUID
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UUID() {}
|
||||||
|
// I need a better UUID class that will work as a key in std::map
|
||||||
|
// because this won't properly work
|
||||||
|
|
||||||
|
bool operator() (const UUID& lhs, const UUID& rhs) const {
|
||||||
|
return 1==1;
|
||||||
|
}
|
||||||
|
bool operator< (const UUID& rhs)const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// method for creating UUID object.
|
||||||
|
void generate ()
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 engine{ rd() };
|
||||||
|
std::uniform_int_distribution<int> dist{ 0, 256 }; //Limits of the interval
|
||||||
|
|
||||||
|
for (int index = 0; index < 16; ++index)
|
||||||
|
{
|
||||||
|
_data[index] = (unsigned char)dist(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
_data[6] = ((_data[6] & 0x0f) | 0x40); // Version 4
|
||||||
|
_data[8] = ((_data[8] & 0x3f) | 0x80); // Variant is 10
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns UUID as formatted string
|
||||||
|
std::string String()
|
||||||
|
{
|
||||||
|
// Formats to "0065e7d7-418c-4da4-b4d6-b54b6cf7466a"
|
||||||
|
char buffer[256] = { 0 };
|
||||||
|
std::snprintf(buffer, 255,
|
||||||
|
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||||
|
_data[0], _data[1], _data[2], _data[3],
|
||||||
|
_data[4], _data[5],
|
||||||
|
_data[6], _data[7],
|
||||||
|
_data[8], _data[9],
|
||||||
|
_data[10], _data[11], _data[12], _data[13], _data[14], _data[15]);
|
||||||
|
|
||||||
|
std::string uuid = buffer;
|
||||||
|
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned char _data[16] = { 0 };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // #ifndef __UUID__
|
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
struct Event
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string name;
|
|
||||||
int argc;
|
|
||||||
void** argv;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "EventEmitter.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
void EventEmitter::Subscribe(EventListener& subscriber)
|
|
||||||
{
|
|
||||||
subscribers.push_back(&subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventEmitter::Unsubscribe(EventListener& subscriber)
|
|
||||||
{
|
|
||||||
subscribers.remove(&subscriber);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventEmitter::EmitEvent(Event& incident)
|
|
||||||
{
|
|
||||||
// Notify all subscribers an event has taken place
|
|
||||||
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
|
|
||||||
{
|
|
||||||
(*it)->ReceiveEvent(incident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EventEmitter::EventEmitter() {
|
|
||||||
subscribers = std::list<EventListener*>{};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace YoggieEngine{
|
|
||||||
class EventEmitter {
|
|
||||||
public:
|
|
||||||
void Subscribe(EventListener& subscriber);
|
|
||||||
void Unsubscribe(EventListener& subscriber);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::list<EventListener*> subscribers;
|
|
||||||
void EmitEvent(Event& incident);
|
|
||||||
|
|
||||||
EventEmitter();
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Event.h"
|
|
||||||
namespace YoggieEngine {
|
|
||||||
class EventListener {
|
|
||||||
public:
|
|
||||||
virtual void ReceiveEvent(Event& incident) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
42
YoggieEngine/src/Graphics/Camera.h
Normal file
42
YoggieEngine/src/Graphics/Camera.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
class Camera {
|
||||||
|
public:
|
||||||
|
Camera() {
|
||||||
|
projection = glm::perspective(glm::radians(90.0f), 800.0f / 600.0f, 0.001f, 1000.0f);
|
||||||
|
//projection[3][1] *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 getTransform() const {
|
||||||
|
|
||||||
|
auto transform = glm::translate(glm::mat4(1.0f), Position)
|
||||||
|
* glm::toMat4(glm::quat(Rotation))
|
||||||
|
* glm::scale(glm::mat4(1.0f), glm::vec3(1.0f));
|
||||||
|
|
||||||
|
return glm::inverse(transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4& getProjection(float width, float height) {
|
||||||
|
|
||||||
|
//projection[3][1] *= -1;
|
||||||
|
|
||||||
|
return projection;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Position = glm::vec3(0.0f);
|
||||||
|
glm::vec3 Rotation = glm::vec3(0.0f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
glm::mat4 view;
|
||||||
|
glm::mat4 projection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
60
YoggieEngine/src/Graphics/OpenglAPI.cpp
Normal file
60
YoggieEngine/src/Graphics/OpenglAPI.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <YoggieEngine.h>
|
||||||
|
#include "OpenglAPI.h"
|
||||||
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
GLenum glCheckError_(const char* file, int line) {
|
||||||
|
GLenum errorCode;
|
||||||
|
while ((errorCode = glGetError()) != GL_NO_ERROR) {
|
||||||
|
std::string error;
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case GL_INVALID_ENUM: error = "INVALID_ENUM"; break;
|
||||||
|
case GL_INVALID_VALUE: error = "INVALID_VALUE"; break;
|
||||||
|
case GL_INVALID_OPERATION: error = "INVALID_OPERATION"; break;
|
||||||
|
case GL_STACK_OVERFLOW: error = "STACK_OVERFLOW"; break;
|
||||||
|
case GL_STACK_UNDERFLOW: error = "STACK_UNDERFLOW"; break;
|
||||||
|
case GL_OUT_OF_MEMORY: error = "OUT_OF_MEMORY"; break;
|
||||||
|
case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break;
|
||||||
|
};
|
||||||
|
spdlog::error("{0} | {1} ({2})", error, file, line);
|
||||||
|
}
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define glCheckError() glCheckError_(__FILE__, __LINE__)
|
||||||
|
#else
|
||||||
|
#define glCheckError()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void OpenGLApi::DrawTriangles(Render3DComponent rc) {
|
||||||
|
|
||||||
|
glBindVertexArray(rc.VAO);
|
||||||
|
glCheckError();
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rc.IBO);
|
||||||
|
glCheckError();
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int> (rc.mesh.elements.size()), GL_UNSIGNED_INT, 0);
|
||||||
|
glCheckError();
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void OpenGLApi::DrawCubeMap(unsigned int VertexAttributeObject, CubeMap CubeTexture) {
|
||||||
|
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeTexture.getID());
|
||||||
|
//glCheckError(); // INVALID ENUM FOR SOME REASON
|
||||||
|
glBindVertexArray(VertexAttributeObject);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
//glCheckError();
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
9
YoggieEngine/src/Graphics/OpenglAPI.h
Normal file
9
YoggieEngine/src/Graphics/OpenglAPI.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
namespace YoggieEngine {
|
||||||
|
class OpenGLApi {
|
||||||
|
public:
|
||||||
|
static void DrawTriangles(Render3DComponent rc);
|
||||||
|
|
||||||
|
static void DrawCubeMap(unsigned int VertexAttributeObject, CubeMap CubeTexture);
|
||||||
|
};
|
||||||
|
};
|
@ -1,46 +0,0 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "Camera.h"
|
|
||||||
namespace YoggieEngine {
|
|
||||||
Camera::Camera(const Camera& other)
|
|
||||||
: Position(other.Position), Rotation(other.Rotation), Zoom(other.Zoom)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
|
|
||||||
: Position(position), Rotation( rotation)
|
|
||||||
{
|
|
||||||
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
|
||||||
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
|
||||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
Zoom = zoom;
|
|
||||||
|
|
||||||
ProjectionMatrix = glm::perspective(glm::radians(Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
|
||||||
Update();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera::~Camera() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Camera::Update() {
|
|
||||||
glm::vec3 WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
|
||||||
|
|
||||||
glm::vec3(direction);
|
|
||||||
|
|
||||||
|
|
||||||
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
|
||||||
direction.z = sin(glm::radians(yaw));
|
|
||||||
direction.y = sin(glm::radians(pitch)) * cos(glm::radians(pitch));
|
|
||||||
Front = glm::normalize(direction);
|
|
||||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
|
||||||
Up = glm::normalize(glm::cross(Right, Front));
|
|
||||||
|
|
||||||
|
|
||||||
ViewMatrix = glm::lookAt(
|
|
||||||
Position,
|
|
||||||
Position + Front,
|
|
||||||
Up);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
class Camera {
|
|
||||||
public:
|
|
||||||
|
|
||||||
Camera() = default;
|
|
||||||
Camera(const Camera& other);
|
|
||||||
Camera(glm::vec3 position, glm::vec3 rotation, float zoom);
|
|
||||||
~Camera();
|
|
||||||
|
|
||||||
void Update();
|
|
||||||
|
|
||||||
|
|
||||||
float yaw = 180;
|
|
||||||
float pitch = 0;
|
|
||||||
float Zoom;
|
|
||||||
|
|
||||||
glm::mat4 ViewMatrix;
|
|
||||||
glm::mat4 ProjectionMatrix;
|
|
||||||
|
|
||||||
glm::vec3 Position;
|
|
||||||
glm::vec3 Rotation;
|
|
||||||
|
|
||||||
glm::vec3 Front;
|
|
||||||
glm::vec3 Right;
|
|
||||||
glm::vec3 Up;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
class Texture {
|
|
||||||
public:
|
|
||||||
Texture() = default;
|
|
||||||
Texture(const std::string texturePath, bool Transparency = false);
|
|
||||||
|
|
||||||
void Bind();
|
|
||||||
void Unbind();
|
|
||||||
const unsigned int GetID() const { return Id; }
|
|
||||||
private:
|
|
||||||
unsigned int Id;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Graphics/Memory/Buffer.h"
|
#include "../Graphics/Buffer.h"
|
||||||
#include "../Graphics/Memory/VertexArray.h"
|
#include "../Graphics/VertexArray.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace YoggieEngine {
|
|
||||||
|
|
||||||
struct Renderable {
|
|
||||||
Mesh* mesh;
|
|
||||||
Material* material;
|
|
||||||
Texture* texture;
|
|
||||||
};
|
|
||||||
}
|
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "../Scene/Components.h"
|
#include "../Scene/Components.h"
|
||||||
#include "../Graphics/Memory/Buffer.h"
|
#include "../Graphics/Buffer.h"
|
||||||
#include "../Graphics/Memory/VertexArray.h"
|
#include "../Graphics/VertexArray.h"
|
||||||
#include "../Graphics/Primitives/DrawCommand.h"
|
#include "Framebuffer.h"
|
||||||
|
#include "../Scene/Components.h"
|
||||||
|
#include"../Scene/Scene.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
#include "OpenglAPI.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
unsigned int quadVAO = 0;
|
unsigned int quadVAO = 0;
|
||||||
@ -65,24 +69,41 @@ float skyboxVertices[]{
|
|||||||
1.0f, -1.0f, 1.0f
|
1.0f, -1.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderer::Renderer(RendererConfig& config)
|
|
||||||
: m_framebuffer(Framebuffer(config.ScreenWidth, config.ScreenHeight)),
|
Renderer::Renderer() :
|
||||||
|
m_framebuffer(800, 600),
|
||||||
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
||||||
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
||||||
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
||||||
BlendingShader("build/Debug/Shaders/forward/Blending.vert", "build/Debug/Shaders/forward/Blending.frag"),
|
BlendingShader("build/Debug/Shaders/forward/Blending.vert", "build/Debug/Shaders/forward/Blending.frag"),
|
||||||
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag")
|
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"),
|
||||||
{
|
postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag")
|
||||||
width = config.ScreenWidth;
|
{
|
||||||
height = config.ScreenHeight;
|
width = 800;
|
||||||
|
height = 600;
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
CreateGBuffer();
|
||||||
|
|
||||||
|
std::vector<std::string> faces{
|
||||||
|
"build/Debug/skybox/Open_Water/right.jpg",
|
||||||
|
"build/Debug/skybox/Open_Water/left.jpg",
|
||||||
|
"build/Debug/skybox/Open_Water/top.jpg",
|
||||||
|
"build/Debug/skybox/Open_Water/bottom.jpg",
|
||||||
|
"build/Debug/skybox/Open_Water/front.jpg",
|
||||||
|
"build/Debug/skybox/Open_Water/back.jpg"
|
||||||
|
};
|
||||||
|
|
||||||
|
skybox = CubeMap(faces);
|
||||||
|
grassTexture.Load("build/Debug/Texture/grass.png");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Renderer::CreateGBuffer() {
|
||||||
// Deferred Rendering
|
// Deferred Rendering
|
||||||
glGenFramebuffers(1, &gBuffer);
|
glGenFramebuffers(1, &gBuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||||
|
|
||||||
// - Position Color Buffer ;
|
// - Position Color Buffer ;
|
||||||
glGenTextures(1, &gPosition);
|
glGenTextures(1, &gPosition);
|
||||||
glBindTexture(GL_TEXTURE_2D, gPosition);
|
glBindTexture(GL_TEXTURE_2D, gPosition);
|
||||||
@ -122,55 +143,139 @@ Renderer::Renderer(RendererConfig& config)
|
|||||||
spdlog::critical("Framebuffer not complete {}{}", __FILE__, __LINE__);
|
spdlog::critical("Framebuffer not complete {}{}", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
std::vector<std::string> faces{
|
|
||||||
"build/Debug/skybox/Open_Water/right.jpg",
|
|
||||||
"build/Debug/skybox/Open_Water/left.jpg",
|
|
||||||
"build/Debug/skybox/Open_Water/top.jpg",
|
|
||||||
"build/Debug/skybox/Open_Water/bottom.jpg",
|
|
||||||
"build/Debug/skybox/Open_Water/front.jpg",
|
|
||||||
"build/Debug/skybox/Open_Water/back.jpg"
|
|
||||||
};
|
|
||||||
|
|
||||||
sky = CubeMap(faces);
|
|
||||||
|
|
||||||
// Create a skybox vao
|
|
||||||
unsigned int VBO;
|
|
||||||
glGenVertexArrays(1, &skyboxVAO);
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindVertexArray(skyboxVAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
|
||||||
|
|
||||||
#ifdef WINDOW
|
|
||||||
grassTexture = Texture("build/Debug/Texture/blending_transparent_window.png", true);
|
|
||||||
#else
|
|
||||||
grassTexture = Texture("build/Debug/Texture/grass.png", true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer(){}
|
|
||||||
|
|
||||||
void SubmitVegetationDemo() {
|
void Renderer::Render(Scene& scene , Camera MainCamera){
|
||||||
|
int oldviewport[4];
|
||||||
|
glGetIntegerv(GL_VIEWPORT, oldviewport);
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Render skybox if the scene has one
|
||||||
|
|
||||||
|
SkyboxShader.Use();
|
||||||
|
SkyboxShader.setUniformMat4("projection", MainCamera.getProjection(width, height));
|
||||||
|
SkyboxShader.setUniformMat4("view", glm::inverse(glm::mat4(glm::mat3(MainCamera.getTransform()))));
|
||||||
|
|
||||||
|
if (!skyboxVAO) {
|
||||||
|
unsigned int VBO;
|
||||||
|
glGenVertexArrays(1, &skyboxVAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindVertexArray(skyboxVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenGLApi::DrawCubeMap(skyboxVAO, skybox);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
auto renderables = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||||
|
gBufferShader.Use();
|
||||||
|
for (auto renderable : renderables) {
|
||||||
|
auto entity = Entity(renderable, &scene);
|
||||||
|
auto& renderComponent = entity.GetComponent<Render3DComponent>();
|
||||||
|
auto& transform = entity.GetComponent<TransformComponent>();
|
||||||
|
|
||||||
|
// Geometry pass
|
||||||
|
gBufferShader.setUniformVec3("Color", renderComponent.color);
|
||||||
|
gBufferShader.setUniformMat4("Model", transform.GetTransform());
|
||||||
|
gBufferShader.setUniformMat4("View", glm::inverse(MainCamera.getTransform()));
|
||||||
|
gBufferShader.setUniformMat4("Projection", MainCamera.getProjection(width, height));
|
||||||
|
OpenGLApi::DrawTriangles(renderComponent);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light pass
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||||
|
lightingPassShader.Use();
|
||||||
|
lightingPassShader.setUniformInt("gPosition", 0);
|
||||||
|
lightingPassShader.setUniformInt("gNormal", 1);
|
||||||
|
lightingPassShader.setUniformInt("gColorSpec", 2);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gPosition);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gNormal);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE2);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, gColorSpec);
|
||||||
|
|
||||||
|
auto lights = scene.getReg().view<LightComponent, TransformComponent>();
|
||||||
|
unsigned int lightnr = 0;
|
||||||
|
for (auto light : lights) {
|
||||||
|
auto lightComponent = Entity(light, &scene).GetComponent<LightComponent>();
|
||||||
|
auto transformComponent = Entity(light, &scene).GetComponent<TransformComponent>();
|
||||||
|
|
||||||
|
auto name = "lights[" + std::to_string(lightnr) + "]";
|
||||||
|
lightingPassShader.setUniformVec3(name + ".Position", transformComponent.Position);
|
||||||
|
lightingPassShader.setUniformVec3(name + ".Color", lightComponent.Color);
|
||||||
|
|
||||||
|
const float linear = 0.7f;
|
||||||
|
const float quadratic = 1.8f;
|
||||||
|
lightingPassShader.setUniformFloat(name + ".Linear", linear);
|
||||||
|
lightingPassShader.setUniformFloat(name + ".Quadratic", quadratic);
|
||||||
|
|
||||||
|
lightnr++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quadVAO == 0)
|
||||||
|
{
|
||||||
|
float quadVertices[] = {
|
||||||
|
-1.0f, 1.0f, 0.0f, 0.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 1.0f, 0.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
};
|
||||||
|
unsigned int quadVBO;
|
||||||
|
// setup plane VAO ;
|
||||||
|
glGenVertexArrays(1, &quadVAO);
|
||||||
|
glGenBuffers(1, &quadVBO);
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
|
// Copy GBuffer
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||||
|
glBindFramebuffer(GL_DRAW_BUFFER, m_framebuffer.GetId());
|
||||||
|
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||||
|
|
||||||
|
|
||||||
if (transparentVAO == 0) {
|
if (transparentVAO == 0) {
|
||||||
|
unsigned int transparentVBO;
|
||||||
float transparentVertices[] = {
|
float transparentVertices[] = {
|
||||||
// positions // texture Coords (swapped y coordinates because texture is flipped upside down)
|
// positions // texture Coords
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.0f, -0.5f, 0.0f, 0.0f, 1.0f,
|
0.0f, -0.5f, 0.0f, 0.0f, 0.0f,
|
||||||
1.0f, -0.5f, 0.0f, 1.0f, 1.0f,
|
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
1.0f, -0.5f, 0.0f, 1.0f, 1.0f,
|
1.0f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
1.0f, 0.5f, 0.0f, 1.0f, 0.0f
|
1.0f, 0.5f, 0.0f, 1.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
glGenVertexArrays(1, &transparentVAO);
|
glGenVertexArrays(1, &transparentVAO);
|
||||||
@ -186,247 +291,43 @@ void SubmitVegetationDemo() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& transform) {
|
|
||||||
if (renderComponent.VAO == 0 || renderComponent.IBO == 0)
|
|
||||||
{
|
|
||||||
if (renderComponent.VAO != 0)
|
|
||||||
glDeleteVertexArrays(1, &(renderComponent.VAO));
|
|
||||||
if (renderComponent.IBO != 0)
|
|
||||||
glDeleteBuffers(1, &(renderComponent.IBO));
|
|
||||||
|
|
||||||
VertexArray va = VertexArray();
|
|
||||||
Buffer vertexBuffer = Buffer();
|
|
||||||
Buffer elementBuffer = Buffer();
|
|
||||||
|
|
||||||
va.Create();
|
|
||||||
va.Bind();
|
|
||||||
|
|
||||||
vertexBuffer.createBuffer();
|
|
||||||
vertexBuffer.Bind(false);
|
|
||||||
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(Vertex), false);
|
|
||||||
|
|
||||||
elementBuffer.createBuffer();
|
|
||||||
elementBuffer.Bind(true);
|
|
||||||
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
|
|
||||||
|
|
||||||
va.AttachAttribute(0, 3, sizeof(Vertex));
|
|
||||||
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
va.Unbind();
|
|
||||||
vertexBuffer.Unbind(false);
|
|
||||||
elementBuffer.Unbind(true);
|
|
||||||
|
|
||||||
renderComponent.VAO = va.getID();
|
|
||||||
renderComponent.IBO = elementBuffer.getBufferID();
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawCommand dc = { renderComponent.isStatic , renderComponent.VAO, renderComponent.mesh.elements.size(), renderComponent.IBO, transform, renderComponent.color };
|
|
||||||
commands.push_back(dc);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::GeometryPass() {
|
|
||||||
// 1.0 Geometry pass
|
|
||||||
gBufferShader.Use();
|
|
||||||
|
|
||||||
for (const DrawCommand& command : commands)
|
|
||||||
{
|
|
||||||
if (command.isDynamic == true)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
glBindVertexArray(command.VAO_identifier);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
|
||||||
|
|
||||||
gBufferShader.setUniformVec3("Color", command.color);
|
|
||||||
gBufferShader.setUniformMat4("Model", command.transform.LocalTransform);
|
|
||||||
gBufferShader.setUniformMat4("View", MainCamera.ViewMatrix);
|
|
||||||
gBufferShader.setUniformMat4("Projection", MainCamera.ProjectionMatrix);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
|
||||||
GL_UNSIGNED_INT, NULL);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SkyboxPass() {
|
|
||||||
// Render skybox
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
SkyboxShader.Use();
|
|
||||||
SkyboxShader.setUniformMat4("projection", MainCamera.ProjectionMatrix);
|
|
||||||
SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.ViewMatrix))); // remove rotation from the view matrix
|
|
||||||
glBindVertexArray(skyboxVAO);
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::lightingPass(Scene& scene){
|
|
||||||
|
|
||||||
// 2.0 Lighting Pass
|
|
||||||
|
|
||||||
// configure shader
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
|
|
||||||
lightingPassShader.Use();
|
|
||||||
lightingPassShader.setUniformInt("gPosition", 0);
|
|
||||||
lightingPassShader.setUniformInt("gNormal", 1);
|
|
||||||
lightingPassShader.setUniformInt("gColorSpec", 2);
|
|
||||||
|
|
||||||
// Bind all Gbuffer textures
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gPosition);
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gNormal);
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, gColorSpec);
|
|
||||||
|
|
||||||
// send relevant Lighting Uniforms
|
|
||||||
auto lights = scene.getReg().view<LightComponent, TransformComponent>();
|
|
||||||
unsigned int lightnr = 0;
|
|
||||||
lights.each([&](auto entity, LightComponent& light, TransformComponent& transform) {
|
|
||||||
lightingPassShader.setUniformVec3("lights[" + std::to_string(lightnr) + "].Position", transform.Position);
|
|
||||||
lightingPassShader.setUniformVec3("lights[" + std::to_string(lightnr) + "].Color", light.Color);
|
|
||||||
|
|
||||||
// Attenuation
|
|
||||||
const float linear = 0.7f;
|
|
||||||
const float quadratic = 1.8f;
|
|
||||||
lightingPassShader.setUniformFloat("lights[" + std::to_string(lightnr) + "].Linear", linear);
|
|
||||||
lightingPassShader.setUniformFloat("lights[" + std::to_string(lightnr) + "].Quadratic", quadratic);
|
|
||||||
|
|
||||||
|
|
||||||
lightnr++;
|
|
||||||
});
|
|
||||||
|
|
||||||
lightingPassShader.setUniformVec3("viewPos", MainCamera.Position);
|
|
||||||
|
|
||||||
// render to quad
|
|
||||||
if (quadVAO == 0)
|
|
||||||
{
|
|
||||||
float quadVertices[] = {
|
|
||||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
};
|
|
||||||
// setup plane VAO ;
|
|
||||||
glGenVertexArrays(1, &quadVAO);
|
|
||||||
glGenBuffers(1, &quadVBO);
|
|
||||||
glBindVertexArray(quadVAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glBindVertexArray(quadVAO);
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::BlendingPass() {
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Vegetation / blending test;
|
|
||||||
BlendingShader.Use();
|
BlendingShader.Use();
|
||||||
glBindVertexArray(transparentVAO);
|
glBindVertexArray(transparentVAO);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
||||||
|
|
||||||
BlendingShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
BlendingShader.setUniformMat4("V", glm::inverse(MainCamera.getTransform()));
|
||||||
BlendingShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
BlendingShader.setUniformMat4("P", MainCamera.getProjection(width, height));
|
||||||
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
||||||
auto rotation = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]);
|
auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]);
|
||||||
auto transform = translation * rotation;
|
BlendingShader.setUniformMat4("M", translation);
|
||||||
BlendingShader.setUniformMat4("M", transform);
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Render(Scene& scene)
|
|
||||||
{
|
|
||||||
SubmitVegetationDemo();
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
SkyboxPass();
|
|
||||||
|
|
||||||
GeometryPass();
|
|
||||||
|
|
||||||
lightingPass(scene);
|
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
|
||||||
|
|
||||||
// Forward rendering approach
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
|
|
||||||
for (const DrawCommand& command : commands)
|
|
||||||
{
|
|
||||||
if (command.isDynamic == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
glBindVertexArray(command.VAO_identifier);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
|
||||||
|
|
||||||
forwardShader.Use();
|
|
||||||
|
|
||||||
forwardShader.setUniformVec3("Color", command.color);
|
|
||||||
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
|
||||||
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
|
||||||
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
|
||||||
GL_UNSIGNED_INT, NULL);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
BlendingPass();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Lighting pass
|
|
||||||
/*
|
|
||||||
auto lights = scene.getReg().view<LightComponent>();
|
|
||||||
lights.each([&](auto entity, LightComponent& light) {
|
|
||||||
renderComponent.shader.setUniformVec3("lighting.color", light.Color);
|
|
||||||
renderComponent.shader.setUniformFloat("lighting.strength", light.Strength);
|
|
||||||
});
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
commands.clear();
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
glViewport(oldviewport[0], oldviewport[1], oldviewport[2], oldviewport[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Renderer::~Renderer(){}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Renderer::setCurrentFrameBuffer(const Framebuffer& fb)
|
void Renderer::setCurrentFrameBuffer(const Framebuffer& fb)
|
||||||
{
|
{
|
||||||
m_framebuffer = fb;
|
m_framebuffer = fb;
|
||||||
|
@ -2,13 +2,8 @@
|
|||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../PerfCounter.h"
|
#include "../PerfCounter.h"
|
||||||
|
#include "../Scene/Scene.h"
|
||||||
#include "Renderable.h"
|
#include "Framebuffer.h"
|
||||||
#include "Memory/Framebuffer.h"
|
|
||||||
#include "../Scene/Components.h"
|
|
||||||
#include"../Scene/Scene.h"
|
|
||||||
#include "Graphics/Primitives/DrawCommand.h"
|
|
||||||
#include "Primitives/Camera.h"
|
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
|
|
||||||
@ -20,37 +15,36 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
Renderer(RendererConfig& config);
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
|
|
||||||
void Submit(Render3DComponent& renderComponent, TransformComponent& transform); // Collects DrawCommands
|
// Forward pass
|
||||||
void Render(Scene&); // Draw to screen (using drawCall structs)
|
/*
|
||||||
|
forwardShader.Use();
|
||||||
|
forwardShader.setUniformVec3("Color", renderComponent.color);
|
||||||
|
forwardShader.setUniformMat4("M", transform.LocalTransform);
|
||||||
|
forwardShader.setUniformMat4("V", MainCamera.view);
|
||||||
|
forwardShader.setUniformMat4("P", MainCamera.projection);
|
||||||
|
|
||||||
|
OpenGLApi::DrawTriangles(renderComponent);
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Render(Scene& scene, Camera MainCamera);
|
||||||
|
|
||||||
void setCurrentFrameBuffer(const Framebuffer& fb);
|
void setCurrentFrameBuffer(const Framebuffer& fb);
|
||||||
void setClearColor(const glm::vec3& ClearColor);
|
void setClearColor(const glm::vec3& ClearColor);
|
||||||
|
|
||||||
void SetMainCamera(const Camera& camera) { MainCamera = camera; }
|
|
||||||
|
|
||||||
Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; }
|
Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; }
|
||||||
private:
|
|
||||||
void GeometryPass();
|
|
||||||
void SkyboxPass();
|
|
||||||
void lightingPass(Scene& scene);
|
|
||||||
void BlendingPass();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Framebuffer m_framebuffer;
|
Framebuffer m_framebuffer;
|
||||||
int width, height;
|
int width, height;
|
||||||
glm::vec3 m_clearColor;
|
glm::vec3 m_clearColor;
|
||||||
bool m_depthTest;
|
bool m_depthTest;
|
||||||
std::vector<DrawCommand> commands;
|
|
||||||
Camera MainCamera;
|
|
||||||
|
|
||||||
unsigned int skyboxVAO = 0;
|
void CreateGBuffer();
|
||||||
CubeMap sky;
|
|
||||||
|
|
||||||
Shader forwardShader;
|
Shader forwardShader;
|
||||||
|
|
||||||
@ -59,8 +53,61 @@ namespace YoggieEngine {
|
|||||||
Shader lightingPassShader;
|
Shader lightingPassShader;
|
||||||
Shader gBufferShader;
|
Shader gBufferShader;
|
||||||
Shader SkyboxShader;
|
Shader SkyboxShader;
|
||||||
|
Shader postProcessingShader;
|
||||||
|
|
||||||
// blending
|
// blending
|
||||||
Shader BlendingShader;
|
Shader BlendingShader;
|
||||||
|
CubeMap skybox;
|
||||||
|
Texture grassTexture;
|
||||||
|
|
||||||
|
unsigned int transparentVAO = 0;
|
||||||
|
unsigned int skyboxVAO = 0;
|
||||||
|
unsigned int quadVAO = 0;
|
||||||
|
float skyboxVertices[36*3]{
|
||||||
|
// positions
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f
|
||||||
|
};
|
||||||
|
std::vector<glm::vec3> vegetation = {
|
||||||
|
glm::vec3(-1.5f, 0.0f, -0.48f),
|
||||||
|
glm::vec3(1.5f, 0.0f, 0.51f),
|
||||||
|
glm::vec3(0.0f, 0.0f, 0.7f),
|
||||||
|
glm::vec3(-0.3f, 0.0f, -2.3f)
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Assets/Asset.h"
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
class Shader {
|
class Shader : public Asset{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
char* readFile(const char* filePath);
|
char* readFile(const char* filePath);
|
||||||
|
|
||||||
|
|
||||||
|
AssetType GetType() override{ return AssetType::Shader; }
|
||||||
public:
|
public:
|
||||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||||
|
|
||||||
|
|
||||||
void Use() const;
|
void Use() const;
|
||||||
void setUniformMat4(std::string uniformName, const glm::mat4& matrix4)const;
|
void setUniformMat4(std::string uniformName, const glm::mat4& matrix4)const;
|
||||||
void setUniformVec4(std::string uniformName, const glm::vec4& vector4)const;
|
void setUniformVec4(std::string uniformName, const glm::vec4& vector4)const;
|
@ -2,13 +2,13 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
Texture::Texture(const std::string texturePath , bool Transparency) {
|
|
||||||
int width, height, channels;
|
void Texture::Load(const std::string texturePath, bool Transparency) {
|
||||||
|
int channels;
|
||||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
glGenTextures(1, &Id);
|
glGenTextures(1, &Id);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, Id);
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
@ -22,15 +22,15 @@ namespace YoggieEngine {
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
}
|
}
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spdlog::error("Failed to load image (%s)", texturePath);
|
std::cout << "Failed to load image!" << std::endl;
|
||||||
|
spdlog::error("Failed to load image ({0})", texturePath);
|
||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::Bind() {
|
void Texture::Bind() {
|
22
YoggieEngine/src/Graphics/Texture.h
Normal file
22
YoggieEngine/src/Graphics/Texture.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Assets/Asset.h"
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
class Texture : public Asset {
|
||||||
|
public:
|
||||||
|
Texture() = default;
|
||||||
|
void Load(const std::string texturePath, bool Transparency = false);
|
||||||
|
|
||||||
|
void Bind();
|
||||||
|
void Unbind();
|
||||||
|
const unsigned int GetID() const { return Id; }
|
||||||
|
const ImVec2 getSize() { return {(float)width, (float)height}; }
|
||||||
|
|
||||||
|
AssetType GetType() override { return AssetType::Texture; }
|
||||||
|
private:
|
||||||
|
unsigned int Id;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -17,10 +17,10 @@ namespace YoggieEngine {
|
|||||||
void init_inputSystem(NativeWindow* window) {
|
void init_inputSystem(NativeWindow* window) {
|
||||||
cursor_pos_x = 0;
|
cursor_pos_x = 0;
|
||||||
cursor_pos_y = 0;
|
cursor_pos_y = 0;
|
||||||
glfwSetKeyCallback(window->GetGLFWHandle(), key_callback);
|
glfwSetKeyCallback((GLFWwindow*) window->GetHandle(), key_callback);
|
||||||
glfwSetMouseButtonCallback(window->GetGLFWHandle(), mouseButton_callback);
|
glfwSetMouseButtonCallback((GLFWwindow*)window->GetHandle(), mouseButton_callback);
|
||||||
glfwSetCursorPosCallback(window->GetGLFWHandle(), cursorPos_callback);
|
glfwSetCursorPosCallback((GLFWwindow*)window->GetHandle(), cursorPos_callback);
|
||||||
glfwSetCursorEnterCallback(window->GetGLFWHandle(), cursorEnter_callback);
|
glfwSetCursorEnterCallback((GLFWwindow*)window->GetHandle(), cursorEnter_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReceiveInput() {
|
void ReceiveInput() {
|
||||||
@ -43,13 +43,13 @@ namespace YoggieEngine {
|
|||||||
|
|
||||||
double getCursorPosX(NativeWindow* window)
|
double getCursorPosX(NativeWindow* window)
|
||||||
{
|
{
|
||||||
glfwGetCursorPos(window->GetGLFWHandle(), &cursor_pos_x, nullptr);
|
glfwGetCursorPos((GLFWwindow*)window->GetHandle(), &cursor_pos_x, nullptr);
|
||||||
return cursor_pos_x;
|
return cursor_pos_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getCursorPosY(NativeWindow* window)
|
double getCursorPosY(NativeWindow* window)
|
||||||
{
|
{
|
||||||
glfwGetCursorPos(window->GetGLFWHandle(), nullptr, &cursor_pos_y);
|
glfwGetCursorPos((GLFWwindow*)window->GetHandle(), nullptr, &cursor_pos_y);
|
||||||
return cursor_pos_y;
|
return cursor_pos_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
YoggieEngine/src/Layer.h
Normal file
34
YoggieEngine/src/Layer.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
class Layer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
~Layer() { OnDestroy(); }
|
||||||
|
Layer() { OnCreate(); }
|
||||||
|
|
||||||
|
virtual void OnUpdate(){}
|
||||||
|
virtual void OnUI(){}
|
||||||
|
|
||||||
|
virtual bool OnKey(int key , int status ) {
|
||||||
|
spdlog::info( "Key {0} , {1}", key, status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnMouseButton(int button, int action) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool OnScroll(int xoffset, int yoffset) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnStartup(){}
|
||||||
|
|
||||||
|
virtual void OnAttach() {}
|
||||||
|
virtual void OnDetach() {}
|
||||||
|
virtual void OnCreate() {}
|
||||||
|
virtual void OnDestroy(){}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
27
YoggieEngine/src/LayerStack.cpp
Normal file
27
YoggieEngine/src/LayerStack.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "YoggieEngine.h"
|
||||||
|
#include "LayerStack.h"
|
||||||
|
|
||||||
|
LayerStack::~LayerStack()
|
||||||
|
{
|
||||||
|
for (Layer* layer : layers) {
|
||||||
|
layer->OnDetach();
|
||||||
|
delete layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LayerStack::PushLayer(Layer* layer) {
|
||||||
|
layers.emplace(layers.begin() + insertion_index, layer);
|
||||||
|
insertion_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LayerStack::PopLayer(Layer* layer) {
|
||||||
|
auto it = std::find(layers.begin(), layers.begin() + insertion_index, layer);
|
||||||
|
if (it != layers.begin() + insertion_index) {
|
||||||
|
layer->OnDetach();
|
||||||
|
layers.erase(it);
|
||||||
|
insertion_index--;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
YoggieEngine/src/LayerStack.h
Normal file
22
YoggieEngine/src/LayerStack.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Layer.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class LayerStack{
|
||||||
|
public:
|
||||||
|
LayerStack() = default;
|
||||||
|
~LayerStack();
|
||||||
|
|
||||||
|
void PushLayer(Layer* layer);
|
||||||
|
void PopLayer(Layer* layer);
|
||||||
|
|
||||||
|
std::vector<Layer*>::iterator begin() { return layers.begin(); }
|
||||||
|
std::vector<Layer*>::iterator end() { return layers.end(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rbegin() { return layers.rbegin(); }
|
||||||
|
std::vector<Layer*>::reverse_iterator rend() { return layers.rend(); }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Layer*> layers;
|
||||||
|
int insertion_index = 0;
|
||||||
|
};
|
@ -1,72 +1,67 @@
|
|||||||
#include <YoggieEngine.h>
|
|
||||||
#include "PerfCounter.h"
|
#include "PerfCounter.h"
|
||||||
|
#include <YoggieEngine.h>
|
||||||
|
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
uint64_t EngineInstrumentation::GetPrecisionTime() {
|
uint64_t EngineInstrumentation::GetPrecisionTime() {
|
||||||
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line width
|
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line
|
||||||
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
// width
|
||||||
}
|
return duration_cast<milliseconds>(
|
||||||
|
high_resolution_clock::now().time_since_epoch())
|
||||||
void EngineInstrumentation::PerfomanceSamplerInit() {
|
.count();
|
||||||
|
|
||||||
std::cout << "Initialize perf sampler" << std::endl;
|
|
||||||
/*EngineInstrumentation::frames = 0;
|
|
||||||
EngineInstrumentation::lastSampleTime = GetPrecisionTime();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EngineInstrumentation::Update() {
|
|
||||||
|
|
||||||
/* uint64_t MilliSecondsPast = GetPrecisionTime() - EngineInstrumentation::lastSampleTime;
|
|
||||||
|
|
||||||
if (MilliSecondsPast >= 1000) {
|
|
||||||
|
|
||||||
EngineInstrumentation::frameTime = (float)1000 / EngineInstrumentation::frames;
|
|
||||||
EngineInstrumentation::FPS = frames;
|
|
||||||
EngineInstrumentation::frames = 0;
|
|
||||||
EngineInstrumentation::lastSampleTime = GetPrecisionTime();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void EngineInstrumentation::ShowStats() {
|
|
||||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
|
|
||||||
|
|
||||||
ImGui::Text("Currently not available");
|
|
||||||
/* ImGui::Text("FPS: %i", ES.FPS);
|
|
||||||
ImGui::Text("Frame Time: %f", ES.frameTime);
|
|
||||||
ImGui::Text("Verts: %i", ES.verts);
|
|
||||||
ImGui::Text("Draw Calls: %i", ES.DC);
|
|
||||||
*/
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PerfSampler::PerfSampler(const std::string& name)
|
|
||||||
: name(name)
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
|
||||||
startTime = high_resolution_clock::now();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PerfSampler::~PerfSampler()
|
|
||||||
{
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PerfSampler::Stop()
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
|
||||||
auto end = high_resolution_clock::now();
|
|
||||||
auto durationInuSeconds =
|
|
||||||
duration_cast<nanoseconds>(end.time_since_epoch()).count() -
|
|
||||||
duration_cast<nanoseconds>(startTime.time_since_epoch()).count();
|
|
||||||
|
|
||||||
auto ms = durationInuSeconds * 0.001f;
|
|
||||||
|
|
||||||
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << " us (" << ms << " ms)" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EngineInstrumentation::PerfomanceSamplerInit() {
|
||||||
|
|
||||||
|
spdlog::info("Initialize perf sampler");
|
||||||
|
/*EngineInstrumentation::frames = 0;
|
||||||
|
EngineInstrumentation::lastSampleTime = GetPrecisionTime();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineInstrumentation::Update() {
|
||||||
|
|
||||||
|
/* uint64_t MilliSecondsPast = GetPrecisionTime() -
|
||||||
|
EngineInstrumentation::lastSampleTime;
|
||||||
|
|
||||||
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
|
EngineInstrumentation::frameTime = (float)1000 /
|
||||||
|
EngineInstrumentation::frames; EngineInstrumentation::FPS = frames;
|
||||||
|
EngineInstrumentation::frames = 0;
|
||||||
|
EngineInstrumentation::lastSampleTime =
|
||||||
|
GetPrecisionTime();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineInstrumentation::ShowStats() {
|
||||||
|
// ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse |
|
||||||
|
//ImGuiWindowFlags_NoResize);
|
||||||
|
|
||||||
|
// ImGui::Text("Currently not available");
|
||||||
|
/* ImGui::Text("FPS: %i", ES.FPS);
|
||||||
|
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||||
|
ImGui::Text("Verts: %i", ES.verts);
|
||||||
|
ImGui::Text("Draw Calls: %i", ES.DC);
|
||||||
|
*/
|
||||||
|
// ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
PerfSampler::PerfSampler(const std::string &name) : name(name) {
|
||||||
|
using namespace std::chrono;
|
||||||
|
startTime = high_resolution_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
PerfSampler::~PerfSampler() { Stop(); }
|
||||||
|
|
||||||
|
void PerfSampler::Stop() {
|
||||||
|
using namespace std::chrono;
|
||||||
|
auto end = high_resolution_clock::now();
|
||||||
|
auto durationInuSeconds =
|
||||||
|
duration_cast<nanoseconds>(end.time_since_epoch()).count() -
|
||||||
|
duration_cast<nanoseconds>(startTime.time_since_epoch()).count();
|
||||||
|
|
||||||
|
auto ms = durationInuSeconds * 0.001f;
|
||||||
|
|
||||||
|
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << "
|
||||||
|
//us (" << ms << " ms)" << std::endl;
|
||||||
|
}
|
||||||
|
} // namespace YoggieEngine
|
||||||
|
26
YoggieEngine/src/Platform/Linux/X11Window.cpp
Normal file
26
YoggieEngine/src/Platform/Linux/X11Window.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "YoggieEngine.h"
|
||||||
|
#include "X11Window.h"
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
|
||||||
|
X11Window::X11Window(const int width, const int height, const char* title) : NativeWindow()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Open a display
|
||||||
|
//Display* d = XOpenDisplay(0);
|
||||||
|
|
||||||
|
//if (d) {
|
||||||
|
// // create the window
|
||||||
|
// Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200, 100, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, 0);
|
||||||
|
// // show the window
|
||||||
|
// XMapWindow(d, w);
|
||||||
|
// XFlush(d);
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
32
YoggieEngine/src/Platform/Linux/X11Window.h
Normal file
32
YoggieEngine/src/Platform/Linux/X11Window.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../Window.h"
|
||||||
|
|
||||||
|
//#include <X11/Xlib.h>
|
||||||
|
//#include <unistd.h>
|
||||||
|
|
||||||
|
namespace YoggieEngine {
|
||||||
|
class X11Window : public NativeWindow {
|
||||||
|
public:
|
||||||
|
X11Window(const int width, const int height, const char* title);
|
||||||
|
~X11Window();
|
||||||
|
|
||||||
|
bool WindowShouldClose();
|
||||||
|
|
||||||
|
void SetViewPort(int width, int height);
|
||||||
|
void Poll();
|
||||||
|
void SwappBuffers();
|
||||||
|
|
||||||
|
void* GetHandle();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* m_handle;
|
||||||
|
bool m_fullscreen;
|
||||||
|
bool m_resizable;
|
||||||
|
bool m_vsync;
|
||||||
|
int m_widht;
|
||||||
|
int m_height;
|
||||||
|
|
||||||
|
void SetContext();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user