Compare commits
2 Commits
a1ec94e983
...
1f1a776686
Author | SHA1 | Date | |
---|---|---|---|
1f1a776686 | |||
e7f1bd7d52 |
@ -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();
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
@ -125,25 +125,11 @@ public:
|
||||
|
||||
class Viewport : EditorWindow {
|
||||
public:
|
||||
Viewport (Scene& scene) : EditorWindow("SceneView") {
|
||||
Framebuffer framebuffer = Framebuffer((int)ImGui::GetWindowWidth(),(int)ImGui::GetWindowHeight());
|
||||
|
||||
|
||||
Renderer renderer = Renderer();
|
||||
renderer.Prepare(scene);
|
||||
renderer.Render(&framebuffer, scene);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Viewport (Framebuffer& fb) : EditorWindow("SceneView") {
|
||||
ImGui::Image(
|
||||
(void*)(intptr_t)framebuffer.GetColourAttachment(),
|
||||
(void*)(intptr_t)fb.GetColourAttachment(),
|
||||
ImVec2{ (float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight() }
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
//ImGuizmo::SetDrawlist();
|
||||
//ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
|
||||
@ -186,6 +172,8 @@ private:
|
||||
class AssetFinder : EditorWindow {
|
||||
public:
|
||||
AssetFinder() : EditorWindow("Assets") {
|
||||
|
||||
|
||||
ImGui::DragInt("IconSize", &iconSize, 1, 30, 90);
|
||||
|
||||
|
||||
@ -209,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);
|
||||
|
||||
@ -234,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;
|
||||
};
|
@ -14,17 +14,28 @@
|
||||
#include "AssetManagement/AssetManager.h"
|
||||
#include "UI/MainMenuBar.h"
|
||||
|
||||
|
||||
const unsigned int MS_PER_UPDATE = 2;
|
||||
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
|
||||
|
||||
class Editor : public Application {
|
||||
public:
|
||||
Editor() : Application("Editor") {}
|
||||
Editor() : Application("Editor"){
|
||||
}
|
||||
|
||||
void Run() override
|
||||
{
|
||||
|
||||
auto NativeEditorWindow = NativeWindow(1200, 700);
|
||||
//auto renderer = Renderer();
|
||||
|
||||
framebuffer = new Framebuffer(800, 600);
|
||||
auto renderer = Renderer(RendererConfig{
|
||||
1200, // Screen Width
|
||||
700, // Screen Height
|
||||
glm::vec3{0,0,0}, // Clear Color
|
||||
true // Depth testing
|
||||
});
|
||||
|
||||
auto GuiRenderer = GUIRenderer(NativeEditorWindow);
|
||||
|
||||
Selected = (entt::entity)-1;
|
||||
@ -33,10 +44,11 @@ public:
|
||||
|
||||
ActiveScene.Start();
|
||||
|
||||
renderer.setCurrentFrameBuffer(*framebuffer);
|
||||
|
||||
|
||||
double previous = glfwGetTime();
|
||||
double lag = 0.0;
|
||||
|
||||
|
||||
while (!NativeEditorWindow.WindowShouldClose())
|
||||
{
|
||||
|
||||
@ -53,8 +65,16 @@ public:
|
||||
lag -= MS_PER_UPDATE;
|
||||
}
|
||||
|
||||
// renderer.Render(framebuffer, ActiveScene);
|
||||
// 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();
|
||||
|
||||
GuiRenderer.Begin();
|
||||
RenderGUI();
|
||||
@ -66,6 +86,8 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
delete framebuffer;
|
||||
ActiveScene.Stop();
|
||||
|
||||
}
|
||||
@ -86,7 +108,7 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
Viewport sceneview = Viewport(ActiveScene);
|
||||
Viewport sceneview = Viewport(*framebuffer);
|
||||
}
|
||||
|
||||
{
|
||||
@ -127,6 +149,8 @@ private:
|
||||
std::unique_ptr<Project> CurrentProject;
|
||||
Scene ActiveScene;
|
||||
entt::entity Selected;
|
||||
Framebuffer* framebuffer ;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
#include "YoggieEngine.h"
|
||||
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application(const std::string& name);
|
||||
~Application();
|
||||
virtual void Run();
|
||||
|
||||
|
||||
|
@ -47,10 +47,6 @@ namespace YoggieEngine {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
std::cout << "Framebuffer is incomplete!" << std::endl;
|
||||
|
12
YoggieEngine/src/Graphics/Primitives/DrawCommand.h
Normal file
12
YoggieEngine/src/Graphics/Primitives/DrawCommand.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "Scene/Components.h"
|
||||
namespace YoggieEngine {
|
||||
struct DrawCommand {
|
||||
unsigned int VAO_identifier;
|
||||
unsigned int num_elements;
|
||||
unsigned int IBO_identifier;
|
||||
TransformComponent& transform;
|
||||
Shader& shader;
|
||||
// Material
|
||||
};
|
||||
};
|
@ -1,24 +1,34 @@
|
||||
#include <YoggieEngine.h>
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "../Scene/Components.h"
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Memory/Buffer.h"
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Primitives/DrawCommand.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
float Angle = 0.0;
|
||||
Camera cam = Camera(glm::vec3(12.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
|
||||
Renderer::Renderer(){
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
Renderer::Renderer(RendererConfig& config)
|
||||
: m_framebuffer(Framebuffer(config.ScreenWidth, config.ScreenHeight))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Renderer::~Renderer(){}
|
||||
|
||||
void Renderer::Prepare(Scene& scene ) {
|
||||
auto group = scene.getReg().view<Render3DComponent>();
|
||||
group.each([](auto enity, Render3DComponent& renderComponent) {
|
||||
|
||||
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();
|
||||
@ -46,64 +56,77 @@ void Renderer::Prepare(Scene& scene ) {
|
||||
|
||||
renderComponent.VAO = va.getID();
|
||||
renderComponent.IBO = elementBuffer.getBufferID();
|
||||
});
|
||||
}
|
||||
|
||||
DrawCommand dc = { renderComponent.VAO, renderComponent.mesh.elements.size(), renderComponent.IBO, transform, renderComponent.shader };
|
||||
commands.push_back(dc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::Render(Scene& scene)
|
||||
void Renderer::Render()
|
||||
{
|
||||
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||
group.each([&](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||
{
|
||||
glBindVertexArray(renderComponent.VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
|
||||
renderComponent.shader.Use();
|
||||
if (m_depthTest) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
auto lights = scene.getReg().view<LightComponent>();
|
||||
glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
for (const DrawCommand& command : commands)
|
||||
{
|
||||
glBindVertexArray(command.VAO_identifier);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||
|
||||
command.shader.Use();
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), command.transform.Rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), command.transform.Rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), command.transform.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), command.transform.Position) * glm::scale(glm::mat4(1.0f), command.transform.Scale) * rotation;
|
||||
|
||||
|
||||
command.shader.setUniformVec3("Color", glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
command.shader.setUniformMat4("M", modelMatrix);
|
||||
command.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
command.shader.setUniformMat4("P", projection);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||
GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
});
|
||||
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), trans.Rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), trans.Rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation *= glm::rotate(glm::mat4(1.0f), trans.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), trans.Position) * glm::scale(glm::mat4(1.0f), trans.Scale) *rotation;
|
||||
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
renderComponent.shader.setUniformMat4("M", modelMatrix);
|
||||
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
renderComponent.shader.setUniformMat4("P", projection);
|
||||
|
||||
//std::cout << "Draw " << renderComponent.mesh.elements.size() << " elements" << std::endl;
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(renderComponent.mesh.elements.size()) ,
|
||||
GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glBindVertexArray(0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Render(Framebuffer* framebuffer, Scene& scene)
|
||||
{
|
||||
if (framebuffer == nullptr)
|
||||
return;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Render(scene);
|
||||
*
|
||||
*/
|
||||
|
||||
commands.clear();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::setCurrentFrameBuffer(const Framebuffer& fb)
|
||||
{
|
||||
m_framebuffer = fb;
|
||||
}
|
||||
|
||||
void Renderer::setClearColor(const glm::vec3& ClearColor)
|
||||
{
|
||||
m_clearColor = ClearColor;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,23 +1,38 @@
|
||||
#pragma once
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include <vector>
|
||||
#include "../PerfCounter.h"
|
||||
|
||||
#include "Renderable.h"
|
||||
#include "Memory/Framebuffer.h"
|
||||
#include "../Scene/Components.h"
|
||||
#include"../Scene/Scene.h"
|
||||
#include "Graphics/Primitives/DrawCommand.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
struct RendererConfig {
|
||||
int ScreenWidth, ScreenHeight;
|
||||
glm::vec3 ClearColor;
|
||||
bool DepthTest;
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer();
|
||||
Renderer(RendererConfig& config);
|
||||
~Renderer();
|
||||
|
||||
void Prepare(Scene& scene);
|
||||
void Render(Scene& scene );
|
||||
|
||||
void Render(Framebuffer* framebuffer, Scene& scene);
|
||||
void Submit(Render3DComponent& renderComponent, TransformComponent& transform); // Collects DrawCommands
|
||||
void Render(); // Draw to screen (usingthe drawCalls
|
||||
|
||||
void setCurrentFrameBuffer(const Framebuffer& fb);
|
||||
void setClearColor(const glm::vec3& ClearColor);
|
||||
|
||||
private:
|
||||
Framebuffer m_framebuffer;
|
||||
glm::vec3 m_clearColor;
|
||||
bool m_depthTest;
|
||||
std::vector<DrawCommand> commands;
|
||||
};
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <imgui.h>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lauxlib.h"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c3d5537bdebd6f5cd82fcaf87474b838fe6fd5fa
|
||||
Subproject commit 9414174ec0140ac6b13f4834f16eea93f435a4e7
|
Loading…
x
Reference in New Issue
Block a user