Engine clean

Added namespaces to the core engine, improved premake setup, added a buildsolution batch script, removed tinygltf submodule
This commit is contained in:
Nigel Barink 2022-11-04 14:14:53 +01:00
parent 644b6db100
commit b44c88d05c
111 changed files with 1700 additions and 1567 deletions

4
.gitmodules vendored
View File

@ -8,10 +8,6 @@
[submodule "spdlog"]
path = libs/spdlog
url = https://github.com/nigelbarink/spdlog.git
[submodule "tinygltf"]
path = libs/tinygltf
url = https://github.com/syoyo/tinygltf.git
ignore = untracked
[submodule "GorrillaAudio"]
path = libs/GorillaAudio
url = https://github.com/mewspring/gorilla-audio.git

View File

@ -1,99 +0,0 @@
#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]);
}
}
}

View File

@ -1,35 +0,0 @@
#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);
};
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <string>
struct Event
{
public:
std::string name;
int argc;
void** argv;
};

View File

@ -1,25 +0,0 @@
#include "EventEmitter.h"
void EventEmitter::Subscribe(EventListener& subscriber)
{
subscribers.push_back(&subscriber);
}
void EventEmitter::Unsubscribe(EventListener& subscriber)
{
subscribers.remove(&subscriber);
}
void EventEmitter::EmitEvent(Event& incident)
{
// Notify all subscribers an event has taken place
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
{
(*it)->ReceiveEvent(incident);
}
}
EventEmitter::EventEmitter() {
subscribers = std::list<EventListener*>{};
}

View File

@ -1,16 +0,0 @@
#pragma once
#include "Event.h"
#include "EventListener.h"
class EventEmitter {
public:
void Subscribe (EventListener& subscriber);
void Unsubscribe(EventListener& subscriber);
protected:
std::list<EventListener*> subscribers;
void EmitEvent(Event& incident);
EventEmitter();
};

View File

@ -1,12 +0,0 @@
#pragma once
#include <list>
#include <iostream>
#include "spdlog/spdlog.h"
#include "Event.h"
class EventListener{
public:
virtual void ReceiveEvent(Event& incident) = 0 ;
};

View File

@ -1,61 +0,0 @@
#include "GUIManager.h"
#include "imgui.h"
#include "backends/imgui_impl_opengl3.h"
#include <backends/imgui_impl_glfw.h>
#include "../../libs/guizmo/ImGuizmo.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();
ImGuizmo::SetOrthographic(true);
ImGuizmo::BeginFrame();
ImmediateGraphicsDraw();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* last_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(last_context);
}
}

View File

@ -1,15 +0,0 @@
#pragma once
#include "../Platform/Window.h"
class GUIManager {
public:
GUIManager(BarinkWindow* window);
~GUIManager();
void Render();
private:
BarinkWindow* currentwindow;
};

View File

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

View File

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

View File

@ -1,71 +0,0 @@
#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, 0, 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);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0);
// Create a depth buffer
glGenTextures(1, &DepthAttachment);
glBindTexture(GL_TEXTURE_2D, DepthAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 800, 600, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DepthAttachment, 0);
/*
* // Render buffer
glGenRenderbuffers(1, &DepthAttachment);
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
*/
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);
}

View File

@ -1,21 +0,0 @@
#pragma once
#include <glad/glad.h>
#include <glm/glm.hpp>
class Framebuffer {
public:
Framebuffer();
~Framebuffer();
GLuint GetId() { return Id; }
GLuint GetColourAttachment() { return ColourAttachment; }
GLuint GetDepthAttachment() { return DepthAttachment; }
private:
GLuint Id = 0;
GLuint ColourAttachment = 0;
GLuint DepthAttachment = 0;
};

View File

@ -1,31 +0,0 @@
#include "UniformBuffer.h"
#include <glad/glad.h>
UniformBuffer::UniformBuffer(unsigned int size)
{
glGenBuffers(1, &Id );
glBindBuffer(GL_ARRAY_BUFFER, Id);
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
UniformBuffer::~UniformBuffer()
{
glDeleteBuffers(1, &Id);
}
void UniformBuffer::setData( unsigned int offset , unsigned int size , void* data)
{
glBindBuffer(GL_ARRAY_BUFFER, Id);
glBufferSubData(GL_ARRAY_BUFFER, offset , size, data);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void UniformBuffer::setDescriptor(unsigned int index, unsigned int size , unsigned int stride, void* pointer)
{
glBindBuffer(GL_ARRAY_BUFFER, Id);
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, pointer);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

View File

@ -1,15 +0,0 @@
#pragma once
class UniformBuffer {
public:
UniformBuffer (unsigned int size);
~UniformBuffer();
void setData(unsigned int offset, unsigned int size, void* data);
void setDescriptor(unsigned int index, unsigned int size, unsigned int stride, void* pointer);
private:
unsigned int Id;
};

View File

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

View File

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

View File

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

View File

@ -1,22 +0,0 @@
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
class Camera {
public:
glm::vec3 Position;
glm::vec3 Rotation;
float Zoom;
Camera(glm::vec3 position, glm::vec3 rotation, float zoom );
~Camera();
glm::mat4 GetViewMatrix();
private:
glm::vec3 Front;
glm::vec3 Right;
glm::vec3 Up;
};

View File

@ -1,11 +0,0 @@
#include "Material.h"
Material::Material(const Shader& shader) :
shader(shader) {
}
void Material::Apply() const {
shader.Use();
shader.setUniformVec3("Color", Color);
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <glm/glm.hpp>
#include <string>
#include "Shader.h"
class Material {
public:
Material(const Shader& shader);
void Apply()const;
glm::vec3 Color;
const Shader& shader;
};

View File

@ -1,129 +0,0 @@
#include "Shader.h"
#include "spdlog/spdlog.h"
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
{
char infoLog[512];
int succes;
char* vertexCode = readFile(vertexShaderPath.c_str());
//spdlog::info(vertexCode);
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertId, 1, &vertexCode, NULL);
glCompileShader(vertId);
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
if(!succes){
glGetShaderInfoLog(vertId, 512, NULL, infoLog);
spdlog::error( "Vertex shader has compile error {}", infoLog);
return;
}
char* fragmentCode = readFile(fragmentShaderPath.c_str());
//spdlog::info(fragmentCode);
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragId, 1, &fragmentCode, NULL);
glCompileShader(fragId);
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
if(!succes){
glGetShaderInfoLog(fragId, 512, NULL, infoLog);
spdlog::error("Fragment shader has compile error {}", infoLog);
return;
}
id = glCreateProgram();
glAttachShader(id, vertId);
glAttachShader(id, fragId);
glLinkProgram(id);
int success;
glGetProgramiv(id, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(id, 512, NULL, infoLog);
printf("ERROR::SHADER_PROGRAM::LINKING_FAILED\n %s", infoLog);
}
delete vertexCode;
delete fragmentCode;
}
char* Shader::readFile (const char* filePath){
spdlog::info("Opening {} ", filePath);
std::ifstream file ;
file.open(filePath);
if(file.is_open() == false){
spdlog::info("File not found.");
return nullptr;
}
// Determine the file size!
file.seekg(0, std::ios::end);
size_t filesize = file.tellg();
// Undo previous seek.
file.seekg(0, std::ios::beg);
//spdlog::info("filesize: {}", filesize);
// Create a big enough buffer for the file
size_t bufferSize = filesize + 3;
char* FileBuffer = new char[bufferSize];
memset(FileBuffer, '\0', bufferSize);
// read the whole file
file.read(FileBuffer, filesize);
return FileBuffer;
}
void Shader::Use() const
{
glUseProgram(id);
}
void Shader::setUniformMat4(std::string uniformName, glm::mat4 matrix4) const
{
glUniformMatrix4fv(glGetUniformLocation(id, uniformName.c_str()), 1, GL_FALSE, glm::value_ptr(matrix4));
}
void Shader::setUniformVec4(std::string uniformName, glm::vec4 vector4) const
{
glUniform4fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector4));
}
void Shader::setUniformVec3(std::string uniformName, glm::vec3 vector3) const
{
glUniform3fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector3));
}
void Shader::setUniformVec2(std::string uniformName, glm::vec2 vector2) const
{
glUniform2fv(glGetUniformLocation(id, uniformName.c_str()),1, glm::value_ptr(vector2));
}
void Shader::setUniformFloat(std::string uniformName, float value) const
{
glUniform1f(glGetUniformLocation(id, uniformName.c_str()), value);
}
void Shader::setUniformInt(std::string uniformName, int value) const
{
glUniform1i(glGetUniformLocation(id, uniformName.c_str()), value);
}

View File

@ -1,40 +0,0 @@
#include "Texture.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define STB_IMAGE_IMPLEMENTATION
#include "../stb_image.h"
#include <iostream>
Texture::Texture(const std::string texturePath) {
int width, height, channels;
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
std::cout << channels << std::endl;
if (data) {
glGenTextures(1, &Id);
glBindTexture(GL_TEXTURE_2D, Id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else {
spdlog::error("Failed to load image (%s)", texturePath );
}
stbi_image_free(data);
}
void Texture::Bind() {
glBindTexture(GL_TEXTURE_2D, Id);
}
void Texture::Unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}

View File

@ -1,18 +0,0 @@
#pragma once
#include <spdlog/spdlog.h>
#include <string>
class Texture {
public:
Texture(const std::string texturePath);
void Bind();
void Unbind();
private:
unsigned int Id;
};

View File

@ -1,46 +0,0 @@
#include "RenderSurface.h";
RenderSurface::RenderSurface(){
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");
verts = std::vector<glm::vec3>{
{-0.5f, 0.5f, 0.0f}, // 0
{-0.5f, -0.5f, 0.0f}, // 1
{0.5f, -0.5f, 0.0f}, // 2
{0.5f, 0.5f, 0.0f}, // 3
};
indices = std::vector<unsigned int>{
0,2,1,
0,3,2
};
VAO.Create();
VAO.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData(&verts[0], verts.size() * sizeof(glm::vec3), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData(&indices[0], indices.size() * sizeof(unsigned int), true);
VAO.AttachAttribute(0, 3, 0);
vertexBuffer.Unbind(false);
VAO.Unbind();
}
RenderSurface::~RenderSurface() {
delete shader;
}
void RenderSurface::Draw() {
}

View File

@ -1,32 +0,0 @@
#pragma once
#include "../BarinkEngine.h"
#include "../Graphics/Memory/Buffer.h"
#include "../Graphics/Memory/VertexArray.h"
#include <vector>
class RenderSurface
{
public:
RenderSurface();
~RenderSurface();
void Draw();
private:
// would normally be a material
// however rendersurface is special and
// thus does not contain a material
Shader* shader;
// Basically a mesh
std::vector<glm::vec3> verts;
std::vector<unsigned int > indices;
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
};

View File

@ -1,119 +0,0 @@
#include "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*>();
}

View File

@ -1,70 +0,0 @@
#include "PerfCounter.h"
#include <imgui.h>
#include <iostream>
EngineStatistics ES;
uint64_t EngineInstrumentation::GetPrecisionTime() {
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line width
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
void EngineInstrumentation::PerfomanceSamplerInit() {
ES.frames = 0;
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
}
void EngineInstrumentation::Update() {
/*
uint64_t MilliSecondsPast = GetPrecisionTime() - EngineInstrumentation::lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES.frameTime = (float)1000 / ES.frames;
ES.FPS = ES.frames;
ES.frames = 0;
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
}
*/
}
void EngineInstrumentation::ShowStats() {
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
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();
}
PerfSampler::PerfSampler(const std::string& name )
: name(name)
{
using namespace std::chrono;
startTime = high_resolution_clock::now();
}
PerfSampler::~PerfSampler()
{
Stop();
}
void PerfSampler::Stop()
{
using namespace std::chrono;
auto end = high_resolution_clock::now();
auto durationInuSeconds =
duration_cast<nanoseconds>(end.time_since_epoch()).count() -
duration_cast<nanoseconds>(startTime.time_since_epoch()).count();
auto ms = durationInuSeconds * 0.001f;
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << " us (" << ms << " ms)" << std::endl;
}

View File

@ -1,37 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include <chrono>
struct EngineStatistics {
float frameTime;
uint32_t verts;
uint32_t DC;
int64_t frames;
int64_t FPS;
};
class EngineInstrumentation {
public:
//static int64_t lastSampleTime;
static uint64_t GetPrecisionTime();
static void PerfomanceSamplerInit();
static void Update();
static void ShowStats();
};
class PerfSampler {
public:
PerfSampler(const std::string& name);
~PerfSampler();
void Stop();
private:
const std::string& name;
std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
};

View File

@ -1,86 +0,0 @@
#include "Window.h"
bool BarinkWindow::InitGLFW(){
if(!glfwInit())
{
spdlog::error("Failed to initialise GLFW!");
return false;
}
return true;
}
BarinkWindow::BarinkWindow(const int width, const int height) :
Width(width), Height(height), FullScreen(false)
{
if (InitGLFW()==false) {
exit(-1);
}
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
// No window decorations such as a border, a close widget
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
// glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
// Disable resizing the window
//glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
if( !window)
{
spdlog::error("GLFW failed to create window!");
glfwTerminate();
return;
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD!\n");
exit(-1);
}
// Set vsync off !!
glfwSwapInterval(0);
VulkanSupported = glfwVulkanSupported();
glfwGetFramebufferSize(window, &Width, &Height);
glViewport(0,0, Width, Height);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
}
BarinkWindow::~BarinkWindow(){
glfwTerminate();
}
GLFWwindow* BarinkWindow::windowptr()
{
return window;
}
bool BarinkWindow::WindowShouldClose(){
return glfwWindowShouldClose(window);
}
void BarinkWindow::Poll()
{
glfwPollEvents();
}
void BarinkWindow::SwapBuffers()
{
glfwSwapBuffers(window);
}
void BarinkWindow::ReceiveEvent(Event& incident)
{
//std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
}

View File

@ -1,7 +0,0 @@
#include "Entity.h"
Entity::Entity(entt::entity e, Scene* scene)
: m_entity(e), m_scene(scene)
{
}

View File

@ -1,40 +0,0 @@
#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);
}
template<class T>
bool HasComponent() {
return m_scene->getReg().all_of<T>(m_entity);
}
// NOTE: Not Scene context aware!!
bool operator== (Entity& other) {
return m_entity == other.m_entity;
}
private:
entt::entity m_entity;
Scene* m_scene;
};

View File

@ -1,24 +0,0 @@
#include "Scene.h"
#include "Entity.h"
#include "Components.h"
Scene::Scene()
{
//m_registry = entt::basic_registry();
}
Scene::~Scene()
{}
Entity Scene::AddEntity(std::string name)
{
Entity entity = { m_registry.create(), this };
auto& ident = entity.AddComponent<BarinkEngine::IdentifierComponent>();
ident.name = name;
entity.AddComponent<BarinkEngine::TransformComponent>();
return entity;
}

View File

@ -1,22 +0,0 @@
#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;
};

View File

@ -1,7 +0,0 @@
#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) {}

View File

@ -1,12 +0,0 @@
#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()
{}

View File

@ -1,11 +0,0 @@
#include "LuaScript.h"
/*
LuaScript::LuaScript(const std::string& path)
: filePath(path) {
}
void LuaScript::execute(lua_State& l)
{
luaL_dofile(&l, filePath.c_str());
}
*/

View File

@ -1,28 +0,0 @@
#pragma once
#include <string>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
#include "LuaScriptingManager.h"
/*
class LuaScript {
public:
LuaScript(const std::string&);
void execute(lua_State& l);
private:
std::string filePath;
};
*/

View File

@ -1,18 +0,0 @@
#include "LuaScriptingManager.h"
/*
LuaScriptingManager::LuaScriptingManager()
{
L = luaL_newstate();
luaL_openlibs(L);
}
void LuaScriptingManager::ExecuteLuaString(const std::string& code) {
luaL_dostring(L, code.c_str());
}
lua_State& LuaScriptingManager::getState()
{
return (*L);
}
*/

View File

@ -1,28 +0,0 @@
#pragma once
#include <vector>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
#include "LuaScript.h"
/*
class LuaScriptingManager
{
public:
std::vector<LuaScript*> scripts;
LuaScriptingManager();
void ExecuteLuaString(const std::string&);
private:
lua_State* L;
lua_State& getState();
};*/

View File

@ -4,7 +4,7 @@ kind "ConsoleApp"
buildmessage "Building editor ..."
links{
"BarinkEngine",
"YoggieEngine",
"ImGuizmo"
}
@ -13,32 +13,27 @@ includedirs{
-- 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",
incfolder["lua"],
incfolder["spdlog"],
incfolder["glm"],
incfolder["assimp"],
incfolder["glad"],
incfolder["glfw"],
"./../libs/assimp/include",
"./../libs/glad/include",
"./../libs/glfw/include",
"./../libs/tinygltf",
"./../libs/glew/include",
"./../libs/glm",
"./../libs/ImGui",
"./../libs/guizmo",
"./../libs/entt/src",
incfolder["imgui"],
incfolder["imguizmo"],
incfolder["entt"],
"./include"
}
libdirs {
'./../build/BarinkEngine/Debug'
staticlib["yoggie"]
}
files {
"./include/*.h",
"./src/*.h",
"./src/*.cpp"
}

View File

@ -1,25 +1,23 @@
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <imgui.h>
#include "stb_image.h"
#include "../../libs/guizmo/ImGuizmo.h"
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
#include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h"
#include "../../BarinkEngine/src/PerfCounter.cpp"
#include "../../BarinkEngine/src/Scene/Entity.h"
#include "../../YoggieEngine/src/BarinkEngine.h"
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
#include "../../YoggieEngine/src/PerfCounter.cpp"
#include "../../YoggieEngine/src/Scene/Entity.h"
#include "Widgets.h"
using namespace YoggieEngine;
/*
* Define globals
*/
Framebuffer* framebuffer;
Scene Level1;
BarinkEngine::SceneObject* Model;
SceneObject* Model;
Entity cube;
entt::entity Selected;
@ -35,25 +33,25 @@ void Start() {
// Create a level and load it as the current level
auto importer = BarinkEngine::ModelImporter();
auto importer = ModelImporter();
// Create a cube
Model = importer.Import("build/Debug/Models/Cube.obj");
cube = Level1.AddEntity("cube");
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
auto& render3DComponent = cube.AddComponent<Render3DComponent>();
render3DComponent.mesh = *(Model->renderable->mesh);
cube.GetComponent<BarinkEngine::TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
auto cube2 = Level1.AddEntity("Cube1");
auto& rendercube2 = cube2.AddComponent<BarinkEngine::Render3DComponent>();
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
rendercube2.mesh = *(Model->renderable->mesh);
// create an ambient light source
auto AmbientLight = Level1.AddEntity("AmbientLight");
auto light = AmbientLight.AddComponent<BarinkEngine::LightComponent>();
auto light = AmbientLight.AddComponent<LightComponent>();
light.Color = glm::vec3(1.0f);
light.Strength = 1.0f;

View File

@ -1,7 +1,8 @@
#include "widgets.h"
//#include "EditorConsole.h"
#include <iostream>
#include "../../BarinkEngine/src/Scene/Components.h"
#include "../../BarinkEngine/src/Scene/Entity.h"
#include "../../YoggieEngine/src/Scene/Components.h"
#include "../../YoggieEngine/src/Scene/Entity.h"
class Editor;
void ComponentView(const std::string& componentName, voidFunction func)
@ -18,6 +19,8 @@ void ComponentView(const std::string& componentName, voidFunction func)
void Inspector(entt::entity ent , Scene& scene) {
ImGui::Begin("Inspector");
static char* names[] = { "Script Component", "Camera Component" };
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);
@ -25,26 +28,52 @@ void Inspector(entt::entity ent , Scene& scene) {
Entity entity = Entity(ent, &scene);
auto component = entity.GetComponent<BarinkEngine::IdentifierComponent>();
ImGui::LabelText("## Name:", component.name.c_str() );
auto component = entity.GetComponent<IdentifierComponent>();
ImGui::LabelText("## Name:", component.name.c_str());
if (entity.HasComponent<BarinkEngine::TransformComponent>()) {
auto& transform = entity.GetComponent<BarinkEngine::TransformComponent>();
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position) , 0.01);
if (ImGui::Button("Add Component"))
ImGui::OpenPopup("Component picker");
ImGui::SameLine();
if (ImGui::BeginPopup("Component picker")) {
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
if (ImGui::MenuItem(names[i])) {
std::cout << "Add a " << names[i] << " to "
<< entity.GetComponent<IdentifierComponent>().name << std::endl;
}
ImGui::EndPopup();
}
ImGui::NewLine();
if (entity.HasComponent<TransformComponent>()) {
auto& transform = entity.GetComponent<TransformComponent>();
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_None )) {
ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.01);
ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.01);
ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.01, 0);
}
}
if (entity.HasComponent<BarinkEngine::LightComponent>()) {
auto& light = entity.GetComponent<BarinkEngine::LightComponent>();
if (entity.HasComponent<LightComponent>()) {
auto& light = entity.GetComponent<LightComponent>();
ImGui::DragFloat("Strength", &light.Strength, 0.001f);
ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color));
}
if (entity.HasComponent <BarinkEngine::CameraComponent>()) {
auto& camera = entity.GetComponent<BarinkEngine::CameraComponent>();
if (entity.HasComponent <CameraComponent>()) {
auto& camera = entity.GetComponent<CameraComponent>();
ComponentView("Camera", [] {
ImGui::SliderFloat("Zoom", &Zoom, 10, 190);
ImGui::InputFloat3("Position:", &Position[0]);
@ -52,7 +81,7 @@ void Inspector(entt::entity ent , Scene& scene) {
});
}
if (entity.HasComponent<BarinkEngine::ScriptComponent>()) {
if (entity.HasComponent<ScriptComponent>()) {
ComponentView("Scripting", [] {
ImGui::LabelText("##--", "Hello scripting");
});
@ -71,7 +100,7 @@ void SceneExplorer(entt::entity& selected, Scene& scene )
scene.getReg().each([&](entt::entity enttNumber) {
Entity entity = Entity(enttNumber, &scene);
auto id = entity.GetComponent<BarinkEngine::IdentifierComponent>();
auto id = entity.GetComponent<IdentifierComponent>();
if (ImGui::Selectable(id.name.c_str(), enttNumber == selected )) {
selected = enttNumber;
@ -122,9 +151,11 @@ void Settings() {
ImGui::End();
}
//auto console = EditorConsole();
void Console() {
ImGui::Begin("Console", false);
ImGui::Dummy(ImVec2{ 128, 128 });
// console.Draw();
ImGui::End();
}

View File

@ -2,11 +2,14 @@
#include <glm/glm.hpp>
#include <imgui.h>
#include <string>
#include "../../libs/guizmo/ImGuizmo.h"
#include "../../BarinkEngine/src/BarinkEngine.h"
#include <entt/entt.hpp>
#include <entt/entity/fwd.hpp>
#include "../../libs/guizmo/ImGuizmo.h"
#include "../../YoggieEngine/src/BarinkEngine.h"
typedef void ( *voidFunction ) (void);
using namespace YoggieEngine;
void ComponentView(const std::string& componentName, voidFunction func);

View File

@ -4,11 +4,11 @@ kind "ConsoleApp"
buildmessage "Building the runtime ..."
links{
"BarinkEngine"
"YoggieEngine"
}
includedirs{
"./../BarinkEngine/src",
"./../YoggieEngine/src",
-- I'd prefer if didn't need these..
-- We'll figure that out some time later
"./../libs/lua/include",
@ -30,7 +30,7 @@ includedirs{
}
libdirs {
'./../build/BarinkEngine/Debug'
'./../YoggieEngine/build/Debug'
}
files {

View File

@ -4,11 +4,11 @@ kind "ConsoleApp"
buildmessage "Building SandboxApp ..."
links{
"BarinkEngine"
"YoggieEngine"
}
includedirs{
"./../BarinkEngine/Include",
"./../YoggieEngine/Include",
-- I'd prefer if didn't need these..
-- We'll figure that out some time later
@ -31,7 +31,7 @@ includedirs{
}
libdirs {
'./../build/BarinkEngine/Debug'
'./../YoggieEngine/build/Debug'
}
files {

View File

@ -1,7 +1,7 @@
#pragma once
#include "imgui.h"
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../BarinkEngine/src/Graphics/Memory/Framebuffer.h"
#include "../../YoggieEngine/src/BarinkEngine.h"
#include "../../YoggieEngine/src/Graphics/Memory/Framebuffer.h"
void CameraTool();
void ScriptingTool(char* code);

View File

@ -1,13 +1,15 @@
#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>
#include "../../BarinkEngine/src/PerfCounter.h"
#include "../../YoggieEngine/src/BarinkEngine.h"
#include "../../YoggieEngine/src/Scene/Components.h"
#include "../../YoggieEngine/src/Scene/Scene.h"
#include "../../YoggieEngine/src/Scene/Entity.h"
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
#include "../../YoggieEngine/src/PerfCounter.h"
/*
* Define globals

View File

@ -1,5 +1,5 @@
#pragma once
#include "../../BarinkEngine/src/BarinkEngine.h"
#include "../../YoggieEngine/src/BarinkEngine.h"
//void PrintSceneTree(Node& node, int depth);

View File

@ -1,7 +1,7 @@
project "BarinkEngine"
project "YoggieEngine"
kind "StaticLib"
buildmessage "Building BarinkEngine"
buildmessage "Building Yoggie Engine"
includedirs {
"../libs/spdlog/include",
@ -59,5 +59,4 @@ project "BarinkEngine"
ok,err = os.copyfile("BarinkEngine/src/Graphics/shaders/*" ,"SandboxApp/build/Debug/")
}
include('../ImGui')
include("../ImGuizmo")

View File

@ -0,0 +1,101 @@
#include "ModelImporter.h"
#include "spdlog/spdlog.h"
namespace YoggieEngine {
SceneObject* 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<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<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene)
{
std::vector<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;
}
Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
std::vector<unsigned int> indices;
std::vector<Vertex> vertices;
ProcessVertices(mesh, vertices);
ProcessIndices(mesh, indices);
Mesh result;
result.vertices = vertices;
result.elements = indices;
return result;
}
void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices) {
// Process vertices
for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
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]);
}
}
}
}

View File

@ -0,0 +1,31 @@
#pragma once
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "../Graphics/Primitives/Mesh.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include "../Scene/TransformTree/SceneNodeTypes.h"
namespace YoggieEngine {
void ProcessVertices(aiMesh* mesh, std::vector<Vertex>& out_vertices);
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
class ModelImporter {
public:
SceneObject* Import(const std::string path);
private:
static Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
};
}

View File

@ -1,19 +1,20 @@
#include "BarinkEngine.h"
using namespace YoggieEngine;
Renderer renderer;
extern EngineStatistics ES;
BarinkEngine::Renderer renderer;
const unsigned int MS_PER_UPDATE = 2;
int main(int argc, char* argv[]) {
// Setup performance sampler
EngineInstrumentation::PerfomanceSamplerInit();
// Startup services
BarinkWindow MainWindow = BarinkWindow(1200, 700);
BarinkWindow MainWindow = BarinkWindow(1200, 700);
renderer = BarinkEngine::Renderer();
InputSystem = BarinkEngine::InputManager();
renderer = Renderer();
InputSystem = InputManager();
ES = EngineStatistics{};
InputSystem.attach(&MainWindow);
GUIManager GUISystem = GUIManager(&MainWindow);
@ -22,7 +23,6 @@ int main(int argc, char* argv[]) {
// First call to setup game
{
PerfSampler("Start");
Start();
}
@ -43,13 +43,11 @@ int main(int argc, char* argv[]) {
// Execute main logic
{
PerfSampler("PollEvents");
InputSystem.PollEvents();
}
{
PerfSampler("Update");
while (lag >= MS_PER_UPDATE) {
Update();
lag -= MS_PER_UPDATE;
@ -57,18 +55,15 @@ int main(int argc, char* argv[]) {
}
{
PerfSampler("Render");
Render();
}
{
PerfSampler("GUI-Render");
GUISystem.Render();
}
{
PerfSampler("BufferSwap");
MainWindow.SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
@ -77,7 +72,6 @@ int main(int argc, char* argv[]) {
// Shutdown game
{
PerfSampler("Stop");
Stop();
}
@ -86,3 +80,5 @@ int main(int argc, char* argv[]) {
return 0;
}

View File

@ -14,10 +14,9 @@
#include "Graphics/Renderer.h"
#include "GUI/GUIManager.h"
#include "Scene/Scene.h"
#include "PerfCounter.h"
using namespace YoggieEngine;
extern Renderer renderer;
extern BarinkEngine::Renderer renderer;
extern void Start();
extern void Update();
extern void Render();

View File

@ -0,0 +1,14 @@
#pragma once
#include <string>
namespace YoggieEngine {
struct Event
{
public:
std::string name;
int argc;
void** argv;
};
}

View File

@ -0,0 +1,27 @@
#include "EventEmitter.h"
namespace YoggieEngine {
void EventEmitter::Subscribe(EventListener& subscriber)
{
subscribers.push_back(&subscriber);
}
void EventEmitter::Unsubscribe(EventListener& subscriber)
{
subscribers.remove(&subscriber);
}
void EventEmitter::EmitEvent(Event& incident)
{
// Notify all subscribers an event has taken place
for (auto it = subscribers.begin(); it != subscribers.end(); ++it)
{
(*it)->ReceiveEvent(incident);
}
}
EventEmitter::EventEmitter() {
subscribers = std::list<EventListener*>{};
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include "Event.h"
#include "EventListener.h"
namespace YoggieEngine{
class EventEmitter {
public:
void Subscribe(EventListener& subscriber);
void Unsubscribe(EventListener& subscriber);
protected:
std::list<EventListener*> subscribers;
void EmitEvent(Event& incident);
EventEmitter();
};
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <list>
#include <iostream>
#include "spdlog/spdlog.h"
#include "Event.h"
namespace YoggieEngine {
class EventListener {
public:
virtual void ReceiveEvent(Event& incident) = 0;
};
}

View File

@ -0,0 +1,65 @@
#include "GUIManager.h"
#include "imgui.h"
#include "backends/imgui_impl_opengl3.h"
#include <backends/imgui_impl_glfw.h>
#include "../../libs/guizmo/ImGuizmo.h"
#include "../BarinkEngine.h"
namespace YoggieEngine {
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();
ImGuizmo::SetOrthographic(true);
ImGuizmo::BeginFrame();
ImmediateGraphicsDraw();
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* last_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(last_context);
}
}
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "../Platform/Window.h"
namespace YoggieEngine {
class GUIManager {
public:
GUIManager(BarinkWindow* window);
~GUIManager();
void Render();
private:
BarinkWindow* currentwindow;
};
}

View File

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

View File

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

View File

@ -0,0 +1,72 @@
#include "Framebuffer.h"
#include <iostream>
namespace YoggieEngine {
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, 0, 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);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0);
// Create a depth buffer
glGenTextures(1, &DepthAttachment);
glBindTexture(GL_TEXTURE_2D, DepthAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 800, 600, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DepthAttachment, 0);
/*
* // Render buffer
glGenRenderbuffers(1, &DepthAttachment);
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
*/
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);
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <glad/glad.h>
#include <glm/glm.hpp>
namespace YoggieEngine {
class Framebuffer {
public:
Framebuffer();
~Framebuffer();
GLuint GetId() { return Id; }
GLuint GetColourAttachment() { return ColourAttachment; }
GLuint GetDepthAttachment() { return DepthAttachment; }
private:
GLuint Id = 0;
GLuint ColourAttachment = 0;
GLuint DepthAttachment = 0;
};
}

View File

@ -0,0 +1,33 @@
#include "UniformBuffer.h"
#include <glad/glad.h>
namespace YoggieEngine {
UniformBuffer::UniformBuffer(unsigned int size)
{
glGenBuffers(1, &Id);
glBindBuffer(GL_ARRAY_BUFFER, Id);
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
UniformBuffer::~UniformBuffer()
{
glDeleteBuffers(1, &Id);
}
void UniformBuffer::setData(unsigned int offset, unsigned int size, void* data)
{
glBindBuffer(GL_ARRAY_BUFFER, Id);
glBufferSubData(GL_ARRAY_BUFFER, offset, size, data);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void UniformBuffer::setDescriptor(unsigned int index, unsigned int size, unsigned int stride, void* pointer)
{
glBindBuffer(GL_ARRAY_BUFFER, Id);
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, stride, pointer);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}

View File

@ -0,0 +1,17 @@
#pragma once
namespace YoggieEngine {
class UniformBuffer {
public:
UniformBuffer(unsigned int size);
~UniformBuffer();
void setData(unsigned int offset, unsigned int size, void* data);
void setDescriptor(unsigned int index, unsigned int size, unsigned int stride, void* pointer);
private:
unsigned int Id;
};
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,24 @@
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
namespace YoggieEngine {
class Camera {
public:
glm::vec3 Position;
glm::vec3 Rotation;
float Zoom;
Camera(glm::vec3 position, glm::vec3 rotation, float zoom);
~Camera();
glm::mat4 GetViewMatrix();
private:
glm::vec3 Front;
glm::vec3 Right;
glm::vec3 Up;
};
}

View File

@ -0,0 +1,14 @@
#include "Material.h"
namespace YoggieEngine {
Material::Material(const Shader& shader) :
shader(shader) {
}
void Material::Apply() const {
shader.Use();
shader.setUniformVec3("Color", Color);
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <glm/glm.hpp>
#include <string>
#include "Shader.h"
namespace YoggieEngine {
class Material {
public:
Material(const Shader& shader);
void Apply()const;
glm::vec3 Color;
const Shader& shader;
};
}

View File

@ -3,7 +3,7 @@
#include <glm/glm.hpp>
#include "Vertex.h"
namespace BarinkEngine {
namespace YoggieEngine {
struct Mesh {
std::vector<Vertex> vertices;
std::vector<unsigned int> elements;

View File

@ -0,0 +1,130 @@
#include "Shader.h"
#include "spdlog/spdlog.h"
namespace YoggieEngine {
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
{
char infoLog[512];
int succes;
char* vertexCode = readFile(vertexShaderPath.c_str());
//spdlog::info(vertexCode);
unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertId, 1, &vertexCode, NULL);
glCompileShader(vertId);
glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
if (!succes) {
glGetShaderInfoLog(vertId, 512, NULL, infoLog);
spdlog::error("Vertex shader has compile error {}", infoLog);
return;
}
char* fragmentCode = readFile(fragmentShaderPath.c_str());
//spdlog::info(fragmentCode);
unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragId, 1, &fragmentCode, NULL);
glCompileShader(fragId);
glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
if (!succes) {
glGetShaderInfoLog(fragId, 512, NULL, infoLog);
spdlog::error("Fragment shader has compile error {}", infoLog);
return;
}
id = glCreateProgram();
glAttachShader(id, vertId);
glAttachShader(id, fragId);
glLinkProgram(id);
int success;
glGetProgramiv(id, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(id, 512, NULL, infoLog);
printf("ERROR::SHADER_PROGRAM::LINKING_FAILED\n %s", infoLog);
}
delete vertexCode;
delete fragmentCode;
}
char* Shader::readFile(const char* filePath) {
spdlog::info("Opening {} ", filePath);
std::ifstream file;
file.open(filePath);
if (file.is_open() == false) {
spdlog::info("File not found.");
return nullptr;
}
// Determine the file size!
file.seekg(0, std::ios::end);
size_t filesize = file.tellg();
// Undo previous seek.
file.seekg(0, std::ios::beg);
//spdlog::info("filesize: {}", filesize);
// Create a big enough buffer for the file
size_t bufferSize = filesize + 3;
char* FileBuffer = new char[bufferSize];
memset(FileBuffer, '\0', bufferSize);
// read the whole file
file.read(FileBuffer, filesize);
return FileBuffer;
}
void Shader::Use() const
{
glUseProgram(id);
}
void Shader::setUniformMat4(std::string uniformName, glm::mat4 matrix4) const
{
glUniformMatrix4fv(glGetUniformLocation(id, uniformName.c_str()), 1, GL_FALSE, glm::value_ptr(matrix4));
}
void Shader::setUniformVec4(std::string uniformName, glm::vec4 vector4) const
{
glUniform4fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector4));
}
void Shader::setUniformVec3(std::string uniformName, glm::vec3 vector3) const
{
glUniform3fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector3));
}
void Shader::setUniformVec2(std::string uniformName, glm::vec2 vector2) const
{
glUniform2fv(glGetUniformLocation(id, uniformName.c_str()), 1, glm::value_ptr(vector2));
}
void Shader::setUniformFloat(std::string uniformName, float value) const
{
glUniform1f(glGetUniformLocation(id, uniformName.c_str()), value);
}
void Shader::setUniformInt(std::string uniformName, int value) const
{
glUniform1i(glGetUniformLocation(id, uniformName.c_str()), value);
}
}

View File

@ -7,11 +7,11 @@
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
class Shader {
namespace YoggieEngine {
class Shader {
private:
char* readFile (const char* filePath);
char* readFile(const char* filePath);
public:
Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath);
void Use() const;
@ -20,8 +20,9 @@ class Shader {
void setUniformVec3(std::string uniformName, glm::vec3 vector3)const;
void setUniformVec2(std::string uniformName, glm::vec2 vector2)const;
void setUniformFloat(std::string uniformName, float value)const;
void setUniformInt(std::string uniformName, int value) const ;
void setUniformInt(std::string uniformName, int value) const;
int id;
};
};
}

View File

@ -0,0 +1,42 @@
#include "Texture.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define STB_IMAGE_IMPLEMENTATION
#include "../stb_image.h"
#include <iostream>
namespace YoggieEngine {
Texture::Texture(const std::string texturePath) {
int width, height, channels;
unsigned char* data = stbi_load(texturePath.c_str(), &width, &height, &channels, 0);
std::cout << channels << std::endl;
if (data) {
glGenTextures(1, &Id);
glBindTexture(GL_TEXTURE_2D, Id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else {
spdlog::error("Failed to load image (%s)", texturePath);
}
stbi_image_free(data);
}
void Texture::Bind() {
glBindTexture(GL_TEXTURE_2D, Id);
}
void Texture::Unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <spdlog/spdlog.h>
#include <string>
namespace YoggieEngine {
class Texture {
public:
Texture(const std::string texturePath);
void Bind();
void Unbind();
private:
unsigned int Id;
};
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <glm/glm.hpp>
namespace BarinkEngine {
namespace YoggieEngine {
struct Vertex {
glm::vec3 vertices;
glm::vec2 uv;

View File

@ -0,0 +1,47 @@
#include "RenderSurface.h";
namespace YoggieEngine {
RenderSurface::RenderSurface() {
shader = new Shader("build/SandboxAppliction/Debug/renderSuface.vs", "build/SandboxApplication/Debug/renderSurface.fs");
verts = std::vector<glm::vec3>{
{-0.5f, 0.5f, 0.0f}, // 0
{-0.5f, -0.5f, 0.0f}, // 1
{0.5f, -0.5f, 0.0f}, // 2
{0.5f, 0.5f, 0.0f}, // 3
};
indices = std::vector<unsigned int>{
0,2,1,
0,3,2
};
VAO.Create();
VAO.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData(&verts[0], verts.size() * sizeof(glm::vec3), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData(&indices[0], indices.size() * sizeof(unsigned int), true);
VAO.AttachAttribute(0, 3, 0);
vertexBuffer.Unbind(false);
VAO.Unbind();
}
RenderSurface::~RenderSurface() {
delete shader;
}
void RenderSurface::Draw() {
}
}

View File

@ -0,0 +1,33 @@
#pragma once
#include "../BarinkEngine.h"
#include "../Graphics/Memory/Buffer.h"
#include "../Graphics/Memory/VertexArray.h"
#include <vector>
namespace YoggieEngine {
class RenderSurface
{
public:
RenderSurface();
~RenderSurface();
void Draw();
private:
// would normally be a material
// however rendersurface is special and
// thus does not contain a material
Shader* shader;
// Basically a mesh
std::vector<glm::vec3> verts;
std::vector<unsigned int > indices;
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
};
}

View File

@ -4,10 +4,10 @@
#include "Primitives/Texture.h"
#include "../Scene/Scene.h"
namespace BarinkEngine {
namespace YoggieEngine {
struct Renderable {
BarinkEngine::Mesh* mesh;
Mesh* mesh;
Material* material;
Texture* texture;
};

View File

@ -4,17 +4,19 @@
#include "../Graphics/Memory/Buffer.h"
#include <glad/glad.h>
#include <glm/gtc/type_precision.hpp>
namespace YoggieEngine {
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(){}
Renderer::Renderer(){}
BarinkEngine::Renderer::~Renderer(){}
Renderer::~Renderer(){}
void BarinkEngine::Renderer::Prepare(Scene& scene ) {
auto group = scene.getReg().view<BarinkEngine::Render3DComponent>();
group.each([](auto enity, BarinkEngine::Render3DComponent& renderComponent) {
void Renderer::Prepare(Scene& scene ) {
auto group = scene.getReg().view<Render3DComponent>();
group.each([](auto enity, Render3DComponent& renderComponent) {
VertexArray va = VertexArray();
Buffer vertexBuffer = Buffer();
Buffer elementBuffer = Buffer();
@ -24,15 +26,15 @@ void BarinkEngine::Renderer::Prepare(Scene& scene ) {
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(BarinkEngine::Vertex), false);
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(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));
va.AttachAttribute(0, 3, sizeof(Vertex));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
@ -47,7 +49,7 @@ void BarinkEngine::Renderer::Prepare(Scene& scene ) {
void BarinkEngine::Renderer::Render(Scene& scene)
void Renderer::Render(Scene& scene)
{
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
group.each([&](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
@ -86,7 +88,7 @@ void BarinkEngine::Renderer::Render(Scene& scene)
}
void BarinkEngine::Renderer::Render(Framebuffer& framebuffer, Scene& scene)
void Renderer::Render(Framebuffer& framebuffer, Scene& scene)
{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.GetId());
@ -100,3 +102,4 @@ void BarinkEngine::Renderer::Render(Framebuffer& framebuffer, Scene& scene)
}

View File

@ -12,7 +12,7 @@
#include "Memory/Framebuffer.h"
#include "../Scene/Components.h"
namespace BarinkEngine {
namespace YoggieEngine {
class Renderer {
public:

View File

@ -0,0 +1,119 @@
#include "InputManager.h"
namespace YoggieEngine {
InputManager InputSystem;
void InputManager::PollEvents()
{
for (auto it = windows.begin(); it != windows.end(); ++it) {
auto window = *it;
window->Poll();
}
}
void 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 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 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 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 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 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));
}
InputManager::InputManager() : EventEmitter ()
{
windows = std::vector<BarinkWindow*>();
}
}

View File

@ -7,7 +7,7 @@
#include "../EventSystem/EventListener.h"
#include "../Platform/Window.h"
namespace BarinkEngine {
namespace YoggieEngine {
class InputManager : EventEmitter {
public:
@ -26,6 +26,5 @@ namespace BarinkEngine {
std::vector<BarinkWindow*> windows;
};
extern InputManager InputSystem;
}
extern BarinkEngine::InputManager InputSystem;

View File

@ -0,0 +1,70 @@
#include "PerfCounter.h"
#include <imgui.h>
#include <iostream>
namespace YoggieEngine {
uint64_t EngineInstrumentation::GetPrecisionTime() {
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line width
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
void EngineInstrumentation::PerfomanceSamplerInit() {
//ES.frames = 0;
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
}
void EngineInstrumentation::Update() {
/*
uint64_t MilliSecondsPast = GetPrecisionTime() - EngineInstrumentation::lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES.frameTime = (float)1000 / ES.frames;
ES.FPS = ES.frames;
ES.frames = 0;
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
}
*/
}
void EngineInstrumentation::ShowStats() {
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
ImGui::Text("Currently not available");
/* 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();
}
PerfSampler::PerfSampler(const std::string& name)
: name(name)
{
using namespace std::chrono;
startTime = high_resolution_clock::now();
}
PerfSampler::~PerfSampler()
{
Stop();
}
void PerfSampler::Stop()
{
using namespace std::chrono;
auto end = high_resolution_clock::now();
auto durationInuSeconds =
duration_cast<nanoseconds>(end.time_since_epoch()).count() -
duration_cast<nanoseconds>(startTime.time_since_epoch()).count();
auto ms = durationInuSeconds * 0.001f;
// std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << " us (" << ms << " ms)" << std::endl;
}
}

View File

@ -0,0 +1,41 @@
#pragma once
#include <string>
#include <vector>
#include <chrono>
namespace YoggieEngine {
struct EngineStatistics {
float frameTime;
uint32_t verts;
uint32_t DC;
int64_t frames;
int64_t FPS;
};
class EngineInstrumentation {
public:
//static int64_t lastSampleTime;
static uint64_t GetPrecisionTime();
static void PerfomanceSamplerInit();
static void Update();
static void ShowStats();
};
class PerfSampler {
public:
PerfSampler(const std::string& name);
~PerfSampler();
void Stop();
private:
const std::string& name;
std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
};
}

View File

@ -0,0 +1,88 @@
#include "Window.h"
namespace YoggieEngine {
bool BarinkWindow::InitGLFW() {
if (!glfwInit())
{
spdlog::error("Failed to initialise GLFW!");
return false;
}
return true;
}
BarinkWindow::BarinkWindow(const int width, const int height) :
Width(width), Height(height), FullScreen(false)
{
if (InitGLFW() == false) {
exit(-1);
}
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
// No window decorations such as a border, a close widget
// glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
// glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
// Disable resizing the window
//glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
if (!window)
{
spdlog::error("GLFW failed to create window!");
glfwTerminate();
return;
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD!\n");
exit(-1);
}
// Set vsync off !!
glfwSwapInterval(0);
VulkanSupported = glfwVulkanSupported();
glfwGetFramebufferSize(window, &Width, &Height);
glViewport(0, 0, Width, Height);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
}
BarinkWindow::~BarinkWindow() {
glfwTerminate();
}
GLFWwindow* BarinkWindow::windowptr()
{
return window;
}
bool BarinkWindow::WindowShouldClose() {
return glfwWindowShouldClose(window);
}
void BarinkWindow::Poll()
{
glfwPollEvents();
}
void BarinkWindow::SwapBuffers()
{
glfwSwapBuffers(window);
}
void BarinkWindow::ReceiveEvent(Event& incident)
{
//std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
}
}

View File

@ -11,8 +11,8 @@
#include "../EventSystem/Event.h"
#include "../EventSystem/EventListener.h"
class BarinkWindow : EventListener {
namespace YoggieEngine {
class BarinkWindow : EventListener {
private:
GLFWwindow* window;
bool FullScreen;
@ -27,11 +27,12 @@ class BarinkWindow : EventListener {
GLFWwindow* windowptr();
void ReceiveEvent(Event& incident) override ;
void ReceiveEvent(Event& incident) override;
bool WindowShouldClose();
void Poll();
void SwapBuffers();
};
};
}

View File

@ -2,7 +2,7 @@
#include <glm/glm.hpp>
#include "../Graphics/Primitives/Shader.h"
#include "../Graphics/Primitives/Mesh.h"
namespace BarinkEngine {
namespace YoggieEngine {
struct IdentifierComponent {
std::string name;
};

View File

@ -0,0 +1,10 @@
#include "Entity.h"
namespace YoggieEngine {
Entity::Entity(entt::entity e, Scene* scene)
: m_entity(e), m_scene(scene)
{
}
}

View File

@ -0,0 +1,40 @@
#pragma once
#include <entt/entt.hpp>
namespace YoggieEngine {
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);
}
template<class T>
bool HasComponent() {
return m_scene->getReg().all_of<T>(m_entity);
}
// NOTE: Not Scene context aware!!
bool operator== (Entity& other) {
return m_entity == other.m_entity;
}
private:
entt::entity m_entity;
Scene* m_scene;
};
}

View File

@ -0,0 +1,25 @@
#include "Scene.h"
#include "Entity.h"
#include "Components.h"
namespace YoggieEngine{
Scene::Scene()
{
}
Scene::~Scene()
{}
Entity Scene::AddEntity(std::string name)
{
Entity entity = { m_registry.create(), this };
auto& ident = entity.AddComponent<IdentifierComponent>();
ident.name = name;
entity.AddComponent<TransformComponent>();
return entity;
}
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <string>
#include <entt/entt.hpp>
namespace YoggieEngine {
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;
};
}

View File

@ -0,0 +1,9 @@
#include "Node.h"
namespace YoggieEngine {
Node::Node(const std::string& name)
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
Group::Group(const std::string& name)
: Node(name) {}
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <string>
#include <vector>
class Node {
namespace YoggieEngine {
class Node {
public:
Node(const std::string& name);
std::string name;
@ -11,12 +11,14 @@ class Node {
void addChild(Node& node);
};
};
class Group : public Node {
public:
Group(const std::string& name);
class Group : public Node {
public:
Group(const std::string& name);
};
};
}

View File

@ -0,0 +1,13 @@
#include "SceneNodeTypes.h"
namespace YoggieEngine {
SceneCamera::SceneCamera()
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))
{}
SceneObject::SceneObject(std::string name, Renderable* visual)
: Group(name), renderable(visual)
{}
SceneObject::~SceneObject()
{}
}

View File

@ -3,7 +3,7 @@
#include "../../Graphics/Renderable.h"
#include "Node.h"
namespace BarinkEngine {
namespace YoggieEngine {
class SceneCamera : public Group
{
public:

View File

@ -0,0 +1,13 @@
#include "LuaScript.h"
/*
namespace YoggieEngine {
LuaScript::LuaScript(const std::string& path)
: filePath(path) {
}
void LuaScript::execute(lua_State& l)
{
luaL_dofile(&l, filePath.c_str());
}
}
*/

Some files were not shown because too many files have changed in this diff Show More