Compare commits
21 Commits
85f9c78adf
...
adf2331ab1
Author | SHA1 | Date | |
---|---|---|---|
adf2331ab1 | |||
99eb5282e5 | |||
bc1254e427 | |||
7458254b2d | |||
b359a940ba | |||
e0e8de90b1 | |||
23ac663667 | |||
955eeabb48 | |||
29e715b92a | |||
463a9ff307 | |||
cbbdafcb3e | |||
b03b82272f | |||
3974889f7e | |||
db6def3bc9 | |||
ab5599f1fc | |||
3639f967e1 | |||
5a06b068f3 | |||
e31fd036ea | |||
6a2e8d3b2f | |||
f8b390923e | |||
b7e3465406 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,12 +1,11 @@
|
|||||||
build/
|
**/build/
|
||||||
intermediates/
|
**/intermediates/
|
||||||
tools/
|
tools/
|
||||||
*.make
|
*.make
|
||||||
Makefile
|
Makefile
|
||||||
.vscode/
|
.vscode/
|
||||||
libs/lua
|
libs/lua
|
||||||
libs/glad
|
libs/glad
|
||||||
Debug/
|
|
||||||
*.sln
|
*.sln
|
||||||
*.vcxproj
|
*.vcxproj
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -4,12 +4,14 @@
|
|||||||
[submodule "glm"]
|
[submodule "glm"]
|
||||||
path = libs/glm
|
path = libs/glm
|
||||||
url = https://github.com/nigelbarink/glm.git
|
url = https://github.com/nigelbarink/glm.git
|
||||||
|
ignore = untracked
|
||||||
[submodule "spdlog"]
|
[submodule "spdlog"]
|
||||||
path = libs/spdlog
|
path = libs/spdlog
|
||||||
url = https://github.com/nigelbarink/spdlog.git
|
url = https://github.com/nigelbarink/spdlog.git
|
||||||
[submodule "tinygltf"]
|
[submodule "tinygltf"]
|
||||||
path = libs/tinygltf
|
path = libs/tinygltf
|
||||||
url = https://github.com/syoyo/tinygltf.git
|
url = https://github.com/syoyo/tinygltf.git
|
||||||
|
ignore = untracked
|
||||||
[submodule "GorrillaAudio"]
|
[submodule "GorrillaAudio"]
|
||||||
path = libs/GorillaAudio
|
path = libs/GorillaAudio
|
||||||
url = https://github.com/mewspring/gorilla-audio.git
|
url = https://github.com/mewspring/gorilla-audio.git
|
||||||
@ -22,6 +24,10 @@
|
|||||||
[submodule "libs/steam-audio"]
|
[submodule "libs/steam-audio"]
|
||||||
path = libs/steam-audio
|
path = libs/steam-audio
|
||||||
url = https://github.com/ValveSoftware/steam-audio.git
|
url = https://github.com/ValveSoftware/steam-audio.git
|
||||||
|
ignore = untracked
|
||||||
[submodule "libs/physx"]
|
[submodule "libs/physx"]
|
||||||
path = libs/physx
|
path = libs/physx
|
||||||
url = https://git.barink.dev/Nigel/PhysX.git
|
url = https://git.barink.dev/Nigel/PhysX.git
|
||||||
|
[submodule "libs/entt"]
|
||||||
|
path = libs/entt
|
||||||
|
url = https://github.com/skypjack/entt.git
|
||||||
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"cmake.configureOnOpen": true,
|
|
||||||
"files.associations": {
|
|
||||||
"iosfwd": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#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();
|
|
||||||
};
|
|
@ -1,24 +0,0 @@
|
|||||||
#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/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 void Start();
|
|
||||||
extern void Update();
|
|
||||||
extern void ImmediateGraphicsDraw();
|
|
||||||
extern void Stop();
|
|
||||||
|
|
||||||
extern BarinkEngine::InputManager InputSystem;
|
|
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class EditorWindow {
|
|
||||||
protected:
|
|
||||||
std::string WindowTitle;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void Show() = 0;
|
|
||||||
|
|
||||||
};
|
|
@ -1,5 +0,0 @@
|
|||||||
#include "EventListener.h"
|
|
||||||
|
|
||||||
void EventListener::ReceiveEvent(Event& incident)
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Event.h"
|
|
||||||
#include <list>
|
|
||||||
class EventListener{
|
|
||||||
public:
|
|
||||||
virtual void ReceiveEvent(Event& incident);
|
|
||||||
|
|
||||||
};
|
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace BarinkEngine{
|
|
||||||
|
|
||||||
|
|
||||||
struct Vertex {
|
|
||||||
glm::vec3 vertices;
|
|
||||||
glm::vec2 uv;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Mesh {
|
|
||||||
public:
|
|
||||||
std::vector<Vertex> vertices;
|
|
||||||
std::vector<unsigned int > elements;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include "Mesh.h"
|
|
||||||
#include "Buffer.h"
|
|
||||||
#include "Material.h"
|
|
||||||
#include "Texture.h"
|
|
||||||
#include "VertexArray.h"
|
|
||||||
#include "Scene.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Renderable : public SceneNode {
|
|
||||||
public:
|
|
||||||
/*
|
|
||||||
* NOTE: Should combine into a Mesh!!
|
|
||||||
*/
|
|
||||||
Buffer vertexBuffer;
|
|
||||||
Buffer elementBuffer;
|
|
||||||
//Buffer uv;
|
|
||||||
VertexArray VAO;
|
|
||||||
|
|
||||||
|
|
||||||
GLuint UV_id;
|
|
||||||
Material* material;
|
|
||||||
Texture* texture;
|
|
||||||
|
|
||||||
|
|
||||||
Shader* shader;
|
|
||||||
|
|
||||||
~Renderable();
|
|
||||||
|
|
||||||
static Renderable* Load();
|
|
||||||
void Draw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<BarinkEngine::Mesh> meshes;
|
|
||||||
Renderable();
|
|
||||||
};
|
|
@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Graphics/Renderable.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace BarinkEngine {
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
public:
|
|
||||||
Renderer();
|
|
||||||
~Renderer();
|
|
||||||
|
|
||||||
void Render();
|
|
||||||
|
|
||||||
void Submit(Renderable* model);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<Renderable*> models;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <chrono>
|
|
||||||
#include <imgui.h>
|
|
||||||
|
|
||||||
struct EngineStatistics {
|
|
||||||
uint32_t lastSampleTime;
|
|
||||||
float frameTime;
|
|
||||||
uint32_t verts;
|
|
||||||
uint32_t DC;
|
|
||||||
|
|
||||||
uint64_t frames;
|
|
||||||
uint64_t FPS;
|
|
||||||
};
|
|
||||||
extern EngineStatistics* ES;
|
|
||||||
|
|
||||||
inline void PerfomanceSamplerInit(){
|
|
||||||
ES = new EngineStatistics();
|
|
||||||
ES->frames = 0;
|
|
||||||
ES->lastSampleTime = 0;
|
|
||||||
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void SamplePerformance(void) {
|
|
||||||
ES->frames++;
|
|
||||||
ES->DC = 0;
|
|
||||||
ES->verts = 0;
|
|
||||||
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
|
||||||
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
|
|
||||||
if (MilliSecondsPast >= 1000) {
|
|
||||||
|
|
||||||
ES->frameTime = (float)1000 / ES->frames;
|
|
||||||
ES->FPS = ES->frames;
|
|
||||||
ES->frames = 0;
|
|
||||||
ES->lastSampleTime = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void ShowStats() {
|
|
||||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
|
||||||
|
|
||||||
ImGui::Text("FPS: %i", ES->FPS);
|
|
||||||
ImGui::Text("Frame Time: %f", ES->frameTime);
|
|
||||||
ImGui::Text("Verts: %i", ES->verts);
|
|
||||||
ImGui::Text("Draw Calls: %i", ES->DC);
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "glm/glm.hpp"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Scene should be a description of a game world
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct Transform {
|
|
||||||
glm::vec3 Position;
|
|
||||||
glm::vec3 Rotation;
|
|
||||||
glm::vec3 Scale;
|
|
||||||
|
|
||||||
glm::mat4 ModelMatrix;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class SceneNode {
|
|
||||||
public:
|
|
||||||
std::string name;
|
|
||||||
Transform transform;
|
|
||||||
SceneNode* parent;
|
|
||||||
std::vector<SceneNode*> children;
|
|
||||||
|
|
||||||
|
|
||||||
void addChild(SceneNode& node);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Scene {
|
|
||||||
|
|
||||||
public:
|
|
||||||
SceneNode& GetSceneNode(std::string);
|
|
||||||
SceneNode& GetRoot();
|
|
||||||
|
|
||||||
Scene(std::string SceneName = "Default Scene");
|
|
||||||
~Scene();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
SceneNode* root;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
|||||||
#include "Scene.h"
|
|
||||||
|
|
||||||
|
|
||||||
SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
|
|
||||||
|
|
||||||
if (root->name == name)
|
|
||||||
return root;
|
|
||||||
|
|
||||||
SceneNode* found = nullptr;
|
|
||||||
for (auto child : root->children) {
|
|
||||||
found = SearchInChildren(child, name);
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SceneNode& Scene::GetSceneNode(std::string name)
|
|
||||||
{
|
|
||||||
return *SearchInChildren(root, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SceneNode& Scene::GetRoot()
|
|
||||||
{
|
|
||||||
return *root;
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene::Scene(std::string sceneName)
|
|
||||||
{
|
|
||||||
// Create a root node
|
|
||||||
root = new SceneNode();
|
|
||||||
root->name = sceneName;
|
|
||||||
root->transform = Transform();
|
|
||||||
|
|
||||||
root->transform.Position = glm::vec3(0);
|
|
||||||
root->transform.Rotation = glm::vec3(0);
|
|
||||||
root->transform.Scale = glm::vec3(0);
|
|
||||||
|
|
||||||
root->transform.ModelMatrix = glm::mat4(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene::~Scene()
|
|
||||||
{
|
|
||||||
// Destruct scene!
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneNode::addChild(SceneNode& node)
|
|
||||||
{
|
|
||||||
children.push_back(&node);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
#include "Graphics/GUI/GUIManager.h"
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "backends/imgui_impl_opengl3.h"
|
|
||||||
#include <backends/imgui_impl_glfw.cpp>
|
|
||||||
|
|
||||||
GUIManager::GUIManager(BarinkWindow* window)
|
|
||||||
: currentwindow(window)
|
|
||||||
{
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
(void)io;
|
|
||||||
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true);
|
|
||||||
ImGui_ImplOpenGL3_Init("#version 440");
|
|
||||||
|
|
||||||
|
|
||||||
ImGui_ImplGlfw_NewFrame();
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
GUIManager::~GUIManager()
|
|
||||||
{
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GUIManager::Render()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::Render();
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
#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/Models/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<unsigned int> indices;
|
|
||||||
std::vector<BarinkEngine::Vertex> vertices;
|
|
||||||
|
|
||||||
// Process vertices
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
|
||||||
BarinkEngine::Vertex v{};
|
|
||||||
glm::vec3 vector;
|
|
||||||
vector.x = mesh->mVertices[i].x;
|
|
||||||
vector.y = mesh->mVertices[i].y;
|
|
||||||
vector.z = mesh->mVertices[i].z;
|
|
||||||
|
|
||||||
v.vertices = vector;
|
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0]) {
|
|
||||||
|
|
||||||
glm::vec2 texCoord;
|
|
||||||
|
|
||||||
texCoord.x = mesh->mTextureCoords[0][i].x;
|
|
||||||
texCoord.y = mesh->mTextureCoords[0][i].y;
|
|
||||||
|
|
||||||
v.uv = texCoord;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
vertices.push_back(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
#include "Graphics/Renderable.h"
|
|
||||||
#include "AssetManager/ModelImporter.h"
|
|
||||||
#include "PerfCounter.h"
|
|
||||||
|
|
||||||
|
|
||||||
Renderable* Renderable::Load()
|
|
||||||
{
|
|
||||||
return new Renderable();
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderable::Renderable()
|
|
||||||
{
|
|
||||||
meshes = ModelImporter::Test();
|
|
||||||
|
|
||||||
transform.Scale = glm::vec3(1.0f);
|
|
||||||
transform.Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
transform.Position = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
VAO.Create();
|
|
||||||
VAO.Bind();
|
|
||||||
|
|
||||||
|
|
||||||
vertexBuffer.createBuffer();
|
|
||||||
vertexBuffer.Bind(false);
|
|
||||||
vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
|
||||||
|
|
||||||
elementBuffer.createBuffer();
|
|
||||||
elementBuffer.Bind(true);
|
|
||||||
elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
|
|
||||||
|
|
||||||
VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
|
||||||
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices));
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
vertexBuffer.Unbind(false);
|
|
||||||
|
|
||||||
VAO.Unbind();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderable::~Renderable()
|
|
||||||
{
|
|
||||||
glDeleteBuffers(1, &UV_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderable::Draw()
|
|
||||||
{
|
|
||||||
VAO.Bind();
|
|
||||||
elementBuffer.Bind(true);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
|
|
||||||
texture->Bind();
|
|
||||||
|
|
||||||
ES->verts = meshes[0].vertices.size();
|
|
||||||
ES->DC++;
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
|
|
||||||
VAO.Unbind();
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#include "Graphics/Renderer.h"
|
|
||||||
|
|
||||||
BarinkEngine::Renderer::Renderer()
|
|
||||||
{
|
|
||||||
models = std::vector<Renderable*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
BarinkEngine::Renderer::~Renderer()
|
|
||||||
{
|
|
||||||
// CleanUp!
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::Renderer::Render()
|
|
||||||
{
|
|
||||||
|
|
||||||
for (auto model : models) {
|
|
||||||
model->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::Renderer::Submit(Renderable* model)
|
|
||||||
{
|
|
||||||
models.push_back(model);
|
|
||||||
}
|
|
@ -4,25 +4,25 @@ project "BarinkEngine"
|
|||||||
buildmessage "Building BarinkEngine"
|
buildmessage "Building BarinkEngine"
|
||||||
|
|
||||||
includedirs {
|
includedirs {
|
||||||
"Include/",
|
|
||||||
|
|
||||||
"../libs/lua/include",
|
|
||||||
"../libs/spdlog/include",
|
"../libs/spdlog/include",
|
||||||
"../libs/glm",
|
"../libs/glm",
|
||||||
"../libs/GorillaAudio/include",
|
|
||||||
|
|
||||||
"../libs/physx/physx/include",
|
|
||||||
"../libs/steam-audio/include",
|
|
||||||
|
|
||||||
"../libs/assimp/include",
|
|
||||||
|
|
||||||
|
|
||||||
"../libs/glad/include",
|
|
||||||
|
|
||||||
"../libs/glfw/include",
|
"../libs/glfw/include",
|
||||||
"../libs/glew/include",
|
"../libs/glew/include",
|
||||||
"../libs/glm",
|
"../libs/glad/include",
|
||||||
|
|
||||||
|
|
||||||
|
"../libs/assimp/include",
|
||||||
|
"../libs/entt/src",
|
||||||
|
|
||||||
|
"../libs/physx/physx/include",
|
||||||
|
|
||||||
|
"../libs/lua/include",
|
||||||
|
|
||||||
|
"../libs/GorillaAudio/include",
|
||||||
|
"../libs/steam-audio/include",
|
||||||
|
|
||||||
|
|
||||||
"../libs/ImGui",
|
"../libs/ImGui",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,11 +33,7 @@ project "BarinkEngine"
|
|||||||
"spdlog",
|
"spdlog",
|
||||||
"assimp-vc143-mtd",
|
"assimp-vc143-mtd",
|
||||||
"glfw3",
|
"glfw3",
|
||||||
|
"ImGui",
|
||||||
"ImGUI_Opengl3",
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,32 +48,15 @@ project "BarinkEngine"
|
|||||||
files {
|
files {
|
||||||
"../libs/glad/src/glad.c",
|
"../libs/glad/src/glad.c",
|
||||||
|
|
||||||
"./*.cpp",
|
"./src/*.cpp",
|
||||||
"./*.h",
|
"./src/*.h",
|
||||||
"./**/*.cpp",
|
"./src/**/*.cpp",
|
||||||
"./**/*.h"
|
"./src/**/*.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prebuildcommands
|
||||||
|
{
|
||||||
filter { "system:windows"}
|
ok,err = os.copyfile("BarinkEngine/src/Graphics/shaders/*" ,"SandboxApp/build/Debug/")
|
||||||
prebuildcommands {
|
}
|
||||||
-- Copy shaders
|
|
||||||
"copy graphics\\shaders\\fragment.shader ..\\build\\SandboxApplication\\Debug\\test.fs",
|
|
||||||
"copy graphics\\shaders\\vertex.shader ..\\build\\SandboxApplication\\Debug\\test.vs",
|
|
||||||
"copy graphics\\shaders\\RenderSurfaceFrag.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.fs",
|
|
||||||
"copy graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filter { "system:linux" }
|
|
||||||
prebuildcommands {
|
|
||||||
-- Copy shaders
|
|
||||||
"cp graphics/shaders/fragment.shader ../build/SandboxApplication/Debug/test.fs",
|
|
||||||
"cp graphics/shaders/vertex.shader ../build/SandboxApplication/Debug/test.vs",
|
|
||||||
"cp graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs",
|
|
||||||
"cp graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs"
|
|
||||||
}
|
|
||||||
|
|
||||||
include('../ImGui')
|
include('../ImGui')
|
||||||
|
99
BarinkEngine/src/AssetManager/ModelImporter.cpp
Normal file
99
BarinkEngine/src/AssetManager/ModelImporter.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include "ModelImporter.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
|
||||||
|
{
|
||||||
|
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
||||||
|
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
|
||||||
|
aiNode* currentNode = scene->mRootNode;
|
||||||
|
|
||||||
|
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
|
||||||
|
|
||||||
|
std::cout << "[DEBUG]: Loaded "<< meshes.size() << " meshes!" << std::endl;
|
||||||
|
|
||||||
|
// create a renderable (per mesh ?? )
|
||||||
|
root->renderable = new Renderable();
|
||||||
|
root->renderable->mesh = new Mesh(meshes[0]);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<BarinkEngine::Mesh> BarinkEngine::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 BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
|
std::vector<unsigned int> indices;
|
||||||
|
std::vector<BarinkEngine::Vertex> vertices;
|
||||||
|
|
||||||
|
ProcessVertices(mesh, vertices);
|
||||||
|
|
||||||
|
ProcessIndices(mesh, indices);
|
||||||
|
|
||||||
|
BarinkEngine::Mesh result;
|
||||||
|
result.vertices = vertices;
|
||||||
|
result.elements = indices;
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
|
||||||
|
// Process vertices
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
|
BarinkEngine::Vertex v{};
|
||||||
|
glm::vec3 vector;
|
||||||
|
vector.x = mesh->mVertices[i].x;
|
||||||
|
vector.y = mesh->mVertices[i].y;
|
||||||
|
vector.z = mesh->mVertices[i].z;
|
||||||
|
|
||||||
|
v.vertices = vector;
|
||||||
|
|
||||||
|
if (mesh->mTextureCoords[0]) {
|
||||||
|
|
||||||
|
glm::vec2 texCoord;
|
||||||
|
|
||||||
|
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||||
|
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||||
|
|
||||||
|
v.uv = texCoord;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
out_vertices.push_back(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices) {
|
||||||
|
// 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++) {
|
||||||
|
out_indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
BarinkEngine/src/AssetManager/ModelImporter.h
Normal file
35
BarinkEngine/src/AssetManager/ModelImporter.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
|
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||||
|
|
||||||
|
#include "../Graphics/Primitives/Mesh.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
#include <string>
|
||||||
|
#include "../Scene/TransformTree/SceneNodeTypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
|
||||||
|
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
class ModelImporter {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject* Import(const std::string path);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
|
||||||
|
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -1,64 +1,48 @@
|
|||||||
#include "BarinkEngine.h"
|
#include "BarinkEngine.h"
|
||||||
#include <phonon.h>
|
|
||||||
|
EngineStatistics ES;
|
||||||
EngineStatistics* ES;
|
BarinkEngine::Renderer renderer;
|
||||||
BarinkEngine::InputManager InputSystem;
|
int main(int argc, char* argv[]) {
|
||||||
|
// Setup performance sampler
|
||||||
int main(int argc, char* argv[]) {
|
PerfomanceSamplerInit();
|
||||||
// Setup performance sampler
|
|
||||||
PerfomanceSamplerInit();
|
// Startup services
|
||||||
|
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||||
|
|
||||||
// Startup services
|
renderer = BarinkEngine::Renderer();
|
||||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
InputSystem = BarinkEngine::InputManager();
|
||||||
|
ES = EngineStatistics();
|
||||||
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
|
||||||
InputSystem = BarinkEngine::InputManager();
|
InputSystem.attach(&MainWindow);
|
||||||
|
|
||||||
InputSystem.attach(&MainWindow);
|
GUIManager GUISystem = GUIManager(&MainWindow);
|
||||||
|
|
||||||
GUIManager GUISystem = GUIManager(&MainWindow);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
// First call to setup game
|
||||||
glEnable(GL_DEPTH_TEST);
|
Start();
|
||||||
|
|
||||||
|
// Runtime loop
|
||||||
|
while (!MainWindow.WindowShouldClose()) {
|
||||||
// First call to setup game
|
SamplePerformance();
|
||||||
Start();
|
|
||||||
|
// Execute main logic
|
||||||
|
InputSystem.PollEvents();
|
||||||
|
|
||||||
// Runtime loop
|
Update();
|
||||||
while (!MainWindow.WindowShouldClose()) {
|
|
||||||
|
GUISystem.Render();
|
||||||
SamplePerformance();
|
|
||||||
|
MainWindow.SwapBuffers();
|
||||||
|
|
||||||
// Execute main logic
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
InputSystem.PollEvents();
|
}
|
||||||
|
|
||||||
Update();
|
// Shutdown game
|
||||||
|
Stop();
|
||||||
renderer.Render();
|
|
||||||
|
// Shutdown Services
|
||||||
ImmediateGraphicsDraw();
|
|
||||||
|
return 0;
|
||||||
GUISystem.Render();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MainWindow.SwapBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Shutdown game
|
|
||||||
Stop();
|
|
||||||
|
|
||||||
|
|
||||||
// Shutdown Services
|
|
||||||
delete ES;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
24
BarinkEngine/src/BarinkEngine.h
Normal file
24
BarinkEngine/src/BarinkEngine.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#include "graphics/Primitives/Shader.h"
|
||||||
|
#include "Platform/Window.h"
|
||||||
|
#include "graphics/Primitives/Texture.h"
|
||||||
|
#include "graphics/Primitives/Camera.h"
|
||||||
|
#include "graphics/Renderable.h"
|
||||||
|
#include "Graphics/Renderer.h"
|
||||||
|
#include "Graphics/Primitives/Material.h"
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
#include "Input/InputManager.h"
|
||||||
|
#include "Graphics/Renderer.h"
|
||||||
|
#include "GUI/GUIManager.h"
|
||||||
|
#include "Scene/Scene.h"
|
||||||
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern BarinkEngine::Renderer renderer;
|
||||||
|
extern void Start();
|
||||||
|
extern void Update();
|
||||||
|
extern void ImmediateGraphicsDraw();
|
||||||
|
extern void Stop();
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
#include "../Include/EventSystem/EventEmitter.h"
|
#include "EventEmitter.h"
|
||||||
|
|
||||||
|
|
||||||
void EventEmitter::Subscribe(EventListener& subscriber)
|
void EventEmitter::Subscribe(EventListener& subscriber)
|
12
BarinkEngine/src/EventSystem/EventListener.h
Normal file
12
BarinkEngine/src/EventSystem/EventListener.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <list>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
class EventListener{
|
||||||
|
public:
|
||||||
|
virtual void ReceiveEvent(Event& incident) = 0 ;
|
||||||
|
|
||||||
|
};
|
53
BarinkEngine/src/GUI/GUIManager.cpp
Normal file
53
BarinkEngine/src/GUI/GUIManager.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "GUIManager.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "backends/imgui_impl_opengl3.h"
|
||||||
|
#include <backends/imgui_impl_glfw.h>
|
||||||
|
#include "../BarinkEngine.h"
|
||||||
|
|
||||||
|
GUIManager::GUIManager(BarinkWindow* window)
|
||||||
|
: currentwindow(window)
|
||||||
|
{
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_ViewportsEnable;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_::ImGuiConfigFlags_DockingEnable;
|
||||||
|
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true);
|
||||||
|
ImGui_ImplOpenGL3_Init("#version 440");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GUIManager::~GUIManager()
|
||||||
|
{
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GUIManager::Render()
|
||||||
|
{
|
||||||
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
ImGui::Begin("##App");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Graphics/Window.h"
|
#include "../Platform/Window.h"
|
||||||
|
|
||||||
|
|
||||||
class GUIManager {
|
class GUIManager {
|
@ -1,47 +1,47 @@
|
|||||||
#include "Graphics/Buffer.h"
|
#include "Buffer.h"
|
||||||
|
|
||||||
|
|
||||||
int Buffer::getBufferID() {
|
int GpuBuffer::getBufferID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::createBuffer() {
|
void GpuBuffer::createBuffer() {
|
||||||
glGenBuffers(1, (GLuint*) &id);
|
glGenBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
void GpuBuffer::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 GpuBuffer::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 GpuBuffer::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 GpuBuffer::Delete() {
|
||||||
glDeleteBuffers(1, (GLuint*) &id);
|
glDeleteBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
class Buffer {
|
class GpuBuffer {
|
||||||
private:
|
private:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
public:
|
public:
|
49
BarinkEngine/src/Graphics/Memory/FrameBuffer.cpp
Normal file
49
BarinkEngine/src/Graphics/Memory/FrameBuffer.cpp
Normal 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);
|
||||||
|
}
|
20
BarinkEngine/src/Graphics/Memory/Framebuffer.h
Normal file
20
BarinkEngine/src/Graphics/Memory/Framebuffer.h
Normal 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;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -1,25 +1,25 @@
|
|||||||
#include "Graphics/VertexArray.h"
|
#include "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);
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ void Create();
|
|||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
|
||||||
|
unsigned int getID() { return id; }
|
||||||
|
|
||||||
void Delete();
|
void Delete();
|
||||||
|
|
||||||
void AttachAttribute(unsigned int index, int size, int stride);
|
void AttachAttribute(unsigned int index, int size, int stride);
|
@ -1,4 +1,4 @@
|
|||||||
#include "Graphics/Camera.h"
|
#include "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) {
|
@ -1,10 +1,11 @@
|
|||||||
#include "../Include/Graphics/Material.h"
|
#include "Material.h"
|
||||||
|
|
||||||
Material::Material(const Shader& shader) :
|
Material::Material(const Shader& shader) :
|
||||||
shader(shader) {
|
shader(shader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Material::Apply() const {
|
||||||
void Material::Apply() {
|
|
||||||
shader.setUniformVec3("Color", Color);
|
shader.Use();
|
||||||
|
shader.setUniformVec3("Color", Color);
|
||||||
}
|
}
|
@ -1,19 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
class Material {
|
class Material {
|
||||||
public:
|
public:
|
||||||
Material(const Shader& shader);
|
Material(const Shader& shader);
|
||||||
|
|
||||||
void Apply();
|
void Apply()const;
|
||||||
|
glm::vec3 Color;
|
||||||
glm::vec3 Color;
|
const Shader& shader;
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Shader& shader;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
12
BarinkEngine/src/Graphics/Primitives/Mesh.h
Normal file
12
BarinkEngine/src/Graphics/Primitives/Mesh.h
Normal file
@ -0,0 +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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "Graphics/Shader.h"
|
#include "Shader.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
|
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
|
||||||
{
|
{
|
||||||
char infoLog[512];
|
char infoLog[512];
|
||||||
@ -57,8 +58,12 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Shader::readFile (const char* filePath){
|
char* Shader::readFile (const char* filePath){
|
||||||
|
|
||||||
|
spdlog::info("Opening {} ", filePath);
|
||||||
|
|
||||||
|
|
||||||
std::ifstream file ;
|
std::ifstream file ;
|
||||||
file.open(filePath);
|
file.open(filePath);
|
||||||
|
|
||||||
@ -90,7 +95,7 @@ char* Shader::readFile (const char* filePath){
|
|||||||
return FileBuffer;
|
return FileBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::Use()
|
void Shader::Use() const
|
||||||
{
|
{
|
||||||
glUseProgram(id);
|
glUseProgram(id);
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ class Shader {
|
|||||||
char* readFile (const char* filePath);
|
char* readFile (const char* filePath);
|
||||||
public:
|
public:
|
||||||
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
|
||||||
void Use();
|
void Use() const;
|
||||||
void setUniformMat4(std::string uniformName, glm::mat4 matrix4)const;
|
void setUniformMat4(std::string uniformName, glm::mat4 matrix4)const;
|
||||||
void setUniformVec4(std::string uniformName, glm::vec4 vector4)const;
|
void setUniformVec4(std::string uniformName, glm::vec4 vector4)const;
|
||||||
void setUniformVec3(std::string uniformName, glm::vec3 vector3)const;
|
void setUniformVec3(std::string uniformName, glm::vec3 vector3)const;
|
@ -1,40 +1,40 @@
|
|||||||
#include "../Include/Graphics/Texture.h"
|
#include "Texture.h"
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "Graphics/stb_image.h"
|
#include "../stb_image.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Texture::Texture(const std::string texturePath) {
|
Texture::Texture(const std::string texturePath) {
|
||||||
|
|
||||||
int width, height, channels;
|
int width, height, channels;
|
||||||
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
|
||||||
std::cout << channels << std::endl;
|
std::cout << channels << std::endl;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
glGenTextures(1, &Id);
|
glGenTextures(1, &Id);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, Id);
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spdlog::error("Failed to load image (%s)", texturePath );
|
spdlog::error("Failed to load image (%s)", texturePath );
|
||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::Bind() {
|
void Texture::Bind() {
|
||||||
glBindTexture(GL_TEXTURE_2D, Id);
|
glBindTexture(GL_TEXTURE_2D, Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::Unbind() {
|
void Texture::Unbind() {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
Texture(const std::string texturePath);
|
Texture(const std::string texturePath);
|
||||||
|
|
||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned int Id;
|
unsigned int Id;
|
||||||
|
|
||||||
};
|
};
|
9
BarinkEngine/src/Graphics/Primitives/Vertex.h
Normal file
9
BarinkEngine/src/Graphics/Primitives/Vertex.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
struct Vertex {
|
||||||
|
glm::vec3 vertices;
|
||||||
|
glm::vec2 uv;
|
||||||
|
};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#include "Graphics/RenderSurface.h";
|
#include "RenderSurface.h";
|
||||||
|
|
||||||
RenderSurface::RenderSurface(){
|
RenderSurface::RenderSurface(){
|
||||||
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");
|
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");
|
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "BarinkEngine.h"
|
#include "../BarinkEngine.h"
|
||||||
#include <vector>;
|
#include "../Graphics/Memory/Buffer.h"
|
||||||
|
#include "../Graphics/Memory/VertexArray.h"
|
||||||
|
#include <vector>
|
||||||
class RenderSurface
|
class RenderSurface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -20,8 +22,8 @@ private:
|
|||||||
std::vector<unsigned int > indices;
|
std::vector<unsigned int > indices;
|
||||||
|
|
||||||
|
|
||||||
Buffer vertexBuffer;
|
GpuBuffer vertexBuffer;
|
||||||
Buffer elementBuffer;
|
GpuBuffer elementBuffer;
|
||||||
|
|
||||||
VertexArray VAO;
|
VertexArray VAO;
|
||||||
|
|
14
BarinkEngine/src/Graphics/Renderable.h
Normal file
14
BarinkEngine/src/Graphics/Renderable.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Primitives/Mesh.h"
|
||||||
|
#include "Primitives/Material.h"
|
||||||
|
#include "Primitives/Texture.h"
|
||||||
|
#include "../Scene/Scene.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
|
||||||
|
struct Renderable {
|
||||||
|
BarinkEngine::Mesh* mesh;
|
||||||
|
Material* material;
|
||||||
|
Texture* texture;
|
||||||
|
};
|
||||||
|
}
|
75
BarinkEngine/src/Graphics/Renderer.cpp
Normal file
75
BarinkEngine/src/Graphics/Renderer.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "Renderer.h"
|
||||||
|
#include "../Scene/Components.h"
|
||||||
|
#include "../Graphics/Memory/VertexArray.h"
|
||||||
|
#include "../Graphics/Memory/Buffer.h"
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
float Angle = 0.0;
|
||||||
|
Camera cam = Camera(glm::vec3(12.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(){}
|
||||||
|
|
||||||
|
BarinkEngine::Renderer::~Renderer(){}
|
||||||
|
|
||||||
|
void BarinkEngine::Renderer::Prepare(Scene& scene ) {
|
||||||
|
auto group = scene.getReg().view<BarinkEngine::Render3DComponent>();
|
||||||
|
group.each([](auto enity, BarinkEngine::Render3DComponent& renderComponent) {
|
||||||
|
VertexArray va = VertexArray();
|
||||||
|
GpuBuffer vertexBuffer = GpuBuffer();
|
||||||
|
GpuBuffer elementBuffer = GpuBuffer();
|
||||||
|
|
||||||
|
va.Create();
|
||||||
|
va.Bind();
|
||||||
|
|
||||||
|
vertexBuffer.createBuffer();
|
||||||
|
vertexBuffer.Bind(false);
|
||||||
|
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||||
|
|
||||||
|
elementBuffer.createBuffer();
|
||||||
|
elementBuffer.Bind(true);
|
||||||
|
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
|
||||||
|
|
||||||
|
va.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||||
|
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
va.Unbind();
|
||||||
|
vertexBuffer.Unbind(false);
|
||||||
|
elementBuffer.Unbind(true);
|
||||||
|
|
||||||
|
renderComponent.VAO = va.getID();
|
||||||
|
renderComponent.IBO = elementBuffer.getBufferID();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarinkEngine::Renderer::Render(Scene& scene)
|
||||||
|
{
|
||||||
|
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||||
|
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||||
|
{
|
||||||
|
|
||||||
|
glBindVertexArray(renderComponent.VAO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
|
||||||
|
|
||||||
|
renderComponent.shader.Use();
|
||||||
|
|
||||||
|
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||||
|
|
||||||
|
renderComponent.shader.setUniformMat4("M", trans.transform);
|
||||||
|
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||||
|
renderComponent.shader.setUniformMat4("P", projection);
|
||||||
|
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(renderComponent.mesh.elements.size()) ,
|
||||||
|
GL_UNSIGNED_INT, NULL);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Render(Framebuffer& framebuffer)
|
||||||
|
{}
|
27
BarinkEngine/src/Graphics/Renderer.h
Normal file
27
BarinkEngine/src/Graphics/Renderer.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include "glad/glad.h"
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
#include "../PerfCounter.h"
|
||||||
|
|
||||||
|
#include "Primitives/Camera.h"
|
||||||
|
#include "Renderable.h"
|
||||||
|
#include "Memory/Framebuffer.h"
|
||||||
|
#include "../Scene/Components.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
|
||||||
|
class Renderer {
|
||||||
|
public:
|
||||||
|
Renderer();
|
||||||
|
~Renderer();
|
||||||
|
|
||||||
|
void Prepare(Scene& scene);
|
||||||
|
void Render(Scene& scene );
|
||||||
|
|
||||||
|
void Render(Framebuffer& framebuffer);
|
||||||
|
};
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,118 +1,119 @@
|
|||||||
#include "BarinkEngine.h"
|
#include "InputManager.h"
|
||||||
#include "Input/InputManager.h"
|
|
||||||
#include "GLFW/glfw3.h"
|
BarinkEngine::InputManager InputSystem;
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include <iostream>
|
void BarinkEngine::InputManager::PollEvents()
|
||||||
void BarinkEngine::InputManager::PollEvents()
|
{
|
||||||
{
|
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||||
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
auto window = *it;
|
||||||
(*it)->Poll();
|
window->Poll();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
||||||
{
|
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
Event KeyEvent{};
|
|
||||||
KeyEvent.name = "KEY";
|
Event KeyEvent{};
|
||||||
|
KeyEvent.name = "KEY";
|
||||||
InputSystem.EmitEvent(KeyEvent);
|
|
||||||
|
InputSystem.EmitEvent(KeyEvent);
|
||||||
|
|
||||||
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
|
||||||
{
|
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
||||||
|
{
|
||||||
std::cout << "'a' key was pressed" << std::endl;
|
|
||||||
}
|
std::cout << "'a' key was pressed" << std::endl;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
|
||||||
{
|
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
||||||
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
{
|
||||||
Event CursorPosUpdate{};
|
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
||||||
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
Event CursorPosUpdate{};
|
||||||
|
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
||||||
InputSystem.EmitEvent(CursorPosUpdate);
|
|
||||||
|
InputSystem.EmitEvent(CursorPosUpdate);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
|
||||||
{
|
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
||||||
if (entered) {
|
{
|
||||||
Event mouseEntered {};
|
if (entered) {
|
||||||
mouseEntered.name = "Mouse Entered Window's confines!";
|
Event mouseEntered {};
|
||||||
mouseEntered.argc = 0;
|
mouseEntered.name = "Mouse Entered Window's confines!";
|
||||||
|
mouseEntered.argc = 0;
|
||||||
InputSystem.EmitEvent(mouseEntered);
|
|
||||||
|
InputSystem.EmitEvent(mouseEntered);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
}
|
||||||
Event mouseLeft{};
|
else {
|
||||||
mouseLeft.name = "Mouse Left Window's confines!";
|
Event mouseLeft{};
|
||||||
mouseLeft.argc = 0;
|
mouseLeft.name = "Mouse Left Window's confines!";
|
||||||
|
mouseLeft.argc = 0;
|
||||||
InputSystem.EmitEvent(mouseLeft);
|
|
||||||
|
InputSystem.EmitEvent(mouseLeft);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
|
||||||
{
|
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||||
|
{
|
||||||
Event MouseButtonEvent{};
|
|
||||||
MouseButtonEvent.name = "MOUSEBUTTON";
|
Event MouseButtonEvent{};
|
||||||
|
MouseButtonEvent.name = "MOUSEBUTTON";
|
||||||
InputSystem.EmitEvent(MouseButtonEvent);
|
|
||||||
|
InputSystem.EmitEvent(MouseButtonEvent);
|
||||||
|
|
||||||
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
|
||||||
std::cout << "Right mouse button was pressed!" << std::endl;
|
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
|
||||||
}
|
std::cout << "Right mouse button was pressed!" << std::endl;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
|
||||||
{
|
void BarinkEngine::InputManager::ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
{
|
||||||
|
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
||||||
Event ScrollEvent{};
|
|
||||||
ScrollEvent.name = "SCROLL";
|
Event ScrollEvent{};
|
||||||
|
ScrollEvent.name = "SCROLL";
|
||||||
InputSystem.EmitEvent(ScrollEvent);
|
|
||||||
|
InputSystem.EmitEvent(ScrollEvent);
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
|
||||||
{
|
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
||||||
|
{
|
||||||
windows.push_back(window);
|
|
||||||
|
windows.push_back(window);
|
||||||
// Attach callbacks
|
|
||||||
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
// Attach callbacks
|
||||||
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
||||||
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
||||||
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
||||||
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
||||||
|
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
||||||
this->Subscribe( (EventListener&)(*window));
|
|
||||||
|
this->Subscribe( (EventListener&)(*window));
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
BarinkEngine::InputManager::InputManager() : EventEmitter ()
|
|
||||||
{
|
BarinkEngine::InputManager::InputManager() : EventEmitter ()
|
||||||
windows = std::vector<BarinkWindow*>();
|
{
|
||||||
}
|
windows = std::vector<BarinkWindow*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Graphics/Window.h"
|
#include <iostream>
|
||||||
#include "EventSystem/EventEmitter.h"
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "../EventSystem/EventEmitter.h"
|
||||||
|
#include "../EventSystem/EventListener.h"
|
||||||
|
#include "../Platform/Window.h"
|
||||||
|
|
||||||
namespace BarinkEngine {
|
namespace BarinkEngine {
|
||||||
|
|
||||||
@ -12,8 +16,6 @@ namespace BarinkEngine {
|
|||||||
void PollEvents();
|
void PollEvents();
|
||||||
void attach(BarinkWindow* window);
|
void attach(BarinkWindow* window);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// GLFW Handlers
|
// GLFW Handlers
|
||||||
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
static void CursorPositionCallback(GLFWwindow* window, double x, double y);
|
static void CursorPositionCallback(GLFWwindow* window, double x, double y);
|
||||||
@ -25,3 +27,5 @@ namespace BarinkEngine {
|
|||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern BarinkEngine::InputManager InputSystem;
|
52
BarinkEngine/src/PerfCounter.h
Normal file
52
BarinkEngine/src/PerfCounter.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <chrono>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
struct EngineStatistics {
|
||||||
|
float frameTime;
|
||||||
|
uint32_t verts;
|
||||||
|
uint32_t DC;
|
||||||
|
|
||||||
|
long long lastSampleTime;
|
||||||
|
long long frames;
|
||||||
|
long long FPS;
|
||||||
|
};
|
||||||
|
extern EngineStatistics ES;
|
||||||
|
|
||||||
|
inline void PerfomanceSamplerInit(){
|
||||||
|
|
||||||
|
ES.frames = 0;
|
||||||
|
ES.lastSampleTime = 0;
|
||||||
|
ES.lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SamplePerformance(void) {
|
||||||
|
ES.frames++;
|
||||||
|
ES.DC = 0;
|
||||||
|
ES.verts = 0;
|
||||||
|
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
|
unsigned long long MilliSecondsPast = now - ES.lastSampleTime;
|
||||||
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
|
ES.frameTime = (float)1000 / ES.frames;
|
||||||
|
ES.FPS = ES.frames;
|
||||||
|
ES.frames = 0;
|
||||||
|
ES.lastSampleTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
inline void ShowStats() {
|
||||||
|
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||||
|
|
||||||
|
ImGui::Text("FPS: %i", ES.FPS);
|
||||||
|
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||||
|
ImGui::Text("Verts: %i", ES.verts);
|
||||||
|
ImGui::Text("Draw Calls: %i", ES.DC);
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
@ -1,84 +1,86 @@
|
|||||||
#include "Graphics/Window.h"
|
#include "Window.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
bool BarinkWindow::InitGLFW(){
|
||||||
#include <iostream>
|
if(!glfwInit())
|
||||||
#include <GLFW/glfw3.h>
|
{
|
||||||
#include <spdlog/spdlog.h>
|
spdlog::error("Failed to initialise GLFW!");
|
||||||
#include "../Include/EventSystem/Event.h"
|
return false;
|
||||||
|
}
|
||||||
bool BarinkWindow::InitGLFW(){
|
|
||||||
if(!glfwInit())
|
return true;
|
||||||
{
|
}
|
||||||
spdlog::error("Failed to initialise GLFW!");
|
|
||||||
return false;
|
BarinkWindow::BarinkWindow(const int width, const int height) :
|
||||||
}
|
Width(width), Height(height), FullScreen(false)
|
||||||
|
{
|
||||||
return true;
|
if (InitGLFW()==false) {
|
||||||
}
|
exit(-1);
|
||||||
|
}
|
||||||
BarinkWindow::BarinkWindow(const int width, const int height) :
|
|
||||||
Width(width), Height(height), FullScreen(false){
|
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
||||||
if (InitGLFW()==false) {
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
|
||||||
exit(-1);
|
// No window decorations such as a border, a close widget
|
||||||
}
|
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
||||||
|
// glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
// Disable resizing the window
|
||||||
|
//glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||||
if( !window)
|
|
||||||
{
|
|
||||||
spdlog::error("GLFW failed to create window!");
|
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||||
glfwTerminate();
|
|
||||||
return;
|
if( !window)
|
||||||
}
|
{
|
||||||
|
spdlog::error("GLFW failed to create window!");
|
||||||
glfwMakeContextCurrent(window);
|
glfwTerminate();
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
return;
|
||||||
printf("Failed to initialize GLAD!\n");
|
}
|
||||||
exit(-1);
|
|
||||||
}
|
glfwMakeContextCurrent(window);
|
||||||
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
// Set vsync off !!
|
printf("Failed to initialize GLAD!\n");
|
||||||
glfwSwapInterval(0);
|
exit(-1);
|
||||||
|
}
|
||||||
VulkanSupported = glfwVulkanSupported();
|
|
||||||
|
// Set vsync off !!
|
||||||
glfwGetFramebufferSize(window, &Width, &Height);
|
glfwSwapInterval(0);
|
||||||
glViewport(0,0, Width, Height);
|
|
||||||
|
VulkanSupported = glfwVulkanSupported();
|
||||||
|
|
||||||
|
glfwGetFramebufferSize(window, &Width, &Height);
|
||||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
glViewport(0,0, Width, Height);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
BarinkWindow::~BarinkWindow(){
|
|
||||||
|
}
|
||||||
glfwTerminate();
|
|
||||||
}
|
BarinkWindow::~BarinkWindow(){
|
||||||
|
|
||||||
GLFWwindow* BarinkWindow::windowptr()
|
glfwTerminate();
|
||||||
{
|
}
|
||||||
return window;
|
|
||||||
}
|
GLFWwindow* BarinkWindow::windowptr()
|
||||||
|
{
|
||||||
bool BarinkWindow::WindowShouldClose(){
|
return window;
|
||||||
return glfwWindowShouldClose(window);
|
}
|
||||||
}
|
|
||||||
|
bool BarinkWindow::WindowShouldClose(){
|
||||||
void BarinkWindow::Poll()
|
return glfwWindowShouldClose(window);
|
||||||
{
|
}
|
||||||
glfwPollEvents();
|
|
||||||
}
|
void BarinkWindow::Poll()
|
||||||
|
{
|
||||||
void BarinkWindow::SwapBuffers()
|
glfwPollEvents();
|
||||||
{
|
}
|
||||||
glfwSwapBuffers(window);
|
|
||||||
}
|
void BarinkWindow::SwapBuffers()
|
||||||
|
{
|
||||||
|
glfwSwapBuffers(window);
|
||||||
void BarinkWindow::ReceiveEvent(Event& incident)
|
}
|
||||||
{
|
|
||||||
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
void BarinkWindow::ReceiveEvent(Event& incident)
|
||||||
|
{
|
||||||
}
|
//std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,15 @@
|
|||||||
#define GLFW_STATIC
|
#define GLFW_STATIC
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "../Include/EventSystem/EventListener.h"
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "../EventSystem/Event.h"
|
||||||
|
#include "../EventSystem/EventListener.h"
|
||||||
|
|
||||||
class BarinkWindow : EventListener {
|
class BarinkWindow : EventListener {
|
||||||
private:
|
private:
|
||||||
@ -18,16 +21,13 @@ class BarinkWindow : EventListener {
|
|||||||
|
|
||||||
static bool InitGLFW();
|
static bool InitGLFW();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BarinkWindow(const int width, const int height);
|
BarinkWindow(const int width, const int height);
|
||||||
~BarinkWindow();
|
~BarinkWindow();
|
||||||
|
|
||||||
GLFWwindow* windowptr();
|
GLFWwindow* windowptr();
|
||||||
|
|
||||||
void ReceiveEvent(Event& incident) override;
|
void ReceiveEvent(Event& incident) override ;
|
||||||
bool WindowShouldClose();
|
bool WindowShouldClose();
|
||||||
|
|
||||||
void Poll();
|
void Poll();
|
41
BarinkEngine/src/Scene/Components.h
Normal file
41
BarinkEngine/src/Scene/Components.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include "../Graphics/Primitives/Shader.h"
|
||||||
|
#include "../Graphics/Primitives/Mesh.h"
|
||||||
|
namespace BarinkEngine {
|
||||||
|
struct IdentifierComponent {
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TransformComponent {
|
||||||
|
glm::mat4 transform = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct CameraComponent {
|
||||||
|
glm::mat4 view;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Render3DComponent {
|
||||||
|
unsigned int VAO = 0;
|
||||||
|
unsigned int IBO = 0;
|
||||||
|
Mesh mesh;
|
||||||
|
|
||||||
|
// TODO: becomes a material
|
||||||
|
glm::vec3 color;
|
||||||
|
Shader shader;
|
||||||
|
|
||||||
|
Render3DComponent()
|
||||||
|
: shader(Shader("build/Debug/test.vs", "build/Debug/test.fs")),
|
||||||
|
color(glm::vec3(1.0f, 0.0f, 0.0f))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Render2DComponent {
|
||||||
|
glm::vec3 Colour;
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
7
BarinkEngine/src/Scene/Entity.cpp
Normal file
7
BarinkEngine/src/Scene/Entity.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
Entity::Entity(entt::entity e, Scene* scene)
|
||||||
|
: m_entity(e), m_scene(scene)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
27
BarinkEngine/src/Scene/Entity.h
Normal file
27
BarinkEngine/src/Scene/Entity.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
class Scene;
|
||||||
|
|
||||||
|
class Entity {
|
||||||
|
public:
|
||||||
|
Entity() = default;
|
||||||
|
Entity(entt::entity e, Scene* scene);
|
||||||
|
Entity(const Entity& other) = default;
|
||||||
|
|
||||||
|
|
||||||
|
template<class T >
|
||||||
|
T& AddComponent() {
|
||||||
|
return m_scene->m_registry.emplace<T>(m_entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T& GetComponent() {
|
||||||
|
return m_scene->m_registry.get<T>(m_entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
entt::entity m_entity;
|
||||||
|
Scene* m_scene;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
21
BarinkEngine/src/Scene/Scene.cpp
Normal file
21
BarinkEngine/src/Scene/Scene.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "Scene.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "Components.h"
|
||||||
|
Scene::Scene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene::~Scene()
|
||||||
|
{}
|
||||||
|
|
||||||
|
Entity Scene::AddEntity(std::string& name)
|
||||||
|
{
|
||||||
|
Entity entity = { m_registry.create(), this };
|
||||||
|
|
||||||
|
entity.AddComponent<BarinkEngine::IdentifierComponent>();
|
||||||
|
entity.AddComponent<BarinkEngine::TransformComponent>();
|
||||||
|
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
22
BarinkEngine/src/Scene/Scene.h
Normal file
22
BarinkEngine/src/Scene/Scene.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
class Entity;
|
||||||
|
|
||||||
|
class Scene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Scene();
|
||||||
|
~Scene();
|
||||||
|
|
||||||
|
Entity AddEntity(std::string& name);
|
||||||
|
|
||||||
|
entt::registry& getReg() { return m_registry; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
entt::registry m_registry;
|
||||||
|
|
||||||
|
friend class Entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
7
BarinkEngine/src/Scene/TransformTree/Node.cpp
Normal file
7
BarinkEngine/src/Scene/TransformTree/Node.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "Node.h"
|
||||||
|
|
||||||
|
Node::Node(const std::string& name)
|
||||||
|
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
||||||
|
|
||||||
|
Group::Group(const std::string& name )
|
||||||
|
: Node(name) {}
|
22
BarinkEngine/src/Scene/TransformTree/Node.h
Normal file
22
BarinkEngine/src/Scene/TransformTree/Node.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Node {
|
||||||
|
public:
|
||||||
|
Node(const std::string& name);
|
||||||
|
std::string name;
|
||||||
|
Node* parent;
|
||||||
|
std::vector<Node*> children;
|
||||||
|
|
||||||
|
void addChild(Node& node);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Group : public Node {
|
||||||
|
public:
|
||||||
|
Group(const std::string& name);
|
||||||
|
|
||||||
|
};
|
12
BarinkEngine/src/Scene/TransformTree/SceneNodeTypes.cpp
Normal file
12
BarinkEngine/src/Scene/TransformTree/SceneNodeTypes.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "SceneNodeTypes.h"
|
||||||
|
|
||||||
|
BarinkEngine::SceneCamera::SceneCamera()
|
||||||
|
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))
|
||||||
|
{}
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject::SceneObject(std::string name, Renderable* visual)
|
||||||
|
: Group(name), renderable(visual)
|
||||||
|
{}
|
||||||
|
|
||||||
|
BarinkEngine::SceneObject::~SceneObject()
|
||||||
|
{}
|
22
BarinkEngine/src/Scene/TransformTree/SceneNodeTypes.h
Normal file
22
BarinkEngine/src/Scene/TransformTree/SceneNodeTypes.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../Graphics/Primitives/Camera.h"
|
||||||
|
#include "../../Graphics/Renderable.h"
|
||||||
|
#include "Node.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
class SceneCamera : public Group
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera& camera;
|
||||||
|
SceneCamera();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SceneObject : public Group
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SceneObject(std::string name, Renderable* visual);
|
||||||
|
~SceneObject();
|
||||||
|
Renderable* renderable;
|
||||||
|
};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#include "Scripting/LuaScript.h"
|
#include "LuaScript.h"
|
||||||
/*
|
/*
|
||||||
LuaScript::LuaScript(const std::string& path)
|
LuaScript::LuaScript(const std::string& path)
|
||||||
: filePath(path) {
|
: filePath(path) {
|
@ -1,4 +1,4 @@
|
|||||||
#include "Scripting/LuaScriptingManager.h"
|
#include "LuaScriptingManager.h"
|
||||||
/*
|
/*
|
||||||
LuaScriptingManager::LuaScriptingManager()
|
LuaScriptingManager::LuaScriptingManager()
|
||||||
{
|
{
|
@ -1,11 +1,11 @@
|
|||||||
#version 440 core
|
#version 440 core
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
uniform vec3 Color;
|
uniform vec3 Color;
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
uniform sampler2D Texture;
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
|
FragColor = vec4(color , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
|
||||||
}
|
}
|
40
Editor/premake5.lua
Normal file
40
Editor/premake5.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
project "Editor"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
|
||||||
|
buildmessage "Building editor ..."
|
||||||
|
|
||||||
|
links{
|
||||||
|
"BarinkEngine"
|
||||||
|
}
|
||||||
|
|
||||||
|
includedirs{
|
||||||
|
"./../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",
|
||||||
|
|
||||||
|
|
||||||
|
"./include"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
libdirs {
|
||||||
|
'./../build/BarinkEngine/Debug'
|
||||||
|
}
|
||||||
|
|
||||||
|
files {
|
||||||
|
"./include/*.h",
|
||||||
|
"./src/*.cpp"
|
||||||
|
}
|
138
Editor/src/main.cpp
Normal file
138
Editor/src/main.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
#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>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define globals
|
||||||
|
*/
|
||||||
|
Shader* shader;
|
||||||
|
|
||||||
|
char* code = new char[254];
|
||||||
|
|
||||||
|
const std::string vertexShaderSource = "build/Debug/test.vs";
|
||||||
|
const std::string fragmentShaderSource = "build/Debug/test.fs";
|
||||||
|
|
||||||
|
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||||
|
Framebuffer* framebuffer;
|
||||||
|
Scene* Level1;
|
||||||
|
BarinkEngine::SceneObject* cube;
|
||||||
|
/*
|
||||||
|
* Runs once at startup
|
||||||
|
* - USe to initialize the game/sandbox/demo
|
||||||
|
*/
|
||||||
|
void Start() {
|
||||||
|
// Build a basic test scene
|
||||||
|
// NOTE: This will later be done through an editor
|
||||||
|
|
||||||
|
// Create a level and load it as the current level
|
||||||
|
std::string levelName("Test Level");
|
||||||
|
Level1 = SceneManager::CreateScene(levelName);
|
||||||
|
SceneManager::LoadScene(*Level1);
|
||||||
|
|
||||||
|
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||||
|
|
||||||
|
// Create a cube node
|
||||||
|
|
||||||
|
cube = MI->Import("build/Debug/Models/cube.obj");
|
||||||
|
cube->renderable->material = new Material(*shader);
|
||||||
|
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
// What is in cube now ??
|
||||||
|
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
|
||||||
|
std::cout << "mesh elements: " << cube->renderable->mesh->elements.size() << std::endl;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs every frame
|
||||||
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||||
|
*/
|
||||||
|
void ImmediateGraphicsDraw()
|
||||||
|
{
|
||||||
|
|
||||||
|
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
|
||||||
|
|
||||||
|
// Show a menu bar
|
||||||
|
ImGui::BeginMainMenuBar();
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("Application")) {
|
||||||
|
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Exit")) {
|
||||||
|
// TODO: Exit application
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndMainMenuBar();
|
||||||
|
|
||||||
|
|
||||||
|
// Show internal BarinkEngine stats
|
||||||
|
ShowStats();
|
||||||
|
|
||||||
|
ImGui::Begin("Viewport");
|
||||||
|
ImGui::Image((void*)(intptr_t)framebuffer->GetColourAttachment(), ImVec2{ 800,600 });
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
static float Zoom = 90;
|
||||||
|
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", &Zoom, 10, 190);
|
||||||
|
ImGui::InputFloat3("Position:", &Position[0]);
|
||||||
|
|
||||||
|
ImGui::InputFloat3("Rotation:", &Rotation[0]);
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::Begin("Scripting");
|
||||||
|
ImGui::Text("Lua Code");
|
||||||
|
ImGui::InputTextMultiline("##", code, 255);
|
||||||
|
bool runCode = ImGui::Button("Run");
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::Begin("Scene Explorer");
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs every frame
|
||||||
|
* - Meant for game logic ( non-physics related)
|
||||||
|
*/
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
delete framebuffer;
|
||||||
|
delete MI;
|
||||||
|
delete shader;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
project "ImGUI_Opengl3"
|
project "ImGui"
|
||||||
kind "StaticLib"
|
kind "StaticLib"
|
||||||
|
|
||||||
includedirs {
|
includedirs {
|
||||||
|
39
Runtime/premake5.lua
Normal file
39
Runtime/premake5.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
project "Runtime"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
|
||||||
|
buildmessage "Building the runtime ..."
|
||||||
|
|
||||||
|
links{
|
||||||
|
"BarinkEngine"
|
||||||
|
}
|
||||||
|
|
||||||
|
includedirs{
|
||||||
|
"./../BarinkEngine/src",
|
||||||
|
-- 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",
|
||||||
|
|
||||||
|
|
||||||
|
"./include"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
libdirs {
|
||||||
|
'./../build/BarinkEngine/Debug'
|
||||||
|
}
|
||||||
|
|
||||||
|
files {
|
||||||
|
"./src/*.h",
|
||||||
|
"./src/*.cpp"
|
||||||
|
}
|
6
Runtime/src/main.cpp
Normal file
6
Runtime/src/main.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "Welcome to the runtime!" << std::endl;
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
# Blender 3.1.2 MTL File: 'None'
|
# Blender 3.1.2 MTL File: 'None'
|
||||||
# www.blender.org
|
# www.blender.org
|
||||||
|
|
||||||
newmtl Material
|
newmtl Material
|
||||||
Ns 360.000000
|
Ns 360.000000
|
||||||
Ka 1.000000 1.000000 1.000000
|
Ka 1.000000 1.000000 1.000000
|
||||||
Kd 0.800000 0.800000 0.800000
|
Kd 0.800000 0.800000 0.800000
|
||||||
Ks 0.500000 0.500000 0.500000
|
Ks 0.500000 0.500000 0.500000
|
||||||
Ke 0.000000 0.000000 0.000000
|
Ke 0.000000 0.000000 0.000000
|
||||||
Ni 1.450000
|
Ni 1.450000
|
||||||
d 1.000000
|
d 1.000000
|
||||||
illum 2
|
illum 2
|
@ -1,40 +1,40 @@
|
|||||||
# Blender 3.1.2
|
# Blender 3.1.2
|
||||||
# www.blender.org
|
# www.blender.org
|
||||||
mtllib Cube.mtl
|
mtllib Cube.mtl
|
||||||
o Cube
|
o Cube
|
||||||
v 1.000000 1.000000 -1.000000
|
v 1.000000 1.000000 -1.000000
|
||||||
v 1.000000 -1.000000 -1.000000
|
v 1.000000 -1.000000 -1.000000
|
||||||
v 1.000000 1.000000 1.000000
|
v 1.000000 1.000000 1.000000
|
||||||
v 1.000000 -1.000000 1.000000
|
v 1.000000 -1.000000 1.000000
|
||||||
v -1.000000 1.000000 -1.000000
|
v -1.000000 1.000000 -1.000000
|
||||||
v -1.000000 -1.000000 -1.000000
|
v -1.000000 -1.000000 -1.000000
|
||||||
v -1.000000 1.000000 1.000000
|
v -1.000000 1.000000 1.000000
|
||||||
v -1.000000 -1.000000 1.000000
|
v -1.000000 -1.000000 1.000000
|
||||||
vn -0.0000 1.0000 -0.0000
|
vn -0.0000 1.0000 -0.0000
|
||||||
vn -0.0000 -0.0000 1.0000
|
vn -0.0000 -0.0000 1.0000
|
||||||
vn -1.0000 -0.0000 -0.0000
|
vn -1.0000 -0.0000 -0.0000
|
||||||
vn -0.0000 -1.0000 -0.0000
|
vn -0.0000 -1.0000 -0.0000
|
||||||
vn 1.0000 -0.0000 -0.0000
|
vn 1.0000 -0.0000 -0.0000
|
||||||
vn -0.0000 -0.0000 -1.0000
|
vn -0.0000 -0.0000 -1.0000
|
||||||
vt 0.625000 0.500000
|
vt 0.625000 0.500000
|
||||||
vt 0.375000 0.500000
|
vt 0.375000 0.500000
|
||||||
vt 0.625000 0.750000
|
vt 0.625000 0.750000
|
||||||
vt 0.375000 0.750000
|
vt 0.375000 0.750000
|
||||||
vt 0.875000 0.500000
|
vt 0.875000 0.500000
|
||||||
vt 0.625000 0.250000
|
vt 0.625000 0.250000
|
||||||
vt 0.125000 0.500000
|
vt 0.125000 0.500000
|
||||||
vt 0.375000 0.250000
|
vt 0.375000 0.250000
|
||||||
vt 0.875000 0.750000
|
vt 0.875000 0.750000
|
||||||
vt 0.625000 1.000000
|
vt 0.625000 1.000000
|
||||||
vt 0.625000 0.000000
|
vt 0.625000 0.000000
|
||||||
vt 0.375000 1.000000
|
vt 0.375000 1.000000
|
||||||
vt 0.375000 0.000000
|
vt 0.375000 0.000000
|
||||||
vt 0.125000 0.750000
|
vt 0.125000 0.750000
|
||||||
s 0
|
s 0
|
||||||
usemtl Material
|
usemtl Material
|
||||||
f 1/1/1 5/5/1 7/9/1 3/3/1
|
f 1/1/1 5/5/1 7/9/1 3/3/1
|
||||||
f 4/4/2 3/3/2 7/10/2 8/12/2
|
f 4/4/2 3/3/2 7/10/2 8/12/2
|
||||||
f 8/13/3 7/11/3 5/6/3 6/8/3
|
f 8/13/3 7/11/3 5/6/3 6/8/3
|
||||||
f 6/7/4 2/2/4 4/4/4 8/14/4
|
f 6/7/4 2/2/4 4/4/4 8/14/4
|
||||||
f 2/2/5 1/1/5 3/3/5 4/4/5
|
f 2/2/5 1/1/5 3/3/5 4/4/5
|
||||||
f 6/8/6 5/6/6 1/1/6 2/2/6
|
f 6/8/6 5/6/6 1/1/6 2/2/6
|
File diff suppressed because it is too large
Load Diff
40
SandboxApp/premake5.lua
Normal file
40
SandboxApp/premake5.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
project "SandboxApp"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
|
||||||
|
buildmessage "Building SandboxApp ..."
|
||||||
|
|
||||||
|
links{
|
||||||
|
"BarinkEngine"
|
||||||
|
}
|
||||||
|
|
||||||
|
includedirs{
|
||||||
|
"./../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",
|
||||||
|
|
||||||
|
"../libs/entt/src",
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
libdirs {
|
||||||
|
'./../build/BarinkEngine/Debug'
|
||||||
|
}
|
||||||
|
|
||||||
|
files {
|
||||||
|
"./src/*.h",
|
||||||
|
"./src/*.cpp"
|
||||||
|
}
|
87
SandboxApp/src/GUI.cpp
Normal file
87
SandboxApp/src/GUI.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "GUI.h"
|
||||||
|
|
||||||
|
|
||||||
|
void SceneExplorer(const std::string& PanelName) {
|
||||||
|
ImGui::Begin(PanelName.c_str());
|
||||||
|
//if (ImGui::ListBoxHeader("##ObjectList")) {
|
||||||
|
//Node& current = scene.GetRoot();
|
||||||
|
|
||||||
|
//Node* next = ¤t;
|
||||||
|
|
||||||
|
// Show first node
|
||||||
|
//ImGui::Selectable(next->name.c_str(), true);
|
||||||
|
// ImGui::Selectable("Scene Node", true);
|
||||||
|
// ImGui::Indent();
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
if (next->children.size() != 0) {
|
||||||
|
for (auto child : next->children)
|
||||||
|
{
|
||||||
|
std::string& name = child->name;
|
||||||
|
ImGui::Selectable(name.c_str(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ImGui::ListBoxFooter();
|
||||||
|
// }
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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:", &Zoom, 10, 190);
|
||||||
|
|
||||||
|
ImGui::InputFloat3("Position:", &Position[0]);
|
||||||
|
|
||||||
|
ImGui::InputFloat3("Rotation:", &Rotation[0]);
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptingTool(char* code) {
|
||||||
|
ImGui::Begin("Scripting");
|
||||||
|
|
||||||
|
ImGui::Text("Lua Code");
|
||||||
|
ImGui::InputTextMultiline("##", code, 255);
|
||||||
|
bool runCode = ImGui::Button("Run");
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
|
||||||
|
ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
|
||||||
|
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void materialWindow(Material& material, std::string PanelName) {
|
||||||
|
ImGui::Begin(PanelName.c_str());
|
||||||
|
ImGui::ColorPicker3("Color:", &material.Color[0]);
|
||||||
|
ImGui::End();
|
||||||
|
}
|
11
SandboxApp/src/GUI.h
Normal file
11
SandboxApp/src/GUI.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||||
|
#include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h"
|
||||||
|
|
||||||
|
void CameraTool();
|
||||||
|
void ScriptingTool(char* code);
|
||||||
|
///void transformWindow(Transform& transform, std::string PanelName);
|
||||||
|
void materialWindow(Material& material, std::string PanelName);
|
||||||
|
void SceneExplorer(const std::string& PanelName);
|
||||||
|
void SceneView(Framebuffer& framebuffer);
|
94
SandboxApp/src/Sandbox.cpp
Normal file
94
SandboxApp/src/Sandbox.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||||
|
#include "../../BarinkEngine/src/Scene/Components.h"
|
||||||
|
#include "../../BarinkEngine/src/Scene/Scene.h"
|
||||||
|
#include "../../BarinkEngine/src/Scene/Entity.h"
|
||||||
|
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
||||||
|
#include <imgui.h>
|
||||||
|
#include "GUI.h"
|
||||||
|
#include "Util.h"
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define globals
|
||||||
|
*/
|
||||||
|
Scene scene;
|
||||||
|
|
||||||
|
BarinkEngine::Renderable* renderable;
|
||||||
|
BarinkEngine::SceneObject* object;
|
||||||
|
Entity cube;
|
||||||
|
/*
|
||||||
|
* Runs once at startup
|
||||||
|
* - USe to initialize the game/sandbox/demo
|
||||||
|
*/
|
||||||
|
void Start() {
|
||||||
|
|
||||||
|
cube = scene.AddEntity((std::string&)"cube");
|
||||||
|
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
auto importer = BarinkEngine::ModelImporter();
|
||||||
|
|
||||||
|
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||||
|
renderable = object->renderable;
|
||||||
|
|
||||||
|
render3DComponent.mesh = *renderable->mesh;
|
||||||
|
cube.GetComponent<BarinkEngine::TransformComponent>()
|
||||||
|
.transform = glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f,1.0f,0.0f));
|
||||||
|
|
||||||
|
// Create a second cube
|
||||||
|
|
||||||
|
auto cube2 = scene.AddEntity((std::string&)"Cube2");
|
||||||
|
auto& cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
cube2Render.mesh = *renderable->mesh;
|
||||||
|
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
auto& cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
||||||
|
cube2Trans.transform = glm::translate( glm::mat4(1.0f), glm::vec3(1.0f,0.0f, 5.0f));
|
||||||
|
|
||||||
|
|
||||||
|
renderer.Prepare(scene);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs every frame
|
||||||
|
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||||
|
*/
|
||||||
|
void ImmediateGraphicsDraw()
|
||||||
|
{
|
||||||
|
// Show internal BarinkEngine stats
|
||||||
|
ShowStats();
|
||||||
|
|
||||||
|
ImGui::Begin("Render edit");
|
||||||
|
|
||||||
|
auto& a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||||
|
|
||||||
|
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs every frame
|
||||||
|
* - Meant for game logic ( non-physics related)
|
||||||
|
*/
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
renderer.Render(scene);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs at the end of the program
|
||||||
|
* - Meant for cleanup
|
||||||
|
*/
|
||||||
|
void Stop()
|
||||||
|
{
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
void PrintSceneTree(SceneNode& node, int depth) {
|
/*
|
||||||
|
* void PrintSceneTree(Node& node, int depth) {
|
||||||
// Indent name based on depth
|
// Indent name based on depth
|
||||||
std::cout << " ";
|
std::cout << " ";
|
||||||
for (int i = 0; i < depth; i++) {
|
for (int i = 0; i < depth; i++) {
|
||||||
@ -30,3 +31,5 @@ glm::mat4 CalculateModelMat(Transform& transform) {
|
|||||||
return tran * rot * scale;
|
return tran * rot * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
6
SandboxApp/src/Util.h
Normal file
6
SandboxApp/src/Util.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../../BarinkEngine/src/BarinkEngine.h"
|
||||||
|
|
||||||
|
//void PrintSceneTree(Node& node, int depth);
|
||||||
|
|
||||||
|
//glm::mat4 CalculateModelMat(Transform& transform);
|
@ -1,41 +0,0 @@
|
|||||||
#include "GUI.h"
|
|
||||||
|
|
||||||
void CameraTool(Camera* cam) {
|
|
||||||
|
|
||||||
ImGui::Begin("Camera");
|
|
||||||
|
|
||||||
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
|
||||||
|
|
||||||
ImGui::InputFloat3("Position:", &cam->Position[0]);
|
|
||||||
|
|
||||||
ImGui::InputFloat3("Rotation:", &cam->Rotation[0]);
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptingTool(char* code) {
|
|
||||||
ImGui::Begin("Scripting");
|
|
||||||
|
|
||||||
ImGui::InputTextMultiline("Lua Script", code, 255);
|
|
||||||
bool runCode = ImGui::Button("Run");
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void transformWindow(Transform& transform, std::string PanelName) {
|
|
||||||
ImGui::Begin(PanelName.c_str());
|
|
||||||
ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
|
|
||||||
ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
|
|
||||||
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void materialWindow(Material& material, std::string PanelName) {
|
|
||||||
ImGui::Begin(PanelName.c_str());
|
|
||||||
ImGui::ColorPicker3("Color:", &material.Color[0]);
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "imgui.h"
|
|
||||||
#include <BarinkEngine.h>
|
|
||||||
|
|
||||||
void CameraTool(Camera* camera);
|
|
||||||
void ScriptingTool(char* code);
|
|
||||||
void transformWindow(Transform& transform, std::string PanelName);
|
|
||||||
void materialWindow(Material& material, std::string PanelName);
|
|
@ -1,174 +0,0 @@
|
|||||||
#include "BarinkEngine.h"
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "GUI.h"
|
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define globals
|
|
||||||
*/
|
|
||||||
Camera* cam;
|
|
||||||
|
|
||||||
|
|
||||||
Shader* shader;
|
|
||||||
|
|
||||||
Renderable* Cube;
|
|
||||||
Material* matCube;
|
|
||||||
Texture* textureCube;
|
|
||||||
|
|
||||||
Renderable* Cube2;
|
|
||||||
Material* matCube2;
|
|
||||||
|
|
||||||
char* code = new char[254];
|
|
||||||
|
|
||||||
|
|
||||||
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
||||||
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs once at startup
|
|
||||||
* - USe to initialize the game/sandbox/demo
|
|
||||||
*/
|
|
||||||
void Start() {
|
|
||||||
|
|
||||||
/*
|
|
||||||
Building a very basic scene graph
|
|
||||||
*/
|
|
||||||
SceneNode MyCube = SceneNode();
|
|
||||||
MyCube.name = "MyCube";
|
|
||||||
|
|
||||||
SceneNode MyBaby = SceneNode();
|
|
||||||
MyBaby.name = "Baby";
|
|
||||||
|
|
||||||
SceneNode MySecondCube = SceneNode();
|
|
||||||
MySecondCube.name = "MySecondCube";
|
|
||||||
|
|
||||||
|
|
||||||
MyCube.addChild(MyBaby);
|
|
||||||
|
|
||||||
|
|
||||||
Scene scene = Scene("My awesome Game Scene");
|
|
||||||
scene.GetRoot().addChild(MyCube);
|
|
||||||
scene.GetRoot().addChild(MySecondCube);
|
|
||||||
|
|
||||||
|
|
||||||
// Walk scene graph
|
|
||||||
PrintSceneTree(scene.GetRoot(),0);
|
|
||||||
|
|
||||||
shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
|
||||||
|
|
||||||
textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg");
|
|
||||||
|
|
||||||
matCube = new Material(*shader);
|
|
||||||
matCube->Color = glm::vec3(1.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
matCube2 = new Material(*shader);
|
|
||||||
matCube2->Color = glm::vec3(0.0, 1.0f, 0.0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* load meshes
|
|
||||||
*/
|
|
||||||
Cube = Renderable::Load();
|
|
||||||
Cube2 = Renderable::Load();
|
|
||||||
Cube->addChild(*Cube2);
|
|
||||||
|
|
||||||
Cube->shader = shader;
|
|
||||||
Cube2->shader = shader;
|
|
||||||
|
|
||||||
Cube->texture = textureCube;
|
|
||||||
Cube2->texture = textureCube;
|
|
||||||
|
|
||||||
Cube2->transform.Position = glm::vec3(-9.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
Cube->transform.Position = glm::vec3(-8.0f, 0.0f, -2.0f);
|
|
||||||
|
|
||||||
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
|
||||||
|
|
||||||
memset(code, '\0', 254);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
|
|
||||||
// Show internal BarinkEngine stats
|
|
||||||
ShowStats();
|
|
||||||
|
|
||||||
|
|
||||||
// Show different tooling for this specific sandbox
|
|
||||||
CameraTool(cam);
|
|
||||||
ScriptingTool(code);
|
|
||||||
|
|
||||||
transformWindow(Cube->transform, "Transform (Cube)");
|
|
||||||
|
|
||||||
transformWindow(Cube2->transform, "Transform (Cube2)");
|
|
||||||
|
|
||||||
materialWindow(*matCube, "Material Cube");
|
|
||||||
materialWindow(*matCube2, "Material Cube2");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs every frame
|
|
||||||
* - Meant for game logic ( non-physics related)
|
|
||||||
*/
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* NOTE: this needs to move to the renderer
|
|
||||||
* Render code should not appear in the sandbox file
|
|
||||||
*/
|
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
||||||
|
|
||||||
shader->Use();
|
|
||||||
shader->setUniformMat4("P", projection);
|
|
||||||
shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
|
|
||||||
shader->setUniformMat4("V", cam->GetViewMatrix());
|
|
||||||
matCube->Apply();
|
|
||||||
|
|
||||||
Cube->Draw();
|
|
||||||
|
|
||||||
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
|
||||||
matCube2->Apply();
|
|
||||||
|
|
||||||
Cube2->Draw();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs at the end of the program
|
|
||||||
* - Meant for cleanup
|
|
||||||
*/
|
|
||||||
void Stop() {
|
|
||||||
// Cleanup
|
|
||||||
Cube->VAO.Delete();
|
|
||||||
Cube->elementBuffer.Delete();
|
|
||||||
|
|
||||||
Cube2->VAO.Delete();
|
|
||||||
Cube2->elementBuffer.Delete();
|
|
||||||
|
|
||||||
delete Cube2;
|
|
||||||
delete Cube;
|
|
||||||
|
|
||||||
delete matCube;
|
|
||||||
delete matCube2;
|
|
||||||
|
|
||||||
delete shader;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "BarinkEngine.h"
|
|
||||||
|
|
||||||
void PrintSceneTree(SceneNode& node, int depth);
|
|
||||||
|
|
||||||
glm::mat4 CalculateModelMat(Transform& transform);
|
|
7
TODO.md
7
TODO.md
@ -11,7 +11,7 @@
|
|||||||
<input type="checkbox"></input> Basic Textures \
|
<input type="checkbox"></input> Basic Textures \
|
||||||
<input type="checkbox" checked></input> Link GLEW or GLAD \
|
<input type="checkbox" checked></input> Link GLEW or GLAD \
|
||||||
<input type="checkbox" checked></input> Work on basic logging \
|
<input type="checkbox" checked></input> Work on basic logging \
|
||||||
<input type="checkbox"></input> Input handling \
|
<input type="checkbox" checked></input> Input handling \
|
||||||
<input type="checkbox"></input> More shader work \
|
<input type="checkbox"></input> More shader work \
|
||||||
<input type="checkbox" checked></input> Load FBX model files \
|
<input type="checkbox" checked></input> Load FBX model files \
|
||||||
<input type="checkbox"></input> Basic Physics \
|
<input type="checkbox"></input> Basic Physics \
|
||||||
@ -21,5 +21,6 @@
|
|||||||
|
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
https://renderdoc.org/
|
https://renderdoc.org/ \
|
||||||
https://api.projectchrono.org/tutorial_table_of_content_chrono.html
|
https://api.projectchrono.org/tutorial_table_of_content_chrono.html \
|
||||||
|
https://github.com/epezent/implot -- Useful when displaying graphs of any kind \
|
@ -1 +1 @@
|
|||||||
Subproject commit 6d27fecce1ea2cb10ca956cd67b8179cb76b35c3
|
Subproject commit d666a1d4737739274449dbe0e8558454bba82ec4
|
1
libs/entt
Submodule
1
libs/entt
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 9ac5f6d0465e80762b5289c659c9306300af4c66
|
52
premake5.lua
52
premake5.lua
@ -3,12 +3,12 @@ workspace "BarinkEngine"
|
|||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
cppdialect "C++17"
|
cppdialect "C++17"
|
||||||
|
|
||||||
targetdir "./build/%{prj.name}/%{cfg.buildcfg}"
|
|
||||||
objdir "./intermediates/%{prj.name}/%{cfg.buildcfg}"
|
|
||||||
|
|
||||||
architecture "x86_64"
|
architecture "x86_64"
|
||||||
|
|
||||||
|
targetdir "./%{prj.name}/build/%{cfg.buildcfg}"
|
||||||
|
objdir "./%{prj.name}/%{cfg.buildcfg}/intermediates/"
|
||||||
|
|
||||||
|
startproject("SandboxApp")
|
||||||
|
|
||||||
filter "configurations:Debug"
|
filter "configurations:Debug"
|
||||||
defines {"DEBUG"}
|
defines {"DEBUG"}
|
||||||
@ -18,46 +18,8 @@ workspace "BarinkEngine"
|
|||||||
defines {"NDEBUG"}
|
defines {"NDEBUG"}
|
||||||
optimize "On"
|
optimize "On"
|
||||||
|
|
||||||
|
|
||||||
project "SandboxApplication"
|
|
||||||
kind "ConsoleApp"
|
|
||||||
|
|
||||||
buildmessage "Building Sandbox ..."
|
|
||||||
|
|
||||||
links{
|
|
||||||
"BarinkEngine"
|
|
||||||
}
|
|
||||||
|
|
||||||
includedirs{
|
|
||||||
"./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 {
|
|
||||||
"./SandboxApplication/*.h",
|
|
||||||
"./SandboxApplication/*.cpp"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
include("./BarinkEngine")
|
include("./BarinkEngine")
|
||||||
|
include("./Runtime")
|
||||||
|
include ("./Editor")
|
||||||
|
include("./SandboxApp")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user