Graphics Engine is now part of the whole engine instead, Project will

actually compile #9
This commit is contained in:
Nigel Barink 2022-05-28 13:32:17 +02:00
parent 3446bc2399
commit dae8830e2b
27 changed files with 401 additions and 394 deletions

View File

@ -1,4 +1,4 @@
#include "Include/BarinkEngine.h" #include "BarinkEngine.h"
extern void Start(int argc, char* argv[]); extern void Start(int argc, char* argv[]);
extern void UpdateApplication(); extern void UpdateApplication();
@ -31,4 +31,7 @@ int main(int argc, char* argv[]) {
} }
void WARN(std::string message) {
spdlog::warn(message);
}

View File

@ -1,26 +1,26 @@
#pragma once #pragma once
#define TINYGLTF_IMPLEMENTATION #define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
#define TINYGLTF_NO_EXTERNAL_IMAGE #define TINYGLTF_NO_EXTERNAL_IMAGE
#include "../MyGraphicsEngine/Mesh.h" #include "Graphics/Mesh.h"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <string> #include <string>
class ModelImporter { class ModelImporter {
private: private:
void ImportFBX(std::string path); void ImportFBX(std::string path);
void ImportBlend(std::string path); void ImportBlend(std::string path);
void ImportGLTF(std::string path); void ImportGLTF(std::string path);
void ImportOBJ(std::string path); void ImportOBJ(std::string path);
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene); static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene); static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
public: public:
void Import(std::string path); void Import(std::string path);
static std::vector<BarinkEngine::Mesh> Test(); static std::vector<BarinkEngine::Mesh> Test();
}; };

View File

@ -2,21 +2,19 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <filesystem> #include <filesystem>
#include "Engine.h" #include "Engine.h"
#include "glm/glm.hpp"
#include <spdlog/spdlog.h>
/*
#include "../MemoryManager.h"
#include <glm/glm.hpp>
#include <MyGraphicsEngine/Shader.h> #include "graphics/Shader.h"
#include <MyGraphicsEngine/Window.h> #include "graphics/Window.h"
#include <MyGraphicsEngine/Camera.h> #include "graphics/Camera.h"
#include <MyGraphicsEngine/Renderable.h> #include "graphics/Renderable.h"
#include "spdlog/spdlog.h"
#include "MemoryManager.h"
extern "C" extern "C"
{ {
@ -24,5 +22,4 @@ extern "C"
#include "lua.h" #include "lua.h"
#include "lualib.h" #include "lualib.h"
} }
void WARN(std::string message);
*/

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <string> #include <string>
class EditorWindow { class EditorWindow {
protected: protected:
std::string WindowTitle; std::string WindowTitle;
public: public:
virtual void Show() = 0; virtual void Show() = 0;
}; };

View File

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

View File

@ -1,19 +1,19 @@
#pragma once #pragma once
#include <glad/glad.h> #include <glad/glad.h>
class Buffer { class Buffer {
private: private:
unsigned int id; unsigned int id;
public: public:
int getBufferID(); int getBufferID();
void createBuffer(); void createBuffer();
void setBufferData(void* data, size_t dataSize, bool elementBuffer ); void setBufferData(void* data, size_t dataSize, bool elementBuffer );
void Bind(bool elementBuffer); void Bind(bool elementBuffer);
void Unbind(bool elementBuffer); void Unbind(bool elementBuffer);
void Delete(); void Delete();
}; };

View File

@ -1,13 +1,13 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <glm/glm.hpp> #include <glm/glm.hpp>
namespace BarinkEngine{ namespace BarinkEngine{
class Mesh { class Mesh {
public: public:
std::vector<glm::vec3> vertices; std::vector<glm::vec3> vertices;
std::vector<unsigned int > elements; std::vector<unsigned int > elements;
std::vector<glm::vec2> uv; std::vector<glm::vec2> uv;
}; };
} }

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <glm/glm.hpp> #include <glm/glm.hpp>
struct Transform { struct Transform {
glm::vec3 Position; glm::vec3 Position;
glm::vec3 Rotation; glm::vec3 Rotation;
glm::vec3 Scale; glm::vec3 Scale;
}; };

View File

@ -1,18 +1,18 @@
#pragma once #pragma once
class VertexArray{ class VertexArray{
private: private:
unsigned int id; unsigned int id;
public: public:
void Create(); void Create();
void Bind(); void Bind();
void Unbind(); void Unbind();
void Delete(); void Delete();
void AttachAttribute(unsigned int index, int size, int stride); void AttachAttribute(unsigned int index, int size, int stride);
}; };

View File

@ -5,12 +5,12 @@
static int HeapAllocations = 0; static int HeapAllocations = 0;
static int HeapDeallocations = 0; static int HeapDeallocations = 0;
void* operator new(std::size_t sz) { inline void* operator new(std::size_t sz) {
HeapAllocations++; HeapAllocations++;
return std::malloc(sz); return std::malloc(sz);
} }
void operator delete(void* ptr) noexcept { inline void operator delete(void* ptr) noexcept {
HeapDeallocations++; HeapDeallocations++;
std::free(ptr); std::free(ptr);
} }

View File

@ -1,47 +1,47 @@
#include "include/MyGraphicsEngine/Buffer.h" #include "Graphics/Buffer.h"
int Buffer::getBufferID() { int Buffer::getBufferID() {
return id; return id;
} }
void Buffer::createBuffer() { void Buffer::createBuffer() {
glGenBuffers(1, (GLuint*) &id); glGenBuffers(1, (GLuint*) &id);
} }
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) { void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
if (elementBuffer) { if (elementBuffer) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
} }
else { else {
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
} }
} }
void Buffer::Bind(bool elementBuffer = false ) { void Buffer::Bind(bool elementBuffer = false ) {
if (elementBuffer) { if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
} }
else { else {
glBindBuffer(GL_ARRAY_BUFFER, id); glBindBuffer(GL_ARRAY_BUFFER, id);
} }
} }
void Buffer::Unbind(bool elementBuffer = false) { void Buffer::Unbind(bool elementBuffer = false) {
if (elementBuffer) { if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} }
else { else {
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
} }
} }
void Buffer::Delete() { void Buffer::Delete() {
glDeleteBuffers(1, (GLuint*) &id); glDeleteBuffers(1, (GLuint*) &id);
} }

View File

@ -1,22 +1,22 @@
#include "include/MyGraphicsEngine/Camera.h" #include "Graphics/Camera.h"
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom) Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
: Position(position), Rotation(rotation), Zoom(zoom) { : Position(position), Rotation(rotation), Zoom(zoom) {
Front = glm::vec3(-1.0f, 0.0f, 0.0f); Front = glm::vec3(-1.0f, 0.0f, 0.0f);
Right = glm::vec3(0.0f, 0.0f, 1.0f); Right = glm::vec3(0.0f, 0.0f, 1.0f);
Up = glm::vec3(0.0f, 1.0f, 0.0f); Up = glm::vec3(0.0f, 1.0f, 0.0f);
} }
Camera::~Camera() { Camera::~Camera() {
} }
glm::mat4 Camera::GetViewMatrix() { glm::mat4 Camera::GetViewMatrix() {
return glm::lookAt( return glm::lookAt(
Position, Position,
Position + Front, Position + Front,
Up Up
); );
} }

View File

@ -1,117 +1,117 @@
#include "include/AssetManager/ModelImporter.h" #include "AssetManager/ModelImporter.h"
void ModelImporter::ImportFBX(std::string path) void ModelImporter::ImportFBX(std::string path)
{ {
//spdlog::warn("ImportFBX not implemented!"); //spdlog::warn("ImportFBX not implemented!");
} }
void ModelImporter::ImportBlend(std::string path) void ModelImporter::ImportBlend(std::string path)
{ {
//spdlog::warn("ImportBlend not implemented!"); //spdlog::warn("ImportBlend not implemented!");
} }
void ModelImporter::ImportGLTF(std::string path) void ModelImporter::ImportGLTF(std::string path)
{ {
//spdlog::warn("ImportGLTF not implemented!"); //spdlog::warn("ImportGLTF not implemented!");
} }
void ModelImporter::ImportOBJ(std::string path) void ModelImporter::ImportOBJ(std::string path)
{ {
//spdlog::warn("ImportOBJ not implemented!"); //spdlog::warn("ImportOBJ not implemented!");
} }
void ModelImporter::Import(std::string path) void ModelImporter::Import(std::string path)
{ {
//spdlog::warn("Import not implemented!"); //spdlog::warn("Import not implemented!");
} }
std::vector<BarinkEngine::Mesh> ModelImporter::Test() { std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
/* /*
spdlog::info("====== Tiny GLTF ======"); spdlog::info("====== Tiny GLTF ======");
tinygltf::Model loadedModel; tinygltf::Model loadedModel;
tinygltf::TinyGLTF loader; tinygltf::TinyGLTF loader;
std::string error; std::string error;
std::string warn; std::string warn;
bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf"); bool ret = loader.LoadASCIIFromFile(&loadedModel, &error, &warn, "./Build/SandboxApplication/Debug/sponza.gltf");
if (!warn.empty()) if (!warn.empty())
spdlog::warn("TinyGLTF Warning: {}", warn); spdlog::warn("TinyGLTF Warning: {}", warn);
if (!error.empty()) if (!error.empty())
spdlog::error("TinyGLTF Error: {}", error); spdlog::error("TinyGLTF Error: {}", error);
if (!ret) { if (!ret) {
spdlog::error("TinyGLTF Error: Failed to parse glTF"); spdlog::error("TinyGLTF Error: Failed to parse glTF");
exit(-1); exit(-1);
} }
spdlog::info("Meshes in model: {}", loadedModel.meshes.size()); spdlog::info("Meshes in model: {}", loadedModel.meshes.size());
spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size()); spdlog::info("Primitives in mesh: {}", loadedModel.meshes[0].primitives.size());
*/ */
//spdlog::info("======= Assimp ======"); //spdlog::info("======= Assimp ======");
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs); const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
aiNode* currentNode = scene->mRootNode; aiNode* currentNode = scene->mRootNode;
return processNode(currentNode, scene); return processNode(currentNode, scene);
} }
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) { std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
std::vector<BarinkEngine::Mesh> meshes; std::vector<BarinkEngine::Mesh> meshes;
for (unsigned int i = 0; i < node->mNumMeshes; i++) { for (unsigned int i = 0; i < node->mNumMeshes; i++) {
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
meshes.push_back(processMesh(mesh, scene)); meshes.push_back(processMesh(mesh, scene));
} }
for (unsigned int i = 0; i < node->mNumChildren; i++) { for (unsigned int i = 0; i < node->mNumChildren; i++) {
auto m2 = processNode(node->mChildren[i], scene); auto m2 = processNode(node->mChildren[i], scene);
for(auto m : m2) { for(auto m : m2) {
meshes.push_back(m); meshes.push_back(m);
} }
} }
return meshes; return meshes;
} }
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) { BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
std::vector<glm::vec3> vertices ; std::vector<glm::vec3> vertices ;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
// Process vertices // Process vertices
for (unsigned int i = 0; i < mesh->mNumVertices; i++) { for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
glm::vec3 vector; glm::vec3 vector;
vector.x = mesh->mVertices[i].x; vector.x = mesh->mVertices[i].x;
vector.y = mesh->mVertices[i].y; vector.y = mesh->mVertices[i].y;
vector.z = mesh->mVertices[i].z; vector.z = mesh->mVertices[i].z;
vertices.push_back(vector); vertices.push_back(vector);
} }
//spdlog::info("{} == {}", mesh->mNumVertices, vertices.size()); //spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
// Process Indices // Process Indices
for (unsigned int i = 0; i < mesh->mNumFaces; i++) { for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
aiFace face = mesh->mFaces[i]; aiFace face = mesh->mFaces[i];
if (face.mNumIndices < 3) if (face.mNumIndices < 3)
continue; continue;
for (unsigned int j = 0; j < face.mNumIndices; j++) { for (unsigned int j = 0; j < face.mNumIndices; j++) {
indices.push_back(face.mIndices[j]); indices.push_back(face.mIndices[j]);
} }
} }
BarinkEngine::Mesh result; BarinkEngine::Mesh result;
result.vertices = vertices; result.vertices = vertices;
result.elements = indices; result.elements = indices;
return result; return result;
} }

View File

@ -1,5 +1,7 @@
#include "include/MyGraphicsEngine/Renderable.h" #include "Graphics/Renderable.h"
#include "include/AssetManager/ModelImporter.h" #include "AssetManager/ModelImporter.h"
Renderable Renderable::Load() Renderable Renderable::Load()
{ {

View File

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

View File

@ -1,25 +1,25 @@
#include "include/MyGraphicsEngine/VertexArray.h" #include "Graphics/VertexArray.h"
#include <glad/glad.h> #include <glad/glad.h>
void VertexArray::Create(){ void VertexArray::Create(){
glGenVertexArrays(1, &id); glGenVertexArrays(1, &id);
} }
void VertexArray::Bind(){ void VertexArray::Bind(){
glBindVertexArray(id); glBindVertexArray(id);
} }
void VertexArray::Unbind(){ void VertexArray::Unbind(){
glBindVertexArray(0); glBindVertexArray(0);
} }
void VertexArray::Delete() { void VertexArray::Delete() {
glDeleteVertexArrays(1, &id); glDeleteVertexArrays(1, &id);
} }
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){ void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0); glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
} }

View File

@ -1,7 +1,7 @@
#version 440 core #version 440 core
out vec4 FragColor; out vec4 FragColor;
void main(){ void main(){
FragColor = vec4(0.5f, 0.5f, 0.0f , 1.0f); FragColor = vec4(0.5f, 0.5f, 0.0f , 1.0f);
} }

View File

@ -1,4 +1,4 @@
#include "include/MyGraphicsEngine/Window.h" #include "Graphics/Window.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -51,11 +51,11 @@ Width(width), Height(height), FullScreen(false){
BarinkWindow::~BarinkWindow(){ BarinkWindow::~BarinkWindow(){
glfwTerminate(); glfwTerminate();
} }
GLFWwindow* BarinkWindow::windowptr() GLFWwindow* BarinkWindow::windowptr()
{ {
return window; return window;
} }
bool BarinkWindow::WindowShouldClose(){ bool BarinkWindow::WindowShouldClose(){

View File

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

View File

@ -1,49 +0,0 @@
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,10 +1,20 @@
#include <BarinkEngine.h> #include "BarinkEngine.h"
void Start(int argc, char* argv[]) { void Start(int argc, char* argv[]) {
std::cout << "Hello start!" << std::endl; std::cout << "Hello start!" << std::endl;
std::cout << "h" << std::endl; std::cout << "h" << std::endl;
// BarinkWindow GameWindow(800, 600);
char cwd[256];
memset(cwd, '\0', 256);
// getcwd(cwd, 256);
//spdlog::info("Working directory: {}", cwd);
WARN("Hello warning");
// BarinkWindow GameWindow(800, 600);
} }

View File

@ -29,7 +29,29 @@ workspace "BarinkEngine"
} }
includedirs{ includedirs{
"./BarinkEngine/include" "./BarinkEngine/Include",
-- I'd prefer if didn't need these..
-- We'll figure that out some time later
"./libs/lua/include",
"./libs/spdlog/include",
"./libs/glm",
"./libs/GorillaAudio/include",
"./libs/assimp/include",
"./libs/glad/include",
"./libs/glfw/include",
"./libs/tinygltf",
"./libs/glew/include",
"./libs/glm",
"./libs/ImGui",
}
libdirs {
'./build/BarinkEngine/Debug'
} }
files { files {
@ -38,6 +60,4 @@ workspace "BarinkEngine"
} }
include("./BarinkEngine") include("./BarinkEngine")
include("./MyGraphicsEngine")