Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/plugin/opengl/src/OpenGL.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#pragma once

#include "component/Model/Model.hpp"
#include "component/MaterialHandle/MaterialHandle.hpp"
#include "component/ModelHandle/ModelHandle.hpp"
#include "component/ShaderHandle/ShaderHandle.hpp"

#include "plugin/PluginOpenGL.hpp"
#include "resource/Camera/Camera.hpp"

#include "resource/GLBufferManager/GLBufferManager.hpp"
#include "resource/MaterialCache/MaterialCache.hpp"
#include "resource/ShaderManager/ShaderManager.hpp"

#include "system/AllSystems.hpp"

#include "utils/GLBuffer/GLBuffer.hpp"
#include "utils/Loader/Loader.hpp"
#include "utils/Material/Material.hpp"
Expand Down
24 changes: 24 additions & 0 deletions src/plugin/opengl/src/component/MaterialHandle/MaterialHandle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <string>

#include <entt/entt.hpp>

namespace ES::Plugin::OpenGL::Component {
/**
* MaterialHandle component
* This is only a reference to the material used by the entity,
* handling of the material is done via the MaterialCache resource.
*/
struct MaterialHandle {
std::string name;

entt::hashed_string id;

MaterialHandle() = default;
explicit MaterialHandle(const std::string &name) : name(name), id(entt::hashed_string(name.c_str())) {}

MaterialHandle(const MaterialHandle &) = default;
MaterialHandle(MaterialHandle &&) = default;
};
} // namespace ES::Plugin::OpenGL::Component
20 changes: 0 additions & 20 deletions src/plugin/opengl/src/component/Model/Model.hpp

This file was deleted.

19 changes: 19 additions & 0 deletions src/plugin/opengl/src/component/ModelHandle/ModelHandle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <string>

#include <entt/entt.hpp>

namespace ES::Plugin::OpenGL::Component {
struct ModelHandle {
std::string name;

entt::hashed_string id;

ModelHandle() = default;
explicit ModelHandle(const std::string &name) : name(name), id(entt::hashed_string(name.c_str())) {}

ModelHandle(const ModelHandle &) = default;
ModelHandle(ModelHandle &&) = default;
};
} // namespace ES::Plugin::OpenGL::Component
24 changes: 24 additions & 0 deletions src/plugin/opengl/src/component/ShaderHandle/ShaderHandle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <string>

#include <entt/entt.hpp>

namespace ES::Plugin::OpenGL::Component {
/**
* ShaderHandle component
* This is only a reference to the shader program used by the entity,
* handling of the shader program is done via the ShaderManager resource.
*/
struct ShaderHandle {
std::string name;

entt::hashed_string id;

ShaderHandle() = default;
explicit ShaderHandle(const std::string &name) : name(name), id(entt::hashed_string(name.c_str())) {}

ShaderHandle(const ShaderHandle &) = default;
ShaderHandle(ShaderHandle &&) = default;
};
} // namespace ES::Plugin::OpenGL::Component
47 changes: 30 additions & 17 deletions src/plugin/opengl/src/system/AllSystems.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#include "AllSystems.hpp"
#include "Button/Buttons.hpp"

#include "Buttons.hpp"
#include "Camera.hpp"
#include "Entity.hpp"
#include "GLBufferManager.hpp"
#include "Light.hpp"
#include "MaterialCache.hpp"
#include "MaterialHandle.hpp"
#include "Mesh.hpp"
#include "ModelHandle.hpp"
#include "ShaderHandle.hpp"
#include "ShaderManager.hpp"

#include <glm/gtc/type_ptr.hpp>
#include <iostream>

void ES::Plugin::OpenGL::System::InitGLEW(const ES::Engine::Core &)
{
Expand Down Expand Up @@ -167,16 +181,16 @@ void ES::Plugin::OpenGL::System::LoadGLBuffer(ES::Engine::Core &core)
{
auto &glBufferManager = core.GetResource<Resource::GLBufferManager>();

core.GetRegistry().view<Component::Model, ES::Plugin::Object::Component::Mesh>().each(
[&](auto entity, Component::Model &model, ES::Plugin::Object::Component::Mesh &mesh) {
if (glBufferManager.Contains(entt::hashed_string(model.modelName.c_str())))
core.GetRegistry().view<Component::ModelHandle, ES::Plugin::Object::Component::Mesh>().each(
[&](auto entity, Component::ModelHandle &model, ES::Plugin::Object::Component::Mesh &mesh) {
if (glBufferManager.Contains(model.id))
{
glBufferManager.Get(entt::hashed_string{model.modelName.c_str()}).update(mesh);
glBufferManager.Get(model.id).Update(mesh);
return;
}
Utils::GLBuffer buffer;
buffer.generateGlBuffers(mesh);
glBufferManager.Add(entt::hashed_string(model.modelName.c_str()), std::move(buffer));
buffer.GenerateGLBuffers(mesh);
glBufferManager.Add(model.id, std::move(buffer));
});
}

Expand Down Expand Up @@ -259,15 +273,14 @@ void ES::Plugin::OpenGL::System::RenderMeshes(ES::Engine::Core &core)
auto &view = core.GetResource<Resource::Camera>().view;
auto &projection = core.GetResource<Resource::Camera>().projection;
core.GetRegistry()
.view<Component::Model, ES::Plugin::Object::Component::Transform, ES::Plugin::Object::Component::Mesh>()
.each([&](auto entity, Component::Model &model, ES::Plugin::Object::Component::Transform &transform,
ES::Plugin::Object::Component::Mesh &mesh) {
auto &shader =
core.GetResource<Resource::ShaderManager>().Get(entt::hashed_string{model.shaderName.c_str()});
const auto material =
core.GetResource<Resource::MaterialCache>().Get(entt::hashed_string{model.materialName.c_str()});
const auto &glbuffer =
core.GetResource<Resource::GLBufferManager>().Get(entt::hashed_string{model.modelName.c_str()});
.view<Component::ModelHandle, ES::Plugin::Object::Component::Transform, ES::Plugin::Object::Component::Mesh,
Component::ShaderHandle, Component::MaterialHandle>()
.each([&](auto entity, Component::ModelHandle &modelHandle, ES::Plugin::Object::Component::Transform &transform,
ES::Plugin::Object::Component::Mesh &mesh, Component::ShaderHandle &shaderHandle,
Component::MaterialHandle &materialHandle) {
auto &shader = core.GetResource<Resource::ShaderManager>().Get(shaderHandle.id);
const auto &material = core.GetResource<Resource::MaterialCache>().Get(materialHandle.id);
const auto &glBuffer = core.GetResource<Resource::GLBufferManager>().Get(modelHandle.id);
shader.use();
LoadMaterial(shader, material);
glm::mat4 modelmat = transform.getTransformationMatrix();
Expand All @@ -277,7 +290,7 @@ void ES::Plugin::OpenGL::System::RenderMeshes(ES::Engine::Core &core)
glUniformMatrix3fv(shader.uniform("NormalMatrix"), 1, GL_FALSE, glm::value_ptr(nmat));
glUniformMatrix4fv(shader.uniform("ModelMatrix"), 1, GL_FALSE, glm::value_ptr(modelmat));
glUniformMatrix4fv(shader.uniform("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glbuffer.draw(mesh);
glBuffer.Draw(mesh);
shader.disable();
});
}
9 changes: 1 addition & 8 deletions src/plugin/opengl/src/system/AllSystems.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#pragma once

#include "Entity.hpp"
#include "GLBufferManager.hpp"
#include "MaterialCache.hpp"
#include "Model.hpp"
#include "ShaderManager.hpp"
#include "resource/Camera/Camera.hpp"
#include "utils/Light/Light.hpp"
#include <iostream>
#include "Core.hpp"

namespace ES::Plugin::OpenGL::System {
const int DEFAULT_WIDTH = 800;
Expand Down
8 changes: 4 additions & 4 deletions src/plugin/opengl/src/utils/GLBuffer/GLBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

namespace ES::Plugin::OpenGL::Utils {

void GLBuffer::draw(const Object::Component::Mesh &mesh) const noexcept
void GLBuffer::Draw(const Object::Component::Mesh &mesh) const noexcept
{
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, mesh.indices.size() * sizeof(uint32_t), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
}

void GLBuffer::destroyGlBuffers() const noexcept
void GLBuffer::DestroyGLBuffers() const noexcept
{
glDeleteBuffers(1, &VBO_position);
glDeleteBuffers(1, &VBO_normal);
glDeleteBuffers(1, &IBO);
glDeleteVertexArrays(1, &VAO);
}

void GLBuffer::generateGlBuffers(const Object::Component::Mesh &mesh) noexcept
void GLBuffer::GenerateGLBuffers(const Object::Component::Mesh &mesh) noexcept
{
// create vao, vbo and ibo here... (We didn't use std::vector here...)
glGenVertexArrays(1, &VAO);
Expand Down Expand Up @@ -45,7 +45,7 @@ void GLBuffer::generateGlBuffers(const Object::Component::Mesh &mesh) noexcept
glBindVertexArray(0);
}

void GLBuffer::update(const Object::Component::Mesh &mesh) const noexcept
void GLBuffer::Update(const Object::Component::Mesh &mesh) const noexcept
{
glBindVertexArray(VAO);

Expand Down
11 changes: 5 additions & 6 deletions src/plugin/opengl/src/utils/GLBuffer/GLBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
#include <vector>

#include "Loader.hpp"
#include "Material.hpp"

#include "component/Mesh.hpp"
#include "Mesh.hpp"

namespace ES::Plugin::OpenGL::Utils {

Expand All @@ -42,13 +41,13 @@ class GLBuffer {
GLBuffer &operator=(const GLBuffer &) = default;
GLBuffer &operator=(GLBuffer &&) = default;

void draw(const Object::Component::Mesh &mesh) const noexcept;
void Draw(const Object::Component::Mesh &mesh) const noexcept;

void destroyGlBuffers() const noexcept;
void DestroyGLBuffers() const noexcept;

void generateGlBuffers(const Object::Component::Mesh &mesh) noexcept;
void GenerateGLBuffers(const Object::Component::Mesh &mesh) noexcept;

void update(const Object::Component::Mesh &mesh) const noexcept;
void Update(const Object::Component::Mesh &mesh) const noexcept;

GLuint VAO = 0;
GLuint VBO_position = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/plugin/opengl/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ target("PluginOpenGL")
add_includedirs("src/utils/Viewer/", {public = true})
add_includedirs("src/utils/Loader/", {public = true})
add_includedirs("src/utils/Light", {public = true})
add_includedirs("src/component/ShaderHandle/", {public = true})
add_includedirs("src/component/MaterialHandle/", {public = true})
add_includedirs("src/component/ModelHandle/", {public = true})
add_includedirs("src/utils/GLBuffer/", {public = true})
add_includedirs("src/component/Model/", {public = true})
add_includedirs("src/resource/ShaderManager/", {public = true})
add_includedirs("src/resource/GLBufferManager/", {public = true})
add_includedirs("src/resource/MaterialCache/", {public = true})
Expand Down