Visual Computing Library
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 // Read depth constructor
44 ReadFramebufferRequest(
45 Point2i queryDepthPoint,
46 Point2<uint> framebufferSize,
47 CallbackReadBuffer callback,
48 const Color& clearColor = Color::Black);
49
50 // read color constructor
51 ReadFramebufferRequest(
52 Point2<uint> framebufferSize,
53 CallbackReadBuffer callback,
54 const Color& clearColor = Color::Black);
55
56 ~ReadFramebufferRequest();
57
58 ReadFramebufferRequest& operator=(ReadFramebufferRequest&& right) = default;
59
60 bgfx::ViewId viewId() const;
61
62 bgfx::FrameBufferHandle frameBuffer() const;
63
64 bool submit();
65
66 bool isSubmitted() const;
67
68 bool isAvailable(uint32_t currentFrame) const;
69
70 [[nodiscard]] bool performRead(uint32_t currFrame) const;
71
72private:
73 enum Type {
74 COLOR = 0, // entire color buffer
75 DEPTH = 1, // single pixel depth
76 COUNT = 2
77 };
78
79 // read back type
80 Type type = COUNT;
81
82 // frame # when data will be available for reading
83 uint32_t frameAvailable = 0;
84 // point to read from
85 Point2i point = {-1, -1};
86
87 // frame buffer for offscreen drawing and reading back
88 bgfx::FrameBufferHandle offscreenFbh = BGFX_INVALID_HANDLE;
89 // view id for offscreen drawing
90 bgfx::ViewId viewOffscreenId = 0;
91
92 // blit texture
93 bgfx::TextureHandle blitTexture = BGFX_INVALID_HANDLE;
94 Point2<uint16_t> blitSize = {0, 0};
95 // data read from the blit texture
96 ReadData readData = {};
97 // callback called when the data is available
98 CallbackReadBuffer readCallback = nullptr;
99 // submitted flag
100 bool submitted = false;
101};
102
103} // namespace detail
104
105} // namespace vcl
106
107#endif // VCL_BGFX_READ_FRAMEBUFFER_REQUEST_H
Point2< int > Point2i
A convenience alias for a 2-dimensional Point with integer components.
Definition point.h:731