OpenGLMeshUploadManager.ixx File
OpenGL manager that uploads mesh data and creates VAO/VBO/EBO objects. More...
#include <glad/gl.h>
#include <GLFW/glfw3.h>
#include <cassert>
#include <iostream>
#include <memory>
#include <ostream>
#include <ranges>
#include <unordered_map>
#include <vector>
#include <helios.engine.runtime.world.tags>
#include <helios.engine.util.log>
#include <
helios.opengl.OpenGLEnumMapper>
#include <helios.engine.rendering.common.types.Vertex>
#include <helios.engine.util.io>
#include <helios.engine.runtime.messaging.command.concepts>
#include <helios.engine.rendering.mesh.commands>
#include <helios.engine.rendering.mesh.components>
#include <helios.engine.rendering.mesh.types>
#include <helios.engine.rendering.mesh.MeshEntity>
#include <helios.engine.runtime.world>
#include <helios.engine.rendering.mesh.concepts>
#include <
helios.opengl.components.OpenGLMeshComponent>
#include <helios.engine.runtime.world.EngineWorld>
#include <helios.engine.runtime.messaging.command.NullCommandBuffer>
#include <helios.engine.runtime.messaging.command.CommandHandlerRegistry>
#include <helios.engine.runtime.concepts>
Namespaces Index
| namespace | helios |
|
|
|
| namespace | opengl |
|
|
|
| namespace | io |
|
|
|
| namespace | tags |
|
|
|
| namespace | commands |
|
|
|
| namespace | mesh |
|
|
|
| namespace | concepts |
|
|
|
| namespace | concepts |
|
|
|
| namespace | command |
|
|
|
Classes Index
Macro Definitions Index
Description
OpenGL manager that uploads mesh data and creates VAO/VBO/EBO objects.
Macro Definitions
HELIOS_LOG_SCOPE
| #define HELIOS_LOG_SCOPE "helios::opengl::OpenGLMeshUploadManager" |
|
File Listing
The file content with the documentation metadata removed is:
14#include <unordered_map>
18export module helios.opengl.OpenGLMeshUploadManager;
20import helios.engine.util.log;
21import helios.engine.util.io;
23import helios.engine.rendering.common.types.Vertex;
24import helios.engine.rendering.mesh.commands;
25import helios.engine.rendering.mesh.components;
26import helios.engine.rendering.mesh.MeshEntity;
27import helios.engine.rendering.mesh.types;
28import helios.engine.rendering.mesh.concepts;
30import helios.engine.runtime.world.EngineWorld;
31import helios.engine.runtime.messaging.command.concepts;
32import helios.engine.runtime.messaging.command.NullCommandBuffer;
33import helios.engine.runtime.messaging.command.CommandHandlerRegistry;
34import helios.engine.runtime.concepts;
35import helios.engine.runtime.world.tags;
36import helios.engine.runtime.world;
39import helios.opengl.components.OpenGLMeshComponent;
40import helios.opengl.OpenGLEnumMapper;
42using namespace helios::engine::runtime::world;
43using namespace helios::engine::util::log;
44using namespace helios::engine::util::io;
45using namespace helios::engine::runtime::world::tags;
46using namespace helios::engine::rendering::mesh::commands;
47using namespace helios::engine::rendering::mesh::components;
48using namespace helios::engine::rendering::mesh;
49using namespace helios::engine::rendering::mesh::types;
50using namespace helios::engine::rendering::mesh::concepts;
51using namespace helios::engine::rendering::mesh::commands;
52using namespace helios::engine::rendering::common::types;
55using namespace helios::engine::runtime::messaging::command::concepts;
56using namespace helios::engine::runtime::messaging::command;
58#define HELIOS_LOG_SCOPE "helios::opengl::OpenGLMeshUploadManager"
67 template<typename THandle, typename TCommandBuffer = NullCommandBuffer>
68 requires IsMeshHandle<THandle> && IsCommandBufferLike<TCommandBuffer>
71 RenderResourceWorld& renderResourceWorld_;
73 std::vector<MeshHandle> meshHandles_;
76 inline static const Logger& logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE);
85 bool upload(MeshEntity mesh) noexcept {
87 using Handle = typename MeshEntity::Handle_type;
89 logger_.info("Uploading mesh data for MeshEntity {0}...", mesh.handle().entityId);
91 if (!mesh.template get<MeshUploadRequestComponent<Handle>>()) {
92 logger_.error("MeshUpload not requested by this entity");
93 assert(false && "MeshUpload not requested by this entity");
99 logger_.error("Mesh already has a MeshComponent");
100 assert(false && "Mesh already has a MeshComponent");
104 auto* meshDataComponent = mesh.template get<MeshDataComponent<Handle>>();
105 auto& meshData = meshDataComponent->meshData;
107 auto& openglMesh = mesh.template add<OpenGLMeshComponent<Handle>>();
109 openglMesh.indexCount = meshData.indices.size();
112 glGenVertexArrays(1, &openglMesh.vao);
113 glGenBuffers(1, &openglMesh.vbo);
114 glGenBuffers(1, &openglMesh.ebo);
116 glBindVertexArray(openglMesh.vao);
117 glBindBuffer(GL_ARRAY_BUFFER, openglMesh.vbo);
121 meshData.vertices.size() * sizeof(Vertex),
122 &(meshData.vertices)[0],
126 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openglMesh.ebo);
128 GL_ELEMENT_ARRAY_BUFFER,
129 meshData.indices.size() * sizeof(unsigned int),
130 &(meshData.indices)[0],
135 glEnableVertexAttribArray(0);
136 glVertexAttribPointer(
138 GL_FALSE, sizeof(Vertex), nullptr
142 glEnableVertexAttribArray(1);
143 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
144 reinterpret_cast<void*>(offsetof(Vertex, normal))
148 glEnableVertexAttribArray(2);
149 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
150 reinterpret_cast<void*>(offsetof(Vertex, texCoords))
153 glBindVertexArray(0);
162 renderResourceWorld_(renderResourceWorld)
176 void flush(UpdateContext& updateContext) noexcept {
178 if (meshHandles_.empty()) {
182 for (const auto& sourceHandle : meshHandles_) {
183 auto meshEntity = renderResourceWorld_.findEntity<THandle>(sourceHandle);
186 logger_.error("Could not find mesh entity");
187 assert(false && "Could not find mesh entity");
191 if (!upload(*meshEntity)) {
192 logger_.error("Could not compile mesh");
194 meshEntity->template remove<MeshUploadRequestComponent<THandle>>();
198 meshHandles_.clear();
207 bool submit(const MeshBatchUploadCommand<THandle>& command) noexcept {
208 for (const auto& meshHandle : command.meshHandles) {
209 meshHandles_.push_back(meshHandle);
219 void init(helios::engine::runtime::messaging::command::CommandHandlerRegistry& commandHandlerRegistry) noexcept {
220 commandHandlerRegistry.registerHandler<MeshBatchUploadCommand<THandle>>(*this);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.