Adding docking support through ImGui , Adding multiviewport support through ImGui, Moving header file back into the src directory , started building the editor, Added framebuffer to renderer.

BUG:
The framebuffer will not be displayed in the editor for some reason
This commit is contained in:
Nigel Barink 2022-10-22 13:27:23 +02:00
parent 463a9ff307
commit 29e715b92a
64 changed files with 8338 additions and 8223 deletions

View File

@ -35,9 +35,6 @@ project "BarinkEngine"
"glfw3",
"ImGUI_Opengl3",
}
@ -53,9 +50,9 @@ project "BarinkEngine"
"../libs/glad/src/glad.c",
"./src/*.cpp",
"./Include/*.h",
"./src/*.h",
"./src/**/*.cpp",
"./Include/**/*.h"
"./src/**/*.h"
}

View File

@ -1,4 +1,4 @@
#include "AssetManager/ModelImporter.h"
#include "ModelImporter.h"
#include "spdlog/spdlog.h"
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)

View File

@ -5,12 +5,12 @@
#define TINYGLTF_IMPLEMENTATION
#define TINYGLTF_NO_EXTERNAL_IMAGE
#include "Graphics/Mesh.h"
#include "../Graphics/Mesh.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include "Scene/SceneNodeTypes.h"
#include "../Scene/SceneNodeTypes.h"
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);

View File

@ -40,10 +40,6 @@ int main(int argc, char* argv[]) {
Update();
renderer.Render();
ImmediateGraphicsDraw();
GUISystem.Render();
MainWindow.SwapBuffers();

View File

@ -1,4 +1,4 @@
#include "../Include/EventSystem/EventEmitter.h"
#include "EventEmitter.h"
void EventEmitter::Subscribe(EventListener& subscriber)

View File

@ -1,4 +1,4 @@
#include "Graphics/Buffer.h"
#include "Buffer.h"
int GpuBuffer::getBufferID() {

View File

@ -1,4 +1,4 @@
#include "Graphics/Camera.h"
#include "Camera.h"
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
: Position(position), Rotation(rotation), Zoom(zoom) {

View File

@ -0,0 +1,49 @@
#include "Framebuffer.h"
#include <iostream>
Framebuffer::Framebuffer()
{
glGenFramebuffers(1, &Id);
glBindFramebuffer(GL_FRAMEBUFFER, Id);
// Create a colour texture!
glGenTextures(1, &ColourAttachment);
glBindTexture(GL_TEXTURE_2D, ColourAttachment);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0);
glBindTexture(GL_TEXTURE_2D, 0);
// Create a depth buffer
glGenRenderbuffers(1, &DepthAttachment);
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
{
std::cout << "Framebuffer is incomplete!" << std::endl;
}
else {
std::cout << "Framebuffer is complete!" << std::endl;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Framebuffer::~Framebuffer()
{
glDeleteTextures(1, &ColourAttachment);
glDeleteRenderbuffers(1, &DepthAttachment);
glDeleteFramebuffers(1, &Id);
}

View File

@ -0,0 +1,20 @@
#pragma once
#include <glad/glad.h>
#include <glm/glm.hpp>
class Framebuffer {
public:
Framebuffer();
~Framebuffer();
unsigned int GetId() { return Id; }
unsigned int GetColourAttachment() { return ColourAttachment; }
private:
unsigned int Id = 0;
unsigned int ColourAttachment = 0;
unsigned int DepthAttachment = 0;
};

View File

@ -1,4 +1,4 @@
#include "Graphics/GPUBucket.h"
#include "GPUBucket.h"
BarinkEngine::GPU_Bucket::GPU_Bucket() {
}
BarinkEngine::GPU_Bucket::~GPU_Bucket() {

View File

@ -1,7 +1,8 @@
#include "Graphics/GUI/GUIManager.h"
#include "GUIManager.h"
#include "imgui.h"
#include "backends/imgui_impl_opengl3.h"
#include <backends/imgui_impl_glfw.cpp>
#include <backends/imgui_impl_glfw.h>
#include "../../BarinkEngine.h"
GUIManager::GUIManager(BarinkWindow* window)
: currentwindow(window)
@ -9,16 +10,15 @@ GUIManager::GUIManager(BarinkWindow* window)
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true);
ImGui_ImplOpenGL3_Init("#version 440");
ImGui_ImplGlfw_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
}
GUIManager::~GUIManager()
@ -28,11 +28,47 @@ GUIManager::~GUIManager()
ImGui::DestroyContext();
}
void GUIManager::Render()
{
ImGui_ImplGlfw_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
ImGui::Begin("##App");
// Show a menu bar
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("Application")) {
if (ImGui::MenuItem("Exit")) {
// TODO: Exit application
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
ImmediateGraphicsDraw();
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* last_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(last_context);
}
}

View File

@ -1,5 +1,5 @@
#pragma once
#include "Graphics/Window.h"
#include "../Window.h"
class GUIManager {

View File

@ -1,4 +1,4 @@
#include "../Include/Graphics/Material.h"
#include "Material.h"
Material::Material(const Shader& shader) :
shader(shader) {

View File

@ -8,12 +8,7 @@ public:
Material(const Shader& shader);
void Apply()const;
glm::vec3 Color;
private:
const Shader& shader;
};

View File

@ -1,4 +1,4 @@
#include "Graphics/RenderSurface.h";
#include "RenderSurface.h";
RenderSurface::RenderSurface(){
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");

View File

@ -1,6 +1,6 @@
#pragma once
#include "BarinkEngine.h"
#include <vector>;
#include "../BarinkEngine.h"
#include <vector>
class RenderSurface
{
public:

View File

@ -2,7 +2,7 @@
#include "Mesh.h"
#include "Material.h"
#include "Texture.h"
#include "Scene.h"
#include "../Scene.h"
namespace BarinkEngine {

View File

@ -1,4 +1,8 @@
#include "Graphics/Renderer.h"
#include "Renderer.h"
float Angle = 0.0;
Camera cam = Camera(glm::vec3(16.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);
BarinkEngine::Renderer::Renderer()
{
@ -18,13 +22,12 @@ BarinkEngine::Renderer::~Renderer()
// glDeleteBuffers(1, &UV_id);
}
float Angle = 0.0;
void BarinkEngine::Renderer::Render()
void BarinkEngine::Renderer::Render(Framebuffer& framebuffer)
{
// This creation of the projection and camera is somewhat wastefull
Camera cam = Camera(glm::vec3(16.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);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.GetId());
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Angle += 0.0001f;
for (auto model : models) {
@ -33,9 +36,9 @@ void BarinkEngine::Renderer::Render()
model->elementBuffer.Bind(true);
if (model->material == nullptr) {
std::cout << "No material attached!" << std::endl;
// continue; //NOTE: Or use some default Material
}
else {
model->material->shader.Use();
@ -47,9 +50,6 @@ void BarinkEngine::Renderer::Render()
model->material->shader.setUniformMat4("M", glm::rotate(glm::mat4(), Angle, glm::vec3(0.5f, 0.5f, 0.0f)));
model->material->shader.setUniformMat4("V", cam.GetViewMatrix());
model->material->shader.setUniformMat4("P", projection);
}
// Update perf counters
ES.verts = model->mesh->vertices.size();
ES.DC++;
@ -59,13 +59,15 @@ void BarinkEngine::Renderer::Render()
GL_UNSIGNED_INT,
NULL
);
}
model->vertexarray.Unbind();
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

View File

@ -5,11 +5,12 @@
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "PerfCounter.h"
#include "../PerfCounter.h"
#include "Graphics/Camera.h"
#include "Graphics/Renderable.h"
#include "Graphics/GPUBucket.h"
#include "Camera.h"
#include "Renderable.h"
#include "GPUBucket.h"
#include "Framebuffer.h"
namespace BarinkEngine {
@ -18,7 +19,7 @@ namespace BarinkEngine {
Renderer();
~Renderer();
void Render();
void Render(Framebuffer& framebuffer);
void Submit(Renderable* model);

View File

@ -1,4 +1,4 @@
#include "Graphics/Shader.h"
#include "Shader.h"
#include "spdlog/spdlog.h"
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)

View File

@ -1,8 +1,8 @@
#include "../Include/Graphics/Texture.h"
#include "Texture.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define STB_IMAGE_IMPLEMENTATION
#include "Graphics/stb_image.h"
#include "stb_image.h"
#include <iostream>
Texture::Texture(const std::string texturePath) {

View File

@ -1,4 +1,4 @@
#include "Graphics/VertexArray.h"
#include "VertexArray.h"
#include <glad/glad.h>
void VertexArray::Create(){

View File

@ -9,8 +9,8 @@
#include <GLFW/glfw3.h>
#include <spdlog/spdlog.h>
#include "EventSystem/Event.h"
#include "EventSystem/EventListener.h"
#include "../EventSystem/Event.h"
#include "../EventSystem/EventListener.h"
class BarinkWindow : EventListener {
private:

View File

@ -1,4 +1,4 @@
#include "Graphics/Window.h"
#include "Window.h"
bool BarinkWindow::InitGLFW(){
if(!glfwInit())
@ -54,7 +54,6 @@ Width(width), Height(height), FullScreen(false){
}
BarinkWindow::~BarinkWindow(){
glfwTerminate();
@ -81,6 +80,6 @@ void BarinkWindow::SwapBuffers()
void BarinkWindow::ReceiveEvent(Event& incident)
{
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
//std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
}

View File

@ -1,4 +1,5 @@
#include "Input/InputManager.h"
#include "InputManager.h"
BarinkEngine::InputManager InputSystem;
void BarinkEngine::InputManager::PollEvents()

View File

@ -3,9 +3,9 @@
#include <iostream>
#include "spdlog/spdlog.h"
#include "EventSystem/EventEmitter.h"
#include "EventSystem/EventListener.h"
#include "Graphics/Window.h"
#include "../EventSystem/EventEmitter.h"
#include "../EventSystem/EventListener.h"
#include "../Graphics/Window.h"
namespace BarinkEngine {

View File

@ -1,4 +1,4 @@
#include "Scene/Node.h"
#include "Node.h"
Node::Node(const std::string& name)
: name(name), parent(nullptr), children(std::vector<Node*>()) {}

View File

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <vector>
#include "Graphics/Transform.h"
#include "../Graphics/Transform.h"
class Node {
public:

View File

@ -1,4 +1,4 @@
#include "Scene/SceneManager.h"
#include "SceneManager.h"
Scene* SceneManager::CreateScene(const std::string& name)
{

View File

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <map>
#include "Scene.h"
#include "../Scene.h"
class SceneManager {
public:

View File

@ -1,4 +1,4 @@
#include "Scene/SceneNodeTypes.h"
#include "SceneNodeTypes.h"
BarinkEngine::SceneCamera::SceneCamera()
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))

View File

@ -1,7 +1,7 @@
#pragma once
#include "Graphics/Camera.h"
#include "Graphics/Renderable.h"
#include "Scene/Node.h"
#include "../Graphics/Camera.h"
#include "../Graphics/Renderable.h"
#include "Node.h"
namespace BarinkEngine {
class SceneCamera : public Group

View File

@ -1,4 +1,4 @@
#include "Scripting/LuaScript.h"
#include "LuaScript.h"
/*
LuaScript::LuaScript(const std::string& path)
: filePath(path) {

View File

@ -1,4 +1,4 @@
#include "Scripting/LuaScriptingManager.h"
#include "LuaScriptingManager.h"
/*
LuaScriptingManager::LuaScriptingManager()
{

View File

@ -1,9 +1,11 @@
#pragma once
#include "imgui.h"
#include <BarinkEngine.h>
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../BarinkEngine/src/Graphics/Framebuffer.h"
void CameraTool(Camera* camera);
void CameraTool();
void ScriptingTool(char* code);
void transformWindow(Transform& transform, std::string PanelName);
void materialWindow(Material& material, std::string PanelName);
void SceneExplorer(Scene& scene, std::string PanelName);
void SceneExplorer(const std::string& PanelName);
void SceneView(Framebuffer& framebuffer);

View File

@ -1,5 +1,5 @@
#pragma once
#include "BarinkEngine.h"
#include "../../BarinkEngine/src/BarinkEngine.h"
void PrintSceneTree(Node& node, int depth);

View File

@ -1,17 +1,19 @@
#include "GUI.h"
void SceneExplorer(Scene& scene, std::string PanelName) {
if (ImGui::Begin(PanelName.c_str())) {
ImGui::ListBoxHeader("##ObjectList");
Node& current = scene.GetRoot();
void SceneExplorer(const std::string& PanelName) {
ImGui::Begin(PanelName.c_str());
//if (ImGui::ListBoxHeader("##ObjectList")) {
//Node& current = scene.GetRoot();
Node* next = &current;
//Node* next = &current;
// Show first node
ImGui::Selectable(next->name.c_str(), true);
//ImGui::Selectable(next->name.c_str(), true);
// ImGui::Selectable("Scene Node", true);
// ImGui::Indent();
ImGui::Indent();
/*
if (next->children.size() != 0) {
for (auto child : next->children)
@ -21,24 +23,29 @@ void SceneExplorer(Scene& scene, std::string PanelName) {
}
}
ImGui::ListBoxFooter();
*/
}
// ImGui::ListBoxFooter();
// }
ImGui::End();
}
void CameraTool(Camera* cam) {
void CameraTool() {
static float Zoom = 0;
static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f);
static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
ImGui::Begin("Camera");
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
ImGui::InputFloat3("Position:", &cam->Position[0]);
ImGui::SliderFloat("Zoom:", &Zoom, 10, 190);
ImGui::InputFloat3("Rotation:", &cam->Rotation[0]);
ImGui::InputFloat3("Position:", &Position[0]);
ImGui::InputFloat3("Rotation:", &Rotation[0]);
ImGui::End();
}
@ -46,7 +53,8 @@ void CameraTool(Camera* cam) {
void ScriptingTool(char* code) {
ImGui::Begin("Scripting");
ImGui::InputTextMultiline("Lua Script", code, 255);
ImGui::Text("Lua Code");
ImGui::InputTextMultiline("##", code, 255);
bool runCode = ImGui::Button("Run");
@ -54,6 +62,12 @@ void ScriptingTool(char* code) {
}
void SceneView(Framebuffer& framebuffer ) {
ImGui::Begin("Viewport");
ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{800, 600});
ImGui::End();
}
void transformWindow(Transform& transform, std::string PanelName) {
ImGui::Begin(PanelName.c_str());

View File

@ -1,8 +1,8 @@
#include "BarinkEngine.h"
#include "Scene\SceneManager.h"
#include "Scene\SceneNodeTypes.h"
#include "AssetManager/ModelImporter.h"
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../BarinkEngine/src/Scene/SceneManager.h"
#include "../../BarinkEngine/src/Scene/SceneNodeTypes.h"
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
#include "../../BarinkEngine/src/Graphics/Framebuffer.h"
#include "imgui.h"
#include "GUI.h"
#include "Util.h"
@ -18,7 +18,7 @@ const std::string vertexShaderSource = "../build/SandboxApplication/Debug/test.v
const std::string fragmentShaderSource = "../build/SandboxApplication/Debug/test.fs";
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
Framebuffer* framebuffer;
Scene* Level1;
BarinkEngine::SceneObject* cube;
/*
@ -49,11 +49,13 @@ void Start() {
Level1->GetRoot().addChild(*cube);
memset(code, '\0', 254);
framebuffer = new Framebuffer();
std::cout << "Colour attachment id; "<< framebuffer->GetColourAttachment() << std::endl;
// TODO: Move to runtime/ Engine
// NOTE: Submits should later be done through walking the sceneTree
renderer.Submit(cube->renderable);
renderer.Submit(cube->renderable);
}
@ -61,21 +63,17 @@ void Start() {
* Runs every frame
* - Use to draw Immediate mode graphics (Not meant for HUD's )
*/
void ImmediateGraphicsDraw() {
ImGui::NewFrame();
// Show ImGui demo such that I can easily look
// at possible GUI elements to use
// ImGui::ShowDemoWindow();
void ImmediateGraphicsDraw()
{
// Show internal BarinkEngine stats
ShowStats();
SceneView(*framebuffer);
// Show different tooling for this specific sandbox
// CameraTool(cam);
//ScriptingTool(code);
CameraTool();
ScriptingTool(code);
//SceneExplorer(*Level1, "Scene Explorer");
SceneExplorer( "Scene Explorer");
}
@ -85,14 +83,20 @@ void ImmediateGraphicsDraw() {
*/
void Update()
{
// glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
renderer.Render(*framebuffer);
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
/*
* Runs at the end of the program
* - Meant for cleanup
*/
void Stop() {
void Stop()
{
delete framebuffer;
delete MI;
delete shader;
}

@ -1 +1 @@
Subproject commit 6d27fecce1ea2cb10ca956cd67b8179cb76b35c3
Subproject commit d666a1d4737739274449dbe0e8558454bba82ec4

View File

@ -9,7 +9,6 @@ workspace "BarinkEngine"
architecture "x86_64"
filter "configurations:Debug"
defines {"DEBUG"}
symbols "On"