ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FilamentRenderToBuffer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
11 
13 namespace filament {
14 class Engine;
15 class Renderer;
16 class Scene;
17 class SwapChain;
18 } // namespace filament
20 
21 namespace cloudViewer {
22 namespace visualization {
23 namespace rendering {
24 
25 class FilamentRenderer;
26 class FilamentScene;
27 class FilamentView;
28 
30 public:
31  // Use Renderer::CreateBufferRenderer to instantiate
32  // FilamentRenderToBuffer, unless you are NOT using
33  // CloudViewer::visualization::gui or another FilamentRenderer instance.
34  explicit FilamentRenderToBuffer(filament::Engine& engine);
35 
36  ~FilamentRenderToBuffer() override;
37 
38  void Configure(const View* view,
39  Scene* scene,
40  int width,
41  int height,
42  int n_channels,
43  bool depth_image,
44  BufferReadyCallback cb) override;
45 
46  void SetDimensions(std::uint32_t width, std::uint32_t height) override;
47  View& GetView() override;
48 
49  void Render() override;
50 
51  // Renders the minimum necessary to get Filament to tick its rendering
52  // thread.
53  void RenderTick();
54 
55 private:
56  friend class FilamentRenderer;
57 
58  filament::Engine& engine_;
59  filament::Renderer* renderer_ = nullptr;
60  filament::SwapChain* swapchain_ = nullptr;
61  FilamentView* view_ = nullptr;
62  FilamentScene* scene_ = nullptr;
63 
64  std::size_t width_ = 0;
65  std::size_t height_ = 0;
66  std::size_t n_channels_ = 0;
67  std::uint8_t* buffer_ = nullptr;
68  std::size_t buffer_size_ = 0;
69  bool depth_image_ = false;
70 
71  BufferReadyCallback callback_;
72  bool frame_done_ = true;
73  bool pending_ = false;
74 
75  static void ReadPixelsCallback(void* buffer, size_t size, void* user);
76  void CopySettings(const View* view);
77 };
78 
79 } // namespace rendering
80 } // namespace visualization
81 } // namespace cloudViewer
int width
int size
int height
void Configure(const View *view, Scene *scene, int width, int height, int n_channels, bool depth_image, BufferReadyCallback cb) override
void SetDimensions(std::uint32_t width, std::uint32_t height) override
std::function< void(const Buffer &)> BufferReadyCallback
void ReadPixelsCallback(void *buffer, size_t buffer_size, void *user)
Generic file read and write utility for python interface.