4 Commits

38 changed files with 486 additions and 482 deletions

View File

@ -1,6 +0,0 @@
{
"cmake.configureOnOpen": true,
"files.associations": {
"iosfwd": "cpp"
}
}

View File

@ -1,4 +1,5 @@
#include "BarinkEngine.h"
#include <phonon.h>
EngineStatistics* ES;
BarinkEngine::InputManager InputSystem;
@ -8,33 +9,17 @@ int main(int argc, char* argv[]) {
PerfomanceSamplerInit();
// Create the window
BarinkWindow MainWindow = BarinkWindow(800, 600);
// =================================================
// Startup services
// =================================================
BarinkWindow MainWindow = BarinkWindow(800, 600);
// Startup Renderer
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
// Startup InputManager
InputSystem = BarinkEngine::InputManager();
InputSystem.attach(&MainWindow);
InputSystem.setupGLFWInput(MainWindow.windowptr());
// Startup GUI System
GUIManager GUISystem = GUIManager(&MainWindow);
// Enable depth testing
// NOTE: TODO Move this into the renderer
glEnable(GL_DEPTH_TEST);
@ -73,9 +58,6 @@ int main(int argc, char* argv[]) {
// Shutdown Services
delete ES;
InputSystem.detach(&MainWindow);
return 0;
}

View File

@ -1,7 +1,8 @@
#pragma once
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define TINYGLTF_IMPLEMENTATION
#define TINYGLTF_NO_EXTERNAL_IMAGE
#include "Graphics/Mesh.h"
@ -9,15 +10,25 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include "Scene/SceneNodeTypes.h"
class ModelImporter {
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
public:
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:
};
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

@ -13,8 +13,6 @@
#include "Graphics/Renderer.h"
#include "Graphics/GUI/GUIManager.h"
#include "Scene.h"
#include "PerfCounter.h"

View File

@ -5,5 +5,7 @@ struct Event
{
public:
std::string name;
int argc;
void** argv;
};

View File

@ -6,12 +6,10 @@ class EventEmitter {
public:
void Subscribe (EventListener& subscriber);
void Unsubscribe(EventListener& subscriber);
void EmitEvent(Event& incident);
protected:
std::list<EventListener*> subscribers;
void EmitEvent(Event& incident);
EventEmitter();

View File

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

View File

@ -1,6 +1,6 @@
#pragma once
#include <glad/glad.h>
class Buffer {
class GpuBuffer {
private:
unsigned int id;
public:

View File

@ -1,10 +1,11 @@
#pragma once
#include <vector>
#include <glm/glm.hpp>
#include "VertexArray.h"
#include "Buffer.h"
namespace BarinkEngine{
struct Vertex {
glm::vec3 vertices;
glm::vec2 uv;
@ -13,8 +14,13 @@ namespace BarinkEngine{
class Mesh {
public:
std::vector<Vertex> vertices;
std::vector<unsigned int > elements;
std::vector<unsigned int> elements;
private:
GpuBuffer vertexBuffer;
GpuBuffer elementBuffer;
VertexArray VAO;
unsigned int UV_id;
};
}

View File

@ -20,8 +20,8 @@ private:
std::vector<unsigned int > indices;
Buffer vertexBuffer;
Buffer elementBuffer;
GpuBuffer vertexBuffer;
GpuBuffer elementBuffer;
VertexArray VAO;

View File

@ -1,37 +1,23 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "Buffer.h"
#include "Material.h"
#include "Texture.h"
#include "VertexArray.h"
#include "Scene.h"
namespace BarinkEngine {
class Renderable : public SceneNode {
public:
/*
* NOTE: Should combine into a Mesh!!
*/
Buffer vertexBuffer;
Buffer elementBuffer;
//Buffer uv;
VertexArray VAO;
class Renderable {
public:
Mesh mesh;
Material* material;
Texture* texture;
Shader* shader;
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);
};
Renderable();
~Renderable();
};
}

View File

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

View File

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

View File

@ -1,29 +1,27 @@
#pragma once
#include <list>
#include <vector>
#include "Graphics/Window.h"
#include "EventSystem/EventEmitter.h"
#include "../Include/Input/GLFWInput.h"
#include "BarinkEngine.h"
namespace BarinkEngine {
class InputManager : public EventEmitter {
class InputManager : EventEmitter {
public:
InputManager();
void PollEvents();
void attach(BarinkWindow* window);
void detach(BarinkWindow* window);
void setupGLFWInput(GLFWwindow* window);
// GLFW Handlers
static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
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:
std::list<BarinkWindow*> windows;
std::vector<BarinkWindow*> windows;
};
}

View File

@ -3,13 +3,13 @@
#include <imgui.h>
struct EngineStatistics {
uint32_t lastSampleTime;
long long lastSampleTime;
float frameTime;
uint32_t verts;
uint32_t DC;
uint64_t frames;
uint64_t FPS;
long long frames;
long long FPS;
};
extern EngineStatistics* ES;
@ -18,15 +18,15 @@ inline void PerfomanceSamplerInit(){
ES->frames = 0;
ES->lastSampleTime = 0;
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
inline void SamplePerformance(void) {
ES->frames++;
ES->DC = 0;
ES->verts = 0;
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES->frameTime = (float)1000 / ES->frames;

View File

@ -2,46 +2,22 @@
#include <string>
#include <vector>
#include "glm/glm.hpp"
#include "Graphics/Transform.h"
#include "Scene/Node.h"
/*
* Scene should be a description of a game world
*/
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
glm::mat4 ModelMatrix;
};
class SceneNode {
public:
std::string name;
Transform transform;
SceneNode* parent;
std::vector<SceneNode*> children;
void addChild(SceneNode& node);
};
class Scene {
public:
SceneNode& GetSceneNode(std::string);
SceneNode& GetRoot();
Node& GetSceneNode(std::string);
Node& GetRoot();
Scene(std::string SceneName = "Default Scene");
Scene(const std::string& sceneName = "Default Scene");
~Scene();
private:
SceneNode* root;
Node* root;
};

View File

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

View File

@ -0,0 +1,14 @@
#pragma once
#include "Graphics/Renderable.h"
#include "Scene/SceneNodeTypes.h"
#include <glm/glm.hpp>
/*
* Define a helper class to more easily build a proper scene
*/
static class SceneBuilder {
static Group* AddGroup(std::string name);
static SceneObject* AddVisual(std::string name, Renderable& object, glm::vec3 position );
};

View File

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

View File

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

View File

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

View File

@ -1,44 +1,118 @@
#include "BarinkEngine.h"
#include "Input/InputManager.h"
#include "GLFW/glfw3.h"
#include "spdlog/spdlog.h"
#include <iostream>
void BarinkEngine::InputManager::PollEvents()
{
for (auto it = windows.begin(); it != windows.end(); ++it) {
(*it)->Poll();
}
}
namespace BarinkEngine {
void BarinkEngine::InputManager::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
void InputManager::PollEvents()
Event KeyEvent{};
KeyEvent.name = "KEY";
InputSystem.EmitEvent(KeyEvent);
if (key == GLFW_KEY_A && action == GLFW_PRESS)
{
for (auto it = windows.begin(); it != windows.end(); ++it) {
(*it)->Poll();
}
std::cout << "'a' key was pressed" << std::endl;
}
}
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 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 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*>();
}
}
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,12 +1,28 @@
#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);
}
SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
Node* SearchInChildren(Node* root, const std::string name ) {
if (root->name == name)
return root;
SceneNode* found = nullptr;
Node* found = nullptr;
for (auto child : root->children) {
found = SearchInChildren(child, name);
}
@ -14,39 +30,37 @@ SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
}
SceneNode& Scene::GetSceneNode(std::string name)
Node& Scene::GetSceneNode(std::string name)
{
return *SearchInChildren(root, name);
}
SceneNode& Scene::GetRoot()
Node& 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)
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);
}
}
}

View File

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

View File

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

View File

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

View File

@ -1,15 +1,15 @@
#include "Graphics/Buffer.h"
int Buffer::getBufferID() {
int GpuBuffer::getBufferID() {
return id;
}
void Buffer::createBuffer() {
void GpuBuffer::createBuffer() {
glGenBuffers(1, (GLuint*) &id);
}
void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
void GpuBuffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = false ) {
if (elementBuffer) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, dataSize, data, GL_STATIC_DRAW);
@ -21,7 +21,7 @@ void Buffer::setBufferData(void* data, size_t dataSize, bool elementBuffer = fal
}
void Buffer::Bind(bool elementBuffer = false ) {
void GpuBuffer::Bind(bool elementBuffer = false ) {
if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
@ -32,7 +32,7 @@ void Buffer::Bind(bool elementBuffer = false ) {
}
}
void Buffer::Unbind(bool elementBuffer = false) {
void GpuBuffer::Unbind(bool elementBuffer = false) {
if (elementBuffer) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
@ -42,6 +42,6 @@ void Buffer::Unbind(bool elementBuffer = false) {
}
}
void Buffer::Delete() {
void GpuBuffer::Delete() {
glDeleteBuffers(1, (GLuint*) &id);
}

View File

@ -1,17 +1,27 @@
#include "AssetManager/ModelImporter.h"
std::vector<BarinkEngine::Mesh> ModelImporter::Import(std::string path)
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.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs);
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
aiNode* currentNode = scene->mRootNode;
return processNode(currentNode, scene);
std::vector<BarinkEngine::Mesh> meshes = processNode(currentNode, scene);
return root;
}
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene) {
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));
@ -28,10 +38,24 @@ std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const a
return meshes;
}
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
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{};
@ -39,9 +63,9 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
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;
@ -52,29 +76,19 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
v.uv = texCoord;
}
vertices.push_back(v);
}
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++) {
indices.push_back(face.mIndices[j]);
out_indices.push_back(face.mIndices[j]);
}
}
BarinkEngine::Mesh result;
result.vertices = vertices;
result.elements = indices;
return result;
}

View File

@ -3,60 +3,51 @@
#include "PerfCounter.h"
Renderable* Renderable::Load(std::string& path)
BarinkEngine::Renderable::Renderable()
{
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.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();
VAO.Unbind();
*/
}
Renderable::~Renderable()
BarinkEngine::Renderable::~Renderable()
{
glDeleteBuffers(1, &UV_id);
// glDeleteBuffers(1, &UV_id);
}
void Renderable::Draw()
{
VAO.Bind();
elementBuffer.Bind(true);
// Draw call Example !!
/*
VAO.Bind();
elementBuffer.Bind(true);
glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(shader->id, "Texture"), GL_TEXTURE0);
texture->Bind();
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();
}
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();
*/

View File

@ -14,7 +14,7 @@ void BarinkEngine::Renderer::Render()
{
for (auto model : models) {
model->Draw();
//model->Draw();
}
}

View File

@ -79,9 +79,6 @@ void BarinkWindow::SwapBuffers()
void BarinkWindow::ReceiveEvent(Event& incident)
{
std::cout << "EVENT RECEIVED: " << incident.name << std::endl;
}

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,32 @@
#include "GUI.h"
void SceneExplorer(Scene& scene, std::string PanelName) {
ImGui::Begin(PanelName.c_str());
ImGui::ListBoxHeader("##ObjectList");
Node& current = scene.GetRoot();
Node* next = &current;
// Show first node
ImGui::Selectable(next->name.c_str(), true);
ImGui::Indent();
if (next->children.size() != 0) {
for (auto child : next->children)
{
std::string& name = child->name;
ImGui::Selectable(name.c_str(), false);
}
}
ImGui::ListBoxFooter();
ImGui::End();
}
void CameraTool(Camera* cam) {
ImGui::Begin("Camera");

View File

@ -5,4 +5,5 @@
void CameraTool(Camera* camera);
void ScriptingTool(char* code);
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);

View File

@ -1,4 +1,8 @@
#include "BarinkEngine.h"
#include "Scene\SceneManager.h"
#include "Scene\SceneNodeTypes.h"
#include "AssetManager/ModelImporter.h"
#include "imgui.h"
#include "GUI.h"
#include "Util.h"
@ -7,88 +11,50 @@
* 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";
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
Scene* Level1;
/*
* 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
/*
Building a very basic scene graph
*/
SceneNode MyCube = SceneNode();
MyCube.name = "MyCube";
// Create a level and load it as the current level
std::string levelName("Test Level");
Level1 = SceneManager::CreateScene(levelName);
SceneManager::LoadScene(*Level1);
SceneNode MyBaby = SceneNode();
MyBaby.name = "Baby";
// Create a cube node
// Load a model
// *(MI->Import("build/SandboxApplication/Debug/Models/Cube.obj"))
SceneNode MySecondCube = SceneNode();
MySecondCube.name = "MySecondCube";
std::string groupName("Nested-Group");
auto testGroup = new Group(groupName);
Level1->GetRoot().addChild( *testGroup);
std::string group2Name("Nested-Group2");
auto testGroup2 = new Group(group2Name);
Level1->GetRoot().addChild(*testGroup2);
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);
// Walk scene graph
PrintSceneTree(Level1->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);
}
@ -103,24 +69,14 @@ void ImmediateGraphicsDraw() {
// 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");
SceneExplorer(*Level1, "Scene Explorer");
}
/*
@ -129,8 +85,6 @@ void ImmediateGraphicsDraw() {
*/
void Update()
{
/*
* NOTE: this needs to move to the renderer
* Render code should not appear in the sandbox file
@ -141,16 +95,16 @@ void Update()
shader->Use();
shader->setUniformMat4("P", projection);
shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
//shader->setUniformMat4("M", CalculateModelMat(Cube->transform));
shader->setUniformMat4("V", cam->GetViewMatrix());
matCube->Apply();
//matCube->Apply();
Cube->Draw();
//Cube->Draw();
shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
matCube2->Apply();
//shader->setUniformMat4("M", CalculateModelMat(Cube2->transform));
// matCube2->Apply();
Cube2->Draw();
//Cube2->Draw();
}
@ -159,18 +113,6 @@ void Update()
* - 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 MI;
delete shader;
}

View File

@ -1,6 +1,6 @@
#include "Util.h"
void PrintSceneTree(SceneNode& node, int depth) {
void PrintSceneTree(Node& node, int depth) {
// Indent name based on depth
std::cout << " ";
for (int i = 0; i < depth; i++) {

View File

@ -1,6 +1,6 @@
#pragma once
#include "BarinkEngine.h"
void PrintSceneTree(SceneNode& node, int depth);
void PrintSceneTree(Node& node, int depth);
glm::mat4 CalculateModelMat(Transform& transform);