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_ImplGlfw_InitForOpenGL(window.GetGLFWHandle(), true);
ImGui_ImplOpenGL3_Init("#version 440");
ImGui_ImplOpenGL3_Init("#version 450");
ImGuizmo::SetOrthographic(true);
}
void Begin ()
@ -29,20 +32,19 @@ public:
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
ImGuizmo::SetOrthographic(true);
ImGuizmo::BeginFrame();
}
void End()
{
{
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* last_context = glfwGetCurrentContext();
@ -50,15 +52,19 @@ public:
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(last_context);
}
}
~GUIRenderer(){
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
};

View File

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

View File

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

View File

@ -24,7 +24,8 @@ project "YoggieEngine"
"../libs/assimp/include",
"../libs/entt/src",
"../libs/physx/pxshared/include",
"../libs/physx/physx/include",
"../libs/lua/include",
@ -32,7 +33,6 @@ project "YoggieEngine"
"../libs/GorillaAudio/include",
"../libs/steam-audio/include",
"../libs/ImGui",
}
@ -44,6 +44,14 @@ project "YoggieEngine"
"assimp-vc143-mtd",
"glfw3",
"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/assimp/lib/Debug",
"../libs/glfw/build/src/Debug",
"../libs/physx/physx/bin/win.x86_64.vc142.md/debug"
}
files {

View File

@ -1,11 +1,45 @@
#include <YoggieEngine.h>
#include "Application.h"
#include <PxPhysicsAPI.h>
#define PVD_HOST "127.0.0.1"
using namespace physx;
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 )
: m_AppName(name)
{
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
#include "YoggieEngine.h"
namespace YoggieEngine {
class Application {
public:
Application(const std::string& name);
~Application();
virtual void Run();

View File

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

View File

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

View File

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

View File

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

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