Compare commits

..

No commits in common. "99eb5282e5dc202c7d9195f86090304bf9b46cf7" and "7458254b2dba6cdd093180750cdad92e1b96444d" have entirely different histories.

11 changed files with 116 additions and 121 deletions

View File

@ -0,0 +1,36 @@
#include "GPUBucket.h"
BarinkEngine::GPU_Bucket::GPU_Bucket() {
}
BarinkEngine::GPU_Bucket::~GPU_Bucket() {
}
void BarinkEngine::GPU_Bucket::Upload(const Mesh& renderable) {
// keep a ref to the origin in main memory
mesh = &renderable;
// Upload gpu
vertexarray.Create();
vertexarray.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData((void*)&renderable.vertices[0], renderable.vertices.size() * sizeof(BarinkEngine::Vertex), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData((void*)&renderable.elements[0], renderable.elements.size() * sizeof(unsigned int), true);
vertexarray.AttachAttribute(0, 3, sizeof(Vertex));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
vertexBuffer.Unbind(false);
vertexarray.Unbind();
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "Memory/VertexArray.h"
#include "Memory/Buffer.h"
#include "Primitives/Mesh.h"
#include "Primitives/Material.h"
#include <glm/glm.hpp>
namespace BarinkEngine {
class GPU_Bucket {
public:
GPU_Bucket();
~GPU_Bucket();
void Upload(const Mesh& renderable);
GpuBuffer vertexBuffer;
GpuBuffer elementBuffer;
VertexArray vertexarray;
const Mesh* mesh;
const Material* material;
private :
unsigned int uv_id;
};
};

View File

@ -10,8 +10,6 @@ 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,73 +1,23 @@
#include "Renderer.h"
#include "../Scene/Components.h"
#include <glad/glad.h>
float Angle = 0.0;
Camera cam = Camera(glm::vec3(16.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
BarinkEngine::Renderer::Renderer(){}
BarinkEngine::Renderer::~Renderer(){}
void BarinkEngine::Renderer::Prepare(Scene& scene ) {
auto group = scene.getReg().view<BarinkEngine::Render3DComponent>();
group.each([](auto enity, BarinkEngine::Render3DComponent& renderComponent) {
VertexArray va = VertexArray();
GpuBuffer vertexBuffer = GpuBuffer();
GpuBuffer elementBuffer = GpuBuffer();
va.Create();
va.Bind();
vertexBuffer.createBuffer();
vertexBuffer.Bind(false);
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(BarinkEngine::Vertex), false);
elementBuffer.createBuffer();
elementBuffer.Bind(true);
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
va.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
va.Unbind();
vertexBuffer.Unbind(false);
elementBuffer.Unbind(true);
renderComponent.VAO = va.getID();
renderComponent.IBO = elementBuffer.getBufferID();
});
BarinkEngine::Renderer::Renderer()
{
}
BarinkEngine::Renderer::~Renderer()
{
}
void BarinkEngine::Renderer::Render(Scene& scene)
{
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
{
glBindVertexArray(renderComponent.VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
renderComponent.shader.Use();
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
renderComponent.shader.setUniformMat4("M", glm::mat4(1.0f));
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
renderComponent.shader.setUniformMat4("P", projection);
{}
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(renderComponent.mesh.elements.size()) ,
GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
});
void Render(Framebuffer& framebuffer) {
}
void Render(Framebuffer& framebuffer)
{}
}

View File

@ -20,9 +20,7 @@ namespace BarinkEngine {
Renderer();
~Renderer();
void Prepare(Scene& scene);
void Render(Scene& scene );
void Render(Framebuffer& framebuffer);
};
}

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,11 +1,7 @@
#pragma once
#include <glm/glm.hpp>
#include "../Graphics/Primitives/Shader.h"
#include "../Graphics/Primitives/Mesh.h"
namespace BarinkEngine {
struct IdentifierComponent {
std::string name;
};
struct TransformComponent {
glm::mat4& transform = glm::mat4(1.0f);
@ -19,19 +15,9 @@ namespace BarinkEngine {
};
struct Render3DComponent {
unsigned int VAO = 0;
unsigned int IBO = 0;
Mesh mesh;
unsigned int VAO;
unsigned int IBO;
// TODO: becomes a material
glm::vec3 color;
Shader shader;
Render3DComponent()
: shader(Shader("build/Debug/test.vs", "build/Debug/test.fs")),
color(glm::vec3(1.0f, 0.0f, 0.0f))
{
}
};
struct Render2DComponent {

View File

@ -10,15 +10,10 @@ public:
template<class T >
T& AddComponent() {
T AddComponent() {
return m_scene->m_registry.emplace<T>(m_entity);
}
template<class T>
T* GetComponent() {
return m_scene->m_registry.try_get<T>(m_entity);
}
private:
entt::entity m_entity;
Scene* m_scene;

View File

@ -1,6 +1,5 @@
#include "Scene.h"
#include "Entity.h"
#include "Components.h"
Scene::Scene()
{
}
@ -10,12 +9,6 @@ Scene::~Scene()
Entity Scene::AddEntity(std::string& name)
{
Entity entity = { m_registry.create(), this };
entity.AddComponent<BarinkEngine::IdentifierComponent>();
entity.AddComponent<BarinkEngine::TransformComponent>();
return entity;
return { m_registry.create(), this };
}

View File

@ -7,5 +7,5 @@ uniform sampler2D Texture;
void main(){
FragColor = vec4(color , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
FragColor = vec4(1.0f, 0.0f, 0.0f , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
}

View File

@ -2,36 +2,43 @@
#include "../../BarinkEngine/src/Scene/Components.h"
#include "../../BarinkEngine/src/Scene/Scene.h"
#include "../../BarinkEngine/src/Scene/Entity.h"
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
#include <imgui.h>
#include "GUI.h"
#include "Util.h"
#include <entt/entt.hpp>
/*
* Define globals
*/
Scene scene;
//Shader* shader;
const std::string vertexShaderSource = "build/Debug/test.vs";
const std::string fragmentShaderSource = "build/Debug/test.fs";
BarinkEngine::Renderable* renderable;
BarinkEngine::SceneObject* object;
Entity cube;
Scene scene;
/*
* Runs once at startup
* - USe to initialize the game/sandbox/demo
*/
void Start() {
// shader = new Shader(vertexShaderSource, fragmentShaderSource);
cube = scene.AddEntity((std::string&)"cube");
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
auto importer = BarinkEngine::ModelImporter();
auto cube = scene.AddEntity((std::string&)"cube");
auto transform = cube.AddComponent<BarinkEngine::TransformComponent>();
auto render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
object = importer.Import("build/Debug/Models/Cube.obj");
renderable = object->renderable;
auto cube2 = scene.AddEntity((std::string&)"cube1");
render3DComponent.mesh = *renderable->mesh;
auto cube3 = scene.AddEntity((std::string&)"cube2");
auto Transform2 = cube3.AddComponent<BarinkEngine::TransformComponent>();
auto render3DComponent2 = cube3.AddComponent<BarinkEngine::Render3DComponent>();
renderer.Prepare(scene);
// Run over every transform component
auto view = scene.getReg().view<BarinkEngine::TransformComponent, BarinkEngine::Render3DComponent>();
view.each([](auto entity, auto& transform) {
std::cout << "Found a transform !" << std::endl;
});
}
/*
@ -42,18 +49,6 @@ void ImmediateGraphicsDraw()
{
// Show internal BarinkEngine stats
ShowStats();
ImGui::Begin("Render edit");
auto a = cube.GetComponent<BarinkEngine::Render3DComponent>();
ImGui::DragFloat3("Color", &a->color[0], 0.01f, 0.0f, 1.0f);
ImGui::End();
}
/*
@ -62,6 +57,7 @@ void ImmediateGraphicsDraw()
*/
void Update()
{
renderer.Render(scene);
}