Visual Computing Library  devel
Loading...
Searching...
No Matches
read_framebuffer_request.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_READ_FRAMEBUFFER_REQUEST_H
24#define VCL_BGFX_READ_FRAMEBUFFER_REQUEST_H
25
26#include <bgfx/bgfx.h>
27#include <vclib/render/read_buffer_types.h>
28#include <vclib/space/core/color.h>
29#include <vclib/space/core/point.h>
30
31namespace vcl {
32
33namespace detail {
34
35class ReadFramebufferRequest
36{
37public:
38 using FloatData = ReadBufferTypes::FloatData;
39 using ByteData = ReadBufferTypes::ByteData;
40 using ReadData = ReadBufferTypes::ReadData;
41 using CallbackReadBuffer = ReadBufferTypes::CallbackReadBuffer;
42
43 enum class Type : uint8_t {
44 COLOR = 0, // entire color buffer
45 DEPTH = 1, // single pixel depth
46 ID = 2, // single pixel id
47 COUNT
48 };
49
50 // Read depth constructor
51 ReadFramebufferRequest(
52 Point2i queryDepthPoint,
53 Point2<uint> framebufferSize,
54 CallbackReadBuffer callback,
55 const Color& clearColor = Color::Black);
56
57 // read color constructor
58 ReadFramebufferRequest(
59 Point2<uint> framebufferSize,
60 CallbackReadBuffer callback,
61 const Color& clearColor = Color::Black);
62
63 // Read ID constructor
64 ReadFramebufferRequest(
65 Point2i queryIdPoint,
66 Point2<uint> framebufferSize,
67 bool idAsColor,
68 CallbackReadBuffer callback);
69
70 ~ReadFramebufferRequest();
71
72 ReadFramebufferRequest& operator=(ReadFramebufferRequest&& right) = default;
73
74 Type type() const;
75
76 bgfx::ViewId viewId() const;
77
78 bgfx::FrameBufferHandle frameBuffer() const;
79
80 bool submit();
81
82 bool isSubmitted() const;
83
84 bool isAvailable(uint32_t currentFrame) const;
85
86 [[nodiscard]] bool performRead(uint32_t currFrame) const;
87
88private:
89 // read back type
90 Type mType = Type::COUNT;
91
92 // frame # when data will be available for reading
93 uint32_t mFrameAvailable = 0;
94 // point to read from
95 Point2i mPoint = {-1, -1};
96
97 // frame buffer for offscreen drawing and reading back
98 bgfx::FrameBufferHandle mOffscreenFbh = BGFX_INVALID_HANDLE;
99 // view id for offscreen drawing
100 bgfx::ViewId mViewOffscreenId = 0;
101
102 // blit texture
103 bgfx::TextureHandle mBlitTexture = BGFX_INVALID_HANDLE;
104 Point2<uint16_t> mBlitSize = {0, 0};
105 // data read from the blit texture
106 ReadData mReadData = {};
107 // callback called when the data is available
108 CallbackReadBuffer mReadCallback = nullptr;
109 // submitted flag
110 bool mSubmitted = false;
111};
112
113} // namespace detail
114
115} // namespace vcl
116
117#endif // VCL_BGFX_READ_FRAMEBUFFER_REQUEST_H
Point2< int > Point2i
A convenience alias for a 2-dimensional Point with integer components.
Definition point.h:706