Skip to main content

OpenGLMeshUploadManager Class Template

Manager that consumes mesh-upload commands and performs OpenGL buffer setup. More...

Declaration

template <typename THandle, typename TCommandBuffer = NullCommandBuffer> class helios::opengl::OpenGLMeshUploadManager<THandle, TCommandBuffer> { ... }

Public Member Typedefs Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
usingEngineRoleTag = ManagerRole

Engine role marker used by runtime registries. More...

Public Constructors Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
OpenGLMeshUploadManager (RenderResourceWorld &renderResourceWorld)

Public Member Functions Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
voidflush (UpdateContext &updateContext) noexcept

Uploads all queued meshes and clears processed queue entries. More...

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
boolsubmit (const MeshBatchUploadCommand< THandle > &command) noexcept

Queues mesh handles from a batch upload command. More...

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
voidinit (helios::engine::runtime::messaging::command::CommandHandlerRegistry &commandHandlerRegistry) noexcept

Registers mesh upload command handlers in the command registry. More...

Private Member Functions Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
boolupload (MeshEntity mesh) noexcept

Uploads one mesh to GPU buffers and configures vertex attributes. More...

Private Member Attributes Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
RenderResourceWorld &renderResourceWorld_
template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
std::vector< MeshHandle >meshHandles_

Private Static Attributes Index

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
static const Logger &logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Description

Manager that consumes mesh-upload commands and performs OpenGL buffer setup.

Template Parameters
THandle

Mesh handle type.

TCommandBuffer

Command buffer type for optional follow-up commands.

Definition at line 69 of file OpenGLMeshUploadManager.ixx.

Public Member Typedefs

EngineRoleTag

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
using helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::EngineRoleTag = ManagerRole

Engine role marker used by runtime registries.

Definition at line 168 of file OpenGLMeshUploadManager.ixx.

168 using EngineRoleTag = ManagerRole;

Public Constructors

OpenGLMeshUploadManager()

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::OpenGLMeshUploadManager (RenderResourceWorld & renderResourceWorld)
inline explicit

Definition at line 160 of file OpenGLMeshUploadManager.ixx.

160 explicit OpenGLMeshUploadManager(RenderResourceWorld& renderResourceWorld)
161 :
162 renderResourceWorld_(renderResourceWorld)
163 { }

Public Member Functions

flush()

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
void helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::flush (UpdateContext & updateContext)
inline noexcept

Uploads all queued meshes and clears processed queue entries.

Parameters
updateContext

Frame-local update context.

Definition at line 176 of file OpenGLMeshUploadManager.ixx.

176 void flush(UpdateContext& updateContext) noexcept {
177
178 if (meshHandles_.empty()) {
179 return;
180 }
181
182 for (const auto& sourceHandle : meshHandles_) {
183 auto meshEntity = renderResourceWorld_.findEntity<THandle>(sourceHandle);
184
185 if (!meshEntity) {
186 logger_.error("Could not find mesh entity");
187 assert(false && "Could not find mesh entity");
188 continue;
189 }
190
191 if (!upload(*meshEntity)) {
192 logger_.error("Could not compile mesh");
193 } else {
194 meshEntity->template remove<MeshUploadRequestComponent<THandle>>();
195 }
196 }
197
198 meshHandles_.clear();
199 }

init()

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
void helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::init (helios::engine::runtime::messaging::command::CommandHandlerRegistry & commandHandlerRegistry)
inline noexcept

Registers mesh upload command handlers in the command registry.

Parameters
commandHandlerRegistry

Registry used for command-handler registration.

Definition at line 219 of file OpenGLMeshUploadManager.ixx.

219 void init(helios::engine::runtime::messaging::command::CommandHandlerRegistry& commandHandlerRegistry) noexcept {
220 commandHandlerRegistry.registerHandler<MeshBatchUploadCommand<THandle>>(*this);
221 }

submit()

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
bool helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::submit (const MeshBatchUploadCommand< THandle > & command)
inline noexcept

Queues mesh handles from a batch upload command.

Parameters
command

Batch command containing mesh handles to upload.

Returns

true when the command was accepted.

Definition at line 207 of file OpenGLMeshUploadManager.ixx.

207 bool submit(const MeshBatchUploadCommand<THandle>& command) noexcept {
208 for (const auto& meshHandle : command.meshHandles) {
209 meshHandles_.push_back(meshHandle);
210 }
211 return true;
212 }

Private Member Functions

upload()

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
bool helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::upload (MeshEntity mesh)
inline noexcept

Uploads one mesh to GPU buffers and configures vertex attributes.

Parameters
mesh

Mesh entity containing upload request and mesh data.

Returns

true if upload succeeded, otherwise false.

Definition at line 85 of file OpenGLMeshUploadManager.ixx.

85 bool upload(MeshEntity mesh) noexcept {
86
87 using Handle = typename MeshEntity::Handle_type;
88
89 logger_.info("Uploading mesh data for MeshEntity {0}...", mesh.handle().entityId);
90
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");
94 return false;
95 }
96
97
98 if (mesh.template get<OpenGLMeshComponent<Handle>>()) {
99 logger_.error("Mesh already has a MeshComponent");
100 assert(false && "Mesh already has a MeshComponent");
101 return false;
102 }
103
104 auto* meshDataComponent = mesh.template get<MeshDataComponent<Handle>>();
105 auto& meshData = meshDataComponent->meshData;
106
107 auto& openglMesh = mesh.template add<OpenGLMeshComponent<Handle>>();
108
109 openglMesh.indexCount = meshData.indices.size();
110 openglMesh.primitiveType = OpenGLEnumMapper::toOpenGL(meshData.primitiveType);
111
112 glGenVertexArrays(1, &openglMesh.vao);
113 glGenBuffers(1, &openglMesh.vbo);
114 glGenBuffers(1, &openglMesh.ebo);
115
116 glBindVertexArray(openglMesh.vao);
117 glBindBuffer(GL_ARRAY_BUFFER, openglMesh.vbo);
118
119 glBufferData(
120 GL_ARRAY_BUFFER,
121 meshData.vertices.size() * sizeof(Vertex),
122 &(meshData.vertices)[0],
123 GL_STATIC_DRAW
124 );
125
126 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openglMesh.ebo);
127 glBufferData(
128 GL_ELEMENT_ARRAY_BUFFER,
129 meshData.indices.size() * sizeof(unsigned int),
130 &(meshData.indices)[0],
131 GL_STATIC_DRAW
132 );
133
134 // vertex position
135 glEnableVertexAttribArray(0);
136 glVertexAttribPointer(
137 0, 3, GL_FLOAT,
138 GL_FALSE, sizeof(Vertex), nullptr
139 );
140
141 // vertex normals
142 glEnableVertexAttribArray(1);
143 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
144 reinterpret_cast<void*>(offsetof(Vertex, normal))
145 );
146
147 // vertex texture coords
148 glEnableVertexAttribArray(2);
149 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
150 reinterpret_cast<void*>(offsetof(Vertex, texCoords))
151 );
152
153 glBindVertexArray(0);
154 return true;
155 }

Private Member Attributes

meshHandles_

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
std::vector<MeshHandle> helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::meshHandles_

Definition at line 73 of file OpenGLMeshUploadManager.ixx.

73 std::vector<MeshHandle> meshHandles_;

renderResourceWorld_

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
RenderResourceWorld& helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::renderResourceWorld_

Definition at line 71 of file OpenGLMeshUploadManager.ixx.

71 RenderResourceWorld& renderResourceWorld_;

Private Static Attributes

logger_

template <typename THandle, typename TCommandBuffer = NullCommandBuffer>
const Logger& helios::opengl::OpenGLMeshUploadManager< THandle, TCommandBuffer >::logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE)
static

Definition at line 76 of file OpenGLMeshUploadManager.ixx.

76 inline static const Logger& logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE);

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.