Skip to main content

OpenGLEnums.ixx File

Included Headers

#include <glad/gl.h> #include <cassert> #include <helios.rendering.mesh.PrimitiveType>

Namespaces Index

namespacehelios
namespaceext

Platform-specific extensions and backend implementations. More...

namespaceopengl

OpenGL-specific implementations. More...

namespacerendering

OpenGL rendering implementations. More...

namespaceOpenGLEnumMapper

File Listing

The file content with the documentation metadata removed is:

1module;
2
3#include <glad/gl.h>
4#include <cassert>
5
6export module helios.ext.opengl.rendering.OpenGLEnumMapper;
7
8import helios.rendering.mesh.PrimitiveType;
9
11
12 /**
13 * @brief Translates a helios abstract PrimitiveType enum to its corresponding OpenGL GLenum value.
14 *
15 * This utility function maps API-agnostic primitive types defined by helios to their
16 * OpenGL equivalents. It is used internally by OpenGLMeshRenderer and other OpenGL
17 * rendering components.
18 *
19 * Supported mappings:
20 * - `PrimitiveType::Points` → `GL_POINTS`
21 * - `PrimitiveType::Lines` → `GL_LINES`
22 * - `PrimitiveType::LineLoop` → `GL_LINE_LOOP`
23 * - `PrimitiveType::LineStrip` → `GL_LINE_STRIP`
24 * - `PrimitiveType::Triangles` → `GL_TRIANGLES`
25 * - `PrimitiveType::TriangleStrip` → `GL_TRIANGLE_STRIP`
26 * - `PrimitiveType::TriangleFan` → `GL_TRIANGLE_FAN`
27 *
28 * Example usage:
29 * ```cpp
30 * auto glPrimitive = OpenGLEnumMapper::toOpenGL(PrimitiveType::Triangles);
31 * glDrawElements(glPrimitive, indexCount, GL_UNSIGNED_INT, nullptr);
32 * ```
33 *
34 * @param primitiveType The API-agnostic PrimitiveType value.
35 *
36 * @return The corresponding OpenGL primitive type as a GLenum. Falls back to
37 * `GL_TRIANGLES` if the mapping is not explicitly defined.
38 *
39 * @note This function is marked `[[nodiscard]]` to encourage proper usage of the return value.
40 */
41 [[nodiscard]] GLenum toOpenGL(helios::rendering::mesh::PrimitiveType primitiveType) noexcept {
42 switch (primitiveType) {
44 return GL_POINTS;
46 return GL_LINES;
48 return GL_LINE_LOOP;
50 return GL_LINE_STRIP;
52 return GL_TRIANGLES;
54 return GL_TRIANGLE_STRIP;
56 return GL_TRIANGLE_FAN;
57 default:
58 return GL_TRIANGLES;
59 }
60 }
61}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.