Compare commits
2 Commits
7458254b2d
...
99eb5282e5
Author | SHA1 | Date | |
---|---|---|---|
99eb5282e5 | |||
bc1254e427 |
@ -1,36 +0,0 @@
|
||||
#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();
|
||||
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -10,6 +10,8 @@ void Create();
|
||||
void Bind();
|
||||
void Unbind();
|
||||
|
||||
unsigned int getID() { return id; }
|
||||
|
||||
void Delete();
|
||||
|
||||
void AttachAttribute(unsigned int index, int size, int stride);
|
||||
|
@ -1,23 +1,73 @@
|
||||
#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(){}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer()
|
||||
{
|
||||
}
|
||||
BarinkEngine::Renderer::~Renderer(){}
|
||||
|
||||
void BarinkEngine::Renderer::Prepare(Scene& scene ) {
|
||||
auto group = scene.getReg().view<BarinkEngine::Render3DComponent>();
|
||||
group.each([](auto enity, BarinkEngine::Render3DComponent& renderComponent) {
|
||||
VertexArray va = VertexArray();
|
||||
GpuBuffer vertexBuffer = GpuBuffer();
|
||||
GpuBuffer elementBuffer = GpuBuffer();
|
||||
|
||||
va.Create();
|
||||
va.Bind();
|
||||
|
||||
vertexBuffer.createBuffer();
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData((void*)&renderComponent.mesh.vertices[0], renderComponent.mesh.vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData((void*)&renderComponent.mesh.elements[0], renderComponent.mesh.elements.size() * sizeof(unsigned int), true);
|
||||
|
||||
va.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex));
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
va.Unbind();
|
||||
vertexBuffer.Unbind(false);
|
||||
elementBuffer.Unbind(true);
|
||||
|
||||
renderComponent.VAO = va.getID();
|
||||
renderComponent.IBO = elementBuffer.getBufferID();
|
||||
});
|
||||
}
|
||||
|
||||
void BarinkEngine::Renderer::Render(Scene& scene)
|
||||
{}
|
||||
{
|
||||
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||
{
|
||||
|
||||
glBindVertexArray(renderComponent.VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
|
||||
|
||||
renderComponent.shader.Use();
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
|
||||
renderComponent.shader.setUniformMat4("M", 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);
|
||||
|
||||
void Render(Framebuffer& framebuffer) {
|
||||
glBindVertexArray(0);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Render(Framebuffer& framebuffer)
|
||||
{}
|
@ -20,7 +20,9 @@ namespace BarinkEngine {
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
void Prepare(Scene& scene);
|
||||
void Render(Scene& scene );
|
||||
|
||||
void Render(Framebuffer& framebuffer);
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
struct Transform {
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Rotation;
|
||||
glm::vec3 Scale;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
#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);
|
||||
@ -15,9 +19,19 @@ namespace BarinkEngine {
|
||||
};
|
||||
|
||||
struct Render3DComponent {
|
||||
unsigned int VAO;
|
||||
unsigned int IBO;
|
||||
unsigned int VAO = 0;
|
||||
unsigned int IBO = 0;
|
||||
Mesh mesh;
|
||||
|
||||
// TODO: becomes a material
|
||||
glm::vec3 color;
|
||||
Shader shader;
|
||||
|
||||
Render3DComponent()
|
||||
: shader(Shader("build/Debug/test.vs", "build/Debug/test.fs")),
|
||||
color(glm::vec3(1.0f, 0.0f, 0.0f))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Render2DComponent {
|
||||
|
@ -10,10 +10,15 @@ 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;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Scene.h"
|
||||
#include "Entity.h"
|
||||
#include "Components.h"
|
||||
Scene::Scene()
|
||||
{
|
||||
}
|
||||
@ -9,6 +10,12 @@ Scene::~Scene()
|
||||
|
||||
Entity Scene::AddEntity(std::string& name)
|
||||
{
|
||||
return { m_registry.create(), this };
|
||||
Entity entity = { m_registry.create(), this };
|
||||
|
||||
entity.AddComponent<BarinkEngine::IdentifierComponent>();
|
||||
entity.AddComponent<BarinkEngine::TransformComponent>();
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@ -7,5 +7,5 @@ uniform sampler2D Texture;
|
||||
|
||||
|
||||
void main(){
|
||||
FragColor = vec4(1.0f, 0.0f, 0.0f , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
|
||||
FragColor = vec4(color , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
|
||||
}
|
@ -2,43 +2,36 @@
|
||||
#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
|
||||
*/
|
||||
//Shader* shader;
|
||||
const std::string vertexShaderSource = "build/Debug/test.vs";
|
||||
const std::string fragmentShaderSource = "build/Debug/test.fs";
|
||||
|
||||
Scene scene;
|
||||
|
||||
BarinkEngine::Renderable* renderable;
|
||||
BarinkEngine::SceneObject* object;
|
||||
Entity cube;
|
||||
/*
|
||||
* Runs once at startup
|
||||
* - USe to initialize the game/sandbox/demo
|
||||
*/
|
||||
void Start() {
|
||||
// shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
||||
|
||||
auto cube = scene.AddEntity((std::string&)"cube");
|
||||
auto transform = cube.AddComponent<BarinkEngine::TransformComponent>();
|
||||
auto render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
cube = scene.AddEntity((std::string&)"cube");
|
||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
auto importer = BarinkEngine::ModelImporter();
|
||||
|
||||
auto cube2 = scene.AddEntity((std::string&)"cube1");
|
||||
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||
renderable = object->renderable;
|
||||
|
||||
auto cube3 = scene.AddEntity((std::string&)"cube2");
|
||||
auto Transform2 = cube3.AddComponent<BarinkEngine::TransformComponent>();
|
||||
auto render3DComponent2 = cube3.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
render3DComponent.mesh = *renderable->mesh;
|
||||
|
||||
|
||||
// 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;
|
||||
});
|
||||
|
||||
|
||||
renderer.Prepare(scene);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -49,6 +42,18 @@ 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();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -57,7 +62,6 @@ void ImmediateGraphicsDraw()
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
|
||||
renderer.Render(scene);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user