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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
#include "include/MyGraphicsEngine/Renderable.h"
#include "include/AssetManager/ModelImporter.h"
#include "Graphics/Renderable.h"
#include "AssetManager/ModelImporter.h"
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)
{

View File

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

View File

@ -1,7 +1,7 @@
#version 440 core
out vec4 FragColor;
void main(){
FragColor = vec4(0.5f, 0.5f, 0.0f , 1.0f);
#version 440 core
out vec4 FragColor;
void main(){
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 <stdio.h>
@ -51,11 +51,11 @@ Width(width), Height(height), FullScreen(false){
BarinkWindow::~BarinkWindow(){
glfwTerminate();
}
GLFWwindow* BarinkWindow::windowptr()
{
return window;
}
GLFWwindow* BarinkWindow::windowptr()
{
return window;
}
bool BarinkWindow::WindowShouldClose(){

View File

@ -3,32 +3,56 @@ project "BarinkEngine"
buildmessage "Building BarinkEngine"
includedirs{
"./../libs/lua/include",
"./libs/spdlog/include",
includedirs {
"Include/",
"./../libs/glm",
"./../MyGraphicsEngine/include",
"../libs/lua/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 {
"./../libs/lua",
"./../libs/spdlog/build/Release"
"../libs/lua",
"../libs/spdlog/build/Release",
"../libs/assimp/lib/Debug",
"../libs/glfw/build/src/Debug",
"../libs/ImGui"
}
links {
"lua54",
"spdlog",
"MyGraphicsEngine"
"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",
"./**/*.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[]) {
std::cout << "Hello start!" << 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{
"./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 {
@ -38,6 +60,4 @@ workspace "BarinkEngine"
}
include("./BarinkEngine")
include("./MyGraphicsEngine")
include("./BarinkEngine")