• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 11822551871

13 Nov 2024 04:32PM UTC coverage: 74.4%. Remained the same
11822551871

push

github

Razakhel
[Render/RenderSystem] The scene's dimensions can be recovered

- They may not necessarily be the same as the window's, and should be those used for the camera's viewport & buffers

2 of 4 new or added lines in 2 files covered. (50.0%)

8059 of 10832 relevant lines covered (74.4%)

1816.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.83
/include/RaZ/Render/RenderSystem.hpp
1
#pragma once
2

3
#ifndef RAZ_RENDERSYSTEM_HPP
4
#define RAZ_RENDERSYSTEM_HPP
5

6
#include "RaZ/System.hpp"
7
#include "RaZ/Render/Cubemap.hpp"
8
#include "RaZ/Render/Renderer.hpp"
9
#include "RaZ/Render/RenderGraph.hpp"
10
#include "RaZ/Render/UniformBuffer.hpp"
11
#include "RaZ/Render/Window.hpp"
12

13
#if !defined(__APPLE__) && !defined(__EMSCRIPTEN__) && !defined(RAZ_NO_WINDOW)
14
// XR currently isn't available with macOS or Emscripten and requires windowing capabilities
15
#define RAZ_USE_XR
16
#endif
17

18
namespace Raz {
19

20
class Entity;
21
class MeshRenderer;
22
#if defined(RAZ_USE_XR)
23
class XrSystem;
24
#endif
25

26
/// RenderSystem class, handling the rendering part.
27
class RenderSystem final : public System {
28
  friend RenderGraph;
29

30
public:
31
  /// Creates a render system, initializing its inner data.
32
  RenderSystem() { initialize(); }
×
33
  /// Creates a render system with a given scene size.
34
  /// \param sceneWidth Width of the scene.
35
  /// \param sceneHeight Height of the scene.
36
  RenderSystem(unsigned int sceneWidth, unsigned int sceneHeight) : RenderSystem() { resizeViewport(sceneWidth, sceneHeight); }
×
37
#if !defined(RAZ_NO_WINDOW)
38
  /// Creates a render system along with a window.
39
  /// \param windowWidth Width of the window.
40
  /// \param windowHeight Height of the window.
41
  /// \param windowTitle Title of the window.
42
  /// \param settings Settings to create the window with.
43
  /// \param antiAliasingSampleCount Number of anti-aliasing samples.
44
  /// \note The window's width & height are to be considered just hints; the window manager remains responsible for the actual dimensions, which may be lower.
45
  ///   This can notably happen when the requested window size exceeds what the screens can display. The actual window's size can be queried afterward.
46
  /// \see getWindow(), Window::getWidth(), Window::getHeight()
47
  RenderSystem(unsigned int windowWidth, unsigned int windowHeight,
×
48
               const std::string& windowTitle,
49
               WindowSetting windowSettings = WindowSetting::DEFAULT,
50
               uint8_t antiAliasingSampleCount = 1)
51
    : m_window{ Window::create(*this, windowWidth, windowHeight, windowTitle, windowSettings, antiAliasingSampleCount) } { initialize(m_window->getWidth(),
×
52
                                                                                                                                      m_window->getHeight()); }
×
53
#endif
54

NEW
55
  unsigned int getSceneWidth() const { return m_sceneWidth; }
×
NEW
56
  unsigned int getSceneHeight() const { return m_sceneHeight; }
×
57
#if !defined(RAZ_NO_WINDOW)
58
  bool hasWindow() const { return (m_window != nullptr); }
×
59
  const Window& getWindow() const { assert("Error: The window must be set before being accessed." && hasWindow()); return *m_window; }
×
60
  Window& getWindow() { return const_cast<Window&>(static_cast<const RenderSystem*>(this)->getWindow()); }
×
61
#endif
62
  const RenderPass& getGeometryPass() const { return m_renderGraph.getGeometryPass(); }
63
  RenderPass& getGeometryPass() { return m_renderGraph.getGeometryPass(); }
×
64
  const RenderGraph& getRenderGraph() const { return m_renderGraph; }
65
  RenderGraph& getRenderGraph() { return m_renderGraph; }
×
66
  bool hasCubemap() const { return m_cubemap.has_value(); }
24✔
67
  const Cubemap& getCubemap() const { assert("Error: The cubemap must be set before being accessed." && hasCubemap()); return *m_cubemap; }
2✔
68

69
  void setCubemap(Cubemap&& cubemap);
70
#if defined(RAZ_USE_XR)
71
  void enableXr(XrSystem& xrSystem);
72
#endif
73

74
#if !defined(RAZ_NO_WINDOW)
75
  void createWindow(unsigned int width, unsigned int height,
2✔
76
                    const std::string& title = {},
77
                    WindowSetting settings = WindowSetting::DEFAULT,
78
                    uint8_t antiAliasingSampleCount = 1) { m_window = Window::create(*this, width, height, title, settings, antiAliasingSampleCount); }
2✔
79
#endif
80
  void resizeViewport(unsigned int width, unsigned int height);
81
  bool update(const FrameTimeInfo& timeInfo) override;
82
  /// Updates all lights referenced by the RenderSystem, sending their data to the GPU.
83
  void updateLights() const;
84
  void updateShaders() const;
85
  void updateMaterials(const MeshRenderer& meshRenderer) const;
86
  void updateMaterials() const;
87
  /// Retrieves & saves the back buffer's data from the GPU.
88
  /// \warning The pixel storage pack & unpack alignments should be set to 1 in order to recover actual pixels.
89
  /// \see Renderer::setPixelStorage()
90
  /// \warning Retrieving an image from the GPU is slow; use this function with caution.
91
  void saveToImage(const FilePath& filePath, TextureFormat format = TextureFormat::RGB, PixelDataType dataType = PixelDataType::UBYTE) const;
92
  void removeCubemap() { m_cubemap.reset(); }
1✔
93
  void destroy() override;
94

95
protected:
96
  void linkEntity(const EntityPtr& entity) override;
97

98
private:
99
  void initialize();
100
  void initialize(unsigned int sceneWidth, unsigned int sceneHeight);
101
  void sendCameraInfo() const;
102
  void sendViewMatrix(const Mat4f& viewMat) const { m_cameraUbo.sendData(viewMat, 0); }
12✔
103
  void sendInverseViewMatrix(const Mat4f& invViewMat) const { m_cameraUbo.sendData(invViewMat, sizeof(Mat4f)); }
12✔
104
  void sendProjectionMatrix(const Mat4f& projMat) const { m_cameraUbo.sendData(projMat, sizeof(Mat4f) * 2); }
21✔
105
  void sendInverseProjectionMatrix(const Mat4f& invProjMat) const { m_cameraUbo.sendData(invProjMat, sizeof(Mat4f) * 3); }
21✔
106
  void sendViewProjectionMatrix(const Mat4f& viewProjMat) const { m_cameraUbo.sendData(viewProjMat, sizeof(Mat4f) * 4); }
21✔
107
  void sendCameraPosition(const Vec3f& cameraPos) const { m_cameraUbo.sendData(cameraPos, sizeof(Mat4f) * 5); }
12✔
108
  /// Updates a single light, sending its data to the GPU.
109
  /// \warning The lights UBO needs to be bound before calling this function.
110
  /// \note If resetting a removed light or updating one not yet known by the application, call updateLights() instead to fully take that change into account.
111
  /// \param entity Light entity to be updated; if not a directional light, needs to have a Transform component.
112
  /// \param lightIndex Index of the light to be updated.
113
  void updateLight(const Entity& entity, unsigned int lightIndex) const;
114
#if defined(RAZ_USE_XR)
115
  void renderXrFrame();
116
#endif
117
  void copyToWindow(const Texture2D& colorBuffer, const Texture2D& depthBuffer, unsigned int windowWidth, unsigned int windowHeight) const;
118

119
  unsigned int m_sceneWidth {};
120
  unsigned int m_sceneHeight {};
121

122
#if !defined(RAZ_NO_WINDOW)
123
  WindowPtr m_window {};
124
#endif
125

126
  Entity* m_cameraEntity {};
127
  RenderGraph m_renderGraph {};
128
  UniformBuffer m_cameraUbo = UniformBuffer(sizeof(Mat4f) * 5 + sizeof(Vec4f), UniformBufferUsage::DYNAMIC);
129
  UniformBuffer m_lightsUbo = UniformBuffer(sizeof(Vec4f) * 4 * 100 + sizeof(Vec4u), UniformBufferUsage::DYNAMIC);
130
  UniformBuffer m_timeUbo   = UniformBuffer(sizeof(float) * 2, UniformBufferUsage::STREAM);
131
  UniformBuffer m_modelUbo  = UniformBuffer(sizeof(Mat4f), UniformBufferUsage::STREAM);
132

133
  std::optional<Cubemap> m_cubemap {};
134

135
#if defined(RAZ_USE_XR)
136
  XrSystem* m_xrSystem {};
137
#endif
138
};
139

140
} // namespace Raz
141

142
#endif // RAZ_RENDERSYSTEM_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc