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 Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
|
||||||
|
unsigned int getID() { return id; }
|
||||||
|
|
||||||
void Delete();
|
void Delete();
|
||||||
|
|
||||||
void AttachAttribute(unsigned int index, int size, int stride);
|
void AttachAttribute(unsigned int index, int size, int stride);
|
||||||
|
@ -1,23 +1,73 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "../Scene/Components.h"
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
float Angle = 0.0;
|
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);
|
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);
|
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)
|
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();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
|
void Prepare(Scene& scene);
|
||||||
void Render(Scene& scene );
|
void Render(Scene& scene );
|
||||||
|
|
||||||
void Render(Framebuffer& framebuffer);
|
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
|
#pragma once
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include "../Graphics/Primitives/Shader.h"
|
||||||
|
#include "../Graphics/Primitives/Mesh.h"
|
||||||
namespace BarinkEngine {
|
namespace BarinkEngine {
|
||||||
|
struct IdentifierComponent {
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
struct TransformComponent {
|
struct TransformComponent {
|
||||||
glm::mat4& transform = glm::mat4(1.0f);
|
glm::mat4& transform = glm::mat4(1.0f);
|
||||||
@ -15,9 +19,19 @@ namespace BarinkEngine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Render3DComponent {
|
struct Render3DComponent {
|
||||||
unsigned int VAO;
|
unsigned int VAO = 0;
|
||||||
unsigned int IBO;
|
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 {
|
struct Render2DComponent {
|
||||||
|
@ -10,10 +10,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
template<class T >
|
template<class T >
|
||||||
T AddComponent() {
|
T& AddComponent() {
|
||||||
return m_scene->m_registry.emplace<T>(m_entity);
|
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:
|
private:
|
||||||
entt::entity m_entity;
|
entt::entity m_entity;
|
||||||
Scene* m_scene;
|
Scene* m_scene;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
#include "Components.h"
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -9,6 +10,12 @@ Scene::~Scene()
|
|||||||
|
|
||||||
Entity Scene::AddEntity(std::string& name)
|
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(){
|
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/Components.h"
|
||||||
#include "../../BarinkEngine/src/Scene/Scene.h"
|
#include "../../BarinkEngine/src/Scene/Scene.h"
|
||||||
#include "../../BarinkEngine/src/Scene/Entity.h"
|
#include "../../BarinkEngine/src/Scene/Entity.h"
|
||||||
|
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define globals
|
* Define globals
|
||||||
*/
|
*/
|
||||||
//Shader* shader;
|
|
||||||
const std::string vertexShaderSource = "build/Debug/test.vs";
|
|
||||||
const std::string fragmentShaderSource = "build/Debug/test.fs";
|
|
||||||
|
|
||||||
Scene scene;
|
Scene scene;
|
||||||
|
|
||||||
|
BarinkEngine::Renderable* renderable;
|
||||||
|
BarinkEngine::SceneObject* object;
|
||||||
|
Entity cube;
|
||||||
/*
|
/*
|
||||||
* Runs once at startup
|
* Runs once at startup
|
||||||
* - USe to initialize the game/sandbox/demo
|
* - USe to initialize the game/sandbox/demo
|
||||||
*/
|
*/
|
||||||
void Start() {
|
void Start() {
|
||||||
// shader = new Shader(vertexShaderSource, fragmentShaderSource);
|
|
||||||
|
|
||||||
auto cube = scene.AddEntity((std::string&)"cube");
|
cube = scene.AddEntity((std::string&)"cube");
|
||||||
auto transform = cube.AddComponent<BarinkEngine::TransformComponent>();
|
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||||
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");
|
render3DComponent.mesh = *renderable->mesh;
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -49,6 +42,18 @@ void ImmediateGraphicsDraw()
|
|||||||
{
|
{
|
||||||
// Show internal BarinkEngine stats
|
// Show internal BarinkEngine stats
|
||||||
ShowStats();
|
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()
|
void Update()
|
||||||
{
|
{
|
||||||
|
|
||||||
renderer.Render(scene);
|
renderer.Render(scene);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user