GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Cubemap3D.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_GRAPHICS_3D_CUBEMAP_3D_HPP
5#define GREM_GRAPHICS_3D_CUBEMAP_3D_HPP
6
8
11#include <GREM/core/math.hpp>
14
15namespace grem::graphics {
16
17class Device; // Forward declaration, to avoid including Device.hpp.
18
22class Cubemap3D {
23public:
25 struct Vertex {
27 };
28
30 using Index = uint16_t;
31
34
37
42
47
52
54 using PerspectiveBuffer = UniformBuffer<PerspectiveParameters, "Cubemap3DPerspective">;
55
58
61
64
67 .depthBufferMode = DepthBufferMode::NONE,
68 .faceCullingMode = FaceCullingMode::NONE,
69 };
70
72 static constexpr mat4 SIDE_PROJECTION_MATRIX{
73 // clang-format off
74 1.0f, 0.0f, 0.0f, 0.0f,
75 0.0f, 1.0f, 0.0f, 0.0f,
76 0.0f, 0.0f, -1.0f, -1.0f,
77 0.0f, 0.0f, 0.0f, 0.0f,
78 // clang-format on
79 };
80
83 vec3{1.0f, 0.0f, 0.0f},
84 vec3{-1.0f, 0.0f, 0.0f},
85 vec3{0.0f, -1.0f, 0.0f},
86 vec3{0.0f, 1.0f, 0.0f},
87 vec3{0.0f, 0.0f, 1.0f},
88 vec3{0.0f, 0.0f, -1.0f},
89 };
90
92 static constexpr Array SIDE_UP_DIRECTIONS{
93 vec3{0.0f, -1.0f, 0.0f},
94 vec3{0.0f, -1.0f, 0.0f},
95 vec3{0.0f, 0.0f, -1.0f},
96 vec3{0.0f, 0.0f, 1.0f},
97 vec3{0.0f, -1.0f, 0.0f},
98 vec3{0.0f, -1.0f, 0.0f},
99 };
100
111 [[nodiscard]] static Array<mat4, 6> getSideViewMatrices(vec3 position) noexcept {
112 return {
113 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[0], SIDE_UP_DIRECTIONS[0]),
114 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[1], SIDE_UP_DIRECTIONS[1]),
115 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[2], SIDE_UP_DIRECTIONS[2]),
116 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[3], SIDE_UP_DIRECTIONS[3]),
117 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[4], SIDE_UP_DIRECTIONS[4]),
118 lookAt(position, position + SIDE_FORWARD_DIRECTIONS[5], SIDE_UP_DIRECTIONS[5]),
119 };
120 }
121
132 explicit Cubemap3D(Device& device)
133 : mesh(device, MESH_VERTICES, MESH_INDICES) {}
134
140 [[nodiscard]] const Mesh& getMesh() const noexcept {
141 return mesh;
142 }
143
144private:
145 GREM_API(graphics_3d) static const Array<Vertex, 8> MESH_VERTICES;
146 GREM_API(graphics_3d) static const Array<Index, 36> MESH_INDICES;
147
148 Mesh mesh;
149};
150
151} // namespace grem::graphics
152
153#endif
graphics::Mesh< Vertex, Index > Mesh
Cubemap mesh primitive type.
Definition Cubemap3D.hpp:33
static Array< mat4, 6 > getSideViewMatrices(vec3 position) noexcept
Get an array of view matrices for rendering each side of an axis-aligned cubemap from its center at a...
Definition Cubemap3D.hpp:111
static constexpr mat4 SIDE_PROJECTION_MATRIX
Projection matrix for rendering a side of a cubemap from its center.
Definition Cubemap3D.hpp:72
const Mesh & getMesh() const noexcept
Get the cubemap mesh.
Definition Cubemap3D.hpp:140
static constexpr Array SIDE_FORWARD_DIRECTIONS
Camera forward directions for rendering each side of an axis-aligned cubemap.
Definition Cubemap3D.hpp:82
static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS
Default cubemap vertex shader constants.
Definition Cubemap3D.hpp:63
static constexpr Array SIDE_UP_DIRECTIONS
Camera up vectors for rendering each side of an axis-algined cubemap.
Definition Cubemap3D.hpp:92
UniformBuffer< PerspectiveParameters, "Cubemap3DPerspective"> PerspectiveBuffer
Shader buffer for cubemap perspective parameters.
Definition Cubemap3D.hpp:54
static constexpr ShaderPipelineOptions DEFAULT_SHADER_PIPELINE_OPTIONS
Default cubemap graphics pipeline configuration.
Definition Cubemap3D.hpp:66
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing cubemaps.
Definition Cubemap3D.hpp:60
graphics::VertexShader< Mesh, VertexShaderConstants, VertexShaderOutputs, PerspectiveBuffer > VertexShader
Default vertex shader for drawing cubemaps.
Definition Cubemap3D.hpp:57
Cubemap3D(Device &device)
Construct a unit cubemap.
Definition Cubemap3D.hpp:132
uint16_t Index
Data type used in the index buffer of a cubemap mesh.
Definition Cubemap3D.hpp:30
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Generic abstraction of a GPU vertex array object and its associated buffers.
Definition Mesh.hpp:209
Linked GPU shader pipeline.
Definition shaders.hpp:1508
GPU memory buffer containing a fixed-size struct of uniform parameters to be read by a shader program...
Definition buffers.hpp:426
Compiled GPU vertex shader stage.
Definition shaders.hpp:1060
Definition buffer_layouts.hpp:20
@ NONE
Ignore the depth buffer.
Definition shaders.hpp:59
@ NONE
Ignore facing, don't cull primitives based on their winding order.
Definition shaders.hpp:319
vec< 4, float > vec4
Definition math.hpp:440
GREM_ALWAYS_INLINE mat< 4, 4, T > GREM_VECTORCALL lookAt(vec< 3, T > eye, vec< 3, T > target, vec< 3, T > up)
Definition math.hpp:2989
vec< 3, float > vec3
Definition math.hpp:439
mat< 4, 4, float > mat4
Definition math.hpp:806
Definition Array.hpp:20
Struct of fields output by the default fragment shader.
Definition Cubemap3D.hpp:44
vec4 outputColor
Final fragment color.
Definition Cubemap3D.hpp:45
Struct of shader parameters representing the perspective viewing the cubemap.
Definition Cubemap3D.hpp:49
mat4 cubemapViewProjectionMatrix
Combined view-projection matrix of the view perspective.
Definition Cubemap3D.hpp:50
Struct of default vertex shader constants.
Definition Cubemap3D.hpp:36
Struct of fields output by the default vertex shader.
Definition Cubemap3D.hpp:39
vec3 fragmentTextureCoordinates
Cube texture coordinates of the vertex.
Definition Cubemap3D.hpp:40
Data layout for the attributes of a single vertex of a cubemap mesh.
Definition Cubemap3D.hpp:25
vec3 vertexPosition
Position relative to the origin of the cube.
Definition Cubemap3D.hpp:26
Configuration of a graphics pipeline.
Definition shaders.hpp:428