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:
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,24 +1,24 @@
#pragma once
#include "glm/glm.hpp"
#include "graphics/Shader.h"
#include "graphics/Window.h"
#include "graphics/Texture.h"
#include "graphics/Camera.h"
#include "graphics/Renderable.h"
#include "Graphics/Renderer.h"
#include "Graphics/Material.h"
#include "spdlog/spdlog.h"
#include "Input/InputManager.h"
#include "Graphics/Renderer.h"
#include "Graphics/GUI/GUIManager.h"
#include "Scene.h"
#include "PerfCounter.h"
extern BarinkEngine::Renderer renderer;
extern void Start();
extern void Update();
extern void ImmediateGraphicsDraw();
extern void Stop();
#pragma once
#include "glm/glm.hpp"
#include "graphics/Shader.h"
#include "graphics/Window.h"
#include "graphics/Texture.h"
#include "graphics/Camera.h"
#include "graphics/Renderable.h"
#include "Graphics/Renderer.h"
#include "Graphics/Material.h"
#include "spdlog/spdlog.h"
#include "Input/InputManager.h"
#include "Graphics/Renderer.h"
#include "Graphics/GUI/GUIManager.h"
#include "Scene.h"
#include "PerfCounter.h"
extern BarinkEngine::Renderer renderer;
extern void Start();
extern void Update();
extern void ImmediateGraphicsDraw();
extern void Stop();

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,24 +1,24 @@
#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)
GUIManager::GUIManager(BarinkWindow* window)
: currentwindow(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

@ -1,19 +1,14 @@
#pragma once
#include <glm/glm.hpp>
#include <string>
#include "Shader.h"
class Material {
public:
Material(const Shader& shader);
void Apply()const;
glm::vec3 Color;
private:
const Shader& shader;
#pragma once
#include <glm/glm.hpp>
#include <string>
#include "Shader.h"
class Material {
public:
Material(const Shader& shader);
void Apply()const;
glm::vec3 Color;
const Shader& shader;
};

View File

@ -1,12 +1,12 @@
#pragma once
#include <vector>
#include <glm/glm.hpp>
#include "Vertex.h"
namespace BarinkEngine {
struct Mesh {
std::vector<Vertex> vertices;
std::vector<unsigned int> elements;
};
}
#pragma once
#include <vector>
#include <glm/glm.hpp>
#include "Vertex.h"
namespace BarinkEngine {
struct Mesh {
std::vector<Vertex> vertices;
std::vector<unsigned int> elements;
};
}

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

@ -1,14 +1,14 @@
#pragma once
#include "Mesh.h"
#include "Material.h"
#include "Texture.h"
#include "Scene.h"
namespace BarinkEngine {
struct Renderable {
BarinkEngine::Mesh* mesh;
Material* material;
Texture* texture;
};
#pragma once
#include "Mesh.h"
#include "Material.h"
#include "Texture.h"
#include "../Scene.h"
namespace BarinkEngine {
struct Renderable {
BarinkEngine::Mesh* mesh;
Material* material;
Texture* texture;
};
}

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,25 +50,24 @@ 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++;
glDrawElements(GL_TRIANGLES,
static_cast<unsigned int>(model->mesh->elements.size()),
GL_UNSIGNED_INT,
NULL
);
}
// Update perf counters
ES.verts = model->mesh->vertices.size();
ES.DC++;
glDrawElements(GL_TRIANGLES,
static_cast<unsigned int>(model->mesh->elements.size()),
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,18 +1,18 @@
#pragma once
#include <spdlog/spdlog.h>
#include <string>
class Texture {
public:
Texture(const std::string texturePath);
void Bind();
void Unbind();
private:
unsigned int Id;
#pragma once
#include <spdlog/spdlog.h>
#include <string>
class Texture {
public:
Texture(const std::string texturePath);
void Bind();
void Unbind();
private:
unsigned int Id;
};

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())
@ -19,8 +19,8 @@ Width(width), Height(height), FullScreen(false){
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
// No window decorations such as a border, a close widget
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
//glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
// glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
// Disable resizing the window
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
@ -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()
{