Adding physx and fixing memory allocation of AssetView

This commit is contained in:
Nigel Barink 2022-12-22 17:16:09 +01:00
parent e7f1bd7d52
commit 1f1a776686
11 changed files with 95 additions and 22 deletions

View File

@ -20,7 +20,10 @@ public:
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true); ImGui_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true);
ImGui_ImplOpenGL3_Init("#version 440"); ImGui_ImplOpenGL3_Init("#version 450");
ImGuizmo::SetOrthographic(true);
} }
void Begin () void Begin ()
@ -29,20 +32,19 @@ public:
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
ImGuizmo::SetOrthographic(true);
ImGuizmo::BeginFrame(); ImGuizmo::BeginFrame();
} }
void End() void End()
{ {
ImGui::EndFrame(); ImGui::EndFrame();
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{ {
GLFWwindow* last_context = glfwGetCurrentContext(); GLFWwindow* last_context = glfwGetCurrentContext();
@ -51,14 +53,18 @@ public:
glfwMakeContextCurrent(last_context); glfwMakeContextCurrent(last_context);
} }
} }
~GUIRenderer(){ ~GUIRenderer(){
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
}; };

View File

@ -172,6 +172,8 @@ private:
class AssetFinder : EditorWindow { class AssetFinder : EditorWindow {
public: public:
AssetFinder() : EditorWindow("Assets") { AssetFinder() : EditorWindow("Assets") {
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90); ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
@ -195,14 +197,14 @@ public:
if (asset.isFolder) { if (asset.isFolder) {
ImGui::ImageButton( ImGui::ImageButton(
(ImTextureID)folderIcon.GetID(), (ImTextureID)(Texture("rsc/folderIcon.png")).GetID(),
ImVec2{ (float)iconSize,(float)iconSize }); ImVec2{ (float)iconSize,(float)iconSize });
ImGui::Text(asset.GetName(), row); ImGui::Text(asset.GetName(), row);
} }
else { else {
ImGui::ImageButton( ImGui::ImageButton(
(ImTextureID)AssetIcon.GetID(), (ImTextureID)(Texture("rsc/assetIcon.png")).GetID(),
ImVec2{ (float)iconSize, (float)iconSize }); ImVec2{ (float)iconSize, (float)iconSize });
ImGui::Text(asset.GetName(), row); ImGui::Text(asset.GetName(), row);
@ -220,7 +222,7 @@ public:
} }
private: private:
Texture folderIcon = Texture("rsc/folderIcon.png"); static Texture folderIcon;
Texture AssetIcon = Texture("rsc/assetIcon.png"); static Texture AssetIcon;
int iconSize = 60; int iconSize = 60;
}; };

View File

@ -66,11 +66,14 @@ public:
} }
// submit DrawCommands for all render3DComponents // submit DrawCommands for all render3DComponents
auto group = ActiveScene.getReg().view<TransformComponent, Render3DComponent>(); auto group = ActiveScene.getReg().view<TransformComponent, Render3DComponent>();
group.each([&renderer](auto enity, TransformComponent& t, Render3DComponent& renderComponent) { group.each([&renderer](auto enity, TransformComponent& t, Render3DComponent& renderComponent) {
renderer.Submit(renderComponent, t); renderer.Submit(renderComponent, t);
}); });
renderer.Render(); renderer.Render();
GuiRenderer.Begin(); GuiRenderer.Begin();
@ -127,7 +130,7 @@ public:
} }
{ {
// AssetFinder assetsView = AssetFinder(); AssetFinder assetsView = AssetFinder();
} }

View File

@ -25,6 +25,7 @@ project "YoggieEngine"
"../libs/assimp/include", "../libs/assimp/include",
"../libs/entt/src", "../libs/entt/src",
"../libs/physx/pxshared/include",
"../libs/physx/physx/include", "../libs/physx/physx/include",
"../libs/lua/include", "../libs/lua/include",
@ -32,7 +33,6 @@ project "YoggieEngine"
"../libs/GorillaAudio/include", "../libs/GorillaAudio/include",
"../libs/steam-audio/include", "../libs/steam-audio/include",
"../libs/ImGui", "../libs/ImGui",
} }
@ -44,6 +44,14 @@ project "YoggieEngine"
"assimp-vc143-mtd", "assimp-vc143-mtd",
"glfw3", "glfw3",
"ImGui", "ImGui",
"PhysX_64",
"PhysXCooking_64",
"PhysXCommon_64",
"PhysXFoundation_64",
"PhysXPvdSDK_static_64",
"PhysXExtensions_static_64"
} }
@ -53,6 +61,8 @@ project "YoggieEngine"
"../libs/spdlog/build/Release", "../libs/spdlog/build/Release",
"../libs/assimp/lib/Debug", "../libs/assimp/lib/Debug",
"../libs/glfw/build/src/Debug", "../libs/glfw/build/src/Debug",
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
} }
files { files {

View File

@ -1,11 +1,45 @@
#include <YoggieEngine.h> #include <YoggieEngine.h>
#include "Application.h" #include "Application.h"
#include <PxPhysicsAPI.h>
#define PVD_HOST "127.0.0.1"
using namespace physx;
namespace YoggieEngine { namespace YoggieEngine {
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
static PxFoundation* mFoundation;
static PxPvd* mPvd;
static PxPvdTransport* transport;
static PxPhysics* mPhysics;
bool recordMemoryAllocations = true;
Application::Application(const std::string& name ) Application::Application(const std::string& name )
: m_AppName(name) : m_AppName(name)
{ {
EngineInstrumentation::PerfomanceSamplerInit(); EngineInstrumentation::PerfomanceSamplerInit();
// startup PhysX
mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
if (!mFoundation) {
spdlog::critical("PxCreateFoundation failed!");
}
mPvd = physx::PxCreatePvd(*mFoundation);
if (!mPvd) {
spdlog::critical("pxCreatPvd failed!");
}
transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10);
mPvd->connect(*transport, PxPvdInstrumentationFlag::eALL);
mPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), recordMemoryAllocations, mPvd);
if (!mPhysics) {
spdlog::critical("pxCreatePhysics failed!");
}
} }
@ -14,4 +48,24 @@ namespace YoggieEngine {
} }
Application::~Application(){
if (mPhysics)
mPhysics->release();
if (mPvd) {
if (mPvd->isConnected()) {
mPvd->disconnect();
}
mPvd->release();
}
if (transport)
transport->release();
if (mFoundation)
mFoundation->release();
}
} }

View File

@ -1,10 +1,13 @@
#pragma once #pragma once
#include "YoggieEngine.h" #include "YoggieEngine.h"
namespace YoggieEngine { namespace YoggieEngine {
class Application { class Application {
public: public:
Application(const std::string& name); Application(const std::string& name);
~Application();
virtual void Run(); virtual void Run();

View File

@ -47,10 +47,6 @@ namespace YoggieEngine {
*/ */
if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
{ {
std::cout << "Framebuffer is incomplete!" << std::endl; std::cout << "Framebuffer is incomplete!" << std::endl;

View File

@ -5,8 +5,8 @@ namespace YoggieEngine {
unsigned int VAO_identifier; unsigned int VAO_identifier;
unsigned int num_elements; unsigned int num_elements;
unsigned int IBO_identifier; unsigned int IBO_identifier;
TransformComponent transform; TransformComponent& transform;
Shader shader; Shader& shader;
// Material // Material
}; };
}; };

View File

@ -74,9 +74,6 @@ void Renderer::Render()
glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1.0f); glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
std::cout << "Draw commands this frame:" << commands.size() << std::endl;
for (const DrawCommand& command : commands) for (const DrawCommand& command : commands)
{ {
glBindVertexArray(command.VAO_identifier); glBindVertexArray(command.VAO_identifier);

View File

@ -19,6 +19,8 @@
#include <imgui.h> #include <imgui.h>
#include <entt/entt.hpp> #include <entt/entt.hpp>
extern "C" extern "C"
{ {
#include "lauxlib.h" #include "lauxlib.h"

@ -1 +1 @@
Subproject commit c3d5537bdebd6f5cd82fcaf87474b838fe6fd5fa Subproject commit 9414174ec0140ac6b13f4834f16eea93f435a4e7