Reorganising the game engine structure. Getting things ready for real development of the engine

Feature/BasicRenderer
Nigel Barink 2022-05-27 22:47:36 +02:00
parent 4625ca657b
commit 3446bc2399
22 changed files with 326 additions and 221 deletions

View File

@ -0,0 +1,34 @@
#include "Include/BarinkEngine.h"
extern void Start(int argc, char* argv[]);
extern void UpdateApplication();
using namespace BarinkEngine;
bool ShouldQuit = false;
int main(int argc, char* argv[]) {
// Start Engine
Engine::Startup();
Start(argc, argv);
while (!ShouldQuit) {
//InputManager::PollEvents();
UpdateApplication();
}
// Kill Engine
Engine::Shutdown();
return 0;
}

10
BarinkEngine/Engine.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "include/BarinkEngine.h"
namespace BarinkEngine {
void Engine::Startup() {
std::cout << "Starting Engine! vroom vroom!" << std::endl;
}
void Engine::Shutdown() {
std::cout << "ShutDown Engine!" << std::endl;
}
};

View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <string>
#include <filesystem>
#include "Engine.h"
#include <spdlog/spdlog.h>
/*
#include "../MemoryManager.h"
#include <glm/glm.hpp>
#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
#include <MyGraphicsEngine/Camera.h>
#include <MyGraphicsEngine/Renderable.h>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
*/

View File

@ -0,0 +1,10 @@
#pragma once
namespace BarinkEngine {
static class Engine {
public:
static void Startup();
static void Shutdown();
};
};

34
BarinkEngine/premake5.lua Normal file
View File

@ -0,0 +1,34 @@
project "BarinkEngine"
kind "StaticLib"
buildmessage "Building BarinkEngine"
includedirs{
"./../libs/lua/include",
"./libs/spdlog/include",
"./../libs/glm",
"./../MyGraphicsEngine/include",
"./../libs/GorillaAudio/include"
}
libdirs {
"./../libs/lua",
"./../libs/spdlog/build/Release"
}
links {
"lua54",
"spdlog",
"MyGraphicsEngine"
}
files {
"./*.cpp",
"./*.h",
"./**/*.cpp",
"./**/*.h"
}

17
MemoryManager.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <iostream>
#include <stdlib.h>
static int HeapAllocations = 0;
static int HeapDeallocations = 0;
void* operator new(std::size_t sz) {
HeapAllocations++;
return std::malloc(sz);
}
void operator delete(void* ptr) noexcept {
HeapDeallocations++;
std::free(ptr);
}

View File

@ -1,4 +1,4 @@
#include <MyGraphicsEngine/Buffer.h>
#include "include/MyGraphicsEngine/Buffer.h"
int Buffer::getBufferID() {

View File

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

View File

@ -3,27 +3,27 @@
void ModelImporter::ImportFBX(std::string path)
{
spdlog::warn("ImportFBX not implemented!");
//spdlog::warn("ImportFBX not implemented!");
}
void ModelImporter::ImportBlend(std::string path)
{
spdlog::warn("ImportBlend not implemented!");
//spdlog::warn("ImportBlend not implemented!");
}
void ModelImporter::ImportGLTF(std::string path)
{
spdlog::warn("ImportGLTF not implemented!");
//spdlog::warn("ImportGLTF not implemented!");
}
void ModelImporter::ImportOBJ(std::string path)
{
spdlog::warn("ImportOBJ not implemented!");
//spdlog::warn("ImportOBJ not implemented!");
}
void ModelImporter::Import(std::string path)
{
spdlog::warn("Import not implemented!");
//spdlog::warn("Import not implemented!");
}
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
@ -51,7 +51,7 @@ std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
*/
spdlog::info("======= Assimp ======");
//spdlog::info("======= Assimp ======");
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
@ -94,7 +94,7 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
vertices.push_back(vector);
}
spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
//spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
// Process Indices
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {

View File

@ -1,50 +1,51 @@
#include "Renderable.h"
Renderable Renderable::Load()
{
return Renderable();
}
Renderable::Renderable()
{
meshes = ModelImporter::Test();
transform.Scale = glm::vec3(1.0f);
transform.Rotation = glm::vec3(0.0f, 90.0f, 0.0f);
transform.Position = glm::vec3(0.0f, 0.0f, -10.0f);
VAO.Create();
VAO.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(glm::vec3), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
VAO.AttachAttribute(0, 3, 0);
vertexBuffer.Unbind(false);
VAO.Unbind();
}
Renderable::~Renderable()
{
}
void Renderable::Draw()
{
VAO.Bind();
elementBuffer.Bind(true);
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
VAO.Unbind();
}
#include "include/MyGraphicsEngine/Renderable.h"
#include "include/AssetManager/ModelImporter.h"
Renderable Renderable::Load()
{
return Renderable();
}
Renderable::Renderable()
{
meshes = ModelImporter::Test();
transform.Scale = glm::vec3(1.0f);
transform.Rotation = glm::vec3(0.0f, 90.0f, 0.0f);
transform.Position = glm::vec3(0.0f, 0.0f, -10.0f);
VAO.Create();
VAO.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(glm::vec3), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
VAO.AttachAttribute(0, 3, 0);
vertexBuffer.Unbind(false);
VAO.Unbind();
}
Renderable::~Renderable()
{
}
void Renderable::Draw()
{
VAO.Bind();
elementBuffer.Bind(true);
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
VAO.Unbind();
}

View File

@ -1,4 +1,4 @@
#include "MyGraphicsEngine/Shader.h"
#include "include/MyGraphicsEngine/Shader.h"
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
{
@ -6,7 +6,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
int succes;
char* vertexCode = readFile(vertexShaderPath.c_str());
spdlog::info(vertexCode);
//spdlog::info(vertexCode);
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertId, 1, &vertexCode, NULL);
@ -15,13 +15,13 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
if(!succes){
glGetShaderInfoLog(vertId, 512, NULL, infoLog);
spdlog::error( "Vertex shader has compile error {}", infoLog);
//spdlog::error( "Vertex shader has compile error {}", infoLog);
return;
}
char* fragmentCode = readFile(fragmentShaderPath.c_str());
spdlog::info(fragmentCode);
//spdlog::info(fragmentCode);
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
@ -33,7 +33,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
if(!succes){
glGetShaderInfoLog(fragId, 512, NULL, infoLog);
spdlog::error("Fragment shader has compile error {}", infoLog);
//spdlog::error("Fragment shader has compile error {}", infoLog);
return;
}
@ -63,7 +63,7 @@ char* Shader::readFile (const char* filePath){
file.open(filePath);
if(file.is_open() == false){
spdlog::info("File not found.");
//spdlog::info("File not found.");
return nullptr;
}
@ -74,7 +74,7 @@ char* Shader::readFile (const char* filePath){
// Undo previous seek.
file.seekg(0, std::ios::beg);
spdlog::info("filesize: {}", filesize);
//spdlog::info("filesize: {}", filesize);
// Create a big enough buffer for the file

View File

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

View File

@ -4,11 +4,10 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define TINYGLTF_NO_EXTERNAL_IMAGE
#include <MyGraphicsEngine/Mesh.h>
#include "../MyGraphicsEngine/Mesh.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <spdlog/spdlog.h>
#include <string>
class ModelImporter {

View File

@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <glm/glm.hpp>
namespace BarinkEngine{
class Mesh {

View File

@ -0,0 +1,30 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "Transform.h"
#include "Buffer.h"
#include "VertexArray.h"
/*
#include <MyGraphicsEngine/AssetManager/ModelImporter.h>
#include <MyGraphicsEngine/MyGraphicsEngine/Buffer.h>
#include <MyGraphicsEngine/MyGraphicsEngine/VertexArray.h>
*/
class Renderable {
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
public:
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
Transform transform;
~Renderable();
static Renderable Load();
void Draw();
};

View File

@ -1,9 +1,9 @@
#pragma once
#include <glad/glad.h>
#include <string>
#include <iostream>
#include <fstream>
#include <spdlog/spdlog.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

View File

@ -1,9 +1,13 @@
#pragma once
#include <glad/glad.h>
#define GLFW_STATIC
#include <glad/glad.h>
#include <GLFW/glfw3.h>
class BarinkWindow{
private:
GLFWwindow* window;

View File

@ -0,0 +1,49 @@
project "MyGraphicsEngine"
kind "StaticLib"
buildmessage "Building MyGraphicsEngine ..."
includedirs {
"../libs/assimp/include",
"../libs/glad/include",
"../libs/glfw/include",
"../libs/tinygltf",
"../libs/glew/include",
"../libs/glm",
"../libs/ImGui",
}
libdirs{
"../libs/assimp/lib/Debug",
"../libs/glfw/build/src/Debug",
"../libs/ImGui"
}
links {
"assimp-vc143-mtd",
"glfw3",
}
files {
"../libs/ImGui/*.cpp",
"../libs/ImGui/backends/imgui_impl_glfw.cpp",
"../libs/ImGui/backends/imgui_impl_Opengl3.cpp",
"../libs/glad/src/glad.c",
"./*.cpp",
"./*.h",
"./**/*.cpp",
"./**/*.shader",
"./**/*.h"
}
-- NOTE: make these copy instructions more flexible
ok, err = os.copyfile("shaders/fragment.shader", "../build/SandboxApplication/Debug/test.fs")
if err then error("Copy fragment shader source failed!") end
ok, err = os.copyfile("shaders/vertex.shader", "../build/SandboxApplication/Debug/test.vs")
if err then error("Copy vertex shader source failed!") end

View File

@ -1,11 +1,12 @@
#include "MyGraphicsEngine/Window.h"
#include <spdlog/spdlog.h>
#include "include/MyGraphicsEngine/Window.h"
#include <stdlib.h>
#include <stdio.h>
bool BarinkWindow::InitGLFW(){
if(!glfwInit())
{
spdlog::error("Failed to initialise GLFW!");
// spdlog::error("Failed to initialise GLFW!");
return false;
}
@ -22,7 +23,7 @@ Width(width), Height(height), FullScreen(false){
if( !window)
{
spdlog::error("GLFW failed to create window!");
// spdlog::error("GLFW failed to create window!");
glfwTerminate();
return;
}

View File

@ -1,24 +0,0 @@
#pragma once
#include <vector>
#include <spdlog/spdlog.h>
#include <MyGraphicsEngine/Mesh.h>
#include <MyGraphicsEngine/Transform.h>
#include <include/AssetManager/ModelImporter.h>
#include <include/MyGraphicsEngine/Buffer.h>
#include <include/MyGraphicsEngine/VertexArray.h>
class Renderable {
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
public:
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
Transform transform;
~Renderable();
static Renderable Load();
void Draw();
};

View File

@ -1,30 +1,18 @@
#include <string>
#include <BarinkEngine.h>
#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
#include <MyGraphicsEngine/Camera.h>
void Start(int argc, char* argv[]) {
#include <glm/glm.hpp>
std::cout << "Hello start!" << std::endl;
std::cout << "h" << std::endl;
// BarinkWindow GameWindow(800, 600);
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include "Renderable.h"
#include <filesystem>
}
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
void UpdateApplication()
{
}
/*
#include <gorilla/gau.h>
#include <gorilla/ga.h>
*/
int main(int argc, char* argv[]) {
@ -33,8 +21,6 @@ int main(int argc, char* argv[]) {
getcwd(cwd, 256);
spdlog::info("Working directory: {}", cwd);
BarinkWindow GameWindow(800, 600);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
@ -61,21 +47,6 @@ int main(int argc, char* argv[]) {
luaL_dofile(L,"build/SandboxApplication/Debug/script.lua");
/*
* gau_Manager* mgr;
ga_Mixer* mixer;
ga_Sound sound;
ga_Handle handle;
gau_SampleSourceLoop* loopSrc = 0;
gau_SampleSourceLoop** pLoopSrc = &loopSrc;
gc_int32 loop = 0;
gc_int32 quit = 0;
gc_initialize(0);
mgr = gau_manager_create();
mixer = gau_manager_mixer(mgr);
*/
char* lua_code = new char[255];
memset(lua_code, '\0', 255);
@ -162,3 +133,4 @@ int main(int argc, char* argv[]) {
}
*/

View File

@ -1,104 +1,43 @@
workspace "BarinkEngine"
configurations { "Debug", "Test", "Release" }
language "C++"
cppdialect "C++17"
targetdir "./build/%{prj.name}/%{cfg.buildcfg}"
objdir "./intermediates/%{prj.name}/%{cfg.buildcfg}"
architecture "x86_64"
filter "configurations:Debug"
defines {"DEBUG"}
symbols "On"
filter "configurations:Release"
defines {"NDEBUG"}
optimize "On"
project "SandboxApplication"
kind "ConsoleApp"
buildmessage "Building BarinkEngineSandbox ..."
includedirs {
"./libs/assimp/include",
"./libs/glad/include",
"./MyGraphicsEngine",
"./MyGraphicsEngine/include",
"./libs/spdlog/include",
"./libs/glm",
"./libs/GorillaAudio/include",
"./libs/lua/include",
"./libs/glfw/include",
"./libs/ImGui",
"./libs/lua/include"
}
libdirs{
"./libs/spdlog/build/Release",
"./libs/glfw/build/src/Debug",
"./libs/lua",
"./libs/ImGui"
}
buildmessage "Building Sandbox ..."
links{
"lua54",
"spdlog",
"glfw3",
"MyGraphicsEngine"
"BarinkEngine"
}
includedirs{
"./BarinkEngine/include"
}
files {
"./libs/ImGui/*.cpp",
"./libs/ImGui/backends/imgui_impl_glfw.cpp",
"./libs/ImGui/backends/imgui_impl_Opengl3.cpp",
"SandboxApplication/*.cpp"
"./SandboxApplication/*.h",
"./SandboxApplication/*.cpp"
}
defines {"DEBUG"}
symbols "On"
-- NOTE: make these copy instructions more flexible
ok, err = os.copyfile("MyGraphicsEngine/shaders/fragment.shader", "build/SandboxApplication/Debug/test.fs")
if err then error("Copy fragment shader source failed!") end
ok, err = os.copyfile("MyGraphicsEngine/shaders/vertex.shader", "build/SandboxApplication/Debug/test.vs")
if err then error("Copy vertex shader source failed!") end
project "MyGraphicsEngine"
kind "StaticLib"
buildmessage "Building MyGraphicsEngine ..."
includedirs {
"./libs/assimp/include",
"./libs/glad/include",
"./libs/glfw/include",
"./libs/tinygltf",
"./libs/glew/include",
"./libs/spdlog/include",
"./libs/glm",
"./MyGraphicsEngine/include"
}
libdirs{
"./libs/spdlog/build/Release",
"./libs/assimp/lib/Debug",
"./libs/glfw/build/src/Debug"
}
links {
"spdlog",
"assimp-vc143-mtd",
"glfw3"
}
files {
"./libs/glad/src/glad.c",
"./MyGraphicsEngine/**/*.*" ,
"./MyGraphicsEngine/*.*"
}
filter "configurations:Debug"
defines {"DEBUG"}
symbols "On"
filter "configurations:Release"
defines {"NDEBUG"}
optimize "On"
include("./BarinkEngine")
include("./MyGraphicsEngine")