Banuba SDK
render_target.hpp
1 #pragma once
2 
3 #include <bnb/utils/defs.hpp>
4 
5 #include <memory>
6 
7 namespace bnb::player_api::interfaces
8 {
9  class render_target;
10  class player;
11 } // namespace bnb::player_api::interfaces
12 
13 namespace bnb::player_api
14 {
15  using render_target_sptr = std::shared_ptr<bnb::player_api::interfaces::render_target>;
16  using texture_t = uint64_t;
17 } // namespace bnb::player_api
18 
19 namespace bnb::player_api::interfaces
20 {
21 
22  /**
23  * Responsible for preparation for drawing frames to 'outputs'.
24  * This part of the RenderTarget is owned and controlled only by the player
25  */
26  class BNB_EXPORT render_target
27  {
28  public:
29  /**
30  * Destroy render_target and release resources
31  */
32  virtual ~render_target() = default;
33 
34  /**
35  * Attach render_target to the player. Called by the player on the render thread.
36  * @param player instance
37  */
38  virtual void attach(player& player) = 0;
39 
40  /**
41  * Detach render_target from the player. Called by the player on the render thread.
42  * @param player instance
43  */
44  virtual void detach(player& player) = 0;
45 
46  /**
47  * Prepare render target to offscreen rendering of the player
48  * @param width rendering surface width
49  * @param height rendering surface height
50  */
51  virtual void prepare_to_offscreen_render(int32_t width, int32_t height) = 0;
52 
53  /**
54  * Prepare render target to screen rendering
55  * @param surface rendering surface
56  */
57  virtual void prepare_to_screen_render(void* surface) = 0;
58 
59  /**
60  * Set presentation frame time
61  * @param time_us time in microseconds
62  */
63  virtual void set_frame_time_us(uint64_t time_us) noexcept = 0;
64 
65  /**
66  * Get frame time microseconds
67  */
68  virtual uint64_t get_frame_time_us() const noexcept = 0;
69 
70  /**
71  * Get render surface size width
72  */
73  virtual int32_t get_render_width() const noexcept = 0;
74 
75  /**
76  * Get render surface size height
77  */
78  virtual int32_t get_render_height() const noexcept = 0;
79 
80  /**
81  * Returns the drawn texture.
82  * With an OpenGL backend, to get an opengl texture you need to do this:
83  * reinterpret_cast<GLuint>(render_terget->get_output_texture())
84  */
85  virtual texture_t get_output_texture() const noexcept = 0;
86 
87  /**
88  * Draw the frame on the prepared surface
89  * @param left viewport x coord
90  * @param top viewport y coord
91  * @param width of the viewport
92  * @param height of the viewport
93  * @param mat4 texture matrix
94  */
95  virtual void present(int32_t left, int32_t top, int32_t width, int32_t height, const float* const mat4) = 0;
96  }; // class render_target
97 
98 } // namespace bnb::player_api::interfaces
bnb::player_api::interfaces::player
Class manages the lifecycle of the EffectPlayer and is responsible for drawing FrameData that comes f...
Definition: player.hpp:33
bnb::player_api::interfaces::render_target
Responsible for preparation for drawing frames to 'outputs'.
Definition: render_target.hpp:26