Compare commits
1 Commits
b03b82272f
...
Feature/In
Author | SHA1 | Date | |
---|---|---|---|
3c30bf7fb7 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,14 +4,12 @@
|
|||||||
[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
|
||||||
@ -24,7 +22,6 @@
|
|||||||
[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
|
||||||
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"cmake.configureOnOpen": true,
|
||||||
|
"files.associations": {
|
||||||
|
"iosfwd": "cpp"
|
||||||
|
}
|
||||||
|
}
|
@ -1,62 +1,82 @@
|
|||||||
#include "BarinkEngine.h"
|
#include "BarinkEngine.h"
|
||||||
|
|
||||||
EngineStatistics* ES;
|
EngineStatistics* ES;
|
||||||
|
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);
|
// Create the window
|
||||||
|
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||||
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
|
||||||
InputSystem = BarinkEngine::InputManager();
|
// =================================================
|
||||||
|
// Startup services
|
||||||
InputSystem.attach(&MainWindow);
|
// =================================================
|
||||||
|
|
||||||
GUIManager GUISystem = GUIManager(&MainWindow);
|
// Startup Renderer
|
||||||
|
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
// Startup InputManager
|
||||||
|
InputSystem = BarinkEngine::InputManager();
|
||||||
|
|
||||||
// First call to setup game
|
InputSystem.attach(&MainWindow);
|
||||||
Start();
|
InputSystem.setupGLFWInput(MainWindow.windowptr());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Runtime loop
|
// Startup GUI System
|
||||||
while (!MainWindow.WindowShouldClose()) {
|
GUIManager GUISystem = GUIManager(&MainWindow);
|
||||||
|
|
||||||
SamplePerformance();
|
|
||||||
|
|
||||||
|
|
||||||
// Execute main logic
|
// Enable depth testing
|
||||||
InputSystem.PollEvents();
|
// NOTE: TODO Move this into the renderer
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
Update();
|
|
||||||
|
|
||||||
renderer.Render();
|
|
||||||
|
// First call to setup game
|
||||||
ImmediateGraphicsDraw();
|
Start();
|
||||||
|
|
||||||
GUISystem.Render();
|
|
||||||
|
|
||||||
|
// Runtime loop
|
||||||
|
while (!MainWindow.WindowShouldClose()) {
|
||||||
MainWindow.SwapBuffers();
|
|
||||||
}
|
SamplePerformance();
|
||||||
|
|
||||||
|
|
||||||
// Shutdown game
|
// Execute main logic
|
||||||
Stop();
|
InputSystem.PollEvents();
|
||||||
|
|
||||||
|
Update();
|
||||||
// Shutdown Services
|
|
||||||
delete ES;
|
renderer.Render();
|
||||||
|
|
||||||
return 0;
|
ImmediateGraphicsDraw();
|
||||||
}
|
|
||||||
|
GUISystem.Render();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow.SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Shutdown game
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
|
||||||
|
// Shutdown Services
|
||||||
|
delete ES;
|
||||||
|
InputSystem.detach(&MainWindow);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
|
||||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
#define TINYGLTF_NO_EXTERNAL_IMAGE
|
||||||
|
|
||||||
#include "Graphics/Mesh.h"
|
#include "Graphics/Mesh.h"
|
||||||
@ -10,26 +9,15 @@
|
|||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Scene/SceneNodeTypes.h"
|
|
||||||
|
|
||||||
|
class ModelImporter {
|
||||||
|
|
||||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
|
public:
|
||||||
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
|
static std::vector<BarinkEngine::Mesh> Import(std::string path);
|
||||||
|
|
||||||
namespace BarinkEngine {
|
|
||||||
class ModelImporter {
|
private:
|
||||||
|
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
|
||||||
|
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -5,7 +5,6 @@
|
|||||||
#include "graphics/Texture.h"
|
#include "graphics/Texture.h"
|
||||||
#include "graphics/Camera.h"
|
#include "graphics/Camera.h"
|
||||||
#include "graphics/Renderable.h"
|
#include "graphics/Renderable.h"
|
||||||
#include "Graphics/Renderer.h"
|
|
||||||
#include "Graphics/Material.h"
|
#include "Graphics/Material.h"
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
@ -14,9 +13,14 @@
|
|||||||
#include "Graphics/Renderer.h"
|
#include "Graphics/Renderer.h"
|
||||||
#include "Graphics/GUI/GUIManager.h"
|
#include "Graphics/GUI/GUIManager.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
|
|
||||||
#include "PerfCounter.h"
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
|
||||||
extern void Start();
|
extern void Start();
|
||||||
extern void Update();
|
extern void Update();
|
||||||
extern void ImmediateGraphicsDraw();
|
extern void ImmediateGraphicsDraw();
|
||||||
extern void Stop();
|
extern void Stop();
|
||||||
|
|
||||||
|
extern BarinkEngine::InputManager InputSystem;
|
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace BECS {
|
|
||||||
|
|
||||||
struct Component {
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include "Component.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace BECS {
|
|
||||||
|
|
||||||
typedef unsigned long int Entity;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
namespace BECS {
|
|
||||||
|
|
||||||
struct System {
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "System.h"
|
|
||||||
#include <vector>
|
|
||||||
#include "Component.h"
|
|
||||||
#include "Entity.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace BECS {
|
|
||||||
struct World {
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<System> systems;
|
|
||||||
std::vector<Component> components;
|
|
||||||
std::vector<Entity> entities;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string name;
|
std::string name;
|
||||||
int argc;
|
|
||||||
void** argv;
|
|
||||||
|
|
||||||
};
|
};
|
@ -6,10 +6,12 @@ class EventEmitter {
|
|||||||
public:
|
public:
|
||||||
void Subscribe (EventListener& subscriber);
|
void Subscribe (EventListener& subscriber);
|
||||||
void Unsubscribe(EventListener& subscriber);
|
void Unsubscribe(EventListener& subscriber);
|
||||||
|
void EmitEvent(Event& incident);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::list<EventListener*> subscribers;
|
std::list<EventListener*> subscribers;
|
||||||
void EmitEvent(Event& incident);
|
|
||||||
|
|
||||||
EventEmitter();
|
EventEmitter();
|
||||||
|
|
||||||
|
5
BarinkEngine/Include/EventSystem/EventListener.cpp
Normal file
5
BarinkEngine/Include/EventSystem/EventListener.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "EventListener.h"
|
||||||
|
|
||||||
|
void EventListener::ReceiveEvent(Event& incident)
|
||||||
|
{
|
||||||
|
}
|
@ -1,12 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include <list>
|
||||||
class EventListener{
|
class EventListener{
|
||||||
public:
|
public:
|
||||||
virtual void ReceiveEvent(Event& incident) = 0 ;
|
virtual void ReceiveEvent(Event& incident);
|
||||||
|
|
||||||
};
|
};
|
18
BarinkEngine/Include/EventSystem/InputSystemEvents.h
Normal file
18
BarinkEngine/Include/EventSystem/InputSystemEvents.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct KEY_DOWN_EVENT : public Event {
|
||||||
|
public:
|
||||||
|
int scancode;
|
||||||
|
int keycode;
|
||||||
|
int mods;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KEY_UP_EVENT : public Event {
|
||||||
|
public:
|
||||||
|
int scancode;
|
||||||
|
int keycode;
|
||||||
|
int mods;
|
||||||
|
|
||||||
|
};
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
class GpuBuffer {
|
class Buffer {
|
||||||
private:
|
private:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
public:
|
public:
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "VertexArray.h"
|
|
||||||
#include "Buffer.h"
|
|
||||||
#include "Mesh.h"
|
|
||||||
#include "Material.h"
|
|
||||||
|
|
||||||
namespace BarinkEngine {
|
|
||||||
|
|
||||||
class GPU_Bucket {
|
|
||||||
public:
|
|
||||||
|
|
||||||
GPU_Bucket();
|
|
||||||
~GPU_Bucket();
|
|
||||||
|
|
||||||
void Upload(const Mesh& renderable);
|
|
||||||
|
|
||||||
GpuBuffer vertexBuffer;
|
|
||||||
GpuBuffer elementBuffer;
|
|
||||||
VertexArray vertexarray;
|
|
||||||
|
|
||||||
const Mesh* mesh;
|
|
||||||
const Material* material;
|
|
||||||
|
|
||||||
private :
|
|
||||||
unsigned int uv_id;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Material {
|
|||||||
public:
|
public:
|
||||||
Material(const Shader& shader);
|
Material(const Shader& shader);
|
||||||
|
|
||||||
void Apply()const;
|
void Apply();
|
||||||
|
|
||||||
glm::vec3 Color;
|
glm::vec3 Color;
|
||||||
|
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include "Vertex.h"
|
|
||||||
|
|
||||||
namespace BarinkEngine {
|
namespace BarinkEngine{
|
||||||
struct Mesh {
|
|
||||||
std::vector<Vertex> vertices;
|
|
||||||
std::vector<unsigned int> elements;
|
struct Vertex {
|
||||||
|
glm::vec3 vertices;
|
||||||
|
glm::vec2 uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
class Mesh {
|
||||||
|
public:
|
||||||
|
std::vector<Vertex> vertices;
|
||||||
|
std::vector<unsigned int > elements;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -20,8 +20,8 @@ private:
|
|||||||
std::vector<unsigned int > indices;
|
std::vector<unsigned int > indices;
|
||||||
|
|
||||||
|
|
||||||
GpuBuffer vertexBuffer;
|
Buffer vertexBuffer;
|
||||||
GpuBuffer elementBuffer;
|
Buffer elementBuffer;
|
||||||
|
|
||||||
VertexArray VAO;
|
VertexArray VAO;
|
||||||
|
|
||||||
|
@ -1,14 +1,37 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
#include "Buffer.h"
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
#include "VertexArray.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
namespace BarinkEngine {
|
|
||||||
|
|
||||||
struct Renderable {
|
class Renderable : public SceneNode {
|
||||||
BarinkEngine::Mesh* mesh;
|
public:
|
||||||
Material* material;
|
/*
|
||||||
Texture* texture;
|
* 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(std::string& path);
|
||||||
|
void Draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<BarinkEngine::Mesh> meshes;
|
||||||
|
Renderable(std::string& path);
|
||||||
|
};
|
@ -1,15 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include "glad/glad.h"
|
|
||||||
#include "GLFW/glfw3.h"
|
|
||||||
|
|
||||||
#include "PerfCounter.h"
|
|
||||||
|
|
||||||
#include "Graphics/Camera.h"
|
|
||||||
#include "Graphics/Renderable.h"
|
#include "Graphics/Renderable.h"
|
||||||
#include "Graphics/GPUBucket.h"
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace BarinkEngine {
|
namespace BarinkEngine {
|
||||||
|
|
||||||
@ -23,7 +15,7 @@ namespace BarinkEngine {
|
|||||||
void Submit(Renderable* model);
|
void Submit(Renderable* model);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<GPU_Bucket*> models;
|
std::vector<Renderable*> models;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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() const;
|
void Use();
|
||||||
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,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
struct Transform {
|
|
||||||
glm::vec3 Position;
|
|
||||||
glm::vec3 Rotation;
|
|
||||||
glm::vec3 Scale;
|
|
||||||
|
|
||||||
glm::mat4 ModelMatrix;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace BarinkEngine {
|
|
||||||
struct Vertex {
|
|
||||||
glm::vec3 vertices;
|
|
||||||
glm::vec2 uv;
|
|
||||||
};
|
|
||||||
}
|
|
@ -2,15 +2,12 @@
|
|||||||
#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 <spdlog/spdlog.h>
|
#include "../Include/EventSystem/EventListener.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "EventSystem/Event.h"
|
|
||||||
#include "EventSystem/EventListener.h"
|
|
||||||
|
|
||||||
class BarinkWindow : EventListener {
|
class BarinkWindow : EventListener {
|
||||||
private:
|
private:
|
||||||
@ -21,13 +18,16 @@ 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();
|
||||||
|
14
BarinkEngine/Include/Input/GLFWInput.h
Normal file
14
BarinkEngine/Include/Input/GLFWInput.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
namespace Input {
|
||||||
|
|
||||||
|
void BE_GLFW_KEYS(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
|
void BE_GLFW_CURSOR_POSITION(GLFWwindow* window, double x, double y);
|
||||||
|
void BE_GLFW_CURSOR_ENTER(GLFWwindow* window, int entered);
|
||||||
|
void BE_GLFW_MOUSE_BUTTON(GLFWwindow* window, int button, int action, int mods);
|
||||||
|
void BE_GLFW_SCROLL(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +1,29 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <list>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "EventSystem/EventEmitter.h"
|
|
||||||
#include "EventSystem/EventListener.h"
|
|
||||||
#include "Graphics/Window.h"
|
#include "Graphics/Window.h"
|
||||||
|
#include "EventSystem/EventEmitter.h"
|
||||||
|
#include "../Include/Input/GLFWInput.h"
|
||||||
|
#include "BarinkEngine.h"
|
||||||
|
|
||||||
namespace BarinkEngine {
|
namespace BarinkEngine {
|
||||||
|
|
||||||
class InputManager : EventEmitter {
|
class InputManager : public EventEmitter {
|
||||||
public:
|
public:
|
||||||
InputManager();
|
InputManager();
|
||||||
|
|
||||||
void PollEvents();
|
void PollEvents();
|
||||||
|
|
||||||
void attach(BarinkWindow* window);
|
void attach(BarinkWindow* window);
|
||||||
|
void detach(BarinkWindow* window);
|
||||||
|
|
||||||
// GLFW Handlers
|
|
||||||
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
void setupGLFWInput(GLFWwindow* window);
|
||||||
static void CursorPositionCallback(GLFWwindow* window, double x, double y);
|
|
||||||
static void CursorEnterCallback(GLFWwindow* window, int entered);
|
|
||||||
static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
|
||||||
static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
|
||||||
private:
|
private:
|
||||||
std::vector<BarinkWindow*> windows;
|
std::list<BarinkWindow*> windows;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
extern BarinkEngine::InputManager InputSystem;
|
|
@ -3,13 +3,13 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
struct EngineStatistics {
|
struct EngineStatistics {
|
||||||
long long lastSampleTime;
|
uint32_t lastSampleTime;
|
||||||
float frameTime;
|
float frameTime;
|
||||||
uint32_t verts;
|
uint32_t verts;
|
||||||
uint32_t DC;
|
uint32_t DC;
|
||||||
|
|
||||||
long long frames;
|
uint64_t frames;
|
||||||
long long FPS;
|
uint64_t FPS;
|
||||||
};
|
};
|
||||||
extern EngineStatistics* ES;
|
extern EngineStatistics* ES;
|
||||||
|
|
||||||
@ -18,15 +18,15 @@ inline void PerfomanceSamplerInit(){
|
|||||||
ES->frames = 0;
|
ES->frames = 0;
|
||||||
ES->lastSampleTime = 0;
|
ES->lastSampleTime = 0;
|
||||||
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SamplePerformance(void) {
|
inline void SamplePerformance(void) {
|
||||||
ES->frames++;
|
ES->frames++;
|
||||||
ES->DC = 0;
|
ES->DC = 0;
|
||||||
ES->verts = 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 int 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;
|
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
|
||||||
if (MilliSecondsPast >= 1000) {
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
ES->frameTime = (float)1000 / ES->frames;
|
ES->frameTime = (float)1000 / ES->frames;
|
||||||
|
@ -2,22 +2,46 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Graphics/Transform.h"
|
#include "glm/glm.hpp"
|
||||||
#include "Scene/Node.h"
|
|
||||||
/*
|
/*
|
||||||
* Scene should be a description of a game world
|
* 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 {
|
class Scene {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Node& GetSceneNode(std::string);
|
SceneNode& GetSceneNode(std::string);
|
||||||
Node& GetRoot();
|
SceneNode& GetRoot();
|
||||||
|
|
||||||
Scene(const std::string& sceneName = "Default Scene");
|
Scene(std::string SceneName = "Default Scene");
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Node* root;
|
SceneNode* root;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "Graphics/Transform.h"
|
|
||||||
|
|
||||||
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);
|
|
||||||
Transform& transform;
|
|
||||||
|
|
||||||
};
|
|
@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Graphics/Renderable.h"
|
|
||||||
#include "Scene/SceneNodeTypes.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "../../src/Scene/SceneNodeTypes.cpp"
|
|
||||||
/*
|
|
||||||
* Define a helper class to more easily build a proper scene
|
|
||||||
*/
|
|
||||||
static class SceneBuilder {
|
|
||||||
|
|
||||||
static Group* AddGroup(std::string name);
|
|
||||||
static BarinkEngine::SceneObject* AddVisual(std::string name, BarinkEngine::Renderable& object, glm::vec3 position );
|
|
||||||
|
|
||||||
};
|
|
@ -1,17 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include "Scene.h"
|
|
||||||
class SceneManager {
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Scene* CreateScene(const std::string& name );
|
|
||||||
static Scene& GetScene(const std::string& name);
|
|
||||||
|
|
||||||
static void LoadScene(Scene& scene);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Scene* CurrentScene;
|
|
||||||
static std::map<std::string, Scene*> Scenes;
|
|
||||||
|
|
||||||
};
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Graphics/Camera.h"
|
|
||||||
#include "Graphics/Renderable.h"
|
|
||||||
#include "Scene/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;
|
|
||||||
};
|
|
||||||
}
|
|
104
BarinkEngine/Input/GLFWInput.cpp
Normal file
104
BarinkEngine/Input/GLFWInput.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#include "BarinkEngine.h"
|
||||||
|
#include "../Include/Input/GLFWInput.h"
|
||||||
|
#include "../Include/EventSystem/InputSystemEvents.h"
|
||||||
|
#include "../Include/Input/InputManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
namespace Input {
|
||||||
|
|
||||||
|
|
||||||
|
void BE_GLFW_KEYS(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case GLFW_KEY_DOWN: {
|
||||||
|
KEY_DOWN_EVENT keydown{};
|
||||||
|
keydown.name = "KEY::DOWN";
|
||||||
|
keydown.mods = mods;
|
||||||
|
keydown.scancode = scancode;
|
||||||
|
keydown.keycode = key;
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(keydown);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case GLFW_KEY_UP: {
|
||||||
|
KEY_UP_EVENT keyup{};
|
||||||
|
keyup.name = "KEY::DOWN";
|
||||||
|
keyup.mods = mods;
|
||||||
|
keyup.scancode = scancode;
|
||||||
|
keyup.keycode = key;
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(keyup);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
Event KeyEvent{};
|
||||||
|
KeyEvent.name = "KEY";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(KeyEvent);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BE_GLFW_CURSOR_POSITION(GLFWwindow* window, double x, double y)
|
||||||
|
{
|
||||||
|
Event CursorPosUpdate{};
|
||||||
|
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(CursorPosUpdate);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void BE_GLFW_CURSOR_ENTER(GLFWwindow* window, int entered)
|
||||||
|
{
|
||||||
|
if (entered) {
|
||||||
|
Event mouseEntered{};
|
||||||
|
mouseEntered.name = "Mouse Entered Window's confines!";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(mouseEntered);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Event mouseLeft{};
|
||||||
|
mouseLeft.name = "Mouse Left Window's confines!";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(mouseLeft);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BE_GLFW_MOUSE_BUTTON(GLFWwindow* window, int button, int action, int mods)
|
||||||
|
{
|
||||||
|
Event MouseButtonEvent{};
|
||||||
|
MouseButtonEvent.name = "MOUSEBUTTON";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(MouseButtonEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BE_GLFW_SCROLL(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
|
{
|
||||||
|
Event ScrollEvent{};
|
||||||
|
ScrollEvent.name = "SCROLL";
|
||||||
|
|
||||||
|
InputSystem.EmitEvent(ScrollEvent);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
BarinkEngine/Input/InputManager.cpp
Normal file
44
BarinkEngine/Input/InputManager.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "Input/InputManager.h"
|
||||||
|
|
||||||
|
namespace BarinkEngine {
|
||||||
|
|
||||||
|
void InputManager::PollEvents()
|
||||||
|
{
|
||||||
|
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
||||||
|
(*it)->Poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InputManager::setupGLFWInput(GLFWwindow* window) {
|
||||||
|
// Attach callbacks
|
||||||
|
glfwSetKeyCallback(window, BarinkEngine::Input::BE_GLFW_KEYS);
|
||||||
|
glfwSetCursorPosCallback(window, BarinkEngine::Input::BE_GLFW_CURSOR_POSITION);
|
||||||
|
glfwSetCursorEnterCallback(window, BarinkEngine::Input::BE_GLFW_CURSOR_ENTER);
|
||||||
|
glfwSetMouseButtonCallback(window, BarinkEngine::Input::BE_GLFW_MOUSE_BUTTON);
|
||||||
|
glfwSetScrollCallback(window, BarinkEngine::Input::BE_GLFW_SCROLL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InputManager::attach(BarinkWindow* window)
|
||||||
|
{
|
||||||
|
windows.push_back(window);
|
||||||
|
this->Subscribe((EventListener&)(*window));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputManager::detach(BarinkWindow* window)
|
||||||
|
{
|
||||||
|
windows.remove(window);
|
||||||
|
this->Unsubscribe((EventListener&)*window);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InputManager::InputManager() : EventEmitter()
|
||||||
|
{
|
||||||
|
windows = std::list<BarinkWindow*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
52
BarinkEngine/Scene.cpp
Normal file
52
BarinkEngine/Scene.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#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,47 +1,47 @@
|
|||||||
#include "Graphics/Buffer.h"
|
#include "Graphics/Buffer.h"
|
||||||
|
|
||||||
|
|
||||||
int GpuBuffer::getBufferID() {
|
int Buffer::getBufferID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuBuffer::createBuffer() {
|
void Buffer::createBuffer() {
|
||||||
glGenBuffers(1, (GLuint*) &id);
|
glGenBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
|
||||||
|
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuBuffer::Bind(bool elementBuffer = false ) {
|
void Buffer::Bind(bool elementBuffer = false ) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, id);
|
glBindBuffer(GL_ARRAY_BUFFER, id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuBuffer::Unbind(bool elementBuffer = false) {
|
void Buffer::Unbind(bool elementBuffer = false) {
|
||||||
if (elementBuffer) {
|
if (elementBuffer) {
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpuBuffer::Delete() {
|
void Buffer::Delete() {
|
||||||
glDeleteBuffers(1, (GLuint*) &id);
|
glDeleteBuffers(1, (GLuint*) &id);
|
||||||
}
|
}
|
@ -1,11 +1,10 @@
|
|||||||
#include "../Include/Graphics/Material.h"
|
#include "../Include/Graphics/Material.h"
|
||||||
|
|
||||||
Material::Material(const Shader& shader) :
|
Material::Material(const Shader& shader) :
|
||||||
shader(shader) {
|
shader(shader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Material::Apply() const {
|
|
||||||
|
void Material::Apply() {
|
||||||
shader.Use();
|
shader.setUniformVec3("Color", Color);
|
||||||
shader.setUniformVec3("Color", Color);
|
|
||||||
}
|
}
|
@ -1,100 +1,80 @@
|
|||||||
#include "AssetManager/ModelImporter.h"
|
#include "AssetManager/ModelImporter.h"
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
|
|
||||||
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
|
std::vector<BarinkEngine::Mesh> ModelImporter::Import(std::string path)
|
||||||
{
|
{
|
||||||
SceneObject* root = new SceneObject(std::string(path), nullptr);
|
Assimp::Importer importer;
|
||||||
|
const aiScene* scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
Assimp::Importer importer;
|
aiNode* currentNode = scene->mRootNode;
|
||||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
|
||||||
|
return processNode(currentNode, scene);
|
||||||
aiNode* currentNode = scene->mRootNode;
|
}
|
||||||
|
|
||||||
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
|
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
|
||||||
|
std::vector<BarinkEngine::Mesh> meshes;
|
||||||
std::cout << "[DEBUG]: Loaded "<< meshes.size() << " meshes!" << std::endl;
|
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
||||||
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
|
meshes.push_back(processMesh(mesh, scene));
|
||||||
// create a renderable (per mesh ?? )
|
}
|
||||||
root->renderable = new Renderable();
|
|
||||||
root->renderable->mesh = &(meshes[0]);
|
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
||||||
|
auto m2 = processNode(node->mChildren[i], scene);
|
||||||
return root;
|
|
||||||
|
for(auto m : m2) {
|
||||||
}
|
meshes.push_back(m);
|
||||||
|
}
|
||||||
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
|
}
|
||||||
{
|
|
||||||
|
return meshes;
|
||||||
std::vector<BarinkEngine::Mesh> meshes;
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
|
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
std::vector<unsigned int> indices;
|
||||||
meshes.push_back(processMesh(mesh, scene));
|
std::vector<BarinkEngine::Vertex> vertices;
|
||||||
}
|
|
||||||
|
// Process vertices
|
||||||
for (unsigned int i = 0; i < node->mNumChildren; i++) {
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
|
||||||
auto m2 = processNode(node->mChildren[i], scene);
|
BarinkEngine::Vertex v{};
|
||||||
|
glm::vec3 vector;
|
||||||
for(auto m : m2) {
|
vector.x = mesh->mVertices[i].x;
|
||||||
meshes.push_back(m);
|
vector.y = mesh->mVertices[i].y;
|
||||||
}
|
vector.z = mesh->mVertices[i].z;
|
||||||
}
|
|
||||||
|
v.vertices = vector;
|
||||||
return meshes;
|
|
||||||
}
|
if (mesh->mTextureCoords[0]) {
|
||||||
|
|
||||||
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
|
glm::vec2 texCoord;
|
||||||
std::vector<unsigned int> indices;
|
|
||||||
std::vector<BarinkEngine::Vertex> vertices;
|
texCoord.x = mesh->mTextureCoords[0][i].x;
|
||||||
|
texCoord.y = mesh->mTextureCoords[0][i].y;
|
||||||
ProcessVertices(mesh, vertices);
|
|
||||||
|
v.uv = texCoord;
|
||||||
ProcessIndices(mesh, indices);
|
|
||||||
|
}
|
||||||
BarinkEngine::Mesh result;
|
|
||||||
result.vertices = vertices;
|
vertices.push_back(v);
|
||||||
result.elements = indices;
|
}
|
||||||
|
|
||||||
|
// Process Indices
|
||||||
return result;
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
}
|
if (face.mNumIndices < 3)
|
||||||
|
continue;
|
||||||
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices) {
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
// Process vertices
|
indices.push_back(face.mIndices[j]);
|
||||||
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;
|
BarinkEngine::Mesh result;
|
||||||
|
|
||||||
v.vertices = vector;
|
|
||||||
|
result.vertices = vertices;
|
||||||
if (mesh->mTextureCoords[0]) {
|
result.elements = indices;
|
||||||
|
|
||||||
glm::vec2 texCoord;
|
|
||||||
|
return result;
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
62
BarinkEngine/graphics/Renderable.cpp
Normal file
62
BarinkEngine/graphics/Renderable.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "Graphics/Renderable.h"
|
||||||
|
#include "AssetManager/ModelImporter.h"
|
||||||
|
#include "PerfCounter.h"
|
||||||
|
|
||||||
|
|
||||||
|
Renderable* Renderable::Load(std::string& path)
|
||||||
|
{
|
||||||
|
return new Renderable(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderable::Renderable(std::string& path)
|
||||||
|
{
|
||||||
|
meshes = ModelImporter::Import(path);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
25
BarinkEngine/graphics/Renderer.cpp
Normal file
25
BarinkEngine/graphics/Renderer.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#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);
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
#include "Graphics/Shader.h"
|
#include "Graphics/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];
|
||||||
@ -58,12 +57,8 @@ 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);
|
||||||
|
|
||||||
@ -95,7 +90,7 @@ char* Shader::readFile (const char* filePath){
|
|||||||
return FileBuffer;
|
return FileBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::Use() const
|
void Shader::Use()
|
||||||
{
|
{
|
||||||
glUseProgram(id);
|
glUseProgram(id);
|
||||||
}
|
}
|
@ -1,40 +1,40 @@
|
|||||||
#include "../Include/Graphics/Texture.h"
|
#include "../Include/Graphics/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 "Graphics/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,25 +1,25 @@
|
|||||||
#include "Graphics/VertexArray.h"
|
#include "Graphics/VertexArray.h"
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
void VertexArray::Create(){
|
void VertexArray::Create(){
|
||||||
glGenVertexArrays(1, &id);
|
glGenVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Bind(){
|
void VertexArray::Bind(){
|
||||||
glBindVertexArray(id);
|
glBindVertexArray(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Unbind(){
|
void VertexArray::Unbind(){
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::Delete() {
|
void VertexArray::Delete() {
|
||||||
glDeleteVertexArrays(1, &id);
|
glDeleteVertexArrays(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
void VertexArray::AttachAttribute(unsigned int index , int size, int stride ){
|
||||||
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
}
|
}
|
||||||
|
|
@ -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 = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
|
||||||
}
|
}
|
@ -1,86 +1,87 @@
|
|||||||
#include "Graphics/Window.h"
|
#include "Graphics/Window.h"
|
||||||
|
#include <stdlib.h>
|
||||||
bool BarinkWindow::InitGLFW(){
|
#include <stdio.h>
|
||||||
if(!glfwInit())
|
#include <iostream>
|
||||||
{
|
#include <GLFW/glfw3.h>
|
||||||
spdlog::error("Failed to initialise GLFW!");
|
#include <spdlog/spdlog.h>
|
||||||
return false;
|
#include "../Include/EventSystem/Event.h"
|
||||||
}
|
|
||||||
|
bool BarinkWindow::InitGLFW(){
|
||||||
return true;
|
if(!glfwInit())
|
||||||
}
|
{
|
||||||
|
spdlog::error("Failed to initialise GLFW!");
|
||||||
BarinkWindow::BarinkWindow(const int width, const int height) :
|
return false;
|
||||||
Width(width), Height(height), FullScreen(false){
|
}
|
||||||
if (InitGLFW()==false) {
|
|
||||||
exit(-1);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
BarinkWindow::BarinkWindow(const int width, const int height) :
|
||||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
|
Width(width), Height(height), FullScreen(false){
|
||||||
// No window decorations such as a border, a close widget
|
if (InitGLFW()==false) {
|
||||||
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
exit(-1);
|
||||||
//glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
}
|
||||||
// Disable resizing the window
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||||
|
|
||||||
|
if( !window)
|
||||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
{
|
||||||
|
spdlog::error("GLFW failed to create window!");
|
||||||
if( !window)
|
glfwTerminate();
|
||||||
{
|
return;
|
||||||
spdlog::error("GLFW failed to create window!");
|
}
|
||||||
glfwTerminate();
|
|
||||||
return;
|
glfwMakeContextCurrent(window);
|
||||||
}
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
|
printf("Failed to initialize GLAD!\n");
|
||||||
glfwMakeContextCurrent(window);
|
exit(-1);
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
}
|
||||||
printf("Failed to initialize GLAD!\n");
|
|
||||||
exit(-1);
|
// Set vsync off !!
|
||||||
}
|
glfwSwapInterval(0);
|
||||||
|
|
||||||
// Set vsync off !!
|
VulkanSupported = glfwVulkanSupported();
|
||||||
glfwSwapInterval(0);
|
|
||||||
|
glfwGetFramebufferSize(window, &Width, &Height);
|
||||||
VulkanSupported = glfwVulkanSupported();
|
glViewport(0,0, Width, Height);
|
||||||
|
|
||||||
glfwGetFramebufferSize(window, &Width, &Height);
|
|
||||||
glViewport(0,0, Width, Height);
|
|
||||||
|
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
|
||||||
|
}
|
||||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
|
||||||
|
|
||||||
}
|
BarinkWindow::~BarinkWindow(){
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
BarinkWindow::~BarinkWindow(){
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
GLFWwindow* BarinkWindow::windowptr()
|
||||||
}
|
{
|
||||||
|
return window;
|
||||||
GLFWwindow* BarinkWindow::windowptr()
|
}
|
||||||
{
|
|
||||||
return window;
|
bool BarinkWindow::WindowShouldClose(){
|
||||||
}
|
return glfwWindowShouldClose(window);
|
||||||
|
}
|
||||||
bool BarinkWindow::WindowShouldClose(){
|
|
||||||
return glfwWindowShouldClose(window);
|
void BarinkWindow::Poll()
|
||||||
}
|
{
|
||||||
|
glfwPollEvents();
|
||||||
void BarinkWindow::Poll()
|
}
|
||||||
{
|
|
||||||
glfwPollEvents();
|
void BarinkWindow::SwapBuffers()
|
||||||
}
|
{
|
||||||
|
glfwSwapBuffers(window);
|
||||||
void BarinkWindow::SwapBuffers()
|
}
|
||||||
{
|
|
||||||
glfwSwapBuffers(window);
|
|
||||||
}
|
void BarinkWindow::ReceiveEvent(Event& incident)
|
||||||
|
{
|
||||||
void BarinkWindow::ReceiveEvent(Event& incident)
|
|
||||||
{
|
|
||||||
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
|
||||||
}
|
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
|
||||||
|
|
||||||
|
}
|
@ -52,10 +52,10 @@ project "BarinkEngine"
|
|||||||
files {
|
files {
|
||||||
"../libs/glad/src/glad.c",
|
"../libs/glad/src/glad.c",
|
||||||
|
|
||||||
"./src/*.cpp",
|
"./*.cpp",
|
||||||
"./Include/*.h",
|
"./*.h",
|
||||||
"./src/**/*.cpp",
|
"./**/*.cpp",
|
||||||
"./Include/**/*.h"
|
"./**/*.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,10 +63,10 @@ project "BarinkEngine"
|
|||||||
filter { "system:windows"}
|
filter { "system:windows"}
|
||||||
prebuildcommands {
|
prebuildcommands {
|
||||||
-- Copy shaders
|
-- Copy shaders
|
||||||
"copy src\\graphics\\shaders\\fragment.shader ..\\build\\SandboxApplication\\Debug\\test.fs",
|
"copy graphics\\shaders\\fragment.shader ..\\build\\SandboxApplication\\Debug\\test.fs",
|
||||||
"copy src\\graphics\\shaders\\vertex.shader ..\\build\\SandboxApplication\\Debug\\test.vs",
|
"copy graphics\\shaders\\vertex.shader ..\\build\\SandboxApplication\\Debug\\test.vs",
|
||||||
"copy src\\graphics\\shaders\\RenderSurfaceFrag.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.fs",
|
"copy graphics\\shaders\\RenderSurfaceFrag.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.fs",
|
||||||
"copy src\\graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs"
|
"copy graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -74,10 +74,10 @@ project "BarinkEngine"
|
|||||||
filter { "system:linux" }
|
filter { "system:linux" }
|
||||||
prebuildcommands {
|
prebuildcommands {
|
||||||
-- Copy shaders
|
-- Copy shaders
|
||||||
"cp src/graphics/shaders/fragment.shader ../build/SandboxApplication/Debug/test.fs",
|
"cp graphics/shaders/fragment.shader ../build/SandboxApplication/Debug/test.fs",
|
||||||
"cp src/graphics/shaders/vertex.shader ../build/SandboxApplication/Debug/test.vs",
|
"cp graphics/shaders/vertex.shader ../build/SandboxApplication/Debug/test.vs",
|
||||||
"cp src/graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs",
|
"cp graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs",
|
||||||
"cp src/graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs"
|
"cp graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs"
|
||||||
}
|
}
|
||||||
|
|
||||||
include('../ImGui')
|
include('../ImGui')
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
#include "Graphics/GPUBucket.h"
|
|
||||||
BarinkEngine::GPU_Bucket::GPU_Bucket() {
|
|
||||||
}
|
|
||||||
BarinkEngine::GPU_Bucket::~GPU_Bucket() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::GPU_Bucket::Upload(const Mesh& renderable) {
|
|
||||||
|
|
||||||
// keep a ref to the origin in main memory
|
|
||||||
mesh = &renderable;
|
|
||||||
|
|
||||||
// Upload gpu
|
|
||||||
|
|
||||||
vertexarray.Create();
|
|
||||||
vertexarray.Bind();
|
|
||||||
|
|
||||||
vertexBuffer.createBuffer();
|
|
||||||
vertexBuffer.Bind(false);
|
|
||||||
vertexBuffer.setBufferData((void*)&renderable.vertices[0], renderable.vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
|
||||||
|
|
||||||
if (renderable.elements.empty() == false) {
|
|
||||||
elementBuffer.createBuffer();
|
|
||||||
elementBuffer.Bind(true);
|
|
||||||
elementBuffer.setBufferData((void*)&renderable.elements[0], renderable.elements.size() * sizeof(unsigned int), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
vertexarray.AttachAttribute(0, 3, sizeof(Vertex));
|
|
||||||
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)offsetof(BarinkEngine::Vertex, vertices));
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
vertexBuffer.Unbind(false);
|
|
||||||
vertexarray.Unbind();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
#include "Graphics/Renderer.h"
|
|
||||||
|
|
||||||
|
|
||||||
BarinkEngine::Renderer::Renderer()
|
|
||||||
{
|
|
||||||
models = std::vector<GPU_Bucket*>();
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BarinkEngine::Renderer::~Renderer()
|
|
||||||
{
|
|
||||||
// CleanUp!
|
|
||||||
|
|
||||||
// For each model submitted
|
|
||||||
for ( auto packet : models )
|
|
||||||
{
|
|
||||||
delete packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
// glDeleteBuffers(1, &UV_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::Renderer::Render()
|
|
||||||
{
|
|
||||||
// This creation of the projection and camera is somewhat wastefull
|
|
||||||
Camera cam = Camera(glm::vec3(0.0f, 1.5f, 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);
|
|
||||||
|
|
||||||
|
|
||||||
for (auto model : models) {
|
|
||||||
// Push matrices etc ....
|
|
||||||
model->vertexarray.Bind();
|
|
||||||
|
|
||||||
model->elementBuffer.Bind(true);
|
|
||||||
|
|
||||||
|
|
||||||
if (model->material == nullptr) {
|
|
||||||
std::cout << "No material attached!" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
model->material->Apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update perf counters
|
|
||||||
ES->verts = model->mesh->vertices.size();
|
|
||||||
ES->DC++;
|
|
||||||
|
|
||||||
glDrawElements( GL_TRIANGLES,
|
|
||||||
static_cast<unsigned int>(model->mesh->elements.size()),
|
|
||||||
GL_UNSIGNED_INT,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
model->vertexarray.Unbind();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Upload data to cpu and add object to render list
|
|
||||||
void BarinkEngine::Renderer::Submit(Renderable* model)
|
|
||||||
{
|
|
||||||
// Upload mesh data to gpu for render
|
|
||||||
|
|
||||||
GPU_Bucket* bucket = new GPU_Bucket();
|
|
||||||
|
|
||||||
bucket->material = model->material;
|
|
||||||
|
|
||||||
bucket->Upload(*model->mesh);
|
|
||||||
|
|
||||||
models.push_back(bucket); // Maybe push a GPU packet or something instead
|
|
||||||
|
|
||||||
}
|
|
@ -1,118 +0,0 @@
|
|||||||
#include "Input/InputManager.h"
|
|
||||||
BarinkEngine::InputManager InputSystem;
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::PollEvents()
|
|
||||||
{
|
|
||||||
for (auto it = windows.begin(); it != windows.end(); ++it) {
|
|
||||||
auto window = *it;
|
|
||||||
window->Poll();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
||||||
{
|
|
||||||
|
|
||||||
Event KeyEvent{};
|
|
||||||
KeyEvent.name = "KEY";
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(KeyEvent);
|
|
||||||
|
|
||||||
|
|
||||||
if (key == GLFW_KEY_A && action == GLFW_PRESS)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::cout << "'a' key was pressed" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::CursorPositionCallback(GLFWwindow* window, double x, double y)
|
|
||||||
{
|
|
||||||
//std::cout << "Cursor Position x: " << x << ", y: " << y << std::endl;
|
|
||||||
Event CursorPosUpdate{};
|
|
||||||
CursorPosUpdate.name = "UPDATE::CURSOR:POSITION";
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(CursorPosUpdate);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::CursorEnterCallback(GLFWwindow* window, int entered)
|
|
||||||
{
|
|
||||||
if (entered) {
|
|
||||||
Event mouseEntered {};
|
|
||||||
mouseEntered.name = "Mouse Entered Window's confines!";
|
|
||||||
mouseEntered.argc = 0;
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(mouseEntered);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Event mouseLeft{};
|
|
||||||
mouseLeft.name = "Mouse Left Window's confines!";
|
|
||||||
mouseLeft.argc = 0;
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(mouseLeft);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
|
||||||
{
|
|
||||||
|
|
||||||
Event MouseButtonEvent{};
|
|
||||||
MouseButtonEvent.name = "MOUSEBUTTON";
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(MouseButtonEvent);
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
std::cout << "Scroll: x: " << xoffset << ", y: " << yoffset << std::endl;
|
|
||||||
|
|
||||||
Event ScrollEvent{};
|
|
||||||
ScrollEvent.name = "SCROLL";
|
|
||||||
|
|
||||||
InputSystem.EmitEvent(ScrollEvent);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BarinkEngine::InputManager::attach(BarinkWindow* window)
|
|
||||||
{
|
|
||||||
|
|
||||||
windows.push_back(window);
|
|
||||||
|
|
||||||
// Attach callbacks
|
|
||||||
glfwSetKeyCallback(window->windowptr(), KeyCallback);
|
|
||||||
glfwSetCursorPosCallback(window->windowptr(), CursorPositionCallback);
|
|
||||||
glfwSetCursorEnterCallback(window->windowptr(), CursorEnterCallback);
|
|
||||||
glfwSetMouseButtonCallback(window->windowptr(), MouseButtonCallback);
|
|
||||||
glfwSetScrollCallback(window->windowptr(), ScrollCallback);
|
|
||||||
|
|
||||||
this->Subscribe( (EventListener&)(*window));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BarinkEngine::InputManager::InputManager() : EventEmitter ()
|
|
||||||
{
|
|
||||||
windows = std::vector<BarinkWindow*>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
#include "Scene.h"
|
|
||||||
#include "Scene.h"
|
|
||||||
#include "Scene/Node.h"
|
|
||||||
void DeleteSubGraph(Node* tree);
|
|
||||||
|
|
||||||
Scene::Scene(const std::string& sceneName)
|
|
||||||
{
|
|
||||||
// Create a root node
|
|
||||||
root = new Group(sceneName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene::~Scene()
|
|
||||||
{
|
|
||||||
// Delete all nodes in the graph.
|
|
||||||
DeleteSubGraph(root);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Node* SearchInChildren(Node* root, const std::string name ) {
|
|
||||||
|
|
||||||
if (root->name == name)
|
|
||||||
return root;
|
|
||||||
|
|
||||||
Node* found = nullptr;
|
|
||||||
for (auto child : root->children) {
|
|
||||||
found = SearchInChildren(child, name);
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Node& Scene::GetSceneNode(std::string name)
|
|
||||||
{
|
|
||||||
return *SearchInChildren(root, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Node& Scene::GetRoot()
|
|
||||||
{
|
|
||||||
return *root;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Node::addChild(Node& node)
|
|
||||||
{
|
|
||||||
children.push_back(&node);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DeleteSubGraph(Node* tree)
|
|
||||||
{
|
|
||||||
if (tree->children.size() == 0) {
|
|
||||||
delete tree;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto child : tree->children) {
|
|
||||||
if (child->children.size() > 0) {
|
|
||||||
DeleteSubGraph(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
#include "Scene/Node.h"
|
|
||||||
|
|
||||||
Node::Node(const std::string& name)
|
|
||||||
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
|
||||||
|
|
||||||
Group::Group(const std::string& name )
|
|
||||||
: Node(name), transform(Transform()) {}
|
|
@ -1,22 +0,0 @@
|
|||||||
#include "Scene/SceneManager.h"
|
|
||||||
|
|
||||||
Scene* SceneManager::CreateScene(const std::string& name)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Scenes = std::map<std::string, Scene*>();
|
|
||||||
SceneManager::Scenes[name] = new Scene(name);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return new Scene(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene& SceneManager::GetScene(const std::string& name)
|
|
||||||
{
|
|
||||||
return Scene();
|
|
||||||
//return *SceneManager::Scenes[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
void SceneManager::LoadScene( Scene& scene)
|
|
||||||
{
|
|
||||||
//SceneManager::CurrentScene = &scene;
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
#include "Scene/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()
|
|
||||||
{}
|
|
BIN
Manuals/GLSL.std.450.pdf
Normal file
BIN
Manuals/GLSL.std.450.pdf
Normal file
Binary file not shown.
BIN
Manuals/SPIRV.pdf
Normal file
BIN
Manuals/SPIRV.pdf
Normal file
Binary file not shown.
@ -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
|
@ -1,71 +1,41 @@
|
|||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
|
||||||
void SceneExplorer(Scene& scene, std::string PanelName) {
|
void CameraTool(Camera* cam) {
|
||||||
if (ImGui::Begin(PanelName.c_str())) {
|
|
||||||
ImGui::ListBoxHeader("##ObjectList");
|
ImGui::Begin("Camera");
|
||||||
|
|
||||||
Node& current = scene.GetRoot();
|
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
||||||
|
|
||||||
Node* next = ¤t;
|
ImGui::InputFloat3("Position:", &cam->Position[0]);
|
||||||
|
|
||||||
// Show first node
|
ImGui::InputFloat3("Rotation:", &cam->Rotation[0]);
|
||||||
ImGui::Selectable(next->name.c_str(), true);
|
|
||||||
|
ImGui::End();
|
||||||
ImGui::Indent();
|
}
|
||||||
|
|
||||||
if (next->children.size() != 0) {
|
void ScriptingTool(char* code) {
|
||||||
for (auto child : next->children)
|
ImGui::Begin("Scripting");
|
||||||
{
|
|
||||||
std::string& name = child->name;
|
ImGui::InputTextMultiline("Lua Script", code, 255);
|
||||||
ImGui::Selectable(name.c_str(), false);
|
bool runCode = ImGui::Button("Run");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
ImGui::End();
|
||||||
ImGui::ListBoxFooter();
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
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]);
|
||||||
void CameraTool(Camera* cam) {
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Begin("Camera");
|
}
|
||||||
|
|
||||||
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
void materialWindow(Material& material, std::string PanelName) {
|
||||||
|
ImGui::Begin(PanelName.c_str());
|
||||||
ImGui::InputFloat3("Position:", &cam->Position[0]);
|
ImGui::ColorPicker3("Color:", &material.Color[0]);
|
||||||
|
ImGui::End();
|
||||||
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,9 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <BarinkEngine.h>
|
#include <BarinkEngine.h>
|
||||||
|
|
||||||
void CameraTool(Camera* camera);
|
void CameraTool(Camera* camera);
|
||||||
void ScriptingTool(char* code);
|
void ScriptingTool(char* code);
|
||||||
void transformWindow(Transform& transform, std::string PanelName);
|
void transformWindow(Transform& transform, std::string PanelName);
|
||||||
void materialWindow(Material& material, std::string PanelName);
|
void materialWindow(Material& material, std::string PanelName);
|
||||||
void SceneExplorer(Scene& scene, std::string PanelName);
|
|
176
SandboxApplication/Sandbox.cpp
Normal file
176
SandboxApplication/Sandbox.cpp
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
#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);
|
||||||
|
|
||||||
|
std::string cubePath = "build/SandboxApplication/Debug/Models/Cube.obj";
|
||||||
|
std::string lanternPath = "build/SandboxApplication/Debug/Models/Latern.gltf";
|
||||||
|
/*
|
||||||
|
* load meshes
|
||||||
|
*/
|
||||||
|
Cube = Renderable::Load(lanternPath);
|
||||||
|
Cube2 = Renderable::Load(cubePath);
|
||||||
|
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 +1,6 @@
|
|||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
void PrintSceneTree(Node& node, int depth) {
|
void PrintSceneTree(SceneNode& 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++) {
|
6
SandboxApplication/Util.h
Normal file
6
SandboxApplication/Util.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "BarinkEngine.h"
|
||||||
|
|
||||||
|
void PrintSceneTree(SceneNode& node, int depth);
|
||||||
|
|
||||||
|
glm::mat4 CalculateModelMat(Transform& transform);
|
@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "BarinkEngine.h"
|
|
||||||
|
|
||||||
void PrintSceneTree(Node& node, int depth);
|
|
||||||
|
|
||||||
glm::mat4 CalculateModelMat(Transform& transform);
|
|
@ -1,40 +0,0 @@
|
|||||||
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",
|
|
||||||
|
|
||||||
|
|
||||||
"./include"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
libdirs {
|
|
||||||
'./../build/BarinkEngine/Debug'
|
|
||||||
}
|
|
||||||
|
|
||||||
files {
|
|
||||||
"./include/*.h",
|
|
||||||
"./src/*.cpp"
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,102 +0,0 @@
|
|||||||
#include "BarinkEngine.h"
|
|
||||||
#include "Scene\SceneManager.h"
|
|
||||||
#include "Scene\SceneNodeTypes.h"
|
|
||||||
#include "AssetManager/ModelImporter.h"
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "GUI.h"
|
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define globals
|
|
||||||
*/
|
|
||||||
Shader* shader;
|
|
||||||
|
|
||||||
char* code = new char[254];
|
|
||||||
|
|
||||||
const std::string vertexShaderSource = "../build/SandboxApplication/Debug/test.vs";
|
|
||||||
const std::string fragmentShaderSource = "../build/SandboxApplication/Debug/test.fs";
|
|
||||||
|
|
||||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
|
||||||
|
|
||||||
Scene* Level1;
|
|
||||||
BarinkEngine::Renderer* renderer;
|
|
||||||
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/SandboxApplication/Debug/Models/Cube.obj");
|
|
||||||
cube->renderable->material = new Material(*shader);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// TODO: Move to runtime/ Engine
|
|
||||||
renderer = new BarinkEngine::Renderer();
|
|
||||||
// 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::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);
|
|
||||||
|
|
||||||
SceneExplorer(*Level1, "Scene Explorer");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs every frame
|
|
||||||
* - Meant for game logic ( non-physics related)
|
|
||||||
*/
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
renderer->Render();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Runs at the end of the program
|
|
||||||
* - Meant for cleanup
|
|
||||||
*/
|
|
||||||
void Stop() {
|
|
||||||
delete MI;
|
|
||||||
delete renderer;
|
|
||||||
delete shader;
|
|
||||||
}
|
|
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" checked></input> Input handling \
|
<input type="checkbox"></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,6 +21,5 @@
|
|||||||
|
|
||||||
|
|
||||||
## 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 \
|
|
||||||
|
42
premake5.lua
42
premake5.lua
@ -18,6 +18,46 @@ workspace "BarinkEngine"
|
|||||||
defines {"NDEBUG"}
|
defines {"NDEBUG"}
|
||||||
optimize "On"
|
optimize "On"
|
||||||
|
|
||||||
include("./SandboxApplication")
|
|
||||||
|
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")
|
||||||
|
Reference in New Issue
Block a user